@optique/core 1.1.0-dev.2096 → 1.1.0-dev.2148
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
|
@@ -49,7 +49,14 @@ interface DependencyResolution {
|
|
|
49
49
|
* @internal
|
|
50
50
|
* @since 1.0.0
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
interface SourceDefaultFailure {
|
|
53
|
+
/** The source that failed. */
|
|
54
|
+
readonly sourceId: symbol;
|
|
55
|
+
/** The path of the node. */
|
|
56
|
+
readonly path: readonly PropertyKey[];
|
|
57
|
+
/** The failed result or error message. */
|
|
58
|
+
readonly error: ValueParserResult<unknown>;
|
|
59
|
+
}
|
|
53
60
|
/**
|
|
54
61
|
* A key for caching replayed parse results.
|
|
55
62
|
*
|
|
@@ -145,5 +152,193 @@ interface DependencyRuntimeContext {
|
|
|
145
152
|
* @internal
|
|
146
153
|
* @since 1.0.0
|
|
147
154
|
*/
|
|
155
|
+
declare function createDependencyRuntimeContext(registry?: DependencyRegistryLike): DependencyRuntimeContext;
|
|
156
|
+
/**
|
|
157
|
+
* Creates a stable fingerprint from dependency values.
|
|
158
|
+
*
|
|
159
|
+
* @param values The dependency values to fingerprint.
|
|
160
|
+
* @returns A string fingerprint.
|
|
161
|
+
* @internal
|
|
162
|
+
* @since 1.0.0
|
|
163
|
+
*/
|
|
164
|
+
declare function createDependencyFingerprint(values: readonly unknown[]): string;
|
|
165
|
+
declare function createReplayKey(path: readonly PropertyKey[], rawInput: string, dependencyValues: readonly unknown[], replayParse?: Function): ReplayKey;
|
|
166
|
+
/**
|
|
167
|
+
* Collects explicit source values from parser states and registers them
|
|
168
|
+
* in the runtime context.
|
|
169
|
+
*
|
|
170
|
+
* @param nodes The runtime nodes to inspect.
|
|
171
|
+
* @param runtime The dependency runtime context.
|
|
172
|
+
* @throws Propagates synchronous errors thrown by `extractSourceValue()`.
|
|
173
|
+
* @throws {TypeError} If `extractSourceValue()` returns a promise-like result.
|
|
174
|
+
* Use {@link collectExplicitSourceValuesAsync} when async source
|
|
175
|
+
* extraction is expected.
|
|
176
|
+
* @internal
|
|
177
|
+
* @since 1.0.0
|
|
178
|
+
*/
|
|
179
|
+
declare function collectExplicitSourceValues(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext): void;
|
|
180
|
+
/**
|
|
181
|
+
* Async version of {@link collectExplicitSourceValues}.
|
|
182
|
+
* Awaits async `extractSourceValue` results instead of rejecting
|
|
183
|
+
* promise-like values as the synchronous variant does.
|
|
184
|
+
*
|
|
185
|
+
* @param nodes The runtime nodes to inspect.
|
|
186
|
+
* @param runtime The dependency runtime context.
|
|
187
|
+
* @throws Propagates errors thrown or rejected by `extractSourceValue()`.
|
|
188
|
+
* @internal
|
|
189
|
+
* @since 1.0.0
|
|
190
|
+
*/
|
|
191
|
+
declare function collectExplicitSourceValuesAsync(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Fills missing source defaults for source parsers whose state is
|
|
194
|
+
* unpopulated.
|
|
195
|
+
*
|
|
196
|
+
* Returns an array of failures for sources whose default evaluation
|
|
197
|
+
* failed (either threw or returned `{ success: false }`). The caller
|
|
198
|
+
* should propagate these so that dependent parsers see the real error
|
|
199
|
+
* instead of silently treating the source as absent.
|
|
200
|
+
*
|
|
201
|
+
* @param nodes The runtime nodes to inspect.
|
|
202
|
+
* @param runtime The dependency runtime context.
|
|
203
|
+
* @returns Failures from default evaluation (empty if all succeeded).
|
|
204
|
+
* @throws {TypeError} If `getMissingSourceValue()` returns a promise-like
|
|
205
|
+
* result. Use {@link fillMissingSourceDefaultsAsync} when async
|
|
206
|
+
* default extraction is expected.
|
|
207
|
+
* @internal
|
|
208
|
+
* @since 1.0.0
|
|
209
|
+
*/
|
|
210
|
+
declare function fillMissingSourceDefaults(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext): readonly SourceDefaultFailure[];
|
|
211
|
+
/**
|
|
212
|
+
* Async version of {@link fillMissingSourceDefaults}.
|
|
213
|
+
* Awaits async `getMissingSourceValue` results.
|
|
214
|
+
*
|
|
215
|
+
* @param nodes The runtime nodes to inspect.
|
|
216
|
+
* @param runtime The dependency runtime context.
|
|
217
|
+
* @returns Failures from default evaluation (empty if all succeeded).
|
|
218
|
+
* @internal
|
|
219
|
+
* @since 1.0.0
|
|
220
|
+
*/
|
|
221
|
+
declare function fillMissingSourceDefaultsAsync(nodes: readonly RuntimeNode[], runtime: DependencyRuntimeContext): Promise<readonly SourceDefaultFailure[]>;
|
|
222
|
+
/**
|
|
223
|
+
* Replays a derived parser with resolved dependency values (sync).
|
|
224
|
+
*
|
|
225
|
+
* Returns `undefined` if dependencies cannot be resolved.
|
|
226
|
+
*
|
|
227
|
+
* @param node The runtime node with derived metadata.
|
|
228
|
+
* @param rawInput The raw input to replay.
|
|
229
|
+
* @param runtime The dependency runtime context.
|
|
230
|
+
* @returns The replay result, or `undefined`.
|
|
231
|
+
* @throws {TypeError} If `replayParse()` returns a promise-like result.
|
|
232
|
+
* Use {@link replayDerivedParserAsync} for async replay.
|
|
233
|
+
* @internal
|
|
234
|
+
* @since 1.0.0
|
|
235
|
+
*/
|
|
236
|
+
declare function replayDerivedParser(node: RuntimeNode, rawInput: string, runtime: DependencyRuntimeContext): ValueParserResult<unknown> | undefined;
|
|
237
|
+
/**
|
|
238
|
+
* Replays a derived parser with resolved dependency values (async).
|
|
239
|
+
*
|
|
240
|
+
* Returns `undefined` if dependencies cannot be resolved.
|
|
241
|
+
*
|
|
242
|
+
* @param node The runtime node with derived metadata.
|
|
243
|
+
* @param rawInput The raw input to replay.
|
|
244
|
+
* @param runtime The dependency runtime context.
|
|
245
|
+
* @returns The replay result, or `undefined`.
|
|
246
|
+
* @internal
|
|
247
|
+
* @since 1.0.0
|
|
248
|
+
*/
|
|
249
|
+
declare function replayDerivedParserAsync(node: RuntimeNode, rawInput: string, runtime: DependencyRuntimeContext): Promise<ValueParserResult<unknown> | undefined>;
|
|
250
|
+
/**
|
|
251
|
+
* Extracts `rawInput` from a parser state that may contain a
|
|
252
|
+
* {@link DeferredParseState}. During the transition period, primitives
|
|
253
|
+
* still produce `DeferredParseState` with `rawInput`.
|
|
254
|
+
*
|
|
255
|
+
* Handles direct `DeferredParseState` and array-wrapped
|
|
256
|
+
* `[DeferredParseState]` (from optional/withDefault wrappers).
|
|
257
|
+
*
|
|
258
|
+
* @param state The parser state to inspect.
|
|
259
|
+
* @returns The raw input string, or `undefined` if the state does not
|
|
260
|
+
* contain a `DeferredParseState`.
|
|
261
|
+
* @internal
|
|
262
|
+
* @since 1.0.0
|
|
263
|
+
*/
|
|
264
|
+
declare function extractRawInputFromState(state: unknown): string | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Recursively collects dependency source values from {@link DependencySourceState}
|
|
267
|
+
* objects found in the state tree and registers them in the runtime.
|
|
268
|
+
*
|
|
269
|
+
* This must run BEFORE deferred resolution so that all source values
|
|
270
|
+
* are available when replaying derived parsers.
|
|
271
|
+
*
|
|
272
|
+
* @param state The state tree to traverse.
|
|
273
|
+
* @param runtime The dependency runtime context to populate.
|
|
274
|
+
* @param visited Cycle guard for recursive traversal.
|
|
275
|
+
* @param excludedFields Optional property keys to skip at the current level.
|
|
276
|
+
* This exclusion set is not propagated recursively.
|
|
277
|
+
*/
|
|
278
|
+
declare function collectSourcesFromState(state: unknown, runtime: DependencyRuntimeContext, visited?: WeakSet<object>, excludedFields?: ReadonlySet<PropertyKey>): void;
|
|
279
|
+
/**
|
|
280
|
+
* Recursively resolves all {@link DeferredParseState} objects in a state
|
|
281
|
+
* tree using the dependency runtime (sync).
|
|
282
|
+
*
|
|
283
|
+
* Performs a two-pass traversal:
|
|
284
|
+
* 1. Collect all {@link DependencySourceState} values into the runtime.
|
|
285
|
+
* 2. Resolve all {@link DeferredParseState} using the populated runtime.
|
|
286
|
+
*
|
|
287
|
+
* This replaces the old `resolveDeferredParseStates` with runtime-based
|
|
288
|
+
* resolution. Only traverses plain objects and arrays; class instances
|
|
289
|
+
* and primitives are returned as-is.
|
|
290
|
+
*
|
|
291
|
+
* @param state The state tree to resolve.
|
|
292
|
+
* @param runtime The dependency runtime context.
|
|
293
|
+
* @returns The resolved state tree.
|
|
294
|
+
* @throws {TypeError} If a deferred parser returns a promise-like result from
|
|
295
|
+
* `parseWithDependency()`. Use {@link resolveStateWithRuntimeAsync}
|
|
296
|
+
* for async resolution.
|
|
297
|
+
* @internal
|
|
298
|
+
* @since 1.0.0
|
|
299
|
+
*/
|
|
300
|
+
declare function resolveStateWithRuntime(state: unknown, runtime: DependencyRuntimeContext): unknown;
|
|
301
|
+
/**
|
|
302
|
+
* Async version of {@link resolveStateWithRuntime}.
|
|
303
|
+
*
|
|
304
|
+
* @param state The state tree to resolve.
|
|
305
|
+
* @param runtime The dependency runtime context.
|
|
306
|
+
* @returns The resolved state tree.
|
|
307
|
+
* @internal
|
|
308
|
+
* @since 1.0.0
|
|
309
|
+
*/
|
|
310
|
+
declare function resolveStateWithRuntimeAsync(state: unknown, runtime: DependencyRuntimeContext): Promise<unknown>;
|
|
311
|
+
/**
|
|
312
|
+
* Builds {@link RuntimeNode}s from field→parser pairs and a state record.
|
|
313
|
+
*
|
|
314
|
+
* Used by `object()` and `merge()` constructs.
|
|
315
|
+
*
|
|
316
|
+
* @param pairs Field→parser pairs.
|
|
317
|
+
* @param state The state record keyed by field name.
|
|
318
|
+
* @param parentPath Optional parent path prefix.
|
|
319
|
+
* @returns An array of runtime nodes.
|
|
320
|
+
* @internal
|
|
321
|
+
* @since 1.0.0
|
|
322
|
+
*/
|
|
323
|
+
declare function buildRuntimeNodesFromPairs(pairs: ReadonlyArray<readonly [PropertyKey, {
|
|
324
|
+
readonly dependencyMetadata?: ParserDependencyMetadata;
|
|
325
|
+
readonly initialState?: unknown;
|
|
326
|
+
}]>, state: Record<PropertyKey, unknown>, parentPath?: readonly PropertyKey[]): readonly RuntimeNode[];
|
|
327
|
+
/**
|
|
328
|
+
* Builds {@link RuntimeNode}s from a parser array and a state array.
|
|
329
|
+
*
|
|
330
|
+
* Used by `tuple()` and `concat()` constructs.
|
|
331
|
+
*
|
|
332
|
+
* @param parsers The child parsers.
|
|
333
|
+
* @param stateArray The state array (one element per parser).
|
|
334
|
+
* @param parentPath Optional parent path prefix.
|
|
335
|
+
* @returns An array of runtime nodes.
|
|
336
|
+
* @internal
|
|
337
|
+
* @since 1.0.0
|
|
338
|
+
*/
|
|
339
|
+
declare function buildRuntimeNodesFromArray(parsers: ReadonlyArray<{
|
|
340
|
+
readonly dependencyMetadata?: ParserDependencyMetadata;
|
|
341
|
+
readonly initialState?: unknown;
|
|
342
|
+
}>, stateArray: readonly unknown[], parentPath?: readonly PropertyKey[]): readonly RuntimeNode[];
|
|
148
343
|
//#endregion
|
|
149
|
-
export { DependencyRuntimeContext, RuntimeNode };
|
|
344
|
+
export { DependencyRequest, DependencyResolution, DependencyRuntimeContext, DependencyValueOrigin, ReplayKey, RuntimeNode, SourceDefaultFailure, buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, createDependencyFingerprint, createDependencyRuntimeContext, createReplayKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, replayDerivedParser, replayDerivedParserAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync };
|
|
@@ -457,6 +457,27 @@ async function replayDerivedParserAsync(node, rawInput, runtime) {
|
|
|
457
457
|
return result;
|
|
458
458
|
}
|
|
459
459
|
/**
|
|
460
|
+
* Extracts `rawInput` from a parser state that may contain a
|
|
461
|
+
* {@link DeferredParseState}. During the transition period, primitives
|
|
462
|
+
* still produce `DeferredParseState` with `rawInput`.
|
|
463
|
+
*
|
|
464
|
+
* Handles direct `DeferredParseState` and array-wrapped
|
|
465
|
+
* `[DeferredParseState]` (from optional/withDefault wrappers).
|
|
466
|
+
*
|
|
467
|
+
* @param state The parser state to inspect.
|
|
468
|
+
* @returns The raw input string, or `undefined` if the state does not
|
|
469
|
+
* contain a `DeferredParseState`.
|
|
470
|
+
* @internal
|
|
471
|
+
* @since 1.0.0
|
|
472
|
+
*/
|
|
473
|
+
function extractRawInputFromState(state) {
|
|
474
|
+
if (state == null) return void 0;
|
|
475
|
+
if (typeof state !== "object") return void 0;
|
|
476
|
+
if (isDeferredParseState(state)) return state.rawInput;
|
|
477
|
+
if (Array.isArray(state) && state.length === 1 && isDeferredParseState(state[0])) return state[0].rawInput;
|
|
478
|
+
return void 0;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
460
481
|
* Checks if a value is a plain object (not a class instance) for the
|
|
461
482
|
* purpose of recursive state traversal.
|
|
462
483
|
*/
|
|
@@ -696,4 +717,4 @@ function buildRuntimeNodesFromArray(parsers, stateArray, parentPath) {
|
|
|
696
717
|
}
|
|
697
718
|
|
|
698
719
|
//#endregion
|
|
699
|
-
export { buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, createDependencyRuntimeContext, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, replayDerivedParser, replayDerivedParserAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync };
|
|
720
|
+
export { buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, createDependencyFingerprint, createDependencyRuntimeContext, createReplayKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, replayDerivedParser, replayDerivedParserAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync };
|
package/dist/dependency.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_internal_dependency = require('./internal/dependency.cjs');
|
|
2
2
|
|
|
3
|
-
exports.dependency =
|
|
4
|
-
exports.deriveFrom =
|
|
5
|
-
exports.deriveFromAsync =
|
|
6
|
-
exports.deriveFromSync =
|
|
7
|
-
exports.isDependencySource =
|
|
8
|
-
exports.isDerivedValueParser =
|
|
3
|
+
exports.dependency = require_internal_dependency.dependency;
|
|
4
|
+
exports.deriveFrom = require_internal_dependency.deriveFrom;
|
|
5
|
+
exports.deriveFromAsync = require_internal_dependency.deriveFromAsync;
|
|
6
|
+
exports.deriveFromSync = require_internal_dependency.deriveFromSync;
|
|
7
|
+
exports.isDependencySource = require_internal_dependency.isDependencySource;
|
|
8
|
+
exports.isDerivedValueParser = require_internal_dependency.isDerivedValueParser;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/displaywidth.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Computes the terminal display width of a string, accounting for
|
|
4
|
+
* East Asian wide characters, combining marks, emoji, and ANSI escapes.
|
|
5
|
+
*
|
|
6
|
+
* @param text The string to measure.
|
|
7
|
+
* @returns The number of terminal columns the string occupies.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
declare function getDisplayWidth(text: string): number;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getDisplayWidth };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/displaywidth.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Computes the terminal display width of a string, accounting for
|
|
4
|
+
* East Asian wide characters, combining marks, emoji, and ANSI escapes.
|
|
5
|
+
*
|
|
6
|
+
* @param text The string to measure.
|
|
7
|
+
* @returns The number of terminal columns the string occupies.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
declare function getDisplayWidth(text: string): number;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getDisplayWidth };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Usage } from "./usage.cjs";
|
|
2
|
+
import { ExecutionContext, ParserContext } from "./internal/parser.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/execution-context.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Appends a child parser segment to the current execution path.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
declare function withChildExecPath(exec: ExecutionContext | undefined, segment: PropertyKey): ExecutionContext | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Merges child-owned execution fields back into the parent execution context.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare function mergeChildExec(parent: ExecutionContext | undefined, child: ExecutionContext | undefined): ExecutionContext | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a child parser context while keeping flat and nested execution data
|
|
18
|
+
* aligned.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
declare function withChildContext<TParentState, TChildState>(context: ParserContext<TParentState>, segment: PropertyKey, state: TChildState, usage?: Usage): ParserContext<TChildState>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { mergeChildExec, withChildContext, withChildExecPath };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Usage } from "./usage.js";
|
|
2
|
+
import { ExecutionContext, ParserContext } from "./internal/parser.js";
|
|
3
|
+
|
|
4
|
+
//#region src/execution-context.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Appends a child parser segment to the current execution path.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
declare function withChildExecPath(exec: ExecutionContext | undefined, segment: PropertyKey): ExecutionContext | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Merges child-owned execution fields back into the parent execution context.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare function mergeChildExec(parent: ExecutionContext | undefined, child: ExecutionContext | undefined): ExecutionContext | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a child parser context while keeping flat and nested execution data
|
|
18
|
+
* aligned.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
declare function withChildContext<TParentState, TChildState>(context: ParserContext<TParentState>, segment: PropertyKey, state: TChildState, usage?: Usage): ParserContext<TChildState>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { mergeChildExec, withChildContext, withChildExecPath };
|
package/dist/extension.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_internal_annotations = require('./internal/annotations.cjs');
|
|
2
2
|
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
3
|
-
const
|
|
3
|
+
const require_internal_parser = require('./internal/parser.cjs');
|
|
4
4
|
const require_annotation_state = require('./annotation-state.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/extension.ts
|
|
@@ -14,13 +14,13 @@ const emptyTraits = Object.freeze({});
|
|
|
14
14
|
* @since 1.0.0
|
|
15
15
|
*/
|
|
16
16
|
function defineTraits(parser, traits) {
|
|
17
|
-
if (traits.inheritsAnnotations === true)
|
|
18
|
-
if (traits.completesFromSource === true) Object.defineProperty(parser,
|
|
17
|
+
if (traits.inheritsAnnotations === true) require_internal_parser.defineInheritedAnnotationParser(parser);
|
|
18
|
+
if (traits.completesFromSource === true) Object.defineProperty(parser, require_internal_parser.unmatchedNonCliDependencySourceStateMarker, {
|
|
19
19
|
value: true,
|
|
20
20
|
configurable: true,
|
|
21
21
|
enumerable: true
|
|
22
22
|
});
|
|
23
|
-
if (traits.requiresSourceBinding === true) Object.defineProperty(parser,
|
|
23
|
+
if (traits.requiresSourceBinding === true) Object.defineProperty(parser, require_internal_parser.annotationWrapperRequiresSourceBindingKey, {
|
|
24
24
|
value: true,
|
|
25
25
|
configurable: true,
|
|
26
26
|
enumerable: false
|
|
@@ -35,9 +35,9 @@ function defineTraits(parser, traits) {
|
|
|
35
35
|
*/
|
|
36
36
|
function getTraits(parser) {
|
|
37
37
|
const traits = {
|
|
38
|
-
...Reflect.get(parser,
|
|
39
|
-
...Reflect.get(parser,
|
|
40
|
-
...Reflect.get(parser,
|
|
38
|
+
...Reflect.get(parser, require_internal_parser.inheritParentAnnotationsKey) === true ? { inheritsAnnotations: true } : {},
|
|
39
|
+
...Reflect.get(parser, require_internal_parser.unmatchedNonCliDependencySourceStateMarker) === true ? { completesFromSource: true } : {},
|
|
40
|
+
...Reflect.get(parser, require_internal_parser.annotationWrapperRequiresSourceBindingKey) === true ? { requiresSourceBinding: true } : {}
|
|
41
41
|
};
|
|
42
42
|
return Object.keys(traits).length > 0 ? traits : emptyTraits;
|
|
43
43
|
}
|
|
@@ -55,7 +55,7 @@ function getTraits(parser) {
|
|
|
55
55
|
* @since 1.0.0
|
|
56
56
|
*/
|
|
57
57
|
function delegateSuggestNodes(innerParser, outerParser, state, path, innerState, position = "append") {
|
|
58
|
-
return
|
|
58
|
+
return require_internal_parser.getDelegatingSuggestRuntimeNodes(innerParser, outerParser, state, path, innerState, position);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Maps the source capability of a parser's dependency metadata while
|
|
@@ -69,7 +69,7 @@ function delegateSuggestNodes(innerParser, outerParser, state, path, innerState,
|
|
|
69
69
|
* @since 1.0.0
|
|
70
70
|
*/
|
|
71
71
|
function mapSourceMetadata(parser, mapSource) {
|
|
72
|
-
return
|
|
72
|
+
return require_internal_parser.composeWrappedSourceMetadata(parser.dependencyMetadata, mapSource);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
//#endregion
|
|
@@ -77,11 +77,11 @@ exports.defineTraits = defineTraits;
|
|
|
77
77
|
exports.delegateSuggestNodes = delegateSuggestNodes;
|
|
78
78
|
exports.dispatchByMode = require_mode_dispatch.dispatchByMode;
|
|
79
79
|
exports.getTraits = getTraits;
|
|
80
|
-
exports.inheritAnnotations =
|
|
81
|
-
exports.injectAnnotations =
|
|
82
|
-
exports.isInjectedAnnotationState =
|
|
80
|
+
exports.inheritAnnotations = require_internal_annotations.inheritAnnotations;
|
|
81
|
+
exports.injectAnnotations = require_internal_annotations.injectAnnotations;
|
|
82
|
+
exports.isInjectedAnnotationState = require_internal_annotations.isInjectedAnnotationState;
|
|
83
83
|
exports.mapModeValue = require_mode_dispatch.mapModeValue;
|
|
84
84
|
exports.mapSourceMetadata = mapSourceMetadata;
|
|
85
|
-
exports.unwrapInjectedAnnotationState =
|
|
85
|
+
exports.unwrapInjectedAnnotationState = require_internal_annotations.unwrapInjectedAnnotationState;
|
|
86
86
|
exports.withAnnotationView = require_annotation_state.withAnnotationView;
|
|
87
87
|
exports.wrapForMode = require_mode_dispatch.wrapForMode;
|
package/dist/facade.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_internal_annotations = require('./internal/annotations.cjs');
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
|
-
const require_completion = require('./completion.cjs');
|
|
4
3
|
const require_validate = require('./validate.cjs');
|
|
5
4
|
const require_usage = require('./usage.cjs');
|
|
6
5
|
const require_doc = require('./doc.cjs');
|
|
7
6
|
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
8
7
|
const require_dependency_runtime = require('./dependency-runtime.cjs');
|
|
9
8
|
const require_input_trace = require('./input-trace.cjs');
|
|
10
|
-
const
|
|
9
|
+
const require_internal_parser = require('./internal/parser.cjs');
|
|
10
|
+
const require_completion = require('./completion.cjs');
|
|
11
|
+
const require_command_alias = require('./internal/command-alias.cjs');
|
|
11
12
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
12
13
|
const require_constructs = require('./constructs.cjs');
|
|
13
14
|
const require_modifiers = require('./modifiers.cjs');
|
|
@@ -15,6 +16,14 @@ const require_valueparser = require('./valueparser.cjs');
|
|
|
15
16
|
const require_primitives = require('./primitives.cjs');
|
|
16
17
|
|
|
17
18
|
//#region src/facade.ts
|
|
19
|
+
/**
|
|
20
|
+
* Combines built-in meta commands while intentionally bypassing duplicate
|
|
21
|
+
* leading command name validation in `createLongestMatch()`.
|
|
22
|
+
*/
|
|
23
|
+
function longestMatchForMetaCommands(...parsers) {
|
|
24
|
+
const options = { [require_command_alias.allowDuplicateLeadingCommandNamesKey]: true };
|
|
25
|
+
return require_constructs.longestMatch(...parsers, options);
|
|
26
|
+
}
|
|
18
27
|
const SuppressedErrorCtor = typeof SuppressedError === "function" ? SuppressedError : (() => {
|
|
19
28
|
class SuppressedErrorPolyfill extends Error {
|
|
20
29
|
error;
|
|
@@ -119,9 +128,9 @@ function createCompleteExec(exec, context) {
|
|
|
119
128
|
};
|
|
120
129
|
}
|
|
121
130
|
function attemptParseSync(parser, args, mode = "complete") {
|
|
122
|
-
const shouldUnwrapAnnotatedValue =
|
|
131
|
+
const shouldUnwrapAnnotatedValue = require_internal_annotations.isInjectedAnnotationWrapper(parser.initialState);
|
|
123
132
|
const exec = createParseExec(parser);
|
|
124
|
-
let context =
|
|
133
|
+
let context = require_internal_parser.createParserContext({
|
|
125
134
|
buffer: args,
|
|
126
135
|
state: parser.initialState,
|
|
127
136
|
optionsTerminated: false
|
|
@@ -168,13 +177,13 @@ function attemptParseSync(parser, args, mode = "complete") {
|
|
|
168
177
|
};
|
|
169
178
|
return {
|
|
170
179
|
kind: "success",
|
|
171
|
-
value: shouldUnwrapAnnotatedValue ?
|
|
180
|
+
value: shouldUnwrapAnnotatedValue ? require_internal_annotations.unwrapInjectedAnnotationWrapper(endResult.value) : endResult.value
|
|
172
181
|
};
|
|
173
182
|
}
|
|
174
183
|
async function attemptParseAsync(parser, args, mode = "complete") {
|
|
175
|
-
const shouldUnwrapAnnotatedValue =
|
|
184
|
+
const shouldUnwrapAnnotatedValue = require_internal_annotations.isInjectedAnnotationWrapper(parser.initialState);
|
|
176
185
|
const exec = createParseExec(parser);
|
|
177
|
-
let context =
|
|
186
|
+
let context = require_internal_parser.createParserContext({
|
|
178
187
|
buffer: args,
|
|
179
188
|
state: parser.initialState,
|
|
180
189
|
optionsTerminated: false
|
|
@@ -221,7 +230,7 @@ async function attemptParseAsync(parser, args, mode = "complete") {
|
|
|
221
230
|
};
|
|
222
231
|
return {
|
|
223
232
|
kind: "success",
|
|
224
|
-
value: shouldUnwrapAnnotatedValue ?
|
|
233
|
+
value: shouldUnwrapAnnotatedValue ? require_internal_annotations.unwrapInjectedAnnotationWrapper(endResult.value) : endResult.value
|
|
225
234
|
};
|
|
226
235
|
}
|
|
227
236
|
function createPhase2SeedExec(parser, context) {
|
|
@@ -250,7 +259,7 @@ function createPhase2SeedContext(parser, args) {
|
|
|
250
259
|
commandPath: [],
|
|
251
260
|
trace: require_input_trace.createInputTrace()
|
|
252
261
|
};
|
|
253
|
-
return
|
|
262
|
+
return require_internal_parser.createParserContext({
|
|
254
263
|
buffer: args,
|
|
255
264
|
state: parser.initialState,
|
|
256
265
|
optionsTerminated: false
|
|
@@ -278,6 +287,10 @@ async function extractPhase2SeedAsync(parser, args) {
|
|
|
278
287
|
} while (context.buffer.length > 0);
|
|
279
288
|
return await require_phase2_seed.completeOrExtractPhase2Seed(parser, context.state, createPhase2SeedExec(parser, context));
|
|
280
289
|
}
|
|
290
|
+
function getMetaCommandAliases(names) {
|
|
291
|
+
const [, firstAlias, ...restAliases] = names;
|
|
292
|
+
return firstAlias == null ? void 0 : [firstAlias, ...restAliases];
|
|
293
|
+
}
|
|
281
294
|
/**
|
|
282
295
|
* Creates help parsers based on the sub-config.
|
|
283
296
|
*/
|
|
@@ -287,12 +300,12 @@ function createHelpParser(commandConfig, optionConfig) {
|
|
|
287
300
|
if (commandConfig) {
|
|
288
301
|
const names = commandConfig.names ?? ["help"];
|
|
289
302
|
const innerParser = require_modifiers.multiple(require_primitives.argument(require_valueparser.string({ metavar: "COMMAND" }), { description: require_message.message`Command name to show help for.` }));
|
|
290
|
-
const
|
|
291
|
-
|
|
303
|
+
const aliases = getMetaCommandAliases(names);
|
|
304
|
+
helpCommand = require_primitives.command(names[0], innerParser, {
|
|
292
305
|
description: require_message.message`Show help information.`,
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
306
|
+
...aliases != null ? { [require_command_alias.hiddenCommandAliasesKey]: aliases } : {},
|
|
307
|
+
hidden: commandConfig.hidden
|
|
308
|
+
});
|
|
296
309
|
}
|
|
297
310
|
if (optionConfig) {
|
|
298
311
|
const names = optionConfig.names ?? ["--help"];
|
|
@@ -315,12 +328,12 @@ function createVersionParser(commandConfig, optionConfig) {
|
|
|
315
328
|
if (commandConfig) {
|
|
316
329
|
const names = commandConfig.names ?? ["version"];
|
|
317
330
|
const innerParser = require_constructs.object({});
|
|
318
|
-
const
|
|
319
|
-
|
|
331
|
+
const aliases = getMetaCommandAliases(names);
|
|
332
|
+
versionCommand = require_primitives.command(names[0], innerParser, {
|
|
320
333
|
description: require_message.message`Show version information.`,
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
334
|
+
...aliases != null ? { [require_command_alias.hiddenCommandAliasesKey]: aliases } : {},
|
|
335
|
+
hidden: commandConfig.hidden
|
|
336
|
+
});
|
|
324
337
|
}
|
|
325
338
|
if (optionConfig) {
|
|
326
339
|
const names = optionConfig.names ?? ["--version"];
|
|
@@ -358,12 +371,12 @@ function createCompletionParser(programName, availableShells, commandConfig, opt
|
|
|
358
371
|
description: require_message.message`Generate shell completion script or provide completions.`,
|
|
359
372
|
footer: require_message.message`Examples:${require_message.lineBreak()} Bash: ${require_message.commandLine(`eval "$(${programName} ${displayName} bash)"`)}${require_message.lineBreak()} zsh: ${require_message.commandLine(`eval "$(${programName} ${displayName} zsh)"`)}${require_message.lineBreak()} fish: ${require_message.commandLine(`eval "$(${programName} ${displayName} fish)"`)}${require_message.lineBreak()} PowerShell: ${require_message.commandLine(`${programName} ${displayName} pwsh > ${programName}-completion.ps1; . ./${programName}-completion.ps1`)}${require_message.lineBreak()} Nushell: ${require_message.commandLine(`${programName} ${displayName} nu | save ${programName}-completion.nu; source ./${programName}-completion.nu`)}`
|
|
360
373
|
};
|
|
361
|
-
const
|
|
362
|
-
|
|
374
|
+
const aliases = getMetaCommandAliases(names);
|
|
375
|
+
completionCommand = require_primitives.command(names[0], completionInner, {
|
|
363
376
|
...completionCommandConfig,
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
377
|
+
...aliases != null ? { [require_command_alias.hiddenCommandAliasesKey]: aliases } : {},
|
|
378
|
+
hidden: commandConfig.hidden
|
|
379
|
+
});
|
|
367
380
|
}
|
|
368
381
|
if (optionConfig) {
|
|
369
382
|
const names = optionConfig.names ?? ["--completion"];
|
|
@@ -463,9 +476,7 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
|
|
|
463
476
|
}));
|
|
464
477
|
const mainParserIndex = parsers.length - 1;
|
|
465
478
|
if (parsers.length === 1) return parsers[0];
|
|
466
|
-
let combined;
|
|
467
|
-
if (parsers.length === 2) combined = require_constructs.longestMatch(parsers[0], parsers[1]);
|
|
468
|
-
else combined = require_constructs.longestMatch(...parsers);
|
|
479
|
+
let combined = longestMatchForMetaCommands(...parsers);
|
|
469
480
|
const topUsage = combined.usage[0];
|
|
470
481
|
if (topUsage?.type === "exclusive" && mainParserIndex > 0) {
|
|
471
482
|
const terms = [...topUsage.terms];
|
|
@@ -606,7 +617,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
606
617
|
stderr("Error: Missing shell name for completion.\n");
|
|
607
618
|
if (completionParser) {
|
|
608
619
|
const displayName = isOptionMode ? completionOptionDisplayName ?? "--completion" : completionCommandDisplayName ?? "completion";
|
|
609
|
-
const doc =
|
|
620
|
+
const doc = require_internal_parser.getDocPage(completionParser, [displayName]);
|
|
610
621
|
if (doc) stderr(require_doc.formatDocPage(programName, doc, {
|
|
611
622
|
colors,
|
|
612
623
|
maxWidth,
|
|
@@ -774,7 +785,7 @@ function getCompletionSuggestRuntimeNodes(parser, state, path) {
|
|
|
774
785
|
}];
|
|
775
786
|
}
|
|
776
787
|
function createCompletionArgumentParserContext(parser, args) {
|
|
777
|
-
return
|
|
788
|
+
return require_internal_parser.createParserContext({
|
|
778
789
|
buffer: args,
|
|
779
790
|
state: parser.initialState,
|
|
780
791
|
optionsTerminated: false
|
|
@@ -1080,8 +1091,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1080
1091
|
for (const [label, optParsers] of Object.entries(groupedMetaOptions)) if (optParsers.length === 1) commandParsers.push(require_constructs.group(label, optParsers[0]));
|
|
1081
1092
|
else commandParsers.push(require_constructs.group(label, require_constructs.longestMatch(...optParsers)));
|
|
1082
1093
|
if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
|
|
1083
|
-
else
|
|
1084
|
-
else helpGeneratorParser = require_constructs.longestMatch(...commandParsers);
|
|
1094
|
+
else helpGeneratorParser = longestMatchForMetaCommands(...commandParsers);
|
|
1085
1095
|
}
|
|
1086
1096
|
const reportInvalidHelpCommand = (validationError) => {
|
|
1087
1097
|
stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
|
|
@@ -1152,7 +1162,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1152
1162
|
res = processStep(resolved);
|
|
1153
1163
|
}
|
|
1154
1164
|
if (res != null) return reportInvalidHelpCommand(res);
|
|
1155
|
-
const docOrPromise$1 =
|
|
1165
|
+
const docOrPromise$1 = require_internal_parser.getDocPage(helpGeneratorParser, classified.commands);
|
|
1156
1166
|
return docOrPromise$1 instanceof Promise ? docOrPromise$1.then(displayHelp) : displayHelp(docOrPromise$1);
|
|
1157
1167
|
};
|
|
1158
1168
|
return stepResult.then(asyncValidate);
|
|
@@ -1161,7 +1171,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1161
1171
|
}
|
|
1162
1172
|
if (validationResult != null) return reportInvalidHelpCommand(validationResult);
|
|
1163
1173
|
}
|
|
1164
|
-
const docOrPromise =
|
|
1174
|
+
const docOrPromise = require_internal_parser.getDocPage(helpGeneratorParser, classified.commands);
|
|
1165
1175
|
if (docOrPromise instanceof Promise) return docOrPromise.then(displayHelp);
|
|
1166
1176
|
return displayHelp(docOrPromise);
|
|
1167
1177
|
}
|
|
@@ -1200,7 +1210,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1200
1210
|
};
|
|
1201
1211
|
if (aboveError === "help") {
|
|
1202
1212
|
const parserForDoc = args.length < 1 ? augmentedParser : parser;
|
|
1203
|
-
const docOrPromise =
|
|
1213
|
+
const docOrPromise = require_internal_parser.getDocPage(parserForDoc, args);
|
|
1204
1214
|
if (docOrPromise instanceof Promise) return docOrPromise.then((doc) => displayError(doc, aboveError));
|
|
1205
1215
|
return displayError(docOrPromise, aboveError);
|
|
1206
1216
|
}
|
|
@@ -1734,7 +1744,7 @@ function runWithAsync(parser, programName, contexts, options) {
|
|
|
1734
1744
|
* @returns A new parser with annotations in its initial state.
|
|
1735
1745
|
*/
|
|
1736
1746
|
function injectAnnotationsIntoParser(parser, annotations) {
|
|
1737
|
-
const newInitialState =
|
|
1747
|
+
const newInitialState = require_internal_annotations.injectAnnotations(parser.initialState, annotations);
|
|
1738
1748
|
const descriptors = { ...Object.getOwnPropertyDescriptors(parser) };
|
|
1739
1749
|
const initialState = descriptors.initialState;
|
|
1740
1750
|
descriptors.initialState = initialState == null ? {
|