@optique/config 1.0.0-dev.921 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +258 -361
- package/dist/index.d.cts +29 -36
- package/dist/index.d.ts +29 -36
- package/dist/index.js +259 -356
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -19,36 +19,6 @@ interface ConfigMeta {
|
|
|
19
19
|
*/
|
|
20
20
|
readonly configPath: string;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Sets active config data for a context.
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
declare function setActiveConfig<T>(contextId: symbol, data: T): void;
|
|
27
|
-
/**
|
|
28
|
-
* Gets active config data for a context.
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
declare function getActiveConfig<T>(contextId: symbol): T | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Clears active config data for a context.
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
declare function clearActiveConfig(contextId: symbol): void;
|
|
37
|
-
/**
|
|
38
|
-
* Sets active config metadata for a context.
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
declare function setActiveConfigMeta<T>(contextId: symbol, meta: T): void;
|
|
42
|
-
/**
|
|
43
|
-
* Gets active config metadata for a context.
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
declare function getActiveConfigMeta<T>(contextId: symbol): T | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* Clears active config metadata for a context.
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
declare function clearActiveConfigMeta(contextId: symbol): void;
|
|
52
22
|
/**
|
|
53
23
|
* Options for creating a config context.
|
|
54
24
|
*
|
|
@@ -82,7 +52,10 @@ interface ConfigContextOptions<T> {
|
|
|
82
52
|
*/
|
|
83
53
|
interface ConfigLoadResult<TConfigMeta = ConfigMeta> {
|
|
84
54
|
/**
|
|
85
|
-
* Raw config data to validate against the schema.
|
|
55
|
+
* Raw config data to validate against the schema. The value is always
|
|
56
|
+
* passed to the schema validator, even when `undefined` or `null`.
|
|
57
|
+
* To signal "no config found" without validation, return `undefined`
|
|
58
|
+
* or `null` directly from `load()` instead of wrapping it in an object.
|
|
86
59
|
*/
|
|
87
60
|
readonly config: unknown;
|
|
88
61
|
/**
|
|
@@ -117,15 +90,18 @@ interface ConfigContextRequiredOptions<TConfigMeta = ConfigMeta> {
|
|
|
117
90
|
* returns the config data (or a Promise of it). This allows full control
|
|
118
91
|
* over file discovery, loading, merging, and error handling.
|
|
119
92
|
*
|
|
120
|
-
* The returned
|
|
93
|
+
* The returned `ConfigLoadResult.config` is always validated against the
|
|
94
|
+
* schema. Return `undefined` or `null` directly (not wrapped in a
|
|
95
|
+
* `ConfigLoadResult`) to signal that no config data was found;
|
|
96
|
+
* `bindConfig()` will fall back to its defaults.
|
|
121
97
|
*
|
|
122
98
|
* When `load` is provided, `getConfigPath` is ignored.
|
|
123
99
|
*
|
|
124
100
|
* @param parsed The result from the first parse pass.
|
|
125
|
-
* @returns Config data and metadata
|
|
101
|
+
* @returns Config data and metadata, or `undefined`/`null` for no config.
|
|
126
102
|
* @since 1.0.0
|
|
127
103
|
*/
|
|
128
|
-
readonly load?: (parsed: ParserValuePlaceholder) => Promise<ConfigLoadResult<TConfigMeta
|
|
104
|
+
readonly load?: (parsed: ParserValuePlaceholder) => Promise<ConfigLoadResult<TConfigMeta> | undefined | null> | ConfigLoadResult<TConfigMeta> | undefined | null;
|
|
129
105
|
}
|
|
130
106
|
/**
|
|
131
107
|
* A config context that provides configuration data via annotations.
|
|
@@ -150,13 +126,24 @@ interface ConfigContext<T, TConfigMeta = ConfigMeta> extends SourceContext<Confi
|
|
|
150
126
|
*
|
|
151
127
|
* The config context implements the `SourceContext` interface and can be used
|
|
152
128
|
* with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
|
|
153
|
-
* *@optique/run* to provide configuration file support.
|
|
129
|
+
* *@optique/run* to provide configuration file support. Each runner call
|
|
130
|
+
* receives its own annotation snapshot, so the same `ConfigContext`
|
|
131
|
+
* instance can be reused safely across independent or concurrent runs.
|
|
132
|
+
* When calling `context.getAnnotations()` manually, omit the request for a
|
|
133
|
+
* phase-1 snapshot or pass `{ phase: "phase2", parsed }` for a phase-two
|
|
134
|
+
* snapshot, then thread the returned annotations into low-level APIs such
|
|
135
|
+
* as `parse()`, `parseAsync()`, `parser.complete()`, `suggest()`, or
|
|
136
|
+
* `getDocPage()`. Calling `getAnnotations()` by itself does not affect
|
|
137
|
+
* later parses unless those returned annotations are explicitly threaded
|
|
138
|
+
* into a low-level API call.
|
|
154
139
|
*
|
|
155
140
|
* @template T The output type of the config schema.
|
|
156
141
|
* @template TConfigMeta The metadata type for config sources.
|
|
157
142
|
* @param options Configuration options including schema and optional file
|
|
158
143
|
* parser.
|
|
159
144
|
* @returns A config context that can be used with `bindConfig()` and runners.
|
|
145
|
+
* @throws {TypeError} If `schema` is not a valid Standard Schema object.
|
|
146
|
+
* @throws {TypeError} If `fileParser` is provided but is not a function.
|
|
160
147
|
* @since 0.10.0
|
|
161
148
|
*
|
|
162
149
|
* @example
|
|
@@ -214,6 +201,12 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
|
|
|
214
201
|
* @param parser The parser to bind to config values.
|
|
215
202
|
* @param options Binding options including context, key, and default.
|
|
216
203
|
* @returns A new parser with config fallback behavior.
|
|
204
|
+
* @throws {TypeError} If `key` is not a property key or function.
|
|
205
|
+
* @throws {Error} If the inner parser's {@link Parser.validateValue} hook
|
|
206
|
+
* throws while re-validating a fallback value (a
|
|
207
|
+
* config-sourced value or the configured `default`) —
|
|
208
|
+
* the hook can run even when no CLI tokens are parsed
|
|
209
|
+
* (see issue #414).
|
|
217
210
|
* @since 0.10.0
|
|
218
211
|
*
|
|
219
212
|
* @example
|
|
@@ -231,4 +224,4 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
|
|
|
231
224
|
*/
|
|
232
225
|
declare function bindConfig<M extends "sync" | "async", TValue, TState, T, TConfigMeta = ConfigMeta>(parser: Parser<M, TValue, TState>, options: BindConfigOptions<T, TValue, TConfigMeta>): Parser<M, TValue, TState>;
|
|
233
226
|
//#endregion
|
|
234
|
-
export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig,
|
|
227
|
+
export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, createConfigContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -19,36 +19,6 @@ interface ConfigMeta {
|
|
|
19
19
|
*/
|
|
20
20
|
readonly configPath: string;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Sets active config data for a context.
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
declare function setActiveConfig<T>(contextId: symbol, data: T): void;
|
|
27
|
-
/**
|
|
28
|
-
* Gets active config data for a context.
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
declare function getActiveConfig<T>(contextId: symbol): T | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Clears active config data for a context.
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
declare function clearActiveConfig(contextId: symbol): void;
|
|
37
|
-
/**
|
|
38
|
-
* Sets active config metadata for a context.
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
declare function setActiveConfigMeta<T>(contextId: symbol, meta: T): void;
|
|
42
|
-
/**
|
|
43
|
-
* Gets active config metadata for a context.
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
declare function getActiveConfigMeta<T>(contextId: symbol): T | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* Clears active config metadata for a context.
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
declare function clearActiveConfigMeta(contextId: symbol): void;
|
|
52
22
|
/**
|
|
53
23
|
* Options for creating a config context.
|
|
54
24
|
*
|
|
@@ -82,7 +52,10 @@ interface ConfigContextOptions<T> {
|
|
|
82
52
|
*/
|
|
83
53
|
interface ConfigLoadResult<TConfigMeta = ConfigMeta> {
|
|
84
54
|
/**
|
|
85
|
-
* Raw config data to validate against the schema.
|
|
55
|
+
* Raw config data to validate against the schema. The value is always
|
|
56
|
+
* passed to the schema validator, even when `undefined` or `null`.
|
|
57
|
+
* To signal "no config found" without validation, return `undefined`
|
|
58
|
+
* or `null` directly from `load()` instead of wrapping it in an object.
|
|
86
59
|
*/
|
|
87
60
|
readonly config: unknown;
|
|
88
61
|
/**
|
|
@@ -117,15 +90,18 @@ interface ConfigContextRequiredOptions<TConfigMeta = ConfigMeta> {
|
|
|
117
90
|
* returns the config data (or a Promise of it). This allows full control
|
|
118
91
|
* over file discovery, loading, merging, and error handling.
|
|
119
92
|
*
|
|
120
|
-
* The returned
|
|
93
|
+
* The returned `ConfigLoadResult.config` is always validated against the
|
|
94
|
+
* schema. Return `undefined` or `null` directly (not wrapped in a
|
|
95
|
+
* `ConfigLoadResult`) to signal that no config data was found;
|
|
96
|
+
* `bindConfig()` will fall back to its defaults.
|
|
121
97
|
*
|
|
122
98
|
* When `load` is provided, `getConfigPath` is ignored.
|
|
123
99
|
*
|
|
124
100
|
* @param parsed The result from the first parse pass.
|
|
125
|
-
* @returns Config data and metadata
|
|
101
|
+
* @returns Config data and metadata, or `undefined`/`null` for no config.
|
|
126
102
|
* @since 1.0.0
|
|
127
103
|
*/
|
|
128
|
-
readonly load?: (parsed: ParserValuePlaceholder) => Promise<ConfigLoadResult<TConfigMeta
|
|
104
|
+
readonly load?: (parsed: ParserValuePlaceholder) => Promise<ConfigLoadResult<TConfigMeta> | undefined | null> | ConfigLoadResult<TConfigMeta> | undefined | null;
|
|
129
105
|
}
|
|
130
106
|
/**
|
|
131
107
|
* A config context that provides configuration data via annotations.
|
|
@@ -150,13 +126,24 @@ interface ConfigContext<T, TConfigMeta = ConfigMeta> extends SourceContext<Confi
|
|
|
150
126
|
*
|
|
151
127
|
* The config context implements the `SourceContext` interface and can be used
|
|
152
128
|
* with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
|
|
153
|
-
* *@optique/run* to provide configuration file support.
|
|
129
|
+
* *@optique/run* to provide configuration file support. Each runner call
|
|
130
|
+
* receives its own annotation snapshot, so the same `ConfigContext`
|
|
131
|
+
* instance can be reused safely across independent or concurrent runs.
|
|
132
|
+
* When calling `context.getAnnotations()` manually, omit the request for a
|
|
133
|
+
* phase-1 snapshot or pass `{ phase: "phase2", parsed }` for a phase-two
|
|
134
|
+
* snapshot, then thread the returned annotations into low-level APIs such
|
|
135
|
+
* as `parse()`, `parseAsync()`, `parser.complete()`, `suggest()`, or
|
|
136
|
+
* `getDocPage()`. Calling `getAnnotations()` by itself does not affect
|
|
137
|
+
* later parses unless those returned annotations are explicitly threaded
|
|
138
|
+
* into a low-level API call.
|
|
154
139
|
*
|
|
155
140
|
* @template T The output type of the config schema.
|
|
156
141
|
* @template TConfigMeta The metadata type for config sources.
|
|
157
142
|
* @param options Configuration options including schema and optional file
|
|
158
143
|
* parser.
|
|
159
144
|
* @returns A config context that can be used with `bindConfig()` and runners.
|
|
145
|
+
* @throws {TypeError} If `schema` is not a valid Standard Schema object.
|
|
146
|
+
* @throws {TypeError} If `fileParser` is provided but is not a function.
|
|
160
147
|
* @since 0.10.0
|
|
161
148
|
*
|
|
162
149
|
* @example
|
|
@@ -214,6 +201,12 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
|
|
|
214
201
|
* @param parser The parser to bind to config values.
|
|
215
202
|
* @param options Binding options including context, key, and default.
|
|
216
203
|
* @returns A new parser with config fallback behavior.
|
|
204
|
+
* @throws {TypeError} If `key` is not a property key or function.
|
|
205
|
+
* @throws {Error} If the inner parser's {@link Parser.validateValue} hook
|
|
206
|
+
* throws while re-validating a fallback value (a
|
|
207
|
+
* config-sourced value or the configured `default`) —
|
|
208
|
+
* the hook can run even when no CLI tokens are parsed
|
|
209
|
+
* (see issue #414).
|
|
217
210
|
* @since 0.10.0
|
|
218
211
|
*
|
|
219
212
|
* @example
|
|
@@ -231,4 +224,4 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
|
|
|
231
224
|
*/
|
|
232
225
|
declare function bindConfig<M extends "sync" | "async", TValue, TState, T, TConfigMeta = ConfigMeta>(parser: Parser<M, TValue, TState>, options: BindConfigOptions<T, TValue, TConfigMeta>): Parser<M, TValue, TState>;
|
|
233
226
|
//#endregion
|
|
234
|
-
export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig,
|
|
227
|
+
export { BindConfigOptions, ConfigContext, ConfigContextOptions, ConfigContextRequiredOptions, ConfigLoadResult, ConfigMeta, bindConfig, createConfigContext };
|