@gunshi/definition 0.27.0-beta.3 → 0.27.0-beta.5
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 +37 -37
- package/lib/index.js +15 -0
- package/package.json +5 -5
package/lib/index.d.ts
CHANGED
|
@@ -473,10 +473,10 @@ interface Args {
|
|
|
473
473
|
*
|
|
474
474
|
* @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
|
|
475
475
|
*/
|
|
476
|
-
type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]> }> : {
|
|
476
|
+
type ArgValues<T$1> = T$1 extends Args ? ResolveArgValues<T$1, { [Arg in keyof T$1]: ExtractOptionValue<T$1[Arg]> }> : {
|
|
477
477
|
[option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
|
|
478
478
|
};
|
|
479
|
-
type IsFunction<T> = T extends ((...args: any[]) => any) ? true : false;
|
|
479
|
+
type IsFunction<T$1> = T$1 extends ((...args: any[]) => any) ? true : false;
|
|
480
480
|
/**
|
|
481
481
|
* Extracts the value type from the argument schema.
|
|
482
482
|
*
|
|
@@ -484,8 +484,8 @@ type IsFunction<T> = T extends ((...args: any[]) => any) ? true : false;
|
|
|
484
484
|
*
|
|
485
485
|
* @internal
|
|
486
486
|
*/
|
|
487
|
-
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>;
|
|
488
|
-
type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T[] : T;
|
|
487
|
+
type ExtractOptionValue<A$1 extends ArgSchema> = A$1['type'] extends 'string' ? ResolveOptionValue<A$1, string> : A$1['type'] extends 'boolean' ? ResolveOptionValue<A$1, boolean> : A$1['type'] extends 'number' ? ResolveOptionValue<A$1, number> : A$1['type'] extends 'positional' ? ResolveOptionValue<A$1, string> : A$1['type'] extends 'enum' ? A$1['choices'] extends string[] | readonly string[] ? ResolveOptionValue<A$1, A$1['choices'][number]> : never : A$1['type'] extends 'custom' ? IsFunction<A$1['parse']> extends true ? ResolveOptionValue<A$1, ReturnType<NonNullable<A$1['parse']>>> : never : ResolveOptionValue<A$1, string | boolean | number>;
|
|
488
|
+
type ResolveOptionValue<A$1 extends ArgSchema, T$1> = A$1['multiple'] extends true ? T$1[] : T$1;
|
|
489
489
|
/**
|
|
490
490
|
* Resolved argument values.
|
|
491
491
|
*
|
|
@@ -494,7 +494,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
|
|
|
494
494
|
*
|
|
495
495
|
* @internal
|
|
496
496
|
*/
|
|
497
|
-
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;
|
|
497
|
+
type ResolveArgValues<A$1 extends Args, V extends Record<keyof A$1, unknown>> = { -readonly [Arg in keyof A$1]?: V[Arg] } & FilterArgs<A$1, V, 'default'> & FilterArgs<A$1, V, 'required'> & FilterPositionalArgs<A$1, V> extends infer P ? { [K in keyof P]: P[K] } : never;
|
|
498
498
|
/**
|
|
499
499
|
* Filters the arguments based on their default values.
|
|
500
500
|
*
|
|
@@ -504,7 +504,7 @@ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -r
|
|
|
504
504
|
*
|
|
505
505
|
* @internal
|
|
506
506
|
*/
|
|
507
|
-
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] };
|
|
507
|
+
type FilterArgs<A$1 extends Args, V extends Record<keyof A$1, unknown>, K$1 extends keyof ArgSchema> = { [Arg in keyof A$1 as A$1[Arg][K$1] extends {} ? Arg : never]: V[Arg] };
|
|
508
508
|
/**
|
|
509
509
|
* Filters positional arguments from the argument schema.
|
|
510
510
|
*
|
|
@@ -513,7 +513,7 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
|
|
|
513
513
|
*
|
|
514
514
|
* @internal
|
|
515
515
|
*/
|
|
516
|
-
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] };
|
|
516
|
+
type FilterPositionalArgs<A$1 extends Args, V extends Record<keyof A$1, unknown>> = { [Arg in keyof A$1 as A$1[Arg]['type'] extends 'positional' ? Arg : never]: V[Arg] };
|
|
517
517
|
/**
|
|
518
518
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
519
519
|
*/
|
|
@@ -526,7 +526,7 @@ type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> =
|
|
|
526
526
|
*
|
|
527
527
|
* @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
|
|
528
528
|
*/
|
|
529
|
-
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
529
|
+
type ArgExplicitlyProvided<A$1 extends Args> = { [K in keyof A$1]: boolean };
|
|
530
530
|
/**
|
|
531
531
|
* Resolve command line arguments.
|
|
532
532
|
*
|
|
@@ -682,11 +682,11 @@ type PluginFunction<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readon
|
|
|
682
682
|
*
|
|
683
683
|
* @since v0.27.0
|
|
684
684
|
*/
|
|
685
|
-
type Plugin<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> = PluginFunction & {
|
|
685
|
+
type Plugin<E$1 extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> = PluginFunction & {
|
|
686
686
|
id: string;
|
|
687
687
|
name?: string;
|
|
688
688
|
dependencies?: (PluginDependency | string)[];
|
|
689
|
-
extension?: CommandContextExtension<E>;
|
|
689
|
+
extension?: CommandContextExtension<E$1>;
|
|
690
690
|
};
|
|
691
691
|
//#endregion
|
|
692
692
|
//#region ../gunshi/src/types.d.ts
|
|
@@ -695,13 +695,13 @@ type Plugin<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensio
|
|
|
695
695
|
*
|
|
696
696
|
* @typeParam T - The type of the value that can be awaited.
|
|
697
697
|
*/
|
|
698
|
-
type Awaitable<T> = T | Promise<T>;
|
|
698
|
+
type Awaitable<T$1> = T$1 | Promise<T$1>;
|
|
699
699
|
/**
|
|
700
700
|
* Prettify a type by flattening its structure.
|
|
701
701
|
*
|
|
702
702
|
* @typeParam T - The type to be prettified.
|
|
703
703
|
*/
|
|
704
|
-
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
704
|
+
type Prettify<T$1> = { [K in keyof T$1]: T$1[K] } & {};
|
|
705
705
|
/**
|
|
706
706
|
* Extend command context type. This type is used to extend the command context with additional properties at {@linkcode CommandContext.extensions}.
|
|
707
707
|
*
|
|
@@ -717,7 +717,7 @@ type ExtendContext = Record<string, unknown>;
|
|
|
717
717
|
*
|
|
718
718
|
* @since v0.27.0
|
|
719
719
|
*/
|
|
720
|
-
interface GunshiParams<P extends {
|
|
720
|
+
interface GunshiParams<P$1 extends {
|
|
721
721
|
args?: Args;
|
|
722
722
|
extensions?: ExtendContext;
|
|
723
723
|
} = {
|
|
@@ -727,13 +727,13 @@ interface GunshiParams<P extends {
|
|
|
727
727
|
/**
|
|
728
728
|
* Command argument definitions.
|
|
729
729
|
*/
|
|
730
|
-
args: P extends {
|
|
730
|
+
args: P$1 extends {
|
|
731
731
|
args: infer A extends Args;
|
|
732
732
|
} ? A : Args;
|
|
733
733
|
/**
|
|
734
734
|
* Command context extensions.
|
|
735
735
|
*/
|
|
736
|
-
extensions: P extends {
|
|
736
|
+
extensions: P$1 extends {
|
|
737
737
|
extensions: infer E extends ExtendContext;
|
|
738
738
|
} ? E : {};
|
|
739
739
|
}
|
|
@@ -1099,7 +1099,7 @@ type CommandContextCore<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1099
1099
|
*
|
|
1100
1100
|
* @since v0.27.0
|
|
1101
1101
|
*/
|
|
1102
|
-
interface CommandContextExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
1102
|
+
interface CommandContextExtension<E$1 extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
1103
1103
|
/**
|
|
1104
1104
|
* Plugin identifier
|
|
1105
1105
|
*/
|
|
@@ -1107,7 +1107,7 @@ interface CommandContextExtension<E extends GunshiParams['extensions'] = Default
|
|
|
1107
1107
|
/**
|
|
1108
1108
|
* Plugin extension factory
|
|
1109
1109
|
*/
|
|
1110
|
-
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E>;
|
|
1110
|
+
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E$1>;
|
|
1111
1111
|
/**
|
|
1112
1112
|
* Plugin extension factory after hook
|
|
1113
1113
|
*/
|
|
@@ -1256,7 +1256,7 @@ type CommandLoader<G extends GunshiParamsConstraint = DefaultGunshiParams> = ()
|
|
|
1256
1256
|
*
|
|
1257
1257
|
* @internal
|
|
1258
1258
|
*/
|
|
1259
|
-
type ExtractExtensions$1<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never };
|
|
1259
|
+
type ExtractExtensions$1<E$1 extends Record<string, CommandContextExtension>> = { [K in keyof E$1]: E$1[K] extends CommandContextExtension<infer T> ? T : never };
|
|
1260
1260
|
/**
|
|
1261
1261
|
* Parameters of {@link createCommandContext}
|
|
1262
1262
|
*/
|
|
@@ -1264,7 +1264,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1264
1264
|
args: Args;
|
|
1265
1265
|
} | {
|
|
1266
1266
|
extensions: ExtendContext;
|
|
1267
|
-
}, V extends ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E extends Record<string, CommandContextExtension> = Record<string, CommandContextExtension>> {
|
|
1267
|
+
}, V extends ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E$1 extends Record<string, CommandContextExtension> = Record<string, CommandContextExtension>> {
|
|
1268
1268
|
/**
|
|
1269
1269
|
* An arguments of target command
|
|
1270
1270
|
*/
|
|
@@ -1308,7 +1308,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1308
1308
|
/**
|
|
1309
1309
|
* Plugin extensions to apply as the command context extension.
|
|
1310
1310
|
*/
|
|
1311
|
-
extensions?: E;
|
|
1311
|
+
extensions?: E$1;
|
|
1312
1312
|
/**
|
|
1313
1313
|
* A command options, which is spicialized from `cli` function
|
|
1314
1314
|
*/
|
|
@@ -1324,7 +1324,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1324
1324
|
* @param param - A {@link CommandContextParams | parameters} to create a command context.
|
|
1325
1325
|
* @returns A {@link CommandContext | command context}, which is readonly.
|
|
1326
1326
|
*/
|
|
1327
|
-
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> = {}>({
|
|
1327
|
+
declare function createCommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams, V extends ArgValues<ExtractArgs<G>> = ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E$1 extends Record<string, CommandContextExtension> = {}>({
|
|
1328
1328
|
args,
|
|
1329
1329
|
explicit,
|
|
1330
1330
|
values,
|
|
@@ -1338,9 +1338,9 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
|
|
|
1338
1338
|
callMode,
|
|
1339
1339
|
omitted,
|
|
1340
1340
|
validationError
|
|
1341
|
-
}: CommandContextParams<G, V, C, E>): Promise<{} extends ExtractExtensions$1<E> ? Readonly<CommandContext<G>> : Readonly<CommandContext<GunshiParams<{
|
|
1341
|
+
}: CommandContextParams<G, V, C, E$1>): Promise<{} extends ExtractExtensions$1<E$1> ? Readonly<CommandContext<G>> : Readonly<CommandContext<GunshiParams<{
|
|
1342
1342
|
args: ExtractArgs<G>;
|
|
1343
|
-
extensions: ExtractExtensions$1<E>;
|
|
1343
|
+
extensions: ExtractExtensions$1<E$1>;
|
|
1344
1344
|
}>>>>;
|
|
1345
1345
|
//#endregion
|
|
1346
1346
|
//#region ../gunshi/src/definition.d.ts
|
|
@@ -1386,8 +1386,8 @@ type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
1386
1386
|
* @param definition - A {@link Command | command} definition
|
|
1387
1387
|
* @returns A defined {@link Command | command}
|
|
1388
1388
|
*/
|
|
1389
|
-
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends InferCommandProps<G> = InferCommandProps<G>>(definition: C & Command<{
|
|
1390
|
-
args: A;
|
|
1389
|
+
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A$1 extends Args = ExtractArgs<G>, C extends InferCommandProps<G> = InferCommandProps<G>>(definition: C & Command<{
|
|
1390
|
+
args: A$1;
|
|
1391
1391
|
extensions: ExtractExtensions<G>;
|
|
1392
1392
|
}>): CommandDefinitionResult<G, C>;
|
|
1393
1393
|
/**
|
|
@@ -1397,14 +1397,14 @@ declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams,
|
|
|
1397
1397
|
*
|
|
1398
1398
|
* @internal
|
|
1399
1399
|
*/
|
|
1400
|
-
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A extends DefaultArgs = DefaultArgs, C extends Partial<Command<{
|
|
1401
|
-
args: A;
|
|
1400
|
+
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A$1 extends DefaultArgs = DefaultArgs, C extends Partial<Command<{
|
|
1401
|
+
args: A$1;
|
|
1402
1402
|
extensions: DefaultExtensions;
|
|
1403
1403
|
}>> = {}>(definition: C & Command<{
|
|
1404
|
-
args: A;
|
|
1404
|
+
args: A$1;
|
|
1405
1405
|
extensions: DefaultExtensions;
|
|
1406
1406
|
}>) => CommandDefinitionResult<{
|
|
1407
|
-
args: A;
|
|
1407
|
+
args: A$1;
|
|
1408
1408
|
extensions: DefaultExtensions;
|
|
1409
1409
|
}, C>;
|
|
1410
1410
|
/**
|
|
@@ -1451,11 +1451,11 @@ declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWith
|
|
|
1451
1451
|
* @param loader - A {@link CommandLoader | command loader}
|
|
1452
1452
|
* @returns A {@link LazyCommand | lazy command} with loader
|
|
1453
1453
|
*/
|
|
1454
|
-
declare function lazy<A extends Args>(loader: CommandLoader<{
|
|
1455
|
-
args: A;
|
|
1454
|
+
declare function lazy<A$1 extends Args>(loader: CommandLoader<{
|
|
1455
|
+
args: A$1;
|
|
1456
1456
|
extensions: {};
|
|
1457
1457
|
}>): LazyCommand<{
|
|
1458
|
-
args: A;
|
|
1458
|
+
args: A$1;
|
|
1459
1459
|
extensions: {};
|
|
1460
1460
|
}, {}>;
|
|
1461
1461
|
/**
|
|
@@ -1493,17 +1493,17 @@ declare function lazy<A extends Args>(loader: CommandLoader<{
|
|
|
1493
1493
|
* @param definition - An optional {@link Command | command} definition
|
|
1494
1494
|
* @returns A {@link LazyCommand | lazy command} that can be executed later
|
|
1495
1495
|
*/
|
|
1496
|
-
declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends ExtractArgs<G> = ExtractArgs<G>, D extends Partial<Command<{
|
|
1497
|
-
args: A;
|
|
1496
|
+
declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A$1 extends ExtractArgs<G> = ExtractArgs<G>, D extends Partial<Command<{
|
|
1497
|
+
args: A$1;
|
|
1498
1498
|
extensions: {};
|
|
1499
1499
|
}>> = Partial<Command<{
|
|
1500
|
-
args: A;
|
|
1500
|
+
args: A$1;
|
|
1501
1501
|
extensions: {};
|
|
1502
1502
|
}>>>(loader: CommandLoader<{
|
|
1503
|
-
args: A;
|
|
1503
|
+
args: A$1;
|
|
1504
1504
|
extensions: {};
|
|
1505
1505
|
}>, definition: D): LazyCommand<{
|
|
1506
|
-
args: A;
|
|
1506
|
+
args: A$1;
|
|
1507
1507
|
extensions: {};
|
|
1508
1508
|
}, D>;
|
|
1509
1509
|
/**
|
package/lib/index.js
CHANGED
|
@@ -70,6 +70,21 @@ function deepFreeze(obj, ignores = []) {
|
|
|
70
70
|
//#endregion
|
|
71
71
|
//#region ../gunshi/src/context.ts
|
|
72
72
|
/**
|
|
73
|
+
* The entry for gunshi context.
|
|
74
|
+
* This module is exported for the purpose of testing the command.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```js
|
|
78
|
+
* import { createCommandContext } from 'gunshi/context'
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @module
|
|
82
|
+
*/
|
|
83
|
+
/**
|
|
84
|
+
* @author kazuya kawaguchi (a.k.a. kazupon)
|
|
85
|
+
* @license MIT
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
73
88
|
* Create a command context.
|
|
74
89
|
*
|
|
75
90
|
* @param param - A {@link CommandContextParams | parameters} to create a command context.
|
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.0-beta.
|
|
4
|
+
"version": "0.27.0-beta.5",
|
|
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.5.
|
|
55
|
+
"deno": "^2.5.6",
|
|
56
56
|
"jsr": "^0.13.5",
|
|
57
57
|
"jsr-exports-lint": "^0.4.1",
|
|
58
|
-
"publint": "^0.3.
|
|
59
|
-
"tsdown": "0.15.
|
|
60
|
-
"gunshi": "0.27.0-beta.
|
|
58
|
+
"publint": "^0.3.15",
|
|
59
|
+
"tsdown": "0.15.12",
|
|
60
|
+
"gunshi": "0.27.0-beta.5"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|