@gunshi/plugin 0.27.0 → 0.27.4
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 +84 -30
- package/package.json +2 -2
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
|
|
476
|
+
type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]> }> : {
|
|
477
477
|
[option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
|
|
478
478
|
};
|
|
479
|
-
type IsFunction<T
|
|
479
|
+
type IsFunction<T> = T 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$1> = T$1 extends ((...args: any[]) => any) ? true : false;
|
|
|
484
484
|
*
|
|
485
485
|
* @internal
|
|
486
486
|
*/
|
|
487
|
-
type ExtractOptionValue<A
|
|
488
|
-
type ResolveOptionValue<A
|
|
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;
|
|
489
489
|
/**
|
|
490
490
|
* Resolved argument values.
|
|
491
491
|
*
|
|
@@ -494,7 +494,7 @@ type ResolveOptionValue<A$1 extends ArgSchema, T$1> = A$1['multiple'] extends tr
|
|
|
494
494
|
*
|
|
495
495
|
* @internal
|
|
496
496
|
*/
|
|
497
|
-
type ResolveArgValues<A
|
|
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;
|
|
498
498
|
/**
|
|
499
499
|
* Filters the arguments based on their default values.
|
|
500
500
|
*
|
|
@@ -504,7 +504,7 @@ type ResolveArgValues<A$1 extends Args, V extends Record<keyof A$1, unknown>> =
|
|
|
504
504
|
*
|
|
505
505
|
* @internal
|
|
506
506
|
*/
|
|
507
|
-
type FilterArgs<A
|
|
507
|
+
type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K$1 extends keyof ArgSchema> = { [Arg in keyof A as A[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$1 extends Args, V extends Record<keyof A$1, unknown>, K$1 exte
|
|
|
513
513
|
*
|
|
514
514
|
* @internal
|
|
515
515
|
*/
|
|
516
|
-
type FilterPositionalArgs<A
|
|
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] };
|
|
517
517
|
/**
|
|
518
518
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
519
519
|
*/
|
|
@@ -526,7 +526,7 @@ type FilterPositionalArgs<A$1 extends Args, V extends Record<keyof A$1, 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
|
|
529
|
+
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
530
530
|
/**
|
|
531
531
|
* Resolve command line arguments.
|
|
532
532
|
*
|
|
@@ -648,18 +648,18 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
648
648
|
}
|
|
649
649
|
//#endregion
|
|
650
650
|
//#region ../gunshi/src/plugin/core.d.ts
|
|
651
|
-
type ProcessDependency<D, A
|
|
651
|
+
type ProcessDependency<D, A extends ExtendContext> = D extends string ? D extends keyof A ? { [K in D]: A[K] } : {} : D extends {
|
|
652
652
|
id: infer ID;
|
|
653
653
|
optional?: any;
|
|
654
|
-
} ? ID extends string ? ID extends keyof A
|
|
654
|
+
} ? ID extends string ? ID extends keyof A ? D extends {
|
|
655
655
|
optional: true;
|
|
656
|
-
} ? { [K in ID]: A
|
|
656
|
+
} ? { [K in ID]: A[K] | undefined } : { [K in ID]: A[K] } : {} : never : never;
|
|
657
657
|
/**
|
|
658
658
|
* Helper type to infer dependency extensions with optional support
|
|
659
659
|
*
|
|
660
660
|
* @internal
|
|
661
661
|
*/
|
|
662
|
-
type InferDependencyExtensions<D extends ReadonlyArray<PluginDependency | string>, A
|
|
662
|
+
type InferDependencyExtensions<D extends ReadonlyArray<PluginDependency | string>, A extends ExtendContext> = D extends readonly [] ? {} : D extends readonly [infer First, ...infer Rest] ? ProcessDependency<First, A> & (Rest extends ReadonlyArray<PluginDependency | string> ? InferDependencyExtensions<Rest, A> : {}) : {};
|
|
663
663
|
/**
|
|
664
664
|
* Plugin dependency definition
|
|
665
665
|
*
|
|
@@ -696,7 +696,7 @@ type PluginFunction<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readon
|
|
|
696
696
|
*
|
|
697
697
|
* @since v0.27.0
|
|
698
698
|
*/
|
|
699
|
-
type PluginExtension<T
|
|
699
|
+
type PluginExtension<T = Record<string, unknown>, G extends GunshiParams = DefaultGunshiParams> = (ctx: CommandContextCore<G>, cmd: Command<G>) => Awaitable<T>;
|
|
700
700
|
/**
|
|
701
701
|
* Plugin extension callback, which is called when the plugin is extended with `extension` option.
|
|
702
702
|
*
|
|
@@ -765,11 +765,11 @@ ResolvedDepExt extends GunshiParams = GunshiParams<{
|
|
|
765
765
|
*
|
|
766
766
|
* @since v0.27.0
|
|
767
767
|
*/
|
|
768
|
-
type Plugin<E
|
|
768
|
+
type Plugin<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> = PluginFunction & {
|
|
769
769
|
id: string;
|
|
770
770
|
name?: string;
|
|
771
771
|
dependencies?: (PluginDependency | string)[];
|
|
772
|
-
extension?: CommandContextExtension<E
|
|
772
|
+
extension?: CommandContextExtension<E>;
|
|
773
773
|
};
|
|
774
774
|
/**
|
|
775
775
|
* Plugin return type with extension, which includes the plugin ID, name, dependencies, and extension.
|
|
@@ -778,7 +778,7 @@ type Plugin<E$1 extends GunshiParams['extensions'] = DefaultGunshiParams['extens
|
|
|
778
778
|
*
|
|
779
779
|
* @typeParam E - A type extending {@link GunshiParams} to specify the shape of {@linkcode CommandContext}'s extensions.
|
|
780
780
|
*/
|
|
781
|
-
interface PluginWithExtension<E
|
|
781
|
+
interface PluginWithExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> extends Plugin<E> {
|
|
782
782
|
/**
|
|
783
783
|
* Plugin identifier
|
|
784
784
|
*/
|
|
@@ -794,7 +794,7 @@ interface PluginWithExtension<E$1 extends GunshiParams['extensions'] = DefaultGu
|
|
|
794
794
|
/**
|
|
795
795
|
* Plugin extension
|
|
796
796
|
*/
|
|
797
|
-
extension: CommandContextExtension<E
|
|
797
|
+
extension: CommandContextExtension<E>;
|
|
798
798
|
}
|
|
799
799
|
/**
|
|
800
800
|
* Plugin return type without extension, which includes the plugin ID, name, and dependencies, but no extension.
|
|
@@ -803,7 +803,7 @@ interface PluginWithExtension<E$1 extends GunshiParams['extensions'] = DefaultGu
|
|
|
803
803
|
*
|
|
804
804
|
* @typeParam E - A type extending {@link GunshiParams} to specify the shape of {@linkcode CommandContext}'s extensions.
|
|
805
805
|
*/
|
|
806
|
-
interface PluginWithoutExtension<E
|
|
806
|
+
interface PluginWithoutExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> extends Plugin<E> {
|
|
807
807
|
/**
|
|
808
808
|
* Plugin identifier
|
|
809
809
|
*/
|
|
@@ -899,13 +899,13 @@ ResolvedDepExtensions extends GunshiParams = GunshiParams<{
|
|
|
899
899
|
*
|
|
900
900
|
* @typeParam T - The type of the value that can be awaited.
|
|
901
901
|
*/
|
|
902
|
-
type Awaitable<T
|
|
902
|
+
type Awaitable<T> = T | Promise<T>;
|
|
903
903
|
/**
|
|
904
904
|
* Prettify a type by flattening its structure.
|
|
905
905
|
*
|
|
906
906
|
* @typeParam T - The type to be prettified.
|
|
907
907
|
*/
|
|
908
|
-
type Prettify<T
|
|
908
|
+
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
909
909
|
/**
|
|
910
910
|
* Extend command context type. This type is used to extend the command context with additional properties at {@linkcode CommandContext.extensions}.
|
|
911
911
|
*
|
|
@@ -1127,7 +1127,7 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
|
1127
1127
|
/**
|
|
1128
1128
|
* Sub commands.
|
|
1129
1129
|
*/
|
|
1130
|
-
subCommands?: Record<string,
|
|
1130
|
+
subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable>;
|
|
1131
1131
|
/**
|
|
1132
1132
|
* Left margin of the command output.
|
|
1133
1133
|
*/
|
|
@@ -1314,7 +1314,7 @@ type CommandContextCore<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1314
1314
|
*
|
|
1315
1315
|
* @since v0.27.0
|
|
1316
1316
|
*/
|
|
1317
|
-
interface CommandContextExtension<E
|
|
1317
|
+
interface CommandContextExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
1318
1318
|
/**
|
|
1319
1319
|
* Plugin identifier
|
|
1320
1320
|
*/
|
|
@@ -1322,7 +1322,7 @@ interface CommandContextExtension<E$1 extends GunshiParams['extensions'] = Defau
|
|
|
1322
1322
|
/**
|
|
1323
1323
|
* Plugin extension factory
|
|
1324
1324
|
*/
|
|
1325
|
-
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E
|
|
1325
|
+
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E>;
|
|
1326
1326
|
/**
|
|
1327
1327
|
* Plugin extension factory after hook
|
|
1328
1328
|
*/
|
|
@@ -1435,6 +1435,60 @@ type LazyCommand<G extends GunshiParamsConstraint = DefaultGunshiParams, D exten
|
|
|
1435
1435
|
} : {
|
|
1436
1436
|
commandName?: string;
|
|
1437
1437
|
}) & Omit<D, 'name' | 'run'> & Partial<Omit<Command<G>, keyof D | 'run' | 'name'>>;
|
|
1438
|
+
/**
|
|
1439
|
+
* Sub-command entry type for use in subCommands.
|
|
1440
|
+
*
|
|
1441
|
+
* This type uses a loose structural match to bypass TypeScript's contravariance issues
|
|
1442
|
+
* with function parameters, allowing any Command or LazyCommand to be used as a sub-command.
|
|
1443
|
+
*
|
|
1444
|
+
* @since v0.27.1
|
|
1445
|
+
*/
|
|
1446
|
+
interface SubCommandable {
|
|
1447
|
+
/**
|
|
1448
|
+
* see {@link Command.name}
|
|
1449
|
+
*/
|
|
1450
|
+
name?: string;
|
|
1451
|
+
/**
|
|
1452
|
+
* see {@link Command.description}
|
|
1453
|
+
*/
|
|
1454
|
+
description?: string;
|
|
1455
|
+
/**
|
|
1456
|
+
* see {@link Command.args}
|
|
1457
|
+
*/
|
|
1458
|
+
args?: Args | Record<string, any>;
|
|
1459
|
+
/**
|
|
1460
|
+
* see {@link Command.examples}
|
|
1461
|
+
*/
|
|
1462
|
+
examples?: string | ((...args: any[]) => any);
|
|
1463
|
+
/**
|
|
1464
|
+
* see {@link Command.run}
|
|
1465
|
+
*/
|
|
1466
|
+
run?: (...args: any[]) => any;
|
|
1467
|
+
/**
|
|
1468
|
+
* see {@link Command.toKebab}
|
|
1469
|
+
*/
|
|
1470
|
+
toKebab?: boolean;
|
|
1471
|
+
/**
|
|
1472
|
+
* see {@link Command.internal}
|
|
1473
|
+
*/
|
|
1474
|
+
internal?: boolean;
|
|
1475
|
+
/**
|
|
1476
|
+
* see {@link Command.entry}
|
|
1477
|
+
*/
|
|
1478
|
+
entry?: boolean;
|
|
1479
|
+
/**
|
|
1480
|
+
* see {@link Command.rendering}
|
|
1481
|
+
*/
|
|
1482
|
+
rendering?: any;
|
|
1483
|
+
/**
|
|
1484
|
+
* see {@link LazyCommand.commandName}
|
|
1485
|
+
*/
|
|
1486
|
+
commandName?: string;
|
|
1487
|
+
/**
|
|
1488
|
+
* Index signature to allow additional properties
|
|
1489
|
+
*/
|
|
1490
|
+
[key: string]: any;
|
|
1491
|
+
}
|
|
1438
1492
|
/**
|
|
1439
1493
|
* Command examples fetcher.
|
|
1440
1494
|
*
|
|
@@ -1480,7 +1534,7 @@ type CommandDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> =
|
|
|
1480
1534
|
*
|
|
1481
1535
|
* @since v0.27.0
|
|
1482
1536
|
*/
|
|
1483
|
-
type RendererDecorator<T
|
|
1537
|
+
type RendererDecorator<T, G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRenderer: (ctx: Readonly<CommandContext<G>>) => Promise<T>, ctx: Readonly<CommandContext<G>>) => Promise<T>;
|
|
1484
1538
|
/**
|
|
1485
1539
|
* Validation errors renderer decorator type.
|
|
1486
1540
|
* A function that wraps a validation errors renderer to add or modify its behavior.
|
|
@@ -1506,7 +1560,7 @@ declare const CLI_OPTIONS_DEFAULT: CliOptions<DefaultGunshiParams>;
|
|
|
1506
1560
|
*
|
|
1507
1561
|
* @internal
|
|
1508
1562
|
*/
|
|
1509
|
-
type ExtractExtensions$1<E
|
|
1563
|
+
type ExtractExtensions$1<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never };
|
|
1510
1564
|
/**
|
|
1511
1565
|
* Parameters of {@link createCommandContext}
|
|
1512
1566
|
*/
|
|
@@ -1514,7 +1568,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1514
1568
|
args: Args;
|
|
1515
1569
|
} | {
|
|
1516
1570
|
extensions: ExtendContext;
|
|
1517
|
-
}, V extends ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E
|
|
1571
|
+
}, V extends ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E extends Record<string, CommandContextExtension> = Record<string, CommandContextExtension>> {
|
|
1518
1572
|
/**
|
|
1519
1573
|
* An arguments of target command
|
|
1520
1574
|
*/
|
|
@@ -1558,7 +1612,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1558
1612
|
/**
|
|
1559
1613
|
* Plugin extensions to apply as the command context extension.
|
|
1560
1614
|
*/
|
|
1561
|
-
extensions?: E
|
|
1615
|
+
extensions?: E;
|
|
1562
1616
|
/**
|
|
1563
1617
|
* A command options, which is spicialized from `cli` function
|
|
1564
1618
|
*/
|
|
@@ -1574,7 +1628,7 @@ interface CommandContextParams<G extends GunshiParams | {
|
|
|
1574
1628
|
* @param param - A {@link CommandContextParams | parameters} to create a command context.
|
|
1575
1629
|
* @returns A {@link CommandContext | command context}, which is readonly.
|
|
1576
1630
|
*/
|
|
1577
|
-
declare function createCommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams, V extends ArgValues<ExtractArgs<G>> = ArgValues<ExtractArgs<G>>, C extends Command<G> | LazyCommand<G> = Command<G>, E
|
|
1631
|
+
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> = {}>({
|
|
1578
1632
|
args,
|
|
1579
1633
|
explicit,
|
|
1580
1634
|
values,
|
|
@@ -1588,9 +1642,9 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
|
|
|
1588
1642
|
callMode,
|
|
1589
1643
|
omitted,
|
|
1590
1644
|
validationError
|
|
1591
|
-
}: CommandContextParams<G, V, C, E
|
|
1645
|
+
}: CommandContextParams<G, V, C, E>): Promise<{} extends ExtractExtensions$1<E> ? Readonly<CommandContext<G>> : Readonly<CommandContext<GunshiParams<{
|
|
1592
1646
|
args: ExtractArgs<G>;
|
|
1593
|
-
extensions: ExtractExtensions$1<E
|
|
1647
|
+
extensions: ExtractExtensions$1<E>;
|
|
1594
1648
|
}>>>>;
|
|
1595
1649
|
//#endregion
|
|
1596
1650
|
export { ANONYMOUS_COMMAND_NAME, type ArgSchema, type ArgToken, type ArgValues, type Args, Awaitable, CLI_OPTIONS_DEFAULT, Command, CommandContext, CommandContextCore, CommandContextExtension, CommandContextParams, CommandDecorator, CommandExamplesFetcher, CommandRunner, DefaultGunshiParams, ExtendContext, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, NormalizeToGunshiParams, OnPluginExtension, Plugin, PluginContext, PluginDependency, PluginExtension, PluginFunction, PluginOptions, PluginWithExtension, PluginWithoutExtension, Prettify, RendererDecorator, ValidationErrorsDecorator, createCommandContext, plugin };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/plugin",
|
|
3
3
|
"description": "plugin development kit for gunshi",
|
|
4
|
-
"version": "0.27.
|
|
4
|
+
"version": "0.27.4",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"jsr-exports-lint": "^0.4.1",
|
|
57
57
|
"publint": "^0.3.16",
|
|
58
58
|
"tsdown": "0.15.12",
|
|
59
|
-
"gunshi": "0.27.
|
|
59
|
+
"gunshi": "0.27.4"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsdown",
|