@gunshi/combinators 0.28.2
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/LICENSE +20 -0
- package/README.md +112 -0
- package/lib/index.d.ts +1073 -0
- package/lib/index.js +503 -0
- package/package.json +67 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,1073 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.24.1/node_modules/args-tokens/lib/resolver.d.ts
|
|
2
|
+
|
|
3
|
+
//#region src/resolver.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* An argument schema definition for command-line argument parsing.
|
|
6
|
+
*
|
|
7
|
+
* This schema is similar to the schema of Node.js `util.parseArgs` but with extended features:
|
|
8
|
+
* - Additional `required` and `description` properties
|
|
9
|
+
* - Extended `type` support: 'string', 'boolean', 'number', 'enum', 'positional', 'custom'
|
|
10
|
+
* - Simplified `default` property (single type, not union types)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* Basic string argument:
|
|
14
|
+
* ```ts
|
|
15
|
+
* const schema: ArgSchema = {
|
|
16
|
+
* type: 'string',
|
|
17
|
+
* description: 'Server hostname',
|
|
18
|
+
* default: 'localhost'
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* Required number argument with alias:
|
|
24
|
+
* ```ts
|
|
25
|
+
* const schema: ArgSchema = {
|
|
26
|
+
* type: 'number',
|
|
27
|
+
* short: 'p',
|
|
28
|
+
* description: 'Port number to listen on',
|
|
29
|
+
* required: true
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* Enum argument with choices:
|
|
35
|
+
* ```ts
|
|
36
|
+
* const schema: ArgSchema = {
|
|
37
|
+
* type: 'enum',
|
|
38
|
+
* choices: ['info', 'warn', 'error'],
|
|
39
|
+
* description: 'Logging level',
|
|
40
|
+
* default: 'info'
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
interface ArgSchema {
|
|
45
|
+
/**
|
|
46
|
+
* Type of the argument value.
|
|
47
|
+
*
|
|
48
|
+
* - `'string'`: Text value (default if not specified)
|
|
49
|
+
* - `'boolean'`: `true`/`false` flag (can be negatable with `--no-` prefix)
|
|
50
|
+
* - `'number'`: Numeric value (parsed as integer or float)
|
|
51
|
+
* - `'enum'`: One of predefined string values (requires `choices` property)
|
|
52
|
+
* - `'positional'`: Non-option argument by position
|
|
53
|
+
* - `'custom'`: Custom parsing with user-defined `parse` function
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* Different argument types:
|
|
57
|
+
* ```ts
|
|
58
|
+
* {
|
|
59
|
+
* name: { type: 'string' }, // --name value
|
|
60
|
+
* verbose: { type: 'boolean' }, // --verbose or --no-verbose
|
|
61
|
+
* port: { type: 'number' }, // --port 3000
|
|
62
|
+
* level: { type: 'enum', choices: ['debug', 'info'] },
|
|
63
|
+
* file: { type: 'positional' }, // first positional arg
|
|
64
|
+
* config: { type: 'custom', parse: JSON.parse }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
type: 'string' | 'boolean' | 'number' | 'enum' | 'positional' | 'custom';
|
|
69
|
+
/**
|
|
70
|
+
* Single character alias for the long option name.
|
|
71
|
+
*
|
|
72
|
+
* As example, allows users to use `-x` instead of `--extended-option`.
|
|
73
|
+
* Only valid for non-positional argument types.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* Short alias usage:
|
|
77
|
+
* ```ts
|
|
78
|
+
* {
|
|
79
|
+
* verbose: {
|
|
80
|
+
* type: 'boolean',
|
|
81
|
+
* short: 'v' // Enables both --verbose and -v
|
|
82
|
+
* },
|
|
83
|
+
* port: {
|
|
84
|
+
* type: 'number',
|
|
85
|
+
* short: 'p' // Enables both --port 3000 and -p 3000
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
short?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Human-readable description of the argument's purpose.
|
|
93
|
+
*
|
|
94
|
+
* Used for help text generation and documentation.
|
|
95
|
+
* Should be concise but descriptive enough to understand the argument's role.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* Descriptive help text:
|
|
99
|
+
* ```ts
|
|
100
|
+
* {
|
|
101
|
+
* config: {
|
|
102
|
+
* type: 'string',
|
|
103
|
+
* description: 'Path to configuration file'
|
|
104
|
+
* },
|
|
105
|
+
* timeout: {
|
|
106
|
+
* type: 'number',
|
|
107
|
+
* description: 'Request timeout in milliseconds'
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
description?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Marks the argument as required.
|
|
115
|
+
*
|
|
116
|
+
* When `true`, the argument must be provided by the user.
|
|
117
|
+
* If missing, an `ArgResolveError` with type 'required' will be thrown.
|
|
118
|
+
*
|
|
119
|
+
* Note: Only `true` is allowed (not `false`) to make intent explicit.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* Required arguments:
|
|
123
|
+
* ```ts
|
|
124
|
+
* {
|
|
125
|
+
* input: {
|
|
126
|
+
* type: 'string',
|
|
127
|
+
* required: true, // Must be provided: --input file.txt
|
|
128
|
+
* description: 'Input file path'
|
|
129
|
+
* },
|
|
130
|
+
* source: {
|
|
131
|
+
* type: 'positional',
|
|
132
|
+
* required: true // First positional argument must exist
|
|
133
|
+
* }
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
required?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Allows the argument to accept multiple values.
|
|
140
|
+
*
|
|
141
|
+
* When `true`, the resolved value becomes an array.
|
|
142
|
+
* For options: can be specified multiple times (--tag foo --tag bar)
|
|
143
|
+
* For positional: collects remaining positional arguments
|
|
144
|
+
*
|
|
145
|
+
* Note: Only `true` is allowed (not `false`) to make intent explicit.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* Multiple values:
|
|
149
|
+
* ```ts
|
|
150
|
+
* {
|
|
151
|
+
* tags: {
|
|
152
|
+
* type: 'string',
|
|
153
|
+
* multiple: true, // --tags foo --tags bar → ['foo', 'bar']
|
|
154
|
+
* description: 'Tags to apply'
|
|
155
|
+
* },
|
|
156
|
+
* files: {
|
|
157
|
+
* type: 'positional',
|
|
158
|
+
* multiple: true // Collects all remaining positional args
|
|
159
|
+
* }
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
multiple?: true;
|
|
164
|
+
/**
|
|
165
|
+
* Enables negation for boolean arguments using `--no-` prefix.
|
|
166
|
+
*
|
|
167
|
+
* When `true`, allows users to explicitly set the boolean to `false`
|
|
168
|
+
* using `--no-option-name`. When `false` or omitted, only positive
|
|
169
|
+
* form is available.
|
|
170
|
+
*
|
|
171
|
+
* Only applicable to `type: 'boolean'` arguments.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* Negatable boolean:
|
|
175
|
+
* ```ts
|
|
176
|
+
* {
|
|
177
|
+
* color: {
|
|
178
|
+
* type: 'boolean',
|
|
179
|
+
* negatable: true,
|
|
180
|
+
* default: true,
|
|
181
|
+
* description: 'Enable colorized output'
|
|
182
|
+
* }
|
|
183
|
+
* // Usage: --color (true), --no-color (false)
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
negatable?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Array of allowed string values for enum-type arguments.
|
|
190
|
+
*
|
|
191
|
+
* Required when `type: 'enum'`. The argument value must be one of these choices,
|
|
192
|
+
* otherwise an `ArgResolveError` with type 'type' will be thrown.
|
|
193
|
+
*
|
|
194
|
+
* Supports both mutable arrays and readonly arrays for type safety.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* Enum choices:
|
|
198
|
+
* ```ts
|
|
199
|
+
* {
|
|
200
|
+
* logLevel: {
|
|
201
|
+
* type: 'enum',
|
|
202
|
+
* choices: ['debug', 'info', 'warn', 'error'] as const,
|
|
203
|
+
* default: 'info',
|
|
204
|
+
* description: 'Logging verbosity level'
|
|
205
|
+
* },
|
|
206
|
+
* format: {
|
|
207
|
+
* type: 'enum',
|
|
208
|
+
* choices: ['json', 'yaml', 'toml'],
|
|
209
|
+
* description: 'Output format'
|
|
210
|
+
* }
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
choices?: string[] | readonly string[];
|
|
215
|
+
/**
|
|
216
|
+
* Default value used when the argument is not provided.
|
|
217
|
+
*
|
|
218
|
+
* The type must match the argument's `type` property:
|
|
219
|
+
* - `string` type: string default
|
|
220
|
+
* - `boolean` type: boolean default
|
|
221
|
+
* - `number` type: number default
|
|
222
|
+
* - `enum` type: must be one of the `choices` values
|
|
223
|
+
* - `positional`/`custom` type: any appropriate default
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* Default values by type:
|
|
227
|
+
* ```ts
|
|
228
|
+
* {
|
|
229
|
+
* host: {
|
|
230
|
+
* type: 'string',
|
|
231
|
+
* default: 'localhost' // string default
|
|
232
|
+
* },
|
|
233
|
+
* verbose: {
|
|
234
|
+
* type: 'boolean',
|
|
235
|
+
* default: false // boolean default
|
|
236
|
+
* },
|
|
237
|
+
* port: {
|
|
238
|
+
* type: 'number',
|
|
239
|
+
* default: 8080 // number default
|
|
240
|
+
* },
|
|
241
|
+
* level: {
|
|
242
|
+
* type: 'enum',
|
|
243
|
+
* choices: ['low', 'high'],
|
|
244
|
+
* default: 'low' // must be in choices
|
|
245
|
+
* }
|
|
246
|
+
* }
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
default?: string | boolean | number;
|
|
250
|
+
/**
|
|
251
|
+
* Converts the argument name from camelCase to kebab-case for CLI usage.
|
|
252
|
+
*
|
|
253
|
+
* When `true`, a property like `maxCount` becomes available as `--max-count`.
|
|
254
|
+
* This allows [CAC](https://github.com/cacjs/cac) user-friendly property names while maintaining CLI conventions.
|
|
255
|
+
*
|
|
256
|
+
* Can be overridden globally with `resolveArgs({ toKebab: true })`.
|
|
257
|
+
*
|
|
258
|
+
* Note: Only `true` is allowed (not `false`) to make intent explicit.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* Kebab-case conversion:
|
|
262
|
+
* ```ts
|
|
263
|
+
* {
|
|
264
|
+
* maxRetries: {
|
|
265
|
+
* type: 'number',
|
|
266
|
+
* toKebab: true, // Accessible as --max-retries
|
|
267
|
+
* description: 'Maximum retry attempts'
|
|
268
|
+
* },
|
|
269
|
+
* enableLogging: {
|
|
270
|
+
* type: 'boolean',
|
|
271
|
+
* toKebab: true // Accessible as --enable-logging
|
|
272
|
+
* }
|
|
273
|
+
* }
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
toKebab?: true;
|
|
277
|
+
/**
|
|
278
|
+
* Names of other options that conflict with this option.
|
|
279
|
+
*
|
|
280
|
+
* When this option is used together with any of the conflicting options,
|
|
281
|
+
* an `ArgResolveError` with type 'conflict' will be thrown.
|
|
282
|
+
*
|
|
283
|
+
* Conflicts only need to be defined on one side - if option A defines a conflict
|
|
284
|
+
* with option B, the conflict is automatically detected when both are used,
|
|
285
|
+
* regardless of whether B also defines a conflict with A.
|
|
286
|
+
*
|
|
287
|
+
* Supports both single option name or array of option names.
|
|
288
|
+
* Option names must match the property keys in the schema object exactly
|
|
289
|
+
* (no automatic conversion between camelCase and kebab-case).
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* Single conflict (bidirectional definition):
|
|
293
|
+
* ```ts
|
|
294
|
+
* {
|
|
295
|
+
* summer: {
|
|
296
|
+
* type: 'boolean',
|
|
297
|
+
* conflicts: 'autumn' // Cannot use --summer with --autumn
|
|
298
|
+
* },
|
|
299
|
+
* autumn: {
|
|
300
|
+
* type: 'boolean',
|
|
301
|
+
* conflicts: 'summer' // Can define on both sides for clarity
|
|
302
|
+
* }
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* Single conflict (one-way definition):
|
|
308
|
+
* ```ts
|
|
309
|
+
* {
|
|
310
|
+
* summer: {
|
|
311
|
+
* type: 'boolean',
|
|
312
|
+
* conflicts: 'autumn' // Only defined on summer side
|
|
313
|
+
* },
|
|
314
|
+
* autumn: {
|
|
315
|
+
* type: 'boolean'
|
|
316
|
+
* // No conflicts defined, but still cannot use with --summer
|
|
317
|
+
* }
|
|
318
|
+
* }
|
|
319
|
+
* // Usage: --summer --autumn will throw error
|
|
320
|
+
* // Error: "Optional argument '--summer' conflicts with '--autumn'"
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* Multiple conflicts:
|
|
325
|
+
* ```ts
|
|
326
|
+
* {
|
|
327
|
+
* port: {
|
|
328
|
+
* type: 'number',
|
|
329
|
+
* conflicts: ['socket', 'pipe'], // Cannot use with --socket or --pipe
|
|
330
|
+
* description: 'TCP port number'
|
|
331
|
+
* },
|
|
332
|
+
* socket: {
|
|
333
|
+
* type: 'string',
|
|
334
|
+
* conflicts: ['port', 'pipe'], // Cannot use with --port or --pipe
|
|
335
|
+
* description: 'Unix socket path'
|
|
336
|
+
* },
|
|
337
|
+
* pipe: {
|
|
338
|
+
* type: 'string',
|
|
339
|
+
* conflicts: ['port', 'socket'], // Cannot use with --port or --socket
|
|
340
|
+
* description: 'Named pipe path'
|
|
341
|
+
* }
|
|
342
|
+
* }
|
|
343
|
+
* // These three options are mutually exclusive
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* With kebab-case conversion:
|
|
348
|
+
* ```ts
|
|
349
|
+
* {
|
|
350
|
+
* summerSeason: {
|
|
351
|
+
* type: 'boolean',
|
|
352
|
+
* toKebab: true, // Accessible as --summer-season
|
|
353
|
+
* conflicts: 'autumnSeason' // Must use property key, not CLI name
|
|
354
|
+
* },
|
|
355
|
+
* autumnSeason: {
|
|
356
|
+
* type: 'boolean',
|
|
357
|
+
* toKebab: true // Accessible as --autumn-season
|
|
358
|
+
* }
|
|
359
|
+
* }
|
|
360
|
+
* // Error: "Optional argument '--summer-season' conflicts with '--autumn-season'"
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
conflicts?: string | string[];
|
|
364
|
+
/**
|
|
365
|
+
* Display name hint for help text generation.
|
|
366
|
+
*
|
|
367
|
+
* Provides a meaningful type hint for the argument value in help output.
|
|
368
|
+
* Particularly useful for `type: 'custom'` arguments where the type
|
|
369
|
+
* name would otherwise be unhelpful.
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* Metavar usage:
|
|
373
|
+
* ```ts
|
|
374
|
+
* {
|
|
375
|
+
* port: {
|
|
376
|
+
* type: 'custom',
|
|
377
|
+
* parse: (v: string) => parseInt(v, 10),
|
|
378
|
+
* metavar: 'integer',
|
|
379
|
+
* description: 'Port number (1-65535)'
|
|
380
|
+
* }
|
|
381
|
+
* }
|
|
382
|
+
* // Help output: --port <integer> Port number (1-65535)
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
metavar?: string;
|
|
386
|
+
/**
|
|
387
|
+
* Custom parsing function for `type: 'custom'` arguments.
|
|
388
|
+
*
|
|
389
|
+
* Required when `type: 'custom'`. Receives the raw string value and must
|
|
390
|
+
* return the parsed result. Should throw an Error (or subclass) if parsing fails.
|
|
391
|
+
*
|
|
392
|
+
* The function's return type becomes the resolved argument type.
|
|
393
|
+
*
|
|
394
|
+
* @param value - Raw string value from command line
|
|
395
|
+
* @returns Parsed value of any type
|
|
396
|
+
* @throws Error or subclass when value is invalid
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* Custom parsing functions:
|
|
400
|
+
* ```ts
|
|
401
|
+
* {
|
|
402
|
+
* config: {
|
|
403
|
+
* type: 'custom',
|
|
404
|
+
* parse: (value: string) => {
|
|
405
|
+
* try {
|
|
406
|
+
* return JSON.parse(value) // Parse JSON config
|
|
407
|
+
* } catch {
|
|
408
|
+
* throw new Error('Invalid JSON configuration')
|
|
409
|
+
* }
|
|
410
|
+
* },
|
|
411
|
+
* description: 'JSON configuration object'
|
|
412
|
+
* },
|
|
413
|
+
* date: {
|
|
414
|
+
* type: 'custom',
|
|
415
|
+
* parse: (value: string) => {
|
|
416
|
+
* const date = new Date(value)
|
|
417
|
+
* if (isNaN(date.getTime())) {
|
|
418
|
+
* throw new Error('Invalid date format')
|
|
419
|
+
* }
|
|
420
|
+
* return date
|
|
421
|
+
* }
|
|
422
|
+
* }
|
|
423
|
+
* }
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
parse?: (value: string) => any;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* An object that contains {@link ArgSchema | argument schema}.
|
|
430
|
+
*
|
|
431
|
+
* This type is used to define the structure and validation rules for command line arguments.
|
|
432
|
+
*/
|
|
433
|
+
interface Args {
|
|
434
|
+
[option: string]: ArgSchema;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* An object that contains the values of the arguments.
|
|
438
|
+
*
|
|
439
|
+
* @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
|
|
440
|
+
*/
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.24.1/node_modules/args-tokens/lib/combinators.d.ts
|
|
443
|
+
//#region src/combinators.d.ts
|
|
444
|
+
/**
|
|
445
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
446
|
+
* @license MIT
|
|
447
|
+
*/
|
|
448
|
+
/**
|
|
449
|
+
* A combinator produced by combinator factory functions.
|
|
450
|
+
*
|
|
451
|
+
* @typeParam T - The parsed value type.
|
|
452
|
+
*
|
|
453
|
+
* @experimental
|
|
454
|
+
*/
|
|
455
|
+
type Combinator<T> = {
|
|
456
|
+
/**
|
|
457
|
+
* The parse function that converts a string to the desired type.
|
|
458
|
+
*
|
|
459
|
+
* @param value - The input string value.
|
|
460
|
+
* @returns The parsed value of type T.
|
|
461
|
+
*/
|
|
462
|
+
parse: (value: string) => T;
|
|
463
|
+
};
|
|
464
|
+
/**
|
|
465
|
+
* A schema produced by combinator factory functions.
|
|
466
|
+
* Any {@link ArgSchema} with a parse function qualifies.
|
|
467
|
+
*
|
|
468
|
+
* @typeParam T - The parsed value type.
|
|
469
|
+
*
|
|
470
|
+
* @experimental
|
|
471
|
+
*/
|
|
472
|
+
type CombinatorSchema<T> = ArgSchema & Combinator<T>;
|
|
473
|
+
/**
|
|
474
|
+
* Common options shared by all base combinators.
|
|
475
|
+
*
|
|
476
|
+
* @experimental
|
|
477
|
+
*/
|
|
478
|
+
interface BaseOptions {
|
|
479
|
+
/**
|
|
480
|
+
* Human-readable description for help text generation.
|
|
481
|
+
*/
|
|
482
|
+
description?: string;
|
|
483
|
+
/**
|
|
484
|
+
* Single character short alias.
|
|
485
|
+
*/
|
|
486
|
+
short?: string;
|
|
487
|
+
/**
|
|
488
|
+
* Mark as required.
|
|
489
|
+
*/
|
|
490
|
+
required?: boolean;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Options for the {@link string} combinator.
|
|
494
|
+
*
|
|
495
|
+
* @experimental
|
|
496
|
+
*/
|
|
497
|
+
interface StringOptions extends BaseOptions {
|
|
498
|
+
/**
|
|
499
|
+
* Minimum string length.
|
|
500
|
+
*/
|
|
501
|
+
minLength?: number;
|
|
502
|
+
/**
|
|
503
|
+
* Maximum string length.
|
|
504
|
+
*/
|
|
505
|
+
maxLength?: number;
|
|
506
|
+
/**
|
|
507
|
+
* Regular expression pattern the value must match.
|
|
508
|
+
*/
|
|
509
|
+
pattern?: RegExp;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Create a string argument schema with optional validation.
|
|
513
|
+
*
|
|
514
|
+
* @param opts - Validation options.
|
|
515
|
+
* @returns A combinator schema that resolves to string.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```ts
|
|
519
|
+
* const args = {
|
|
520
|
+
* name: string({ minLength: 1, maxLength: 50 })
|
|
521
|
+
* }
|
|
522
|
+
* ```
|
|
523
|
+
*
|
|
524
|
+
* @experimental
|
|
525
|
+
*/
|
|
526
|
+
declare function string(opts?: StringOptions): CombinatorSchema<string>;
|
|
527
|
+
/**
|
|
528
|
+
* Options for the {@link number} combinator.
|
|
529
|
+
*
|
|
530
|
+
* @experimental
|
|
531
|
+
*/
|
|
532
|
+
interface NumberOptions extends BaseOptions {
|
|
533
|
+
/**
|
|
534
|
+
* Minimum value (inclusive).
|
|
535
|
+
*/
|
|
536
|
+
min?: number;
|
|
537
|
+
/**
|
|
538
|
+
* Maximum value (inclusive).
|
|
539
|
+
*/
|
|
540
|
+
max?: number;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Create a number argument schema with optional range validation.
|
|
544
|
+
*
|
|
545
|
+
* Accepts any numeric value (integer or float).
|
|
546
|
+
*
|
|
547
|
+
* @param opts - Range options.
|
|
548
|
+
* @returns A combinator schema that resolves to number.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* ```ts
|
|
552
|
+
* const args = {
|
|
553
|
+
* timeout: number({ min: 0, max: 30000 })
|
|
554
|
+
* }
|
|
555
|
+
* ```
|
|
556
|
+
*
|
|
557
|
+
* @experimental
|
|
558
|
+
*/
|
|
559
|
+
declare function number(opts?: NumberOptions): CombinatorSchema<number>;
|
|
560
|
+
/**
|
|
561
|
+
* Options for the {@link integer} combinator.
|
|
562
|
+
*
|
|
563
|
+
* @experimental
|
|
564
|
+
*/
|
|
565
|
+
interface IntegerOptions extends BaseOptions {
|
|
566
|
+
/**
|
|
567
|
+
* Minimum value (inclusive).
|
|
568
|
+
*/
|
|
569
|
+
min?: number;
|
|
570
|
+
/**
|
|
571
|
+
* Maximum value (inclusive).
|
|
572
|
+
*/
|
|
573
|
+
max?: number;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Create an integer argument schema with optional range validation.
|
|
577
|
+
*
|
|
578
|
+
* Only accepts integer values (no decimals).
|
|
579
|
+
*
|
|
580
|
+
* @param opts - Range options.
|
|
581
|
+
* @returns A combinator schema that resolves to number (integer).
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
* ```ts
|
|
585
|
+
* const args = {
|
|
586
|
+
* retries: integer({ min: 0, max: 10 })
|
|
587
|
+
* }
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* @experimental
|
|
591
|
+
*/
|
|
592
|
+
declare function integer(opts?: IntegerOptions): CombinatorSchema<number>;
|
|
593
|
+
/**
|
|
594
|
+
* Options for the {@link float} combinator.
|
|
595
|
+
*
|
|
596
|
+
* @experimental
|
|
597
|
+
*/
|
|
598
|
+
interface FloatOptions extends BaseOptions {
|
|
599
|
+
/**
|
|
600
|
+
* Minimum value (inclusive).
|
|
601
|
+
*/
|
|
602
|
+
min?: number;
|
|
603
|
+
/**
|
|
604
|
+
* Maximum value (inclusive).
|
|
605
|
+
*/
|
|
606
|
+
max?: number;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Create a floating-point argument schema with optional range validation.
|
|
610
|
+
*
|
|
611
|
+
* Rejects `NaN` and `Infinity` values.
|
|
612
|
+
*
|
|
613
|
+
* @param opts - Range options.
|
|
614
|
+
* @returns A combinator schema that resolves to number (float).
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```ts
|
|
618
|
+
* const args = {
|
|
619
|
+
* ratio: float({ min: 0, max: 1 })
|
|
620
|
+
* }
|
|
621
|
+
* ```
|
|
622
|
+
*
|
|
623
|
+
* @experimental
|
|
624
|
+
*/
|
|
625
|
+
declare function float(opts?: FloatOptions): CombinatorSchema<number>;
|
|
626
|
+
/**
|
|
627
|
+
* Options for the {@link boolean} combinator.
|
|
628
|
+
*
|
|
629
|
+
* @experimental
|
|
630
|
+
*/
|
|
631
|
+
interface BooleanOptions extends BaseOptions {
|
|
632
|
+
/**
|
|
633
|
+
* Enable negation with `--no-` prefix.
|
|
634
|
+
*/
|
|
635
|
+
negatable?: boolean;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Create a boolean argument schema.
|
|
639
|
+
*
|
|
640
|
+
* Boolean arguments are existence-based. The resolver passes `"true"` or `"false"`
|
|
641
|
+
* to the parse function based on the presence or negation of the flag.
|
|
642
|
+
*
|
|
643
|
+
* @param opts - Boolean options.
|
|
644
|
+
* @returns A combinator schema for boolean flags.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```ts
|
|
648
|
+
* const args = {
|
|
649
|
+
* color: boolean({ negatable: true })
|
|
650
|
+
* }
|
|
651
|
+
* // Usage: --color (true), --no-color (false)
|
|
652
|
+
* ```
|
|
653
|
+
*
|
|
654
|
+
* @experimental
|
|
655
|
+
*/
|
|
656
|
+
declare function boolean(opts?: BooleanOptions): CombinatorSchema<boolean>;
|
|
657
|
+
/**
|
|
658
|
+
* Positional argument schema type.
|
|
659
|
+
*/
|
|
660
|
+
type ArgSchemaPositionalType = {
|
|
661
|
+
type: 'positional';
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Create a positional argument schema.
|
|
665
|
+
*
|
|
666
|
+
* Without a parser, resolves to string.
|
|
667
|
+
* With a parser (e.g., `positional(integer())`), resolves to the parser's return type.
|
|
668
|
+
*
|
|
669
|
+
* @typeParam T - The parser's resolved type.
|
|
670
|
+
*
|
|
671
|
+
* @param parser - The parser combinator schema.
|
|
672
|
+
* @returns A positional argument schema resolving to the parser's type.
|
|
673
|
+
*
|
|
674
|
+
* @example
|
|
675
|
+
* ```ts
|
|
676
|
+
* const args = {
|
|
677
|
+
* command: positional(), // resolves to string
|
|
678
|
+
* port: positional(integer()), // resolves to number
|
|
679
|
+
* }
|
|
680
|
+
* ```
|
|
681
|
+
*
|
|
682
|
+
* @experimental
|
|
683
|
+
*/
|
|
684
|
+
declare function positional<T>(parser: CombinatorSchema<T>): CombinatorSchema<T> & ArgSchemaPositionalType;
|
|
685
|
+
/**
|
|
686
|
+
* Create a positional argument schema.
|
|
687
|
+
*
|
|
688
|
+
* Without a parser, resolves to string.
|
|
689
|
+
* With a parser (e.g., `positional(integer())`), resolves to the parser's return type.
|
|
690
|
+
*
|
|
691
|
+
* @param parser - Optional base options (description, short, required).
|
|
692
|
+
* @returns A positional argument schema resolving to string.
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```ts
|
|
696
|
+
* const args = {
|
|
697
|
+
* command: positional(), // resolves to string
|
|
698
|
+
* port: positional(integer()), // resolves to number
|
|
699
|
+
* }
|
|
700
|
+
* ```
|
|
701
|
+
*
|
|
702
|
+
* @experimental
|
|
703
|
+
*/
|
|
704
|
+
declare function positional(parser?: BaseOptions): ArgSchema & ArgSchemaPositionalType;
|
|
705
|
+
/**
|
|
706
|
+
* Create an enum-like argument schema with literal type inference.
|
|
707
|
+
*
|
|
708
|
+
* Uses `const T` generic to infer literal union types from the values array.
|
|
709
|
+
*
|
|
710
|
+
* @typeParam T - The readonly array of allowed string values.
|
|
711
|
+
*
|
|
712
|
+
* @param values - Allowed values.
|
|
713
|
+
* @param opts - Common options (description, short, required).
|
|
714
|
+
* @returns A combinator schema that resolves to a union of the allowed values.
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* ```ts
|
|
718
|
+
* const args = {
|
|
719
|
+
* level: choice(['debug', 'info', 'warn', 'error'] as const)
|
|
720
|
+
* }
|
|
721
|
+
* // typeof values.level === 'debug' | 'info' | 'warn' | 'error'
|
|
722
|
+
* ```
|
|
723
|
+
*
|
|
724
|
+
* @experimental
|
|
725
|
+
*/
|
|
726
|
+
declare function choice<const T extends readonly string[]>(values: T, opts?: BaseOptions): CombinatorSchema<T[number]>;
|
|
727
|
+
/**
|
|
728
|
+
* Options for the {@link combinator} factory function.
|
|
729
|
+
*
|
|
730
|
+
* @typeParam T - The parsed value type.
|
|
731
|
+
*
|
|
732
|
+
* @experimental
|
|
733
|
+
*/
|
|
734
|
+
interface CombinatorOptions<T> extends BaseOptions {
|
|
735
|
+
/**
|
|
736
|
+
* The parse function that converts a string to the desired type.
|
|
737
|
+
*
|
|
738
|
+
* @param value - The input string value.
|
|
739
|
+
* @returns The parsed value of type T.
|
|
740
|
+
*/
|
|
741
|
+
parse: (value: string) => T;
|
|
742
|
+
/**
|
|
743
|
+
* Display name hint for help text generation.
|
|
744
|
+
*
|
|
745
|
+
* @default 'custom'
|
|
746
|
+
*/
|
|
747
|
+
metavar?: string;
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Create a custom argument schema with a user-defined parse function.
|
|
751
|
+
*
|
|
752
|
+
* This is the most general custom combinator. Use it when none of the built-in
|
|
753
|
+
* base combinators ({@link string}, {@link number}, {@link integer},
|
|
754
|
+
* {@link float}, {@link boolean}, {@link choice}) fit your needs.
|
|
755
|
+
*
|
|
756
|
+
* The returned schema has `type: 'custom'`.
|
|
757
|
+
*
|
|
758
|
+
* @typeParam T - The parsed value type.
|
|
759
|
+
*
|
|
760
|
+
* @param config - Configuration with a parse function and optional metavar.
|
|
761
|
+
* @returns A combinator schema that resolves to the parse function's return type.
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* const date = combinator({
|
|
766
|
+
* parse: (value) => {
|
|
767
|
+
* const d = new Date(value)
|
|
768
|
+
* if (isNaN(d.getTime())) {
|
|
769
|
+
* throw new Error('Invalid date format')
|
|
770
|
+
* }
|
|
771
|
+
* return d
|
|
772
|
+
* },
|
|
773
|
+
* metavar: 'date'
|
|
774
|
+
* })
|
|
775
|
+
* ```
|
|
776
|
+
*
|
|
777
|
+
* @experimental
|
|
778
|
+
*/
|
|
779
|
+
declare function combinator<T>(config: CombinatorOptions<T>): CombinatorSchema<T>;
|
|
780
|
+
/**
|
|
781
|
+
* Transform the output of a combinator schema.
|
|
782
|
+
*
|
|
783
|
+
* Creates a new schema that applies `transform` to the result of `schema.parse`.
|
|
784
|
+
* The original schema is not modified.
|
|
785
|
+
*
|
|
786
|
+
* @typeParam T - The input schema's parsed type.
|
|
787
|
+
* @typeParam U - The transformed type.
|
|
788
|
+
*
|
|
789
|
+
* @param schema - The base combinator schema.
|
|
790
|
+
* @param transform - The transformation function.
|
|
791
|
+
* @returns A new combinator schema that resolves to the transformed type.
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* ```ts
|
|
795
|
+
* const args = {
|
|
796
|
+
* doubled: map(integer(), n => n * 2)
|
|
797
|
+
* }
|
|
798
|
+
* ```
|
|
799
|
+
*
|
|
800
|
+
* @experimental
|
|
801
|
+
*/
|
|
802
|
+
declare function map<T, U>(schema: CombinatorSchema<T>, transform: (value: T) => U): CombinatorSchema<U>;
|
|
803
|
+
/**
|
|
804
|
+
* Options for the {@link withDefault} combinator.
|
|
805
|
+
*/
|
|
806
|
+
type CombinatorWithDefault<T> = {
|
|
807
|
+
default: T;
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Set a default value on a combinator schema.
|
|
811
|
+
*
|
|
812
|
+
* The original schema is not modified.
|
|
813
|
+
*
|
|
814
|
+
* @typeParam T - The schema's parsed type.
|
|
815
|
+
*
|
|
816
|
+
* @param schema - The base combinator schema.
|
|
817
|
+
* @param defaultValue - The default value.
|
|
818
|
+
* @returns A new schema with the default value set.
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```ts
|
|
822
|
+
* const args = {
|
|
823
|
+
* port: withDefault(integer({ min: 1, max: 65535 }), 8080)
|
|
824
|
+
* }
|
|
825
|
+
* ```
|
|
826
|
+
*
|
|
827
|
+
* @experimental
|
|
828
|
+
*/
|
|
829
|
+
declare function withDefault<T extends string | boolean | number>(schema: CombinatorSchema<T>, defaultValue: T): CombinatorSchema<T> & CombinatorWithDefault<T>;
|
|
830
|
+
/**
|
|
831
|
+
* Options for the {@link multiple} combinator.
|
|
832
|
+
*/
|
|
833
|
+
type CombinatorMultiple = {
|
|
834
|
+
multiple: true;
|
|
835
|
+
};
|
|
836
|
+
/**
|
|
837
|
+
* Mark a combinator schema as accepting multiple values.
|
|
838
|
+
*
|
|
839
|
+
* The resolved value becomes an array. The original schema is not modified.
|
|
840
|
+
*
|
|
841
|
+
* @typeParam T - The schema's parsed type.
|
|
842
|
+
* @param schema - The base combinator schema.
|
|
843
|
+
* @returns A new schema with `multiple: true`.
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
846
|
+
* ```ts
|
|
847
|
+
* const args = {
|
|
848
|
+
* tags: multiple(string())
|
|
849
|
+
* }
|
|
850
|
+
* // typeof values.tags === string[]
|
|
851
|
+
* ```
|
|
852
|
+
*
|
|
853
|
+
* @experimental
|
|
854
|
+
*/
|
|
855
|
+
declare function multiple<T>(schema: CombinatorSchema<T>): CombinatorSchema<T> & CombinatorMultiple;
|
|
856
|
+
/**
|
|
857
|
+
* Options for the {@link required} combinator.
|
|
858
|
+
*/
|
|
859
|
+
type CombinatorRequired = {
|
|
860
|
+
required: true;
|
|
861
|
+
};
|
|
862
|
+
/**
|
|
863
|
+
* Mark a combinator schema as required.
|
|
864
|
+
*
|
|
865
|
+
* The original schema is not modified.
|
|
866
|
+
*
|
|
867
|
+
* @typeParam T - The schema's parsed type.
|
|
868
|
+
*
|
|
869
|
+
* @param schema - The base combinator schema.
|
|
870
|
+
* @returns A new schema with `required: true`.
|
|
871
|
+
*
|
|
872
|
+
* @example
|
|
873
|
+
* ```ts
|
|
874
|
+
* const args = {
|
|
875
|
+
* name: required(string())
|
|
876
|
+
* }
|
|
877
|
+
* ```
|
|
878
|
+
*
|
|
879
|
+
* @experimental
|
|
880
|
+
*/
|
|
881
|
+
declare function required<T>(schema: CombinatorSchema<T>): CombinatorSchema<T> & CombinatorRequired;
|
|
882
|
+
/**
|
|
883
|
+
* Options for the {@link short} combinator.
|
|
884
|
+
*/
|
|
885
|
+
type CombinatorShort<S extends string> = {
|
|
886
|
+
short: S;
|
|
887
|
+
};
|
|
888
|
+
/**
|
|
889
|
+
* Set a short alias on a combinator schema.
|
|
890
|
+
*
|
|
891
|
+
* The original schema is not modified.
|
|
892
|
+
*
|
|
893
|
+
* @typeParam T - The schema's parsed type.
|
|
894
|
+
* @typeParam S - The short alias string literal type.
|
|
895
|
+
*
|
|
896
|
+
* @param schema - The base combinator schema.
|
|
897
|
+
* @param alias - Single character short alias.
|
|
898
|
+
* @returns A new schema with the short alias set.
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```ts
|
|
902
|
+
* const args = {
|
|
903
|
+
* verbose: short(boolean(), 'v')
|
|
904
|
+
* }
|
|
905
|
+
* // Usage: -v or --verbose
|
|
906
|
+
* ```
|
|
907
|
+
*
|
|
908
|
+
* @experimental
|
|
909
|
+
*/
|
|
910
|
+
declare function short<T, S extends string>(schema: CombinatorSchema<T>, alias: S): CombinatorSchema<T> & CombinatorShort<S>;
|
|
911
|
+
/**
|
|
912
|
+
* Options for the {@link describe} combinator.
|
|
913
|
+
*/
|
|
914
|
+
type CombinatorDescribe<D extends string> = {
|
|
915
|
+
description: D;
|
|
916
|
+
};
|
|
917
|
+
/**
|
|
918
|
+
* Set a description on a combinator schema for help text generation.
|
|
919
|
+
*
|
|
920
|
+
* The original schema is not modified.
|
|
921
|
+
*
|
|
922
|
+
* @typeParam T - The schema's parsed type.
|
|
923
|
+
* @typeParam D - The description string literal type.
|
|
924
|
+
*
|
|
925
|
+
* @param schema - The base combinator schema.
|
|
926
|
+
* @param text - Human-readable description.
|
|
927
|
+
* @returns A new schema with the description set.
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* ```ts
|
|
931
|
+
* const args = {
|
|
932
|
+
* port: describe(integer(), 'Port number to listen on')
|
|
933
|
+
* }
|
|
934
|
+
* ```
|
|
935
|
+
*
|
|
936
|
+
* @experimental
|
|
937
|
+
*/
|
|
938
|
+
declare function describe<T, D extends string>(schema: CombinatorSchema<T>, text: D): CombinatorSchema<T> & CombinatorDescribe<D>;
|
|
939
|
+
/**
|
|
940
|
+
* Options for the {@link unrequired} combinator.
|
|
941
|
+
*/
|
|
942
|
+
type CombinatorUnrequired = {
|
|
943
|
+
required: false;
|
|
944
|
+
};
|
|
945
|
+
/**
|
|
946
|
+
* Mark a combinator schema as not required.
|
|
947
|
+
*
|
|
948
|
+
* Useful for overriding a base combinator that was created with `required: true`.
|
|
949
|
+
* The original schema is not modified.
|
|
950
|
+
*
|
|
951
|
+
* @typeParam T - The schema's parsed type.
|
|
952
|
+
*
|
|
953
|
+
* @param schema - The base combinator schema.
|
|
954
|
+
* @returns A new schema with `required: false`.
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* ```ts
|
|
958
|
+
* const args = {
|
|
959
|
+
* name: unrequired(string({ required: true }))
|
|
960
|
+
* }
|
|
961
|
+
* ```
|
|
962
|
+
*
|
|
963
|
+
* @experimental
|
|
964
|
+
*/
|
|
965
|
+
declare function unrequired<T>(schema: CombinatorSchema<T>): CombinatorSchema<T> & CombinatorUnrequired;
|
|
966
|
+
/**
|
|
967
|
+
* Recursively merge a tuple of {@link Args} types.
|
|
968
|
+
* Later types override earlier ones on key conflicts.
|
|
969
|
+
*
|
|
970
|
+
* @internal
|
|
971
|
+
*/
|
|
972
|
+
type MergeArgs<T extends Args[]> = T extends [infer Only extends Args] ? Only : T extends [infer First extends Args, ...infer Rest extends Args[]] ? Omit<First, keyof MergeArgs<Rest>> & MergeArgs<Rest> : never;
|
|
973
|
+
/**
|
|
974
|
+
* Type-safe schema factory.
|
|
975
|
+
*
|
|
976
|
+
* Returns the input unchanged at runtime, but provides type inference
|
|
977
|
+
* so that `satisfies Args` is not needed.
|
|
978
|
+
*
|
|
979
|
+
* @typeParam T - The exact schema type.
|
|
980
|
+
*
|
|
981
|
+
* @param fields - The argument schema object.
|
|
982
|
+
* @returns The same schema object with its type inferred.
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* ```ts
|
|
986
|
+
* const common = args({
|
|
987
|
+
* verbose: boolean(),
|
|
988
|
+
* help: short(boolean(), 'h')
|
|
989
|
+
* })
|
|
990
|
+
* ```
|
|
991
|
+
*
|
|
992
|
+
* @experimental
|
|
993
|
+
*/
|
|
994
|
+
declare function args<T extends Args>(fields: T): T;
|
|
995
|
+
/**
|
|
996
|
+
* Compose multiple {@link Args} schemas into one.
|
|
997
|
+
*
|
|
998
|
+
* On key conflicts the later schema wins (last-write-wins).
|
|
999
|
+
*
|
|
1000
|
+
* @typeParam A - First schema type.
|
|
1001
|
+
* @typeParam B - Second schema type.
|
|
1002
|
+
*
|
|
1003
|
+
* @param a - First schema.
|
|
1004
|
+
* @param b - Second schema.
|
|
1005
|
+
* @returns A merged schema containing all fields.
|
|
1006
|
+
*
|
|
1007
|
+
* @example
|
|
1008
|
+
* ```ts
|
|
1009
|
+
* const common = args({ verbose: boolean() })
|
|
1010
|
+
* const network = args({ host: required(string()), port: withDefault(integer(), 8080) })
|
|
1011
|
+
* const schema = merge(common, network)
|
|
1012
|
+
* ```
|
|
1013
|
+
*
|
|
1014
|
+
* @experimental
|
|
1015
|
+
*/
|
|
1016
|
+
declare function merge<A extends Args, B extends Args>(a: A, b: B): Omit<A, keyof B> & B;
|
|
1017
|
+
/**
|
|
1018
|
+
* Compose multiple {@link Args} schemas into one.
|
|
1019
|
+
*
|
|
1020
|
+
* @param a - First schema.
|
|
1021
|
+
* @param b - Second schema.
|
|
1022
|
+
* @param c - Third schema.
|
|
1023
|
+
* @returns A merged schema containing all fields.
|
|
1024
|
+
*
|
|
1025
|
+
* @experimental
|
|
1026
|
+
*/
|
|
1027
|
+
declare function merge<A extends Args, B extends Args, C extends Args>(a: A, b: B, c: C): Omit<Omit<A, keyof B | keyof C> & Omit<B, keyof C>, never> & C;
|
|
1028
|
+
/**
|
|
1029
|
+
* Compose multiple {@link Args} schemas into one.
|
|
1030
|
+
*
|
|
1031
|
+
* @param a - First schema.
|
|
1032
|
+
* @param b - Second schema.
|
|
1033
|
+
* @param c - Third schema.
|
|
1034
|
+
* @param d - Fourth schema.
|
|
1035
|
+
* @returns A merged schema containing all fields.
|
|
1036
|
+
*
|
|
1037
|
+
* @experimental
|
|
1038
|
+
*/
|
|
1039
|
+
declare function merge<A extends Args, B extends Args, C extends Args, D extends Args>(a: A, b: B, c: C, d: D): MergeArgs<[A, B, C, D]>;
|
|
1040
|
+
/**
|
|
1041
|
+
* Compose multiple {@link Args} schemas into one.
|
|
1042
|
+
*
|
|
1043
|
+
* @param schemas - The schemas to merge.
|
|
1044
|
+
* @returns A merged schema containing all fields.
|
|
1045
|
+
*
|
|
1046
|
+
* @experimental
|
|
1047
|
+
*/
|
|
1048
|
+
declare function merge<T extends Args[]>(...schemas: T): MergeArgs<T>;
|
|
1049
|
+
/**
|
|
1050
|
+
* Extend a schema by overriding or adding fields.
|
|
1051
|
+
*
|
|
1052
|
+
* Equivalent to `merge(base, overrides)` but communicates the intent of
|
|
1053
|
+
* intentional overrides rather than general composition.
|
|
1054
|
+
*
|
|
1055
|
+
* @typeParam T - Base schema type.
|
|
1056
|
+
* @typeParam U - Overrides schema type.
|
|
1057
|
+
*
|
|
1058
|
+
* @param base - The base schema to extend.
|
|
1059
|
+
* @param overrides - Fields to override or add.
|
|
1060
|
+
* @returns A new schema with overrides applied.
|
|
1061
|
+
*
|
|
1062
|
+
* @example
|
|
1063
|
+
* ```ts
|
|
1064
|
+
* const base = args({ port: withDefault(integer(), 8080) })
|
|
1065
|
+
* const strict = extend(base, { port: required(integer({ min: 1, max: 65535 })) })
|
|
1066
|
+
* ```
|
|
1067
|
+
*
|
|
1068
|
+
* @experimental
|
|
1069
|
+
*/
|
|
1070
|
+
declare function extend<T extends Args, U extends Args>(base: T, overrides: U): Omit<T, keyof U> & U;
|
|
1071
|
+
//#endregion
|
|
1072
|
+
//#endregion
|
|
1073
|
+
export { BaseOptions, BooleanOptions, Combinator, CombinatorOptions, CombinatorSchema, FloatOptions, IntegerOptions, NumberOptions, StringOptions, args, boolean, choice, combinator, describe, extend, float, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|