@optique/core 1.2.2 → 1.2.4
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/constructs.cjs +346 -24
- package/dist/constructs.js +347 -25
- package/dist/internal/parser.cjs +35 -0
- package/dist/internal/parser.d.cts +62 -1
- package/dist/internal/parser.d.ts +62 -1
- package/dist/internal/parser.js +33 -1
- package/dist/modifiers.cjs +53 -0
- package/dist/modifiers.js +54 -1
- package/package.json +2 -2
package/dist/internal/parser.js
CHANGED
|
@@ -8,6 +8,12 @@ import { createInputTrace } from "../input-trace.js";
|
|
|
8
8
|
|
|
9
9
|
//#region src/internal/parser.ts
|
|
10
10
|
/**
|
|
11
|
+
* Internal symbol used by transparent combinators to expose independently
|
|
12
|
+
* competing parse operations to shared-buffer parents.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
const parseLanesKey = Symbol("parseLanes");
|
|
16
|
+
/**
|
|
11
17
|
* Internal marker for wrappers whose `{ hasCliValue: false }` states should
|
|
12
18
|
* be treated as unmatched dependency-source states during completion-time
|
|
13
19
|
* Phase 1.
|
|
@@ -387,6 +393,32 @@ function composeWrappedSourceMetadata(dependencyMetadata, wrapSource) {
|
|
|
387
393
|
};
|
|
388
394
|
}
|
|
389
395
|
/**
|
|
396
|
+
* Defines internal parse-lane metadata without exposing it through object
|
|
397
|
+
* spreads used by custom parser wrappers.
|
|
398
|
+
*
|
|
399
|
+
* @internal
|
|
400
|
+
*/
|
|
401
|
+
function defineParseLanes(parser, lanes) {
|
|
402
|
+
if (lanes == null) return;
|
|
403
|
+
Object.defineProperty(parser, parseLanesKey, {
|
|
404
|
+
value: lanes,
|
|
405
|
+
configurable: true,
|
|
406
|
+
enumerable: false
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Gets parse-lane metadata defined directly on a parser.
|
|
411
|
+
*
|
|
412
|
+
* Inherited metadata belongs to the parser's prototype and must not bypass an
|
|
413
|
+
* overriding `parse()` implementation on a custom wrapper.
|
|
414
|
+
*
|
|
415
|
+
* @internal
|
|
416
|
+
*/
|
|
417
|
+
function getOwnParseLanes(parser) {
|
|
418
|
+
if (!Object.hasOwn(parser, parseLanesKey)) return void 0;
|
|
419
|
+
return parser[parseLanesKey];
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
390
422
|
* Marks a parser as inheriting parent-state annotations through wrapper-state
|
|
391
423
|
* reconstruction.
|
|
392
424
|
*
|
|
@@ -850,4 +882,4 @@ function findNextMatchedCommandArgIndex(args, matchedCommandArgIndices, start) {
|
|
|
850
882
|
}
|
|
851
883
|
|
|
852
884
|
//#endregion
|
|
853
|
-
export { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, createParserContext, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
|
885
|
+
export { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, createParserContext, defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getOwnParseLanes, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseLanesKey, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
package/dist/modifiers.cjs
CHANGED
|
@@ -231,6 +231,44 @@ function processOptionalStyleResult(result, innerState, context) {
|
|
|
231
231
|
};
|
|
232
232
|
return result;
|
|
233
233
|
}
|
|
234
|
+
function adaptOptionalStyleParseLanes(parser) {
|
|
235
|
+
const lanes = require_internal_parser.getOwnParseLanes(parser);
|
|
236
|
+
if (lanes == null) return void 0;
|
|
237
|
+
const consumptionGroup = {};
|
|
238
|
+
return lanes.map((lane) => ({
|
|
239
|
+
priority: lane.priority,
|
|
240
|
+
zeroConsumptionGroup: lane.zeroConsumptionGroup,
|
|
241
|
+
settlesZeroConsumption: lane.settlesZeroConsumption,
|
|
242
|
+
leadingNames: lane.leadingNames,
|
|
243
|
+
acceptingAnyToken: false,
|
|
244
|
+
requiredConsumptionGroups: [...lane.requiredConsumptionGroups?.map((group) => ({
|
|
245
|
+
id: group.id,
|
|
246
|
+
...group.isActive == null ? {} : { isActive(state) {
|
|
247
|
+
const innerState = Array.isArray(state) ? state[0] : parser.initialState;
|
|
248
|
+
return group.isActive?.(innerState) ?? true;
|
|
249
|
+
} }
|
|
250
|
+
})) ?? [], {
|
|
251
|
+
id: consumptionGroup,
|
|
252
|
+
isActive(state) {
|
|
253
|
+
return Array.isArray(state);
|
|
254
|
+
}
|
|
255
|
+
}],
|
|
256
|
+
parse(context) {
|
|
257
|
+
const innerState = deriveOptionalInnerParseState(context.state, parser);
|
|
258
|
+
const innerContext = {
|
|
259
|
+
...context,
|
|
260
|
+
state: innerState
|
|
261
|
+
};
|
|
262
|
+
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
263
|
+
const result = lane.parse(innerContext);
|
|
264
|
+
return processOptionalStyleResult(result, innerState, context);
|
|
265
|
+
}, async () => {
|
|
266
|
+
const result = await lane.parse(innerContext);
|
|
267
|
+
return processOptionalStyleResult(result, innerState, context);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
234
272
|
/**
|
|
235
273
|
* Creates a `shouldDeferCompletion` adapter that unwraps the outer state
|
|
236
274
|
* shape (`[TState] | undefined`) used by {@link optional} and
|
|
@@ -420,6 +458,7 @@ function optional(parser) {
|
|
|
420
458
|
const composed = require_dependency_metadata.composeDependencyMetadata(parser.dependencyMetadata, "optional");
|
|
421
459
|
if (composed != null) optionalParser.dependencyMetadata = composed;
|
|
422
460
|
}
|
|
461
|
+
require_internal_parser.defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
|
|
423
462
|
require_internal_parser.defineInheritedAnnotationParser(optionalParser);
|
|
424
463
|
require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
|
|
425
464
|
return fluent(optionalParser);
|
|
@@ -654,6 +693,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
654
693
|
} });
|
|
655
694
|
if (composed != null) withDefaultParser.dependencyMetadata = composed;
|
|
656
695
|
}
|
|
696
|
+
require_internal_parser.defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
|
|
657
697
|
require_internal_parser.defineInheritedAnnotationParser(withDefaultParser);
|
|
658
698
|
require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
|
|
659
699
|
return fluent(withDefaultParser);
|
|
@@ -793,6 +833,7 @@ function map(parser, transform) {
|
|
|
793
833
|
return parser.getDocFragments(state, void 0);
|
|
794
834
|
}
|
|
795
835
|
};
|
|
836
|
+
require_internal_parser.defineParseLanes(mappedParser, require_internal_parser.getOwnParseLanes(parser));
|
|
796
837
|
delete mappedParser.normalizeValue;
|
|
797
838
|
delete mappedParser.validateValue;
|
|
798
839
|
if ("placeholder" in parser) Object.defineProperty(mappedParser, "placeholder", {
|
|
@@ -1680,6 +1721,7 @@ function multiple(parser, options = {}) {
|
|
|
1680
1721
|
function nonEmpty(parser) {
|
|
1681
1722
|
const syncParser = parser;
|
|
1682
1723
|
const initialState = parser.initialState;
|
|
1724
|
+
const consumptionGroup = {};
|
|
1683
1725
|
const processNonEmptyResult = (result) => {
|
|
1684
1726
|
if (!result.success) return result;
|
|
1685
1727
|
if (result.consumed.length === 0) return {
|
|
@@ -1732,6 +1774,17 @@ function nonEmpty(parser) {
|
|
|
1732
1774
|
return syncParser.getDocFragments(state, defaultValue);
|
|
1733
1775
|
}
|
|
1734
1776
|
};
|
|
1777
|
+
require_internal_parser.defineParseLanes(nonEmptyParser, require_internal_parser.getOwnParseLanes(parser)?.map((lane) => ({
|
|
1778
|
+
priority: lane.priority,
|
|
1779
|
+
zeroConsumptionGroup: lane.zeroConsumptionGroup,
|
|
1780
|
+
settlesZeroConsumption: lane.settlesZeroConsumption,
|
|
1781
|
+
leadingNames: lane.leadingNames,
|
|
1782
|
+
acceptingAnyToken: lane.acceptingAnyToken,
|
|
1783
|
+
requiredConsumptionGroups: [...lane.requiredConsumptionGroups ?? [], { id: consumptionGroup }],
|
|
1784
|
+
parse(context) {
|
|
1785
|
+
return lane.parse(context);
|
|
1786
|
+
}
|
|
1787
|
+
})));
|
|
1735
1788
|
if ("placeholder" in parser) Object.defineProperty(nonEmptyParser, "placeholder", {
|
|
1736
1789
|
get() {
|
|
1737
1790
|
return parser.placeholder;
|
package/dist/modifiers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./internal/annotations.js";
|
|
2
2
|
import { formatMessage, message, text } from "./message.js";
|
|
3
3
|
import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
|
|
4
|
-
import { defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
4
|
+
import { defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getOwnParseLanes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
5
5
|
import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
|
|
6
6
|
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
7
7
|
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
@@ -231,6 +231,44 @@ function processOptionalStyleResult(result, innerState, context) {
|
|
|
231
231
|
};
|
|
232
232
|
return result;
|
|
233
233
|
}
|
|
234
|
+
function adaptOptionalStyleParseLanes(parser) {
|
|
235
|
+
const lanes = getOwnParseLanes(parser);
|
|
236
|
+
if (lanes == null) return void 0;
|
|
237
|
+
const consumptionGroup = {};
|
|
238
|
+
return lanes.map((lane) => ({
|
|
239
|
+
priority: lane.priority,
|
|
240
|
+
zeroConsumptionGroup: lane.zeroConsumptionGroup,
|
|
241
|
+
settlesZeroConsumption: lane.settlesZeroConsumption,
|
|
242
|
+
leadingNames: lane.leadingNames,
|
|
243
|
+
acceptingAnyToken: false,
|
|
244
|
+
requiredConsumptionGroups: [...lane.requiredConsumptionGroups?.map((group) => ({
|
|
245
|
+
id: group.id,
|
|
246
|
+
...group.isActive == null ? {} : { isActive(state) {
|
|
247
|
+
const innerState = Array.isArray(state) ? state[0] : parser.initialState;
|
|
248
|
+
return group.isActive?.(innerState) ?? true;
|
|
249
|
+
} }
|
|
250
|
+
})) ?? [], {
|
|
251
|
+
id: consumptionGroup,
|
|
252
|
+
isActive(state) {
|
|
253
|
+
return Array.isArray(state);
|
|
254
|
+
}
|
|
255
|
+
}],
|
|
256
|
+
parse(context) {
|
|
257
|
+
const innerState = deriveOptionalInnerParseState(context.state, parser);
|
|
258
|
+
const innerContext = {
|
|
259
|
+
...context,
|
|
260
|
+
state: innerState
|
|
261
|
+
};
|
|
262
|
+
return dispatchByMode(parser.mode, () => {
|
|
263
|
+
const result = lane.parse(innerContext);
|
|
264
|
+
return processOptionalStyleResult(result, innerState, context);
|
|
265
|
+
}, async () => {
|
|
266
|
+
const result = await lane.parse(innerContext);
|
|
267
|
+
return processOptionalStyleResult(result, innerState, context);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
234
272
|
/**
|
|
235
273
|
* Creates a `shouldDeferCompletion` adapter that unwraps the outer state
|
|
236
274
|
* shape (`[TState] | undefined`) used by {@link optional} and
|
|
@@ -420,6 +458,7 @@ function optional(parser) {
|
|
|
420
458
|
const composed = composeDependencyMetadata(parser.dependencyMetadata, "optional");
|
|
421
459
|
if (composed != null) optionalParser.dependencyMetadata = composed;
|
|
422
460
|
}
|
|
461
|
+
defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
|
|
423
462
|
defineInheritedAnnotationParser(optionalParser);
|
|
424
463
|
defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
|
|
425
464
|
return fluent(optionalParser);
|
|
@@ -654,6 +693,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
654
693
|
} });
|
|
655
694
|
if (composed != null) withDefaultParser.dependencyMetadata = composed;
|
|
656
695
|
}
|
|
696
|
+
defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
|
|
657
697
|
defineInheritedAnnotationParser(withDefaultParser);
|
|
658
698
|
defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
|
|
659
699
|
return fluent(withDefaultParser);
|
|
@@ -793,6 +833,7 @@ function map(parser, transform) {
|
|
|
793
833
|
return parser.getDocFragments(state, void 0);
|
|
794
834
|
}
|
|
795
835
|
};
|
|
836
|
+
defineParseLanes(mappedParser, getOwnParseLanes(parser));
|
|
796
837
|
delete mappedParser.normalizeValue;
|
|
797
838
|
delete mappedParser.validateValue;
|
|
798
839
|
if ("placeholder" in parser) Object.defineProperty(mappedParser, "placeholder", {
|
|
@@ -1680,6 +1721,7 @@ function multiple(parser, options = {}) {
|
|
|
1680
1721
|
function nonEmpty(parser) {
|
|
1681
1722
|
const syncParser = parser;
|
|
1682
1723
|
const initialState = parser.initialState;
|
|
1724
|
+
const consumptionGroup = {};
|
|
1683
1725
|
const processNonEmptyResult = (result) => {
|
|
1684
1726
|
if (!result.success) return result;
|
|
1685
1727
|
if (result.consumed.length === 0) return {
|
|
@@ -1732,6 +1774,17 @@ function nonEmpty(parser) {
|
|
|
1732
1774
|
return syncParser.getDocFragments(state, defaultValue);
|
|
1733
1775
|
}
|
|
1734
1776
|
};
|
|
1777
|
+
defineParseLanes(nonEmptyParser, getOwnParseLanes(parser)?.map((lane) => ({
|
|
1778
|
+
priority: lane.priority,
|
|
1779
|
+
zeroConsumptionGroup: lane.zeroConsumptionGroup,
|
|
1780
|
+
settlesZeroConsumption: lane.settlesZeroConsumption,
|
|
1781
|
+
leadingNames: lane.leadingNames,
|
|
1782
|
+
acceptingAnyToken: lane.acceptingAnyToken,
|
|
1783
|
+
requiredConsumptionGroups: [...lane.requiredConsumptionGroups ?? [], { id: consumptionGroup }],
|
|
1784
|
+
parse(context) {
|
|
1785
|
+
return lane.parse(context);
|
|
1786
|
+
}
|
|
1787
|
+
})));
|
|
1735
1788
|
if ("placeholder" in parser) Object.defineProperty(nonEmptyParser, "placeholder", {
|
|
1736
1789
|
get() {
|
|
1737
1790
|
return parser.placeholder;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
"fast-check": "^4.7.0",
|
|
226
226
|
"tsdown": "^0.13.0",
|
|
227
227
|
"typescript": "^5.8.3",
|
|
228
|
-
"@optique/env": "1.2.
|
|
228
|
+
"@optique/env": "1.2.4"
|
|
229
229
|
},
|
|
230
230
|
"scripts": {
|
|
231
231
|
"build": "tsdown",
|