@optique/core 1.0.0-dev.1251 → 1.0.0-dev.1252
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/constructs.cjs +68 -3
- package/dist/constructs.js +69 -4
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -8,6 +8,21 @@ const require_usage_internals = require('./usage-internals.cjs');
|
|
|
8
8
|
|
|
9
9
|
//#region src/constructs.ts
|
|
10
10
|
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
11
|
+
/**
|
|
12
|
+
* Returns the field state with parent annotations inherited, respecting
|
|
13
|
+
* the parser's {@link inheritParentAnnotationsKey} flag. This is the
|
|
14
|
+
* same logic as {@link createFieldStateGetter} inside `object()` but
|
|
15
|
+
* without the per-state cache, for use in module-level helpers like
|
|
16
|
+
* {@link pendingDependencyDefaults}.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
function getAnnotatedFieldState(parentState, field, parser) {
|
|
20
|
+
const sourceState = parentState != null && typeof parentState === "object" && field in parentState ? parentState[field] : parser.initialState;
|
|
21
|
+
if (sourceState == null || typeof sourceState !== "object") return sourceState;
|
|
22
|
+
const annotations = require_annotations.getAnnotations(parentState);
|
|
23
|
+
if (annotations === void 0 || require_annotations.getAnnotations(sourceState) === annotations) return sourceState;
|
|
24
|
+
return Reflect.get(parser, inheritParentAnnotationsKey) === true ? require_annotations.injectAnnotations(sourceState, annotations) : require_annotations.inheritAnnotations(parentState, sourceState);
|
|
25
|
+
}
|
|
11
26
|
function createUnexpectedInputErrorWithScopedSuggestions(baseError, invalidInput, parsers, customFormatter) {
|
|
12
27
|
const options = /* @__PURE__ */ new Set();
|
|
13
28
|
const commands = /* @__PURE__ */ new Set();
|
|
@@ -693,7 +708,13 @@ function registerCompletedDependency(completed, registry) {
|
|
|
693
708
|
function* pendingDependencyDefaults(context, parserPairs) {
|
|
694
709
|
for (const [field, fieldParser] of parserPairs) {
|
|
695
710
|
const fieldState = context.state != null && typeof context.state === "object" && field in context.state ? context.state[field] : void 0;
|
|
696
|
-
if (fieldState != null)
|
|
711
|
+
if (fieldState != null) {
|
|
712
|
+
if (!Array.isArray(fieldState) && !require_dependency.isDependencySourceState(fieldState) && (require_dependency.isWrappedDependencySource(fieldParser) || require_dependency.isPendingDependencySourceState(fieldParser.initialState))) yield {
|
|
713
|
+
parser: fieldParser,
|
|
714
|
+
state: getAnnotatedFieldState(context.state, field, fieldParser)
|
|
715
|
+
};
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
697
718
|
if (require_dependency.isPendingDependencySourceState(fieldParser.initialState)) yield {
|
|
698
719
|
parser: fieldParser,
|
|
699
720
|
state: fieldParser.initialState
|
|
@@ -714,7 +735,31 @@ function* pendingDependencyDefaults(context, parserPairs) {
|
|
|
714
735
|
* @internal
|
|
715
736
|
*/
|
|
716
737
|
function completeDependencySourceDefaults(context, parserPairs, registry) {
|
|
717
|
-
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs))
|
|
738
|
+
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs)) {
|
|
739
|
+
const completed = parser.complete(state);
|
|
740
|
+
const depState = wrapAsDependencySourceState(completed, parser);
|
|
741
|
+
if (depState) registerCompletedDependency(depState, registry);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Wraps a completed result as a {@link DependencySourceState} if the parser
|
|
746
|
+
* contains a dependency source and the result is a successful plain Result
|
|
747
|
+
* with a defined value. Returns the existing state if the result is already
|
|
748
|
+
* a DependencySourceState, or `undefined` if no wrapping applies.
|
|
749
|
+
*
|
|
750
|
+
* This helper is shared by both `object()` Phase 1 and the suggest-time
|
|
751
|
+
* pre-completion paths to keep the dep-ID selection and `value !== undefined`
|
|
752
|
+
* rule in one place.
|
|
753
|
+
* @internal
|
|
754
|
+
*/
|
|
755
|
+
function wrapAsDependencySourceState(completed, parser) {
|
|
756
|
+
if (require_dependency.isDependencySourceState(completed)) return completed;
|
|
757
|
+
const hasDep = require_dependency.isWrappedDependencySource(parser) || require_dependency.isPendingDependencySourceState(parser.initialState);
|
|
758
|
+
if (hasDep && typeof completed === "object" && completed !== null && "success" in completed && completed.success && "value" in completed && completed.value !== void 0) {
|
|
759
|
+
const depId = require_dependency.isWrappedDependencySource(parser) ? parser[require_dependency.wrappedDependencySourceMarker][require_dependency.dependencyId] : parser.initialState[require_dependency.dependencyId];
|
|
760
|
+
return require_dependency.createDependencySourceState(completed, depId);
|
|
761
|
+
}
|
|
762
|
+
return void 0;
|
|
718
763
|
}
|
|
719
764
|
/**
|
|
720
765
|
* Async version of {@link completeDependencySourceDefaults} that awaits
|
|
@@ -725,7 +770,11 @@ function completeDependencySourceDefaults(context, parserPairs, registry) {
|
|
|
725
770
|
* @internal
|
|
726
771
|
*/
|
|
727
772
|
async function completeDependencySourceDefaultsAsync(context, parserPairs, registry) {
|
|
728
|
-
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs))
|
|
773
|
+
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs)) {
|
|
774
|
+
const completed = await parser.complete(state);
|
|
775
|
+
const depState = wrapAsDependencySourceState(completed, parser);
|
|
776
|
+
if (depState) registerCompletedDependency(depState, registry);
|
|
777
|
+
}
|
|
729
778
|
}
|
|
730
779
|
/**
|
|
731
780
|
* Recursively collects dependency values from DependencySourceState objects
|
|
@@ -1085,6 +1134,14 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1085
1134
|
preCompletedState[fieldKey] = completed;
|
|
1086
1135
|
preCompletedKeys.add(fieldKey);
|
|
1087
1136
|
} else preCompletedState[fieldKey] = fieldState;
|
|
1137
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !require_dependency.isDependencySourceState(fieldState) && (require_dependency.isWrappedDependencySource(fieldParser) || require_dependency.isPendingDependencySourceState(fieldParser.initialState))) {
|
|
1138
|
+
const annotatedFieldState = getFieldState(field, fieldParser);
|
|
1139
|
+
const completed = fieldParser.complete(annotatedFieldState);
|
|
1140
|
+
const depState = wrapAsDependencySourceState(completed, fieldParser);
|
|
1141
|
+
if (depState) {
|
|
1142
|
+
preCompletedState[fieldKey] = depState;
|
|
1143
|
+
preCompletedKeys.add(fieldKey);
|
|
1144
|
+
} else preCompletedState[fieldKey] = annotatedFieldState;
|
|
1088
1145
|
} else preCompletedState[fieldKey] = getFieldState(field, fieldParser);
|
|
1089
1146
|
}
|
|
1090
1147
|
const resolvedState = resolveDeferredParseStates(preCompletedState);
|
|
@@ -1138,6 +1195,14 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1138
1195
|
preCompletedState[fieldKey] = completed;
|
|
1139
1196
|
preCompletedKeys.add(fieldKey);
|
|
1140
1197
|
} else preCompletedState[fieldKey] = fieldState;
|
|
1198
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !require_dependency.isDependencySourceState(fieldState) && (require_dependency.isWrappedDependencySource(fieldParser) || require_dependency.isPendingDependencySourceState(fieldParser.initialState))) {
|
|
1199
|
+
const annotatedFieldState = getFieldState(field, fieldParser);
|
|
1200
|
+
const completed = await fieldParser.complete(annotatedFieldState);
|
|
1201
|
+
const depState = wrapAsDependencySourceState(completed, fieldParser);
|
|
1202
|
+
if (depState) {
|
|
1203
|
+
preCompletedState[fieldKey] = depState;
|
|
1204
|
+
preCompletedKeys.add(fieldKey);
|
|
1205
|
+
} else preCompletedState[fieldKey] = annotatedFieldState;
|
|
1141
1206
|
} else preCompletedState[fieldKey] = getFieldState(field, fieldParser);
|
|
1142
1207
|
}
|
|
1143
1208
|
const resolvedState = await resolveDeferredParseStatesAsync(preCompletedState);
|
package/dist/constructs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getAnnotations, inheritAnnotations, injectAnnotations } from "./annotations.js";
|
|
2
2
|
import { message, optionName, text, values } from "./message.js";
|
|
3
|
-
import { DependencyRegistry, dependencyId, isDeferredParseState, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, wrappedDependencySourceMarker } from "./dependency.js";
|
|
3
|
+
import { DependencyRegistry, createDependencySourceState, dependencyId, isDeferredParseState, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, wrappedDependencySourceMarker } from "./dependency.js";
|
|
4
4
|
import { dispatchByMode, dispatchIterableByMode } from "./mode-dispatch.js";
|
|
5
5
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames, isDocHidden, mergeHidden } from "./usage.js";
|
|
6
6
|
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, deduplicateSuggestions, findSimilar } from "./suggestion.js";
|
|
@@ -8,6 +8,21 @@ import { collectLeadingCandidates } from "./usage-internals.js";
|
|
|
8
8
|
|
|
9
9
|
//#region src/constructs.ts
|
|
10
10
|
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
11
|
+
/**
|
|
12
|
+
* Returns the field state with parent annotations inherited, respecting
|
|
13
|
+
* the parser's {@link inheritParentAnnotationsKey} flag. This is the
|
|
14
|
+
* same logic as {@link createFieldStateGetter} inside `object()` but
|
|
15
|
+
* without the per-state cache, for use in module-level helpers like
|
|
16
|
+
* {@link pendingDependencyDefaults}.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
function getAnnotatedFieldState(parentState, field, parser) {
|
|
20
|
+
const sourceState = parentState != null && typeof parentState === "object" && field in parentState ? parentState[field] : parser.initialState;
|
|
21
|
+
if (sourceState == null || typeof sourceState !== "object") return sourceState;
|
|
22
|
+
const annotations = getAnnotations(parentState);
|
|
23
|
+
if (annotations === void 0 || getAnnotations(sourceState) === annotations) return sourceState;
|
|
24
|
+
return Reflect.get(parser, inheritParentAnnotationsKey) === true ? injectAnnotations(sourceState, annotations) : inheritAnnotations(parentState, sourceState);
|
|
25
|
+
}
|
|
11
26
|
function createUnexpectedInputErrorWithScopedSuggestions(baseError, invalidInput, parsers, customFormatter) {
|
|
12
27
|
const options = /* @__PURE__ */ new Set();
|
|
13
28
|
const commands = /* @__PURE__ */ new Set();
|
|
@@ -693,7 +708,13 @@ function registerCompletedDependency(completed, registry) {
|
|
|
693
708
|
function* pendingDependencyDefaults(context, parserPairs) {
|
|
694
709
|
for (const [field, fieldParser] of parserPairs) {
|
|
695
710
|
const fieldState = context.state != null && typeof context.state === "object" && field in context.state ? context.state[field] : void 0;
|
|
696
|
-
if (fieldState != null)
|
|
711
|
+
if (fieldState != null) {
|
|
712
|
+
if (!Array.isArray(fieldState) && !isDependencySourceState(fieldState) && (isWrappedDependencySource(fieldParser) || isPendingDependencySourceState(fieldParser.initialState))) yield {
|
|
713
|
+
parser: fieldParser,
|
|
714
|
+
state: getAnnotatedFieldState(context.state, field, fieldParser)
|
|
715
|
+
};
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
697
718
|
if (isPendingDependencySourceState(fieldParser.initialState)) yield {
|
|
698
719
|
parser: fieldParser,
|
|
699
720
|
state: fieldParser.initialState
|
|
@@ -714,7 +735,31 @@ function* pendingDependencyDefaults(context, parserPairs) {
|
|
|
714
735
|
* @internal
|
|
715
736
|
*/
|
|
716
737
|
function completeDependencySourceDefaults(context, parserPairs, registry) {
|
|
717
|
-
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs))
|
|
738
|
+
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs)) {
|
|
739
|
+
const completed = parser.complete(state);
|
|
740
|
+
const depState = wrapAsDependencySourceState(completed, parser);
|
|
741
|
+
if (depState) registerCompletedDependency(depState, registry);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Wraps a completed result as a {@link DependencySourceState} if the parser
|
|
746
|
+
* contains a dependency source and the result is a successful plain Result
|
|
747
|
+
* with a defined value. Returns the existing state if the result is already
|
|
748
|
+
* a DependencySourceState, or `undefined` if no wrapping applies.
|
|
749
|
+
*
|
|
750
|
+
* This helper is shared by both `object()` Phase 1 and the suggest-time
|
|
751
|
+
* pre-completion paths to keep the dep-ID selection and `value !== undefined`
|
|
752
|
+
* rule in one place.
|
|
753
|
+
* @internal
|
|
754
|
+
*/
|
|
755
|
+
function wrapAsDependencySourceState(completed, parser) {
|
|
756
|
+
if (isDependencySourceState(completed)) return completed;
|
|
757
|
+
const hasDep = isWrappedDependencySource(parser) || isPendingDependencySourceState(parser.initialState);
|
|
758
|
+
if (hasDep && typeof completed === "object" && completed !== null && "success" in completed && completed.success && "value" in completed && completed.value !== void 0) {
|
|
759
|
+
const depId = isWrappedDependencySource(parser) ? parser[wrappedDependencySourceMarker][dependencyId] : parser.initialState[dependencyId];
|
|
760
|
+
return createDependencySourceState(completed, depId);
|
|
761
|
+
}
|
|
762
|
+
return void 0;
|
|
718
763
|
}
|
|
719
764
|
/**
|
|
720
765
|
* Async version of {@link completeDependencySourceDefaults} that awaits
|
|
@@ -725,7 +770,11 @@ function completeDependencySourceDefaults(context, parserPairs, registry) {
|
|
|
725
770
|
* @internal
|
|
726
771
|
*/
|
|
727
772
|
async function completeDependencySourceDefaultsAsync(context, parserPairs, registry) {
|
|
728
|
-
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs))
|
|
773
|
+
for (const { parser, state } of pendingDependencyDefaults(context, parserPairs)) {
|
|
774
|
+
const completed = await parser.complete(state);
|
|
775
|
+
const depState = wrapAsDependencySourceState(completed, parser);
|
|
776
|
+
if (depState) registerCompletedDependency(depState, registry);
|
|
777
|
+
}
|
|
729
778
|
}
|
|
730
779
|
/**
|
|
731
780
|
* Recursively collects dependency values from DependencySourceState objects
|
|
@@ -1085,6 +1134,14 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1085
1134
|
preCompletedState[fieldKey] = completed;
|
|
1086
1135
|
preCompletedKeys.add(fieldKey);
|
|
1087
1136
|
} else preCompletedState[fieldKey] = fieldState;
|
|
1137
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !isDependencySourceState(fieldState) && (isWrappedDependencySource(fieldParser) || isPendingDependencySourceState(fieldParser.initialState))) {
|
|
1138
|
+
const annotatedFieldState = getFieldState(field, fieldParser);
|
|
1139
|
+
const completed = fieldParser.complete(annotatedFieldState);
|
|
1140
|
+
const depState = wrapAsDependencySourceState(completed, fieldParser);
|
|
1141
|
+
if (depState) {
|
|
1142
|
+
preCompletedState[fieldKey] = depState;
|
|
1143
|
+
preCompletedKeys.add(fieldKey);
|
|
1144
|
+
} else preCompletedState[fieldKey] = annotatedFieldState;
|
|
1088
1145
|
} else preCompletedState[fieldKey] = getFieldState(field, fieldParser);
|
|
1089
1146
|
}
|
|
1090
1147
|
const resolvedState = resolveDeferredParseStates(preCompletedState);
|
|
@@ -1138,6 +1195,14 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1138
1195
|
preCompletedState[fieldKey] = completed;
|
|
1139
1196
|
preCompletedKeys.add(fieldKey);
|
|
1140
1197
|
} else preCompletedState[fieldKey] = fieldState;
|
|
1198
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !isDependencySourceState(fieldState) && (isWrappedDependencySource(fieldParser) || isPendingDependencySourceState(fieldParser.initialState))) {
|
|
1199
|
+
const annotatedFieldState = getFieldState(field, fieldParser);
|
|
1200
|
+
const completed = await fieldParser.complete(annotatedFieldState);
|
|
1201
|
+
const depState = wrapAsDependencySourceState(completed, fieldParser);
|
|
1202
|
+
if (depState) {
|
|
1203
|
+
preCompletedState[fieldKey] = depState;
|
|
1204
|
+
preCompletedKeys.add(fieldKey);
|
|
1205
|
+
} else preCompletedState[fieldKey] = annotatedFieldState;
|
|
1141
1206
|
} else preCompletedState[fieldKey] = getFieldState(field, fieldParser);
|
|
1142
1207
|
}
|
|
1143
1208
|
const resolvedState = await resolveDeferredParseStatesAsync(preCompletedState);
|