@optique/core 1.1.0-dev.2087 → 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.
Files changed (74) hide show
  1. package/dist/annotation-state.cjs +26 -26
  2. package/dist/annotation-state.d.cts +133 -1
  3. package/dist/annotation-state.d.ts +133 -1
  4. package/dist/annotations.cjs +2 -2
  5. package/dist/constructs.cjs +873 -73
  6. package/dist/constructs.d.cts +72 -1
  7. package/dist/constructs.d.ts +72 -1
  8. package/dist/constructs.js +808 -9
  9. package/dist/dependency-metadata.cjs +12 -12
  10. package/dist/dependency-metadata.d.cts +34 -3
  11. package/dist/dependency-metadata.d.ts +34 -3
  12. package/dist/dependency-runtime.cjs +37 -13
  13. package/dist/dependency-runtime.d.cts +197 -2
  14. package/dist/dependency-runtime.d.ts +197 -2
  15. package/dist/dependency-runtime.js +22 -1
  16. package/dist/dependency.cjs +7 -7
  17. package/dist/displaywidth.d.cts +12 -0
  18. package/dist/displaywidth.d.ts +12 -0
  19. package/dist/doc.cjs +3 -0
  20. package/dist/doc.js +3 -0
  21. package/dist/execution-context.d.cts +23 -0
  22. package/dist/execution-context.d.ts +23 -0
  23. package/dist/extension.cjs +14 -14
  24. package/dist/facade.cjs +49 -37
  25. package/dist/facade.js +34 -22
  26. package/dist/index.cjs +23 -21
  27. package/dist/index.d.cts +3 -3
  28. package/dist/index.d.ts +3 -3
  29. package/dist/index.js +4 -4
  30. package/dist/input-trace.d.cts +2 -1
  31. package/dist/input-trace.d.ts +2 -1
  32. package/dist/internal/annotations.cjs +3 -0
  33. package/dist/internal/annotations.d.cts +47 -5
  34. package/dist/internal/annotations.d.ts +47 -5
  35. package/dist/internal/annotations.js +1 -1
  36. package/dist/internal/command-alias.cjs +16 -0
  37. package/dist/internal/command-alias.js +14 -0
  38. package/dist/internal/dependency.cjs +131 -0
  39. package/dist/internal/dependency.d.cts +311 -2
  40. package/dist/internal/dependency.d.ts +311 -2
  41. package/dist/internal/dependency.js +119 -1
  42. package/dist/internal/parser.cjs +108 -23
  43. package/dist/internal/parser.d.cts +58 -3
  44. package/dist/internal/parser.d.ts +58 -3
  45. package/dist/internal/parser.js +101 -16
  46. package/dist/modifiers.cjs +74 -44
  47. package/dist/modifiers.js +34 -4
  48. package/dist/parser.cjs +11 -11
  49. package/dist/phase2-seed.cjs +2 -2
  50. package/dist/phase2-seed.d.cts +50 -0
  51. package/dist/phase2-seed.d.ts +50 -0
  52. package/dist/primitives.cjs +104 -33
  53. package/dist/primitives.d.cts +10 -0
  54. package/dist/primitives.d.ts +10 -0
  55. package/dist/primitives.js +84 -13
  56. package/dist/suggestion.cjs +72 -2
  57. package/dist/suggestion.d.cts +188 -0
  58. package/dist/suggestion.d.ts +188 -0
  59. package/dist/suggestion.js +71 -3
  60. package/dist/usage-internals.cjs +14 -6
  61. package/dist/usage-internals.js +14 -6
  62. package/dist/usage.cjs +33 -8
  63. package/dist/usage.d.cts +31 -0
  64. package/dist/usage.d.ts +31 -0
  65. package/dist/usage.js +33 -8
  66. package/dist/validate.cjs +1 -0
  67. package/dist/validate.d.cts +99 -0
  68. package/dist/validate.d.ts +99 -0
  69. package/dist/validate.js +1 -1
  70. package/dist/valueparser.cjs +333 -79
  71. package/dist/valueparser.d.cts +197 -1
  72. package/dist/valueparser.d.ts +197 -1
  73. package/dist/valueparser.js +334 -81
  74. package/package.json +19 -4
@@ -1,5 +1,38 @@
1
1
  //#region src/internal/annotations.d.ts
