@optique/config 1.3.0-dev.2444 → 1.3.0-dev.2452
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 +15 -5
- package/dist/index.js +15 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -266,9 +266,10 @@ function bindConfig(parser, options) {
|
|
|
266
266
|
function isConfigBindState(value) {
|
|
267
267
|
return value != null && typeof value === "object" && configBindStateKey in value;
|
|
268
268
|
}
|
|
269
|
-
function
|
|
269
|
+
function shouldDeferCompletion(state, exec) {
|
|
270
270
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
271
|
-
|
|
271
|
+
if (annotations?.[options.context.id] === phase1ConfigAnnotationMarker) return true;
|
|
272
|
+
return typeof parser.shouldDeferCompletion === "function" && parser.shouldDeferCompletion(getInnerState(state), exec) === true;
|
|
272
273
|
}
|
|
273
274
|
function getInnerState(state) {
|
|
274
275
|
if (!isConfigBindState(state)) return state;
|
|
@@ -362,7 +363,7 @@ function bindConfig(parser, options) {
|
|
|
362
363
|
},
|
|
363
364
|
complete: (state, exec) => {
|
|
364
365
|
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState, exec);
|
|
365
|
-
return getConfigOrDefault(state, options, parser.mode, parser);
|
|
366
|
+
return getConfigOrDefault(state, options, parser.mode, parser, getInnerState(state), exec);
|
|
366
367
|
},
|
|
367
368
|
suggest: (context, prefix) => {
|
|
368
369
|
const innerState = getInnerState(context.state);
|
|
@@ -372,7 +373,7 @@ function bindConfig(parser, options) {
|
|
|
372
373
|
} : context;
|
|
373
374
|
return parser.suggest(innerContext, prefix);
|
|
374
375
|
},
|
|
375
|
-
shouldDeferCompletion
|
|
376
|
+
shouldDeferCompletion,
|
|
376
377
|
getDocFragments(state, upperDefaultValue) {
|
|
377
378
|
const defaultValue = upperDefaultValue ?? options.default;
|
|
378
379
|
return parser.getDocFragments(state, defaultValue);
|
|
@@ -446,11 +447,14 @@ function bindConfig(parser, options) {
|
|
|
446
447
|
* config-sourced value or the configured `default`
|
|
447
448
|
* against the inner CLI parser's constraints (see
|
|
448
449
|
* issue #414).
|
|
450
|
+
* @throws {Error} Propagates errors thrown by `innerParser.complete()` when
|
|
451
|
+
* falling through to a deferred inner parser.
|
|
449
452
|
*/
|
|
450
|
-
function getConfigOrDefault(state, options, mode, innerParser) {
|
|
453
|
+
function getConfigOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
451
454
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
452
455
|
const contextId = options.context.id;
|
|
453
456
|
const configContextAbsent = annotations != null && !(contextId in annotations);
|
|
457
|
+
const configPending = annotations?.[contextId] === phase1ConfigAnnotationMarker;
|
|
454
458
|
const annotationValue = annotations?.[contextId];
|
|
455
459
|
const configData = annotationValue?.data;
|
|
456
460
|
const configMeta = annotationValue?.meta;
|
|
@@ -461,10 +465,16 @@ function getConfigOrDefault(state, options, mode, innerParser) {
|
|
|
461
465
|
} else configValue = configData[options.key];
|
|
462
466
|
if (configValue !== void 0) return validateFallbackValue(mode, innerParser, configValue);
|
|
463
467
|
if (options.default !== void 0) return validateFallbackValue(mode, innerParser, options.default);
|
|
468
|
+
if (configPending && innerParser != null && typeof innerParser.shouldDeferCompletion === "function" && innerParser.shouldDeferCompletion(innerState ?? innerParser.initialState, exec) === true) return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
469
|
+
success: true,
|
|
470
|
+
value: void 0,
|
|
471
|
+
deferred: true
|
|
472
|
+
});
|
|
464
473
|
if (configContextAbsent) return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
465
474
|
success: false,
|
|
466
475
|
error: __optique_core_message.message`Configuration value could not be read: the config context was not passed to run()'s contexts option.`
|
|
467
476
|
});
|
|
477
|
+
if (!configPending && annotations != null && contextId in annotations && innerParser != null && typeof innerParser.shouldDeferCompletion === "function" && innerParser.shouldDeferCompletion(innerState ?? innerParser.initialState, exec) === true) return innerParser.complete(innerState ?? innerParser.initialState, exec);
|
|
468
478
|
return (0, __optique_core_extension.wrapForMode)(mode, {
|
|
469
479
|
success: false,
|
|
470
480
|
error: __optique_core_message.message`Missing required configuration value.`
|
package/dist/index.js
CHANGED
|
@@ -243,9 +243,10 @@ function bindConfig(parser, options) {
|
|
|
243
243
|
function isConfigBindState(value) {
|
|
244
244
|
return value != null && typeof value === "object" && configBindStateKey in value;
|
|
245
245
|
}
|
|
246
|
-
function
|
|
246
|
+
function shouldDeferCompletion(state, exec) {
|
|
247
247
|
const annotations = getAnnotations(state);
|
|
248
|
-
|
|
248
|
+
if (annotations?.[options.context.id] === phase1ConfigAnnotationMarker) return true;
|
|
249
|
+
return typeof parser.shouldDeferCompletion === "function" && parser.shouldDeferCompletion(getInnerState(state), exec) === true;
|
|
249
250
|
}
|
|
250
251
|
function getInnerState(state) {
|
|
251
252
|
if (!isConfigBindState(state)) return state;
|
|
@@ -339,7 +340,7 @@ function bindConfig(parser, options) {
|
|
|
339
340
|
},
|
|
340
341
|
complete: (state, exec) => {
|
|
341
342
|
if (isConfigBindState(state) && state.hasCliValue) return parser.complete(state.cliState, exec);
|
|
342
|
-
return getConfigOrDefault(state, options, parser.mode, parser);
|
|
343
|
+
return getConfigOrDefault(state, options, parser.mode, parser, getInnerState(state), exec);
|
|
343
344
|
},
|
|
344
345
|
suggest: (context, prefix) => {
|
|
345
346
|
const innerState = getInnerState(context.state);
|
|
@@ -349,7 +350,7 @@ function bindConfig(parser, options) {
|
|
|
349
350
|
} : context;
|
|
350
351
|
return parser.suggest(innerContext, prefix);
|
|
351
352
|
},
|
|
352
|
-
shouldDeferCompletion
|
|
353
|
+
shouldDeferCompletion,
|
|
353
354
|
getDocFragments(state, upperDefaultValue) {
|
|
354
355
|
const defaultValue = upperDefaultValue ?? options.default;
|
|
355
356
|
return parser.getDocFragments(state, defaultValue);
|
|
@@ -423,11 +424,14 @@ function bindConfig(parser, options) {
|
|
|
423
424
|
* config-sourced value or the configured `default`
|
|
424
425
|
* against the inner CLI parser's constraints (see
|
|
425
426
|
* issue #414).
|
|
427
|
+
* @throws {Error} Propagates errors thrown by `innerParser.complete()` when
|
|
428
|
+
* falling through to a deferred inner parser.
|
|
426
429
|
*/
|
|
427
|
-
function getConfigOrDefault(state, options, mode, innerParser) {
|
|
430
|
+
function getConfigOrDefault(state, options, mode, innerParser, innerState, exec) {
|
|
428
431
|
const annotations = getAnnotations(state);
|
|
429
432
|
const contextId = options.context.id;
|
|
430
433
|
const configContextAbsent = annotations != null && !(contextId in annotations);
|
|
434
|
+
const configPending = annotations?.[contextId] === phase1ConfigAnnotationMarker;
|
|
431
435
|
const annotationValue = annotations?.[contextId];
|
|
432
436
|
const configData = annotationValue?.data;
|
|
433
437
|
const configMeta = annotationValue?.meta;
|
|
@@ -438,10 +442,16 @@ function getConfigOrDefault(state, options, mode, innerParser) {
|
|
|
438
442
|
} else configValue = configData[options.key];
|
|
439
443
|
if (configValue !== void 0) return validateFallbackValue(mode, innerParser, configValue);
|
|
440
444
|
if (options.default !== void 0) return validateFallbackValue(mode, innerParser, options.default);
|
|
445
|
+
if (configPending && innerParser != null && typeof innerParser.shouldDeferCompletion === "function" && innerParser.shouldDeferCompletion(innerState ?? innerParser.initialState, exec) === true) return wrapForMode(mode, {
|
|
446
|
+
success: true,
|
|
447
|
+
value: void 0,
|
|
448
|
+
deferred: true
|
|
449
|
+
});
|
|
441
450
|
if (configContextAbsent) return wrapForMode(mode, {
|
|
442
451
|
success: false,
|
|
443
452
|
error: message`Configuration value could not be read: the config context was not passed to run()'s contexts option.`
|
|
444
453
|
});
|
|
454
|
+
if (!configPending && annotations != null && contextId in annotations && innerParser != null && typeof innerParser.shouldDeferCompletion === "function" && innerParser.shouldDeferCompletion(innerState ?? innerParser.initialState, exec) === true) return innerParser.complete(innerState ?? innerParser.initialState, exec);
|
|
445
455
|
return wrapForMode(mode, {
|
|
446
456
|
success: false,
|
|
447
457
|
error: message`Missing required configuration value.`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/config",
|
|
3
|
-
"version": "1.3.0-dev.
|
|
3
|
+
"version": "1.3.0-dev.2452",
|
|
4
4
|
"description": "Configuration file support for Optique with Standard Schema validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"@standard-schema/spec": "^1.1.0"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@optique/core": "1.3.0-dev.
|
|
68
|
+
"@optique/core": "1.3.0-dev.2452+0b677f5c"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@optique/env": "1.3.0-dev.
|
|
71
|
+
"@optique/env": "1.3.0-dev.2452+0b677f5c",
|
|
72
72
|
"@standard-schema/spec": "^1.1.0",
|
|
73
73
|
"@types/node": "^24.0.0",
|
|
74
74
|
"fast-check": "^4.7.0",
|