@optique/core 0.10.0-dev.294 → 0.10.0-dev.295

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.
@@ -848,12 +848,45 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
848
848
  return parseSync(context);
849
849
  },
850
850
  complete(state) {
851
- const resolvedState = isAsync ? state : resolveDeferredParseStates(state);
852
851
  if (!isAsync) {
852
+ const preCompletedState = {};
853
+ for (const field of parserKeys) {
854
+ const fieldKey = field;
855
+ const fieldState = state[fieldKey];
856
+ const fieldParser = parsers[field];
857
+ if (Array.isArray(fieldState) && fieldState.length === 1 && require_dependency.isPendingDependencySourceState(fieldState[0])) {
858
+ const completed = fieldParser.complete(fieldState);
859
+ preCompletedState[fieldKey] = completed;
860
+ } else if (fieldState === void 0 && require_dependency.isPendingDependencySourceState(fieldParser.initialState)) {
861
+ const completed = fieldParser.complete([fieldParser.initialState]);
862
+ preCompletedState[fieldKey] = completed;
863
+ } else if (fieldState === void 0 && require_dependency.isWrappedDependencySource(fieldParser)) {
864
+ const pendingState = fieldParser[require_dependency.WrappedDependencySourceMarker];
865
+ const completed = fieldParser.complete([pendingState]);
866
+ preCompletedState[fieldKey] = completed;
867
+ } else preCompletedState[fieldKey] = fieldState;
868
+ }
869
+ const resolvedState = resolveDeferredParseStates(preCompletedState);
853
870
  const result = {};
854
871
  for (const field of parserKeys) {
855
- const valueResult = parsers[field].complete(resolvedState[field]);
856
- if (valueResult.success) result[field] = valueResult.value;
872
+ const fieldKey = field;
873
+ const fieldResolvedState = resolvedState[fieldKey];
874
+ const fieldParser = parsers[field];
875
+ const originalFieldState = state[fieldKey];
876
+ const wasPreCompletedCase1 = Array.isArray(originalFieldState) && originalFieldState.length === 1 && require_dependency.isPendingDependencySourceState(originalFieldState[0]);
877
+ const wasPreCompletedCase2 = originalFieldState === void 0 && require_dependency.isPendingDependencySourceState(fieldParser.initialState);
878
+ const wasPreCompletedCase3 = originalFieldState === void 0 && require_dependency.isWrappedDependencySource(fieldParser);
879
+ if (require_dependency.isDependencySourceState(fieldResolvedState) && (wasPreCompletedCase1 || wasPreCompletedCase2 || wasPreCompletedCase3)) {
880
+ const depResult = fieldResolvedState.result;
881
+ if (depResult.success) result[fieldKey] = depResult.value;
882
+ else return {
883
+ success: false,
884
+ error: depResult.error
885
+ };
886
+ continue;
887
+ }
888
+ const valueResult = fieldParser.complete(fieldResolvedState);
889
+ if (valueResult.success) result[fieldKey] = valueResult.value;
857
890
  else return {
858
891
  success: false,
859
892
  error: valueResult.error
@@ -865,11 +898,44 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
865
898
  };
866
899
  }
867
900
  return (async () => {
868
- const resolvedState$1 = await resolveDeferredParseStatesAsync(state);
901
+ const preCompletedState = {};
902
+ for (const field of parserKeys) {
903
+ const fieldKey = field;
904
+ const fieldState = state[fieldKey];
905
+ const fieldParser = parsers[field];
906
+ if (Array.isArray(fieldState) && fieldState.length === 1 && require_dependency.isPendingDependencySourceState(fieldState[0])) {
907
+ const completed = await fieldParser.complete(fieldState);
908
+ preCompletedState[fieldKey] = completed;
909
+ } else if (fieldState === void 0 && require_dependency.isPendingDependencySourceState(fieldParser.initialState)) {
910
+ const completed = await fieldParser.complete([fieldParser.initialState]);
911
+ preCompletedState[fieldKey] = completed;
912
+ } else if (fieldState === void 0 && require_dependency.isWrappedDependencySource(fieldParser)) {
913
+ const pendingState = fieldParser[require_dependency.WrappedDependencySourceMarker];
914
+ const completed = await fieldParser.complete([pendingState]);
915
+ preCompletedState[fieldKey] = completed;
916
+ } else preCompletedState[fieldKey] = fieldState;
917
+ }
918
+ const resolvedState = await resolveDeferredParseStatesAsync(preCompletedState);
869
919
  const result = {};
870
920
  for (const field of parserKeys) {
871
- const valueResult = await parsers[field].complete(resolvedState$1[field]);
872
- if (valueResult.success) result[field] = valueResult.value;
921
+ const fieldKey = field;
922
+ const fieldResolvedState = resolvedState[fieldKey];
923
+ const fieldParser = parsers[field];
924
+ const originalFieldState = state[fieldKey];
925
+ const wasPreCompletedCase1 = Array.isArray(originalFieldState) && originalFieldState.length === 1 && require_dependency.isPendingDependencySourceState(originalFieldState[0]);
926
+ const wasPreCompletedCase2 = originalFieldState === void 0 && require_dependency.isPendingDependencySourceState(fieldParser.initialState);
927
+ const wasPreCompletedCase3 = originalFieldState === void 0 && require_dependency.isWrappedDependencySource(fieldParser);
928
+ if (require_dependency.isDependencySourceState(fieldResolvedState) && (wasPreCompletedCase1 || wasPreCompletedCase2 || wasPreCompletedCase3)) {
929
+ const depResult = fieldResolvedState.result;
930
+ if (depResult.success) result[fieldKey] = depResult.value;
931
+ else return {
932
+ success: false,
933
+ error: depResult.error
934
+ };
935
+ continue;
936
+ }
937
+ const valueResult = await fieldParser.complete(fieldResolvedState);
938
+ if (valueResult.success) result[fieldKey] = valueResult.value;
873
939
  else return {
874
940
  success: false,
875
941
  error: valueResult.error
@@ -1576,11 +1642,14 @@ function concat(...parsers) {
1576
1642
  };
1577
1643
  };
1578
1644
  const completeSync = (state) => {
1579
- const results = [];
1580
1645
  const stateArray = state;
1646
+ const combinedState = {};
1647
+ for (let i = 0; i < stateArray.length; i++) combinedState[i] = stateArray[i];
1648
+ const resolvedCombinedState = resolveDeferredParseStates(combinedState);
1649
+ const results = [];
1581
1650
  for (let i = 0; i < syncParsers.length; i++) {
1582
1651
  const parser = syncParsers[i];
1583
- const parserState = stateArray[i];
1652
+ const parserState = resolvedCombinedState[i];
1584
1653
  const result = parser.complete(parserState);
1585
1654
  if (!result.success) return result;
1586
1655
  if (Array.isArray(result.value)) results.push(...result.value);
@@ -1592,11 +1661,14 @@ function concat(...parsers) {
1592
1661
  };
1593
1662
  };
1594
1663
  const completeAsync = async (state) => {
1595
- const results = [];
1596
1664
  const stateArray = state;
1665
+ const combinedState = {};
1666
+ for (let i = 0; i < stateArray.length; i++) combinedState[i] = stateArray[i];
1667
+ const resolvedCombinedState = await resolveDeferredParseStatesAsync(combinedState);
1668
+ const results = [];
1597
1669
  for (let i = 0; i < parsers.length; i++) {
1598
1670
  const parser = parsers[i];
1599
- const parserState = stateArray[i];
1671
+ const parserState = resolvedCombinedState[i];
1600
1672
  const result = await parser.complete(parserState);
1601
1673
  if (!result.success) return result;
1602
1674
  if (Array.isArray(result.value)) results.push(...result.value);
@@ -1,5 +1,5 @@
1
1
  import { message, optionName, values } from "./message.js";
2
- import { DependencyId, DependencyRegistry, ParseWithDependency, isDeferredParseState, isDependencySourceState } from "./dependency.js";
2
+ import { DependencyId, DependencyRegistry, ParseWithDependency, WrappedDependencySourceMarker, isDeferredParseState, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource } from "./dependency.js";
3
3
  import { extractArgumentMetavars, extractCommandNames, extractOptionNames } from "./usage.js";
4
4
  import { createErrorWithSuggestions, deduplicateSuggestions } from "./suggestion.js";
5
5
 
@@ -848,12 +848,45 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
848
848
  return parseSync(context);
849
849
  },
850
850
  complete(state) {
851
- const resolvedState = isAsync ? state : resolveDeferredParseStates(state);
852
851
  if (!isAsync) {
852
+ const preCompletedState = {};
853
+ for (const field of parserKeys) {
854
+ const fieldKey = field;
855
+ const fieldState = state[fieldKey];
856
+ const fieldParser = parsers[field];
857
+ if (Array.isArray(fieldState) && fieldState.length === 1 && isPendingDependencySourceState(fieldState[0])) {
858
+ const completed = fieldParser.complete(fieldState);
859
+ preCompletedState[fieldKey] = completed;
860
+ } else if (fieldState === void 0 && isPendingDependencySourceState(fieldParser.initialState)) {
861
+ const completed = fieldParser.complete([fieldParser.initialState]);
862
+ preCompletedState[fieldKey] = completed;
863
+ } else if (fieldState === void 0 && isWrappedDependencySource(fieldParser)) {
864
+ const pendingState = fieldParser[WrappedDependencySourceMarker];
865
+ const completed = fieldParser.complete([pendingState]);
866
+ preCompletedState[fieldKey] = completed;
867
+ } else preCompletedState[fieldKey] = fieldState;
868
+ }
869
+ const resolvedState = resolveDeferredParseStates(preCompletedState);
853
870
  const result = {};
854
871
  for (const field of parserKeys) {
855
- const valueResult = parsers[field].complete(resolvedState[field]);
856
- if (valueResult.success) result[field] = valueResult.value;
872
+ const fieldKey = field;
873
+ const fieldResolvedState = resolvedState[fieldKey];
874
+ const fieldParser = parsers[field];
875
+ const originalFieldState = state[fieldKey];
876
+ const wasPreCompletedCase1 = Array.isArray(originalFieldState) && originalFieldState.length === 1 && isPendingDependencySourceState(originalFieldState[0]);
877
+ const wasPreCompletedCase2 = originalFieldState === void 0 && isPendingDependencySourceState(fieldParser.initialState);
878
+ const wasPreCompletedCase3 = originalFieldState === void 0 && isWrappedDependencySource(fieldParser);
879
+ if (isDependencySourceState(fieldResolvedState) && (wasPreCompletedCase1 || wasPreCompletedCase2 || wasPreCompletedCase3)) {
880
+ const depResult = fieldResolvedState.result;
881
+ if (depResult.success) result[fieldKey] = depResult.value;
882
+ else return {
883
+ success: false,
884
+ error: depResult.error
885
+ };
886
+ continue;
887
+ }
888
+ const valueResult = fieldParser.complete(fieldResolvedState);
889
+ if (valueResult.success) result[fieldKey] = valueResult.value;
857
890
  else return {
858
891
  success: false,
859
892
  error: valueResult.error
@@ -865,11 +898,44 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
865
898
  };
866
899
  }
867
900
  return (async () => {
868
- const resolvedState$1 = await resolveDeferredParseStatesAsync(state);
901
+ const preCompletedState = {};
902
+ for (const field of parserKeys) {
903
+ const fieldKey = field;
904
+ const fieldState = state[fieldKey];
905
+ const fieldParser = parsers[field];
906
+ if (Array.isArray(fieldState) && fieldState.length === 1 && isPendingDependencySourceState(fieldState[0])) {
907
+ const completed = await fieldParser.complete(fieldState);
908
+ preCompletedState[fieldKey] = completed;
909
+ } else if (fieldState === void 0 && isPendingDependencySourceState(fieldParser.initialState)) {
910
+ const completed = await fieldParser.complete([fieldParser.initialState]);
911
+ preCompletedState[fieldKey] = completed;
912
+ } else if (fieldState === void 0 && isWrappedDependencySource(fieldParser)) {
913
+ const pendingState = fieldParser[WrappedDependencySourceMarker];
914
+ const completed = await fieldParser.complete([pendingState]);
915
+ preCompletedState[fieldKey] = completed;
916
+ } else preCompletedState[fieldKey] = fieldState;
917
+ }
918
+ const resolvedState = await resolveDeferredParseStatesAsync(preCompletedState);
869
919
  const result = {};
870
920
  for (const field of parserKeys) {
871
- const valueResult = await parsers[field].complete(resolvedState$1[field]);
872
- if (valueResult.success) result[field] = valueResult.value;
921
+ const fieldKey = field;
922
+ const fieldResolvedState = resolvedState[fieldKey];
923
+ const fieldParser = parsers[field];
924
+ const originalFieldState = state[fieldKey];
925
+ const wasPreCompletedCase1 = Array.isArray(originalFieldState) && originalFieldState.length === 1 && isPendingDependencySourceState(originalFieldState[0]);
926
+ const wasPreCompletedCase2 = originalFieldState === void 0 && isPendingDependencySourceState(fieldParser.initialState);
927
+ const wasPreCompletedCase3 = originalFieldState === void 0 && isWrappedDependencySource(fieldParser);
928
+ if (isDependencySourceState(fieldResolvedState) && (wasPreCompletedCase1 || wasPreCompletedCase2 || wasPreCompletedCase3)) {
929
+ const depResult = fieldResolvedState.result;
930
+ if (depResult.success) result[fieldKey] = depResult.value;
931
+ else return {
932
+ success: false,
933
+ error: depResult.error
934
+ };
935
+ continue;
936
+ }
937
+ const valueResult = await fieldParser.complete(fieldResolvedState);
938
+ if (valueResult.success) result[fieldKey] = valueResult.value;
873
939
  else return {
874
940
  success: false,
875
941
  error: valueResult.error
@@ -1576,11 +1642,14 @@ function concat(...parsers) {
1576
1642
  };
1577
1643
  };
1578
1644
  const completeSync = (state) => {
1579
- const results = [];
1580
1645
  const stateArray = state;
1646
+ const combinedState = {};
1647
+ for (let i = 0; i < stateArray.length; i++) combinedState[i] = stateArray[i];
1648
+ const resolvedCombinedState = resolveDeferredParseStates(combinedState);
1649
+ const results = [];
1581
1650
  for (let i = 0; i < syncParsers.length; i++) {
1582
1651
  const parser = syncParsers[i];
1583
- const parserState = stateArray[i];
1652
+ const parserState = resolvedCombinedState[i];
1584
1653
  const result = parser.complete(parserState);
1585
1654
  if (!result.success) return result;
1586
1655
  if (Array.isArray(result.value)) results.push(...result.value);
@@ -1592,11 +1661,14 @@ function concat(...parsers) {
1592
1661
  };
1593
1662
  };
1594
1663
  const completeAsync = async (state) => {
1595
- const results = [];
1596
1664
  const stateArray = state;
1665
+ const combinedState = {};
1666
+ for (let i = 0; i < stateArray.length; i++) combinedState[i] = stateArray[i];
1667
+ const resolvedCombinedState = await resolveDeferredParseStatesAsync(combinedState);
1668
+ const results = [];
1597
1669
  for (let i = 0; i < parsers.length; i++) {
1598
1670
  const parser = parsers[i];
1599
- const parserState = stateArray[i];
1671
+ const parserState = resolvedCombinedState[i];
1600
1672
  const result = await parser.complete(parserState);
1601
1673
  if (!result.success) return result;
1602
1674
  if (Array.isArray(result.value)) results.push(...result.value);
@@ -457,6 +457,51 @@ function createDependencySourceState(result, dependencyId) {
457
457
  };
458
458
  }
459
459
  /**
460
+ * A unique symbol used to identify pending dependency source states.
461
+ * @since 0.10.0
462
+ */
463
+ const PendingDependencySourceStateMarker = Symbol.for("@optique/core/dependency/PendingDependencySourceStateMarker");
464
+ /**
465
+ * Checks if a value is a {@link PendingDependencySourceState}.
466
+ *
467
+ * @param value The value to check.
468
+ * @returns `true` if the value is a pending dependency source state.
469
+ * @since 0.10.0
470
+ */
471
+ function isPendingDependencySourceState(value) {
472
+ return typeof value === "object" && value !== null && PendingDependencySourceStateMarker in value && value[PendingDependencySourceStateMarker] === true;
473
+ }
474
+ /**
475
+ * Creates a pending dependency source state.
476
+ *
477
+ * @param dependencyId The dependency ID.
478
+ * @returns A PendingDependencySourceState object.
479
+ * @since 0.10.0
480
+ */
481
+ function createPendingDependencySourceState(dependencyId) {
482
+ return {
483
+ [PendingDependencySourceStateMarker]: true,
484
+ [DependencyId]: dependencyId
485
+ };
486
+ }
487
+ /**
488
+ * A unique symbol used to identify parsers that wrap a dependency source.
489
+ * This is used by withDefault to indicate it contains an inner parser
490
+ * with a PendingDependencySourceState initialState.
491
+ * @since 0.10.0
492
+ */
493
+ const WrappedDependencySourceMarker = Symbol.for("@optique/core/dependency/WrappedDependencySourceMarker");
494
+ /**
495
+ * Checks if a parser wraps a dependency source (has WrappedDependencySourceMarker).
496
+ *
497
+ * @param parser The parser to check.
498
+ * @returns `true` if the parser wraps a dependency source.
499
+ * @since 0.10.0
500
+ */
501
+ function isWrappedDependencySource(parser) {
502
+ return typeof parser === "object" && parser !== null && WrappedDependencySourceMarker in parser;
503
+ }
504
+ /**
460
505
  * A registry for storing resolved dependency values during parsing.
461
506
  * This is used to pass dependency values from DependencySource options
462
507
  * to DerivedValueParser options.
@@ -530,8 +575,11 @@ exports.DependencySourceMarker = DependencySourceMarker;
530
575
  exports.DependencySourceStateMarker = DependencySourceStateMarker;
531
576
  exports.DerivedValueParserMarker = DerivedValueParserMarker;
532
577
  exports.ParseWithDependency = ParseWithDependency;
578
+ exports.PendingDependencySourceStateMarker = PendingDependencySourceStateMarker;
579
+ exports.WrappedDependencySourceMarker = WrappedDependencySourceMarker;
533
580
  exports.createDeferredParseState = createDeferredParseState;
534
581
  exports.createDependencySourceState = createDependencySourceState;
582
+ exports.createPendingDependencySourceState = createPendingDependencySourceState;
535
583
  exports.dependency = dependency;
536
584
  exports.deriveFrom = deriveFrom;
537
585
  exports.deriveFromAsync = deriveFromAsync;
@@ -540,4 +588,6 @@ exports.formatDependencyError = formatDependencyError;
540
588
  exports.isDeferredParseState = isDeferredParseState;
541
589
  exports.isDependencySource = isDependencySource;
542
590
  exports.isDependencySourceState = isDependencySourceState;
543
- exports.isDerivedValueParser = isDerivedValueParser;
591
+ exports.isDerivedValueParser = isDerivedValueParser;
592
+ exports.isPendingDependencySourceState = isPendingDependencySourceState;
593
+ exports.isWrappedDependencySource = isWrappedDependencySource;
@@ -556,6 +556,62 @@ declare function isDependencySourceState<T>(value: unknown): value is Dependency
556
556
  * @since 0.10.0
557
557
  */
558
558
  declare function createDependencySourceState<T>(result: ValueParserResult<T>, dependencyId: symbol): DependencySourceState<T>;
559
+ /**
560
+ * A unique symbol used to identify pending dependency source states.
561
+ * @since 0.10.0
562
+ */
563
+ declare const PendingDependencySourceStateMarker: unique symbol;
564
+ /**
565
+ * Represents a pending dependency source state.
566
+ * This is used when a dependency source option was not provided, but its
567
+ * dependency ID still needs to be tracked for later resolution with a
568
+ * default value.
569
+ *
570
+ * @since 0.10.0
571
+ */
572
+ interface PendingDependencySourceState {
573
+ /**
574
+ * Marker to identify this as a pending dependency source state.
575
+ */
576
+ readonly [PendingDependencySourceStateMarker]: true;
577
+ /**
578
+ * The dependency ID of the source.
579
+ */
580
+ readonly [DependencyId]: symbol;
581
+ }
582
+ /**
583
+ * Checks if a value is a {@link PendingDependencySourceState}.
584
+ *
585
+ * @param value The value to check.
586
+ * @returns `true` if the value is a pending dependency source state.
587
+ * @since 0.10.0
588
+ */
589
+ declare function isPendingDependencySourceState(value: unknown): value is PendingDependencySourceState;
590
+ /**
591
+ * Creates a pending dependency source state.
592
+ *
593
+ * @param dependencyId The dependency ID.
594
+ * @returns A PendingDependencySourceState object.
595
+ * @since 0.10.0
596
+ */
597
+ declare function createPendingDependencySourceState(dependencyId: symbol): PendingDependencySourceState;
598
+ /**
599
+ * A unique symbol used to identify parsers that wrap a dependency source.
600
+ * This is used by withDefault to indicate it contains an inner parser
601
+ * with a PendingDependencySourceState initialState.
602
+ * @since 0.10.0
603
+ */
604
+ declare const WrappedDependencySourceMarker: unique symbol;
605
+ /**
606
+ * Checks if a parser wraps a dependency source (has WrappedDependencySourceMarker).
607
+ *
608
+ * @param parser The parser to check.
609
+ * @returns `true` if the parser wraps a dependency source.
610
+ * @since 0.10.0
611
+ */
612
+ declare function isWrappedDependencySource(parser: unknown): parser is {
613
+ [WrappedDependencySourceMarker]: PendingDependencySourceState;
614
+ };
559
615
  /**
560
616
  * Represents a resolved dependency value stored during parsing.
561
617
  * @since 0.10.0
@@ -635,4 +691,4 @@ type DependencyError = {
635
691
  */
636
692
  declare function formatDependencyError(error: DependencyError): Message;
637
693
  //#endregion
638
- export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
694
+ export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource };
@@ -556,6 +556,62 @@ declare function isDependencySourceState<T>(value: unknown): value is Dependency
556
556
  * @since 0.10.0
557
557
  */
558
558
  declare function createDependencySourceState<T>(result: ValueParserResult<T>, dependencyId: symbol): DependencySourceState<T>;
559
+ /**
560
+ * A unique symbol used to identify pending dependency source states.
561
+ * @since 0.10.0
562
+ */
563
+ declare const PendingDependencySourceStateMarker: unique symbol;
564
+ /**
565
+ * Represents a pending dependency source state.
566
+ * This is used when a dependency source option was not provided, but its
567
+ * dependency ID still needs to be tracked for later resolution with a
568
+ * default value.
569
+ *
570
+ * @since 0.10.0
571
+ */
572
+ interface PendingDependencySourceState {
573
+ /**
574
+ * Marker to identify this as a pending dependency source state.
575
+ */
576
+ readonly [PendingDependencySourceStateMarker]: true;
577
+ /**
578
+ * The dependency ID of the source.
579
+ */
580
+ readonly [DependencyId]: symbol;
581
+ }
582
+ /**
583
+ * Checks if a value is a {@link PendingDependencySourceState}.
584
+ *
585
+ * @param value The value to check.
586
+ * @returns `true` if the value is a pending dependency source state.
587
+ * @since 0.10.0
588
+ */
589
+ declare function isPendingDependencySourceState(value: unknown): value is PendingDependencySourceState;
590
+ /**
591
+ * Creates a pending dependency source state.
592
+ *
593
+ * @param dependencyId The dependency ID.
594
+ * @returns A PendingDependencySourceState object.
595
+ * @since 0.10.0
596
+ */
597
+ declare function createPendingDependencySourceState(dependencyId: symbol): PendingDependencySourceState;
598
+ /**
599
+ * A unique symbol used to identify parsers that wrap a dependency source.
600
+ * This is used by withDefault to indicate it contains an inner parser
601
+ * with a PendingDependencySourceState initialState.
602
+ * @since 0.10.0
603
+ */
604
+ declare const WrappedDependencySourceMarker: unique symbol;
605
+ /**
606
+ * Checks if a parser wraps a dependency source (has WrappedDependencySourceMarker).
607
+ *
608
+ * @param parser The parser to check.
609
+ * @returns `true` if the parser wraps a dependency source.
610
+ * @since 0.10.0
611
+ */
612
+ declare function isWrappedDependencySource(parser: unknown): parser is {
613
+ [WrappedDependencySourceMarker]: PendingDependencySourceState;
614
+ };
559
615
  /**
560
616
  * Represents a resolved dependency value stored during parsing.
561
617
  * @since 0.10.0
@@ -635,4 +691,4 @@ type DependencyError = {
635
691
  */
636
692
  declare function formatDependencyError(error: DependencyError): Message;
637
693
  //#endregion
638
- export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
694
+ export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource };
@@ -456,6 +456,51 @@ function createDependencySourceState(result, dependencyId) {
456
456
  };
457
457
  }
458
458
  /**
459
+ * A unique symbol used to identify pending dependency source states.
460
+ * @since 0.10.0
461
+ */
462
+ const PendingDependencySourceStateMarker = Symbol.for("@optique/core/dependency/PendingDependencySourceStateMarker");
463
+ /**
464
+ * Checks if a value is a {@link PendingDependencySourceState}.
465
+ *
466
+ * @param value The value to check.
467
+ * @returns `true` if the value is a pending dependency source state.
468
+ * @since 0.10.0
469
+ */
470
+ function isPendingDependencySourceState(value) {
471
+ return typeof value === "object" && value !== null && PendingDependencySourceStateMarker in value && value[PendingDependencySourceStateMarker] === true;
472
+ }
473
+ /**
474
+ * Creates a pending dependency source state.
475
+ *
476
+ * @param dependencyId The dependency ID.
477
+ * @returns A PendingDependencySourceState object.
478
+ * @since 0.10.0
479
+ */
480
+ function createPendingDependencySourceState(dependencyId) {
481
+ return {
482
+ [PendingDependencySourceStateMarker]: true,
483
+ [DependencyId]: dependencyId
484
+ };
485
+ }
486
+ /**
487
+ * A unique symbol used to identify parsers that wrap a dependency source.
488
+ * This is used by withDefault to indicate it contains an inner parser
489
+ * with a PendingDependencySourceState initialState.
490
+ * @since 0.10.0
491
+ */
492
+ const WrappedDependencySourceMarker = Symbol.for("@optique/core/dependency/WrappedDependencySourceMarker");
493
+ /**
494
+ * Checks if a parser wraps a dependency source (has WrappedDependencySourceMarker).
495
+ *
496
+ * @param parser The parser to check.
497
+ * @returns `true` if the parser wraps a dependency source.
498
+ * @since 0.10.0
499
+ */
500
+ function isWrappedDependencySource(parser) {
501
+ return typeof parser === "object" && parser !== null && WrappedDependencySourceMarker in parser;
502
+ }
503
+ /**
459
504
  * A registry for storing resolved dependency values during parsing.
460
505
  * This is used to pass dependency values from DependencySource options
461
506
  * to DerivedValueParser options.
@@ -521,4 +566,4 @@ function formatDependencyError(error) {
521
566
  }
522
567
 
523
568
  //#endregion
524
- export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
569
+ export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceStateMarker, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource };
package/dist/index.cjs CHANGED
@@ -20,9 +20,11 @@ exports.DependencySourceStateMarker = require_dependency.DependencySourceStateMa
20
20
  exports.DerivedValueParserMarker = require_dependency.DerivedValueParserMarker;
21
21
  exports.DuplicateOptionError = require_constructs.DuplicateOptionError;
22
22
  exports.ParseWithDependency = require_dependency.ParseWithDependency;
23
+ exports.PendingDependencySourceStateMarker = require_dependency.PendingDependencySourceStateMarker;
23
24
  exports.RunError = require_facade.RunError;
24
25
  exports.RunParserError = require_facade.RunParserError;
25
26
  exports.WithDefaultError = require_modifiers.WithDefaultError;
27
+ exports.WrappedDependencySourceMarker = require_dependency.WrappedDependencySourceMarker;
26
28
  exports.argument = require_primitives.argument;
27
29
  exports.bash = require_completion.bash;
28
30
  exports.choice = require_valueparser.choice;
@@ -33,6 +35,7 @@ exports.conditional = require_constructs.conditional;
33
35
  exports.constant = require_primitives.constant;
34
36
  exports.createDeferredParseState = require_dependency.createDeferredParseState;
35
37
  exports.createDependencySourceState = require_dependency.createDependencySourceState;
38
+ exports.createPendingDependencySourceState = require_dependency.createPendingDependencySourceState;
36
39
  exports.dependency = require_dependency.dependency;
37
40
  exports.deriveFrom = require_dependency.deriveFrom;
38
41
  exports.deriveFromAsync = require_dependency.deriveFromAsync;
@@ -60,7 +63,9 @@ exports.isDependencySource = require_dependency.isDependencySource;
60
63
  exports.isDependencySourceState = require_dependency.isDependencySourceState;
61
64
  exports.isDerivedValueParser = require_dependency.isDerivedValueParser;
62
65
  exports.isNonEmptyString = require_nonempty.isNonEmptyString;
66
+ exports.isPendingDependencySourceState = require_dependency.isPendingDependencySourceState;
63
67
  exports.isValueParser = require_valueparser.isValueParser;
68
+ exports.isWrappedDependencySource = require_dependency.isWrappedDependencySource;
64
69
  exports.locale = require_valueparser.locale;
65
70
  exports.longestMatch = require_constructs.longestMatch;
66
71
  exports.map = require_modifiers.map;
package/dist/index.d.cts CHANGED
@@ -5,9 +5,9 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
5
5
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
6
6
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
7
7
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.cjs";
8
- import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.cjs";
8
+ import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource } from "./dependency.cjs";
9
9
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.cjs";
10
10
  import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.cjs";
11
11
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
12
12
  import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.cjs";
13
- export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
13
+ export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, WrappedDependencySourceMarker, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.d.ts CHANGED
@@ -5,9 +5,9 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
5
5
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
6
6
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
7
7
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.js";
8
- import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
8
+ import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource } from "./dependency.js";
9
9
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
10
10
  import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
11
11
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
12
12
  import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
13
- export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
13
+ export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, WrappedDependencySourceMarker, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
2
2
  import { bash, fish, nu, pwsh, zsh } from "./completion.js";
3
- import { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
3
+ import { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceStateMarker, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource } from "./dependency.js";
4
4
  import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
5
5
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
6
6
  import { formatDocPage } from "./doc.js";
@@ -11,4 +11,4 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
11
11
  import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
12
12
  import { RunError, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
13
13
 
14
- export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, DuplicateOptionError, ParseWithDependency, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
14
+ export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, DuplicateOptionError, ParseWithDependency, PendingDependencySourceStateMarker, RunError, RunParserError, WithDefaultError, WrappedDependencySourceMarker, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
@@ -1,4 +1,5 @@
1
1
  const require_message = require('./message.cjs');
2
+ const require_dependency = require('./dependency.cjs');
2
3
 
3
4
  //#region src/modifiers.ts
4
5
  /**
@@ -176,6 +177,8 @@ function withDefault(parser, defaultValue, options) {
176
177
  }, prefix);
177
178
  for await (const s of suggestions) yield s;
178
179
  }
180
+ const innerInitialState = syncParser.initialState;
181
+ const wrappedDependencyMarker = require_dependency.isPendingDependencySourceState(innerInitialState) ? { [require_dependency.WrappedDependencySourceMarker]: innerInitialState } : {};
179
182
  return {
180
183
  $mode: parser.$mode,
181
184
  $valueType: [],
@@ -186,6 +189,7 @@ function withDefault(parser, defaultValue, options) {
186
189
  terms: parser.usage
187
190
  }],
188
191
  initialState: void 0,
192
+ ...wrappedDependencyMarker,
189
193
  parse(context) {
190
194
  if (isAsync) return parseOptionalStyleAsync(context, parser);
191
195
  return parseOptionalStyleSync(context, syncParser);
@@ -203,6 +207,18 @@ function withDefault(parser, defaultValue, options) {
203
207
  error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
204
208
  };
205
209
  }
210
+ if (require_dependency.isPendingDependencySourceState(state[0])) try {
211
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
212
+ return require_dependency.createDependencySourceState({
213
+ success: true,
214
+ value
215
+ }, state[0][require_dependency.DependencyId]);
216
+ } catch (error) {
217
+ return {
218
+ success: false,
219
+ error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
220
+ };
221
+ }
206
222
  if (!isAsync) return syncParser.complete(state[0]);
207
223
  return parser.complete(state[0]);
208
224
  },
package/dist/modifiers.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { formatMessage, message, text } from "./message.js";
2
+ import { DependencyId, WrappedDependencySourceMarker, createDependencySourceState, isPendingDependencySourceState } from "./dependency.js";
2
3
 
3
4
  //#region src/modifiers.ts
4
5
  /**
@@ -176,6 +177,8 @@ function withDefault(parser, defaultValue, options) {
176
177
  }, prefix);
177
178
  for await (const s of suggestions) yield s;
178
179
  }
180
+ const innerInitialState = syncParser.initialState;
181
+ const wrappedDependencyMarker = isPendingDependencySourceState(innerInitialState) ? { [WrappedDependencySourceMarker]: innerInitialState } : {};
179
182
  return {
180
183
  $mode: parser.$mode,
181
184
  $valueType: [],
@@ -186,6 +189,7 @@ function withDefault(parser, defaultValue, options) {
186
189
  terms: parser.usage
187
190
  }],
188
191
  initialState: void 0,
192
+ ...wrappedDependencyMarker,
189
193
  parse(context) {
190
194
  if (isAsync) return parseOptionalStyleAsync(context, parser);
191
195
  return parseOptionalStyleSync(context, syncParser);
@@ -203,6 +207,18 @@ function withDefault(parser, defaultValue, options) {
203
207
  error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
204
208
  };
205
209
  }
210
+ if (isPendingDependencySourceState(state[0])) try {
211
+ const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
212
+ return createDependencySourceState({
213
+ success: true,
214
+ value
215
+ }, state[0][DependencyId]);
216
+ } catch (error) {
217
+ return {
218
+ success: false,
219
+ error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
220
+ };
221
+ }
206
222
  if (!isAsync) return syncParser.complete(state[0]);
207
223
  return parser.complete(state[0]);
208
224
  },
@@ -203,7 +203,7 @@ function option(...args) {
203
203
  initialState: valueParser == null ? {
204
204
  success: true,
205
205
  value: false
206
- } : {
206
+ } : require_dependency.isDependencySource(valueParser) ? require_dependency.createPendingDependencySourceState(valueParser[require_dependency.DependencyId]) : {
207
207
  success: false,
208
208
  error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
209
209
  },
@@ -357,6 +357,10 @@ function option(...args) {
357
357
  success: false,
358
358
  error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
359
359
  };
360
+ if (require_dependency.isPendingDependencySourceState(state)) return {
361
+ success: false,
362
+ error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
363
+ };
360
364
  if (require_dependency.isDeferredParseState(state)) {
361
365
  const preliminaryResult = state.preliminaryResult;
362
366
  if (preliminaryResult.success) return preliminaryResult;
@@ -1,16 +1,17 @@
1
1
  import { Message } from "./message.cjs";
2
2
  import { OptionName } from "./usage.cjs";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.cjs";
4
- import { DeferredParseState } from "./dependency.cjs";
4
+ import { DeferredParseState, PendingDependencySourceState } from "./dependency.cjs";
5
5
  import { Mode, Parser } from "./parser.cjs";
6
6
 
7
7
  //#region src/primitives.d.ts
8
8
  /**
9
9
  * State type for options that may use deferred parsing (DerivedValueParser).
10
- * This extends the normal ValueParserResult to also support DeferredParseState.
10
+ * This extends the normal ValueParserResult to also support DeferredParseState
11
+ * and PendingDependencySourceState.
11
12
  * @internal
12
13
  */
13
- type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | undefined;
14
+ type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | PendingDependencySourceState | undefined;
14
15
  /**
15
16
  * Creates a parser that always succeeds without consuming any input and
16
17
  * produces a constant value of the type {@link T}.
@@ -1,16 +1,17 @@
1
1
  import { Message } from "./message.js";
2
2
  import { OptionName } from "./usage.js";
3
3
  import { ValueParser, ValueParserResult } from "./valueparser.js";
4
- import { DeferredParseState } from "./dependency.js";
4
+ import { DeferredParseState, PendingDependencySourceState } from "./dependency.js";
5
5
  import { Mode, Parser } from "./parser.js";
6
6
 
7
7
  //#region src/primitives.d.ts
8
8
  /**
9
9
  * State type for options that may use deferred parsing (DerivedValueParser).
10
- * This extends the normal ValueParserResult to also support DeferredParseState.
10
+ * This extends the normal ValueParserResult to also support DeferredParseState
11
+ * and PendingDependencySourceState.
11
12
  * @internal
12
13
  */
13
- type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | undefined;
14
+ type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | PendingDependencySourceState | undefined;
14
15
  /**
15
16
  * Creates a parser that always succeeds without consuming any input and
16
17
  * produces a constant value of the type {@link T}.
@@ -1,5 +1,5 @@
1
1
  import { message, metavar, optionName, optionNames } from "./message.js";
2
- import { DependencyId, createDeferredParseState, createDependencySourceState, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
2
+ import { DependencyId, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState } from "./dependency.js";
3
3
  import { extractCommandNames, extractOptionNames } from "./usage.js";
4
4
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, findSimilar } from "./suggestion.js";
5
5
  import { isValueParser } from "./valueparser.js";
@@ -203,7 +203,7 @@ function option(...args) {
203
203
  initialState: valueParser == null ? {
204
204
  success: true,
205
205
  value: false
206
- } : {
206
+ } : isDependencySource(valueParser) ? createPendingDependencySourceState(valueParser[DependencyId]) : {
207
207
  success: false,
208
208
  error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
209
209
  },
@@ -357,6 +357,10 @@ function option(...args) {
357
357
  success: false,
358
358
  error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
359
359
  };
360
+ if (isPendingDependencySourceState(state)) return {
361
+ success: false,
362
+ error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
363
+ };
360
364
  if (isDeferredParseState(state)) {
361
365
  const preliminaryResult = state.preliminaryResult;
362
366
  if (preliminaryResult.success) return preliminaryResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.10.0-dev.294+7d6c1ae6",
3
+ "version": "0.10.0-dev.295+b5bcb58e",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",