@optique/core 1.0.0-dev.921 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/annotation-state.cjs +425 -0
- package/dist/annotation-state.d.cts +24 -0
- package/dist/annotation-state.d.ts +24 -0
- package/dist/annotation-state.js +414 -0
- package/dist/annotations.cjs +2 -248
- package/dist/annotations.d.cts +2 -137
- package/dist/annotations.d.ts +2 -137
- package/dist/annotations.js +2 -238
- package/dist/completion.cjs +611 -100
- package/dist/completion.d.cts +1 -1
- package/dist/completion.d.ts +1 -1
- package/dist/completion.js +611 -100
- package/dist/constructs.cjs +3338 -827
- package/dist/constructs.d.cts +48 -7
- package/dist/constructs.d.ts +48 -7
- package/dist/constructs.js +3338 -827
- package/dist/context.cjs +0 -23
- package/dist/context.d.cts +119 -53
- package/dist/context.d.ts +119 -53
- package/dist/context.js +0 -22
- package/dist/dependency-metadata.cjs +139 -0
- package/dist/dependency-metadata.d.cts +112 -0
- package/dist/dependency-metadata.d.ts +112 -0
- package/dist/dependency-metadata.js +138 -0
- package/dist/dependency-runtime.cjs +698 -0
- package/dist/dependency-runtime.d.cts +149 -0
- package/dist/dependency-runtime.d.ts +149 -0
- package/dist/dependency-runtime.js +687 -0
- package/dist/dependency.cjs +7 -928
- package/dist/dependency.d.cts +2 -794
- package/dist/dependency.d.ts +2 -794
- package/dist/dependency.js +2 -899
- package/dist/displaywidth.cjs +44 -0
- package/dist/displaywidth.js +43 -0
- package/dist/doc.cjs +285 -23
- package/dist/doc.d.cts +57 -2
- package/dist/doc.d.ts +57 -2
- package/dist/doc.js +283 -25
- package/dist/execution-context.cjs +56 -0
- package/dist/execution-context.js +53 -0
- package/dist/extension.cjs +87 -0
- package/dist/extension.d.cts +97 -0
- package/dist/extension.d.ts +97 -0
- package/dist/extension.js +76 -0
- package/dist/facade.cjs +718 -525
- package/dist/facade.d.cts +59 -15
- package/dist/facade.d.ts +59 -15
- package/dist/facade.js +718 -525
- package/dist/index.cjs +14 -29
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +7 -7
- package/dist/input-trace.cjs +56 -0
- package/dist/input-trace.d.cts +77 -0
- package/dist/input-trace.d.ts +77 -0
- package/dist/input-trace.js +55 -0
- package/dist/internal/annotations.cjs +316 -0
- package/dist/internal/annotations.d.cts +140 -0
- package/dist/internal/annotations.d.ts +140 -0
- package/dist/internal/annotations.js +306 -0
- package/dist/internal/dependency.cjs +984 -0
- package/dist/internal/dependency.d.cts +539 -0
- package/dist/internal/dependency.d.ts +539 -0
- package/dist/internal/dependency.js +964 -0
- package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
- package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
- package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
- package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
- package/dist/internal/parser.cjs +728 -0
- package/dist/internal/parser.d.cts +947 -0
- package/dist/internal/parser.d.ts +947 -0
- package/dist/internal/parser.js +711 -0
- package/dist/message.cjs +84 -26
- package/dist/message.d.cts +49 -9
- package/dist/message.d.ts +49 -9
- package/dist/message.js +84 -27
- package/dist/modifiers.cjs +1023 -240
- package/dist/modifiers.d.cts +42 -1
- package/dist/modifiers.d.ts +42 -1
- package/dist/modifiers.js +1023 -240
- package/dist/parser.cjs +11 -463
- package/dist/parser.d.cts +3 -537
- package/dist/parser.d.ts +3 -537
- package/dist/parser.js +2 -433
- package/dist/phase2-seed.cjs +59 -0
- package/dist/phase2-seed.js +56 -0
- package/dist/primitives.cjs +557 -208
- package/dist/primitives.d.cts +10 -14
- package/dist/primitives.d.ts +10 -14
- package/dist/primitives.js +557 -208
- package/dist/program.cjs +5 -1
- package/dist/program.d.cts +5 -3
- package/dist/program.d.ts +5 -3
- package/dist/program.js +6 -1
- package/dist/suggestion.cjs +22 -8
- package/dist/suggestion.js +22 -8
- package/dist/usage-internals.cjs +3 -2
- package/dist/usage-internals.js +4 -2
- package/dist/usage.cjs +195 -40
- package/dist/usage.d.cts +92 -11
- package/dist/usage.d.ts +92 -11
- package/dist/usage.js +194 -41
- package/dist/validate.cjs +170 -0
- package/dist/validate.js +164 -0
- package/dist/valueparser.cjs +1270 -187
- package/dist/valueparser.d.cts +320 -14
- package/dist/valueparser.d.ts +320 -14
- package/dist/valueparser.js +1269 -188
- package/package.json +9 -9
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import { NonEmptyString } from "../nonempty.cjs";
|
|
2
|
+
import { ValueParser, ValueParserResult } from "../valueparser.cjs";
|
|
3
|
+
import { Mode, Suggestion } from "./parser.cjs";
|
|
4
|
+
|
|
5
|
+
//#region src/internal/dependency.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A unique symbol used to identify dependency sources at compile time.
|
|
9
|
+
* This marker is used to distinguish {@link DependencySource} from regular
|
|
10
|
+
* {@link ValueParser} instances.
|
|
11
|
+
* @since 0.10.0
|
|
12
|
+
*/
|
|
13
|
+
declare const dependencySourceMarker: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* A unique symbol used to identify derived value parsers at compile time.
|
|
16
|
+
* This marker is used to distinguish {@link DerivedValueParser} from regular
|
|
17
|
+
* {@link ValueParser} instances.
|
|
18
|
+
* @since 0.10.0
|
|
19
|
+
*/
|
|
20
|
+
declare const derivedValueParserMarker: unique symbol;
|
|
21
|
+
/**
|
|
22
|
+
* A unique symbol used to store the dependency ID on value parsers.
|
|
23
|
+
* @since 0.10.0
|
|
24
|
+
*/
|
|
25
|
+
declare const dependencyId: unique symbol;
|
|
26
|
+
/**
|
|
27
|
+
* A unique symbol used to store multiple dependency IDs on derived parsers
|
|
28
|
+
* that depend on multiple sources (created via {@link deriveFrom}).
|
|
29
|
+
* @since 0.10.0
|
|
30
|
+
*/
|
|
31
|
+
declare const dependencyIds: unique symbol;
|
|
32
|
+
/**
|
|
33
|
+
* A unique symbol used to store the default values function on derived parsers.
|
|
34
|
+
* This is used during partial dependency resolution to fill in missing values.
|
|
35
|
+
* @since 0.10.0
|
|
36
|
+
*/
|
|
37
|
+
declare const defaultValues: unique symbol;
|
|
38
|
+
/**
|
|
39
|
+
* A unique symbol used to store the single default value thunk on derived
|
|
40
|
+
* parsers created by {@link DependencySource.derive}. Unlike
|
|
41
|
+
* {@link defaultValues} (which `createDeferredParseState` only falls back to
|
|
42
|
+
* when no parse-time snapshot is available), this symbol is only read by the
|
|
43
|
+
* dependency-metadata bridge so that
|
|
44
|
+
* single-source defaults are accessible without double evaluation.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
declare const singleDefaultValue: unique symbol;
|
|
48
|
+
/**
|
|
49
|
+
* A unique symbol used to store the snapshotted default dependency values on
|
|
50
|
+
* a parse result produced by a derived parser's default path.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A unique symbol used to access the parseWithDependency method on derived parsers.
|
|
57
|
+
* @since 0.10.0
|
|
58
|
+
*/
|
|
59
|
+
declare const parseWithDependency: unique symbol;
|
|
60
|
+
/**
|
|
61
|
+
* A unique symbol used to access the suggestWithDependency method on derived parsers.
|
|
62
|
+
* This method generates suggestions using the provided dependency values instead of defaults.
|
|
63
|
+
* @since 0.10.0
|
|
64
|
+
*/
|
|
65
|
+
declare const suggestWithDependency: unique symbol;
|
|
66
|
+
/**
|
|
67
|
+
* Combines two modes into a single mode.
|
|
68
|
+
* If either mode is async, the result is async.
|
|
69
|
+
* @template M1 The first mode.
|
|
70
|
+
* @template M2 The second mode.
|
|
71
|
+
* @since 0.10.0
|
|
72
|
+
*/
|
|
73
|
+
type CombineMode<M1 extends Mode, M2 extends Mode> = M1 extends "async" ? "async" : M2 extends "async" ? "async" : "sync";
|
|
74
|
+
/**
|
|
75
|
+
* Options for creating a derived value parser.
|
|
76
|
+
*
|
|
77
|
+
* @template S The type of the source dependency value.
|
|
78
|
+
* @template T The type of the derived parser value.
|
|
79
|
+
* @template FM The mode of the factory's returned parser.
|
|
80
|
+
* @since 0.10.0
|
|
81
|
+
*/
|
|
82
|
+
interface DeriveOptions<S, T, FM extends Mode = Mode> {
|
|
83
|
+
/**
|
|
84
|
+
* The metavariable name for the derived parser. Used in help messages
|
|
85
|
+
* to indicate what kind of value this parser expects.
|
|
86
|
+
*/
|
|
87
|
+
readonly metavar: NonEmptyString;
|
|
88
|
+
/**
|
|
89
|
+
* Factory function that creates a {@link ValueParser} based on the
|
|
90
|
+
* dependency source's value.
|
|
91
|
+
*
|
|
92
|
+
* @param sourceValue The value parsed from the dependency source.
|
|
93
|
+
* @returns A {@link ValueParser} for the derived value.
|
|
94
|
+
*/
|
|
95
|
+
readonly factory: (sourceValue: S) => ValueParser<NoInfer<FM>, T>;
|
|
96
|
+
/**
|
|
97
|
+
* Default value to use when the dependency source is not provided.
|
|
98
|
+
* This allows the derived parser to work even when the dependency
|
|
99
|
+
* is optional.
|
|
100
|
+
*
|
|
101
|
+
* @returns The default value for the dependency source.
|
|
102
|
+
*/
|
|
103
|
+
readonly defaultValue: () => S;
|
|
104
|
+
/**
|
|
105
|
+
* The execution mode of the factory's returned parser. This tells the
|
|
106
|
+
* runtime whether the factory returns a sync or async parser, avoiding
|
|
107
|
+
* the need to call the factory during parser construction.
|
|
108
|
+
*
|
|
109
|
+
* @since 1.0.0
|
|
110
|
+
*/
|
|
111
|
+
readonly mode: FM;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Options for creating a derived value parser with a synchronous factory.
|
|
115
|
+
*
|
|
116
|
+
* @template S The type of the source dependency value.
|
|
117
|
+
* @template T The type of the derived parser value.
|
|
118
|
+
* @since 0.10.0
|
|
119
|
+
*/
|
|
120
|
+
interface DeriveSyncOptions<S, T> {
|
|
121
|
+
/**
|
|
122
|
+
* The metavariable name for the derived parser.
|
|
123
|
+
*/
|
|
124
|
+
readonly metavar: NonEmptyString;
|
|
125
|
+
/**
|
|
126
|
+
* Factory function that creates a synchronous {@link ValueParser}.
|
|
127
|
+
*/
|
|
128
|
+
readonly factory: (sourceValue: S) => ValueParser<"sync", T>;
|
|
129
|
+
/**
|
|
130
|
+
* Default value to use when the dependency source is not provided.
|
|
131
|
+
*/
|
|
132
|
+
readonly defaultValue: () => S;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Options for creating a derived value parser with an asynchronous factory.
|
|
136
|
+
*
|
|
137
|
+
* @template S The type of the source dependency value.
|
|
138
|
+
* @template T The type of the derived parser value.
|
|
139
|
+
* @since 0.10.0
|
|
140
|
+
*/
|
|
141
|
+
interface DeriveAsyncOptions<S, T> {
|
|
142
|
+
/**
|
|
143
|
+
* The metavariable name for the derived parser.
|
|
144
|
+
*/
|
|
145
|
+
readonly metavar: NonEmptyString;
|
|
146
|
+
/**
|
|
147
|
+
* Factory function that creates an asynchronous {@link ValueParser}.
|
|
148
|
+
*/
|
|
149
|
+
readonly factory: (sourceValue: S) => ValueParser<"async", T>;
|
|
150
|
+
/**
|
|
151
|
+
* Default value to use when the dependency source is not provided.
|
|
152
|
+
*/
|
|
153
|
+
readonly defaultValue: () => S;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Represents a dependency source that can be used to create derived parsers.
|
|
157
|
+
*
|
|
158
|
+
* A dependency source wraps a {@link ValueParser} and provides methods to
|
|
159
|
+
* create derived parsers that depend on the parsed value. This enables
|
|
160
|
+
* inter-option dependencies where one option's valid values depend on
|
|
161
|
+
* another option's value.
|
|
162
|
+
*
|
|
163
|
+
* @template M The execution mode of the parser (`"sync"` or `"async"`).
|
|
164
|
+
* @template T The type of value this dependency source produces.
|
|
165
|
+
* @since 0.10.0
|
|
166
|
+
*/
|
|
167
|
+
interface DependencySource<M extends Mode = "sync", T = unknown> extends ValueParser<M, T> {
|
|
168
|
+
/**
|
|
169
|
+
* Marker to identify this as a dependency source.
|
|
170
|
+
* @internal
|
|
171
|
+
*/
|
|
172
|
+
readonly [dependencySourceMarker]: true;
|
|
173
|
+
/**
|
|
174
|
+
* Unique identifier for this dependency source.
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
readonly [dependencyId]: symbol;
|
|
178
|
+
/**
|
|
179
|
+
* Creates a derived value parser whose behavior depends on this
|
|
180
|
+
* dependency source's value.
|
|
181
|
+
*
|
|
182
|
+
* The derived parser uses a factory function to create parsers based on
|
|
183
|
+
* the source value. The factory can return either a sync or async parser,
|
|
184
|
+
* and the resulting derived parser's mode will be the combination of
|
|
185
|
+
* the source mode and the factory's returned parser mode.
|
|
186
|
+
*
|
|
187
|
+
* @template U The type of value the derived parser produces.
|
|
188
|
+
* @template FM The mode of the factory's returned parser.
|
|
189
|
+
* @param options Configuration for the derived parser.
|
|
190
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
191
|
+
* @throws {TypeError} If the `mode` field is missing or invalid.
|
|
192
|
+
*/
|
|
193
|
+
derive<U, FM extends Mode = "sync">(options: DeriveOptions<T, U, FM>): DerivedValueParser<CombineMode<M, FM>, U, T>;
|
|
194
|
+
/**
|
|
195
|
+
* Creates a derived value parser with a synchronous factory.
|
|
196
|
+
*
|
|
197
|
+
* This is a convenience method that explicitly requires a sync factory,
|
|
198
|
+
* making the type inference more predictable.
|
|
199
|
+
*
|
|
200
|
+
* @template U The type of value the derived parser produces.
|
|
201
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
202
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
203
|
+
* @since 0.10.0
|
|
204
|
+
*/
|
|
205
|
+
deriveSync<U>(options: DeriveSyncOptions<T, U>): DerivedValueParser<M, U, T>;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a derived value parser with an asynchronous factory.
|
|
208
|
+
*
|
|
209
|
+
* This is a convenience method that explicitly requires an async factory,
|
|
210
|
+
* making the type inference more predictable.
|
|
211
|
+
*
|
|
212
|
+
* @template U The type of value the derived parser produces.
|
|
213
|
+
* @param options Configuration for the derived parser with async factory.
|
|
214
|
+
* @returns A {@link DerivedValueParser} that depends on this source.
|
|
215
|
+
* @since 0.10.0
|
|
216
|
+
*/
|
|
217
|
+
deriveAsync<U>(options: DeriveAsyncOptions<T, U>): DerivedValueParser<"async", U, T>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Extracts the value type from a DependencySource.
|
|
221
|
+
* @template D The DependencySource type.
|
|
222
|
+
* @since 0.10.0
|
|
223
|
+
*/
|
|
224
|
+
type DependencyValue<D> = D extends DependencySource<Mode, infer T> ? T : never;
|
|
225
|
+
/**
|
|
226
|
+
* Extracts the mode from a DependencySource.
|
|
227
|
+
* @template D The DependencySource type.
|
|
228
|
+
* @since 0.10.0
|
|
229
|
+
*/
|
|
230
|
+
type DependencyMode<D> = D extends DependencySource<infer M, unknown> ? M : never;
|
|
231
|
+
/**
|
|
232
|
+
* Maps a tuple of DependencySources to a tuple of their value types.
|
|
233
|
+
* @template T The tuple of DependencySource types.
|
|
234
|
+
* @since 0.10.0
|
|
235
|
+
*/
|
|
236
|
+
type DependencyValues<T extends readonly unknown[]> = { [K in keyof T]: T[K] extends DependencySource<Mode, infer V> ? V : never };
|
|
237
|
+
/**
|
|
238
|
+
* Combines modes from multiple dependency sources.
|
|
239
|
+
* If any source is async, the result is async.
|
|
240
|
+
* @template T The tuple of DependencySource types.
|
|
241
|
+
* @since 0.10.0
|
|
242
|
+
*/
|
|
243
|
+
type CombinedDependencyMode<T extends readonly unknown[]> = "async" extends { [K in keyof T]: T[K] extends DependencySource<infer M, unknown> ? M : never }[number] ? "async" : "sync";
|
|
244
|
+
/**
|
|
245
|
+
* Minimal structural supertype for dependency-source tuple constraints.
|
|
246
|
+
*
|
|
247
|
+
* TypeScript cannot express an existential type like
|
|
248
|
+
* `DependencySource<Mode, some T>`, and `DependencySource<Mode, unknown>` is
|
|
249
|
+
* too strict because dependency sources are invariant in their value type.
|
|
250
|
+
* This structural view preserves assignability without resorting to `any`.
|
|
251
|
+
*
|
|
252
|
+
* @since 0.10.0
|
|
253
|
+
*/
|
|
254
|
+
interface AnyDependencySource<M extends Mode = Mode> {
|
|
255
|
+
readonly [dependencySourceMarker]: true;
|
|
256
|
+
readonly [dependencyId]: symbol;
|
|
257
|
+
readonly mode: M;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Options for creating a derived value parser from multiple dependencies.
|
|
261
|
+
*
|
|
262
|
+
* @template Deps A tuple of DependencySource types.
|
|
263
|
+
* @template T The type of the derived parser value.
|
|
264
|
+
* @template FM The mode of the factory's returned parser.
|
|
265
|
+
* @since 0.10.0
|
|
266
|
+
*/
|
|
267
|
+
interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T, FM extends Mode = Mode> {
|
|
268
|
+
/**
|
|
269
|
+
* The metavariable name for the derived parser. Used in help messages
|
|
270
|
+
* to indicate what kind of value this parser expects.
|
|
271
|
+
*/
|
|
272
|
+
readonly metavar: NonEmptyString;
|
|
273
|
+
/**
|
|
274
|
+
* The dependency sources that this derived parser depends on.
|
|
275
|
+
*/
|
|
276
|
+
readonly dependencies: Deps;
|
|
277
|
+
/**
|
|
278
|
+
* Factory function that creates a {@link ValueParser} based on the
|
|
279
|
+
* dependency sources' values.
|
|
280
|
+
*
|
|
281
|
+
* @param values The values parsed from the dependency sources (in order).
|
|
282
|
+
* @returns A {@link ValueParser} for the derived value.
|
|
283
|
+
*/
|
|
284
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<NoInfer<FM>, T>;
|
|
285
|
+
/**
|
|
286
|
+
* Default values to use when the dependency sources are not provided.
|
|
287
|
+
* Must return a tuple with the same length and types as the dependencies.
|
|
288
|
+
*
|
|
289
|
+
* @returns A tuple of default values for each dependency source.
|
|
290
|
+
*/
|
|
291
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
292
|
+
/**
|
|
293
|
+
* The execution mode of the factory's returned parser. This tells the
|
|
294
|
+
* runtime whether the factory returns a sync or async parser, avoiding
|
|
295
|
+
* the need to call the factory during parser construction.
|
|
296
|
+
*
|
|
297
|
+
* @since 1.0.0
|
|
298
|
+
*/
|
|
299
|
+
readonly mode: FM;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Options for creating a derived value parser from multiple dependencies
|
|
303
|
+
* with a synchronous factory.
|
|
304
|
+
*
|
|
305
|
+
* @template Deps A tuple of DependencySource types.
|
|
306
|
+
* @template T The type of the derived parser value.
|
|
307
|
+
* @since 0.10.0
|
|
308
|
+
*/
|
|
309
|
+
interface DeriveFromSyncOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
310
|
+
/**
|
|
311
|
+
* The metavariable name for the derived parser.
|
|
312
|
+
*/
|
|
313
|
+
readonly metavar: NonEmptyString;
|
|
314
|
+
/**
|
|
315
|
+
* The dependency sources that this derived parser depends on.
|
|
316
|
+
*/
|
|
317
|
+
readonly dependencies: Deps;
|
|
318
|
+
/**
|
|
319
|
+
* Factory function that creates a synchronous {@link ValueParser}.
|
|
320
|
+
*/
|
|
321
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"sync", T>;
|
|
322
|
+
/**
|
|
323
|
+
* Default values to use when the dependency sources are not provided.
|
|
324
|
+
*/
|
|
325
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Options for creating a derived value parser from multiple dependencies
|
|
329
|
+
* with an asynchronous factory.
|
|
330
|
+
*
|
|
331
|
+
* @template Deps A tuple of DependencySource types.
|
|
332
|
+
* @template T The type of the derived parser value.
|
|
333
|
+
* @since 0.10.0
|
|
334
|
+
*/
|
|
335
|
+
interface DeriveFromAsyncOptions<Deps extends readonly AnyDependencySource[], T> {
|
|
336
|
+
/**
|
|
337
|
+
* The metavariable name for the derived parser.
|
|
338
|
+
*/
|
|
339
|
+
readonly metavar: NonEmptyString;
|
|
340
|
+
/**
|
|
341
|
+
* The dependency sources that this derived parser depends on.
|
|
342
|
+
*/
|
|
343
|
+
readonly dependencies: Deps;
|
|
344
|
+
/**
|
|
345
|
+
* Factory function that creates an asynchronous {@link ValueParser}.
|
|
346
|
+
*/
|
|
347
|
+
readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"async", T>;
|
|
348
|
+
/**
|
|
349
|
+
* Default values to use when the dependency sources are not provided.
|
|
350
|
+
*/
|
|
351
|
+
readonly defaultValues: () => DependencyValues<Deps>;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* A value parser that depends on another parser's value.
|
|
355
|
+
*
|
|
356
|
+
* A derived value parser cannot be nested (i.e., you cannot call
|
|
357
|
+
* {@link DependencySource.derive} on a {@link DerivedValueParser}).
|
|
358
|
+
*
|
|
359
|
+
* @template M The execution mode of the parser (`"sync"` or `"async"`).
|
|
360
|
+
* @template T The type of value this parser produces.
|
|
361
|
+
* @template S The type of the source dependency value.
|
|
362
|
+
* @since 0.10.0
|
|
363
|
+
*/
|
|
364
|
+
interface DerivedValueParser<M extends Mode = "sync", T = unknown, S = unknown> extends ValueParser<M, T> {
|
|
365
|
+
/**
|
|
366
|
+
* Marker to identify this as a derived value parser.
|
|
367
|
+
* @internal
|
|
368
|
+
*/
|
|
369
|
+
readonly [derivedValueParserMarker]: true;
|
|
370
|
+
/**
|
|
371
|
+
* The unique identifier of the dependency source this parser depends on.
|
|
372
|
+
* For parsers created with {@link deriveFrom} that have multiple dependencies,
|
|
373
|
+
* this is set to the first dependency's ID for backwards compatibility.
|
|
374
|
+
* @internal
|
|
375
|
+
*/
|
|
376
|
+
readonly [dependencyId]: symbol;
|
|
377
|
+
/**
|
|
378
|
+
* The unique identifiers of all dependency sources this parser depends on.
|
|
379
|
+
* Present only for parsers created with {@link deriveFrom} that have multiple
|
|
380
|
+
* dependencies. If present, this takes precedence over {@link dependencyId}
|
|
381
|
+
* during dependency resolution.
|
|
382
|
+
* @internal
|
|
383
|
+
*/
|
|
384
|
+
readonly [dependencyIds]?: readonly symbol[];
|
|
385
|
+
/**
|
|
386
|
+
* The default values function for this parser's dependencies.
|
|
387
|
+
* Used during partial dependency resolution to fill in missing values.
|
|
388
|
+
* @internal
|
|
389
|
+
*/
|
|
390
|
+
readonly [defaultValues]?: () => readonly unknown[];
|
|
391
|
+
/**
|
|
392
|
+
* The single default value thunk for single-source derived parsers.
|
|
393
|
+
* Read by the dependency-metadata bridge; not consumed by
|
|
394
|
+
* `createDeferredParseState()`.
|
|
395
|
+
* @internal
|
|
396
|
+
*/
|
|
397
|
+
readonly [singleDefaultValue]?: () => S;
|
|
398
|
+
/**
|
|
399
|
+
* Parses the input using the actual dependency value instead of the default.
|
|
400
|
+
* This method is used during dependency resolution in `complete()`.
|
|
401
|
+
*
|
|
402
|
+
* @param input The raw input string to parse.
|
|
403
|
+
* @param dependencyValue The resolved dependency value.
|
|
404
|
+
* @returns The parse result.
|
|
405
|
+
* @internal
|
|
406
|
+
*/
|
|
407
|
+
readonly [parseWithDependency]: (input: string, dependencyValue: S) => ValueParserResult<T> | Promise<ValueParserResult<T>>;
|
|
408
|
+
/**
|
|
409
|
+
* Generates suggestions using the provided dependency value instead of the default.
|
|
410
|
+
* This method is used during shell completion when dependency sources have been parsed.
|
|
411
|
+
*
|
|
412
|
+
* @param prefix The input prefix to filter suggestions.
|
|
413
|
+
* @param dependencyValue The resolved dependency value.
|
|
414
|
+
* @returns An iterable of suggestions.
|
|
415
|
+
* @internal
|
|
416
|
+
*/
|
|
417
|
+
readonly [suggestWithDependency]?: (prefix: string, dependencyValue: S) => Iterable<Suggestion> | AsyncIterable<Suggestion>;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Creates a dependency source from a {@link ValueParser}.
|
|
421
|
+
*
|
|
422
|
+
* A dependency source wraps an existing value parser and enables creating
|
|
423
|
+
* derived parsers that depend on the parsed value. This is useful for
|
|
424
|
+
* scenarios where one option's valid values depend on another option's value.
|
|
425
|
+
*
|
|
426
|
+
* @template M The execution mode of the value parser.
|
|
427
|
+
* @template T The type of value the parser produces.
|
|
428
|
+
* @param parser The value parser to wrap as a dependency source.
|
|
429
|
+
* @returns A {@link DependencySource} that can be used to create
|
|
430
|
+
* derived parsers.
|
|
431
|
+
* @example
|
|
432
|
+
* ```typescript
|
|
433
|
+
* import { dependency } from "@optique/core/dependency";
|
|
434
|
+
* import { string } from "@optique/core/valueparser";
|
|
435
|
+
*
|
|
436
|
+
* // Create a dependency source for a directory path
|
|
437
|
+
* const cwdParser = dependency(string({ metavar: "DIR" }));
|
|
438
|
+
*
|
|
439
|
+
* // Create a derived parser that depends on the directory
|
|
440
|
+
* const branchParser = cwdParser.derive({
|
|
441
|
+
* metavar: "BRANCH",
|
|
442
|
+
* mode: "sync",
|
|
443
|
+
* factory: (dir) => gitBranch({ dir }),
|
|
444
|
+
* defaultValue: () => process.cwd(),
|
|
445
|
+
* });
|
|
446
|
+
* ```
|
|
447
|
+
* @since 0.10.0
|
|
448
|
+
*/
|
|
449
|
+
declare function dependency<M extends Mode, T>(parser: ValueParser<M, T>): DependencySource<M, T>;
|
|
450
|
+
/**
|
|
451
|
+
* Checks if a value parser is a {@link DependencySource}.
|
|
452
|
+
*
|
|
453
|
+
* @param parser The value parser to check.
|
|
454
|
+
* @returns `true` if the parser is a dependency source, `false` otherwise.
|
|
455
|
+
* @since 0.10.0
|
|
456
|
+
*/
|
|
457
|
+
declare function isDependencySource<M extends Mode, T>(parser: ValueParser<M, T>): parser is DependencySource<M, T>;
|
|
458
|
+
/**
|
|
459
|
+
* Checks if a value parser is a {@link DerivedValueParser}.
|
|
460
|
+
*
|
|
461
|
+
* @param parser The value parser to check.
|
|
462
|
+
* @returns `true` if the parser is a derived value parser, `false` otherwise.
|
|
463
|
+
* @since 0.10.0
|
|
464
|
+
*/
|
|
465
|
+
declare function isDerivedValueParser<M extends Mode, T>(parser: ValueParser<M, T>): parser is DerivedValueParser<M, T, unknown>;
|
|
466
|
+
/**
|
|
467
|
+
* Creates a derived value parser from multiple dependency sources.
|
|
468
|
+
*
|
|
469
|
+
* This function allows creating a parser whose behavior depends on
|
|
470
|
+
* multiple other parsers' values. This is useful for scenarios where
|
|
471
|
+
* an option's valid values depend on a combination of other options.
|
|
472
|
+
*
|
|
473
|
+
* @template Deps A tuple of DependencySource types.
|
|
474
|
+
* @template T The type of value the derived parser produces.
|
|
475
|
+
* @param options Configuration for the derived parser.
|
|
476
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
477
|
+
* @example
|
|
478
|
+
* ```typescript
|
|
479
|
+
* import { dependency, deriveFrom } from "@optique/core/dependency";
|
|
480
|
+
* import { string, choice } from "@optique/core/valueparser";
|
|
481
|
+
*
|
|
482
|
+
* const dirParser = dependency(string({ metavar: "DIR" }));
|
|
483
|
+
* const modeParser = dependency(choice(["dev", "prod"]));
|
|
484
|
+
*
|
|
485
|
+
* const configParser = deriveFrom({
|
|
486
|
+
* metavar: "CONFIG",
|
|
487
|
+
* mode: "sync",
|
|
488
|
+
* dependencies: [dirParser, modeParser] as const,
|
|
489
|
+
* factory: (dir, mode) =>
|
|
490
|
+
* choice(mode === "dev"
|
|
491
|
+
* ? [`${dir}/dev.json`, `${dir}/dev.yaml`]
|
|
492
|
+
* : [`${dir}/prod.json`, `${dir}/prod.yaml`]),
|
|
493
|
+
* defaultValues: () => ["/config", "dev"],
|
|
494
|
+
* });
|
|
495
|
+
* ```
|
|
496
|
+
* @throws {TypeError} If the `mode` field is missing or invalid.
|
|
497
|
+
* @since 0.10.0
|
|
498
|
+
*/
|
|
499
|
+
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>>;
|
|
500
|
+
/**
|
|
501
|
+
* Creates a derived value parser from multiple dependency sources
|
|
502
|
+
* with a synchronous factory.
|
|
503
|
+
*
|
|
504
|
+
* This function allows creating a parser whose behavior depends on
|
|
505
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
506
|
+
* a sync parser.
|
|
507
|
+
*
|
|
508
|
+
* @template Deps A tuple of DependencySource types.
|
|
509
|
+
* @template T The type of value the derived parser produces.
|
|
510
|
+
* @param options Configuration for the derived parser with sync factory.
|
|
511
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
512
|
+
* @since 0.10.0
|
|
513
|
+
*/
|
|
514
|
+
declare function deriveFromSync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromSyncOptions<Deps, T>): DerivedValueParser<CombinedDependencyMode<Deps>, T, DependencyValues<Deps>>;
|
|
515
|
+
/**
|
|
516
|
+
* Creates a derived value parser from multiple dependency sources
|
|
517
|
+
* with an asynchronous factory.
|
|
518
|
+
*
|
|
519
|
+
* This function allows creating a parser whose behavior depends on
|
|
520
|
+
* multiple other parsers' values. The factory explicitly returns
|
|
521
|
+
* an async parser.
|
|
522
|
+
*
|
|
523
|
+
* @template Deps A tuple of DependencySource types.
|
|
524
|
+
* @template T The type of value the derived parser produces.
|
|
525
|
+
* @param options Configuration for the derived parser with async factory.
|
|
526
|
+
* @returns A {@link DerivedValueParser} that depends on the given sources.
|
|
527
|
+
* @since 0.10.0
|
|
528
|
+
*/
|
|
529
|
+
declare function deriveFromAsync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromAsyncOptions<Deps, T>): DerivedValueParser<"async", T, DependencyValues<Deps>>;
|
|
530
|
+
/**
|
|
531
|
+
* Attaches a default dependency snapshot to a derived parser's parse result.
|
|
532
|
+
*
|
|
533
|
+
* @param result The parse result to annotate.
|
|
534
|
+
* @param values The dependency values used for the default-path parse.
|
|
535
|
+
* @returns A cloned parse result with an internal snapshot attached.
|
|
536
|
+
* @internal
|
|
537
|
+
*/
|
|
538
|
+
//#endregion
|
|
539
|
+
export { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser };
|