2
-
2
+ /**
3
+ * Runtime context extension system for Optique parsers.
4
+ *
5
+ * This module provides the annotations system that allows external runtime data
6
+ * to be passed to parsers during the parsing session. This enables use cases like
7
+ * config file fallbacks, environment-based validation, and shared context.
8
+ *
9
+ * @module
10
+ * @since 0.10.0
11
+ */
12
+ /**
13
+ * Annotation key symbol for storing data in parser state.
14
+ * @since 0.10.0
15
+ */
16
+ declare const annotationKey: unique symbol;
17
+ /**
18
+ * Internal marker attached during the first pass of `runWith()` so wrappers
19
+ * with side effects can defer work until two-pass contexts have resolved.
20
+ *
21
+ * @internal
22
+ */
23
+ declare const firstPassAnnotationKey: unique symbol;
24
+ /**
25
+ * Internal key for preserving primitive parser state values when annotations
26
+ * are injected into non-object states.
27
+ * @internal
28
+ */
29
+ declare const annotationStateValueKey: unique symbol;
30
+ /**
31
+ * Internal marker key that indicates annotation wrapping was injected by
32
+ * Optique internals for non-object states.
33
+ * @internal
34
+ */
35
+ declare const annotationWrapperKey: unique symbol;
3
36
  /**
4
37
  * Annotations that can be passed to parsers during execution.
5
38
  * Allows external packages to provide additional data that parsers can access
@@ -53,7 +86,7 @@ declare function getAnnotations(state: unknown): Annotations | undefined;
53
86
  * @returns The target array, with annotations copied when available.
54
87
  * @internal
55
88
  */
56
-
89
+ declare function annotateFreshArray<T>(source: unknown, target: readonly T[]): readonly T[];
57
90
  /**
58
91
  * Propagates annotations from one parser state to another.
59
92
  *
@@ -85,7 +118,7 @@ declare function inheritAnnotations<T>(source: unknown, target: T): T;
85
118
  * @returns `true` when the record has at least one own symbol key.
86
119
  * @internal
87
120
  */
88
-
121
+ declare function hasMeaningfulAnnotations(annotations: Annotations | null | undefined): annotations is Annotations;
89
122
  /**
90
123
  * Injects annotations into parser state while preserving state shape.
91
124
  *
@@ -111,7 +144,16 @@ declare function injectAnnotations<TState>(state: TState, annotations: Annotatio
111
144
  * otherwise the original value.
112
145
  * @internal
113
146
  */
114
-
147
+ declare function unwrapInjectedAnnotationWrapper<T>(value: T): T;
148
+ /**
149
+ * Returns whether the given value is an internal primitive-state annotation
150
+ * wrapper that was injected by Optique.
151
+ *
152
+ * @param value Value to check.
153
+ * @returns `true` if the value is an injected internal wrapper.
154
+ * @internal
155
+ */
156
+ declare function isInjectedAnnotationWrapper(value: unknown): boolean;
115
157
  /**
116
158
  * Returns whether the given value is an injected annotation state wrapper.
117
159
  *
@@ -137,4 +179,4 @@ declare function isInjectedAnnotationState(value: unknown): boolean;
137
179
  */
138
180
  declare function unwrapInjectedAnnotationState<T>(value: T): T;
139
181
  //#endregion
140
- export { Annotations, ParseOptions, getAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwrapInjectedAnnotationState };
182
+ export { Annotations, ParseOptions, annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, isInjectedAnnotationWrapper, unwrapInjectedAnnotationState, unwrapInjectedAnnotationWrapper };
@@ -1,5 +1,38 @@
1
1
  //#region src/internal/annotations.d.ts
2
-
2
+ /**
3
+ * Runtime context extension system for Optique parsers.
4
+ *
5
+ * This module provides the annotations system that allows external runtime data
6
+ * to be passed to parsers during the parsing session. This enables use cases like
7
+ * config file fallbacks, environment-based validation, and shared context.
8
+ *
9
+ * @module
10
+ * @since 0.10.0
11
+ */
12
+ /**
13
+ * Annotation key symbol for storing data in parser state.
14
+ * @since 0.10.0
15
+ */
16
+ declare const annotationKey: unique symbol;
17
+ /**
18
+ * Internal marker attached during the first pass of `runWith()` so wrappers
19
+ * with side effects can defer work until two-pass contexts have resolved.
20
+ *
21
+ * @internal
22
+ */
23
+ declare const firstPassAnnotationKey: unique symbol;
24
+ /**
25
+ * Internal key for preserving primitive parser state values when annotations
26
+ * are injected into non-object states.
27
+ * @internal
28
+ */
29
+ declare const annotationStateValueKey: unique symbol;
30
+ /**
31
+ * Internal marker key that indicates annotation wrapping was injected by
32
+ * Optique internals for non-object states.
33
+ * @internal
34
+ */
35
+ declare const annotationWrapperKey: unique symbol;
3
36
  /**
4
37
  * Annotations that can be passed to parsers during execution.
5
38
  * Allows external packages to provide additional data that parsers can access
@@ -53,7 +86,7 @@ declare function getAnnotations(state: unknown): Annotations | undefined;
53
86
  * @returns The target array, with annotations copied when available.
54
87
  * @internal
55
88
  */
