@optique/core 1.1.0-dev.2096 → 1.1.0-dev.2146
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/annotation-state.cjs +26 -26
- package/dist/annotation-state.d.cts +133 -1
- package/dist/annotation-state.d.ts +133 -1
- package/dist/annotations.cjs +2 -2
- package/dist/constructs.cjs +141 -73
- package/dist/constructs.js +70 -2
- package/dist/dependency-metadata.cjs +12 -12
- package/dist/dependency-metadata.d.cts +34 -3
- package/dist/dependency-metadata.d.ts +34 -3
- package/dist/dependency-runtime.cjs +37 -13
- package/dist/dependency-runtime.d.cts +197 -2
- package/dist/dependency-runtime.d.ts +197 -2
- package/dist/dependency-runtime.js +22 -1
- package/dist/dependency.cjs +7 -7
- package/dist/displaywidth.d.cts +12 -0
- package/dist/displaywidth.d.ts +12 -0
- package/dist/execution-context.d.cts +23 -0
- package/dist/execution-context.d.ts +23 -0
- package/dist/extension.cjs +14 -14
- package/dist/facade.cjs +46 -36
- package/dist/facade.js +31 -21
- package/dist/index.cjs +22 -21
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/input-trace.d.cts +2 -1
- package/dist/input-trace.d.ts +2 -1
- package/dist/internal/annotations.cjs +3 -0
- package/dist/internal/annotations.d.cts +47 -5
- package/dist/internal/annotations.d.ts +47 -5
- package/dist/internal/annotations.js +1 -1
- package/dist/internal/command-alias.cjs +16 -0
- package/dist/internal/command-alias.js +14 -0
- package/dist/internal/dependency.cjs +131 -0
- package/dist/internal/dependency.d.cts +311 -2
- package/dist/internal/dependency.d.ts +311 -2
- package/dist/internal/dependency.js +119 -1
- package/dist/internal/parser.cjs +35 -13
- package/dist/internal/parser.d.cts +44 -3
- package/dist/internal/parser.d.ts +44 -3
- package/dist/internal/parser.js +28 -6
- package/dist/modifiers.cjs +41 -41
- package/dist/parser.cjs +11 -11
- package/dist/phase2-seed.cjs +2 -2
- package/dist/phase2-seed.d.cts +50 -0
- package/dist/phase2-seed.d.ts +50 -0
- package/dist/primitives.cjs +74 -33
- package/dist/primitives.d.cts +10 -0
- package/dist/primitives.d.ts +10 -0
- package/dist/primitives.js +54 -13
- package/dist/suggestion.cjs +72 -2
- package/dist/suggestion.d.cts +188 -0
- package/dist/suggestion.d.ts +188 -0
- package/dist/suggestion.js +71 -3
- package/dist/usage-internals.cjs +5 -1
- package/dist/usage-internals.js +5 -1
- package/dist/usage.cjs +9 -1
- package/dist/usage.d.cts +14 -0
- package/dist/usage.d.ts +14 -0
- package/dist/usage.js +9 -1
- package/dist/validate.cjs +1 -0
- package/dist/validate.d.cts +99 -0
- package/dist/validate.d.ts +99 -0
- package/dist/validate.js +1 -1
- package/dist/valueparser.cjs +333 -79
- package/dist/valueparser.d.cts +197 -1
- package/dist/valueparser.d.ts +197 -1
- package/dist/valueparser.js +334 -81
- package/package.json +19 -4
|
@@ -885,6 +885,37 @@ function getDefaultValuesFunction(parser) {
|
|
|
885
885
|
return void 0;
|
|
886
886
|
}
|
|
887
887
|
/**
|
|
888
|
+
* Creates a deferred parse state for a DerivedValueParser.
|
|
889
|
+
*
|
|
890
|
+
* @template T The type of value the parser will produce.
|
|
891
|
+
* @template S The type of the source dependency value.
|
|
892
|
+
* @param rawInput The raw input string to be parsed.
|
|
893
|
+
* @param parser The DerivedValueParser that will parse the input.
|
|
894
|
+
* @param preliminaryResult The parse result using default dependency value.
|
|
895
|
+
* @returns A DeferredParseState object.
|
|
896
|
+
* @since 0.10.0
|
|
897
|
+
*/
|
|
898
|
+
function createDeferredParseState(rawInput, parser, preliminaryResult) {
|
|
899
|
+
const multipleIds = dependencyIds in parser ? parser[dependencyIds] : void 0;
|
|
900
|
+
const defaultValuesFn = getDefaultValuesFunction(parser);
|
|
901
|
+
let defaultVals = getSnapshottedDefaultDependencyValues(preliminaryResult);
|
|
902
|
+
if (defaultVals != null) defaultVals = [...defaultVals];
|
|
903
|
+
if (defaultVals == null && defaultValuesFn != null) try {
|
|
904
|
+
defaultVals = [...defaultValuesFn()];
|
|
905
|
+
} catch {
|
|
906
|
+
defaultVals = void 0;
|
|
907
|
+
}
|
|
908
|
+
return {
|
|
909
|
+
[deferredParseMarker]: true,
|
|
910
|
+
rawInput,
|
|
911
|
+
parser,
|
|
912
|
+
dependencyId: parser[dependencyId],
|
|
913
|
+
dependencyIds: multipleIds,
|
|
914
|
+
defaultValues: defaultVals,
|
|
915
|
+
preliminaryResult
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
888
919
|
* A unique symbol used to identify dependency source parse states.
|
|
889
920
|
* @since 0.10.0
|
|
890
921
|
*/
|
|
@@ -931,6 +962,19 @@ function isPendingDependencySourceState(value) {
|
|
|
931
962
|
return typeof value === "object" && value !== null && pendingDependencySourceStateMarker in value && value[pendingDependencySourceStateMarker] === true;
|
|
932
963
|
}
|
|
933
964
|
/**
|
|
965
|
+
* Creates a pending dependency source state.
|
|
966
|
+
*
|
|
967
|
+
* @param depId The dependency ID.
|
|
968
|
+
* @returns A PendingDependencySourceState object.
|
|
969
|
+
* @since 0.10.0
|
|
970
|
+
*/
|
|
971
|
+
function createPendingDependencySourceState(depId) {
|
|
972
|
+
return {
|
|
973
|
+
[pendingDependencySourceStateMarker]: true,
|
|
974
|
+
[dependencyId]: depId
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
934
978
|
* A unique symbol used to identify parsers that wrap a dependency source.
|
|
935
979
|
* This is used by withDefault to indicate it contains an inner parser
|
|
936
980
|
* with a PendingDependencySourceState initialState.
|
|
@@ -950,6 +994,16 @@ const wrappedDependencySourceMarker = Symbol.for("@optique/core/dependency/wrapp
|
|
|
950
994
|
*/
|
|
951
995
|
const transformsDependencyValueMarker = Symbol.for("@optique/core/dependency/transformsDependencyValueMarker");
|
|
952
996
|
/**
|
|
997
|
+
* Checks if a parser transforms the dependency value (has transformsDependencyValueMarker).
|
|
998
|
+
*
|
|
999
|
+
* @param parser The parser to check.
|
|
1000
|
+
* @returns `true` if the parser transforms the dependency value.
|
|
1001
|
+
* @since 0.10.0
|
|
1002
|
+
*/
|
|
1003
|
+
function transformsDependencyValue(parser) {
|
|
1004
|
+
return typeof parser === "object" && parser !== null && transformsDependencyValueMarker in parser && parser[transformsDependencyValueMarker] === true;
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
953
1007
|
* Checks if a parser wraps a dependency source (has wrappedDependencySourceMarker).
|
|
954
1008
|
*
|
|
955
1009
|
* @param parser The parser to check.
|
|
@@ -959,16 +1013,89 @@ const transformsDependencyValueMarker = Symbol.for("@optique/core/dependency/tra
|
|
|
959
1013
|
function isWrappedDependencySource(parser) {
|
|
960
1014
|
return typeof parser === "object" && parser !== null && wrappedDependencySourceMarker in parser;
|
|
961
1015
|
}
|
|
1016
|
+
/**
|
|
1017
|
+
* A registry for storing resolved dependency values during parsing.
|
|
1018
|
+
* This is used to pass dependency values from DependencySource options
|
|
1019
|
+
* to DerivedValueParser options.
|
|
1020
|
+
* @since 0.10.0
|
|
1021
|
+
*/
|
|
1022
|
+
var DependencyRegistry = class DependencyRegistry {
|
|
1023
|
+
values = /* @__PURE__ */ new Map();
|
|
1024
|
+
/**
|
|
1025
|
+
* Registers a resolved dependency value.
|
|
1026
|
+
* @param id The dependency ID.
|
|
1027
|
+
* @param value The resolved value.
|
|
1028
|
+
*/
|
|
1029
|
+
set(id, value) {
|
|
1030
|
+
this.values.set(id, value);
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Gets a resolved dependency value.
|
|
1034
|
+
* @param id The dependency ID.
|
|
1035
|
+
* @returns The resolved value, or undefined if not found.
|
|
1036
|
+
*/
|
|
1037
|
+
get(id) {
|
|
1038
|
+
return this.values.get(id);
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Checks if a dependency has been resolved.
|
|
1042
|
+
* @param id The dependency ID.
|
|
1043
|
+
* @returns `true` if the dependency has been resolved.
|
|
1044
|
+
*/
|
|
1045
|
+
has(id) {
|
|
1046
|
+
return this.values.has(id);
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Creates a copy of the registry.
|
|
1050
|
+
*/
|
|
1051
|
+
clone() {
|
|
1052
|
+
const copy = new DependencyRegistry();
|
|
1053
|
+
for (const [id, value] of this.values) copy.values.set(id, value);
|
|
1054
|
+
return copy;
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
/**
|
|
1058
|
+
* Formats a {@link DependencyError} into a human-readable {@link Message}.
|
|
1059
|
+
*
|
|
1060
|
+
* @param error The dependency error to format.
|
|
1061
|
+
* @returns A Message describing the error.
|
|
1062
|
+
* @since 0.10.0
|
|
1063
|
+
*/
|
|
1064
|
+
function formatDependencyError(error) {
|
|
1065
|
+
switch (error.kind) {
|
|
1066
|
+
case "duplicate": return [{
|
|
1067
|
+
type: "text",
|
|
1068
|
+
text: `Dependency used in multiple locations: ${error.locations.join(", ")}.`
|
|
1069
|
+
}];
|
|
1070
|
+
case "unresolved": return [{
|
|
1071
|
+
type: "text",
|
|
1072
|
+
text: `Unresolved dependency for ${error.derivedParserMetavar}: the dependency was not provided.`
|
|
1073
|
+
}];
|
|
1074
|
+
case "circular": return [{
|
|
1075
|
+
type: "text",
|
|
1076
|
+
text: `Circular dependency detected.`
|
|
1077
|
+
}];
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
962
1080
|
|
|
963
1081
|
//#endregion
|
|
1082
|
+
exports.DependencyRegistry = DependencyRegistry;
|
|
1083
|
+
exports.createDeferredParseState = createDeferredParseState;
|
|
964
1084
|
exports.createDependencySourceState = createDependencySourceState;
|
|
1085
|
+
exports.createPendingDependencySourceState = createPendingDependencySourceState;
|
|
1086
|
+
exports.defaultDependencyValueSnapshot = defaultDependencyValueSnapshot;
|
|
965
1087
|
exports.defaultValues = defaultValues;
|
|
1088
|
+
exports.deferredParseMarker = deferredParseMarker;
|
|
966
1089
|
exports.dependency = dependency;
|
|
967
1090
|
exports.dependencyId = dependencyId;
|
|
968
1091
|
exports.dependencyIds = dependencyIds;
|
|
1092
|
+
exports.dependencySourceMarker = dependencySourceMarker;
|
|
1093
|
+
exports.dependencySourceStateMarker = dependencySourceStateMarker;
|
|
969
1094
|
exports.deriveFrom = deriveFrom;
|
|
970
1095
|
exports.deriveFromAsync = deriveFromAsync;
|
|
971
1096
|
exports.deriveFromSync = deriveFromSync;
|
|
1097
|
+
exports.derivedValueParserMarker = derivedValueParserMarker;
|
|
1098
|
+
exports.formatDependencyError = formatDependencyError;
|
|
972
1099
|
exports.getDefaultValuesFunction = getDefaultValuesFunction;
|
|
973
1100
|
exports.getDependencyIds = getDependencyIds;
|
|
974
1101
|
exports.getSnapshottedDefaultDependencyValues = getSnapshottedDefaultDependencyValues;
|
|
@@ -979,6 +1106,10 @@ exports.isDerivedValueParser = isDerivedValueParser;
|
|
|
979
1106
|
exports.isPendingDependencySourceState = isPendingDependencySourceState;
|
|
980
1107
|
exports.isWrappedDependencySource = isWrappedDependencySource;
|
|
981
1108
|
exports.parseWithDependency = parseWithDependency;
|
|
1109
|
+
exports.pendingDependencySourceStateMarker = pendingDependencySourceStateMarker;
|
|
982
1110
|
exports.singleDefaultValue = singleDefaultValue;
|
|
1111
|
+
exports.snapshotDefaultDependencyValues = snapshotDefaultDependencyValues;
|
|
983
1112
|
exports.suggestWithDependency = suggestWithDependency;
|
|
1113
|
+
exports.transformsDependencyValue = transformsDependencyValue;
|
|
1114
|
+
exports.transformsDependencyValueMarker = transformsDependencyValueMarker;
|
|
984
1115
|
exports.wrappedDependencySourceMarker = wrappedDependencySourceMarker;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { NonEmptyString } from "../nonempty.cjs";
|
|
2
|
+
import { Message } from "../message.cjs";
|
|
3
|
+
import { DependencyRegistryLike } from "../registry-types.cjs";
|
|
2
4
|
import { ValueParser, ValueParserResult } from "../valueparser.cjs";
|
|
3
5
|
import { Mode, Suggestion } from "./parser.cjs";
|
|
4
6
|
|
|
@@ -51,7 +53,7 @@ declare const singleDefaultValue: unique symbol;
|
|
|
51
53
|
*
|
|
52
54
|
* @internal
|
|
53
55
|
*/
|
|
54
|
-
|
|
56
|
+
declare const defaultDependencyValueSnapshot: unique symbol;
|
|
55
57
|
/**
|
|
56
58
|
* A unique symbol used to access the parseWithDependency method on derived parsers.
|
|
57
59
|
* @since 0.10.0
|
|
@@ -535,5 +537,312 @@ declare function deriveFromAsync<Deps extends readonly AnyDependencySource[], T>
|
|
|
535
537
|
* @returns A cloned parse result with an internal snapshot attached.
|
|
536
538
|
* @internal
|
|
537
539
|
*/
|
|
540
|
+
declare function snapshotDefaultDependencyValues<T>(result: ValueParserResult<T>, values: readonly unknown[]): ValueParserResult<T>;
|
|
541
|
+
/**
|
|
542
|
+
* Reads the snapshotted default dependency values from a parse result.
|
|
543
|
+
*
|
|
544
|
+
* @param result The parse result to inspect.
|
|
545
|
+
* @returns The snapshotted dependency values, if present.
|
|
546
|
+
* @internal
|
|
547
|
+
*/
|
|
548
|
+
declare function getSnapshottedDefaultDependencyValues<T>(result: ValueParserResult<T>): readonly unknown[] | undefined;
|
|
549
|
+
/**
|
|
550
|
+
* A unique symbol used to identify deferred parse states.
|
|
551
|
+
* @since 0.10.0
|
|
552
|
+
*/
|
|
553
|
+
declare const deferredParseMarker: unique symbol;
|
|
554
|
+
/**
|
|
555
|
+
* Represents a deferred parse state for a DerivedValueParser.
|
|
556
|
+
*
|
|
557
|
+
* When a DerivedValueParser is used in an option or argument, the raw
|
|
558
|
+
* input string is stored along with the parser reference. The actual
|
|
559
|
+
* parsing is deferred until `complete()` time when all dependencies
|
|
560
|
+
* have been resolved.
|
|
561
|
+
*
|
|
562
|
+
* @template T The type of value this parser will produce after resolution.
|
|
563
|
+
* @since 0.10.0
|
|
564
|
+
*/
|
|
565
|
+
interface DeferredParseState<T = unknown> {
|
|
566
|
+
/**
|
|
567
|
+
* Marker to identify this as a deferred parse state.
|
|
568
|
+
*/
|
|
569
|
+
readonly [deferredParseMarker]: true;
|
|
570
|
+
/**
|
|
571
|
+
* The raw input string to be parsed.
|
|
572
|
+
*/
|
|
573
|
+
readonly rawInput: string;
|
|
574
|
+
/**
|
|
575
|
+
* The DerivedValueParser that will parse the input.
|
|
576
|
+
*/
|
|
577
|
+
readonly parser: DerivedValueParser<Mode, T, unknown>;
|
|
578
|
+
/**
|
|
579
|
+
* The dependency ID that this parser depends on (for single-dependency parsers).
|
|
580
|
+
*/
|
|
581
|
+
readonly dependencyId: symbol;
|
|
582
|
+
/**
|
|
583
|
+
* The dependency IDs that this parser depends on (for multi-dependency parsers).
|
|
584
|
+
* If present, this is used instead of `dependencyId`.
|
|
585
|
+
*/
|
|
586
|
+
readonly dependencyIds?: readonly symbol[];
|
|
587
|
+
/**
|
|
588
|
+
* The default values to use for dependencies that are not provided.
|
|
589
|
+
* For multi-dependency parsers, this is a tuple of default values in order.
|
|
590
|
+
* For single-dependency parsers, this is the single default value.
|
|
591
|
+
*/
|
|
592
|
+
readonly defaultValues?: readonly unknown[];
|
|
593
|
+
/**
|
|
594
|
+
* The preliminary parse result using the default dependency value.
|
|
595
|
+
* This is used as a fallback if dependency resolution is not needed
|
|
596
|
+
* or if the dependency was not provided.
|
|
597
|
+
*/
|
|
598
|
+
readonly preliminaryResult: ValueParserResult<T>;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Checks if a value is a {@link DeferredParseState}.
|
|
602
|
+
*
|
|
603
|
+
* @param value The value to check.
|
|
604
|
+
* @returns `true` if the value is a deferred parse state, `false` otherwise.
|
|
605
|
+
* @since 0.10.0
|
|
606
|
+
*/
|
|
607
|
+
declare function isDeferredParseState<T>(value: unknown): value is DeferredParseState<T>;
|
|
608
|
+
/**
|
|
609
|
+
* Gets all dependency IDs from a derived parser.
|
|
610
|
+
* If the parser was created with `deriveFrom` (multiple dependencies),
|
|
611
|
+
* returns the array of dependency IDs. Otherwise, returns an array
|
|
612
|
+
* containing the single dependency ID.
|
|
613
|
+
*
|
|
614
|
+
* @param parser The derived value parser to get dependency IDs from.
|
|
615
|
+
* @returns An array of dependency ID symbols.
|
|
616
|
+
* @internal
|
|
617
|
+
* @since 0.10.0
|
|
618
|
+
*/
|
|
619
|
+
declare function getDependencyIds<M extends Mode, T, S>(parser: DerivedValueParser<M, T, S>): readonly symbol[];
|
|
620
|
+
/**
|
|
621
|
+
* Gets the default values function from a multi-source derived parser, if
|
|
622
|
+
* present.
|
|
623
|
+
*
|
|
624
|
+
* Single-source `derive()` defaults must stay lazy during suggestion-time
|
|
625
|
+
* replay so missing dependencies do not eagerly evaluate side-effectful
|
|
626
|
+
* `defaultValue()` thunks.
|
|
627
|
+
*
|
|
628
|
+
* @param parser The derived value parser to get the default values function from.
|
|
629
|
+
* @returns The default values function, or undefined if not available.
|
|
630
|
+
* @internal
|
|
631
|
+
* @since 0.10.0
|
|
632
|
+
*/
|
|
633
|
+
declare function getDefaultValuesFunction<M extends Mode, T, S>(parser: DerivedValueParser<M, T, S>): (() => readonly unknown[]) | undefined;
|
|
634
|
+
/**
|
|
635
|
+
* Creates a deferred parse state for a DerivedValueParser.
|
|
636
|
+
*
|
|
637
|
+
* @template T The type of value the parser will produce.
|
|
638
|
+
* @template S The type of the source dependency value.
|
|
639
|
+
* @param rawInput The raw input string to be parsed.
|
|
640
|
+
* @param parser The DerivedValueParser that will parse the input.
|
|
641
|
+
* @param preliminaryResult The parse result using default dependency value.
|
|
642
|
+
* @returns A DeferredParseState object.
|
|
643
|
+
* @since 0.10.0
|
|
644
|
+
*/
|
|
645
|
+
declare function createDeferredParseState<T, S>(rawInput: string, parser: DerivedValueParser<Mode, T, S>, preliminaryResult: ValueParserResult<T>): DeferredParseState<T>;
|
|
646
|
+
/**
|
|
647
|
+
* A unique symbol used to identify dependency source parse states.
|
|
648
|
+
* @since 0.10.0
|
|
649
|
+
*/
|
|
650
|
+
declare const dependencySourceStateMarker: unique symbol;
|
|
651
|
+
/**
|
|
652
|
+
* Represents a parse state from a DependencySource.
|
|
653
|
+
* This wraps the normal ValueParserResult with the dependency ID so that
|
|
654
|
+
* it can be matched with DeferredParseState during resolution.
|
|
655
|
+
*
|
|
656
|
+
* @template T The type of value this state contains.
|
|
657
|
+
* @since 0.10.0
|
|
658
|
+
*/
|
|
659
|
+
interface DependencySourceState<T = unknown> {
|
|
660
|
+
/**
|
|
661
|
+
* Marker to identify this as a dependency source state.
|
|
662
|
+
*/
|
|
663
|
+
readonly [dependencySourceStateMarker]: true;
|
|
664
|
+
/**
|
|
665
|
+
* The dependency ID of the source.
|
|
666
|
+
*/
|
|
667
|
+
readonly [dependencyId]: symbol;
|
|
668
|
+
/**
|
|
669
|
+
* The underlying parse result.
|
|
670
|
+
*/
|
|
671
|
+
readonly result: ValueParserResult<T>;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Checks if a value is a {@link DependencySourceState}.
|
|
675
|
+
*
|
|
676
|
+
* @param value The value to check.
|
|
677
|
+
* @returns `true` if the value is a dependency source state, `false` otherwise.
|
|
678
|
+
* @since 0.10.0
|
|
679
|
+
*/
|
|
680
|
+
declare function isDependencySourceState<T>(value: unknown): value is DependencySourceState<T>;
|
|
681
|
+
/**
|
|
682
|
+
* Creates a dependency source state from a parse result.
|
|
683
|
+
*
|
|
684
|
+
* @template T The type of value the state contains.
|
|
685
|
+
* @param result The parse result.
|
|
686
|
+
* @param depId The dependency ID.
|
|
687
|
+
* @returns A DependencySourceState object.
|
|
688
|
+
* @since 0.10.0
|
|
689
|
+
*/
|
|
690
|
+
declare function createDependencySourceState<T>(result: ValueParserResult<T>, depId: symbol): DependencySourceState<T>;
|
|
691
|
+
/**
|
|
692
|
+
* A unique symbol used to identify pending dependency source states.
|
|
693
|
+
* @since 0.10.0
|
|
694
|
+
*/
|
|
695
|
+
declare const pendingDependencySourceStateMarker: unique symbol;
|
|
696
|
+
/**
|
|
697
|
+
* Represents a pending dependency source state.
|
|
698
|
+
* This is used when a dependency source option was not provided, but its
|
|
699
|
+
* dependency ID still needs to be tracked for later resolution with a
|
|
700
|
+
* default value.
|
|
701
|
+
*
|
|
702
|
+
* @since 0.10.0
|
|
703
|
+
*/
|
|
704
|
+
interface PendingDependencySourceState {
|
|
705
|
+
/**
|
|
706
|
+
* Marker to identify this as a pending dependency source state.
|
|
707
|
+
*/
|
|
708
|
+
readonly [pendingDependencySourceStateMarker]: true;
|
|
709
|
+
/**
|
|
710
|
+
* The dependency ID of the source.
|
|
711
|
+
*/
|
|
712
|
+
readonly [dependencyId]: symbol;
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Checks if a value is a {@link PendingDependencySourceState}.
|
|
716
|
+
*
|
|
717
|
+
* @param value The value to check.
|
|
718
|
+
* @returns `true` if the value is a pending dependency source state.
|
|
719
|
+
* @since 0.10.0
|
|
720
|
+
*/
|
|
721
|
+
declare function isPendingDependencySourceState(value: unknown): value is PendingDependencySourceState;
|
|
722
|
+
/**
|
|
723
|
+
* Creates a pending dependency source state.
|
|
724
|
+
*
|
|
725
|
+
* @param depId The dependency ID.
|
|
726
|
+
* @returns A PendingDependencySourceState object.
|
|
727
|
+
* @since 0.10.0
|
|
728
|
+
*/
|
|
729
|
+
declare function createPendingDependencySourceState(depId: symbol): PendingDependencySourceState;
|
|
730
|
+
/**
|
|
731
|
+
* A unique symbol used to identify parsers that wrap a dependency source.
|
|
732
|
+
* This is used by withDefault to indicate it contains an inner parser
|
|
733
|
+
* with a PendingDependencySourceState initialState.
|
|
734
|
+
* @since 0.10.0
|
|
735
|
+
*/
|
|
736
|
+
declare const wrappedDependencySourceMarker: unique symbol;
|
|
737
|
+
/**
|
|
738
|
+
* A unique symbol used to indicate that a wrapper transforms the dependency
|
|
739
|
+
* source value. This is used by withDefault to determine whether its default
|
|
740
|
+
* value should be registered as the dependency value.
|
|
741
|
+
*
|
|
742
|
+
* When a wrapper has this marker set to `true`, it means the wrapper transforms
|
|
743
|
+
* the dependency source value (e.g., via map()), so the wrapper's output is NOT
|
|
744
|
+
* a valid dependency source value.
|
|
745
|
+
*
|
|
746
|
+
* @since 0.10.0
|
|
747
|
+
*/
|
|
748
|
+
declare const transformsDependencyValueMarker: unique symbol;
|
|
749
|
+
/**
|
|
750
|
+
* Checks if a parser transforms the dependency value (has transformsDependencyValueMarker).
|
|
751
|
+
*
|
|
752
|
+
* @param parser The parser to check.
|
|
753
|
+
* @returns `true` if the parser transforms the dependency value.
|
|
754
|
+
* @since 0.10.0
|
|
755
|
+
*/
|
|
756
|
+
declare function transformsDependencyValue(parser: unknown): parser is {
|
|
757
|
+
[transformsDependencyValueMarker]: true;
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* Checks if a parser wraps a dependency source (has wrappedDependencySourceMarker).
|
|
761
|
+
*
|
|
762
|
+
* @param parser The parser to check.
|
|
763
|
+
* @returns `true` if the parser wraps a dependency source.
|
|
764
|
+
* @since 0.10.0
|
|
765
|
+
*/
|
|
766
|
+
declare function isWrappedDependencySource(parser: unknown): parser is {
|
|
767
|
+
[wrappedDependencySourceMarker]: PendingDependencySourceState;
|
|
768
|
+
};
|
|
769
|
+
/**
|
|
770
|
+
* Represents a resolved dependency value stored during parsing.
|
|
771
|
+
* @since 0.10.0
|
|
772
|
+
*/
|
|
773
|
+
interface ResolvedDependency<T = unknown> {
|
|
774
|
+
/**
|
|
775
|
+
* The dependency ID.
|
|
776
|
+
*/
|
|
777
|
+
readonly id: symbol;
|
|
778
|
+
/**
|
|
779
|
+
* The resolved value.
|
|
780
|
+
*/
|
|
781
|
+
readonly value: T;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* A registry for storing resolved dependency values during parsing.
|
|
785
|
+
* This is used to pass dependency values from DependencySource options
|
|
786
|
+
* to DerivedValueParser options.
|
|
787
|
+
* @since 0.10.0
|
|
788
|
+
*/
|
|
789
|
+
declare class DependencyRegistry implements DependencyRegistryLike {
|
|
790
|
+
private readonly values;
|
|
791
|
+
/**
|
|
792
|
+
* Registers a resolved dependency value.
|
|
793
|
+
* @param id The dependency ID.
|
|
794
|
+
* @param value The resolved value.
|
|
795
|
+
*/
|
|
796
|
+
set<T>(id: symbol, value: T): void;
|
|
797
|
+
/**
|
|
798
|
+
* Gets a resolved dependency value.
|
|
799
|
+
* @param id The dependency ID.
|
|
800
|
+
* @returns The resolved value, or undefined if not found.
|
|
801
|
+
*/
|
|
802
|
+
get<T>(id: symbol): T | undefined;
|
|
803
|
+
/**
|
|
804
|
+
* Checks if a dependency has been resolved.
|
|
805
|
+
* @param id The dependency ID.
|
|
806
|
+
* @returns `true` if the dependency has been resolved.
|
|
807
|
+
*/
|
|
808
|
+
has(id: symbol): boolean;
|
|
809
|
+
/**
|
|
810
|
+
* Creates a copy of the registry.
|
|
811
|
+
*/
|
|
812
|
+
clone(): DependencyRegistry;
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Error types for dependency resolution failures.
|
|
816
|
+
* @since 0.10.0
|
|
817
|
+
*/
|
|
818
|
+
type DependencyError = {
|
|
819
|
+
/**
|
|
820
|
+
* The dependency was used in multiple locations.
|
|
821
|
+
*/
|
|
822
|
+
readonly kind: "duplicate";
|
|
823
|
+
readonly dependencyId: symbol;
|
|
824
|
+
readonly locations: readonly string[];
|
|
825
|
+
} | {
|
|
826
|
+
/**
|
|
827
|
+
* A derived parser references a dependency that was not provided.
|
|
828
|
+
*/
|
|
829
|
+
readonly kind: "unresolved";
|
|
830
|
+
readonly dependencyId: symbol;
|
|
831
|
+
readonly derivedParserMetavar: string;
|
|
832
|
+
} | {
|
|
833
|
+
/**
|
|
834
|
+
* Circular dependency detected.
|
|
835
|
+
*/
|
|
836
|
+
readonly kind: "circular";
|
|
837
|
+
readonly cycle: readonly symbol[];
|
|
838
|
+
};
|
|
839
|
+
/**
|
|
840
|
+
* Formats a {@link DependencyError} into a human-readable {@link Message}.
|
|
841
|
+
*
|
|
842
|
+
* @param error The dependency error to format.
|
|
843
|
+
* @returns A Message describing the error.
|
|
844
|
+
* @since 0.10.0
|
|
845
|
+
*/
|
|
846
|
+
declare function formatDependencyError(error: DependencyError): Message;
|
|
538
847
|
//#endregion
|
|
539
|
-
export { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser };
|
|
848
|
+
export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultDependencyValueSnapshot, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, getSnapshottedDefaultDependencyValues, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, singleDefaultValue, snapshotDefaultDependencyValues, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker };
|