@optique/core 0.10.0-dev.292 → 0.10.0-dev.293
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/dependency.cjs +151 -6
- package/dist/dependency.d.cts +169 -9
- package/dist/dependency.d.ts +169 -9
- package/dist/dependency.js +150 -7
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/dependency.cjs
CHANGED
|
@@ -55,14 +55,22 @@ const ParseWithDependency = Symbol.for("@optique/core/dependency/ParseWithDepend
|
|
|
55
55
|
*/
|
|
56
56
|
function dependency(parser) {
|
|
57
57
|
const id = Symbol();
|
|
58
|
-
|
|
58
|
+
const result = {
|
|
59
59
|
...parser,
|
|
60
60
|
[DependencySourceMarker]: true,
|
|
61
61
|
[DependencyId]: id,
|
|
62
62
|
derive(options) {
|
|
63
63
|
return createDerivedValueParser(id, parser, options);
|
|
64
|
+
},
|
|
65
|
+
deriveSync(options) {
|
|
66
|
+
if (parser.$mode === "async") return createAsyncDerivedParserFromSyncFactory(id, options);
|
|
67
|
+
return createSyncDerivedParser(id, options);
|
|
68
|
+
},
|
|
69
|
+
deriveAsync(options) {
|
|
70
|
+
return createDerivedValueParser(id, parser, options);
|
|
64
71
|
}
|
|
65
72
|
};
|
|
73
|
+
return result;
|
|
66
74
|
}
|
|
67
75
|
/**
|
|
68
76
|
* Checks if a value parser is a {@link DependencySource}.
|
|
@@ -116,11 +124,62 @@ function isDerivedValueParser(parser) {
|
|
|
116
124
|
* @since 0.10.0
|
|
117
125
|
*/
|
|
118
126
|
function deriveFrom(options) {
|
|
119
|
-
const
|
|
127
|
+
const depsAsync = options.dependencies.some((dep) => dep.$mode === "async");
|
|
128
|
+
const factoryReturnsAsync = determineFactoryModeForDeriveFrom(options);
|
|
129
|
+
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
130
|
+
const isAsync = depsAsync || factoryReturnsAsync;
|
|
131
|
+
if (isAsync) {
|
|
132
|
+
if (factoryReturnsAsync) return createAsyncDerivedFromParserFromAsyncFactory(sourceId, options);
|
|
133
|
+
return createAsyncDerivedFromParserFromSyncFactory(sourceId, options);
|
|
134
|
+
}
|
|
135
|
+
return createSyncDerivedFromParser(sourceId, options);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Creates a derived value parser from multiple dependency sources
|
|
139
|
+
* with a synchronous factory.
|
|
140
|
+
*
|
|
141
|
+
* This function allows creating a parser whose behavior depends on
|
|
142
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
143
|
+
* a sync parser.
|
|
144
|
+
*
|
|
145
|
+
* @template Deps A tuple of DependencySource types.
|
|
146
|
+
* @template T The type of value the derived parser produces.
|
|
147
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
148
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
149
|
+
* @since 0.10.0
|
|
150
|
+
*/
|
|
151
|
+
function deriveFromSync(options) {
|
|
152
|
+
const depsAsync = options.dependencies.some((dep) => dep.$mode === "async");
|
|
120
153
|
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
121
|
-
if (
|
|
154
|
+
if (depsAsync) return createAsyncDerivedFromParserFromSyncFactory(sourceId, options);
|
|
122
155
|
return createSyncDerivedFromParser(sourceId, options);
|
|
123
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates a derived value parser from multiple dependency sources
|
|
159
|
+
* with an asynchronous factory.
|
|
160
|
+
*
|
|
161
|
+
* This function allows creating a parser whose behavior depends on
|
|
162
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
163
|
+
* an async parser.
|
|
164
|
+
*
|
|
165
|
+
* @template Deps A tuple of DependencySource types.
|
|
166
|
+
* @template T The type of value the derived parser produces.
|
|
167
|
+
* @param options Configuration for the derived parser with async factory.
|
|
168
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
169
|
+
* @since 0.10.0
|
|
170
|
+
*/
|
|
171
|
+
function deriveFromAsync(options) {
|
|
172
|
+
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
173
|
+
return createAsyncDerivedFromParserFromAsyncFactory(sourceId, options);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Determines if the factory returns an async parser for deriveFrom options.
|
|
177
|
+
*/
|
|
178
|
+
function determineFactoryModeForDeriveFrom(options) {
|
|
179
|
+
const defaultValues = options.defaultValues();
|
|
180
|
+
const parser = options.factory(...defaultValues);
|
|
181
|
+
return parser.$mode === "async";
|
|
182
|
+
}
|
|
124
183
|
function createSyncDerivedFromParser(sourceId, options) {
|
|
125
184
|
return {
|
|
126
185
|
$mode: "sync",
|
|
@@ -148,7 +207,42 @@ function createSyncDerivedFromParser(sourceId, options) {
|
|
|
148
207
|
}
|
|
149
208
|
};
|
|
150
209
|
}
|
|
151
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Creates an async derived parser from multiple dependencies when the
|
|
212
|
+
* factory returns an async parser.
|
|
213
|
+
*/
|
|
214
|
+
function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
|
|
215
|
+
return {
|
|
216
|
+
$mode: "async",
|
|
217
|
+
metavar: options.metavar,
|
|
218
|
+
[DerivedValueParserMarker]: true,
|
|
219
|
+
[DependencyId]: sourceId,
|
|
220
|
+
parse(input) {
|
|
221
|
+
const sourceValues = options.defaultValues();
|
|
222
|
+
const derivedParser = options.factory(...sourceValues);
|
|
223
|
+
return derivedParser.parse(input);
|
|
224
|
+
},
|
|
225
|
+
[ParseWithDependency](input, dependencyValue) {
|
|
226
|
+
const derivedParser = options.factory(...dependencyValue);
|
|
227
|
+
return derivedParser.parse(input);
|
|
228
|
+
},
|
|
229
|
+
format(value) {
|
|
230
|
+
const sourceValues = options.defaultValues();
|
|
231
|
+
const derivedParser = options.factory(...sourceValues);
|
|
232
|
+
return derivedParser.format(value);
|
|
233
|
+
},
|
|
234
|
+
async *suggest(prefix) {
|
|
235
|
+
const sourceValues = options.defaultValues();
|
|
236
|
+
const derivedParser = options.factory(...sourceValues);
|
|
237
|
+
if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Creates an async derived parser from multiple dependencies when the
|
|
243
|
+
* sources are async but the factory returns a sync parser.
|
|
244
|
+
*/
|
|
245
|
+
function createAsyncDerivedFromParserFromSyncFactory(sourceId, options) {
|
|
152
246
|
return {
|
|
153
247
|
$mode: "async",
|
|
154
248
|
metavar: options.metavar,
|
|
@@ -176,9 +270,23 @@ function createAsyncDerivedFromParser(sourceId, options) {
|
|
|
176
270
|
};
|
|
177
271
|
}
|
|
178
272
|
function createDerivedValueParser(sourceId, sourceParser, options) {
|
|
179
|
-
|
|
273
|
+
const factoryReturnsAsync = determineFactoryMode(options);
|
|
274
|
+
const isAsync = sourceParser.$mode === "async" || factoryReturnsAsync;
|
|
275
|
+
if (isAsync) {
|
|
276
|
+
if (factoryReturnsAsync) return createAsyncDerivedParserFromAsyncFactory(sourceId, options);
|
|
277
|
+
return createAsyncDerivedParserFromSyncFactory(sourceId, options);
|
|
278
|
+
}
|
|
180
279
|
return createSyncDerivedParser(sourceId, options);
|
|
181
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Determines if the factory returns an async parser by calling it with
|
|
283
|
+
* the default value and checking the mode.
|
|
284
|
+
*/
|
|
285
|
+
function determineFactoryMode(options) {
|
|
286
|
+
const defaultValue = options.defaultValue();
|
|
287
|
+
const parser = options.factory(defaultValue);
|
|
288
|
+
return parser.$mode === "async";
|
|
289
|
+
}
|
|
182
290
|
function createSyncDerivedParser(sourceId, options) {
|
|
183
291
|
return {
|
|
184
292
|
$mode: "sync",
|
|
@@ -206,7 +314,42 @@ function createSyncDerivedParser(sourceId, options) {
|
|
|
206
314
|
}
|
|
207
315
|
};
|
|
208
316
|
}
|
|
209
|
-
|
|
317
|
+
/**
|
|
318
|
+
* Creates an async derived parser when the factory returns an async parser.
|
|
319
|
+
* The parse result is awaited since the factory returns an async parser.
|
|
320
|
+
*/
|
|
321
|
+
function createAsyncDerivedParserFromAsyncFactory(sourceId, options) {
|
|
322
|
+
return {
|
|
323
|
+
$mode: "async",
|
|
324
|
+
metavar: options.metavar,
|
|
325
|
+
[DerivedValueParserMarker]: true,
|
|
326
|
+
[DependencyId]: sourceId,
|
|
327
|
+
parse(input) {
|
|
328
|
+
const sourceValue = options.defaultValue();
|
|
329
|
+
const derivedParser = options.factory(sourceValue);
|
|
330
|
+
return derivedParser.parse(input);
|
|
331
|
+
},
|
|
332
|
+
[ParseWithDependency](input, dependencyValue) {
|
|
333
|
+
const derivedParser = options.factory(dependencyValue);
|
|
334
|
+
return derivedParser.parse(input);
|
|
335
|
+
},
|
|
336
|
+
format(value) {
|
|
337
|
+
const sourceValue = options.defaultValue();
|
|
338
|
+
const derivedParser = options.factory(sourceValue);
|
|
339
|
+
return derivedParser.format(value);
|
|
340
|
+
},
|
|
341
|
+
async *suggest(prefix) {
|
|
342
|
+
const sourceValue = options.defaultValue();
|
|
343
|
+
const derivedParser = options.factory(sourceValue);
|
|
344
|
+
if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Creates an async derived parser when the source is async but the factory
|
|
350
|
+
* returns a sync parser. The sync result is wrapped in a Promise.
|
|
351
|
+
*/
|
|
352
|
+
function createAsyncDerivedParserFromSyncFactory(sourceId, options) {
|
|
210
353
|
return {
|
|
211
354
|
$mode: "async",
|
|
212
355
|
metavar: options.metavar,
|
|
@@ -376,6 +519,8 @@ exports.createDeferredParseState = createDeferredParseState;
|
|
|
376
519
|
exports.createDependencySourceState = createDependencySourceState;
|
|
377
520
|
exports.dependency = dependency;
|
|
378
521
|
exports.deriveFrom = deriveFrom;
|
|
522
|
+
exports.deriveFromAsync = deriveFromAsync;
|
|
523
|
+
exports.deriveFromSync = deriveFromSync;
|
|
379
524
|
exports.formatDependencyError = formatDependencyError;
|
|
380
525
|
exports.isDeferredParseState = isDeferredParseState;
|
|
381
526
|
exports.isDependencySource = isDependencySource;
|
package/dist/dependency.d.cts
CHANGED
|
@@ -29,14 +29,23 @@ declare const DependencyId: unique symbol;
|
|
|
29
29
|
* @since 0.10.0
|
|
30
30
|
*/
|
|
31
31
|
declare const ParseWithDependency: unique symbol;
|
|
32
|
+
/**
|
|
33
|
+
* Combines two modes into a single mode.
|
|
34
|
+
* If either mode is async, the result is async.
|
|
35
|
+
* @template M1 The first mode.
|
|
36
|
+
* @template M2 The second mode.
|
|
37
|
+
* @since 0.10.0
|
|
38
|
+
*/
|
|
39
|
+
type CombineMode<M1 extends Mode, M2 extends Mode> = M1 extends "async" ? "async" : M2 extends "async" ? "async" : "sync";
|
|
32
40
|
/**
|
|
33
41
|
* Options for creating a derived value parser.
|
|
34
42
|
*
|
|
35
43
|
* @template S The type of the source dependency value.
|
|
36
44
|
* @template T The type of the derived parser value.
|
|
45
|
+
* @template FM The mode of the factory's returned parser.
|
|
37
46
|
* @since 0.10.0
|
|
38
47
|
*/
|
|
39
|
-
interface DeriveOptions<S, T> {
|
|
48
|
+
interface DeriveOptions<S, T, FM extends Mode = Mode> {
|
|
40
49
|
/**
|
|
41
50
|
* The metavariable name for the derived parser. Used in help messages
|
|
42
51
|
* to indicate what kind of value this parser expects.
|
|
@@ -49,7 +58,7 @@ interface DeriveOptions<S, T> {
|
|
|
49
58
|
* @param sourceValue The value parsed from the dependency source.
|
|
50
59
|
* @returns A {@link ValueParser} for the derived value.
|
|
51
60
|
*/
|
|
52
|
-
readonly factory: (sourceValue: S) => ValueParser<
|
|
61
|
+
readonly factory: (sourceValue: S) => ValueParser<FM, T>;
|
|
53
62
|
/**
|
|
54
63
|
* Default value to use when the dependency source is not provided.
|
|
55
64
|
* This allows the derived parser to work even when the dependency
|
|
@@ -59,6 +68,48 @@ interface DeriveOptions<S, T> {
|
|
|
59
68
|
*/
|
|
60
69
|
readonly defaultValue: () => S;
|
|
61
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Options for creating a derived value parser with a synchronous factory.
|
|
73
|
+
*
|
|
74
|
+
* @template S The type of the source dependency value.
|
|
75
|
+
* @template T The type of the derived parser value.
|
|
76
|
+
* @since 0.10.0
|
|
77
|
+
*/
|
|
78
|
+
interface DeriveSyncOptions<S, T> {
|
|
79
|
+
/**
|
|
80
|
+
* The metavariable name for the derived parser.
|
|
81
|
+
*/
|
|
82
|
+
readonly metavar: NonEmptyString;
|
|
83
|
+
/**
|
|
84
|
+
* Factory function that creates a synchronous {@link ValueParser}.
|
|
85
|
+
*/
|
|
86
|
+
readonly factory: (sourceValue: S) => ValueParser<"sync", T>;
|
|
87
|
+
/**
|
|
88
|
+
* Default value to use when the dependency source is not provided.
|
|
89
|
+
*/
|
|
90
|
+
readonly defaultValue: () => S;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Options for creating a derived value parser with an asynchronous factory.
|
|
94
|
+
*
|
|
95
|
+
* @template S The type of the source dependency value.
|
|
96
|
+
* @template T The type of the derived parser value.
|
|
97
|
+
* @since 0.10.0
|
|
98
|
+
*/
|
|
99
|
+
interface DeriveAsyncOptions<S, T> {
|
|
100
|
+
/**
|
|
101
|
+
* The metavariable name for the derived parser.
|
|
102
|
+
*/
|
|
103
|
+
readonly metavar: NonEmptyString;
|
|
104
|
+
/**
|
|
105
|
+
* Factory function that creates an asynchronous {@link ValueParser}.
|
|
106
|
+
*/
|
|
107
|
+
readonly factory: (sourceValue: S) => ValueParser<"async", T>;
|
|
108
|
+
/**
|
|
109
|
+
* Default value to use when the dependency source is not provided.
|
|
110
|
+
*/
|
|
111
|
+
readonly defaultValue: () => S;
|
|
112
|
+
}
|
|
62
113
|
/**
|
|
63
114
|
* Represents a dependency source that can be used to create derived parsers.
|
|
64
115
|
*
|
|
@@ -87,14 +138,40 @@ interface DependencySource<M extends Mode = "sync", T = unknown> extends ValuePa
|
|
|
87
138
|
* dependency source's value.
|
|
88
139
|
*
|
|
89
140
|
* The derived parser uses a factory function to create parsers based on
|
|
90
|
-
* the source value.
|
|
91
|
-
*
|
|
141
|
+
* the source value. The factory can return either a sync or async parser,
|
|
142
|
+
* and the resulting derived parser's mode will be the combination of
|
|
143
|
+
* the source mode and the factory's returned parser mode.
|
|
92
144
|
*
|
|
93
145
|
* @template U The type of value the derived parser produces.
|
|
146
|
+
* @template FM The mode of the factory's returned parser.
|
|
94
147
|
* @param options Configuration for the derived parser.
|
|
95
148
|
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
96
149
|
*/
|
|
97
|
-
derive<U>(options: DeriveOptions<T, U>): DerivedValueParser<M, U, T>;
|
|
150
|
+
derive<U, FM extends Mode = "sync">(options: DeriveOptions<T, U, FM>): DerivedValueParser<CombineMode<M, FM>, U, T>;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a derived value parser with a synchronous factory.
|
|
153
|
+
*
|
|
154
|
+
* This is a convenience method that explicitly requires a sync factory,
|
|
155
|
+
* making the type inference more predictable.
|
|
156
|
+
*
|
|
157
|
+
* @template U The type of value the derived parser produces.
|
|
158
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
159
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
160
|
+
* @since 0.10.0
|
|
161
|
+
*/
|
|
162
|
+
deriveSync<U>(options: DeriveSyncOptions<T, U>): DerivedValueParser<M, U, T>;
|
|
163
|
+
/**
|
|
164
|
+
* Creates a derived value parser with an asynchronous factory.
|
|
165
|
+
*
|
|
166
|
+
* This is a convenience method that explicitly requires an async factory,
|
|
167
|
+
* making the type inference more predictable.
|
|
168
|
+
*
|
|
169
|
+
* @template U The type of value the derived parser produces.
|
|
170
|
+
* @param options Configuration for the derived parser with async factory.
|
|
171
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
172
|
+
* @since 0.10.0
|
|
173
|
+
*/
|
|
174
|
+
deriveAsync<U>(options: DeriveAsyncOptions<T, U>): DerivedValueParser<"async", U, T>;
|
|
98
175
|
}
|
|
99
176
|
/**
|
|
100
177
|
* Extracts the value type from a DependencySource.
|
|
@@ -131,9 +208,10 @@ type AnyDependencySource = DependencySource<Mode, any>;
|
|
|
131
208
|
*
|
|
132
209
|
* @template Deps A tuple of DependencySource types.
|
|
133
210
|
* @template T The type of the derived parser value.
|
|
211
|
+
* @template FM The mode of the factory's returned parser.
|
|
134
212
|
* @since 0.10.0
|
|
135
213
|
*/
|
|
136
|
-
interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
214
|
+
interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T, FM extends Mode = Mode> {
|
|
137
215
|
/**
|
|
138
216
|
* The metavariable name for the derived parser. Used in help messages
|
|
139
217
|
* to indicate what kind of value this parser expects.
|
|
@@ -150,7 +228,7 @@ interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
|
150
228
|
* @param values The values parsed from the dependency sources (in order).
|
|
151
229
|
* @returns A {@link ValueParser} for the derived value.
|
|
152
230
|
*/
|
|
153
|
-
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<
|
|
231
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<FM, T>;
|
|
154
232
|
/**
|
|
155
233
|
* Default values to use when the dependency sources are not provided.
|
|
156
234
|
* Must return a tuple with the same length and types as the dependencies.
|
|
@@ -159,6 +237,58 @@ interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
|
159
237
|
*/
|
|
160
238
|
readonly defaultValues: () => DependencyValues<Deps>;
|
|
161
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Options for creating a derived value parser from multiple dependencies
|
|
242
|
+
* with a synchronous factory.
|
|
243
|
+
*
|
|
244
|
+
* @template Deps A tuple of DependencySource types.
|
|
245
|
+
* @template T The type of the derived parser value.
|
|
246
|
+
* @since 0.10.0
|
|
247
|
+
*/
|
|
248
|
+
interface DeriveFromSyncOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
249
|
+
/**
|
|
250
|
+
* The metavariable name for the derived parser.
|
|
251
|
+
*/
|
|
252
|
+
readonly metavar: NonEmptyString;
|
|
253
|
+
/**
|
|
254
|
+
* The dependency sources that this derived parser depends on.
|
|
255
|
+
*/
|
|
256
|
+
readonly dependencies: Deps;
|
|
257
|
+
/**
|
|
258
|
+
* Factory function that creates a synchronous {@link ValueParser}.
|
|
259
|
+
*/
|
|
260
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"sync", T>;
|
|
261
|
+
/**
|
|
262
|
+
* Default values to use when the dependency sources are not provided.
|
|
263
|
+
*/
|
|
264
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Options for creating a derived value parser from multiple dependencies
|
|
268
|
+
* with an asynchronous factory.
|
|
269
|
+
*
|
|
270
|
+
* @template Deps A tuple of DependencySource types.
|
|
271
|
+
* @template T The type of the derived parser value.
|
|
272
|
+
* @since 0.10.0
|
|
273
|
+
*/
|
|
274
|
+
interface DeriveFromAsyncOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
275
|
+
/**
|
|
276
|
+
* The metavariable name for the derived parser.
|
|
277
|
+
*/
|
|
278
|
+
readonly metavar: NonEmptyString;
|
|
279
|
+
/**
|
|
280
|
+
* The dependency sources that this derived parser depends on.
|
|
281
|
+
*/
|
|
282
|
+
readonly dependencies: Deps;
|
|
283
|
+
/**
|
|
284
|
+
* Factory function that creates an asynchronous {@link ValueParser}.
|
|
285
|
+
*/
|
|
286
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"async", T>;
|
|
287
|
+
/**
|
|
288
|
+
* Default values to use when the dependency sources are not provided.
|
|
289
|
+
*/
|
|
290
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
291
|
+
}
|
|
162
292
|
/**
|
|
163
293
|
* A value parser that depends on another parser's value.
|
|
164
294
|
*
|
|
@@ -269,7 +399,37 @@ declare function isDerivedValueParser<M extends Mode, T>(parser: ValueParser<M,
|
|
|
269
399
|
* ```
|
|
270
400
|
* @since 0.10.0
|
|
271
401
|
*/
|
|
272
|
-
declare function deriveFrom<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromOptions<Deps, T>): DerivedValueParser<CombinedDependencyMode<Deps>, T, DependencyValues<Deps>>;
|
|
402
|
+
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>>;
|
|
403
|
+
/**
|
|
404
|
+
* Creates a derived value parser from multiple dependency sources
|
|
405
|
+
* with a synchronous factory.
|
|
406
|
+
*
|
|
407
|
+
* This function allows creating a parser whose behavior depends on
|
|
408
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
409
|
+
* a sync parser.
|
|
410
|
+
*
|
|
411
|
+
* @template Deps A tuple of DependencySource types.
|
|
412
|
+
* @template T The type of value the derived parser produces.
|
|
413
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
414
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
415
|
+
* @since 0.10.0
|
|
416
|
+
*/
|
|
417
|
+
declare function deriveFromSync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromSyncOptions<Deps, T>): DerivedValueParser<CombinedDependencyMode<Deps>, T, DependencyValues<Deps>>;
|
|
418
|
+
/**
|
|
419
|
+
* Creates a derived value parser from multiple dependency sources
|
|
420
|
+
* with an asynchronous factory.
|
|
421
|
+
*
|
|
422
|
+
* This function allows creating a parser whose behavior depends on
|
|
423
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
424
|
+
* an async parser.
|
|
425
|
+
*
|
|
426
|
+
* @template Deps A tuple of DependencySource types.
|
|
427
|
+
* @template T The type of value the derived parser produces.
|
|
428
|
+
* @param options Configuration for the derived parser with async factory.
|
|
429
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
430
|
+
* @since 0.10.0
|
|
431
|
+
*/
|
|
432
|
+
declare function deriveFromAsync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromAsyncOptions<Deps, T>): DerivedValueParser<"async", T, DependencyValues<Deps>>;
|
|
273
433
|
/**
|
|
274
434
|
* A unique symbol used to identify deferred parse states.
|
|
275
435
|
* @since 0.10.0
|
|
@@ -454,4 +614,4 @@ type DependencyError = {
|
|
|
454
614
|
*/
|
|
455
615
|
declare function formatDependencyError(error: DependencyError): Message;
|
|
456
616
|
//#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 };
|
|
617
|
+
export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, 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.d.ts
CHANGED
|
@@ -29,14 +29,23 @@ declare const DependencyId: unique symbol;
|
|
|
29
29
|
* @since 0.10.0
|
|
30
30
|
*/
|
|
31
31
|
declare const ParseWithDependency: unique symbol;
|
|
32
|
+
/**
|
|
33
|
+
* Combines two modes into a single mode.
|
|
34
|
+
* If either mode is async, the result is async.
|
|
35
|
+
* @template M1 The first mode.
|
|
36
|
+
* @template M2 The second mode.
|
|
37
|
+
* @since 0.10.0
|
|
38
|
+
*/
|
|
39
|
+
type CombineMode<M1 extends Mode, M2 extends Mode> = M1 extends "async" ? "async" : M2 extends "async" ? "async" : "sync";
|
|
32
40
|
/**
|
|
33
41
|
* Options for creating a derived value parser.
|
|
34
42
|
*
|
|
35
43
|
* @template S The type of the source dependency value.
|
|
36
44
|
* @template T The type of the derived parser value.
|
|
45
|
+
* @template FM The mode of the factory's returned parser.
|
|
37
46
|
* @since 0.10.0
|
|
38
47
|
*/
|
|
39
|
-
interface DeriveOptions<S, T> {
|
|
48
|
+
interface DeriveOptions<S, T, FM extends Mode = Mode> {
|
|
40
49
|
/**
|
|
41
50
|
* The metavariable name for the derived parser. Used in help messages
|
|
42
51
|
* to indicate what kind of value this parser expects.
|
|
@@ -49,7 +58,7 @@ interface DeriveOptions<S, T> {
|
|
|
49
58
|
* @param sourceValue The value parsed from the dependency source.
|
|
50
59
|
* @returns A {@link ValueParser} for the derived value.
|
|
51
60
|
*/
|
|
52
|
-
readonly factory: (sourceValue: S) => ValueParser<
|
|
61
|
+
readonly factory: (sourceValue: S) => ValueParser<FM, T>;
|
|
53
62
|
/**
|
|
54
63
|
* Default value to use when the dependency source is not provided.
|
|
55
64
|
* This allows the derived parser to work even when the dependency
|
|
@@ -59,6 +68,48 @@ interface DeriveOptions<S, T> {
|
|
|
59
68
|
*/
|
|
60
69
|
readonly defaultValue: () => S;
|
|
61
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Options for creating a derived value parser with a synchronous factory.
|
|
73
|
+
*
|
|
74
|
+
* @template S The type of the source dependency value.
|
|
75
|
+
* @template T The type of the derived parser value.
|
|
76
|
+
* @since 0.10.0
|
|
77
|
+
*/
|
|
78
|
+
interface DeriveSyncOptions<S, T> {
|
|
79
|
+
/**
|
|
80
|
+
* The metavariable name for the derived parser.
|
|
81
|
+
*/
|
|
82
|
+
readonly metavar: NonEmptyString;
|
|
83
|
+
/**
|
|
84
|
+
* Factory function that creates a synchronous {@link ValueParser}.
|
|
85
|
+
*/
|
|
86
|
+
readonly factory: (sourceValue: S) => ValueParser<"sync", T>;
|
|
87
|
+
/**
|
|
88
|
+
* Default value to use when the dependency source is not provided.
|
|
89
|
+
*/
|
|
90
|
+
readonly defaultValue: () => S;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Options for creating a derived value parser with an asynchronous factory.
|
|
94
|
+
*
|
|
95
|
+
* @template S The type of the source dependency value.
|
|
96
|
+
* @template T The type of the derived parser value.
|
|
97
|
+
* @since 0.10.0
|
|
98
|
+
*/
|
|
99
|
+
interface DeriveAsyncOptions<S, T> {
|
|
100
|
+
/**
|
|
101
|
+
* The metavariable name for the derived parser.
|
|
102
|
+
*/
|
|
103
|
+
readonly metavar: NonEmptyString;
|
|
104
|
+
/**
|
|
105
|
+
* Factory function that creates an asynchronous {@link ValueParser}.
|
|
106
|
+
*/
|
|
107
|
+
readonly factory: (sourceValue: S) => ValueParser<"async", T>;
|
|
108
|
+
/**
|
|
109
|
+
* Default value to use when the dependency source is not provided.
|
|
110
|
+
*/
|
|
111
|
+
readonly defaultValue: () => S;
|
|
112
|
+
}
|
|
62
113
|
/**
|
|
63
114
|
* Represents a dependency source that can be used to create derived parsers.
|
|
64
115
|
*
|
|
@@ -87,14 +138,40 @@ interface DependencySource<M extends Mode = "sync", T = unknown> extends ValuePa
|
|
|
87
138
|
* dependency source's value.
|
|
88
139
|
*
|
|
89
140
|
* The derived parser uses a factory function to create parsers based on
|
|
90
|
-
* the source value.
|
|
91
|
-
*
|
|
141
|
+
* the source value. The factory can return either a sync or async parser,
|
|
142
|
+
* and the resulting derived parser's mode will be the combination of
|
|
143
|
+
* the source mode and the factory's returned parser mode.
|
|
92
144
|
*
|
|
93
145
|
* @template U The type of value the derived parser produces.
|
|
146
|
+
* @template FM The mode of the factory's returned parser.
|
|
94
147
|
* @param options Configuration for the derived parser.
|
|
95
148
|
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
96
149
|
*/
|
|
97
|
-
derive<U>(options: DeriveOptions<T, U>): DerivedValueParser<M, U, T>;
|
|
150
|
+
derive<U, FM extends Mode = "sync">(options: DeriveOptions<T, U, FM>): DerivedValueParser<CombineMode<M, FM>, U, T>;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a derived value parser with a synchronous factory.
|
|
153
|
+
*
|
|
154
|
+
* This is a convenience method that explicitly requires a sync factory,
|
|
155
|
+
* making the type inference more predictable.
|
|
156
|
+
*
|
|
157
|
+
* @template U The type of value the derived parser produces.
|
|
158
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
159
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
160
|
+
* @since 0.10.0
|
|
161
|
+
*/
|
|
162
|
+
deriveSync<U>(options: DeriveSyncOptions<T, U>): DerivedValueParser<M, U, T>;
|
|
163
|
+
/**
|
|
164
|
+
* Creates a derived value parser with an asynchronous factory.
|
|
165
|
+
*
|
|
166
|
+
* This is a convenience method that explicitly requires an async factory,
|
|
167
|
+
* making the type inference more predictable.
|
|
168
|
+
*
|
|
169
|
+
* @template U The type of value the derived parser produces.
|
|
170
|
+
* @param options Configuration for the derived parser with async factory.
|
|
171
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
172
|
+
* @since 0.10.0
|
|
173
|
+
*/
|
|
174
|
+
deriveAsync<U>(options: DeriveAsyncOptions<T, U>): DerivedValueParser<"async", U, T>;
|
|
98
175
|
}
|
|
99
176
|
/**
|
|
100
177
|
* Extracts the value type from a DependencySource.
|
|
@@ -131,9 +208,10 @@ type AnyDependencySource = DependencySource<Mode, any>;
|
|
|
131
208
|
*
|
|
132
209
|
* @template Deps A tuple of DependencySource types.
|
|
133
210
|
* @template T The type of the derived parser value.
|
|
211
|
+
* @template FM The mode of the factory's returned parser.
|
|
134
212
|
* @since 0.10.0
|
|
135
213
|
*/
|
|
136
|
-
interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
214
|
+
interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T, FM extends Mode = Mode> {
|
|
137
215
|
/**
|
|
138
216
|
* The metavariable name for the derived parser. Used in help messages
|
|
139
217
|
* to indicate what kind of value this parser expects.
|
|
@@ -150,7 +228,7 @@ interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
|
150
228
|
* @param values The values parsed from the dependency sources (in order).
|
|
151
229
|
* @returns A {@link ValueParser} for the derived value.
|
|
152
230
|
*/
|
|
153
|
-
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<
|
|
231
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<FM, T>;
|
|
154
232
|
/**
|
|
155
233
|
* Default values to use when the dependency sources are not provided.
|
|
156
234
|
* Must return a tuple with the same length and types as the dependencies.
|
|
@@ -159,6 +237,58 @@ interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
|
159
237
|
*/
|
|
160
238
|
readonly defaultValues: () => DependencyValues<Deps>;
|
|
161
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Options for creating a derived value parser from multiple dependencies
|
|
242
|
+
* with a synchronous factory.
|
|
243
|
+
*
|
|
244
|
+
* @template Deps A tuple of DependencySource types.
|
|
245
|
+
* @template T The type of the derived parser value.
|
|
246
|
+
* @since 0.10.0
|
|
247
|
+
*/
|
|
248
|
+
interface DeriveFromSyncOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
249
|
+
/**
|
|
250
|
+
* The metavariable name for the derived parser.
|
|
251
|
+
*/
|
|
252
|
+
readonly metavar: NonEmptyString;
|
|
253
|
+
/**
|
|
254
|
+
* The dependency sources that this derived parser depends on.
|
|
255
|
+
*/
|
|
256
|
+
readonly dependencies: Deps;
|
|
257
|
+
/**
|
|
258
|
+
* Factory function that creates a synchronous {@link ValueParser}.
|
|
259
|
+
*/
|
|
260
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"sync", T>;
|
|
261
|
+
/**
|
|
262
|
+
* Default values to use when the dependency sources are not provided.
|
|
263
|
+
*/
|
|
264
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Options for creating a derived value parser from multiple dependencies
|
|
268
|
+
* with an asynchronous factory.
|
|
269
|
+
*
|
|
270
|
+
* @template Deps A tuple of DependencySource types.
|
|
271
|
+
* @template T The type of the derived parser value.
|
|
272
|
+
* @since 0.10.0
|
|
273
|
+
*/
|
|
274
|
+
interface DeriveFromAsyncOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
275
|
+
/**
|
|
276
|
+
* The metavariable name for the derived parser.
|
|
277
|
+
*/
|
|
278
|
+
readonly metavar: NonEmptyString;
|
|
279
|
+
/**
|
|
280
|
+
* The dependency sources that this derived parser depends on.
|
|
281
|
+
*/
|
|
282
|
+
readonly dependencies: Deps;
|
|
283
|
+
/**
|
|
284
|
+
* Factory function that creates an asynchronous {@link ValueParser}.
|
|
285
|
+
*/
|
|
286
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"async", T>;
|
|
287
|
+
/**
|
|
288
|
+
* Default values to use when the dependency sources are not provided.
|
|
289
|
+
*/
|
|
290
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
291
|
+
}
|
|
162
292
|
/**
|
|
163
293
|
* A value parser that depends on another parser's value.
|
|
164
294
|
*
|
|
@@ -269,7 +399,37 @@ declare function isDerivedValueParser<M extends Mode, T>(parser: ValueParser<M,
|
|
|
269
399
|
* ```
|
|
270
400
|
* @since 0.10.0
|
|
271
401
|
*/
|
|
272
|
-
declare function deriveFrom<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromOptions<Deps, T>): DerivedValueParser<CombinedDependencyMode<Deps>, T, DependencyValues<Deps>>;
|
|
402
|
+
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>>;
|
|
403
|
+
/**
|
|
404
|
+
* Creates a derived value parser from multiple dependency sources
|
|
405
|
+
* with a synchronous factory.
|
|
406
|
+
*
|
|
407
|
+
* This function allows creating a parser whose behavior depends on
|
|
408
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
409
|
+
* a sync parser.
|
|
410
|
+
*
|
|
411
|
+
* @template Deps A tuple of DependencySource types.
|
|
412
|
+
* @template T The type of value the derived parser produces.
|
|
413
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
414
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
415
|
+
* @since 0.10.0
|
|
416
|
+
*/
|
|
417
|
+
declare function deriveFromSync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromSyncOptions<Deps, T>): DerivedValueParser<CombinedDependencyMode<Deps>, T, DependencyValues<Deps>>;
|
|
418
|
+
/**
|
|
419
|
+
* Creates a derived value parser from multiple dependency sources
|
|
420
|
+
* with an asynchronous factory.
|
|
421
|
+
*
|
|
422
|
+
* This function allows creating a parser whose behavior depends on
|
|
423
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
424
|
+
* an async parser.
|
|
425
|
+
*
|
|
426
|
+
* @template Deps A tuple of DependencySource types.
|
|
427
|
+
* @template T The type of value the derived parser produces.
|
|
428
|
+
* @param options Configuration for the derived parser with async factory.
|
|
429
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
430
|
+
* @since 0.10.0
|
|
431
|
+
*/
|
|
432
|
+
declare function deriveFromAsync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromAsyncOptions<Deps, T>): DerivedValueParser<"async", T, DependencyValues<Deps>>;
|
|
273
433
|
/**
|
|
274
434
|
* A unique symbol used to identify deferred parse states.
|
|
275
435
|
* @since 0.10.0
|
|
@@ -454,4 +614,4 @@ type DependencyError = {
|
|
|
454
614
|
*/
|
|
455
615
|
declare function formatDependencyError(error: DependencyError): Message;
|
|
456
616
|
//#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 };
|
|
617
|
+
export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, 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
|
@@ -54,14 +54,22 @@ const ParseWithDependency = Symbol.for("@optique/core/dependency/ParseWithDepend
|
|
|
54
54
|
*/
|
|
55
55
|
function dependency(parser) {
|
|
56
56
|
const id = Symbol();
|
|
57
|
-
|
|
57
|
+
const result = {
|
|
58
58
|
...parser,
|
|
59
59
|
[DependencySourceMarker]: true,
|
|
60
60
|
[DependencyId]: id,
|
|
61
61
|
derive(options) {
|
|
62
62
|
return createDerivedValueParser(id, parser, options);
|
|
63
|
+
},
|
|
64
|
+
deriveSync(options) {
|
|
65
|
+
if (parser.$mode === "async") return createAsyncDerivedParserFromSyncFactory(id, options);
|
|
66
|
+
return createSyncDerivedParser(id, options);
|
|
67
|
+
},
|
|
68
|
+
deriveAsync(options) {
|
|
69
|
+
return createDerivedValueParser(id, parser, options);
|
|
63
70
|
}
|
|
64
71
|
};
|
|
72
|
+
return result;
|
|
65
73
|
}
|
|
66
74
|
/**
|
|
67
75
|
* Checks if a value parser is a {@link DependencySource}.
|
|
@@ -115,11 +123,62 @@ function isDerivedValueParser(parser) {
|
|
|
115
123
|
* @since 0.10.0
|
|
116
124
|
*/
|
|
117
125
|
function deriveFrom(options) {
|
|
118
|
-
const
|
|
126
|
+
const depsAsync = options.dependencies.some((dep) => dep.$mode === "async");
|
|
127
|
+
const factoryReturnsAsync = determineFactoryModeForDeriveFrom(options);
|
|
128
|
+
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
129
|
+
const isAsync = depsAsync || factoryReturnsAsync;
|
|
130
|
+
if (isAsync) {
|
|
131
|
+
if (factoryReturnsAsync) return createAsyncDerivedFromParserFromAsyncFactory(sourceId, options);
|
|
132
|
+
return createAsyncDerivedFromParserFromSyncFactory(sourceId, options);
|
|
133
|
+
}
|
|
134
|
+
return createSyncDerivedFromParser(sourceId, options);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Creates a derived value parser from multiple dependency sources
|
|
138
|
+
* with a synchronous factory.
|
|
139
|
+
*
|
|
140
|
+
* This function allows creating a parser whose behavior depends on
|
|
141
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
142
|
+
* a sync parser.
|
|
143
|
+
*
|
|
144
|
+
* @template Deps A tuple of DependencySource types.
|
|
145
|
+
* @template T The type of value the derived parser produces.
|
|
146
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
147
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
148
|
+
* @since 0.10.0
|
|
149
|
+
*/
|
|
150
|
+
function deriveFromSync(options) {
|
|
151
|
+
const depsAsync = options.dependencies.some((dep) => dep.$mode === "async");
|
|
119
152
|
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
120
|
-
if (
|
|
153
|
+
if (depsAsync) return createAsyncDerivedFromParserFromSyncFactory(sourceId, options);
|
|
121
154
|
return createSyncDerivedFromParser(sourceId, options);
|
|
122
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Creates a derived value parser from multiple dependency sources
|
|
158
|
+
* with an asynchronous factory.
|
|
159
|
+
*
|
|
160
|
+
* This function allows creating a parser whose behavior depends on
|
|
161
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
162
|
+
* an async parser.
|
|
163
|
+
*
|
|
164
|
+
* @template Deps A tuple of DependencySource types.
|
|
165
|
+
* @template T The type of value the derived parser produces.
|
|
166
|
+
* @param options Configuration for the derived parser with async factory.
|
|
167
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
168
|
+
* @since 0.10.0
|
|
169
|
+
*/
|
|
170
|
+
function deriveFromAsync(options) {
|
|
171
|
+
const sourceId = options.dependencies.length > 0 ? options.dependencies[0][DependencyId] : Symbol();
|
|
172
|
+
return createAsyncDerivedFromParserFromAsyncFactory(sourceId, options);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Determines if the factory returns an async parser for deriveFrom options.
|
|
176
|
+
*/
|
|
177
|
+
function determineFactoryModeForDeriveFrom(options) {
|
|
178
|
+
const defaultValues = options.defaultValues();
|
|
179
|
+
const parser = options.factory(...defaultValues);
|
|
180
|
+
return parser.$mode === "async";
|
|
181
|
+
}
|
|
123
182
|
function createSyncDerivedFromParser(sourceId, options) {
|
|
124
183
|
return {
|
|
125
184
|
$mode: "sync",
|
|
@@ -147,7 +206,42 @@ function createSyncDerivedFromParser(sourceId, options) {
|
|
|
147
206
|
}
|
|
148
207
|
};
|
|
149
208
|
}
|
|
150
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Creates an async derived parser from multiple dependencies when the
|
|
211
|
+
* factory returns an async parser.
|
|
212
|
+
*/
|
|
213
|
+
function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
|
|
214
|
+
return {
|
|
215
|
+
$mode: "async",
|
|
216
|
+
metavar: options.metavar,
|
|
217
|
+
[DerivedValueParserMarker]: true,
|
|
218
|
+
[DependencyId]: sourceId,
|
|
219
|
+
parse(input) {
|
|
220
|
+
const sourceValues = options.defaultValues();
|
|
221
|
+
const derivedParser = options.factory(...sourceValues);
|
|
222
|
+
return derivedParser.parse(input);
|
|
223
|
+
},
|
|
224
|
+
[ParseWithDependency](input, dependencyValue) {
|
|
225
|
+
const derivedParser = options.factory(...dependencyValue);
|
|
226
|
+
return derivedParser.parse(input);
|
|
227
|
+
},
|
|
228
|
+
format(value) {
|
|
229
|
+
const sourceValues = options.defaultValues();
|
|
230
|
+
const derivedParser = options.factory(...sourceValues);
|
|
231
|
+
return derivedParser.format(value);
|
|
232
|
+
},
|
|
233
|
+
async *suggest(prefix) {
|
|
234
|
+
const sourceValues = options.defaultValues();
|
|
235
|
+
const derivedParser = options.factory(...sourceValues);
|
|
236
|
+
if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Creates an async derived parser from multiple dependencies when the
|
|
242
|
+
* sources are async but the factory returns a sync parser.
|
|
243
|
+
*/
|
|
244
|
+
function createAsyncDerivedFromParserFromSyncFactory(sourceId, options) {
|
|
151
245
|
return {
|
|
152
246
|
$mode: "async",
|
|
153
247
|
metavar: options.metavar,
|
|
@@ -175,9 +269,23 @@ function createAsyncDerivedFromParser(sourceId, options) {
|
|
|
175
269
|
};
|
|
176
270
|
}
|
|
177
271
|
function createDerivedValueParser(sourceId, sourceParser, options) {
|
|
178
|
-
|
|
272
|
+
const factoryReturnsAsync = determineFactoryMode(options);
|
|
273
|
+
const isAsync = sourceParser.$mode === "async" || factoryReturnsAsync;
|
|
274
|
+
if (isAsync) {
|
|
275
|
+
if (factoryReturnsAsync) return createAsyncDerivedParserFromAsyncFactory(sourceId, options);
|
|
276
|
+
return createAsyncDerivedParserFromSyncFactory(sourceId, options);
|
|
277
|
+
}
|
|
179
278
|
return createSyncDerivedParser(sourceId, options);
|
|
180
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Determines if the factory returns an async parser by calling it with
|
|
282
|
+
* the default value and checking the mode.
|
|
283
|
+
*/
|
|
284
|
+
function determineFactoryMode(options) {
|
|
285
|
+
const defaultValue = options.defaultValue();
|
|
286
|
+
const parser = options.factory(defaultValue);
|
|
287
|
+
return parser.$mode === "async";
|
|
288
|
+
}
|
|
181
289
|
function createSyncDerivedParser(sourceId, options) {
|
|
182
290
|
return {
|
|
183
291
|
$mode: "sync",
|
|
@@ -205,7 +313,42 @@ function createSyncDerivedParser(sourceId, options) {
|
|
|
205
313
|
}
|
|
206
314
|
};
|
|
207
315
|
}
|
|
208
|
-
|
|
316
|
+
/**
|
|
317
|
+
* Creates an async derived parser when the factory returns an async parser.
|
|
318
|
+
* The parse result is awaited since the factory returns an async parser.
|
|
319
|
+
*/
|
|
320
|
+
function createAsyncDerivedParserFromAsyncFactory(sourceId, options) {
|
|
321
|
+
return {
|
|
322
|
+
$mode: "async",
|
|
323
|
+
metavar: options.metavar,
|
|
324
|
+
[DerivedValueParserMarker]: true,
|
|
325
|
+
[DependencyId]: sourceId,
|
|
326
|
+
parse(input) {
|
|
327
|
+
const sourceValue = options.defaultValue();
|
|
328
|
+
const derivedParser = options.factory(sourceValue);
|
|
329
|
+
return derivedParser.parse(input);
|
|
330
|
+
},
|
|
331
|
+
[ParseWithDependency](input, dependencyValue) {
|
|
332
|
+
const derivedParser = options.factory(dependencyValue);
|
|
333
|
+
return derivedParser.parse(input);
|
|
334
|
+
},
|
|
335
|
+
format(value) {
|
|
336
|
+
const sourceValue = options.defaultValue();
|
|
337
|
+
const derivedParser = options.factory(sourceValue);
|
|
338
|
+
return derivedParser.format(value);
|
|
339
|
+
},
|
|
340
|
+
async *suggest(prefix) {
|
|
341
|
+
const sourceValue = options.defaultValue();
|
|
342
|
+
const derivedParser = options.factory(sourceValue);
|
|
343
|
+
if (derivedParser.suggest) for await (const suggestion of derivedParser.suggest(prefix)) yield suggestion;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Creates an async derived parser when the source is async but the factory
|
|
349
|
+
* returns a sync parser. The sync result is wrapped in a Promise.
|
|
350
|
+
*/
|
|
351
|
+
function createAsyncDerivedParserFromSyncFactory(sourceId, options) {
|
|
209
352
|
return {
|
|
210
353
|
$mode: "async",
|
|
211
354
|
metavar: options.metavar,
|
|
@@ -364,4 +507,4 @@ function formatDependencyError(error) {
|
|
|
364
507
|
}
|
|
365
508
|
|
|
366
509
|
//#endregion
|
|
367
|
-
export { DeferredParseMarker, DependencyId, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
|
|
510
|
+
export { DeferredParseMarker, DependencyId, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
|
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,8 @@ exports.createDeferredParseState = require_dependency.createDeferredParseState;
|
|
|
34
34
|
exports.createDependencySourceState = require_dependency.createDependencySourceState;
|
|
35
35
|
exports.dependency = require_dependency.dependency;
|
|
36
36
|
exports.deriveFrom = require_dependency.deriveFrom;
|
|
37
|
+
exports.deriveFromAsync = require_dependency.deriveFromAsync;
|
|
38
|
+
exports.deriveFromSync = require_dependency.deriveFromSync;
|
|
37
39
|
exports.ensureNonEmptyString = require_nonempty.ensureNonEmptyString;
|
|
38
40
|
exports.envVar = require_message.envVar;
|
|
39
41
|
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, 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, 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, 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, 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, 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, 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 };
|