@optique/core 1.0.0-dev.1258 → 1.0.0-dev.1267
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 +104 -13
- package/dist/constructs.js +104 -13
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/valueparser.cjs +39 -0
- package/dist/valueparser.d.cts +15 -1
- package/dist/valueparser.d.ts +15 -1
- package/dist/valueparser.js +39 -1
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -9,6 +9,13 @@ const require_usage_internals = require('./usage-internals.cjs');
|
|
|
9
9
|
//#region src/constructs.ts
|
|
10
10
|
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
11
11
|
/**
|
|
12
|
+
* Internal symbol for exposing field-level parser pairs from `object()`
|
|
13
|
+
* and `merge()` parsers. This allows `merge()` to pre-complete dependency
|
|
14
|
+
* source fields from child parsers before resolving deferred states.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
const fieldParsersKey = Symbol("fieldParsers");
|
|
18
|
+
/**
|
|
12
19
|
* Returns the field state with parent annotations inherited, respecting
|
|
13
20
|
* the parser's {@link inheritParentAnnotationsKey} flag. This is the
|
|
14
21
|
* same logic as {@link createFieldStateGetter} inside `object()` but
|
|
@@ -777,6 +784,64 @@ async function completeDependencySourceDefaultsAsync(context, parserPairs, regis
|
|
|
777
784
|
}
|
|
778
785
|
}
|
|
779
786
|
/**
|
|
787
|
+
* Collects field-level parser pairs from child parsers that expose them
|
|
788
|
+
* via {@link fieldParsersKey}. Used by `merge()` to gather field→parser
|
|
789
|
+
* mappings from its child `object()` (or nested `merge()`) parsers.
|
|
790
|
+
* @internal
|
|
791
|
+
*/
|
|
792
|
+
function collectChildFieldParsers(parsers) {
|
|
793
|
+
const pairs = [];
|
|
794
|
+
for (const parser of parsers) if (fieldParsersKey in parser) pairs.push(...parser[fieldParsersKey]);
|
|
795
|
+
return pairs;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Pre-completes dependency source fields and registers their values in
|
|
799
|
+
* the given registry. Unlike `completeDependencySourceDefaults()` (used
|
|
800
|
+
* by suggest), this function handles all four Phase 1 cases — including
|
|
801
|
+
* PendingDependencySourceState in arrays and wrappedDependencySourceMarker.
|
|
802
|
+
*
|
|
803
|
+
* The original state is NOT modified; only the registry is populated.
|
|
804
|
+
* @internal
|
|
805
|
+
*/
|
|
806
|
+
function preCompleteAndRegisterDependencies(state, fieldParserPairs, registry) {
|
|
807
|
+
for (const [field, fieldParser] of fieldParserPairs) {
|
|
808
|
+
const fieldState = state[field];
|
|
809
|
+
let completed;
|
|
810
|
+
if (Array.isArray(fieldState) && fieldState.length === 1 && require_dependency.isPendingDependencySourceState(fieldState[0])) completed = fieldParser.complete(fieldState);
|
|
811
|
+
else if (fieldState === void 0 && require_dependency.isPendingDependencySourceState(fieldParser.initialState)) completed = fieldParser.complete([fieldParser.initialState]);
|
|
812
|
+
else if (fieldState === void 0 && require_dependency.isWrappedDependencySource(fieldParser)) {
|
|
813
|
+
const pendingState = fieldParser[require_dependency.wrappedDependencySourceMarker];
|
|
814
|
+
completed = fieldParser.complete([pendingState]);
|
|
815
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !require_dependency.isDependencySourceState(fieldState) && (require_dependency.isWrappedDependencySource(fieldParser) || require_dependency.isPendingDependencySourceState(fieldParser.initialState))) {
|
|
816
|
+
const annotatedFieldState = getAnnotatedFieldState(state, field, fieldParser);
|
|
817
|
+
completed = fieldParser.complete(annotatedFieldState);
|
|
818
|
+
} else continue;
|
|
819
|
+
const depState = wrapAsDependencySourceState(completed, fieldParser);
|
|
820
|
+
if (depState) registerCompletedDependency(depState, registry);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Async version of {@link preCompleteAndRegisterDependencies}.
|
|
825
|
+
* @internal
|
|
826
|
+
*/
|
|
827
|
+
async function preCompleteAndRegisterDependenciesAsync(state, fieldParserPairs, registry) {
|
|
828
|
+
for (const [field, fieldParser] of fieldParserPairs) {
|
|
829
|
+
const fieldState = state[field];
|
|
830
|
+
let completed;
|
|
831
|
+
if (Array.isArray(fieldState) && fieldState.length === 1 && require_dependency.isPendingDependencySourceState(fieldState[0])) completed = await fieldParser.complete(fieldState);
|
|
832
|
+
else if (fieldState === void 0 && require_dependency.isPendingDependencySourceState(fieldParser.initialState)) completed = await fieldParser.complete([fieldParser.initialState]);
|
|
833
|
+
else if (fieldState === void 0 && require_dependency.isWrappedDependencySource(fieldParser)) {
|
|
834
|
+
const pendingState = fieldParser[require_dependency.wrappedDependencySourceMarker];
|
|
835
|
+
completed = await fieldParser.complete([pendingState]);
|
|
836
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !require_dependency.isDependencySourceState(fieldState) && (require_dependency.isWrappedDependencySource(fieldParser) || require_dependency.isPendingDependencySourceState(fieldParser.initialState))) {
|
|
837
|
+
const annotatedFieldState = getAnnotatedFieldState(state, field, fieldParser);
|
|
838
|
+
completed = await fieldParser.complete(annotatedFieldState);
|
|
839
|
+
} else continue;
|
|
840
|
+
const depState = wrapAsDependencySourceState(completed, fieldParser);
|
|
841
|
+
if (depState) registerCompletedDependency(depState, registry);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
780
845
|
* Recursively collects dependency values from DependencySourceState objects
|
|
781
846
|
* found anywhere in the state tree.
|
|
782
847
|
* @internal
|
|
@@ -869,8 +934,8 @@ function resolveDeferred(state, registry, visited = /* @__PURE__ */ new WeakSet(
|
|
|
869
934
|
}
|
|
870
935
|
return state;
|
|
871
936
|
}
|
|
872
|
-
function resolveDeferredParseStates(fieldStates) {
|
|
873
|
-
const registry = new require_dependency.DependencyRegistry();
|
|
937
|
+
function resolveDeferredParseStates(fieldStates, initialRegistry) {
|
|
938
|
+
const registry = initialRegistry ?? new require_dependency.DependencyRegistry();
|
|
874
939
|
collectDependencies(fieldStates, registry);
|
|
875
940
|
return resolveDeferred(fieldStates, registry);
|
|
876
941
|
}
|
|
@@ -916,8 +981,8 @@ async function resolveDeferredAsync(state, registry, visited = /* @__PURE__ */ n
|
|
|
916
981
|
* Async version of resolveDeferredParseStates for async parsers.
|
|
917
982
|
* @internal
|
|
918
983
|
*/
|
|
919
|
-
async function resolveDeferredParseStatesAsync(fieldStates) {
|
|
920
|
-
const registry = new require_dependency.DependencyRegistry();
|
|
984
|
+
async function resolveDeferredParseStatesAsync(fieldStates, initialRegistry) {
|
|
985
|
+
const registry = initialRegistry ?? new require_dependency.DependencyRegistry();
|
|
921
986
|
collectDependencies(fieldStates, registry);
|
|
922
987
|
return await resolveDeferredAsync(fieldStates, registry);
|
|
923
988
|
}
|
|
@@ -1102,6 +1167,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1102
1167
|
$mode: combinedMode,
|
|
1103
1168
|
$valueType: [],
|
|
1104
1169
|
$stateType: [],
|
|
1170
|
+
[fieldParsersKey]: parserPairs,
|
|
1105
1171
|
priority: Math.max(...parserKeys.map((k) => parsers[k].priority)),
|
|
1106
1172
|
usage: applyHiddenToUsage(parserPairs.flatMap(([_, p]) => p.usage), options.hidden),
|
|
1107
1173
|
get initialState() {
|
|
@@ -1724,10 +1790,12 @@ function merge(...args) {
|
|
|
1724
1790
|
error: require_message.message`No matching option or argument found.`
|
|
1725
1791
|
};
|
|
1726
1792
|
};
|
|
1793
|
+
const mergedFieldParsers = collectChildFieldParsers(parsers);
|
|
1727
1794
|
return {
|
|
1728
1795
|
$mode: combinedMode,
|
|
1729
1796
|
$valueType: [],
|
|
1730
1797
|
$stateType: [],
|
|
1798
|
+
[fieldParsersKey]: mergedFieldParsers,
|
|
1731
1799
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
1732
1800
|
usage: applyHiddenToUsage(parsers.flatMap((p) => p.usage), options.hidden),
|
|
1733
1801
|
initialState,
|
|
@@ -1745,6 +1813,8 @@ function merge(...args) {
|
|
|
1745
1813
|
if (resolvedState && typeof resolvedState === "object") {
|
|
1746
1814
|
const extractedState = {};
|
|
1747
1815
|
for (const field in parser.initialState) extractedState[field] = field in resolvedState ? resolvedState[field] : parser.initialState[field];
|
|
1816
|
+
const annotations = require_annotations.getAnnotations(resolvedState);
|
|
1817
|
+
if (annotations !== void 0) return require_annotations.inheritAnnotations(resolvedState, extractedState);
|
|
1748
1818
|
return extractedState;
|
|
1749
1819
|
}
|
|
1750
1820
|
return parser.initialState;
|
|
@@ -1752,7 +1822,10 @@ function merge(...args) {
|
|
|
1752
1822
|
return parser.initialState;
|
|
1753
1823
|
};
|
|
1754
1824
|
if (!isAsync) {
|
|
1755
|
-
const
|
|
1825
|
+
const childFieldPairs = collectChildFieldParsers(syncParsers);
|
|
1826
|
+
const registry = new require_dependency.DependencyRegistry();
|
|
1827
|
+
preCompleteAndRegisterDependencies(state, childFieldPairs, registry);
|
|
1828
|
+
const resolvedState = resolveDeferredParseStates(state, registry);
|
|
1756
1829
|
const object$1 = {};
|
|
1757
1830
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
1758
1831
|
const parser = syncParsers[i];
|
|
@@ -1767,7 +1840,10 @@ function merge(...args) {
|
|
|
1767
1840
|
};
|
|
1768
1841
|
}
|
|
1769
1842
|
return (async () => {
|
|
1770
|
-
const
|
|
1843
|
+
const childFieldPairs = collectChildFieldParsers(parsers);
|
|
1844
|
+
const registry = new require_dependency.DependencyRegistry();
|
|
1845
|
+
await preCompleteAndRegisterDependenciesAsync(state, childFieldPairs, registry);
|
|
1846
|
+
const resolvedState = await resolveDeferredParseStatesAsync(state, registry);
|
|
1771
1847
|
const object$1 = {};
|
|
1772
1848
|
for (let i = 0; i < parsers.length; i++) {
|
|
1773
1849
|
const parser = parsers[i];
|
|
@@ -1799,19 +1875,23 @@ function merge(...args) {
|
|
|
1799
1875
|
}
|
|
1800
1876
|
return p.initialState;
|
|
1801
1877
|
};
|
|
1802
|
-
const registry = context.dependencyRegistry ? context.dependencyRegistry.clone() : new require_dependency.DependencyRegistry();
|
|
1803
|
-
if (context.state && typeof context.state === "object") collectDependencies(context.state, registry);
|
|
1804
|
-
const contextWithRegistry = {
|
|
1805
|
-
...context,
|
|
1806
|
-
dependencyRegistry: registry
|
|
1807
|
-
};
|
|
1808
1878
|
if (isAsync) return async function* () {
|
|
1879
|
+
const registry$1 = context.dependencyRegistry ? context.dependencyRegistry.clone() : new require_dependency.DependencyRegistry();
|
|
1880
|
+
const childFieldPairs$1 = collectChildFieldParsers(parsers);
|
|
1881
|
+
if (context.state && typeof context.state === "object") {
|
|
1882
|
+
await preCompleteAndRegisterDependenciesAsync(context.state, childFieldPairs$1, registry$1);
|
|
1883
|
+
collectDependencies(context.state, registry$1);
|
|
1884
|
+
} else await completeDependencySourceDefaultsAsync(context, childFieldPairs$1, registry$1);
|
|
1885
|
+
const contextWithRegistry$1 = {
|
|
1886
|
+
...context,
|
|
1887
|
+
dependencyRegistry: registry$1
|
|
1888
|
+
};
|
|
1809
1889
|
const suggestions = [];
|
|
1810
1890
|
for (let i = 0; i < parsers.length; i++) {
|
|
1811
1891
|
const parser = parsers[i];
|
|
1812
1892
|
const parserState = extractState(parser, i);
|
|
1813
1893
|
const parserSuggestions = parser.suggest({
|
|
1814
|
-
...contextWithRegistry,
|
|
1894
|
+
...contextWithRegistry$1,
|
|
1815
1895
|
state: parserState
|
|
1816
1896
|
}, prefix);
|
|
1817
1897
|
if (parser.$mode === "async") for await (const s of parserSuggestions) suggestions.push(s);
|
|
@@ -1819,6 +1899,16 @@ function merge(...args) {
|
|
|
1819
1899
|
}
|
|
1820
1900
|
yield* require_suggestion.deduplicateSuggestions(suggestions);
|
|
1821
1901
|
}();
|
|
1902
|
+
const registry = context.dependencyRegistry ? context.dependencyRegistry.clone() : new require_dependency.DependencyRegistry();
|
|
1903
|
+
const childFieldPairs = collectChildFieldParsers(syncParsers);
|
|
1904
|
+
if (context.state && typeof context.state === "object") {
|
|
1905
|
+
preCompleteAndRegisterDependencies(context.state, childFieldPairs, registry);
|
|
1906
|
+
collectDependencies(context.state, registry);
|
|
1907
|
+
} else completeDependencySourceDefaults(context, childFieldPairs, registry);
|
|
1908
|
+
const contextWithRegistry = {
|
|
1909
|
+
...context,
|
|
1910
|
+
dependencyRegistry: registry
|
|
1911
|
+
};
|
|
1822
1912
|
return function* () {
|
|
1823
1913
|
const suggestions = [];
|
|
1824
1914
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
@@ -2257,6 +2347,7 @@ function group(label, parser, options = {}) {
|
|
|
2257
2347
|
priority: parser.priority,
|
|
2258
2348
|
usage: applyHiddenToUsage(parser.usage, options.hidden),
|
|
2259
2349
|
initialState: parser.initialState,
|
|
2350
|
+
...fieldParsersKey in parser ? { [fieldParsersKey]: parser[fieldParsersKey] } : {},
|
|
2260
2351
|
...typeof parser.shouldDeferCompletion === "function" ? { shouldDeferCompletion: parser.shouldDeferCompletion.bind(parser) } : {},
|
|
2261
2352
|
parse: (context) => parser.parse(context),
|
|
2262
2353
|
complete: (state) => parser.complete(state),
|
package/dist/constructs.js
CHANGED
|
@@ -9,6 +9,13 @@ import { collectLeadingCandidates } from "./usage-internals.js";
|
|
|
9
9
|
//#region src/constructs.ts
|
|
10
10
|
const inheritParentAnnotationsKey = Symbol.for("@optique/core/inheritParentAnnotations");
|
|
11
11
|
/**
|
|
12
|
+
* Internal symbol for exposing field-level parser pairs from `object()`
|
|
13
|
+
* and `merge()` parsers. This allows `merge()` to pre-complete dependency
|
|
14
|
+
* source fields from child parsers before resolving deferred states.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
const fieldParsersKey = Symbol("fieldParsers");
|
|
18
|
+
/**
|
|
12
19
|
* Returns the field state with parent annotations inherited, respecting
|
|
13
20
|
* the parser's {@link inheritParentAnnotationsKey} flag. This is the
|
|
14
21
|
* same logic as {@link createFieldStateGetter} inside `object()` but
|
|
@@ -777,6 +784,64 @@ async function completeDependencySourceDefaultsAsync(context, parserPairs, regis
|
|
|
777
784
|
}
|
|
778
785
|
}
|
|
779
786
|
/**
|
|
787
|
+
* Collects field-level parser pairs from child parsers that expose them
|
|
788
|
+
* via {@link fieldParsersKey}. Used by `merge()` to gather field→parser
|
|
789
|
+
* mappings from its child `object()` (or nested `merge()`) parsers.
|
|
790
|
+
* @internal
|
|
791
|
+
*/
|
|
792
|
+
function collectChildFieldParsers(parsers) {
|
|
793
|
+
const pairs = [];
|
|
794
|
+
for (const parser of parsers) if (fieldParsersKey in parser) pairs.push(...parser[fieldParsersKey]);
|
|
795
|
+
return pairs;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Pre-completes dependency source fields and registers their values in
|
|
799
|
+
* the given registry. Unlike `completeDependencySourceDefaults()` (used
|
|
800
|
+
* by suggest), this function handles all four Phase 1 cases — including
|
|
801
|
+
* PendingDependencySourceState in arrays and wrappedDependencySourceMarker.
|
|
802
|
+
*
|
|
803
|
+
* The original state is NOT modified; only the registry is populated.
|
|
804
|
+
* @internal
|
|
805
|
+
*/
|
|
806
|
+
function preCompleteAndRegisterDependencies(state, fieldParserPairs, registry) {
|
|
807
|
+
for (const [field, fieldParser] of fieldParserPairs) {
|
|
808
|
+
const fieldState = state[field];
|
|
809
|
+
let completed;
|
|
810
|
+
if (Array.isArray(fieldState) && fieldState.length === 1 && isPendingDependencySourceState(fieldState[0])) completed = fieldParser.complete(fieldState);
|
|
811
|
+
else if (fieldState === void 0 && isPendingDependencySourceState(fieldParser.initialState)) completed = fieldParser.complete([fieldParser.initialState]);
|
|
812
|
+
else if (fieldState === void 0 && isWrappedDependencySource(fieldParser)) {
|
|
813
|
+
const pendingState = fieldParser[wrappedDependencySourceMarker];
|
|
814
|
+
completed = fieldParser.complete([pendingState]);
|
|
815
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !isDependencySourceState(fieldState) && (isWrappedDependencySource(fieldParser) || isPendingDependencySourceState(fieldParser.initialState))) {
|
|
816
|
+
const annotatedFieldState = getAnnotatedFieldState(state, field, fieldParser);
|
|
817
|
+
completed = fieldParser.complete(annotatedFieldState);
|
|
818
|
+
} else continue;
|
|
819
|
+
const depState = wrapAsDependencySourceState(completed, fieldParser);
|
|
820
|
+
if (depState) registerCompletedDependency(depState, registry);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Async version of {@link preCompleteAndRegisterDependencies}.
|
|
825
|
+
* @internal
|
|
826
|
+
*/
|
|
827
|
+
async function preCompleteAndRegisterDependenciesAsync(state, fieldParserPairs, registry) {
|
|
828
|
+
for (const [field, fieldParser] of fieldParserPairs) {
|
|
829
|
+
const fieldState = state[field];
|
|
830
|
+
let completed;
|
|
831
|
+
if (Array.isArray(fieldState) && fieldState.length === 1 && isPendingDependencySourceState(fieldState[0])) completed = await fieldParser.complete(fieldState);
|
|
832
|
+
else if (fieldState === void 0 && isPendingDependencySourceState(fieldParser.initialState)) completed = await fieldParser.complete([fieldParser.initialState]);
|
|
833
|
+
else if (fieldState === void 0 && isWrappedDependencySource(fieldParser)) {
|
|
834
|
+
const pendingState = fieldParser[wrappedDependencySourceMarker];
|
|
835
|
+
completed = await fieldParser.complete([pendingState]);
|
|
836
|
+
} else if (fieldState != null && !Array.isArray(fieldState) && !isDependencySourceState(fieldState) && (isWrappedDependencySource(fieldParser) || isPendingDependencySourceState(fieldParser.initialState))) {
|
|
837
|
+
const annotatedFieldState = getAnnotatedFieldState(state, field, fieldParser);
|
|
838
|
+
completed = await fieldParser.complete(annotatedFieldState);
|
|
839
|
+
} else continue;
|
|
840
|
+
const depState = wrapAsDependencySourceState(completed, fieldParser);
|
|
841
|
+
if (depState) registerCompletedDependency(depState, registry);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
780
845
|
* Recursively collects dependency values from DependencySourceState objects
|
|
781
846
|
* found anywhere in the state tree.
|
|
782
847
|
* @internal
|
|
@@ -869,8 +934,8 @@ function resolveDeferred(state, registry, visited = /* @__PURE__ */ new WeakSet(
|
|
|
869
934
|
}
|
|
870
935
|
return state;
|
|
871
936
|
}
|
|
872
|
-
function resolveDeferredParseStates(fieldStates) {
|
|
873
|
-
const registry = new DependencyRegistry();
|
|
937
|
+
function resolveDeferredParseStates(fieldStates, initialRegistry) {
|
|
938
|
+
const registry = initialRegistry ?? new DependencyRegistry();
|
|
874
939
|
collectDependencies(fieldStates, registry);
|
|
875
940
|
return resolveDeferred(fieldStates, registry);
|
|
876
941
|
}
|
|
@@ -916,8 +981,8 @@ async function resolveDeferredAsync(state, registry, visited = /* @__PURE__ */ n
|
|
|
916
981
|
* Async version of resolveDeferredParseStates for async parsers.
|
|
917
982
|
* @internal
|
|
918
983
|
*/
|
|
919
|
-
async function resolveDeferredParseStatesAsync(fieldStates) {
|
|
920
|
-
const registry = new DependencyRegistry();
|
|
984
|
+
async function resolveDeferredParseStatesAsync(fieldStates, initialRegistry) {
|
|
985
|
+
const registry = initialRegistry ?? new DependencyRegistry();
|
|
921
986
|
collectDependencies(fieldStates, registry);
|
|
922
987
|
return await resolveDeferredAsync(fieldStates, registry);
|
|
923
988
|
}
|
|
@@ -1102,6 +1167,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
1102
1167
|
$mode: combinedMode,
|
|
1103
1168
|
$valueType: [],
|
|
1104
1169
|
$stateType: [],
|
|
1170
|
+
[fieldParsersKey]: parserPairs,
|
|
1105
1171
|
priority: Math.max(...parserKeys.map((k) => parsers[k].priority)),
|
|
1106
1172
|
usage: applyHiddenToUsage(parserPairs.flatMap(([_, p]) => p.usage), options.hidden),
|
|
1107
1173
|
get initialState() {
|
|
@@ -1724,10 +1790,12 @@ function merge(...args) {
|
|
|
1724
1790
|
error: message`No matching option or argument found.`
|
|
1725
1791
|
};
|
|
1726
1792
|
};
|
|
1793
|
+
const mergedFieldParsers = collectChildFieldParsers(parsers);
|
|
1727
1794
|
return {
|
|
1728
1795
|
$mode: combinedMode,
|
|
1729
1796
|
$valueType: [],
|
|
1730
1797
|
$stateType: [],
|
|
1798
|
+
[fieldParsersKey]: mergedFieldParsers,
|
|
1731
1799
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
1732
1800
|
usage: applyHiddenToUsage(parsers.flatMap((p) => p.usage), options.hidden),
|
|
1733
1801
|
initialState,
|
|
@@ -1745,6 +1813,8 @@ function merge(...args) {
|
|
|
1745
1813
|
if (resolvedState && typeof resolvedState === "object") {
|
|
1746
1814
|
const extractedState = {};
|
|
1747
1815
|
for (const field in parser.initialState) extractedState[field] = field in resolvedState ? resolvedState[field] : parser.initialState[field];
|
|
1816
|
+
const annotations = getAnnotations(resolvedState);
|
|
1817
|
+
if (annotations !== void 0) return inheritAnnotations(resolvedState, extractedState);
|
|
1748
1818
|
return extractedState;
|
|
1749
1819
|
}
|
|
1750
1820
|
return parser.initialState;
|
|
@@ -1752,7 +1822,10 @@ function merge(...args) {
|
|
|
1752
1822
|
return parser.initialState;
|
|
1753
1823
|
};
|
|
1754
1824
|
if (!isAsync) {
|
|
1755
|
-
const
|
|
1825
|
+
const childFieldPairs = collectChildFieldParsers(syncParsers);
|
|
1826
|
+
const registry = new DependencyRegistry();
|
|
1827
|
+
preCompleteAndRegisterDependencies(state, childFieldPairs, registry);
|
|
1828
|
+
const resolvedState = resolveDeferredParseStates(state, registry);
|
|
1756
1829
|
const object$1 = {};
|
|
1757
1830
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
1758
1831
|
const parser = syncParsers[i];
|
|
@@ -1767,7 +1840,10 @@ function merge(...args) {
|
|
|
1767
1840
|
};
|
|
1768
1841
|
}
|
|
1769
1842
|
return (async () => {
|
|
1770
|
-
const
|
|
1843
|
+
const childFieldPairs = collectChildFieldParsers(parsers);
|
|
1844
|
+
const registry = new DependencyRegistry();
|
|
1845
|
+
await preCompleteAndRegisterDependenciesAsync(state, childFieldPairs, registry);
|
|
1846
|
+
const resolvedState = await resolveDeferredParseStatesAsync(state, registry);
|
|
1771
1847
|
const object$1 = {};
|
|
1772
1848
|
for (let i = 0; i < parsers.length; i++) {
|
|
1773
1849
|
const parser = parsers[i];
|
|
@@ -1799,19 +1875,23 @@ function merge(...args) {
|
|
|
1799
1875
|
}
|
|
1800
1876
|
return p.initialState;
|
|
1801
1877
|
};
|
|
1802
|
-
const registry = context.dependencyRegistry ? context.dependencyRegistry.clone() : new DependencyRegistry();
|
|
1803
|
-
if (context.state && typeof context.state === "object") collectDependencies(context.state, registry);
|
|
1804
|
-
const contextWithRegistry = {
|
|
1805
|
-
...context,
|
|
1806
|
-
dependencyRegistry: registry
|
|
1807
|
-
};
|
|
1808
1878
|
if (isAsync) return async function* () {
|
|
1879
|
+
const registry$1 = context.dependencyRegistry ? context.dependencyRegistry.clone() : new DependencyRegistry();
|
|
1880
|
+
const childFieldPairs$1 = collectChildFieldParsers(parsers);
|
|
1881
|
+
if (context.state && typeof context.state === "object") {
|
|
1882
|
+
await preCompleteAndRegisterDependenciesAsync(context.state, childFieldPairs$1, registry$1);
|
|
1883
|
+
collectDependencies(context.state, registry$1);
|
|
1884
|
+
} else await completeDependencySourceDefaultsAsync(context, childFieldPairs$1, registry$1);
|
|
1885
|
+
const contextWithRegistry$1 = {
|
|
1886
|
+
...context,
|
|
1887
|
+
dependencyRegistry: registry$1
|
|
1888
|
+
};
|
|
1809
1889
|
const suggestions = [];
|
|
1810
1890
|
for (let i = 0; i < parsers.length; i++) {
|
|
1811
1891
|
const parser = parsers[i];
|
|
1812
1892
|
const parserState = extractState(parser, i);
|
|
1813
1893
|
const parserSuggestions = parser.suggest({
|
|
1814
|
-
...contextWithRegistry,
|
|
1894
|
+
...contextWithRegistry$1,
|
|
1815
1895
|
state: parserState
|
|
1816
1896
|
}, prefix);
|
|
1817
1897
|
if (parser.$mode === "async") for await (const s of parserSuggestions) suggestions.push(s);
|
|
@@ -1819,6 +1899,16 @@ function merge(...args) {
|
|
|
1819
1899
|
}
|
|
1820
1900
|
yield* deduplicateSuggestions(suggestions);
|
|
1821
1901
|
}();
|
|
1902
|
+
const registry = context.dependencyRegistry ? context.dependencyRegistry.clone() : new DependencyRegistry();
|
|
1903
|
+
const childFieldPairs = collectChildFieldParsers(syncParsers);
|
|
1904
|
+
if (context.state && typeof context.state === "object") {
|
|
1905
|
+
preCompleteAndRegisterDependencies(context.state, childFieldPairs, registry);
|
|
1906
|
+
collectDependencies(context.state, registry);
|
|
1907
|
+
} else completeDependencySourceDefaults(context, childFieldPairs, registry);
|
|
1908
|
+
const contextWithRegistry = {
|
|
1909
|
+
...context,
|
|
1910
|
+
dependencyRegistry: registry
|
|
1911
|
+
};
|
|
1822
1912
|
return function* () {
|
|
1823
1913
|
const suggestions = [];
|
|
1824
1914
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
@@ -2257,6 +2347,7 @@ function group(label, parser, options = {}) {
|
|
|
2257
2347
|
priority: parser.priority,
|
|
2258
2348
|
usage: applyHiddenToUsage(parser.usage, options.hidden),
|
|
2259
2349
|
initialState: parser.initialState,
|
|
2350
|
+
...fieldParsersKey in parser ? { [fieldParsersKey]: parser[fieldParsersKey] } : {},
|
|
2260
2351
|
...typeof parser.shouldDeferCompletion === "function" ? { shouldDeferCompletion: parser.shouldDeferCompletion.bind(parser) } : {},
|
|
2261
2352
|
parse: (context) => parser.parse(context),
|
|
2262
2353
|
complete: (state) => parser.complete(state),
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ exports.annotationKey = require_annotations.annotationKey;
|
|
|
20
20
|
exports.argument = require_primitives.argument;
|
|
21
21
|
exports.bash = require_completion.bash;
|
|
22
22
|
exports.checkBooleanOption = require_valueparser.checkBooleanOption;
|
|
23
|
+
exports.checkEnumOption = require_valueparser.checkEnumOption;
|
|
23
24
|
exports.choice = require_valueparser.choice;
|
|
24
25
|
exports.cidr = require_valueparser.cidr;
|
|
25
26
|
exports.command = require_primitives.command;
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonemp
|
|
|
3
3
|
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
|
|
4
4
|
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
|
|
5
5
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
|
|
6
|
-
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.cjs";
|
|
6
|
+
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.cjs";
|
|
7
7
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
|
|
8
8
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
|
|
9
9
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.cjs";
|
|
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
|
|
|
12
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
13
13
|
import { ParserValuePlaceholder, SourceContext } from "./context.cjs";
|
|
14
14
|
import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
|
|
15
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
15
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonemp
|
|
|
3
3
|
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
4
4
|
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
5
5
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage } from "./doc.js";
|
|
6
|
-
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
|
|
6
|
+
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
|
|
7
7
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
8
8
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
9
9
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
|
|
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
|
|
|
12
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
13
13
|
import { ParserValuePlaceholder, SourceContext } from "./context.js";
|
|
14
14
|
import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
15
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
15
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.js
CHANGED
|
@@ -7,9 +7,9 @@ import { DuplicateOptionError, concat, conditional, group, longestMatch, merge,
|
|
|
7
7
|
import { formatDocPage } from "./doc.js";
|
|
8
8
|
import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
9
9
|
import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
10
|
-
import { checkBooleanOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
|
|
10
|
+
import { checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
|
|
11
11
|
import { argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
|
|
12
12
|
import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
13
13
|
import { RunParserError, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
14
14
|
|
|
15
|
-
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, checkBooleanOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
15
|
+
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/valueparser.cjs
CHANGED
|
@@ -173,6 +173,26 @@ function checkBooleanOption(options, key) {
|
|
|
173
173
|
if (value !== void 0 && typeof value !== "boolean") throw new TypeError(`Expected ${String(key)} to be a boolean, but got ${typeof value}: ${String(value)}.`);
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
|
+
* Validates that an option value, if present, is one of the allowed values.
|
|
177
|
+
* Throws a {@link TypeError} if the value is defined but not in the allowed
|
|
178
|
+
* list.
|
|
179
|
+
*
|
|
180
|
+
* @template T The type of the options object.
|
|
181
|
+
* @param options The options object to check.
|
|
182
|
+
* @param key The key of the option to validate.
|
|
183
|
+
* @param allowed The list of allowed values.
|
|
184
|
+
* @throws {TypeError} If the option value is defined but not in the allowed
|
|
185
|
+
* list.
|
|
186
|
+
* @since 1.0.0
|
|
187
|
+
*/
|
|
188
|
+
function checkEnumOption(options, key, allowed) {
|
|
189
|
+
const value = options?.[key];
|
|
190
|
+
if (value !== void 0 && (typeof value !== "string" || !allowed.includes(value))) {
|
|
191
|
+
const rendered = typeof value === "string" ? JSON.stringify(value) : typeof value === "symbol" ? value.toString() : String(value);
|
|
192
|
+
throw new TypeError(`Expected ${String(key)} to be one of ${allowed.map((v) => JSON.stringify(v)).join(", ")}, but got ${typeof value}: ${rendered}.`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
176
196
|
* Expands a numeric string in scientific notation (e.g., `"1e+21"`,
|
|
177
197
|
* `"1.5e-3"`, `".1e-6"`) into plain decimal form for normalization.
|
|
178
198
|
* Used for both canonical `String(number)` output and user input.
|
|
@@ -1877,6 +1897,24 @@ function portRange(options) {
|
|
|
1877
1897
|
* ```
|
|
1878
1898
|
*/
|
|
1879
1899
|
function macAddress(options) {
|
|
1900
|
+
checkEnumOption(options, "separator", [
|
|
1901
|
+
":",
|
|
1902
|
+
"-",
|
|
1903
|
+
".",
|
|
1904
|
+
"none",
|
|
1905
|
+
"any"
|
|
1906
|
+
]);
|
|
1907
|
+
checkEnumOption(options, "outputSeparator", [
|
|
1908
|
+
":",
|
|
1909
|
+
"-",
|
|
1910
|
+
".",
|
|
1911
|
+
"none"
|
|
1912
|
+
]);
|
|
1913
|
+
checkEnumOption(options, "case", [
|
|
1914
|
+
"preserve",
|
|
1915
|
+
"upper",
|
|
1916
|
+
"lower"
|
|
1917
|
+
]);
|
|
1880
1918
|
const separator = options?.separator ?? "any";
|
|
1881
1919
|
const caseOption = options?.case ?? "preserve";
|
|
1882
1920
|
const outputSeparator = options?.outputSeparator;
|
|
@@ -3072,6 +3110,7 @@ function cidr(options) {
|
|
|
3072
3110
|
|
|
3073
3111
|
//#endregion
|
|
3074
3112
|
exports.checkBooleanOption = checkBooleanOption;
|
|
3113
|
+
exports.checkEnumOption = checkEnumOption;
|
|
3075
3114
|
exports.choice = choice;
|
|
3076
3115
|
exports.cidr = cidr;
|
|
3077
3116
|
exports.domain = domain;
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -244,6 +244,20 @@ declare function choice<const T extends number>(choices: readonly T[], options?:
|
|
|
244
244
|
* @since 1.0.0
|
|
245
245
|
*/
|
|
246
246
|
declare function checkBooleanOption<T extends object>(options: T | undefined, key: keyof T): void;
|
|
247
|
+
/**
|
|
248
|
+
* Validates that an option value, if present, is one of the allowed values.
|
|
249
|
+
* Throws a {@link TypeError} if the value is defined but not in the allowed
|
|
250
|
+
* list.
|
|
251
|
+
*
|
|
252
|
+
* @template T The type of the options object.
|
|
253
|
+
* @param options The options object to check.
|
|
254
|
+
* @param key The key of the option to validate.
|
|
255
|
+
* @param allowed The list of allowed values.
|
|
256
|
+
* @throws {TypeError} If the option value is defined but not in the allowed
|
|
257
|
+
* list.
|
|
258
|
+
* @since 1.0.0
|
|
259
|
+
*/
|
|
260
|
+
declare function checkEnumOption<T extends object>(options: T | undefined, key: keyof T, allowed: readonly string[]): void;
|
|
247
261
|
/**
|
|
248
262
|
* Creates a {@link ValueParser} for strings.
|
|
249
263
|
*
|
|
@@ -1995,4 +2009,4 @@ interface CidrOptions {
|
|
|
1995
2009
|
*/
|
|
1996
2010
|
declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
|
|
1997
2011
|
//#endregion
|
|
1998
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
|
2012
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -244,6 +244,20 @@ declare function choice<const T extends number>(choices: readonly T[], options?:
|
|
|
244
244
|
* @since 1.0.0
|
|
245
245
|
*/
|
|
246
246
|
declare function checkBooleanOption<T extends object>(options: T | undefined, key: keyof T): void;
|
|
247
|
+
/**
|
|
248
|
+
* Validates that an option value, if present, is one of the allowed values.
|
|
249
|
+
* Throws a {@link TypeError} if the value is defined but not in the allowed
|
|
250
|
+
* list.
|
|
251
|
+
*
|
|
252
|
+
* @template T The type of the options object.
|
|
253
|
+
* @param options The options object to check.
|
|
254
|
+
* @param key The key of the option to validate.
|
|
255
|
+
* @param allowed The list of allowed values.
|
|
256
|
+
* @throws {TypeError} If the option value is defined but not in the allowed
|
|
257
|
+
* list.
|
|
258
|
+
* @since 1.0.0
|
|
259
|
+
*/
|
|
260
|
+
declare function checkEnumOption<T extends object>(options: T | undefined, key: keyof T, allowed: readonly string[]): void;
|
|
247
261
|
/**
|
|
248
262
|
* Creates a {@link ValueParser} for strings.
|
|
249
263
|
*
|
|
@@ -1995,4 +2009,4 @@ interface CidrOptions {
|
|
|
1995
2009
|
*/
|
|
1996
2010
|
declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
|
|
1997
2011
|
//#endregion
|
|
1998
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
|
2012
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
package/dist/valueparser.js
CHANGED
|
@@ -173,6 +173,26 @@ function checkBooleanOption(options, key) {
|
|
|
173
173
|
if (value !== void 0 && typeof value !== "boolean") throw new TypeError(`Expected ${String(key)} to be a boolean, but got ${typeof value}: ${String(value)}.`);
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
|
+
* Validates that an option value, if present, is one of the allowed values.
|
|
177
|
+
* Throws a {@link TypeError} if the value is defined but not in the allowed
|
|
178
|
+
* list.
|
|
179
|
+
*
|
|
180
|
+
* @template T The type of the options object.
|
|
181
|
+
* @param options The options object to check.
|
|
182
|
+
* @param key The key of the option to validate.
|
|
183
|
+
* @param allowed The list of allowed values.
|
|
184
|
+
* @throws {TypeError} If the option value is defined but not in the allowed
|
|
185
|
+
* list.
|
|
186
|
+
* @since 1.0.0
|
|
187
|
+
*/
|
|
188
|
+
function checkEnumOption(options, key, allowed) {
|
|
189
|
+
const value = options?.[key];
|
|
190
|
+
if (value !== void 0 && (typeof value !== "string" || !allowed.includes(value))) {
|
|
191
|
+
const rendered = typeof value === "string" ? JSON.stringify(value) : typeof value === "symbol" ? value.toString() : String(value);
|
|
192
|
+
throw new TypeError(`Expected ${String(key)} to be one of ${allowed.map((v) => JSON.stringify(v)).join(", ")}, but got ${typeof value}: ${rendered}.`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
176
196
|
* Expands a numeric string in scientific notation (e.g., `"1e+21"`,
|
|
177
197
|
* `"1.5e-3"`, `".1e-6"`) into plain decimal form for normalization.
|
|
178
198
|
* Used for both canonical `String(number)` output and user input.
|
|
@@ -1877,6 +1897,24 @@ function portRange(options) {
|
|
|
1877
1897
|
* ```
|
|
1878
1898
|
*/
|
|
1879
1899
|
function macAddress(options) {
|
|
1900
|
+
checkEnumOption(options, "separator", [
|
|
1901
|
+
":",
|
|
1902
|
+
"-",
|
|
1903
|
+
".",
|
|
1904
|
+
"none",
|
|
1905
|
+
"any"
|
|
1906
|
+
]);
|
|
1907
|
+
checkEnumOption(options, "outputSeparator", [
|
|
1908
|
+
":",
|
|
1909
|
+
"-",
|
|
1910
|
+
".",
|
|
1911
|
+
"none"
|
|
1912
|
+
]);
|
|
1913
|
+
checkEnumOption(options, "case", [
|
|
1914
|
+
"preserve",
|
|
1915
|
+
"upper",
|
|
1916
|
+
"lower"
|
|
1917
|
+
]);
|
|
1880
1918
|
const separator = options?.separator ?? "any";
|
|
1881
1919
|
const caseOption = options?.case ?? "preserve";
|
|
1882
1920
|
const outputSeparator = options?.outputSeparator;
|
|
@@ -3071,4 +3109,4 @@ function cidr(options) {
|
|
|
3071
3109
|
}
|
|
3072
3110
|
|
|
3073
3111
|
//#endregion
|
|
3074
|
-
export { checkBooleanOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
|
3112
|
+
export { checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|