56
-
89
+ declare function annotateFreshArray<T>(source: unknown, target: readonly T[]): readonly T[];
57
90
  /**
58
91
  * Propagates annotations from one parser state to another.
59
92
  *
@@ -85,7 +118,7 @@ declare function inheritAnnotations<T>(source: unknown, target: T): T;
85
118
  * @returns `true` when the record has at least one own symbol key.
86
119
  * @internal
87
120
  */
88
-
121
+ declare function hasMeaningfulAnnotations(annotations: Annotations | null | undefined): annotations is Annotations;
89
122
  /**
90
123
  * Injects annotations into parser state while preserving state shape.
91
124
  *
@@ -111,7 +144,16 @@ declare function injectAnnotations<TState>(state: TState, annotations: Annotatio
111
144
  * otherwise the original value.
112
145
  * @internal
113
146
  */
114
-
147
+ declare function unwrapInjectedAnnotationWrapper<T>(value: T): T;
148
+ /**
149
+ * Returns whether the given value is an internal primitive-state annotation
150
+ * wrapper that was injected by Optique.
151
+ *
152
+ * @param value Value to check.
153
+ * @returns `true` if the value is an injected internal wrapper.
154
+ * @internal
155
+ */
156
+ declare function isInjectedAnnotationWrapper(value: unknown): boolean;
115
157
  /**
116
158
  * Returns whether the given value is an injected annotation state wrapper.
117
159
  *
@@ -137,4 +179,4 @@ declare function isInjectedAnnotationState(value: unknown): boolean;
137
179
  */
138
180
  declare function unwrapInjectedAnnotationState<T>(value: T): T;
139
181
  //#endregion
140
- export { Annotations, ParseOptions, getAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwrapInjectedAnnotationState };
182
+ export { Annotations, ParseOptions, annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, isInjectedAnnotationWrapper, unwrapInjectedAnnotationState, unwrapInjectedAnnotationWrapper };
@@ -303,4 +303,4 @@ function unwrapInjectedAnnotationState(value) {
303
303
  }
304
304
 
305
305
  //#endregion
306
- export { annotateFreshArray, annotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, isInjectedAnnotationWrapper, unwrapInjectedAnnotationState, unwrapInjectedAnnotationWrapper };
306
+ export { annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, isInjectedAnnotationWrapper, unwrapInjectedAnnotationState, unwrapInjectedAnnotationWrapper };
@@ -0,0 +1,16 @@
1
+
2
+ //#region src/internal/command-alias.ts
3
+ /**
4
+ * Internal key used to bypass duplicate leading command name validation when
5
+ * composing built-in meta commands with user parsers.
6
+ */
7
+ const allowDuplicateLeadingCommandNamesKey = Symbol("allowDuplicateLeadingCommandNames");
8
+ /**
9
+ * Internal command() option key for aliases that are accepted by parsing but
10
+ * omitted from completion and typo-suggestion display.
11
+ */
12
+ const hiddenCommandAliasesKey = Symbol("hiddenCommandAliases");
13
+
14
+ //#endregion
15
+ exports.allowDuplicateLeadingCommandNamesKey = allowDuplicateLeadingCommandNamesKey;
16
+ exports.hiddenCommandAliasesKey = hiddenCommandAliasesKey;
@@ -0,0 +1,14 @@
1
+ //#region src/internal/command-alias.ts
2
+ /**
3
+ * Internal key used to bypass duplicate leading command name validation when
4
+ * composing built-in meta commands with user parsers.
5
+ */
6
+ const allowDuplicateLeadingCommandNamesKey = Symbol("allowDuplicateLeadingCommandNames");
7
+ /**
8
+ * Internal command() option key for aliases that are accepted by parsing but
9
+ * omitted from completion and typo-suggestion display.
10
+ */
11
+ const hiddenCommandAliasesKey = Symbol("hiddenCommandAliases");
12
+
13
+ //#endregion
14
+ export { allowDuplicateLeadingCommandNamesKey, hiddenCommandAliasesKey };
@@ -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;