@baseplate-dev/sync
Version:
Library for syncing Baseplate descriptions
68 lines • 2.55 kB
TypeScript
import type { FieldMap, FieldMapSchema, FieldMapSchemaBuilder, FieldMapValues } from '@baseplate-dev/utils';
import type { GeneratorTask } from '#src/generators/generators.js';
import type { ProviderExportScope } from '#src/providers/export-scopes.js';
import type { ProviderType } from '#src/providers/providers.js';
/**
* Options for creating a configuration provider task
*/
interface ConfigProviderTaskOptions {
/**
* The prefix for the providers
*/
prefix: string;
/**
* The name of the task
*
* @default 'config'
*/
taskName?: string;
/**
* The scope for the config provider
*/
configScope?: ProviderExportScope;
/**
* The scope for the config values output provider
*/
configValuesScope?: ProviderExportScope;
}
type ConfigProviderTaskResult<TSchema extends FieldMapSchema> = [
GeneratorTask,
ProviderType<Omit<FieldMap<TSchema>, 'getValues'>>,
ProviderType<FieldMapValues<TSchema>>
];
/**
* Creates a configuration provider task that exposes both a modifiable config map and its resolved values
*
* This helper creates a task with two providers:
* 1. A standard provider exposing the field map with modifiable containers
* 2. An output provider exposing the resolved configuration values (read-only)
*
* The field map contains containers for each field that can be modified by calling
* methods like set(), push(), or merge() depending on the container type.
*
* @param schemaBuilder - The schema builder for defining the field map structure
* @param options - The options for the configuration task
* @returns A tuple containing the generator task and both provider types
*
* @example
* ```typescript
* const [nodeConfigTask, nodeConfigProvider, nodeConfigValuesProvider] = createConfigProviderTask(
* t => ({
* port: t.number().default(3000),
* host: t.string().default('localhost')
* }),
* { prefix: 'node-server' }
* );
*
* // In a consuming task:
* // 1. Modify the field map containers:
* deps.nodeConfigProvider.port.set(4000, 'environment-override');
*
* // 2. Read the resolved values:
* const config = deps.nodeConfigValues;
* console.log(config.port); // 4000
* ```
*/
export declare function createConfigProviderTask<TSchema extends FieldMapSchema>(schemaBuilder: (t: FieldMapSchemaBuilder) => TSchema, { prefix, taskName, configScope, configValuesScope, }: ConfigProviderTaskOptions): ConfigProviderTaskResult<TSchema>;
export {};
//# sourceMappingURL=create-config-provider-task.d.ts.map