@optique/core 1.0.0-dev.1901 → 1.0.0-dev.1970

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 (77) hide show
  1. package/dist/annotation-state.cjs +115 -60
  2. package/dist/annotation-state.d.cts +24 -0
  3. package/dist/annotation-state.d.ts +24 -0
  4. package/dist/annotation-state.js +114 -60
  5. package/dist/annotations.cjs +2 -267
  6. package/dist/annotations.d.cts +2 -152
  7. package/dist/annotations.d.ts +2 -152
  8. package/dist/annotations.js +2 -256
  9. package/dist/completion.d.cts +1 -1
  10. package/dist/completion.d.ts +1 -1
  11. package/dist/constructs.cjs +206 -238
  12. package/dist/constructs.d.cts +1 -1
  13. package/dist/constructs.d.ts +1 -1
  14. package/dist/constructs.js +96 -128
  15. package/dist/context.d.cts +1 -1
  16. package/dist/context.d.ts +1 -1
  17. package/dist/dependency-metadata.cjs +1 -1
  18. package/dist/dependency-metadata.d.cts +1 -1
  19. package/dist/dependency-metadata.d.ts +1 -1
  20. package/dist/dependency-metadata.js +1 -1
  21. package/dist/dependency-runtime.cjs +2 -2
  22. package/dist/dependency-runtime.js +2 -2
  23. package/dist/dependency.cjs +7 -1111
  24. package/dist/dependency.d.cts +2 -838
  25. package/dist/dependency.d.ts +2 -838
  26. package/dist/dependency.js +2 -1078
  27. package/dist/execution-context.cjs +56 -0
  28. package/dist/execution-context.js +53 -0
  29. package/dist/extension.cjs +87 -0
  30. package/dist/extension.d.cts +97 -0
  31. package/dist/extension.d.ts +97 -0
  32. package/dist/extension.js +76 -0
  33. package/dist/facade.cjs +19 -19
  34. package/dist/facade.d.cts +1 -1
  35. package/dist/facade.d.ts +1 -1
  36. package/dist/facade.js +19 -19
  37. package/dist/index.cjs +4 -41
  38. package/dist/index.d.cts +7 -7
  39. package/dist/index.d.ts +7 -7
  40. package/dist/index.js +5 -5
  41. package/dist/internal/annotations.cjs +316 -0
  42. package/dist/internal/annotations.d.cts +140 -0
  43. package/dist/internal/annotations.d.ts +140 -0
  44. package/dist/internal/annotations.js +306 -0
  45. package/dist/internal/dependency.cjs +984 -0
  46. package/dist/internal/dependency.d.cts +539 -0
  47. package/dist/internal/dependency.d.ts +539 -0
  48. package/dist/internal/dependency.js +964 -0
  49. package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
  50. package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
  51. package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
  52. package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
  53. package/dist/internal/parser.cjs +728 -0
  54. package/dist/internal/parser.d.cts +947 -0
  55. package/dist/internal/parser.d.ts +947 -0
  56. package/dist/internal/parser.js +711 -0
  57. package/dist/modifiers.cjs +108 -125
  58. package/dist/modifiers.d.cts +1 -1
  59. package/dist/modifiers.d.ts +1 -1
  60. package/dist/modifiers.js +92 -109
  61. package/dist/parser.cjs +11 -743
  62. package/dist/parser.d.cts +3 -991
  63. package/dist/parser.d.ts +3 -991
  64. package/dist/parser.js +2 -704
  65. package/dist/phase2-seed.cjs +4 -4
  66. package/dist/phase2-seed.js +4 -4
  67. package/dist/primitives.cjs +39 -74
  68. package/dist/primitives.d.cts +1 -1
  69. package/dist/primitives.d.ts +1 -1
  70. package/dist/primitives.js +26 -61
  71. package/dist/program.d.cts +1 -1
  72. package/dist/program.d.ts +1 -1
  73. package/dist/valueparser.cjs +23 -23
  74. package/dist/valueparser.d.cts +3 -3
  75. package/dist/valueparser.d.ts +3 -3
  76. package/dist/valueparser.js +23 -23
  77. package/package.json +9 -9
