@optique/core 1.0.0-dev.908 → 1.0.0

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.
Files changed (109) hide show
  1. package/dist/annotation-state.cjs +425 -0
  2. package/dist/annotation-state.d.cts +24 -0
  3. package/dist/annotation-state.d.ts +24 -0
  4. package/dist/annotation-state.js +414 -0
  5. package/dist/annotations.cjs +2 -248
  6. package/dist/annotations.d.cts +2 -137
  7. package/dist/annotations.d.ts +2 -137
  8. package/dist/annotations.js +2 -238
  9. package/dist/completion.cjs +611 -100
  10. package/dist/completion.d.cts +1 -1
  11. package/dist/completion.d.ts +1 -1
  12. package/dist/completion.js +611 -100
  13. package/dist/constructs.cjs +3338 -827
  14. package/dist/constructs.d.cts +48 -7
  15. package/dist/constructs.d.ts +48 -7
  16. package/dist/constructs.js +3338 -827
  17. package/dist/context.cjs +0 -23
  18. package/dist/context.d.cts +119 -53
  19. package/dist/context.d.ts +119 -53
  20. package/dist/context.js +0 -22
  21. package/dist/dependency-metadata.cjs +139 -0
  22. package/dist/dependency-metadata.d.cts +112 -0
  23. package/dist/dependency-metadata.d.ts +112 -0
  24. package/dist/dependency-metadata.js +138 -0
  25. package/dist/dependency-runtime.cjs +698 -0
  26. package/dist/dependency-runtime.d.cts +149 -0
  27. package/dist/dependency-runtime.d.ts +149 -0
  28. package/dist/dependency-runtime.js +687 -0
  29. package/dist/dependency.cjs +7 -928
  30. package/dist/dependency.d.cts +2 -794
  31. package/dist/dependency.d.ts +2 -794
  32. package/dist/dependency.js +2 -899
  33. package/dist/displaywidth.cjs +44 -0
  34. package/dist/displaywidth.js +43 -0
  35. package/dist/doc.cjs +285 -23
  36. package/dist/doc.d.cts +57 -2
  37. package/dist/doc.d.ts +57 -2
  38. package/dist/doc.js +283 -25
  39. package/dist/execution-context.cjs +56 -0
  40. package/dist/execution-context.js +53 -0
  41. package/dist/extension.cjs +87 -0
  42. package/dist/extension.d.cts +97 -0
  43. package/dist/extension.d.ts +97 -0
  44. package/dist/extension.js +76 -0
  45. package/dist/facade.cjs +718 -523
  46. package/dist/facade.d.cts +87 -18
  47. package/dist/facade.d.ts +87 -18
  48. package/dist/facade.js +718 -523
  49. package/dist/index.cjs +14 -29
  50. package/dist/index.d.cts +10 -10
  51. package/dist/index.d.ts +10 -10
  52. package/dist/index.js +7 -7
  53. package/dist/input-trace.cjs +56 -0
  54. package/dist/input-trace.d.cts +77 -0
  55. package/dist/input-trace.d.ts +77 -0
  56. package/dist/input-trace.js +55 -0
  57. package/dist/internal/annotations.cjs +316 -0
  58. package/dist/internal/annotations.d.cts +140 -0
  59. package/dist/internal/annotations.d.ts +140 -0
  60. package/dist/internal/annotations.js +306 -0
  61. package/dist/internal/dependency.cjs +984 -0
  62. package/dist/internal/dependency.d.cts +539 -0
  63. package/dist/internal/dependency.d.ts +539 -0
  64. package/dist/internal/dependency.js +964 -0
  65. package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
  66. package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
  67. package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
  68. package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
  69. package/dist/internal/parser.cjs +728 -0
  70. package/dist/internal/parser.d.cts +947 -0
  71. package/dist/internal/parser.d.ts +947 -0
  72. package/dist/internal/parser.js +711 -0
  73. package/dist/message.cjs +84 -26
  74. package/dist/message.d.cts +49 -9
  75. package/dist/message.d.ts +49 -9
  76. package/dist/message.js +84 -27
  77. package/dist/modifiers.cjs +1023 -240
  78. package/dist/modifiers.d.cts +42 -1
  79. package/dist/modifiers.d.ts +42 -1
  80. package/dist/modifiers.js +1023 -240
  81. package/dist/parser.cjs +11 -463
  82. package/dist/parser.d.cts +3 -537
  83. package/dist/parser.d.ts +3 -537
  84. package/dist/parser.js +2 -433
  85. package/dist/phase2-seed.cjs +59 -0
  86. package/dist/phase2-seed.js +56 -0
  87. package/dist/primitives.cjs +557 -208
  88. package/dist/primitives.d.cts +10 -14
  89. package/dist/primitives.d.ts +10 -14
  90. package/dist/primitives.js +557 -208
  91. package/dist/program.cjs +5 -1
  92. package/dist/program.d.cts +5 -3
  93. package/dist/program.d.ts +5 -3
  94. package/dist/program.js +6 -1
  95. package/dist/suggestion.cjs +22 -8
  96. package/dist/suggestion.js +22 -8
  97. package/dist/usage-internals.cjs +3 -2
  98. package/dist/usage-internals.js +4 -2
  99. package/dist/usage.cjs +195 -40
  100. package/dist/usage.d.cts +92 -11
  101. package/dist/usage.d.ts +92 -11
  102. package/dist/usage.js +194 -41
  103. package/dist/validate.cjs +170 -0
  104. package/dist/validate.js +164 -0
  105. package/dist/valueparser.cjs +1278 -191
  106. package/dist/valueparser.d.cts +330 -20
  107. package/dist/valueparser.d.ts +330 -20
  108. package/dist/valueparser.js +1277 -192
  109. package/package.json +9 -9
