Files
winos-config/packages/dsc-ts/src/dsl/dsl-core.ts
EthanShoeDev 3f18e881fa dynamic config
2025-12-22 16:52:35 -05:00

49 lines
1.5 KiB
TypeScript

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<typeof ConfigurationSchema>;
/**
* A resource that can be nested in an array.
*/
export type UserResource =
| S.Schema.Encoded<typeof ResourceUnion>
| Array<UserResource>;
/**
* The configuration type that the user provides.
* This makes fields like $schema optional and allows nested resources.
*/
export interface UserConfiguration
extends Omit<S.Schema.Encoded<typeof ConfigurationSchema>, 'resources'> {
resources: Array<UserResource>;
}
/**
* 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<UserConfiguration>);