@optique/core 0.10.0-dev.292 → 0.10.0-dev.294
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 +144 -50
- package/dist/constructs.js +144 -50
- package/dist/dependency.cjs +166 -6
- package/dist/dependency.d.cts +191 -10
- package/dist/dependency.d.ts +191 -10
- package/dist/dependency.js +164 -7
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/primitives.cjs +2 -1
- package/dist/primitives.js +2 -1
- package/package.json +1 -1
package/dist/dependency.d.ts
CHANGED
|
@@ -24,19 +24,34 @@ declare const DerivedValueParserMarker: unique symbol;
|
|
|
24
24
|
* @since 0.10.0
|
|
25
25
|
*/
|
|
26
26
|
declare const DependencyId: unique symbol;
|
|
27
|
+
/**
|
|
28
|
+
* A unique symbol used to store multiple dependency IDs on derived parsers
|
|
29
|
+
* that depend on multiple sources (created via {@link deriveFrom}).
|
|
30
|
+
* @since 0.10.0
|
|
31
|
+
*/
|
|
32
|
+
declare const DependencyIds: unique symbol;
|
|
27
33
|
/**
|
|
28
34
|
* A unique symbol used to access the parseWithDependency method on derived parsers.
|
|
29
35
|
* @since 0.10.0
|
|
30
36
|
*/
|
|
31
37
|
declare const ParseWithDependency: unique symbol;
|
|
38
|
+
/**
|
|
39
|
+
* Combines two modes into a single mode.
|
|
40
|
+
* If either mode is async, the result is async.
|
|
41
|
+
* @template M1 The first mode.
|
|
42
|
+
* @template M2 The second mode.
|
|
43
|
+
* @since 0.10.0
|
|
44
|
+
*/
|
|
45
|
+
type CombineMode<M1 extends Mode, M2 extends Mode> = M1 extends "async" ? "async" : M2 extends "async" ? "async" : "sync";
|
|
32
46
|
/**
|
|
33
47
|
* Options for creating a derived value parser.
|
|
34
48
|
*
|
|
35
49
|
* @template S The type of the source dependency value.
|
|
36
50
|
* @template T The type of the derived parser value.
|
|
51
|
+
* @template FM The mode of the factory's returned parser.
|
|
37
52
|
* @since 0.10.0
|
|
38
53
|
*/
|
|
39
|
-
interface DeriveOptions<S, T> {
|
|
54
|
+
interface DeriveOptions<S, T, FM extends Mode = Mode> {
|
|
40
55
|
/**
|
|
41
56
|
* The metavariable name for the derived parser. Used in help messages
|
|
42
57
|
* to indicate what kind of value this parser expects.
|
|
@@ -49,7 +64,7 @@ interface DeriveOptions<S, T> {
|
|
|
49
64
|
* @param sourceValue The value parsed from the dependency source.
|
|
50
65
|
* @returns A {@link ValueParser} for the derived value.
|
|
51
66
|
*/
|
|
52
|
-
readonly factory: (sourceValue: S) => ValueParser<
|
|
67
|
+
readonly factory: (sourceValue: S) => ValueParser<FM, T>;
|
|
53
68
|
/**
|
|
54
69
|
* Default value to use when the dependency source is not provided.
|
|
55
70
|
* This allows the derived parser to work even when the dependency
|
|
@@ -59,6 +74,48 @@ interface DeriveOptions<S, T> {
|
|
|
59
74
|
*/
|
|
60
75
|
readonly defaultValue: () => S;
|
|
61
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Options for creating a derived value parser with a synchronous factory.
|
|
79
|
+
*
|
|
80
|
+
* @template S The type of the source dependency value.
|
|
81
|
+
* @template T The type of the derived parser value.
|
|
82
|
+
* @since 0.10.0
|
|
83
|
+
*/
|
|
84
|
+
interface DeriveSyncOptions<S, T> {
|
|
85
|
+
/**
|
|
86
|
+
* The metavariable name for the derived parser.
|
|
87
|
+
*/
|
|
88
|
+
readonly metavar: NonEmptyString;
|
|
89
|
+
/**
|
|
90
|
+
* Factory function that creates a synchronous {@link ValueParser}.
|
|
91
|
+
*/
|
|
92
|
+
readonly factory: (sourceValue: S) => ValueParser<"sync", T>;
|
|
93
|
+
/**
|
|
94
|
+
* Default value to use when the dependency source is not provided.
|
|
95
|
+
*/
|
|
96
|
+
readonly defaultValue: () => S;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Options for creating a derived value parser with an asynchronous factory.
|
|
100
|
+
*
|
|
101
|
+
* @template S The type of the source dependency value.
|
|
102
|
+
* @template T The type of the derived parser value.
|
|
103
|
+
* @since 0.10.0
|
|
104
|
+
*/
|
|
105
|
+
interface DeriveAsyncOptions<S, T> {
|
|
106
|
+
/**
|
|
107
|
+
* The metavariable name for the derived parser.
|
|
108
|
+
*/
|
|
109
|
+
readonly metavar: NonEmptyString;
|
|
110
|
+
/**
|
|
111
|
+
* Factory function that creates an asynchronous {@link ValueParser}.
|
|
112
|
+
*/
|
|
113
|
+
readonly factory: (sourceValue: S) => ValueParser<"async", T>;
|
|
114
|
+
/**
|
|
115
|
+
* Default value to use when the dependency source is not provided.
|
|
116
|
+
*/
|
|
117
|
+
readonly defaultValue: () => S;
|
|
118
|
+
}
|
|
62
119
|
/**
|
|
63
120
|
* Represents a dependency source that can be used to create derived parsers.
|
|
64
121
|
*
|
|
@@ -87,14 +144,40 @@ interface DependencySource<M extends Mode = "sync", T = unknown> extends ValuePa
|
|
|
87
144
|
* dependency source's value.
|
|
88
145
|
*
|
|
89
146
|
* The derived parser uses a factory function to create parsers based on
|
|
90
|
-
* the source value.
|
|
91
|
-
*
|
|
147
|
+
* the source value. The factory can return either a sync or async parser,
|
|
148
|
+
* and the resulting derived parser's mode will be the combination of
|
|
149
|
+
* the source mode and the factory's returned parser mode.
|
|
92
150
|
*
|
|
93
151
|
* @template U The type of value the derived parser produces.
|
|
152
|
+
* @template FM The mode of the factory's returned parser.
|
|
94
153
|
* @param options Configuration for the derived parser.
|
|
95
154
|
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
96
155
|
*/
|
|
97
|
-
derive<U>(options: DeriveOptions<T, U>): DerivedValueParser<M, U, T>;
|
|
156
|
+
derive<U, FM extends Mode = "sync">(options: DeriveOptions<T, U, FM>): DerivedValueParser<CombineMode<M, FM>, U, T>;
|
|
157
|
+
/**
|
|
158
|
+
* Creates a derived value parser with a synchronous factory.
|
|
159
|
+
*
|
|
160
|
+
* This is a convenience method that explicitly requires a sync factory,
|
|
161
|
+
* making the type inference more predictable.
|
|
162
|
+
*
|
|
163
|
+
* @template U The type of value the derived parser produces.
|
|
164
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
165
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
166
|
+
* @since 0.10.0
|
|
167
|
+
*/
|
|
168
|
+
deriveSync<U>(options: DeriveSyncOptions<T, U>): DerivedValueParser<M, U, T>;
|
|
169
|
+
/**
|
|
170
|
+
* Creates a derived value parser with an asynchronous factory.
|
|
171
|
+
*
|
|
172
|
+
* This is a convenience method that explicitly requires an async factory,
|
|
173
|
+
* making the type inference more predictable.
|
|
174
|
+
*
|
|
175
|
+
* @template U The type of value the derived parser produces.
|
|
176
|
+
* @param options Configuration for the derived parser with async factory.
|
|
177
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
178
|
+
* @since 0.10.0
|
|
179
|
+
*/
|
|
180
|
+
deriveAsync<U>(options: DeriveAsyncOptions<T, U>): DerivedValueParser<"async", U, T>;
|
|
98
181
|
}
|
|
99
182
|
/**
|
|
100
183
|
* Extracts the value type from a DependencySource.
|
|
@@ -131,9 +214,10 @@ type AnyDependencySource = DependencySource<Mode, any>;
|
|
|
131
214
|
*
|
|
132
215
|
* @template Deps A tuple of DependencySource types.
|
|
133
216
|
* @template T The type of the derived parser value.
|
|
217
|
+
* @template FM The mode of the factory's returned parser.
|
|
134
218
|
* @since 0.10.0
|
|
135
219
|
*/
|
|
136
|
-
interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
220
|
+
interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T, FM extends Mode = Mode> {
|
|
137
221
|
/**
|
|
138
222
|
* The metavariable name for the derived parser. Used in help messages
|
|
139
223
|
* to indicate what kind of value this parser expects.
|
|
@@ -150,7 +234,7 @@ interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
|
150
234
|
* @param values The values parsed from the dependency sources (in order).
|
|
151
235
|
* @returns A {@link ValueParser} for the derived value.
|
|
152
236
|
*/
|
|
153
|
-
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<
|
|
237
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<FM, T>;
|
|
154
238
|
/**
|
|
155
239
|
* Default values to use when the dependency sources are not provided.
|
|
156
240
|
* Must return a tuple with the same length and types as the dependencies.
|
|
@@ -159,6 +243,58 @@ interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
|
159
243
|
*/
|
|
160
244
|
readonly defaultValues: () => DependencyValues<Deps>;
|
|
161
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Options for creating a derived value parser from multiple dependencies
|
|
248
|
+
* with a synchronous factory.
|
|
249
|
+
*
|
|
250
|
+
* @template Deps A tuple of DependencySource types.
|
|
251
|
+
* @template T The type of the derived parser value.
|
|
252
|
+
* @since 0.10.0
|
|
253
|
+
*/
|
|
254
|
+
interface DeriveFromSyncOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
255
|
+
/**
|
|
256
|
+
* The metavariable name for the derived parser.
|
|
257
|
+
*/
|
|
258
|
+
readonly metavar: NonEmptyString;
|
|
259
|
+
/**
|
|
260
|
+
* The dependency sources that this derived parser depends on.
|
|
261
|
+
*/
|
|
262
|
+
readonly dependencies: Deps;
|
|
263
|
+
/**
|
|
264
|
+
* Factory function that creates a synchronous {@link ValueParser}.
|
|
265
|
+
*/
|
|
266
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"sync", T>;
|
|
267
|
+
/**
|
|
268
|
+
* Default values to use when the dependency sources are not provided.
|
|
269
|
+
*/
|
|
270
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Options for creating a derived value parser from multiple dependencies
|
|
274
|
+
* with an asynchronous factory.
|
|
275
|
+
*
|
|
276
|
+
* @template Deps A tuple of DependencySource types.
|
|
277
|
+
* @template T The type of the derived parser value.
|
|
278
|
+
* @since 0.10.0
|
|
279
|
+
*/
|
|
280
|
+
interface DeriveFromAsyncOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
281
|
+
/**
|
|
282
|
+
* The metavariable name for the derived parser.
|
|
283
|
+
*/
|
|
284
|
+
readonly metavar: NonEmptyString;
|
|
285
|
+
/**
|
|
286
|
+
* The dependency sources that this derived parser depends on.
|
|
287
|
+
*/
|
|
288
|
+
readonly dependencies: Deps;
|
|
289
|
+
/**
|
|
290
|
+
* Factory function that creates an asynchronous {@link ValueParser}.
|
|
291
|
+
*/
|
|
292
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"async", T>;
|
|
293
|
+
/**
|
|
294
|
+
* Default values to use when the dependency sources are not provided.
|
|
295
|
+
*/
|
|
296
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
297
|
+
}
|
|
162
298
|
/**
|
|
163
299
|
* A value parser that depends on another parser's value.
|
|
164
300
|
*
|
|
@@ -178,9 +314,19 @@ interface DerivedValueParser<M extends Mode = "sync", T = unknown, S = unknown>
|
|
|
178
314
|
readonly [DerivedValueParserMarker]: true;
|
|
179
315
|
/**
|
|
180
316
|
* The unique identifier of the dependency source this parser depends on.
|
|
317
|
+
* For parsers created with {@link deriveFrom} that have multiple dependencies,
|
|
318
|
+
* this is set to the first dependency's ID for backwards compatibility.
|
|
181
319
|
* @internal
|
|
182
320
|
*/
|
|
183
321
|
readonly [DependencyId]: symbol;
|
|
322
|
+
/**
|
|
323
|
+
* The unique identifiers of all dependency sources this parser depends on.
|
|
324
|
+
* Present only for parsers created with {@link deriveFrom} that have multiple
|
|
325
|
+
* dependencies. If present, this takes precedence over {@link DependencyId}
|
|
326
|
+
* during dependency resolution.
|
|
327
|
+
* @internal
|
|
328
|
+
*/
|
|
329
|
+
readonly [DependencyIds]?: readonly symbol[];
|
|
184
330
|
/**
|
|
185
331
|
* Parses the input using the actual dependency value instead of the default.
|
|
186
332
|
* This method is used during dependency resolution in `complete()`.
|
|
@@ -269,7 +415,37 @@ declare function isDerivedValueParser<M extends Mode, T>(parser: ValueParser<M,
|
|
|
269
415
|
* ```
|
|
270
416
|
* @since 0.10.0
|
|
271
417
|
*/
|
|
272
|
-
declare function deriveFrom<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromOptions<Deps, T>): DerivedValueParser<CombinedDependencyMode<Deps>, T, DependencyValues<Deps>>;
|
|
418
|
+
declare function deriveFrom<Deps extends readonly AnyDependencySource[], T, FM extends Mode = "sync">(options: DeriveFromOptions<Deps, T, FM>): DerivedValueParser<CombineMode<CombinedDependencyMode<Deps>, FM>, T, DependencyValues<Deps>>;
|
|
419
|
+
/**
|
|
420
|
+
* Creates a derived value parser from multiple dependency sources
|
|
421
|
+
* with a synchronous factory.
|
|
422
|
+
*
|
|
423
|
+
* This function allows creating a parser whose behavior depends on
|
|
424
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
425
|
+
* a sync parser.
|
|
426
|
+
*
|
|
427
|
+
* @template Deps A tuple of DependencySource types.
|
|
428
|
+
* @template T The type of value the derived parser produces.
|
|
429
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
430
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
431
|
+
* @since 0.10.0
|
|
432
|
+
*/
|
|
433
|
+
declare function deriveFromSync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromSyncOptions<Deps, T>): DerivedValueParser<CombinedDependencyMode<Deps>, T, DependencyValues<Deps>>;
|
|
434
|
+
/**
|
|
435
|
+
* Creates a derived value parser from multiple dependency sources
|
|
436
|
+
* with an asynchronous factory.
|
|
437
|
+
*
|
|
438
|
+
* This function allows creating a parser whose behavior depends on
|
|
439
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
440
|
+
* an async parser.
|
|
441
|
+
*
|
|
442
|
+
* @template Deps A tuple of DependencySource types.
|
|
443
|
+
* @template T The type of value the derived parser produces.
|
|
444
|
+
* @param options Configuration for the derived parser with async factory.
|
|
445
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
446
|
+
* @since 0.10.0
|
|
447
|
+
*/
|
|
448
|
+
declare function deriveFromAsync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromAsyncOptions<Deps, T>): DerivedValueParser<"async", T, DependencyValues<Deps>>;
|
|
273
449
|
/**
|
|
274
450
|
* A unique symbol used to identify deferred parse states.
|
|
275
451
|
* @since 0.10.0
|
|
@@ -300,9 +476,14 @@ interface DeferredParseState<T = unknown> {
|
|
|
300
476
|
*/
|
|
301
477
|
readonly parser: DerivedValueParser<Mode, T, unknown>;
|
|
302
478
|
/**
|
|
303
|
-
* The dependency ID that this parser depends on.
|
|
479
|
+
* The dependency ID that this parser depends on (for single-dependency parsers).
|
|
304
480
|
*/
|
|
305
481
|
readonly dependencyId: symbol;
|
|
482
|
+
/**
|
|
483
|
+
* The dependency IDs that this parser depends on (for multi-dependency parsers).
|
|
484
|
+
* If present, this is used instead of `dependencyId`.
|
|
485
|
+
*/
|
|
486
|
+
readonly dependencyIds?: readonly symbol[];
|
|
306
487
|
/**
|
|
307
488
|
* The preliminary parse result using the default dependency value.
|
|
308
489
|
* This is used as a fallback if dependency resolution is not needed
|
|
@@ -454,4 +635,4 @@ type DependencyError = {
|
|
|
454
635
|
*/
|
|
455
636
|
declare function formatDependencyError(error: DependencyError): Message;
|
|
456
637
|
//#endregion
|
|
457
|
-
export { AnyDependencySource, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveFromOptions, DeriveOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
|
|
638
|
+
export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
|
package/dist/dependency.js
CHANGED
|
@@ -19,6 +19,12 @@ const DerivedValueParserMarker = Symbol.for("@optique/core/dependency/DerivedVal
|
|
|
19
19
|
*/
|
|
20
20
|
const DependencyId = Symbol.for("@optique/core/dependency/DependencyId");
|
|
21
21
|
/**
|
|
22
|
+
* A unique symbol used to store multiple dependency IDs on derived parsers
|
|
23
|
+
* that depend on multiple sources (created via {@link deriveFrom}).
|
|
24
|
+
* @since 0.10.0
|
|
25
|
+
*/
|
|
26
|
+
const DependencyIds = Symbol.for("@optique/core/dependency/DependencyIds");
|
|
27
|
+
/**
|
|
22
28
|
* A unique symbol used to access the parseWithDependency method on derived parsers.
|
|
23
29
|
* @since 0.10.0
|
|
24
30
|
*/
|
|
@@ -54,14 +60,22 @@ const ParseWithDependency = Symbol.for("@optique/core/dependency/ParseWithDepend
|
|
|
54
60
|
*/
|
|
55
61
|
function dependency(parser) {
|
|
56
62
|
const id = Symbol();
|
|
57
|
-
|
|
63
|
+
const result = {
|
|
58
64
|
...parser,
|
|
59
65
|
[DependencySourceMarker]: true,
|
|
60
66
|
[DependencyId]: id,
|
|
61
67
|
derive(options) {
|
|
62
68
|
return createDerivedValueParser(id, parser, options);
|
|
69
|
+
},
|
|
70
|
+
deriveSync(options) {
|
|
71
|
+
if (parser.$mode === "async") return createAsyncDerivedParserFromSyncFactory(id, options);
|
|
72
|
+
return createSyncDerivedParser(id, options);
|
|
73
|
+
},
|
|
74
|
+
deriveAsync(options) {
|
|
75
|
+
return createDerivedValueParser(id, parser, options);
|
|
63
76
|
}
|
|
64
77
|
};
|
|
78
|
+
return result;
|
|
65
79
|
}
|
|
66
80
|
/**
|
|
67
81
|
* Checks if a value parser is a {@link DependencySource}.
|
|
@@ -115,17 +129,70 @@ function isDerivedValueParser(parser) {
|
|
|
115
129
|
* @since 0.10.0
|
|
116
130
|
*/
|
|
117
131
|
function deriveFrom(options) {
|
|
118
|
-
const
|
|
132
|
+
const depsAsync = options.dependencies.some((dep) => dep.$mode === "async");
|
|
133
|
+
const factoryReturnsAsync = determineFactoryModeForDeriveFrom(options);
|
|
134
|
+
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
135
|
+
const isAsync = depsAsync || factoryReturnsAsync;
|
|
136
|
+
if (isAsync) {
|
|
137
|
+
if (factoryReturnsAsync) return createAsyncDerivedFromParserFromAsyncFactory(sourceId, options);
|
|
138
|
+
return createAsyncDerivedFromParserFromSyncFactory(sourceId, options);
|
|
139
|
+
}
|
|
140
|
+
return createSyncDerivedFromParser(sourceId, options);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Creates a derived value parser from multiple dependency sources
|
|
144
|
+
* with a synchronous factory.
|
|
145
|
+
*
|
|
146
|
+
* This function allows creating a parser whose behavior depends on
|
|
147
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
148
|
+
* a sync parser.
|
|
149
|
+
*
|
|
150
|
+
* @template Deps A tuple of DependencySource types.
|
|
151
|
+
* @template T The type of value the derived parser produces.
|
|
152
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
153
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
154
|
+
* @since 0.10.0
|
|
155
|
+
*/
|
|
156
|
+
function deriveFromSync(options) {
|
|
157
|
+
const depsAsync = options.dependencies.some((dep) => dep.$mode === "async");
|
|
119
158
|
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
120
|
-
if (
|
|
159
|
+
if (depsAsync) return createAsyncDerivedFromParserFromSyncFactory(sourceId, options);
|
|
121
160
|
return createSyncDerivedFromParser(sourceId, options);
|
|
122
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates a derived value parser from multiple dependency sources
|
|
164
|
+
* with an asynchronous factory.
|
|
165
|
+
*
|
|
166
|
+
* This function allows creating a parser whose behavior depends on
|
|
167
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
168
|
+
* an async parser.
|
|
169
|
+
*
|
|
170
|
+
* @template Deps A tuple of DependencySource types.
|
|
171
|
+
* @template T The type of value the derived parser produces.
|
|
172
|
+
* @param options Configuration for the derived parser with async factory.
|
|
173
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
174
|
+
* @since 0.10.0
|
|
175
|
+
*/
|
|
176
|
+
function deriveFromAsync(options) {
|
|
177
|
+
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
178
|
+
return createAsyncDerivedFromParserFromAsyncFactory(sourceId, options);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Determines if the factory returns an async parser for deriveFrom options.
|
|
182
|
+
*/
|
|
183
|
+
function determineFactoryModeForDeriveFrom(options) {
|
|
184
|
+
const defaultValues = options.defaultValues();
|
|
185
|
+
const parser = options.factory(...defaultValues);
|
|
186
|
+
return parser.$mode === "async";
|
|
187
|
+
}
|
|
123
188
|
function createSyncDerivedFromParser(sourceId, options) {
|
|
189
|
+
const allDependencyIds = options.dependencies.map((dep) => dep[DependencyId]);
|
|
124
190
|
return {
|
|
125
191
|
$mode: "sync",
|
|
126
192
|
metavar: options.metavar,
|
|
127
193
|
[DerivedValueParserMarker]: true,
|
|
128
194
|
[DependencyId]: sourceId,
|
|
195
|
+
[DependencyIds]: allDependencyIds,
|
|
129
196
|
parse(input) {
|
|
130
197
|
const sourceValues = options.defaultValues();
|
|
131
198
|
const derivedParser = options.factory(...sourceValues);
|
|
@@ -147,12 +214,51 @@ function createSyncDerivedFromParser(sourceId, options) {
|
|
|
147
214
|
}
|
|
148
215
|
};
|
|
149
216
|
}
|
|
150
|
-
|
|
217
|
+
/**
|
|
218
|
+
* Creates an async derived parser from multiple dependencies when the
|
|
219
|
+
* factory returns an async parser.
|
|
220
|
+
*/
|
|
221
|
+
function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
|
|
222
|
+
const allDependencyIds = options.dependencies.map((dep) => dep[DependencyId]);
|
|
223
|
+
return {
|
|
224
|
+
$mode: "async",
|
|
225
|
+
metavar: options.metavar,
|
|
226
|
+
[DerivedValueParserMarker]: true,
|
|
227
|
+
[DependencyId]: sourceId,
|
|
228
|
+
[DependencyIds]: allDependencyIds,
|
|
229
|
+
parse(input) {
|
|
230
|
+
const sourceValues = options.defaultValues();
|
|
231
|
+
const derivedParser = options.factory(...sourceValues);
|
|
232
|
+
return derivedParser.parse(input);
|
|
233
|
+
},
|
|
234
|
+
[ParseWithDependency](input, dependencyValue) {
|
|
235
|
+
const derivedParser = options.factory(...dependencyValue);
|
|
236
|
+
return derivedParser.parse(input);
|
|
237
|
+
},
|
|
238
|
+
format(value) {
|
|
239
|
+
const sourceValues = options.defaultValues();
|
|
240
|
+
const derivedParser = options.factory(...sourceValues);
|
|
241
|
+
return derivedParser.format(value);
|
|
242
|
+
},
|
|
243
|
+
async *suggest(prefix) {
|
|
244
|
+
const sourceValues = options.defaultValues();
|
|
245
|
+
const derivedParser = options.factory(...sourceValues);
|
|
246
|
+
if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Creates an async derived parser from multiple dependencies when the
|
|
252
|
+
* sources are async but the factory returns a sync parser.
|
|
253
|
+
*/
|
|
254
|
+
function createAsyncDerivedFromParserFromSyncFactory(sourceId, options) {
|
|
255
|
+
const allDependencyIds = options.dependencies.map((dep) => dep[DependencyId]);
|
|
151
256
|
return {
|
|
152
257
|
$mode: "async",
|
|
153
258
|
metavar: options.metavar,
|
|
154
259
|
[DerivedValueParserMarker]: true,
|
|
155
260
|
[DependencyId]: sourceId,
|
|
261
|
+
[DependencyIds]: allDependencyIds,
|
|
156
262
|
parse(input) {
|
|
157
263
|
const sourceValues = options.defaultValues();
|
|
158
264
|
const derivedParser = options.factory(...sourceValues);
|
|
@@ -175,9 +281,23 @@ function createAsyncDerivedFromParser(sourceId, options) {
|
|
|
175
281
|
};
|
|
176
282
|
}
|
|
177
283
|
function createDerivedValueParser(sourceId, sourceParser, options) {
|
|
178
|
-
|
|
284
|
+
const factoryReturnsAsync = determineFactoryMode(options);
|
|
285
|
+
const isAsync = sourceParser.$mode === "async" || factoryReturnsAsync;
|
|
286
|
+
if (isAsync) {
|
|
287
|
+
if (factoryReturnsAsync) return createAsyncDerivedParserFromAsyncFactory(sourceId, options);
|
|
288
|
+
return createAsyncDerivedParserFromSyncFactory(sourceId, options);
|
|
289
|
+
}
|
|
179
290
|
return createSyncDerivedParser(sourceId, options);
|
|
180
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Determines if the factory returns an async parser by calling it with
|
|
294
|
+
* the default value and checking the mode.
|
|
295
|
+
*/
|
|
296
|
+
function determineFactoryMode(options) {
|
|
297
|
+
const defaultValue = options.defaultValue();
|
|
298
|
+
const parser = options.factory(defaultValue);
|
|
299
|
+
return parser.$mode === "async";
|
|
300
|
+
}
|
|
181
301
|
function createSyncDerivedParser(sourceId, options) {
|
|
182
302
|
return {
|
|
183
303
|
$mode: "sync",
|
|
@@ -205,7 +325,42 @@ function createSyncDerivedParser(sourceId, options) {
|
|
|
205
325
|
}
|
|
206
326
|
};
|
|
207
327
|
}
|
|
208
|
-
|
|
328
|
+
/**
|
|
329
|
+
* Creates an async derived parser when the factory returns an async parser.
|
|
330
|
+
* The parse result is awaited since the factory returns an async parser.
|
|
331
|
+
*/
|
|
332
|
+
function createAsyncDerivedParserFromAsyncFactory(sourceId, options) {
|
|
333
|
+
return {
|
|
334
|
+
$mode: "async",
|
|
335
|
+
metavar: options.metavar,
|
|
336
|
+
[DerivedValueParserMarker]: true,
|
|
337
|
+
[DependencyId]: sourceId,
|
|
338
|
+
parse(input) {
|
|
339
|
+
const sourceValue = options.defaultValue();
|
|
340
|
+
const derivedParser = options.factory(sourceValue);
|
|
341
|
+
return derivedParser.parse(input);
|
|
342
|
+
},
|
|
343
|
+
[ParseWithDependency](input, dependencyValue) {
|
|
344
|
+
const derivedParser = options.factory(dependencyValue);
|
|
345
|
+
return derivedParser.parse(input);
|
|
346
|
+
},
|
|
347
|
+
format(value) {
|
|
348
|
+
const sourceValue = options.defaultValue();
|
|
349
|
+
const derivedParser = options.factory(sourceValue);
|
|
350
|
+
return derivedParser.format(value);
|
|
351
|
+
},
|
|
352
|
+
async *suggest(prefix) {
|
|
353
|
+
const sourceValue = options.defaultValue();
|
|
354
|
+
const derivedParser = options.factory(sourceValue);
|
|
355
|
+
if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Creates an async derived parser when the source is async but the factory
|
|
361
|
+
* returns a sync parser. The sync result is wrapped in a Promise.
|
|
362
|
+
*/
|
|
363
|
+
function createAsyncDerivedParserFromSyncFactory(sourceId, options) {
|
|
209
364
|
return {
|
|
210
365
|
$mode: "async",
|
|
211
366
|
metavar: options.metavar,
|
|
@@ -259,11 +414,13 @@ function isDeferredParseState(value) {
|
|
|
259
414
|
* @since 0.10.0
|
|
260
415
|
*/
|
|
261
416
|
function createDeferredParseState(rawInput, parser, preliminaryResult) {
|
|
417
|
+
const multipleIds = DependencyIds in parser ? parser[DependencyIds] : void 0;
|
|
262
418
|
return {
|
|
263
419
|
[DeferredParseMarker]: true,
|
|
264
420
|
rawInput,
|
|
265
421
|
parser,
|
|
266
422
|
dependencyId: parser[DependencyId],
|
|
423
|
+
dependencyIds: multipleIds,
|
|
267
424
|
preliminaryResult
|
|
268
425
|
};
|
|
269
426
|
}
|
|
@@ -364,4 +521,4 @@ function formatDependencyError(error) {
|
|
|
364
521
|
}
|
|
365
522
|
|
|
366
523
|
//#endregion
|
|
367
|
-
export { DeferredParseMarker, DependencyId, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
|
|
524
|
+
export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
|
package/dist/index.cjs
CHANGED
|
@@ -13,6 +13,7 @@ const require_facade = require('./facade.cjs');
|
|
|
13
13
|
|
|
14
14
|
exports.DeferredParseMarker = require_dependency.DeferredParseMarker;
|
|
15
15
|
exports.DependencyId = require_dependency.DependencyId;
|
|
16
|
+
exports.DependencyIds = require_dependency.DependencyIds;
|
|
16
17
|
exports.DependencyRegistry = require_dependency.DependencyRegistry;
|
|
17
18
|
exports.DependencySourceMarker = require_dependency.DependencySourceMarker;
|
|
18
19
|
exports.DependencySourceStateMarker = require_dependency.DependencySourceStateMarker;
|
|
@@ -34,6 +35,8 @@ exports.createDeferredParseState = require_dependency.createDeferredParseState;
|
|
|
34
35
|
exports.createDependencySourceState = require_dependency.createDependencySourceState;
|
|
35
36
|
exports.dependency = require_dependency.dependency;
|
|
36
37
|
exports.deriveFrom = require_dependency.deriveFrom;
|
|
38
|
+
exports.deriveFromAsync = require_dependency.deriveFromAsync;
|
|
39
|
+
exports.deriveFromSync = require_dependency.deriveFromSync;
|
|
37
40
|
exports.ensureNonEmptyString = require_nonempty.ensureNonEmptyString;
|
|
38
41
|
exports.envVar = require_message.envVar;
|
|
39
42
|
exports.extractArgumentMetavars = require_usage.extractArgumentMetavars;
|
package/dist/index.d.cts
CHANGED
|
@@ -5,9 +5,9 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
|
|
|
5
5
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
|
|
6
6
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
|
|
7
7
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.cjs";
|
|
8
|
-
import { AnyDependencySource, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveFromOptions, DeriveOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.cjs";
|
|
8
|
+
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.cjs";
|
|
9
9
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.cjs";
|
|
10
10
|
import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.cjs";
|
|
11
11
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
12
12
|
import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.cjs";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveFromOptions, DeriveOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
|
13
|
+
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
|
|
|
5
5
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
|
|
6
6
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
7
7
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.js";
|
|
8
|
-
import { AnyDependencySource, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveFromOptions, DeriveOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
|
|
8
|
+
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
|
|
9
9
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
|
|
10
10
|
import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
11
11
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
12
12
|
import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveFromOptions, DeriveOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
|
13
|
+
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
2
2
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
3
|
-
import { DeferredParseMarker, DependencyId, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
|
|
3
|
+
import { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
|
|
4
4
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
5
5
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
6
6
|
import { formatDocPage } from "./doc.js";
|
|
@@ -11,4 +11,4 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
|
|
|
11
11
|
import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
12
12
|
import { RunError, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
13
|
|
|
14
|
-
export { DeferredParseMarker, DependencyId, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, DuplicateOptionError, ParseWithDependency, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
|
14
|
+
export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, DuplicateOptionError, ParseWithDependency, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/primitives.cjs
CHANGED
|
@@ -229,7 +229,8 @@ function option(...args) {
|
|
|
229
229
|
consumed: context.buffer.slice(0, 1)
|
|
230
230
|
};
|
|
231
231
|
if (optionNames$1.includes(context.buffer[0])) {
|
|
232
|
-
|
|
232
|
+
const hasValue = valueParser != null ? context.state?.success || require_dependency.isDeferredParseState(context.state) || require_dependency.isDependencySourceState(context.state) : context.state?.success && context.state?.value;
|
|
233
|
+
if (hasValue) return {
|
|
233
234
|
success: false,
|
|
234
235
|
consumed: 1,
|
|
235
236
|
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : require_message.message`${require_message.optionName(context.buffer[0])} cannot be used multiple times.`
|
package/dist/primitives.js
CHANGED
|
@@ -229,7 +229,8 @@ function option(...args) {
|
|
|
229
229
|
consumed: context.buffer.slice(0, 1)
|
|
230
230
|
};
|
|
231
231
|
if (optionNames$1.includes(context.buffer[0])) {
|
|
232
|
-
|
|
232
|
+
const hasValue = valueParser != null ? context.state?.success || isDeferredParseState(context.state) || isDependencySourceState(context.state) : context.state?.success && context.state?.value;
|
|
233
|
+
if (hasValue) return {
|
|
233
234
|
success: false,
|
|
234
235
|
consumed: 1,
|
|
235
236
|
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : message`${optionName(context.buffer[0])} cannot be used multiple times.`
|