@@ -1,794 +1,2 @@
1
- import { NonEmptyString } from "./nonempty.js";
2
- import { Message } from "./message.js";
3
- import { DependencyRegistryLike } from "./registry-types.js";
4
- import { ValueParser, ValueParserResult } from "./valueparser.js";
5
- import { Mode, Suggestion } from "./parser.js";
6
-
7
- //#region src/dependency.d.ts
8
-
9
- /**
10
- * A unique symbol used to identify dependency sources at compile time.
11
- * This marker is used to distinguish {@link DependencySource} from regular
12
- * {@link ValueParser} instances.
13
- * @since 0.10.0
14
- */
15
- declare const dependencySourceMarker: unique symbol;
16
- /**
17
- * A unique symbol used to identify derived value parsers at compile time.
18
- * This marker is used to distinguish {@link DerivedValueParser} from regular
19
- * {@link ValueParser} instances.
20
- * @since 0.10.0
21
- */
22
- declare const derivedValueParserMarker: unique symbol;
23
- /**
24
- * A unique symbol used to store the dependency ID on value parsers.
25
- * @since 0.10.0
26
- */
27
- declare const dependencyId: unique symbol;
28
- /**
29
- * A unique symbol used to store multiple dependency IDs on derived parsers
30
- * that depend on multiple sources (created via {@link deriveFrom}).
31
- * @since 0.10.0
32
- */
33
- declare const dependencyIds: unique symbol;
34
- /**
35
- * A unique symbol used to store the default values function on derived parsers.
36
- * This is used during partial dependency resolution to fill in missing values.
37
- * @since 0.10.0
38
- */
39
- declare const defaultValues: unique symbol;
40
- /**
41
- * A unique symbol used to access the parseWithDependency method on derived parsers.
42
- * @since 0.10.0
43
- */
44
- declare const parseWithDependency: unique symbol;
45
- /**
46
- * A unique symbol used to access the suggestWithDependency method on derived parsers.
47
- * This method generates suggestions using the provided dependency values instead of defaults.
48
- * @since 0.10.0
49
- */
50
- declare const suggestWithDependency: unique symbol;
51
- /**
52
- * Combines two modes into a single mode.
53
- * If either mode is async, the result is async.
54
- * @template M1 The first mode.
55
- * @template M2 The second mode.
56
- * @since 0.10.0
57
- */
58
- type CombineMode<M1 extends Mode, M2 extends Mode> = M1 extends "async" ? "async" : M2 extends "async" ? "async" : "sync";
59
- /**
60
- * Options for creating a derived value parser.
61
- *
62
- * @template S The type of the source dependency value.
63
- * @template T The type of the derived parser value.
64
- * @template FM The mode of the factory's returned parser.
65
- * @since 0.10.0
66
- */
67
- interface DeriveOptions<S, T, FM extends Mode = Mode> {
68
- /**
69
- * The metavariable name for the derived parser. Used in help messages
70
- * to indicate what kind of value this parser expects.
71
- */
72
- readonly metavar: NonEmptyString;
73
- /**
74
- * Factory function that creates a {@link ValueParser} based on the
75
- * dependency source's value.
76
- *
77
- * @param sourceValue The value parsed from the dependency source.
78
- * @returns A {@link ValueParser} for the derived value.
79
- */
80
- readonly factory: (sourceValue: S) => ValueParser<NoInfer<FM>, T>;
81
- /**
82
- * Default value to use when the dependency source is not provided.
83
- * This allows the derived parser to work even when the dependency
84
- * is optional.
85
- *
86
- * @returns The default value for the dependency source.
87
- */
88
- readonly defaultValue: () => S;
89
- /**
90
- * The execution mode of the factory's returned parser. This tells the
91
- * runtime whether the factory returns a sync or async parser, avoiding
92
- * the need to call the factory during parser construction.
93
- *
94
- * @since 1.0.0
95
- */
96
- readonly mode: FM;
97
- }
98
- /**
99
- * Options for creating a derived value parser with a synchronous factory.
100
- *
101
- * @template S The type of the source dependency value.
102
- * @template T The type of the derived parser value.
103
- * @since 0.10.0
104
- */
105
- interface DeriveSyncOptions<S, T> {
106
- /**
107
- * The metavariable name for the derived parser.
108
- */
109
- readonly metavar: NonEmptyString;
110
- /**
111
- * Factory function that creates a synchronous {@link ValueParser}.
112
- */
113
- readonly factory: (sourceValue: S) => ValueParser<"sync", T>;
114
- /**
115
- * Default value to use when the dependency source is not provided.
116
- */
117
- readonly defaultValue: () => S;
118
- }
119
- /**
120
- * Options for creating a derived value parser with an asynchronous factory.
121
- *
122
- * @template S The type of the source dependency value.
123
- * @template T The type of the derived parser value.
124
- * @since 0.10.0
125
- */
126
- interface DeriveAsyncOptions<S, T> {
127
- /**
128
- * The metavariable name for the derived parser.
129
- */
130
- readonly metavar: NonEmptyString;
131
- /**
132
- * Factory function that creates an asynchronous {@link ValueParser}.
133
- */
134
- readonly factory: (sourceValue: S) => ValueParser<"async", T>;
135
- /**
136
- * Default value to use when the dependency source is not provided.
137
- */
138
- readonly defaultValue: () => S;
139
- }
140
- /**
141
- * Represents a dependency source that can be used to create derived parsers.
142
- *
143
- * A dependency source wraps a {@link ValueParser} and provides methods to
144
- * create derived parsers that depend on the parsed value. This enables
145
- * inter-option dependencies where one option's valid values depend on
146
- * another option's value.
147
- *
148
- * @template M The execution mode of the parser (`"sync"` or `"async"`).
149
- * @template T The type of value this dependency source produces.
150
- * @since 0.10.0
151
- */
152
- interface DependencySource<M extends Mode = "sync", T = unknown> extends ValueParser<M, T> {
153
- /**
154
- * Marker to identify this as a dependency source.
155
- * @internal
156
- */
157
- readonly [dependencySourceMarker]: true;
158
- /**
159
- * Unique identifier for this dependency source.
160
- * @internal
161
- */
162
- readonly [dependencyId]: symbol;
163
- /**
164
- * Creates a derived value parser whose behavior depends on this
165
- * dependency source's value.
166
- *
167
- * The derived parser uses a factory function to create parsers based on
168
- * the source value. The factory can return either a sync or async parser,
169
- * and the resulting derived parser's mode will be the combination of
170
- * the source mode and the factory's returned parser mode.
171
- *
172
- * @template U The type of value the derived parser produces.
173
- * @template FM The mode of the factory's returned parser.
174
- * @param options Configuration for the derived parser.
175
- * @returns A {@link DerivedValueParser} that depends on this source.
176
- * @throws {TypeError} If the `mode` field is missing or invalid.
177
- */
178
- derive<U, FM extends Mode = "sync">(options: DeriveOptions<T, U, FM>): DerivedValueParser<CombineMode<M, FM>, U, T>;
179
- /**
180
- * Creates a derived value parser with a synchronous factory.
181
- *
182
- * This is a convenience method that explicitly requires a sync factory,
183
- * making the type inference more predictable.
184
- *
185
- * @template U The type of value the derived parser produces.
186
- * @param options Configuration for the derived parser with sync factory.
187
- * @returns A {@link DerivedValueParser} that depends on this source.
188
- * @since 0.10.0
189
- */
190
- deriveSync<U>(options: DeriveSyncOptions<T, U>): DerivedValueParser<M, U, T>;
191
- /**
192
- * Creates a derived value parser with an asynchronous factory.
193
- *
194
- * This is a convenience method that explicitly requires an async factory,
195
- * making the type inference more predictable.
196
- *
197
- * @template U The type of value the derived parser produces.
198
- * @param options Configuration for the derived parser with async factory.
199
- * @returns A {@link DerivedValueParser} that depends on this source.
200
- * @since 0.10.0
201
- */
202
- deriveAsync<U>(options: DeriveAsyncOptions<T, U>): DerivedValueParser<"async", U, T>;
203
- }
204
- /**
205
- * Extracts the value type from a DependencySource.
206
- * @template D The DependencySource type.
207
- * @since 0.10.0
208
- */
209
- type DependencyValue<D> = D extends DependencySource<Mode, infer T> ? T : never;
210
- /**
211
- * Extracts the mode from a DependencySource.
212
- * @template D The DependencySource type.
213
- * @since 0.10.0
214
- */
215
- type DependencyMode<D> = D extends DependencySource<infer M, unknown> ? M : never;
216
- /**
217
- * Maps a tuple of DependencySources to a tuple of their value types.
218
- * @template T The tuple of DependencySource types.
219
- * @since 0.10.0
220
- */
221
- type DependencyValues<T extends readonly unknown[]> = { [K in keyof T]: T[K] extends DependencySource<Mode, infer V> ? V : never };
222
- /**
223
- * Combines modes from multiple dependency sources.
224
- * If any source is async, the result is async.
225
- * @template T The tuple of DependencySource types.
226
- * @since 0.10.0
227
- */
228
- type CombinedDependencyMode<T extends readonly unknown[]> = "async" extends { [K in keyof T]: T[K] extends DependencySource<infer M, unknown> ? M : never }[number] ? "async" : "sync";
229
- /**
230
- * Represents any dependency source, used in type constraints.
231
- * @since 0.10.0
232
- */
233
- type AnyDependencySource = DependencySource<Mode, any>;
234
- /**
235
- * Options for creating a derived value parser from multiple dependencies.
236
- *
237
- * @template Deps A tuple of DependencySource types.
238
- * @template T The type of the derived parser value.
239
- * @template FM The mode of the factory's returned parser.
240
- * @since 0.10.0
241
- */
242
- interface DeriveFromOptions<Deps extends readonly AnyDependencySource[], T, FM extends Mode = Mode> {
243
- /**
244
- * The metavariable name for the derived parser. Used in help messages
245
- * to indicate what kind of value this parser expects.
246
- */
247
- readonly metavar: NonEmptyString;
248
- /**
249
- * The dependency sources that this derived parser depends on.
250
- */
251
- readonly dependencies: Deps;
252
- /**
253
- * Factory function that creates a {@link ValueParser} based on the
254
- * dependency sources' values.
255
- *
256
- * @param values The values parsed from the dependency sources (in order).
257
- * @returns A {@link ValueParser} for the derived value.
258
- */
259
- readonly factory: (...values: DependencyValues<Deps>) => ValueParser<NoInfer<FM>, T>;
260
- /**
261
- * Default values to use when the dependency sources are not provided.
262
- * Must return a tuple with the same length and types as the dependencies.
263
- *
264
- * @returns A tuple of default values for each dependency source.
265
- */
266
- readonly defaultValues: () => DependencyValues<Deps>;
267
- /**
268
- * The execution mode of the factory's returned parser. This tells the
269
- * runtime whether the factory returns a sync or async parser, avoiding
270
- * the need to call the factory during parser construction.
271
- *
272
- * @since 1.0.0
273
- */
274
- readonly mode: FM;
275
- }
276
- /**
277
- * Options for creating a derived value parser from multiple dependencies
278
- * with a synchronous factory.
279
- *
280
- * @template Deps A tuple of DependencySource types.
281
- * @template T The type of the derived parser value.
282
- * @since 0.10.0
283
- */
284
- interface DeriveFromSyncOptions<Deps extends readonly AnyDependencySource[], T> {
285
- /**
286
- * The metavariable name for the derived parser.
287
- */
288
- readonly metavar: NonEmptyString;
289
- /**
290
- * The dependency sources that this derived parser depends on.
291
- */
292
- readonly dependencies: Deps;
293
- /**
294
- * Factory function that creates a synchronous {@link ValueParser}.
295
- */
296
- readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"sync", T>;
297
- /**
298
- * Default values to use when the dependency sources are not provided.
299
- */
300
- readonly defaultValues: () => DependencyValues<Deps>;
301
- }
302
- /**
303
- * Options for creating a derived value parser from multiple dependencies
304
- * with an asynchronous factory.
305
- *
306
- * @template Deps A tuple of DependencySource types.
307
- * @template T The type of the derived parser value.
308
- * @since 0.10.0
309
- */
310
- interface DeriveFromAsyncOptions<Deps extends readonly AnyDependencySource[], T> {
311
- /**
312
- * The metavariable name for the derived parser.
313
- */
314
- readonly metavar: NonEmptyString;
315
- /**
316
- * The dependency sources that this derived parser depends on.
317
- */
318
- readonly dependencies: Deps;
319
- /**
320
- * Factory function that creates an asynchronous {@link ValueParser}.
321
- */
322
- readonly factory: (...values: DependencyValues<Deps>) => ValueParser<"async", T>;
323
- /**
324
- * Default values to use when the dependency sources are not provided.
325
- */
326
- readonly defaultValues: () => DependencyValues<Deps>;
327
- }
328
- /**
329
- * A value parser that depends on another parser's value.
330
- *
331
- * A derived value parser cannot be nested (i.e., you cannot call
332
- * {@link DependencySource.derive} on a {@link DerivedValueParser}).
333
- *
334
- * @template M The execution mode of the parser (`"sync"` or `"async"`).
335
- * @template T The type of value this parser produces.
336
- * @template S The type of the source dependency value.
337
- * @since 0.10.0
338
- */
339
- interface DerivedValueParser<M extends Mode = "sync", T = unknown, S = unknown> extends ValueParser<M, T> {
340
- /**
341
- * Marker to identify this as a derived value parser.
342
- * @internal
343
- */
344
- readonly [derivedValueParserMarker]: true;
345
- /**
346
- * The unique identifier of the dependency source this parser depends on.
347
- * For parsers created with {@link deriveFrom} that have multiple dependencies,
348
- * this is set to the first dependency's ID for backwards compatibility.
349
- * @internal
350
- */
351
- readonly [dependencyId]: symbol;
352
- /**
353
- * The unique identifiers of all dependency sources this parser depends on.
354
- * Present only for parsers created with {@link deriveFrom} that have multiple
355
- * dependencies. If present, this takes precedence over {@link dependencyId}
356
- * during dependency resolution.
357
- * @internal
358
- */
359
- readonly [dependencyIds]?: readonly symbol[];
360
- /**
361
- * The default values function for this parser's dependencies.
362
- * Used during partial dependency resolution to fill in missing values.
363
- * @internal
364
- */
365
- readonly [defaultValues]?: () => readonly unknown[];
366
- /**
367
- * Parses the input using the actual dependency value instead of the default.
368
- * This method is used during dependency resolution in `complete()`.
369
- *
370
- * @param input The raw input string to parse.
371
- * @param dependencyValue The resolved dependency value.
372
- * @returns The parse result.
373
- * @internal
374
- */
375
- readonly [parseWithDependency]: (input: string, dependencyValue: S) => ValueParserResult<T> | Promise<ValueParserResult<T>>;
376
- /**
377
- * Generates suggestions using the provided dependency value instead of the default.
378
- * This method is used during shell completion when dependency sources have been parsed.
379
- *
380
- * @param prefix The input prefix to filter suggestions.
381
- * @param dependencyValue The resolved dependency value.
382
- * @returns An iterable of suggestions.
383
- * @internal
384
- */
385
- readonly [suggestWithDependency]?: (prefix: string, dependencyValue: S) => Iterable<Suggestion> | AsyncIterable<Suggestion>;
386
- }
387
- /**
388
- * Creates a dependency source from a {@link ValueParser}.
389
- *
390
- * A dependency source wraps an existing value parser and enables creating
391
- * derived parsers that depend on the parsed value. This is useful for
392
- * scenarios where one option's valid values depend on another option's value.
393
- *
394
- * @template M The execution mode of the value parser.
395
- * @template T The type of value the parser produces.
396
- * @param parser The value parser to wrap as a dependency source.
397
- * @returns A {@link DependencySource} that can be used to create
398
- * derived parsers.
399
- * @example
400
- * ```typescript
401
- * import { dependency } from "@optique/core/dependency";
402
- * import { string } from "@optique/core/valueparser";
403
- *
404
- * // Create a dependency source for a directory path
405
- * const cwdParser = dependency(string({ metavar: "DIR" }));
406
- *
407
- * // Create a derived parser that depends on the directory
408
- * const branchParser = cwdParser.derive({
409
- * metavar: "BRANCH",
410
- * mode: "sync",
411
- * factory: (dir) => gitBranch({ dir }),
412
- * defaultValue: () => process.cwd(),
413
- * });
414
- * ```
415
- * @since 0.10.0
416
- */
417
- declare function dependency<M extends Mode, T>(parser: ValueParser<M, T>): DependencySource<M, T>;
418
- /**
419
- * Checks if a value parser is a {@link DependencySource}.
420
- *
421
- * @param parser The value parser to check.
422
- * @returns `true` if the parser is a dependency source, `false` otherwise.
423
- * @since 0.10.0
424
- */
425
- declare function isDependencySource<M extends Mode, T>(parser: ValueParser<M, T>): parser is DependencySource<M, T>;
426
- /**
427
- * Checks if a value parser is a {@link DerivedValueParser}.
428
- *
429
- * @param parser The value parser to check.
430
- * @returns `true` if the parser is a derived value parser, `false` otherwise.
431
- * @since 0.10.0
432
- */
433
- declare function isDerivedValueParser<M extends Mode, T>(parser: ValueParser<M, T>): parser is DerivedValueParser<M, T, unknown>;
434
- /**
435
- * Creates a derived value parser from multiple dependency sources.
436
- *
437
- * This function allows creating a parser whose behavior depends on
438
- * multiple other parsers' values. This is useful for scenarios where
439
- * an option's valid values depend on a combination of other options.
440
- *
441
- * @template Deps A tuple of DependencySource types.
442
- * @template T The type of value the derived parser produces.
443
- * @param options Configuration for the derived parser.
444
- * @returns A {@link DerivedValueParser} that depends on the given sources.
445
- * @example
446
- * ```typescript
447
- * import { dependency, deriveFrom } from "@optique/core/dependency";
448
- * import { string, choice } from "@optique/core/valueparser";
449
- *
450
- * const dirParser = dependency(string({ metavar: "DIR" }));
451
- * const modeParser = dependency(choice(["dev", "prod"]));
452
- *
453
- * const configParser = deriveFrom({
454
- * metavar: "CONFIG",
455
- * mode: "sync",
456
- * dependencies: [dirParser, modeParser] as const,
457
- * factory: (dir, mode) =>
458
- * choice(mode === "dev"
459
- * ? [`${dir}/dev.json`, `${dir}/dev.yaml`]
460
- * : [`${dir}/prod.json`, `${dir}/prod.yaml`]),
461
- * defaultValues: () => ["/config", "dev"],
462
- * });
463
- * ```
464
- * @throws {TypeError} If the `mode` field is missing or invalid.
465
- * @since 0.10.0
466
- */
467
- 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>>;
468
- /**
469
- * Creates a derived value parser from multiple dependency sources
470
- * with a synchronous factory.
471
- *
472
- * This function allows creating a parser whose behavior depends on
473
- * multiple other parsers' values. The factory explicitly returns
474
- * a sync parser.
475
- *
476
- * @template Deps A tuple of DependencySource types.
477
- * @template T The type of value the derived parser produces.
478
- * @param options Configuration for the derived parser with sync factory.
479
- * @returns A {@link DerivedValueParser} that depends on the given sources.
480
- * @since 0.10.0
481
- */
482
- declare function deriveFromSync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromSyncOptions<Deps, T>): DerivedValueParser<CombinedDependencyMode<Deps>, T, DependencyValues<Deps>>;
483
- /**
484
- * Creates a derived value parser from multiple dependency sources
485
- * with an asynchronous factory.
486
- *
487
- * This function allows creating a parser whose behavior depends on
488
- * multiple other parsers' values. The factory explicitly returns
489
- * an async parser.
490
- *
491
- * @template Deps A tuple of DependencySource types.
492
- * @template T The type of value the derived parser produces.
493
- * @param options Configuration for the derived parser with async factory.
494
- * @returns A {@link DerivedValueParser} that depends on the given sources.
495
- * @since 0.10.0
496
- */
497
- declare function deriveFromAsync<Deps extends readonly AnyDependencySource[], T>(options: DeriveFromAsyncOptions<Deps, T>): DerivedValueParser<"async", T, DependencyValues<Deps>>;
498
- /**
499
- * A unique symbol used to identify deferred parse states.
500
- * @since 0.10.0
501
- */
502
- declare const deferredParseMarker: unique symbol;
503
- /**
504
- * Represents a deferred parse state for a DerivedValueParser.
505
- *
506
- * When a DerivedValueParser is used in an option or argument, the raw
507
- * input string is stored along with the parser reference. The actual
508
- * parsing is deferred until `complete()` time when all dependencies
509
- * have been resolved.
510
- *
511
- * @template T The type of value this parser will produce after resolution.
512
- * @since 0.10.0
513
- */
514
- interface DeferredParseState<T = unknown> {
515
- /**
516
- * Marker to identify this as a deferred parse state.
517
- */
518
- readonly [deferredParseMarker]: true;
519
- /**
520
- * The raw input string to be parsed.
521
- */
522
- readonly rawInput: string;
523
- /**
524
- * The DerivedValueParser that will parse the input.
525
- */
526
- readonly parser: DerivedValueParser<Mode, T, unknown>;
527
- /**
528
- * The dependency ID that this parser depends on (for single-dependency parsers).
529
- */
530
- readonly dependencyId: symbol;
531
- /**
532
- * The dependency IDs that this parser depends on (for multi-dependency parsers).
533
- * If present, this is used instead of `dependencyId`.
534
- */
535
- readonly dependencyIds?: readonly symbol[];
536
- /**
537
- * The default values to use for dependencies that are not provided.
538
- * For multi-dependency parsers, this is a tuple of default values in order.
539
- * For single-dependency parsers, this is the single default value.
540
- */
541
- readonly defaultValues?: readonly unknown[];
542
- /**
543
- * The preliminary parse result using the default dependency value.
544
- * This is used as a fallback if dependency resolution is not needed
545
- * or if the dependency was not provided.
546
- */
547
- readonly preliminaryResult: ValueParserResult<T>;
548
- }
549
- /**
550
- * Checks if a value is a {@link DeferredParseState}.
551
- *
552
- * @param value The value to check.
553
- * @returns `true` if the value is a deferred parse state, `false` otherwise.
554
- * @since 0.10.0
555
- */
556
- declare function isDeferredParseState<T>(value: unknown): value is DeferredParseState<T>;
557
- /**
558
- * Gets all dependency IDs from a derived parser.
559
- * If the parser was created with `deriveFrom` (multiple dependencies),
560
- * returns the array of dependency IDs. Otherwise, returns an array
561
- * containing the single dependency ID.
562
- *
563
- * @param parser The derived value parser to get dependency IDs from.
564
- * @returns An array of dependency ID symbols.
565
- * @internal
566
- * @since 0.10.0
567
- */
568
- declare function getDependencyIds<M extends Mode, T, S>(parser: DerivedValueParser<M, T, S>): readonly symbol[];
569
- /**
570
- * Gets the default values function from a derived parser, if present.
571
- * This function is available on parsers created with `deriveFrom` that
572
- * specify default values for their dependencies.
573
- *
574
- * @param parser The derived value parser to get the default values function from.
575
- * @returns The default values function, or undefined if not available.
576
- * @internal
577
- * @since 0.10.0
578
- */
579
- declare function getDefaultValuesFunction<M extends Mode, T, S>(parser: DerivedValueParser<M, T, S>): (() => readonly unknown[]) | undefined;
580
- /**
581
- * Creates a deferred parse state for a DerivedValueParser.
582
- *
583
- * @template T The type of value the parser will produce.
584
- * @template S The type of the source dependency value.
585
- * @param rawInput The raw input string to be parsed.
586
- * @param parser The DerivedValueParser that will parse the input.
587
- * @param preliminaryResult The parse result using default dependency value.
588
- * @returns A DeferredParseState object.
589
- * @since 0.10.0
590
- */
591
- declare function createDeferredParseState<T, S>(rawInput: string, parser: DerivedValueParser<Mode, T, S>, preliminaryResult: ValueParserResult<T>): DeferredParseState<T>;
592
- /**
593
- * A unique symbol used to identify dependency source parse states.
594
- * @since 0.10.0
595
- */
596
- declare const dependencySourceStateMarker: unique symbol;
597
- /**
598
- * Represents a parse state from a DependencySource.
599
- * This wraps the normal ValueParserResult with the dependency ID so that
600
- * it can be matched with DeferredParseState during resolution.
601
- *
602
- * @template T The type of value this state contains.
603
- * @since 0.10.0
604
- */
605
- interface DependencySourceState<T = unknown> {
606
- /**
607
- * Marker to identify this as a dependency source state.
608
- */
609
- readonly [dependencySourceStateMarker]: true;
610
- /**
611
- * The dependency ID of the source.
612
- */
613
- readonly [dependencyId]: symbol;
614
- /**
615
- * The underlying parse result.
616
- */
617
- readonly result: ValueParserResult<T>;
618
- }
619
- /**
620
- * Checks if a value is a {@link DependencySourceState}.
621
- *
622
- * @param value The value to check.
623
- * @returns `true` if the value is a dependency source state, `false` otherwise.
624
- * @since 0.10.0
625
- */
626
- declare function isDependencySourceState<T>(value: unknown): value is DependencySourceState<T>;
627
- /**
628
- * Creates a dependency source state from a parse result.
629
- *
630
- * @template T The type of value the state contains.
631
- * @param result The parse result.
632
- * @param depId The dependency ID.
633
- * @returns A DependencySourceState object.
634
- * @since 0.10.0
635
- */
636
- declare function createDependencySourceState<T>(result: ValueParserResult<T>, depId: symbol): DependencySourceState<T>;
637
- /**
638
- * A unique symbol used to identify pending dependency source states.
639
- * @since 0.10.0
640
- */
641
- declare const pendingDependencySourceStateMarker: unique symbol;
642
- /**
643
- * Represents a pending dependency source state.
644
- * This is used when a dependency source option was not provided, but its
645
- * dependency ID still needs to be tracked for later resolution with a
646
- * default value.
647
- *
648
- * @since 0.10.0
649
- */
650
- interface PendingDependencySourceState {
651
- /**
652
- * Marker to identify this as a pending dependency source state.
653
- */
654
- readonly [pendingDependencySourceStateMarker]: true;
655
- /**
656
- * The dependency ID of the source.
657
- */
658
- readonly [dependencyId]: symbol;
659
- }
660
- /**
661
- * Checks if a value is a {@link PendingDependencySourceState}.
662
- *
663
- * @param value The value to check.
664
- * @returns `true` if the value is a pending dependency source state.
665
- * @since 0.10.0
666
- */
667
- declare function isPendingDependencySourceState(value: unknown): value is PendingDependencySourceState;
668
- /**
669
- * Creates a pending dependency source state.
670
- *
671
- * @param depId The dependency ID.
672
- * @returns A PendingDependencySourceState object.
673
- * @since 0.10.0
674
- */
675
- declare function createPendingDependencySourceState(depId: symbol): PendingDependencySourceState;
676
- /**
677
- * A unique symbol used to identify parsers that wrap a dependency source.
678
- * This is used by withDefault to indicate it contains an inner parser
679
- * with a PendingDependencySourceState initialState.
680
- * @since 0.10.0
681
- */
682
- declare const wrappedDependencySourceMarker: unique symbol;
683
- /**
684
- * A unique symbol used to indicate that a wrapper transforms the dependency
685
- * source value. This is used by withDefault to determine whether its default
686
- * value should be registered as the dependency value.
687
- *
688
- * When a wrapper has this marker set to `true`, it means the wrapper transforms
689
- * the dependency source value (e.g., via map()), so the wrapper's output is NOT
690
- * a valid dependency source value.
691
- *
692
- * @since 0.10.0
693
- */
694
- declare const transformsDependencyValueMarker: unique symbol;
695
- /**
696
- * Checks if a parser transforms the dependency value (has transformsDependencyValueMarker).
697
- *
698
- * @param parser The parser to check.
699
- * @returns `true` if the parser transforms the dependency value.
700
- * @since 0.10.0
701
- */
702
- declare function transformsDependencyValue(parser: unknown): parser is {
703
- [transformsDependencyValueMarker]: true;
704
- };
705
- /**
706
- * Checks if a parser wraps a dependency source (has wrappedDependencySourceMarker).
707
- *
708
- * @param parser The parser to check.
709
- * @returns `true` if the parser wraps a dependency source.
710
- * @since 0.10.0
711
- */
712
- declare function isWrappedDependencySource(parser: unknown): parser is {
713
- [wrappedDependencySourceMarker]: PendingDependencySourceState;
714
- };
715
- /**
716
- * Represents a resolved dependency value stored during parsing.
717
- * @since 0.10.0
718
- */
719
- interface ResolvedDependency<T = unknown> {
720
- /**
721
- * The dependency ID.
722
- */
723
- readonly id: symbol;
724
- /**
725
- * The resolved value.
726
- */
727
- readonly value: T;
728
- }
729
- /**
730
- * A registry for storing resolved dependency values during parsing.
731
- * This is used to pass dependency values from DependencySource options
732
- * to DerivedValueParser options.
733
- * @since 0.10.0
734
- */
735
- declare class DependencyRegistry implements DependencyRegistryLike {
736
- private readonly values;
737
- /**
738
- * Registers a resolved dependency value.
739
- * @param id The dependency ID.
740
- * @param value The resolved value.
741
- */
742
- set<T>(id: symbol, value: T): void;
743
- /**
744
- * Gets a resolved dependency value.
745
- * @param id The dependency ID.
746
- * @returns The resolved value, or undefined if not found.
747
- */
748
- get<T>(id: symbol): T | undefined;
749
- /**
750
- * Checks if a dependency has been resolved.
751
- * @param id The dependency ID.
752
- * @returns `true` if the dependency has been resolved.
753
- */
754
- has(id: symbol): boolean;
755
- /**
756
- * Creates a copy of the registry.
757
- */
758
- clone(): DependencyRegistry;
759
- }
760
- /**
761
- * Error types for dependency resolution failures.
762
- * @since 0.10.0
763
- */
764
- type DependencyError = {
765
- /**
766
- * The dependency was used in multiple locations.
767
- */
768
- readonly kind: "duplicate";
769
- readonly dependencyId: symbol;
770
- readonly locations: readonly string[];
771
- } | {
772
- /**
773
- * A derived parser references a dependency that was not provided.
774
- */
775
- readonly kind: "unresolved";
776
- readonly dependencyId: symbol;
777
- readonly derivedParserMetavar: string;
778
- } | {
779
- /**
780
- * Circular dependency detected.
781
- */
782
- readonly kind: "circular";
783
- readonly cycle: readonly symbol[];
784
- };
785
- /**
786
- * Formats a {@link DependencyError} into a human-readable {@link Message}.
787
- *
788
- * @param error The dependency error to format.
789
- * @returns A Message describing the error.
790
- * @since 0.10.0
791
- */
792
- declare function formatDependencyError(error: DependencyError): Message;
793
- //#endregion
794
- export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker };
1
+ import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser } from "./internal/dependency.js";
2
+ export { type AnyDependencySource, type CombineMode, type CombinedDependencyMode, type DependencyMode, type DependencySource, type DependencyValue, type DependencyValues, type DeriveAsyncOptions, type DeriveFromAsyncOptions, type DeriveFromOptions, type DeriveFromSyncOptions, type DeriveOptions, type DeriveSyncOptions, type DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser };