@gunshi/definition 0.27.4 → 0.27.6
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/lib/index.d.ts +40 -41
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.23.
|
|
1
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.23.1/node_modules/args-tokens/lib/parser.d.ts
|
|
2
2
|
//#region src/parser.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Entry point of argument parser.
|
|
@@ -55,9 +55,8 @@ interface ArgToken {
|
|
|
55
55
|
* Parser Options.
|
|
56
56
|
*/
|
|
57
57
|
//#endregion
|
|
58
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.23.
|
|
58
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.23.1/node_modules/args-tokens/lib/resolver.d.ts
|
|
59
59
|
//#region src/resolver.d.ts
|
|
60
|
-
|
|
61
60
|
/**
|
|
62
61
|
* An argument schema definition for command-line argument parsing.
|
|
63
62
|
*
|
|
@@ -484,8 +483,8 @@ type IsFunction<T> = T extends ((...args: any[]) => any) ? true : false;
|
|
|
484
483
|
*
|
|
485
484
|
* @internal
|
|
486
485
|
*/
|
|
487
|
-
type ExtractOptionValue<A
|
|
488
|
-
type ResolveOptionValue<A
|
|
486
|
+
type ExtractOptionValue<A extends ArgSchema> = A['type'] extends 'string' ? ResolveOptionValue<A, string> : A['type'] extends 'boolean' ? ResolveOptionValue<A, boolean> : A['type'] extends 'number' ? ResolveOptionValue<A, number> : A['type'] extends 'positional' ? ResolveOptionValue<A, string> : A['type'] extends 'enum' ? A['choices'] extends string[] | readonly string[] ? ResolveOptionValue<A, A['choices'][number]> : never : A['type'] extends 'custom' ? IsFunction<A['parse']> extends true ? ResolveOptionValue<A, ReturnType<NonNullable<A['parse']>>> : never : ResolveOptionValue<A, string | boolean | number>;
|
|
487
|
+
type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T[] : T;
|
|
489
488
|
/**
|
|
490
489
|
* Resolved argument values.
|
|
491
490
|
*
|
|
@@ -494,7 +493,7 @@ type ResolveOptionValue<A$1 extends ArgSchema, T> = A$1['multiple'] extends true
|
|
|
494
493
|
*
|
|
495
494
|
* @internal
|
|
496
495
|
*/
|
|
497
|
-
type ResolveArgValues<A
|
|
496
|
+
type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: V[Arg] } & FilterArgs<A, V, 'default'> & FilterArgs<A, V, 'required'> & FilterPositionalArgs<A, V> extends infer P ? { [K in keyof P]: P[K] } : never;
|
|
498
497
|
/**
|
|
499
498
|
* Filters the arguments based on their default values.
|
|
500
499
|
*
|
|
@@ -504,7 +503,7 @@ type ResolveArgValues<A$1 extends Args, V extends Record<keyof A$1, unknown>> =
|
|
|
504
503
|
*
|
|
505
504
|
* @internal
|
|
506
505
|
*/
|
|
507
|
-
type FilterArgs<A
|
|
506
|
+
type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends keyof ArgSchema> = { [Arg in keyof A as A[Arg][K] extends {} ? Arg : never]: V[Arg] };
|
|
508
507
|
/**
|
|
509
508
|
* Filters positional arguments from the argument schema.
|
|
510
509
|
*
|
|
@@ -513,7 +512,7 @@ type FilterArgs<A$1 extends Args, V extends Record<keyof A$1, unknown>, K$1 exte
|
|
|
513
512
|
*
|
|
514
513
|
* @internal
|
|
515
514
|
*/
|
|
516
|
-
type FilterPositionalArgs<A
|
|
515
|
+
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as A[Arg]['type'] extends 'positional' ? Arg : never]: V[Arg] };
|
|
517
516
|
/**
|
|
518
517
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
519
518
|
*/
|
|
@@ -526,7 +525,7 @@ type FilterPositionalArgs<A$1 extends Args, V extends Record<keyof A$1, unknown>
|
|
|
526
525
|
*
|
|
527
526
|
* @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
|
|
528
527
|
*/
|
|
529
|
-
type ArgExplicitlyProvided<A
|
|
528
|
+
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
530
529
|
/**
|
|
531
530
|
* Resolve command line arguments.
|
|
532
531
|
*
|
|
@@ -568,7 +567,7 @@ type ArgExplicitlyProvided<A$1 extends Args> = { [K in keyof A$1]: boolean };
|
|
|
568
567
|
*/
|
|
569
568
|
type ExtractedParams<G extends GunshiParamsConstraint, L extends Record<string, unknown> = {}> = {
|
|
570
569
|
args: ExtractArgs<G>;
|
|
571
|
-
extensions: ExtractExtensions<G> & L;
|
|
570
|
+
extensions: ExtractExtensions$1<G> & L;
|
|
572
571
|
};
|
|
573
572
|
/**
|
|
574
573
|
* Gunshi plugin context interface.
|
|
@@ -682,11 +681,11 @@ type PluginFunction<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readon
|
|
|
682
681
|
*
|
|
683
682
|
* @since v0.27.0
|
|
684
683
|
*/
|
|
685
|
-
type Plugin<E
|
|
684
|
+
type Plugin<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> = PluginFunction & {
|
|
686
685
|
id: string;
|
|
687
686
|
name?: string;
|
|
688
687
|
dependencies?: (PluginDependency | string)[];
|
|
689
|
-
extension?: CommandContextExtension<E
|
|
688
|
+
extension?: CommandContextExtension<E>;
|
|
690
689
|
};
|
|
691
690
|
//#endregion
|
|
692
691
|
//#region ../gunshi/src/types.d.ts
|
|
@@ -717,7 +716,7 @@ type ExtendContext = Record<string, unknown>;
|
|
|
717
716
|
*
|
|
718
717
|
* @since v0.27.0
|
|
719
718
|
*/
|
|
720
|
-
interface GunshiParams<P
|
|
719
|
+
interface GunshiParams<P extends {
|
|
721
720
|
args?: Args;
|
|
722
721
|
extensions?: ExtendContext;
|
|
723
722
|
} = {
|
|
@@ -727,13 +726,13 @@ interface GunshiParams<P$1 extends {
|
|
|
727
726
|
/**
|
|
728
727
|
* Command argument definitions.
|
|
729
728
|
*/
|
|
730
|
-
args: P
|
|
729
|
+
args: P extends {
|
|
731
730
|
args: infer A extends Args;
|
|
732
731
|
} ? A : Args;
|
|
733
732
|
/**
|
|
734
733
|
* Command context extensions.
|
|
735
734
|
*/
|
|
736
|
-
extensions: P
|
|
735
|
+
extensions: P extends {
|
|
737
736
|
extensions: infer E extends ExtendContext;
|
|
738
737
|
} ? E : {};
|
|
739
738
|
}
|
|
@@ -778,7 +777,7 @@ type ExtractArgExplicitlyProvided<G> = ArgExplicitlyProvided<ExtractArgs<G>>;
|
|
|
778
777
|
*
|
|
779
778
|
* @internal
|
|
780
779
|
*/
|
|
781
|
-
type ExtractExtensions<G> = G extends GunshiParams<any> ? G['extensions'] : G extends {
|
|
780
|
+
type ExtractExtensions$1<G> = G extends GunshiParams<any> ? G['extensions'] : G extends {
|
|
782
781
|
extensions: infer E;
|
|
783
782
|
} ? E : {};
|
|
784
783
|
/**
|
|
@@ -1077,7 +1076,7 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1077
1076
|
*
|
|
1078
1077
|
* @since v0.27.0
|
|
1079
1078
|
*/
|
|
1080
|
-
extensions: keyof ExtractExtensions<G> extends never ? any : ExtractExtensions<G>;
|
|
1079
|
+
extensions: keyof ExtractExtensions$1<G> extends never ? any : ExtractExtensions$1<G>;
|
|
1081
1080
|
/**
|
|
1082
1081
|
* Validation error from argument parsing.
|
|
1083
1082
|
* This will be set if argument validation fails during CLI execution.
|
|
@@ -1099,7 +1098,7 @@ type CommandContextCore<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1099
1098
|
*
|
|
1100
1099
|
* @since v0.27.0
|
|
1101
1100
|
*/
|
|
1102
|
-
interface CommandContextExtension<E
|
|
1101
|
+
interface CommandContextExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
1103
1102
|
/**
|
|
1104
1103
|
* Plugin identifier
|
|
1105
1104
|
*/
|
|
@@ -1107,7 +1106,7 @@ interface CommandContextExtension<E$1 extends GunshiParams['extensions'] = Defau
|
|
|
1107
1106
|
/**
|
|
1108
1107
|
* Plugin extension factory
|
|
1109
1108
|
*/
|
|
1110
|
-
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E
|
|
1109
|
+
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E>;
|
|
1111
1110
|
/**
|
|
1112
1111
|
* Plugin extension factory after hook
|
|
1113
1112
|
*/
|
|
@@ -1310,7 +1309,7 @@ type CommandLoader<G extends GunshiParamsConstraint = DefaultGunshiParams> = ()
|
|
|
1310
1309
|
*
|
|
1311
1310
|
* @internal
|
|
1312
1311
|
*/
|
|
1313
|
-
type ExtractExtensions
|
|
1312
|
+
type ExtractExtensions<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never };
|
|
1314
1313
|
/**
|
|
1315
1314
|
* Parameters of {@link createCommandContext}
|
|
1316
1315
|
*/
|
|
@@ -1318,7 +1317,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1318
1317
|
args: Args;
|
|
1319
1318
|
} | {
|
|
1320
1319
|
extensions: ExtendContext;
|
|
1321
|
-
}, V extends ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E
|
|
1320
|
+
}, V extends ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E extends Record<string, CommandContextExtension> = Record<string, CommandContextExtension>> {
|
|
1322
1321
|
/**
|
|
1323
1322
|
* An arguments of target command
|
|
1324
1323
|
*/
|
|
@@ -1362,7 +1361,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1362
1361
|
/**
|
|
1363
1362
|
* Plugin extensions to apply as the command context extension.
|
|
1364
1363
|
*/
|
|
1365
|
-
extensions?: E
|
|
1364
|
+
extensions?: E;
|
|
1366
1365
|
/**
|
|
1367
1366
|
* A command options, which is spicialized from `cli` function
|
|
1368
1367
|
*/
|
|
@@ -1378,7 +1377,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1378
1377
|
* @param param - A {@link CommandContextParams | parameters} to create a command context.
|
|
1379
1378
|
* @returns A {@link CommandContext | command context}, which is readonly.
|
|
1380
1379
|
*/
|
|
1381
|
-
declare function createCommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams, V extends ArgValues<ExtractArgs<G>> = ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E
|
|
1380
|
+
declare function createCommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams, V extends ArgValues<ExtractArgs<G>> = ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E extends Record<string, CommandContextExtension> = {}>({
|
|
1382
1381
|
args,
|
|
1383
1382
|
explicit,
|
|
1384
1383
|
values,
|
|
@@ -1392,9 +1391,9 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
|
|
|
1392
1391
|
callMode,
|
|
1393
1392
|
omitted,
|
|
1394
1393
|
validationError
|
|
1395
|
-
}: CommandContextParams<G, V, C, E
|
|
1394
|
+
}: CommandContextParams<G, V, C, E>): Promise<{} extends ExtractExtensions<E> ? Readonly<CommandContext<G>> : Readonly<CommandContext<GunshiParams<{
|
|
1396
1395
|
args: ExtractArgs<G>;
|
|
1397
|
-
extensions: ExtractExtensions
|
|
1396
|
+
extensions: ExtractExtensions<E>;
|
|
1398
1397
|
}>>>>;
|
|
1399
1398
|
//#endregion
|
|
1400
1399
|
//#region ../gunshi/src/definition.d.ts
|
|
@@ -1440,9 +1439,9 @@ type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
1440
1439
|
* @param definition - A {@link Command | command} definition
|
|
1441
1440
|
* @returns A defined {@link Command | command}
|
|
1442
1441
|
*/
|
|
1443
|
-
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A
|
|
1444
|
-
args: A
|
|
1445
|
-
extensions: ExtractExtensions<G>;
|
|
1442
|
+
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends InferCommandProps<G> = InferCommandProps<G>>(definition: C & Command<{
|
|
1443
|
+
args: A;
|
|
1444
|
+
extensions: ExtractExtensions$1<G>;
|
|
1446
1445
|
}>): CommandDefinitionResult<G, C>;
|
|
1447
1446
|
/**
|
|
1448
1447
|
* Return type for defineWithTypes
|
|
@@ -1451,14 +1450,14 @@ declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams,
|
|
|
1451
1450
|
*
|
|
1452
1451
|
* @internal
|
|
1453
1452
|
*/
|
|
1454
|
-
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A
|
|
1455
|
-
args: A
|
|
1453
|
+
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A extends DefaultArgs = DefaultArgs, C extends Partial<Command<{
|
|
1454
|
+
args: A;
|
|
1456
1455
|
extensions: DefaultExtensions;
|
|
1457
1456
|
}>> = {}>(definition: C & Command<{
|
|
1458
|
-
args: A
|
|
1457
|
+
args: A;
|
|
1459
1458
|
extensions: DefaultExtensions;
|
|
1460
1459
|
}>) => CommandDefinitionResult<{
|
|
1461
|
-
args: A
|
|
1460
|
+
args: A;
|
|
1462
1461
|
extensions: DefaultExtensions;
|
|
1463
1462
|
}, C>;
|
|
1464
1463
|
/**
|
|
@@ -1490,7 +1489,7 @@ type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs
|
|
|
1490
1489
|
*
|
|
1491
1490
|
* @since v0.27.0
|
|
1492
1491
|
*/
|
|
1493
|
-
declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWithTypesReturn<ExtractExtensions<G>, ExtractArgs<G>>;
|
|
1492
|
+
declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWithTypesReturn<ExtractExtensions$1<G>, ExtractArgs<G>>;
|
|
1494
1493
|
/**
|
|
1495
1494
|
* Define a {@link LazyCommand | lazy command}.
|
|
1496
1495
|
*
|
|
@@ -1505,11 +1504,11 @@ declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWith
|
|
|
1505
1504
|
* @param loader - A {@link CommandLoader | command loader}
|
|
1506
1505
|
* @returns A {@link LazyCommand | lazy command} with loader
|
|
1507
1506
|
*/
|
|
1508
|
-
declare function lazy<A
|
|
1509
|
-
args: A
|
|
1507
|
+
declare function lazy<A extends Args>(loader: CommandLoader<{
|
|
1508
|
+
args: A;
|
|
1510
1509
|
extensions: {};
|
|
1511
1510
|
}>): LazyCommand<{
|
|
1512
|
-
args: A
|
|
1511
|
+
args: A;
|
|
1513
1512
|
extensions: {};
|
|
1514
1513
|
}, {}>;
|
|
1515
1514
|
/**
|
|
@@ -1547,17 +1546,17 @@ declare function lazy<A$1 extends Args>(loader: CommandLoader<{
|
|
|
1547
1546
|
* @param definition - An optional {@link Command | command} definition
|
|
1548
1547
|
* @returns A {@link LazyCommand | lazy command} that can be executed later
|
|
1549
1548
|
*/
|
|
1550
|
-
declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A
|
|
1551
|
-
args: A
|
|
1549
|
+
declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends ExtractArgs<G> = ExtractArgs<G>, D extends Partial<Command<{
|
|
1550
|
+
args: A;
|
|
1552
1551
|
extensions: {};
|
|
1553
1552
|
}>> = Partial<Command<{
|
|
1554
|
-
args: A
|
|
1553
|
+
args: A;
|
|
1555
1554
|
extensions: {};
|
|
1556
1555
|
}>>>(loader: CommandLoader<{
|
|
1557
|
-
args: A
|
|
1556
|
+
args: A;
|
|
1558
1557
|
extensions: {};
|
|
1559
1558
|
}>, definition: D): LazyCommand<{
|
|
1560
|
-
args: A
|
|
1559
|
+
args: A;
|
|
1561
1560
|
extensions: {};
|
|
1562
1561
|
}, D>;
|
|
1563
1562
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/definition",
|
|
3
3
|
"description": "utilities for gunshi command definition",
|
|
4
|
-
"version": "0.27.
|
|
4
|
+
"version": "0.27.6",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"deno": "^2.
|
|
55
|
+
"deno": "^2.6.3",
|
|
56
56
|
"jsr": "^0.13.5",
|
|
57
57
|
"jsr-exports-lint": "^0.4.1",
|
|
58
58
|
"publint": "^0.3.16",
|
|
59
59
|
"tsdown": "0.15.12",
|
|
60
|
-
"gunshi": "0.27.
|
|
60
|
+
"gunshi": "0.27.6"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|