@gunshi/combinators 1.0.0-rc.1 → 1.0.0-rc.10
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/README.md +0 -6
- package/lib/index.d.ts +123 -69
- package/lib/index.js +78 -24
- package/package.json +30 -36
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[![Version][npm-version-src]][npm-version-href]
|
|
4
4
|
[![InstallSize][install-size-src]][install-size-src]
|
|
5
|
-
[![JSR][jsr-src]][jsr-href]
|
|
6
5
|
|
|
7
6
|
> parser combinators for gunshi argument schema
|
|
8
7
|
|
|
@@ -32,9 +31,6 @@ pnpm add @gunshi/combinators
|
|
|
32
31
|
## yarn
|
|
33
32
|
yarn add @gunshi/combinators
|
|
34
33
|
|
|
35
|
-
## deno
|
|
36
|
-
deno add jsr:@gunshi/combinators
|
|
37
|
-
|
|
38
34
|
## bun
|
|
39
35
|
bun add @gunshi/combinators
|
|
40
36
|
```
|
|
@@ -100,6 +96,4 @@ About details, See the below official docs sections:
|
|
|
100
96
|
|
|
101
97
|
[npm-version-src]: https://img.shields.io/npm/v/@gunshi/combinators?style=flat
|
|
102
98
|
[npm-version-href]: https://npmjs.com/package/@gunshi/combinators@alpha
|
|
103
|
-
[jsr-src]: https://jsr.io/badges/@gunshi/combinators
|
|
104
|
-
[jsr-href]: https://jsr.io/@gunshi/combinators
|
|
105
99
|
[install-size-src]: https://pkg-size.dev/badge/install/23122
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.0/node_modules/args-tokens/lib/resolver.d.ts
|
|
2
|
-
//#region src/resolver.d.ts
|
|
3
1
|
/**
|
|
4
2
|
* An argument schema definition for command-line argument parsing.
|
|
5
3
|
*
|
|
6
4
|
* This schema is similar to the schema of Node.js `util.parseArgs` but with extended features:
|
|
7
|
-
* - Additional `required`, `description`, and `
|
|
5
|
+
* - Additional `required`, `description`, `hidden`, and `deprecated` properties
|
|
8
6
|
* - Extended `type` support: 'string', 'boolean', 'number', 'enum', 'positional', 'custom'
|
|
9
7
|
* - Simplified `default` property (single type, not union types)
|
|
10
8
|
*
|
|
@@ -134,6 +132,32 @@ interface ArgSchema {
|
|
|
134
132
|
* ```
|
|
135
133
|
*/
|
|
136
134
|
hidden?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Mark the argument as deprecated: `true`, or a text that tells what to use instead, such as
|
|
137
|
+
* `'Use --output.'`.
|
|
138
|
+
*
|
|
139
|
+
* Like {@link ArgSchema.hidden}, this is metadata for the tools that read the schema, such as a CLI
|
|
140
|
+
* framework that warns when a deprecated argument is given and leaves it out of the help. It does
|
|
141
|
+
* not affect parsing, validation, required checks, defaults, conflicts, or resolved values: a
|
|
142
|
+
* deprecated argument still works. `false`, like leaving it out, means that the argument is not
|
|
143
|
+
* deprecated.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* The old name of an option, kept while the scripts that use it move to the new one:
|
|
147
|
+
* ```ts
|
|
148
|
+
* {
|
|
149
|
+
* output: {
|
|
150
|
+
* type: 'string',
|
|
151
|
+
* description: 'Output format'
|
|
152
|
+
* },
|
|
153
|
+
* format: {
|
|
154
|
+
* type: 'string',
|
|
155
|
+
* deprecated: 'Use --output.'
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
deprecated?: boolean | string;
|
|
137
161
|
/**
|
|
138
162
|
* Marks the argument as required.
|
|
139
163
|
*
|
|
@@ -361,9 +385,9 @@ interface ArgSchema {
|
|
|
361
385
|
*/
|
|
362
386
|
toKebab?: true;
|
|
363
387
|
/**
|
|
364
|
-
* Names of other
|
|
388
|
+
* Names of other arguments that conflict with this argument.
|
|
365
389
|
*
|
|
366
|
-
* When this
|
|
390
|
+
* When this argument is used together with any of the conflicting arguments, the error is an
|
|
367
391
|
* `ArgResolveError` with type 'conflict' and the code `err:arg:conflict`
|
|
368
392
|
* ({@link ArgsValidationErrorKeys}.conflict). Its `values` has the `displayName` and `name` of
|
|
369
393
|
* the argument whose `conflicts` names the other one, and the `conflictDisplayName` and
|
|
@@ -373,9 +397,8 @@ interface ArgSchema {
|
|
|
373
397
|
*
|
|
374
398
|
* A positional argument can be on either side, such as `[file]` and `--stdin`. It conflicts when
|
|
375
399
|
* it is given, and it is shown by its name, such as `'file'` (in kebab-case with `toKebab`), as
|
|
376
|
-
* in its other errors. The message
|
|
377
|
-
* `
|
|
378
|
-
* `Optional argument '--stdin' conflicts with 'file'`.
|
|
400
|
+
* in its other errors. The message names the argument given as `name` first:
|
|
401
|
+
* `'file' conflicts with '--stdin'` or `'--stdin' conflicts with 'file'`.
|
|
379
402
|
*
|
|
380
403
|
* Conflicts only need to be defined on one side - if option A defines a conflict
|
|
381
404
|
* with option B, the conflict is automatically detected when both are used,
|
|
@@ -414,7 +437,7 @@ interface ArgSchema {
|
|
|
414
437
|
* }
|
|
415
438
|
* }
|
|
416
439
|
* // Usage: --summer --autumn reports an error
|
|
417
|
-
* // Error: "
|
|
440
|
+
* // Error: "'--summer' conflicts with '--autumn'"
|
|
418
441
|
* ```
|
|
419
442
|
*
|
|
420
443
|
* @example
|
|
@@ -454,7 +477,7 @@ interface ArgSchema {
|
|
|
454
477
|
* toKebab: true // Accessible as --autumn-season
|
|
455
478
|
* }
|
|
456
479
|
* }
|
|
457
|
-
* // Error: "
|
|
480
|
+
* // Error: "'--summer-season' conflicts with '--autumn-season'"
|
|
458
481
|
* ```
|
|
459
482
|
*/
|
|
460
483
|
conflicts?: string | string[];
|
|
@@ -558,9 +581,6 @@ interface ArgSchema {
|
|
|
558
581
|
interface Args {
|
|
559
582
|
[option: string]: ArgSchema;
|
|
560
583
|
}
|
|
561
|
-
//#endregion
|
|
562
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.0/node_modules/args-tokens/lib/combinators.d.ts
|
|
563
|
-
//#region src/combinators.d.ts
|
|
564
584
|
/**
|
|
565
585
|
* A combinator produced by combinator factory functions.
|
|
566
586
|
*
|
|
@@ -586,9 +606,10 @@ type Combinator<T> = {
|
|
|
586
606
|
type CombinatorSchema<T> = Omit<ArgSchema, 'parse'> & Combinator<T>;
|
|
587
607
|
/**
|
|
588
608
|
* How {@link short}, {@link describe}, {@link withDefault}, {@link required}, {@link multiple},
|
|
589
|
-
* {@link hidden}, {@link unrequired} and {@link positional} read a schema
|
|
590
|
-
* is typed `unknown`, and the `parse` of {@link ArgSchema}, which returns
|
|
591
|
-
* the result still fits any {@link CombinatorSchema}, as the schema typed
|
|
609
|
+
* {@link hidden}, {@link deprecated}, {@link unrequired} and {@link positional} read a schema
|
|
610
|
+
* typed as `any`: its value is typed `unknown`, and the `parse` of {@link ArgSchema}, which returns
|
|
611
|
+
* `any`, is kept, so that the result still fits any {@link CombinatorSchema}, as the schema typed
|
|
612
|
+
* as `any` does.
|
|
592
613
|
*
|
|
593
614
|
* For a schema typed by a type parameter, whether it is `any` is not known, so the result is built
|
|
594
615
|
* from the properties of the type parameter, which TypeScript reads through its constraint.
|
|
@@ -688,7 +709,7 @@ interface StringOptions extends BaseOptions {
|
|
|
688
709
|
* }
|
|
689
710
|
* ```
|
|
690
711
|
*/
|
|
691
|
-
declare function string<const R extends boolean>(opts: StringOptions & {
|
|
712
|
+
export declare function string<const R extends boolean>(opts: StringOptions & {
|
|
692
713
|
required: R;
|
|
693
714
|
}): WithRequiredOption<CombinatorSchema<string>, R>;
|
|
694
715
|
/**
|
|
@@ -708,7 +729,7 @@ declare function string<const R extends boolean>(opts: StringOptions & {
|
|
|
708
729
|
* }
|
|
709
730
|
* ```
|
|
710
731
|
*/
|
|
711
|
-
declare function string<const R extends boolean | undefined = boolean | undefined>(opts?: StringOptions & {
|
|
732
|
+
export declare function string<const R extends boolean | undefined = boolean | undefined>(opts?: StringOptions & {
|
|
712
733
|
required?: R;
|
|
713
734
|
}): WithUnrequiredOption<CombinatorSchema<string>, R>;
|
|
714
735
|
/**
|
|
@@ -724,7 +745,7 @@ declare function string<const R extends boolean | undefined = boolean | undefine
|
|
|
724
745
|
* }
|
|
725
746
|
* ```
|
|
726
747
|
*/
|
|
727
|
-
declare function string(opts?: StringOptions): CombinatorSchema<string>;
|
|
748
|
+
export declare function string(opts?: StringOptions): CombinatorSchema<string>;
|
|
728
749
|
/**
|
|
729
750
|
* Options for the {@link number} combinator.
|
|
730
751
|
*/
|
|
@@ -755,7 +776,7 @@ interface NumberOptions extends BaseOptions {
|
|
|
755
776
|
* }
|
|
756
777
|
* ```
|
|
757
778
|
*/
|
|
758
|
-
declare function number<const R extends boolean>(opts: NumberOptions & {
|
|
779
|
+
export declare function number<const R extends boolean>(opts: NumberOptions & {
|
|
759
780
|
required: R;
|
|
760
781
|
}): WithRequiredOption<CombinatorSchema<number>, R>;
|
|
761
782
|
/**
|
|
@@ -777,7 +798,7 @@ declare function number<const R extends boolean>(opts: NumberOptions & {
|
|
|
777
798
|
* }
|
|
778
799
|
* ```
|
|
779
800
|
*/
|
|
780
|
-
declare function number<const R extends boolean | undefined = boolean | undefined>(opts?: NumberOptions & {
|
|
801
|
+
export declare function number<const R extends boolean | undefined = boolean | undefined>(opts?: NumberOptions & {
|
|
781
802
|
required?: R;
|
|
782
803
|
}): WithUnrequiredOption<CombinatorSchema<number>, R>;
|
|
783
804
|
/**
|
|
@@ -795,7 +816,7 @@ declare function number<const R extends boolean | undefined = boolean | undefine
|
|
|
795
816
|
* }
|
|
796
817
|
* ```
|
|
797
818
|
*/
|
|
798
|
-
declare function number(opts?: NumberOptions): CombinatorSchema<number>;
|
|
819
|
+
export declare function number(opts?: NumberOptions): CombinatorSchema<number>;
|
|
799
820
|
/**
|
|
800
821
|
* Options for the {@link integer} combinator.
|
|
801
822
|
*/
|
|
@@ -826,7 +847,7 @@ interface IntegerOptions extends BaseOptions {
|
|
|
826
847
|
* }
|
|
827
848
|
* ```
|
|
828
849
|
*/
|
|
829
|
-
declare function integer<const R extends boolean>(opts: IntegerOptions & {
|
|
850
|
+
export declare function integer<const R extends boolean>(opts: IntegerOptions & {
|
|
830
851
|
required: R;
|
|
831
852
|
}): WithRequiredOption<CombinatorSchema<number>, R>;
|
|
832
853
|
/**
|
|
@@ -848,7 +869,7 @@ declare function integer<const R extends boolean>(opts: IntegerOptions & {
|
|
|
848
869
|
* }
|
|
849
870
|
* ```
|
|
850
871
|
*/
|
|
851
|
-
declare function integer<const R extends boolean | undefined = boolean | undefined>(opts?: IntegerOptions & {
|
|
872
|
+
export declare function integer<const R extends boolean | undefined = boolean | undefined>(opts?: IntegerOptions & {
|
|
852
873
|
required?: R;
|
|
853
874
|
}): WithUnrequiredOption<CombinatorSchema<number>, R>;
|
|
854
875
|
/**
|
|
@@ -866,7 +887,7 @@ declare function integer<const R extends boolean | undefined = boolean | undefin
|
|
|
866
887
|
* }
|
|
867
888
|
* ```
|
|
868
889
|
*/
|
|
869
|
-
declare function integer(opts?: IntegerOptions): CombinatorSchema<number>;
|
|
890
|
+
export declare function integer(opts?: IntegerOptions): CombinatorSchema<number>;
|
|
870
891
|
/**
|
|
871
892
|
* Options for the {@link float} combinator.
|
|
872
893
|
*/
|
|
@@ -897,7 +918,7 @@ interface FloatOptions extends BaseOptions {
|
|
|
897
918
|
* }
|
|
898
919
|
* ```
|
|
899
920
|
*/
|
|
900
|
-
declare function float<const R extends boolean>(opts: FloatOptions & {
|
|
921
|
+
export declare function float<const R extends boolean>(opts: FloatOptions & {
|
|
901
922
|
required: R;
|
|
902
923
|
}): WithRequiredOption<CombinatorSchema<number>, R>;
|
|
903
924
|
/**
|
|
@@ -919,7 +940,7 @@ declare function float<const R extends boolean>(opts: FloatOptions & {
|
|
|
919
940
|
* }
|
|
920
941
|
* ```
|
|
921
942
|
*/
|
|
922
|
-
declare function float<const R extends boolean | undefined = boolean | undefined>(opts?: FloatOptions & {
|
|
943
|
+
export declare function float<const R extends boolean | undefined = boolean | undefined>(opts?: FloatOptions & {
|
|
923
944
|
required?: R;
|
|
924
945
|
}): WithUnrequiredOption<CombinatorSchema<number>, R>;
|
|
925
946
|
/**
|
|
@@ -937,7 +958,7 @@ declare function float<const R extends boolean | undefined = boolean | undefined
|
|
|
937
958
|
* }
|
|
938
959
|
* ```
|
|
939
960
|
*/
|
|
940
|
-
declare function float(opts?: FloatOptions): CombinatorSchema<number>;
|
|
961
|
+
export declare function float(opts?: FloatOptions): CombinatorSchema<number>;
|
|
941
962
|
/**
|
|
942
963
|
* Options for the {@link boolean} combinator.
|
|
943
964
|
*/
|
|
@@ -967,7 +988,7 @@ interface BooleanOptions extends BaseOptions {
|
|
|
967
988
|
* // Usage: --color (true), --no-color (false)
|
|
968
989
|
* ```
|
|
969
990
|
*/
|
|
970
|
-
declare function boolean<const R extends boolean>(opts: BooleanOptions & {
|
|
991
|
+
export declare function boolean<const R extends boolean>(opts: BooleanOptions & {
|
|
971
992
|
required: R;
|
|
972
993
|
}): WithRequiredOption<CombinatorSchema<boolean>, R>;
|
|
973
994
|
/**
|
|
@@ -992,7 +1013,7 @@ declare function boolean<const R extends boolean>(opts: BooleanOptions & {
|
|
|
992
1013
|
* // Usage: --color (true), --no-color (false)
|
|
993
1014
|
* ```
|
|
994
1015
|
*/
|
|
995
|
-
declare function boolean<const R extends boolean | undefined = boolean | undefined>(opts?: BooleanOptions & {
|
|
1016
|
+
export declare function boolean<const R extends boolean | undefined = boolean | undefined>(opts?: BooleanOptions & {
|
|
996
1017
|
required?: R;
|
|
997
1018
|
}): WithUnrequiredOption<CombinatorSchema<boolean>, R>;
|
|
998
1019
|
/**
|
|
@@ -1013,7 +1034,7 @@ declare function boolean<const R extends boolean | undefined = boolean | undefin
|
|
|
1013
1034
|
* // Usage: --color (true), --no-color (false)
|
|
1014
1035
|
* ```
|
|
1015
1036
|
*/
|
|
1016
|
-
declare function boolean(opts?: BooleanOptions): CombinatorSchema<boolean>;
|
|
1037
|
+
export declare function boolean(opts?: BooleanOptions): CombinatorSchema<boolean>;
|
|
1017
1038
|
/**
|
|
1018
1039
|
* Positional argument schema type.
|
|
1019
1040
|
*/
|
|
@@ -1023,7 +1044,7 @@ type ArgSchemaPositionalType = {
|
|
|
1023
1044
|
/**
|
|
1024
1045
|
* The properties of a parser that {@link positional} keeps.
|
|
1025
1046
|
*/
|
|
1026
|
-
type PositionalParserKey = 'parse' | 'metavar' | 'description' | 'hidden' | 'required' | 'default' | 'multiple';
|
|
1047
|
+
type PositionalParserKey = 'parse' | 'metavar' | 'description' | 'hidden' | 'deprecated' | 'required' | 'default' | 'multiple';
|
|
1027
1048
|
/**
|
|
1028
1049
|
* The positional argument schema that {@link positional} builds from a parser: the properties it
|
|
1029
1050
|
* keeps, with their types, as `type: 'positional'`. A parser of type `any` is read as
|
|
@@ -1057,9 +1078,9 @@ type PositionalOf<S> = S extends unknown ? PositionalWithParser<S> : never;
|
|
|
1057
1078
|
*
|
|
1058
1079
|
* @typeParam T - The parser's resolved type.
|
|
1059
1080
|
* @typeParam S - The type of the parser, inferred from `parser`, whose `required`, `default`,
|
|
1060
|
-
* `multiple`, `description`, `hidden` and `metavar` the positional argument keeps.
|
|
1061
|
-
* arguments are given explicitly without `S`, `S` is `CombinatorSchema<T>`, and the type
|
|
1062
|
-
* result lacks them, although the returned object has them.
|
|
1081
|
+
* `multiple`, `description`, `hidden`, `deprecated` and `metavar` the positional argument keeps.
|
|
1082
|
+
* If type arguments are given explicitly without `S`, `S` is `CombinatorSchema<T>`, and the type
|
|
1083
|
+
* of the result lacks them, although the returned object has them.
|
|
1063
1084
|
*
|
|
1064
1085
|
* @param parser - The parser combinator schema.
|
|
1065
1086
|
* @returns A positional argument schema resolving to the parser's type.
|
|
@@ -1073,7 +1094,7 @@ type PositionalOf<S> = S extends unknown ? PositionalWithParser<S> : never;
|
|
|
1073
1094
|
* }
|
|
1074
1095
|
* ```
|
|
1075
1096
|
*/
|
|
1076
|
-
declare function positional<T, S extends CombinatorSchema<T> = CombinatorSchema<T>>(parser: S & CombinatorSchema<T>): PositionalOf<S>;
|
|
1097
|
+
export declare function positional<T, S extends CombinatorSchema<T> = CombinatorSchema<T>>(parser: S & CombinatorSchema<T>): PositionalOf<S>;
|
|
1077
1098
|
/**
|
|
1078
1099
|
* Create a positional argument schema from a union of combinator schemas of different types, such
|
|
1079
1100
|
* as `strict ? integer() : string()`.
|
|
@@ -1101,7 +1122,7 @@ declare function positional<T, S extends CombinatorSchema<T> = CombinatorSchema<
|
|
|
1101
1122
|
* }
|
|
1102
1123
|
* ```
|
|
1103
1124
|
*/
|
|
1104
|
-
declare function positional<S extends CombinatorSchema<unknown>>(parser: S): PositionalOf<S>;
|
|
1125
|
+
export declare function positional<S extends CombinatorSchema<unknown>>(parser: S): PositionalOf<S>;
|
|
1105
1126
|
/**
|
|
1106
1127
|
* Create a positional argument schema.
|
|
1107
1128
|
*
|
|
@@ -1130,7 +1151,7 @@ declare function positional<S extends CombinatorSchema<unknown>>(parser: S): Pos
|
|
|
1130
1151
|
* }
|
|
1131
1152
|
* ```
|
|
1132
1153
|
*/
|
|
1133
|
-
declare function positional<const R extends boolean>(parser: BaseOptions & {
|
|
1154
|
+
export declare function positional<const R extends boolean>(parser: BaseOptions & {
|
|
1134
1155
|
required: R;
|
|
1135
1156
|
}): WithRequiredOption<Omit<CombinatorSchema<string>, 'type'> & ArgSchemaPositionalType, R>;
|
|
1136
1157
|
/**
|
|
@@ -1163,7 +1184,7 @@ declare function positional<const R extends boolean>(parser: BaseOptions & {
|
|
|
1163
1184
|
* }
|
|
1164
1185
|
* ```
|
|
1165
1186
|
*/
|
|
1166
|
-
declare function positional<const R extends boolean | undefined = boolean | undefined>(parser?: BaseOptions & {
|
|
1187
|
+
export declare function positional<const R extends boolean | undefined = boolean | undefined>(parser?: BaseOptions & {
|
|
1167
1188
|
required?: R;
|
|
1168
1189
|
}): WithUnrequiredOption<Omit<CombinatorSchema<string>, 'type'> & ArgSchemaPositionalType, R>;
|
|
1169
1190
|
/**
|
|
@@ -1189,7 +1210,7 @@ declare function positional<const R extends boolean | undefined = boolean | unde
|
|
|
1189
1210
|
* }
|
|
1190
1211
|
* ```
|
|
1191
1212
|
*/
|
|
1192
|
-
declare function positional(parser?: BaseOptions): Omit<CombinatorSchema<string>, 'type'> & ArgSchemaPositionalType;
|
|
1213
|
+
export declare function positional(parser?: BaseOptions): Omit<CombinatorSchema<string>, 'type'> & ArgSchemaPositionalType;
|
|
1193
1214
|
/**
|
|
1194
1215
|
* Create an enum-like argument schema with literal type inference.
|
|
1195
1216
|
*
|
|
@@ -1210,7 +1231,7 @@ declare function positional(parser?: BaseOptions): Omit<CombinatorSchema<string>
|
|
|
1210
1231
|
* // typeof values.level === 'debug' | 'info' | 'warn' | 'error'
|
|
1211
1232
|
* ```
|
|
1212
1233
|
*/
|
|
1213
|
-
declare function choice<const T extends readonly string[], const R extends boolean>(values: T, opts: BaseOptions & {
|
|
1234
|
+
export declare function choice<const T extends readonly string[], const R extends boolean>(values: T, opts: BaseOptions & {
|
|
1214
1235
|
required: R;
|
|
1215
1236
|
}): WithRequiredOption<CombinatorSchema<T[number]>, R>;
|
|
1216
1237
|
/**
|
|
@@ -1235,7 +1256,7 @@ declare function choice<const T extends readonly string[], const R extends boole
|
|
|
1235
1256
|
* // typeof values.level === 'debug' | 'info' | 'warn' | 'error'
|
|
1236
1257
|
* ```
|
|
1237
1258
|
*/
|
|
1238
|
-
declare function choice<const T extends readonly string[], const R extends boolean | undefined = boolean | undefined>(values: T, opts?: BaseOptions & {
|
|
1259
|
+
export declare function choice<const T extends readonly string[], const R extends boolean | undefined = boolean | undefined>(values: T, opts?: BaseOptions & {
|
|
1239
1260
|
required?: R;
|
|
1240
1261
|
}): WithUnrequiredOption<CombinatorSchema<T[number]>, R>;
|
|
1241
1262
|
/**
|
|
@@ -1257,7 +1278,7 @@ declare function choice<const T extends readonly string[], const R extends boole
|
|
|
1257
1278
|
* // typeof values.level === 'debug' | 'info' | 'warn' | 'error'
|
|
1258
1279
|
* ```
|
|
1259
1280
|
*/
|
|
1260
|
-
declare function choice<const T extends readonly string[]>(values: T, opts?: BaseOptions): CombinatorSchema<T[number]>;
|
|
1281
|
+
export declare function choice<const T extends readonly string[]>(values: T, opts?: BaseOptions): CombinatorSchema<T[number]>;
|
|
1261
1282
|
/**
|
|
1262
1283
|
* Options for the {@link combinator} factory function.
|
|
1263
1284
|
*
|
|
@@ -1310,7 +1331,7 @@ interface CombinatorOptions<T> extends BaseOptions {
|
|
|
1310
1331
|
* })
|
|
1311
1332
|
* ```
|
|
1312
1333
|
*/
|
|
1313
|
-
declare function combinator<T, const R extends boolean>(config: CombinatorOptions<T> & {
|
|
1334
|
+
export declare function combinator<T, const R extends boolean>(config: CombinatorOptions<T> & {
|
|
1314
1335
|
required: R;
|
|
1315
1336
|
}): WithRequiredOption<CombinatorSchema<T>, R>;
|
|
1316
1337
|
/**
|
|
@@ -1344,7 +1365,7 @@ declare function combinator<T, const R extends boolean>(config: CombinatorOption
|
|
|
1344
1365
|
* })
|
|
1345
1366
|
* ```
|
|
1346
1367
|
*/
|
|
1347
|
-
declare function combinator<T, const R extends boolean | undefined = boolean | undefined>(config: CombinatorOptions<T> & {
|
|
1368
|
+
export declare function combinator<T, const R extends boolean | undefined = boolean | undefined>(config: CombinatorOptions<T> & {
|
|
1348
1369
|
required?: R;
|
|
1349
1370
|
}): WithUnrequiredOption<CombinatorSchema<T>, R>;
|
|
1350
1371
|
/**
|
|
@@ -1375,7 +1396,7 @@ declare function combinator<T, const R extends boolean | undefined = boolean | u
|
|
|
1375
1396
|
* })
|
|
1376
1397
|
* ```
|
|
1377
1398
|
*/
|
|
1378
|
-
declare function combinator<T>(config: CombinatorOptions<T>): CombinatorSchema<T>;
|
|
1399
|
+
export declare function combinator<T>(config: CombinatorOptions<T>): CombinatorSchema<T>;
|
|
1379
1400
|
/**
|
|
1380
1401
|
* Transform the output of a combinator schema.
|
|
1381
1402
|
*
|
|
@@ -1411,7 +1432,7 @@ declare function combinator<T>(config: CombinatorOptions<T>): CombinatorSchema<T
|
|
|
1411
1432
|
* }
|
|
1412
1433
|
* ```
|
|
1413
1434
|
*/
|
|
1414
|
-
declare function map<T, U, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S & CombinatorSchema<T>, transform: (value: T) => U): Modified<S, Combinator<U>>;
|
|
1435
|
+
export declare function map<T, U, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S & CombinatorSchema<T>, transform: (value: T) => U): Modified<S, Combinator<U>>;
|
|
1415
1436
|
/**
|
|
1416
1437
|
* Transform the output of a combinator schema, as the first overload does, for a schema that fits
|
|
1417
1438
|
* the first overload but that TypeScript does not match with it at first, such as
|
|
@@ -1442,7 +1463,7 @@ declare function map<T, U, S extends CombinatorSchema<T> = CombinatorSchema<T>>(
|
|
|
1442
1463
|
* }
|
|
1443
1464
|
* ```
|
|
1444
1465
|
*/
|
|
1445
|
-
declare function map<T, U, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S & Combinator<T>, transform: (value: T) => U): Modified<S, Combinator<U>>;
|
|
1466
|
+
export declare function map<T, U, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S & Combinator<T>, transform: (value: T) => U): Modified<S, Combinator<U>>;
|
|
1446
1467
|
/**
|
|
1447
1468
|
* Transform the output of a union of combinator schemas of different types, such as
|
|
1448
1469
|
* `strict ? integer() : string()`.
|
|
@@ -1475,7 +1496,7 @@ declare function map<T, U, S extends CombinatorSchema<T> = CombinatorSchema<T>>(
|
|
|
1475
1496
|
* }
|
|
1476
1497
|
* ```
|
|
1477
1498
|
*/
|
|
1478
|
-
declare function map<S extends CombinatorSchema<unknown>, U>(schema: S, transform: (value: ParsedType<S>) => U): Modified<S, Combinator<U>>;
|
|
1499
|
+
export declare function map<S extends CombinatorSchema<unknown>, U>(schema: S, transform: (value: ParsedType<S>) => U): Modified<S, Combinator<U>>;
|
|
1479
1500
|
/**
|
|
1480
1501
|
* Options for the {@link withDefault} combinator.
|
|
1481
1502
|
*/
|
|
@@ -1517,7 +1538,7 @@ type CombinatorWithDefault<T> = {
|
|
|
1517
1538
|
* }
|
|
1518
1539
|
* ```
|
|
1519
1540
|
*/
|
|
1520
|
-
declare function withDefault<T extends string | boolean | number, D extends T = T, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S & CombinatorSchema<T>, defaultValue: D): Modified<S, CombinatorWithDefault<T>>;
|
|
1541
|
+
export declare function withDefault<T extends string | boolean | number, D extends T = T, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S & CombinatorSchema<T>, defaultValue: D): Modified<S, CombinatorWithDefault<T>>;
|
|
1521
1542
|
/**
|
|
1522
1543
|
* Set a default value on a combinator schema, as the first overload does, for a schema that fits
|
|
1523
1544
|
* the first overload but that TypeScript does not match with it at first, such as
|
|
@@ -1545,7 +1566,7 @@ declare function withDefault<T extends string | boolean | number, D extends T =
|
|
|
1545
1566
|
* }
|
|
1546
1567
|
* ```
|
|
1547
1568
|
*/
|
|
1548
|
-
declare function withDefault<T extends string | boolean | number, D extends T = T, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S & Combinator<T>, defaultValue: D): Modified<S, CombinatorWithDefault<T>>;
|
|
1569
|
+
export declare function withDefault<T extends string | boolean | number, D extends T = T, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S & Combinator<T>, defaultValue: D): Modified<S, CombinatorWithDefault<T>>;
|
|
1549
1570
|
/**
|
|
1550
1571
|
* Set a default value on a union of combinator schemas of different types, such as
|
|
1551
1572
|
* `strict ? integer() : string()`.
|
|
@@ -1578,7 +1599,7 @@ declare function withDefault<T extends string | boolean | number, D extends T =
|
|
|
1578
1599
|
* // typeof values.timeout === number | string
|
|
1579
1600
|
* ```
|
|
1580
1601
|
*/
|
|
1581
|
-
declare function withDefault<S extends CombinatorSchema<string | boolean | number>>(schema: S, defaultValue: unknown extends ParsedType<S> ? never : ParsedType<S>): Modified<S, CombinatorWithDefault<ParsedType<S>> & Combinator<ParsedType<S>>>;
|
|
1602
|
+
export declare function withDefault<S extends CombinatorSchema<string | boolean | number>>(schema: S, defaultValue: unknown extends ParsedType<S> ? never : ParsedType<S>): Modified<S, CombinatorWithDefault<ParsedType<S>> & Combinator<ParsedType<S>>>;
|
|
1582
1603
|
/**
|
|
1583
1604
|
* Overlay the properties of `F` onto a combinator schema without dropping its other properties.
|
|
1584
1605
|
*
|
|
@@ -1614,8 +1635,9 @@ type Modified<S, F> = S extends unknown ? WithFlag<S, F> : never;
|
|
|
1614
1635
|
*
|
|
1615
1636
|
* It maps the properties of `S` itself, so that TypeScript still sees them when `S` is a type
|
|
1616
1637
|
* parameter with other modifiers on it, and it maps each schema of a union on its own.
|
|
1617
|
-
* For a type parameter, TypeScript does not take it for `Omit<S, K>`, so {@link hidden}
|
|
1618
|
-
* {@link unrequired}, whose results were typed `Omit<S, K>` with their flag,
|
|
1638
|
+
* For a type parameter, TypeScript does not take it for `Omit<S, K>`, so {@link hidden},
|
|
1639
|
+
* {@link deprecated} and {@link unrequired}, whose results were typed `Omit<S, K>` with their flag,
|
|
1640
|
+
* return that type too.
|
|
1619
1641
|
*/
|
|
1620
1642
|
type Without<S, K> = { [P in keyof S as P extends K ? never : NamedKey<P>]: S[P]; };
|
|
1621
1643
|
/**
|
|
@@ -1653,7 +1675,7 @@ type CombinatorMultiple = {
|
|
|
1653
1675
|
* // typeof values.tags === string[]
|
|
1654
1676
|
* ```
|
|
1655
1677
|
*/
|
|
1656
|
-
declare function multiple<S extends CombinatorSchema<unknown>>(schema: S): Modified<S, CombinatorMultiple>;
|
|
1678
|
+
export declare function multiple<S extends CombinatorSchema<unknown>>(schema: S): Modified<S, CombinatorMultiple>;
|
|
1657
1679
|
/**
|
|
1658
1680
|
* Options for the {@link required} combinator.
|
|
1659
1681
|
*/
|
|
@@ -1678,7 +1700,7 @@ type CombinatorRequired = {
|
|
|
1678
1700
|
* }
|
|
1679
1701
|
* ```
|
|
1680
1702
|
*/
|
|
1681
|
-
declare function required<S extends CombinatorSchema<unknown>>(schema: S): Modified<S, CombinatorRequired>;
|
|
1703
|
+
export declare function required<S extends CombinatorSchema<unknown>>(schema: S): Modified<S, CombinatorRequired>;
|
|
1682
1704
|
/**
|
|
1683
1705
|
* Options for the {@link short} combinator.
|
|
1684
1706
|
*/
|
|
@@ -1710,7 +1732,7 @@ type CombinatorShort<S extends string> = {
|
|
|
1710
1732
|
* // Usage: -v or --verbose
|
|
1711
1733
|
* ```
|
|
1712
1734
|
*/
|
|
1713
|
-
declare function short<T, A extends string, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S, alias: A): Modified<S, CombinatorShort<A>>;
|
|
1735
|
+
export declare function short<T, A extends string, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S, alias: A): Modified<S, CombinatorShort<A>>;
|
|
1714
1736
|
/**
|
|
1715
1737
|
* Options for the {@link describe} combinator.
|
|
1716
1738
|
*/
|
|
@@ -1741,7 +1763,7 @@ type CombinatorDescribe<D extends string> = {
|
|
|
1741
1763
|
* }
|
|
1742
1764
|
* ```
|
|
1743
1765
|
*/
|
|
1744
|
-
declare function describe<T, D extends string, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S, text: D): Modified<S, CombinatorDescribe<D>>;
|
|
1766
|
+
export declare function describe<T, D extends string, S extends CombinatorSchema<T> = CombinatorSchema<T>>(schema: S, text: D): Modified<S, CombinatorDescribe<D>>;
|
|
1745
1767
|
/**
|
|
1746
1768
|
* Options for the {@link hidden} combinator.
|
|
1747
1769
|
*/
|
|
@@ -1767,7 +1789,41 @@ type CombinatorHidden = {
|
|
|
1767
1789
|
* }
|
|
1768
1790
|
* ```
|
|
1769
1791
|
*/
|
|
1770
|
-
declare function hidden<T extends ArgSchema>(schema: T): T extends unknown ? WithFlag<T, CombinatorHidden> & Omit<T, 'hidden'> : never;
|
|
1792
|
+
export declare function hidden<T extends ArgSchema>(schema: T): T extends unknown ? WithFlag<T, CombinatorHidden> & Omit<T, 'hidden'> : never;
|
|
1793
|
+
/**
|
|
1794
|
+
* Options for the {@link deprecated} combinator: `true`, or the text that tells what to use
|
|
1795
|
+
* instead.
|
|
1796
|
+
*/
|
|
1797
|
+
type CombinatorDeprecated<M extends true | string> = {
|
|
1798
|
+
deprecated: M;
|
|
1799
|
+
};
|
|
1800
|
+
/**
|
|
1801
|
+
* Mark a combinator schema as deprecated: `true`, or the text that tells what to use instead.
|
|
1802
|
+
*
|
|
1803
|
+
* The original schema is not modified. Like {@link hidden}, this only marks metadata for the tools
|
|
1804
|
+
* that read the schema, such as a CLI framework that warns when the argument is given and leaves it
|
|
1805
|
+
* out of the help. It does not change parsing, validation, required checks, defaults, conflicts,
|
|
1806
|
+
* or resolved values. For a union of schemas, such as `strict ? integer() : string()`, each schema
|
|
1807
|
+
* gets `deprecated`.
|
|
1808
|
+
*
|
|
1809
|
+
* @typeParam T - The schema type.
|
|
1810
|
+
* @typeParam M - The type of `message`: `deprecated` is typed `string` with it, and `true` without
|
|
1811
|
+
* it.
|
|
1812
|
+
*
|
|
1813
|
+
* @param schema - The base combinator schema.
|
|
1814
|
+
* @param message - The text that tells what to use instead, such as `'Use --output.'`. Without it,
|
|
1815
|
+
* `deprecated` is `true`.
|
|
1816
|
+
* @returns A new schema with `deprecated` set to `message`, or to `true`.
|
|
1817
|
+
*
|
|
1818
|
+
* @example
|
|
1819
|
+
* ```ts
|
|
1820
|
+
* const args = {
|
|
1821
|
+
* output: string(),
|
|
1822
|
+
* format: deprecated(string(), 'Use --output.')
|
|
1823
|
+
* }
|
|
1824
|
+
* ```
|
|
1825
|
+
*/
|
|
1826
|
+
export declare function deprecated<T extends ArgSchema, M extends string | undefined = undefined>(schema: T, message?: M): T extends unknown ? WithFlag<T, CombinatorDeprecated<M extends string ? string : true>> & Omit<T, 'deprecated'> : never;
|
|
1771
1827
|
/**
|
|
1772
1828
|
* Options for the {@link unrequired} combinator.
|
|
1773
1829
|
*/
|
|
@@ -1796,7 +1852,7 @@ type CombinatorUnrequired = {
|
|
|
1796
1852
|
* }
|
|
1797
1853
|
* ```
|
|
1798
1854
|
*/
|
|
1799
|
-
declare function unrequired<T extends ArgSchema>(schema: T): T extends unknown ? WithFlag<T, CombinatorUnrequired> & Omit<T, 'required'> : never;
|
|
1855
|
+
export declare function unrequired<T extends ArgSchema>(schema: T): T extends unknown ? WithFlag<T, CombinatorUnrequired> & Omit<T, 'required'> : never;
|
|
1800
1856
|
/**
|
|
1801
1857
|
* Recursively merge a tuple of {@link Args} types.
|
|
1802
1858
|
* Later types override earlier ones on key conflicts.
|
|
@@ -1823,7 +1879,7 @@ type MergeArgs<T extends Args[]> = T extends [infer Only extends Args] ? Only :
|
|
|
1823
1879
|
* })
|
|
1824
1880
|
* ```
|
|
1825
1881
|
*/
|
|
1826
|
-
declare function args<T extends Args>(fields: T): T;
|
|
1882
|
+
export declare function args<T extends Args>(fields: T): T;
|
|
1827
1883
|
/**
|
|
1828
1884
|
* Compose multiple {@link Args} schemas into one.
|
|
1829
1885
|
*
|
|
@@ -1843,7 +1899,7 @@ declare function args<T extends Args>(fields: T): T;
|
|
|
1843
1899
|
* const schema = merge(common, network)
|
|
1844
1900
|
* ```
|
|
1845
1901
|
*/
|
|
1846
|
-
declare function merge<A extends Args, B extends Args>(a: A, b: B): Omit<A, keyof B> & B;
|
|
1902
|
+
export declare function merge<A extends Args, B extends Args>(a: A, b: B): Omit<A, keyof B> & B;
|
|
1847
1903
|
/**
|
|
1848
1904
|
* Compose multiple {@link Args} schemas into one.
|
|
1849
1905
|
*
|
|
@@ -1852,7 +1908,7 @@ declare function merge<A extends Args, B extends Args>(a: A, b: B): Omit<A, keyo
|
|
|
1852
1908
|
* @param c - Third schema.
|
|
1853
1909
|
* @returns A merged schema containing all fields.
|
|
1854
1910
|
*/
|
|
1855
|
-
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;
|
|
1911
|
+
export 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;
|
|
1856
1912
|
/**
|
|
1857
1913
|
* Compose multiple {@link Args} schemas into one.
|
|
1858
1914
|
*
|
|
@@ -1862,14 +1918,14 @@ declare function merge<A extends Args, B extends Args, C extends Args>(a: A, b:
|
|
|
1862
1918
|
* @param d - Fourth schema.
|
|
1863
1919
|
* @returns A merged schema containing all fields.
|
|
1864
1920
|
*/
|
|
1865
|
-
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]>;
|
|
1921
|
+
export 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]>;
|
|
1866
1922
|
/**
|
|
1867
1923
|
* Compose multiple {@link Args} schemas into one.
|
|
1868
1924
|
*
|
|
1869
1925
|
* @param schemas - The schemas to merge.
|
|
1870
1926
|
* @returns A merged schema containing all fields.
|
|
1871
1927
|
*/
|
|
1872
|
-
declare function merge<T extends Args[]>(...schemas: T): MergeArgs<T>;
|
|
1928
|
+
export declare function merge<T extends Args[]>(...schemas: T): MergeArgs<T>;
|
|
1873
1929
|
/**
|
|
1874
1930
|
* Extend a schema by overriding or adding fields.
|
|
1875
1931
|
*
|
|
@@ -1889,7 +1945,5 @@ declare function merge<T extends Args[]>(...schemas: T): MergeArgs<T>;
|
|
|
1889
1945
|
* const strict = extend(base, { port: required(integer({ min: 1, max: 65535 })) })
|
|
1890
1946
|
* ```
|
|
1891
1947
|
*/
|
|
1892
|
-
declare function extend<T extends Args, U extends Args>(base: T, overrides: U): Omit<T, keyof U> & U;
|
|
1893
|
-
|
|
1894
|
-
//#endregion
|
|
1895
|
-
export { type BaseOptions, type BooleanOptions, type Combinator, type CombinatorOptions, type CombinatorSchema, type FloatOptions, type IntegerOptions, type NumberOptions, type StringOptions, args, boolean, choice, combinator, describe, extend, float, hidden, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
|
1948
|
+
export declare function extend<T extends Args, U extends Args>(base: T, overrides: U): Omit<T, keyof U> & U;
|
|
1949
|
+
export type { BaseOptions, BooleanOptions, Combinator, CombinatorOptions, CombinatorSchema, FloatOptions, IntegerOptions, NumberOptions, StringOptions };
|
package/lib/index.js
CHANGED
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
"-".codePointAt(0);
|
|
10
10
|
"=".codePointAt(0);
|
|
11
|
-
|
|
12
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.0/node_modules/args-tokens/lib/utils.js
|
|
11
|
+
// ../../node_modules/.pnpm/args-tokens@1.3.0/node_modules/args-tokens/lib/utils.js
|
|
13
12
|
/**
|
|
14
13
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
15
14
|
* @license MIT
|
|
@@ -23,8 +22,7 @@
|
|
|
23
22
|
function formatChoices(choices) {
|
|
24
23
|
return choices.map((value) => JSON.stringify(value)).join(", ");
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.0/node_modules/args-tokens/lib/resolver-CAlgxe_R.js
|
|
25
|
+
// ../../node_modules/.pnpm/args-tokens@1.3.0/node_modules/args-tokens/lib/resolver-DWmHKGSL.js
|
|
28
26
|
/**
|
|
29
27
|
* Internal definitions shared by the modules of `args-tokens`.
|
|
30
28
|
*
|
|
@@ -60,9 +58,16 @@ const PURE_PARSE = Symbol.for("args-tokens.pureParse");
|
|
|
60
58
|
* Each code identifies a validation failure category and is also suitable as an
|
|
61
59
|
* i18n resource key for localized rendering.
|
|
62
60
|
*
|
|
63
|
-
*
|
|
61
|
+
* A value that breaks a constraint of the options of a combinator is reported with a code of its
|
|
62
|
+
* own: `tooSmall` and `tooLarge` for `min` and `max` of `number()`, `integer()` and `float()`,
|
|
63
|
+
* `tooShort` and `tooLong` for `minLength` and `maxLength` of `string()`, and `patternMismatch` for
|
|
64
|
+
* its `pattern`. What a `parse` function of your own throws is reported as `customParse`.
|
|
65
|
+
*
|
|
66
|
+
* {@link resolveArgs} and `parse()` do not report `unknownOption` or `unexpectedPositional`: a caller
|
|
67
|
+
* that knows what a command takes, such as a CLI framework, reports them. An option that is not in the
|
|
64
68
|
* schema takes the argument after it as its value, unless that argument is an option, and the value
|
|
65
|
-
* is dropped: with no `foo` in the schema, `--foo bar` gives no positional argument.
|
|
69
|
+
* is dropped: with no `foo` in the schema, `--foo bar` gives no positional argument. A positional
|
|
70
|
+
* argument that the schema does not take stays in `positionals`, as the other positional arguments do.
|
|
66
71
|
*/
|
|
67
72
|
const ArgsValidationErrorKeys = {
|
|
68
73
|
requiredOption: "err:arg:required-option",
|
|
@@ -74,7 +79,13 @@ const ArgsValidationErrorKeys = {
|
|
|
74
79
|
unexpectedValue: "err:arg:unexpected-value",
|
|
75
80
|
missingValue: "err:arg:missing-value",
|
|
76
81
|
conflict: "err:arg:conflict",
|
|
77
|
-
invalidDefault: "err:arg:invalid-default"
|
|
82
|
+
invalidDefault: "err:arg:invalid-default",
|
|
83
|
+
unexpectedPositional: "err:arg:unexpected-positional",
|
|
84
|
+
tooSmall: "err:arg:too-small",
|
|
85
|
+
tooLarge: "err:arg:too-large",
|
|
86
|
+
tooShort: "err:arg:too-short",
|
|
87
|
+
tooLong: "err:arg:too-long",
|
|
88
|
+
patternMismatch: "err:arg:pattern-mismatch"
|
|
78
89
|
};
|
|
79
90
|
/**
|
|
80
91
|
* Brand that marks {@link ArgsValidationError} instances.
|
|
@@ -126,8 +137,7 @@ var ArgsValidationError = class extends Error {
|
|
|
126
137
|
});
|
|
127
138
|
}
|
|
128
139
|
};
|
|
129
|
-
|
|
130
|
-
//#region ../../node_modules/.pnpm/args-tokens@1.0.0/node_modules/args-tokens/lib/combinators.js
|
|
140
|
+
// ../../node_modules/.pnpm/args-tokens@1.3.0/node_modules/args-tokens/lib/combinators.js
|
|
131
141
|
/**
|
|
132
142
|
* Parser combinator factory functions for composable argument schema construction.
|
|
133
143
|
*
|
|
@@ -186,6 +196,12 @@ function createInvalidTypeError(message, expected, actual) {
|
|
|
186
196
|
}
|
|
187
197
|
});
|
|
188
198
|
}
|
|
199
|
+
function createConstraintError(message, code, values) {
|
|
200
|
+
return new ArgsValidationError(message, {
|
|
201
|
+
code,
|
|
202
|
+
values
|
|
203
|
+
});
|
|
204
|
+
}
|
|
189
205
|
function createInvalidChoiceError(message, choices, actual) {
|
|
190
206
|
return new ArgsValidationError(message, {
|
|
191
207
|
code: ArgsValidationErrorKeys.invalidChoice,
|
|
@@ -220,9 +236,18 @@ function string(opts) {
|
|
|
220
236
|
...opts?.short != null ? { short: opts.short } : {},
|
|
221
237
|
...opts?.required != null ? { required: opts.required } : {},
|
|
222
238
|
parse(value) {
|
|
223
|
-
if (opts?.minLength != null && value.length < opts.minLength) throw
|
|
224
|
-
|
|
225
|
-
|
|
239
|
+
if (opts?.minLength != null && value.length < opts.minLength) throw createConstraintError(`String must be at least ${opts.minLength} characters`, ArgsValidationErrorKeys.tooShort, {
|
|
240
|
+
minLength: opts.minLength,
|
|
241
|
+
actual: value
|
|
242
|
+
});
|
|
243
|
+
if (opts?.maxLength != null && value.length > opts.maxLength) throw createConstraintError(`String must be at most ${opts.maxLength} characters`, ArgsValidationErrorKeys.tooLong, {
|
|
244
|
+
maxLength: opts.maxLength,
|
|
245
|
+
actual: value
|
|
246
|
+
});
|
|
247
|
+
if (opts?.pattern != null && !opts.pattern.test(value)) throw createConstraintError(`String must match pattern ${opts.pattern}`, ArgsValidationErrorKeys.patternMismatch, {
|
|
248
|
+
pattern: String(opts.pattern),
|
|
249
|
+
actual: value
|
|
250
|
+
});
|
|
226
251
|
return value;
|
|
227
252
|
}
|
|
228
253
|
};
|
|
@@ -241,8 +266,16 @@ function number(opts) {
|
|
|
241
266
|
parse(value) {
|
|
242
267
|
const n = Number(value);
|
|
243
268
|
if (value.trim() === "" || isNaN(n)) throw createInvalidTypeError(`Expected a number, got '${value}'`, "number", value);
|
|
244
|
-
if (opts?.min != null && n < opts.min) throw
|
|
245
|
-
|
|
269
|
+
if (opts?.min != null && n < opts.min) throw createConstraintError(`Number must be >= ${opts.min}, got ${n}`, ArgsValidationErrorKeys.tooSmall, {
|
|
270
|
+
expected: "number",
|
|
271
|
+
min: opts.min,
|
|
272
|
+
actual: value
|
|
273
|
+
});
|
|
274
|
+
if (opts?.max != null && n > opts.max) throw createConstraintError(`Number must be <= ${opts.max}, got ${n}`, ArgsValidationErrorKeys.tooLarge, {
|
|
275
|
+
expected: "number",
|
|
276
|
+
max: opts.max,
|
|
277
|
+
actual: value
|
|
278
|
+
});
|
|
246
279
|
return n;
|
|
247
280
|
}
|
|
248
281
|
});
|
|
@@ -260,8 +293,16 @@ function integer(opts) {
|
|
|
260
293
|
if (!/^-?\d+$/.test(value)) throw createInvalidTypeError(`Expected an integer, got '${value}'`, "integer", value);
|
|
261
294
|
const n = Number.parseInt(value, 10);
|
|
262
295
|
if (isNaN(n)) throw createInvalidTypeError(`Expected an integer, got '${value}'`, "integer", value);
|
|
263
|
-
if (opts?.min != null && n < opts.min) throw
|
|
264
|
-
|
|
296
|
+
if (opts?.min != null && n < opts.min) throw createConstraintError(`Integer must be >= ${opts.min}, got ${n}`, ArgsValidationErrorKeys.tooSmall, {
|
|
297
|
+
expected: "integer",
|
|
298
|
+
min: opts.min,
|
|
299
|
+
actual: value
|
|
300
|
+
});
|
|
301
|
+
if (opts?.max != null && n > opts.max) throw createConstraintError(`Integer must be <= ${opts.max}, got ${n}`, ArgsValidationErrorKeys.tooLarge, {
|
|
302
|
+
expected: "integer",
|
|
303
|
+
max: opts.max,
|
|
304
|
+
actual: value
|
|
305
|
+
});
|
|
265
306
|
return n;
|
|
266
307
|
}
|
|
267
308
|
});
|
|
@@ -280,8 +321,16 @@ function float(opts) {
|
|
|
280
321
|
if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(trimmed)) throw createInvalidTypeError(`Expected a finite float, got '${value}'`, "float", value);
|
|
281
322
|
const n = Number.parseFloat(trimmed);
|
|
282
323
|
if (isNaN(n) || !isFinite(n)) throw createInvalidTypeError(`Expected a finite float, got '${value}'`, "float", value);
|
|
283
|
-
if (opts?.min != null && n < opts.min) throw
|
|
284
|
-
|
|
324
|
+
if (opts?.min != null && n < opts.min) throw createConstraintError(`Float must be >= ${opts.min}, got ${n}`, ArgsValidationErrorKeys.tooSmall, {
|
|
325
|
+
expected: "float",
|
|
326
|
+
min: opts.min,
|
|
327
|
+
actual: value
|
|
328
|
+
});
|
|
329
|
+
if (opts?.max != null && n > opts.max) throw createConstraintError(`Float must be <= ${opts.max}, got ${n}`, ArgsValidationErrorKeys.tooLarge, {
|
|
330
|
+
expected: "float",
|
|
331
|
+
max: opts.max,
|
|
332
|
+
actual: value
|
|
333
|
+
});
|
|
285
334
|
return n;
|
|
286
335
|
}
|
|
287
336
|
});
|
|
@@ -309,6 +358,7 @@ function positional(parser) {
|
|
|
309
358
|
...parser.metavar != null ? { metavar: parser.metavar } : {},
|
|
310
359
|
...parser.description != null ? { description: parser.description } : {},
|
|
311
360
|
...parser.hidden != null ? { hidden: parser.hidden } : {},
|
|
361
|
+
...parser.deprecated != null ? { deprecated: parser.deprecated } : {},
|
|
312
362
|
...parser.required != null ? { required: parser.required } : {},
|
|
313
363
|
...parser.default != null ? { default: parser.default } : {},
|
|
314
364
|
...parser.multiple != null ? { multiple: parser.multiple } : {}
|
|
@@ -406,6 +456,13 @@ function hidden(schema) {
|
|
|
406
456
|
};
|
|
407
457
|
}
|
|
408
458
|
// @__NO_SIDE_EFFECTS__
|
|
459
|
+
function deprecated(schema, message) {
|
|
460
|
+
return {
|
|
461
|
+
...schema,
|
|
462
|
+
deprecated: message ?? true
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
// @__NO_SIDE_EFFECTS__
|
|
409
466
|
function unrequired(schema) {
|
|
410
467
|
return {
|
|
411
468
|
...schema,
|
|
@@ -467,17 +524,14 @@ function extend(base, overrides) {
|
|
|
467
524
|
for (const key of Object.keys(overrides)) result[key] = overrides[key];
|
|
468
525
|
return result;
|
|
469
526
|
}
|
|
470
|
-
|
|
471
|
-
//#region ../gunshi/src/combinators.ts
|
|
527
|
+
// ../gunshi/src/combinators.ts
|
|
472
528
|
/**
|
|
473
529
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
474
530
|
* @license MIT
|
|
475
531
|
*/
|
|
476
|
-
|
|
477
|
-
//#region src/index.ts
|
|
532
|
+
// src/index.ts
|
|
478
533
|
/**
|
|
479
534
|
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
480
535
|
* @license MIT
|
|
481
536
|
*/
|
|
482
|
-
|
|
483
|
-
export { args, boolean, choice, combinator, describe, extend, float, hidden, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
|
537
|
+
export { args, boolean, choice, combinator, deprecated, describe, extend, float, hidden, integer, map, merge, multiple, number, positional, required, short, string, unrequired, withDefault };
|
package/package.json
CHANGED
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/combinators",
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
3
4
|
"description": "parser combinators for gunshi argument schema",
|
|
4
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"combinators",
|
|
8
|
+
"gunshi",
|
|
9
|
+
"parser"
|
|
10
|
+
],
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/kazupon/gunshi/issues"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
5
15
|
"author": {
|
|
6
16
|
"name": "kazuya kawaguchi",
|
|
7
17
|
"email": "kawakazu80@gmail.com"
|
|
8
18
|
},
|
|
9
|
-
"license": "MIT",
|
|
10
|
-
"funding": "https://github.com/sponsors/kazupon",
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/kazupon/gunshi/issues"
|
|
13
|
-
},
|
|
14
19
|
"repository": {
|
|
15
20
|
"type": "git",
|
|
16
21
|
"url": "git+https://github.com/kazupon/gunshi.git",
|
|
17
22
|
"directory": "packages/combinators"
|
|
18
23
|
},
|
|
19
|
-
"
|
|
20
|
-
"gunshi",
|
|
21
|
-
"combinators",
|
|
22
|
-
"parser",
|
|
23
|
-
"cli"
|
|
24
|
-
],
|
|
25
|
-
"publishConfig": {
|
|
26
|
-
"access": "public"
|
|
27
|
-
},
|
|
28
|
-
"engines": {
|
|
29
|
-
"node": ">= 22"
|
|
30
|
-
},
|
|
31
|
-
"type": "module",
|
|
24
|
+
"funding": "https://github.com/sponsors/kazupon",
|
|
32
25
|
"files": [
|
|
33
26
|
"lib"
|
|
34
27
|
],
|
|
28
|
+
"type": "module",
|
|
35
29
|
"module": "lib/index.js",
|
|
30
|
+
"types": "lib/index.d.ts",
|
|
31
|
+
"typesVersions": {
|
|
32
|
+
"*": {
|
|
33
|
+
"*": [
|
|
34
|
+
"./lib/*",
|
|
35
|
+
"./*"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
36
39
|
"exports": {
|
|
37
40
|
".": {
|
|
38
41
|
"types": "./lib/index.d.ts",
|
|
@@ -42,26 +45,17 @@
|
|
|
42
45
|
},
|
|
43
46
|
"./package.json": "./package.json"
|
|
44
47
|
},
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
"*": {
|
|
48
|
-
"*": [
|
|
49
|
-
"./lib/*",
|
|
50
|
-
"./*"
|
|
51
|
-
]
|
|
52
|
-
}
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
53
50
|
},
|
|
54
51
|
"devDependencies": {
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
"tsdown": "0.22.14"
|
|
52
|
+
"gunshi": "1.0.0-rc.10",
|
|
53
|
+
"publint": "^0.3.20"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">= 22"
|
|
61
57
|
},
|
|
62
58
|
"scripts": {
|
|
63
|
-
"build": "
|
|
64
|
-
"lint:jsr": "jsr publish --dry-run --allow-dirty",
|
|
65
|
-
"typecheck:deno": "deno check --import-map=../../importmap.json ./src"
|
|
59
|
+
"build": "vp pack"
|
|
66
60
|
}
|
|
67
61
|
}
|