import * as S from 'effect/Schema'; import { ResourceUnion } from '../dsc-resource-schema-types/_resource-union.gen'; import { Configuration as DscConfiguration } from '../dsc-schema-types/configuration.gen'; const defaultSchemaUri = 'https://aka.ms/dsc/schemas/v3/config/document.json' as const; /** * Enhanced configuration schema with strong typing for resources. * This extends the base DSC Configuration schema but overrides the 'resources' * field with our strongly-typed union of all resources available on this system. */ export const ConfigurationSchema = S.Struct({ ...DscConfiguration.fields, $schema: S.optional(DscConfiguration.fields.$schema).pipe( S.withDefaults({ constructor: () => defaultSchemaUri, decoding: () => defaultSchemaUri, }), ), resources: S.Array(ResourceUnion), }); export type Configuration = S.Schema.Type; /** * A resource that can be nested in an array. */ export type UserResource = | S.Schema.Encoded | Array; /** * The configuration type that the user provides. * This makes fields like $schema optional and allows nested resources. */ export interface UserConfiguration extends Omit, 'resources'> { resources: Array; } /** * The configuration can be a plain object or a function that returns the configuration. * The function can be asynchronous. */ export type ConfigProvider = | UserConfiguration | (() => UserConfiguration | Promise);