@optique/config 1.1.0-dev.2006 → 1.1.0-dev.2053
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 +25 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +25 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -87,6 +87,14 @@ function validateWithSchema(schema, rawData) {
|
|
|
87
87
|
/**
|
|
88
88
|
* Creates a config context for use with Optique parsers.
|
|
89
89
|
*
|
|
90
|
+
* Pass the returned context to `run()`'s `contexts` option so that
|
|
91
|
+
* `bindConfig()` can read configuration values during parsing:
|
|
92
|
+
*
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const configContext = createConfigContext({ schema });
|
|
95
|
+
* run(parser, { contexts: [configContext], contextOptions: { load } });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
90
98
|
* The config context implements the `SourceContext` interface and can be used
|
|
91
99
|
* with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
|
|
92
100
|
* *@optique/run* to provide configuration file support. Each runner call
|
|
@@ -210,6 +218,18 @@ function createConfigContext(options) {
|
|
|
210
218
|
* 3. Default value (if specified)
|
|
211
219
|
* 4. Error (if none of the above)
|
|
212
220
|
*
|
|
221
|
+
* > **Important:** `bindConfig()` only reads configuration values when its
|
|
222
|
+
* > `ConfigContext` is registered with the runner via the `contexts` option:
|
|
223
|
+
* >
|
|
224
|
+
* > ```typescript
|
|
225
|
+
* > run(parser, { contexts: [configContext], contextOptions: { load } });
|
|
226
|
+
* > ```
|
|
227
|
+
* >
|
|
228
|
+
* > Omitting `contexts` causes `bindConfig()` to skip the config lookup and
|
|
229
|
+
* > fall through to the default or an error. When other contexts are
|
|
230
|
+
* > registered but this config context is not, the error explicitly names the
|
|
231
|
+
* > `contexts` option to aid diagnosis.
|
|
232
|
+
*
|
|
213
233
|
* @template M The parser mode (sync or async).
|
|
214
234
|
* @template TValue The parser value type.
|
|
215
235
|
* @template TState The parser state type.
|
|
@@ -396,6 +416,7 @@ function bindConfig(parser, options) {
|
|
|
396
416
|
function getConfigOrDefault(state, options, mode, innerParser) {
|
|
397
417
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
398
418
|
const contextId = options.context.id;
|
|
419
|
+
const configContextAbsent = annotations != null && !(contextId in annotations);
|
|
399
420
|
const annotationValue = annotations?.[contextId];
|
|
400
421
|
const configData = annotationValue?.data;
|
|
401
422
|
const configMeta = annotationValue?.meta;
|
|
@@ -406,6 +427,10 @@ function getConfigOrDefault(state, options, mode, innerParser) {
|
|
|
406
427
|
} else configValue = configData[options.key];
|
|
407
428
|
if (configValue !== void 0) return validateFallbackValue(mode, innerParser, configValue);
|
|
408
429
|
if (options.default !== void 0) return validateFallbackValue(mode, innerParser, options.default);
|
|
430
|
+
if (configContextAbsent) return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
431
|
+
success: false,
|
|
432
|
+
error: __optique_core_message.message`Configuration value could not be read: the config context was not passed to run()'s contexts option.`
|
|
433
|
+
});
|
|
409
434
|
return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
410
435
|
success: false,
|
|
411
436
|
error: __optique_core_message.message`Missing required configuration value.`
|
package/dist/index.d.cts
CHANGED
|
@@ -124,6 +124,14 @@ interface ConfigContext<T, TConfigMeta = ConfigMeta> extends SourceContext<Confi
|
|
|
124
124
|
/**
|
|
125
125
|
* Creates a config context for use with Optique parsers.
|
|
126
126
|
*
|
|
127
|
+
* Pass the returned context to `run()`'s `contexts` option so that
|
|
128
|
+
* `bindConfig()` can read configuration values during parsing:
|
|
129
|
+
*
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const configContext = createConfigContext({ schema });
|
|
132
|
+
* run(parser, { contexts: [configContext], contextOptions: { load } });
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
127
135
|
* The config context implements the `SourceContext` interface and can be used
|
|
128
136
|
* with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
|
|
129
137
|
* *@optique/run* to provide configuration file support. Each runner call
|
|
@@ -194,6 +202,18 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
|
|
|
194
202
|
* 3. Default value (if specified)
|
|
195
203
|
* 4. Error (if none of the above)
|
|
196
204
|
*
|
|
205
|
+
* > **Important:** `bindConfig()` only reads configuration values when its
|
|
206
|
+
* > `ConfigContext` is registered with the runner via the `contexts` option:
|
|
207
|
+
* >
|
|
208
|
+
* > ```typescript
|
|
209
|
+
* > run(parser, { contexts: [configContext], contextOptions: { load } });
|
|
210
|
+
* > ```
|
|
211
|
+
* >
|
|
212
|
+
* > Omitting `contexts` causes `bindConfig()` to skip the config lookup and
|
|
213
|
+
* > fall through to the default or an error. When other contexts are
|
|
214
|
+
* > registered but this config context is not, the error explicitly names the
|
|
215
|
+
* > `contexts` option to aid diagnosis.
|
|
216
|
+
*
|
|
197
217
|
* @template M The parser mode (sync or async).
|
|
198
218
|
* @template TValue The parser value type.
|
|
199
219
|
* @template TState The parser state type.
|
package/dist/index.d.ts
CHANGED
|
@@ -124,6 +124,14 @@ interface ConfigContext<T, TConfigMeta = ConfigMeta> extends SourceContext<Confi
|
|
|
124
124
|
/**
|
|
125
125
|
* Creates a config context for use with Optique parsers.
|
|
126
126
|
*
|
|
127
|
+
* Pass the returned context to `run()`'s `contexts` option so that
|
|
128
|
+
* `bindConfig()` can read configuration values during parsing:
|
|
129
|
+
*
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const configContext = createConfigContext({ schema });
|
|
132
|
+
* run(parser, { contexts: [configContext], contextOptions: { load } });
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
127
135
|
* The config context implements the `SourceContext` interface and can be used
|
|
128
136
|
* with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
|
|
129
137
|
* *@optique/run* to provide configuration file support. Each runner call
|
|
@@ -194,6 +202,18 @@ interface BindConfigOptions<T, TValue, TConfigMeta = ConfigMeta> {
|
|
|
194
202
|
* 3. Default value (if specified)
|
|
195
203
|
* 4. Error (if none of the above)
|
|
196
204
|
*
|
|
205
|
+
* > **Important:** `bindConfig()` only reads configuration values when its
|
|
206
|
+
* > `ConfigContext` is registered with the runner via the `contexts` option:
|
|
207
|
+
* >
|
|
208
|
+
* > ```typescript
|
|
209
|
+
* > run(parser, { contexts: [configContext], contextOptions: { load } });
|
|
210
|
+
* > ```
|
|
211
|
+
* >
|
|
212
|
+
* > Omitting `contexts` causes `bindConfig()` to skip the config lookup and
|
|
213
|
+
* > fall through to the default or an error. When other contexts are
|
|
214
|
+
* > registered but this config context is not, the error explicitly names the
|
|
215
|
+
* > `contexts` option to aid diagnosis.
|
|
216
|
+
*
|
|
197
217
|
* @template M The parser mode (sync or async).
|
|
198
218
|
* @template TValue The parser value type.
|
|
199
219
|
* @template TState The parser state type.
|
package/dist/index.js
CHANGED
|
@@ -64,6 +64,14 @@ function validateWithSchema(schema, rawData) {
|
|
|
64
64
|
/**
|
|
65
65
|
* Creates a config context for use with Optique parsers.
|
|
66
66
|
*
|
|
67
|
+
* Pass the returned context to `run()`'s `contexts` option so that
|
|
68
|
+
* `bindConfig()` can read configuration values during parsing:
|
|
69
|
+
*
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const configContext = createConfigContext({ schema });
|
|
72
|
+
* run(parser, { contexts: [configContext], contextOptions: { load } });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
67
75
|
* The config context implements the `SourceContext` interface and can be used
|
|
68
76
|
* with `runWith()` from *@optique/core* or `run()`/`runAsync()` from
|
|
69
77
|
* *@optique/run* to provide configuration file support. Each runner call
|
|
@@ -187,6 +195,18 @@ function createConfigContext(options) {
|
|
|
187
195
|
* 3. Default value (if specified)
|
|
188
196
|
* 4. Error (if none of the above)
|
|
189
197
|
*
|
|
198
|
+
* > **Important:** `bindConfig()` only reads configuration values when its
|
|
199
|
+
* > `ConfigContext` is registered with the runner via the `contexts` option:
|
|
200
|
+
* >
|
|
201
|
+
* > ```typescript
|
|
202
|
+
* > run(parser, { contexts: [configContext], contextOptions: { load } });
|
|
203
|
+
* > ```
|
|
204
|
+
* >
|
|
205
|
+
* > Omitting `contexts` causes `bindConfig()` to skip the config lookup and
|
|
206
|
+
* > fall through to the default or an error. When other contexts are
|
|
207
|
+
* > registered but this config context is not, the error explicitly names the
|
|
208
|
+
* > `contexts` option to aid diagnosis.
|
|
209
|
+
*
|
|
190
210
|
* @template M The parser mode (sync or async).
|
|
191
211
|
* @template TValue The parser value type.
|
|
192
212
|
* @template TState The parser state type.
|
|
@@ -373,6 +393,7 @@ function bindConfig(parser, options) {
|
|
|
373
393
|
function getConfigOrDefault(state, options, mode, innerParser) {
|
|
374
394
|
const annotations = getAnnotations(state);
|
|
375
395
|
const contextId = options.context.id;
|
|
396
|
+
const configContextAbsent = annotations != null && !(contextId in annotations);
|
|
376
397
|
const annotationValue = annotations?.[contextId];
|
|
377
398
|
const configData = annotationValue?.data;
|
|
378
399
|
const configMeta = annotationValue?.meta;
|
|
@@ -383,6 +404,10 @@ function getConfigOrDefault(state, options, mode, innerParser) {
|
|
|
383
404
|
} else configValue = configData[options.key];
|
|
384
405
|
if (configValue !== void 0) return validateFallbackValue(mode, innerParser, configValue);
|
|
385
406
|
if (options.default !== void 0) return validateFallbackValue(mode, innerParser, options.default);
|
|
407
|
+
if (configContextAbsent) return wrapForMode(mode, {
|
|
408
|
+
success: false,
|
|
409
|
+
error: message`Configuration value could not be read: the config context was not passed to run()'s contexts option.`
|
|
410
|
+
});
|
|
386
411
|
return wrapForMode(mode, {
|
|
387
412
|
success: false,
|
|
388
413
|
error: message`Missing required configuration value.`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/config",
|
|
3
|
-
"version": "1.1.0-dev.
|
|
3
|
+
"version": "1.1.0-dev.2053",
|
|
4
4
|
"description": "Configuration file support for Optique with Standard Schema validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@standard-schema/spec": "^1.1.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@optique/core": "1.1.0-dev.
|
|
62
|
+
"@optique/core": "1.1.0-dev.2053+ed892f45"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@standard-schema/spec": "^1.1.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"tsdown": "^0.13.0",
|
|
69
69
|
"typescript": "^5.8.3",
|
|
70
70
|
"zod": "^3.25.0 || ^4.0.0",
|
|
71
|
-
"@optique/env": "1.1.0-dev.
|
|
71
|
+
"@optique/env": "1.1.0-dev.2053+ed892f45"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "tsdown",
|