@@ -0,0 +1,56 @@
1
+
2
+ //#region src/execution-context.ts
3
+ /**
4
+ * Appends a child parser segment to the current execution path.
5
+ * @internal
6
+ */
7
+ function withChildExecPath(exec, segment) {
8
+ if (exec == null) return void 0;
9
+ return {
10
+ ...exec,
11
+ path: [...exec.path ?? [], segment]
12
+ };
13
+ }
14
+ /**
15
+ * Merges child-owned execution fields back into the parent execution context.
16
+ * @internal
17
+ */
18
+ function mergeChildExec(parent, child) {
19
+ if (parent == null) return child;
20
+ if (child == null) return parent;
21
+ return {
22
+ ...parent,
23
+ trace: child.trace ?? parent.trace,
24
+ dependencyRuntime: child.dependencyRuntime ?? parent.dependencyRuntime,
25
+ dependencyRegistry: child.dependencyRegistry ?? parent.dependencyRegistry,
26
+ commandPath: child.commandPath ?? parent.commandPath,
27
+ preCompletedByParser: child.preCompletedByParser ?? parent.preCompletedByParser,
28
+ excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
29
+ };
30
+ }
31
+ /**
32
+ * Creates a child parser context while keeping flat and nested execution data
33
+ * aligned.
34
+ * @internal
35
+ */
36
+ function withChildContext(context, segment, state, usage) {
37
+ const exec = withChildExecPath(context.exec, segment);
38
+ const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
39
+ return {
40
+ ...context,
41
+ state,
42
+ ...usage != null ? { usage } : {},
43
+ ...exec != null ? {
44
+ exec: dependencyRegistry === exec.dependencyRegistry ? exec : {
45
+ ...exec,
46
+ dependencyRegistry
47
+ },
48
+ dependencyRegistry
49
+ } : {}
50
+ };
51
+ }
52
+
53
+ //#endregion
54
+ exports.mergeChildExec = mergeChildExec;
55
+ exports.withChildContext = withChildContext;
56
+ exports.withChildExecPath = withChildExecPath;
@@ -0,0 +1,53 @@
1
+ //#region src/execution-context.ts
2
+ /**
3
+ * Appends a child parser segment to the current execution path.
4
+ * @internal
5
+ */
6
+ function withChildExecPath(exec, segment) {
7
+ if (exec == null) return void 0;
8
+ return {
9
+ ...exec,
10
+ path: [...exec.path ?? [], segment]
11
+ };
12
+ }
13
+ /**
14
+ * Merges child-owned execution fields back into the parent execution context.
15
+ * @internal
16
+ */
17
+ function mergeChildExec(parent, child) {
18
+ if (parent == null) return child;
19
+ if (child == null) return parent;
20
+ return {
21
+ ...parent,
22
+ trace: child.trace ?? parent.trace,
23
+ dependencyRuntime: child.dependencyRuntime ?? parent.dependencyRuntime,
24
+ dependencyRegistry: child.dependencyRegistry ?? parent.dependencyRegistry,
25
+ commandPath: child.commandPath ?? parent.commandPath,
26
+ preCompletedByParser: child.preCompletedByParser ?? parent.preCompletedByParser,
27
+ excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
28
+ };
29
+ }
30
+ /**
31
+ * Creates a child parser context while keeping flat and nested execution data
32
+ * aligned.
33
+ * @internal
34
+ */
35
+ function withChildContext(context, segment, state, usage) {
36
+ const exec = withChildExecPath(context.exec, segment);
37
+ const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
38
+ return {
39
+ ...context,
40
+ state,
41
+ ...usage != null ? { usage } : {},
42
+ ...exec != null ? {
43
+ exec: dependencyRegistry === exec.dependencyRegistry ? exec : {
44
+ ...exec,
45
+ dependencyRegistry
46
+ },
47
+ dependencyRegistry
48
+ } : {}
49
+ };
50
+ }
51
+
52
+ //#endregion
53
+ export { mergeChildExec, withChildContext, withChildExecPath };
@@ -0,0 +1,87 @@
1
+ const require_annotations = require('./internal/annotations.cjs');
2
+ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
3
+ const require_parser = require('./internal/parser.cjs');
4
+ const require_annotation_state = require('./annotation-state.cjs');
5
+
6
+ //#region src/extension.ts
7
+ const emptyTraits = Object.freeze({});
8
+ /**
9
+ * Defines stable extension traits on a parser object.
10
+ *
11
+ * @param parser The parser object to annotate.
12
+ * @param traits Traits to enable.
13
+ * @throws {TypeError} If a trait property cannot be defined on `parser`.
14
+ * @since 1.0.0
15
+ */
16
+ function defineTraits(parser, traits) {
17
+ if (traits.inheritsAnnotations === true) require_parser.defineInheritedAnnotationParser(parser);
18
+ if (traits.completesFromSource === true) Object.defineProperty(parser, require_parser.unmatchedNonCliDependencySourceStateMarker, {
19
+ value: true,
20
+ configurable: true,
21
+ enumerable: true
22
+ });
23
+ if (traits.requiresSourceBinding === true) Object.defineProperty(parser, require_parser.annotationWrapperRequiresSourceBindingKey, {
24
+ value: true,
25
+ configurable: true,
26
+ enumerable: false
27
+ });
28
+ }
29
+ /**
30
+ * Reads the stable extension traits defined on a parser object.
31
+ *
32
+ * @param parser The parser object to inspect.
33
+ * @returns The enabled traits. Returns an empty object when none are set.
34
+ * @since 1.0.0
35
+ */
36
+ function getTraits(parser) {
37
+ const traits = {
38
+ ...Reflect.get(parser, require_parser.inheritParentAnnotationsKey) === true ? { inheritsAnnotations: true } : {},
39
+ ...Reflect.get(parser, require_parser.unmatchedNonCliDependencySourceStateMarker) === true ? { completesFromSource: true } : {},
40
+ ...Reflect.get(parser, require_parser.annotationWrapperRequiresSourceBindingKey) === true ? { requiresSourceBinding: true } : {}
41
+ };
42
+ return Object.keys(traits).length > 0 ? traits : emptyTraits;
43
+ }
44
+ /**
45
+ * Delegates suggest-time runtime nodes to an inner parser while preserving an
46
+ * outer parser's own source metadata node.
47
+ *
48
+ * @param innerParser The wrapped parser that owns the underlying nodes.
49
+ * @param outerParser The outer parser that may contribute its own source node.
50
+ * @param state The outer parser state.
51
+ * @param path The parser path within the parse tree.
52
+ * @param innerState The state to use when collecting inner nodes.
53
+ * @param position Whether the outer node is appended or prepended.
54
+ * @returns The composed runtime nodes.
55
+ * @since 1.0.0
56
+ */
57
+ function delegateSuggestNodes(innerParser, outerParser, state, path, innerState, position = "append") {
58
+ return require_parser.getDelegatingSuggestRuntimeNodes(innerParser, outerParser, state, path, innerState, position);
59
+ }
60
+ /**
61
+ * Maps the source capability of a parser's dependency metadata while
62
+ * preserving any derived or transform capabilities unchanged.
63
+ *
64
+ * @param parser The parser whose source metadata should be transformed.
65
+ * @param mapSource Function that transforms the source capability.
66
+ * @returns The dependency metadata with its source capability transformed when
67
+ * present; otherwise the original dependency metadata, or
68
+ * `undefined` when the parser has no dependency metadata.
69
+ * @since 1.0.0
70
+ */
71
+ function mapSourceMetadata(parser, mapSource) {
72
+ return require_parser.composeWrappedSourceMetadata(parser.dependencyMetadata, mapSource);
73
+ }
74
+
75
+ //#endregion
76
+ exports.defineTraits = defineTraits;
77
+ exports.delegateSuggestNodes = delegateSuggestNodes;
78
+ exports.dispatchByMode = require_mode_dispatch.dispatchByMode;
79
+ exports.getTraits = getTraits;
80
+ exports.inheritAnnotations = require_annotations.inheritAnnotations;
81
+ exports.injectAnnotations = require_annotations.injectAnnotations;
82
+ exports.isInjectedAnnotationState = require_annotations.isInjectedAnnotationState;
83
+ exports.mapModeValue = require_mode_dispatch.mapModeValue;
84
+ exports.mapSourceMetadata = mapSourceMetadata;
85
+ exports.unwrapInjectedAnnotationState = require_annotations.unwrapInjectedAnnotationState;
86
+ exports.withAnnotationView = require_annotation_state.withAnnotationView;
87
+ exports.wrapForMode = require_mode_dispatch.wrapForMode;
@@ -0,0 +1,97 @@
1
+ import { inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwrapInjectedAnnotationState } from "./internal/annotations.cjs";
2
+ import { Mode, Parser } from "./internal/parser.cjs";
3
+ import { withAnnotationView } from "./annotation-state.cjs";
4
+ import { dispatchByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.cjs";
5
+
6
+ //#region src/extension.d.ts
7
+
8
+ /**
9
+ * Stable trait flags for custom parser extensions.
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ interface ParserTraits {
14
+ /**
15
+ * Whether parent-state annotations should be injected into rebuilt child
16
+ * states instead of relying on structural inheritance.
17
+ */
18
+ readonly inheritsAnnotations?: true;
19
+ /**
20
+ * Whether a missing CLI state can still complete from a source-backed
21
+ * fallback such as config or environment data.
22
+ */
23
+ readonly completesFromSource?: true;
24
+ /**
25
+ * Whether annotation-only primitive states should count as completable only
26
+ * when they come from a nested source-bound parser.
27
+ */
28
+ readonly requiresSourceBinding?: true;
29
+ }
30
+ /**
31
+ * Suggest-time runtime node used to seed dependency-aware completion.
32
+ *
33
+ * @since 1.0.0
34
+ */
35
+ interface SuggestNode {
36
+ /** Path from the root parser to this node. */
37
+ readonly path: readonly PropertyKey[];
38
+ /** The parser whose dependency metadata should be inspected. */
39
+ readonly parser: Parser<Mode, unknown, unknown>;
40
+ /** Current parser state for this node. */
41
+ readonly state: unknown;
42
+ /** Whether this node reflects explicit input consumption. */
43
+ readonly matched?: boolean;
44
+ /** Snapshotted default dependency values for derived parsers. */
45
+ readonly defaultDependencyValues?: readonly unknown[];
46
+ }
47
+ /**
48
+ * Public view of a parser's source capability metadata.
49
+ *
50
+ * @since 1.0.0
51
+ */
52
+ type ParserSourceMetadata<M extends Mode = Mode, TValue = unknown, TState = unknown> = NonNullable<NonNullable<Parser<M, TValue, TState>["dependencyMetadata"]>["source"]>;
53
+ /**
54
+ * Defines stable extension traits on a parser object.
55
+ *
56
+ * @param parser The parser object to annotate.
57
+ * @param traits Traits to enable.
58
+ * @throws {TypeError} If a trait property cannot be defined on `parser`.
59
+ * @since 1.0.0
60
+ */
61
+ declare function defineTraits(parser: object, traits: ParserTraits): void;
62
+ /**
63
+ * Reads the stable extension traits defined on a parser object.
64
+ *
65
+ * @param parser The parser object to inspect.
66
+ * @returns The enabled traits. Returns an empty object when none are set.
67
+ * @since 1.0.0
68
+ */
69
+ declare function getTraits(parser: object): ParserTraits;
70
+ /**
71
+ * Delegates suggest-time runtime nodes to an inner parser while preserving an
72
+ * outer parser's own source metadata node.
73
+ *
74
+ * @param innerParser The wrapped parser that owns the underlying nodes.
75
+ * @param outerParser The outer parser that may contribute its own source node.
76
+ * @param state The outer parser state.
77
+ * @param path The parser path within the parse tree.
78
+ * @param innerState The state to use when collecting inner nodes.
79
+ * @param position Whether the outer node is appended or prepended.
80
+ * @returns The composed runtime nodes.
81
+ * @since 1.0.0
82
+ */
83
+ declare function delegateSuggestNodes<TInnerState>(innerParser: Parser<Mode, unknown, TInnerState>, outerParser: Parser<Mode, unknown, unknown>, state: unknown, path: readonly PropertyKey[], innerState: TInnerState, position?: "append" | "prepend"): readonly SuggestNode[];
84
+ /**
85
+ * Maps the source capability of a parser's dependency metadata while
86
+ * preserving any derived or transform capabilities unchanged.
87
+ *
88
+ * @param parser The parser whose source metadata should be transformed.
89
+ * @param mapSource Function that transforms the source capability.
90
+ * @returns The dependency metadata with its source capability transformed when
91
+ * present; otherwise the original dependency metadata, or
92
+ * `undefined` when the parser has no dependency metadata.
93
+ * @since 1.0.0
94
+ */
95
+ declare function mapSourceMetadata<M extends Mode, TValue, TState>(parser: Pick<Parser<M, TValue, TState>, "dependencyMetadata">, mapSource: (source: ParserSourceMetadata<M, TValue, TState>) => ParserSourceMetadata<M, TValue, TState>): Parser<M, TValue, TState>["dependencyMetadata"] | undefined;
96
+ //#endregion
97
+ export { ParserSourceMetadata, ParserTraits, SuggestNode, defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
@@ -0,0 +1,97 @@
1
+ import { inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwrapInjectedAnnotationState } from "./internal/annotations.js";
2
+ import { Mode, Parser } from "./internal/parser.js";
3
+ import { withAnnotationView } from "./annotation-state.js";
4
+ import { dispatchByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
5
+
6
+ //#region src/extension.d.ts
7
+
8
+ /**
9
+ * Stable trait flags for custom parser extensions.
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ interface ParserTraits {
14
+ /**
15
+ * Whether parent-state annotations should be injected into rebuilt child
16
+ * states instead of relying on structural inheritance.
17
+ */
18
+ readonly inheritsAnnotations?: true;
19
+ /**
20
+ * Whether a missing CLI state can still complete from a source-backed
21
+ * fallback such as config or environment data.
22
+ */
23
+ readonly completesFromSource?: true;
24
+ /**
25
+ * Whether annotation-only primitive states should count as completable only
26
+ * when they come from a nested source-bound parser.
27
+ */
28
+ readonly requiresSourceBinding?: true;
29
+ }
30
+ /**
31
+ * Suggest-time runtime node used to seed dependency-aware completion.
32
+ *
33
+ * @since 1.0.0
34
+ */
35
+ interface SuggestNode {
36
+ /** Path from the root parser to this node. */
37
+ readonly path: readonly PropertyKey[];
38
+ /** The parser whose dependency metadata should be inspected. */
39
+ readonly parser: Parser<Mode, unknown, unknown>;
40
+ /** Current parser state for this node. */
41
+ readonly state: unknown;
42
+ /** Whether this node reflects explicit input consumption. */
43
+ readonly matched?: boolean;
44
+ /** Snapshotted default dependency values for derived parsers. */
45
+ readonly defaultDependencyValues?: readonly unknown[];
46
+ }
47
+ /**
48
+ * Public view of a parser's source capability metadata.
49
+ *
50
+ * @since 1.0.0
51
+ */
52
+ type ParserSourceMetadata<M extends Mode = Mode, TValue = unknown, TState = unknown> = NonNullable<NonNullable<Parser<M, TValue, TState>["dependencyMetadata"]>["source"]>;
53
+ /**
54
+ * Defines stable extension traits on a parser object.
55
+ *
56
+ * @param parser The parser object to annotate.
57
+ * @param traits Traits to enable.
58
+ * @throws {TypeError} If a trait property cannot be defined on `parser`.
59
+ * @since 1.0.0
60
+ */
61
+ declare function defineTraits(parser: object, traits: ParserTraits): void;
62
+ /**
63
+ * Reads the stable extension traits defined on a parser object.
64
+ *
65
+ * @param parser The parser object to inspect.
66
+ * @returns The enabled traits. Returns an empty object when none are set.
67
+ * @since 1.0.0
68
+ */
69
+ declare function getTraits(parser: object): ParserTraits;
70
+ /**
71
+ * Delegates suggest-time runtime nodes to an inner parser while preserving an
72
+ * outer parser's own source metadata node.
73
+ *
74
+ * @param innerParser The wrapped parser that owns the underlying nodes.
75
+ * @param outerParser The outer parser that may contribute its own source node.
76
+ * @param state The outer parser state.
77
+ * @param path The parser path within the parse tree.
78
+ * @param innerState The state to use when collecting inner nodes.
79
+ * @param position Whether the outer node is appended or prepended.
80
+ * @returns The composed runtime nodes.
81
+ * @since 1.0.0
82
+ */
83
+ declare function delegateSuggestNodes<TInnerState>(innerParser: Parser<Mode, unknown, TInnerState>, outerParser: Parser<Mode, unknown, unknown>, state: unknown, path: readonly PropertyKey[], innerState: TInnerState, position?: "append" | "prepend"): readonly SuggestNode[];
84
+ /**
85
+ * Maps the source capability of a parser's dependency metadata while
86
+ * preserving any derived or transform capabilities unchanged.
87
+ *
88
+ * @param parser The parser whose source metadata should be transformed.
89
+ * @param mapSource Function that transforms the source capability.
90
+ * @returns The dependency metadata with its source capability transformed when
91
+ * present; otherwise the original dependency metadata, or
92
+ * `undefined` when the parser has no dependency metadata.
93
+ * @since 1.0.0
94
+ */
95
+ declare function mapSourceMetadata<M extends Mode, TValue, TState>(parser: Pick<Parser<M, TValue, TState>, "dependencyMetadata">, mapSource: (source: ParserSourceMetadata<M, TValue, TState>) => ParserSourceMetadata<M, TValue, TState>): Parser<M, TValue, TState>["dependencyMetadata"] | undefined;
96
+ //#endregion
97
+ export { ParserSourceMetadata, ParserTraits, SuggestNode, defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
@@ -0,0 +1,76 @@
1
+ import { inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwrapInjectedAnnotationState } from "./internal/annotations.js";
2
+ import { dispatchByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
3
+ import { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, defineInheritedAnnotationParser, getDelegatingSuggestRuntimeNodes, inheritParentAnnotationsKey, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
4
+ import { withAnnotationView } from "./annotation-state.js";
5
+
6
+ //#region src/extension.ts
7
+ const emptyTraits = Object.freeze({});
8
+ /**
9
+ * Defines stable extension traits on a parser object.
10
+ *
11
+ * @param parser The parser object to annotate.
12
+ * @param traits Traits to enable.
13
+ * @throws {TypeError} If a trait property cannot be defined on `parser`.
14
+ * @since 1.0.0
15
+ */
16
+ function defineTraits(parser, traits) {
17
+ if (traits.inheritsAnnotations === true) defineInheritedAnnotationParser(parser);
18
+ if (traits.completesFromSource === true) Object.defineProperty(parser, unmatchedNonCliDependencySourceStateMarker, {
19
+ value: true,
20
+ configurable: true,
21
+ enumerable: true
22
+ });
23
+ if (traits.requiresSourceBinding === true) Object.defineProperty(parser, annotationWrapperRequiresSourceBindingKey, {
24
+ value: true,
25
+ configurable: true,
26
+ enumerable: false
27
+ });
28
+ }
29
+ /**
30
+ * Reads the stable extension traits defined on a parser object.
31
+ *
32
+ * @param parser The parser object to inspect.
33
+ * @returns The enabled traits. Returns an empty object when none are set.
34
+ * @since 1.0.0
35
+ */
36
+ function getTraits(parser) {
37
+ const traits = {
38
+ ...Reflect.get(parser, inheritParentAnnotationsKey) === true ? { inheritsAnnotations: true } : {},
39
+ ...Reflect.get(parser, unmatchedNonCliDependencySourceStateMarker) === true ? { completesFromSource: true } : {},
40
+ ...Reflect.get(parser, annotationWrapperRequiresSourceBindingKey) === true ? { requiresSourceBinding: true } : {}
41
+ };
42
+ return Object.keys(traits).length > 0 ? traits : emptyTraits;
43
+ }
44
+ /**
45
+ * Delegates suggest-time runtime nodes to an inner parser while preserving an
46
+ * outer parser's own source metadata node.
47
+ *
48
+ * @param innerParser The wrapped parser that owns the underlying nodes.
49
+ * @param outerParser The outer parser that may contribute its own source node.
50
+ * @param state The outer parser state.
51
+ * @param path The parser path within the parse tree.
52
+ * @param innerState The state to use when collecting inner nodes.
53
+ * @param position Whether the outer node is appended or prepended.
54
+ * @returns The composed runtime nodes.
55
+ * @since 1.0.0
56
+ */
57
+ function delegateSuggestNodes(innerParser, outerParser, state, path, innerState, position = "append") {
58
+ return getDelegatingSuggestRuntimeNodes(innerParser, outerParser, state, path, innerState, position);
59
+ }
60
+ /**
61
+ * Maps the source capability of a parser's dependency metadata while
62
+ * preserving any derived or transform capabilities unchanged.
63
+ *
64
+ * @param parser The parser whose source metadata should be transformed.
65
+ * @param mapSource Function that transforms the source capability.
66
+ * @returns The dependency metadata with its source capability transformed when
67
+ * present; otherwise the original dependency metadata, or
68
+ * `undefined` when the parser has no dependency metadata.
69
+ * @since 1.0.0
70
+ */
71
+ function mapSourceMetadata(parser, mapSource) {
72
+ return composeWrappedSourceMetadata(parser.dependencyMetadata, mapSource);
73
+ }
74
+
75
+ //#endregion
76
+ export { defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
package/dist/facade.cjs CHANGED
@@ -1,18 +1,18 @@
1
- const require_annotations = require('./annotations.cjs');
1
+ const require_annotations = require('./internal/annotations.cjs');
2
2
  const require_message = require('./message.cjs');
3
3
  const require_completion = require('./completion.cjs');
4
4
  const require_validate = require('./validate.cjs');
5
5
  const require_usage = require('./usage.cjs');
6
6
  const require_doc = require('./doc.cjs');
7
- const require_mode_dispatch = require('./mode-dispatch.cjs');
7
+ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
8
8
  const require_dependency_runtime = require('./dependency-runtime.cjs');
9
9
  const require_input_trace = require('./input-trace.cjs');
10
+ const require_parser = require('./internal/parser.cjs');
10
11
  const require_phase2_seed = require('./phase2-seed.cjs');
12
+ const require_constructs = require('./constructs.cjs');
11
13
  const require_modifiers = require('./modifiers.cjs');
12
14
  const require_valueparser = require('./valueparser.cjs');
13
15
  const require_primitives = require('./primitives.cjs');
14
- const require_parser = require('./parser.cjs');
15
- const require_constructs = require('./constructs.cjs');
16
16
 
17
17
  //#region src/facade.ts
18
18
  const SuppressedErrorCtor = typeof SuppressedError === "function" ? SuppressedError : (() => {
@@ -390,7 +390,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
390
390
  const effectiveVersionOptionNames = versionOptionNames ?? ["--version"];
391
391
  if (helpParsers.helpOption) {
392
392
  const lenientHelpParser = {
393
- $mode: "sync",
393
+ mode: "sync",
394
394
  $valueType: [],
395
395
  $stateType: [],
396
396
  priority: 200,
@@ -471,7 +471,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
471
471
  }
472
472
  if (versionParsers.versionOption) {
473
473
  const lenientVersionParser = {
474
- $mode: "sync",
474
+ mode: "sync",
475
475
  $valueType: [],
476
476
  $stateType: [],
477
477
  priority: 200,
@@ -733,7 +733,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
733
733
  sectionOrder
734
734
  }));
735
735
  }
736
- return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
736
+ return require_mode_dispatch.dispatchByMode(parser.mode, () => {
737
737
  const result = callOnError(1);
738
738
  if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
739
739
  return result;
@@ -750,7 +750,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
750
750
  colors,
751
751
  quotes: !colors
752
752
  }));
753
- return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
753
+ return require_mode_dispatch.dispatchByMode(parser.mode, () => {
754
754
  const result = callOnError(1);
755
755
  if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
756
756
  return result;
@@ -760,13 +760,13 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
760
760
  const completionArg = isOptionMode ? completionOptionDisplayName ?? "--completion" : completionCommandDisplayName ?? "completion";
761
761
  const script = shell.generateScript(programName, [completionArg, shellName]);
762
762
  stdout(script);
763
- return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
763
+ return require_mode_dispatch.dispatchByMode(parser.mode, () => {
764
764
  const result = callOnCompletion(0);
765
765
  if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
766
766
  return result;
767
767
  }, async () => callOnCompletion(0));
768
768
  }
769
- return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
769
+ return require_mode_dispatch.dispatchByMode(parser.mode, () => {
770
770
  const syncParser = parser;
771
771
  const suggestions = require_parser.suggest(syncParser, args);
772
772
  for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
@@ -1095,7 +1095,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1095
1095
  default: throw new RunParserError("Unexpected parse result type");
1096
1096
  }
1097
1097
  };
1098
- const parserMode = parser.$mode;
1098
+ const parserMode = parser.mode;
1099
1099
  return require_mode_dispatch.dispatchByMode(parserMode, () => {
1100
1100
  const attempted = attemptParseSync(parser, args);
1101
1101
  const classified = attempted.kind === "success" ? {
@@ -1135,7 +1135,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1135
1135
  * @since 0.9.0
1136
1136
  */
1137
1137
  function runParserSync(parser, programName, args, options) {
1138
- if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runParserSync(). Use runParser() or runParserAsync() instead.");
1138
+ if (parser.mode !== "sync") throw new TypeError("Cannot use an async parser with runParserSync(). Use runParser() or runParserAsync() instead.");
1139
1139
  return runParser(parser, programName, args, options);
1140
1140
  }
1141
1141
  /**
@@ -1402,24 +1402,24 @@ async function runWithBody(parser, programName, contexts, args, options) {
1402
1402
  if (shouldProbeEarlyExit(options, needsTwoPhase)) {
1403
1403
  const earlyExitParser = injectAnnotationsIntoParser(parser, phase1Annotations);
1404
1404
  if (await needsEarlyExitAsync(earlyExitParser, args, options)) {
1405
- if (parser.$mode === "async") return runParser(earlyExitParser, programName, args, options);
1405
+ if (parser.mode === "async") return runParser(earlyExitParser, programName, args, options);
1406
1406
  return Promise.resolve(runParser(earlyExitParser, programName, args, options));
1407
1407
  }
1408
1408
  }
1409
1409
  const augmentedParser1 = injectAnnotationsIntoParser(parser, phase1Annotations);
1410
1410
  if (!needsTwoPhase) {
1411
- if (parser.$mode === "async") return runParser(augmentedParser1, programName, args, options);
1411
+ if (parser.mode === "async") return runParser(augmentedParser1, programName, args, options);
1412
1412
  return Promise.resolve(runParser(augmentedParser1, programName, args, options));
1413
1413
  }
1414
- const firstPassSeed = await require_mode_dispatch.dispatchByMode(parser.$mode, () => extractPhase2SeedSync(augmentedParser1, args), () => extractPhase2SeedAsync(augmentedParser1, args));
1414
+ const firstPassSeed = await require_mode_dispatch.dispatchByMode(parser.mode, () => extractPhase2SeedSync(augmentedParser1, args), () => extractPhase2SeedAsync(augmentedParser1, args));
1415
1415
  if (firstPassSeed == null) {
1416
1416
  const fallbackParser = injectAnnotationsIntoParser(parser, phase1Annotations);
1417
- if (parser.$mode === "async") return runParser(fallbackParser, programName, args, options);
1417
+ if (parser.mode === "async") return runParser(fallbackParser, programName, args, options);
1418
1418
  return Promise.resolve(runParser(fallbackParser, programName, args, options));
1419
1419
  }
1420
1420
  const { annotations: finalAnnotations } = await collectFinalAnnotations(contexts, phase1Snapshots, firstPassSeed.value, ctxOptions, firstPassSeed.deferred, firstPassSeed.deferredKeys);
1421
1421
  const augmentedParser2 = injectAnnotationsIntoParser(parser, finalAnnotations);
1422
- if (parser.$mode === "async") return runParser(augmentedParser2, programName, args, options);
1422
+ if (parser.mode === "async") return runParser(augmentedParser2, programName, args, options);
1423
1423
  return Promise.resolve(runParser(augmentedParser2, programName, args, options));
1424
1424
  }
1425
1425
  /**
@@ -1490,7 +1490,7 @@ async function runWithBody(parser, programName, contexts, args, options) {
1490
1490
  async function runWith(parser, programName, contexts, options) {
1491
1491
  const args = options?.args ?? [];
1492
1492
  if (contexts.length === 0) {
1493
- if (parser.$mode === "async") return runParser(parser, programName, args, options);
1493
+ if (parser.mode === "async") return runParser(parser, programName, args, options);
1494
1494
  return Promise.resolve(runParser(parser, programName, args, options));
1495
1495
  }
1496
1496
  let result;
@@ -1567,7 +1567,7 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
1567
1567
  * @since 0.10.0
1568
1568
  */
1569
1569
  function runWithSync(parser, programName, contexts, options) {
1570
- if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runWithSync(). Use runWith() or runWithAsync() instead.");
1570
+ if (parser.mode !== "sync") throw new TypeError("Cannot use an async parser with runWithSync(). Use runWith() or runWithAsync() instead.");
1571
1571
  const args = options?.args ?? [];
1572
1572
  if (contexts.length === 0) return runParser(parser, programName, args, options);
1573
1573
  let result;
package/dist/facade.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Message } from "./message.cjs";
2
2
  import { HiddenVisibility, OptionName } from "./usage.cjs";
3
3
  import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "./doc.cjs";
4
- import { InferMode, InferValue, Mode, ModeValue, Parser } from "./parser.cjs";
4
+ import { InferMode, InferValue, Mode, ModeValue, Parser } from "./internal/parser.cjs";
5
5
  import { ShellCompletion } from "./completion.cjs";
6
6
  import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.cjs";
7
7
  import { Program } from "./program.cjs";
package/dist/facade.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Message } from "./message.js";
2
2
  import { HiddenVisibility, OptionName } from "./usage.js";
3
3
  import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "./doc.js";
4
- import { InferMode, InferValue, Mode, ModeValue, Parser } from "./parser.js";
4
+ import { InferMode, InferValue, Mode, ModeValue, Parser } from "./internal/parser.js";
5
5
  import { ShellCompletion } from "./completion.js";
6
6
  import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.js";
7
7
  import { Program } from "./program.js";