@gunshi/definition 0.31.0 → 0.33.0
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 +71 -58
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -581,15 +581,6 @@ type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
|
581
581
|
*/
|
|
582
582
|
//#endregion
|
|
583
583
|
//#region ../gunshi/src/plugin/context.d.ts
|
|
584
|
-
/**
|
|
585
|
-
* Type helper to create GunshiParams from extracted args and extensions
|
|
586
|
-
*
|
|
587
|
-
* @internal
|
|
588
|
-
*/
|
|
589
|
-
type ExtractedParams<G extends GunshiParamsConstraint, L extends Record<string, unknown> = {}> = {
|
|
590
|
-
args: ExtractArgs<G>;
|
|
591
|
-
extensions: ExtractExtensions$1<G> & L;
|
|
592
|
-
};
|
|
593
584
|
/**
|
|
594
585
|
* Gunshi plugin context interface.
|
|
595
586
|
*
|
|
@@ -638,7 +629,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
638
629
|
*
|
|
639
630
|
* @param decorator - A decorator function that wraps the base header renderer.
|
|
640
631
|
*/
|
|
641
|
-
decorateHeaderRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
632
|
+
decorateHeaderRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>): void;
|
|
642
633
|
/**
|
|
643
634
|
* Decorate the usage renderer.
|
|
644
635
|
*
|
|
@@ -646,7 +637,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
646
637
|
*
|
|
647
638
|
* @param decorator - A decorator function that wraps the base usage renderer.
|
|
648
639
|
*/
|
|
649
|
-
decorateUsageRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
640
|
+
decorateUsageRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Promise<string>): void;
|
|
650
641
|
/**
|
|
651
642
|
* Decorate the validation errors renderer.
|
|
652
643
|
*
|
|
@@ -654,7 +645,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
654
645
|
*
|
|
655
646
|
* @param decorator - A decorator function that wraps the base validation errors renderer.
|
|
656
647
|
*/
|
|
657
|
-
decorateValidationErrorsRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<
|
|
648
|
+
decorateValidationErrorsRenderer<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRenderer: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>, error: AggregateError) => Promise<string>, ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>, error: AggregateError) => Promise<string>): void;
|
|
658
649
|
/**
|
|
659
650
|
* Decorate the command execution.
|
|
660
651
|
*
|
|
@@ -664,7 +655,7 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
664
655
|
*
|
|
665
656
|
* @param decorator - A decorator function that wraps the command runner
|
|
666
657
|
*/
|
|
667
|
-
decorateCommand<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRunner: (ctx: Readonly<CommandContext<
|
|
658
|
+
decorateCommand<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRunner: (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Awaitable<void | string>) => (ctx: Readonly<CommandContext<MergeGunshiExtensions<G, L>>>) => Awaitable<void | string>): void;
|
|
668
659
|
}
|
|
669
660
|
//#endregion
|
|
670
661
|
//#region ../gunshi/src/plugin/core.d.ts
|
|
@@ -798,9 +789,46 @@ type ExtractArgExplicitlyProvided<G> = ArgExplicitlyProvided<ExtractArgs<G>>;
|
|
|
798
789
|
*
|
|
799
790
|
* @internal
|
|
800
791
|
*/
|
|
801
|
-
type ExtractExtensions
|
|
792
|
+
type ExtractExtensions<G> = G extends GunshiParams<any> ? G['extensions'] : G extends {
|
|
802
793
|
extensions: infer E;
|
|
803
794
|
} ? E : {};
|
|
795
|
+
/**
|
|
796
|
+
* Type helper to normalize G to GunshiParams
|
|
797
|
+
*
|
|
798
|
+
* @internal
|
|
799
|
+
*/
|
|
800
|
+
type NormalizeToGunshiParams<G> = G extends GunshiParams<any> ? G : G extends {
|
|
801
|
+
args: infer A extends Args;
|
|
802
|
+
extensions: infer E extends ExtendContext;
|
|
803
|
+
} ? GunshiParams<{
|
|
804
|
+
args: A;
|
|
805
|
+
extensions: E;
|
|
806
|
+
}> : G extends {
|
|
807
|
+
args: infer A extends Args;
|
|
808
|
+
} ? GunshiParams<{
|
|
809
|
+
args: A;
|
|
810
|
+
extensions: {};
|
|
811
|
+
}> : G extends {
|
|
812
|
+
extensions: infer E extends ExtendContext;
|
|
813
|
+
} ? GunshiParams<{
|
|
814
|
+
args: Args;
|
|
815
|
+
extensions: E;
|
|
816
|
+
}> : DefaultGunshiParams;
|
|
817
|
+
/**
|
|
818
|
+
* Type helper to merge command context extensions into G
|
|
819
|
+
*
|
|
820
|
+
* @internal
|
|
821
|
+
*/
|
|
822
|
+
type MergeGunshiExtensions<G extends GunshiParamsConstraint, E extends ExtendContext> = GunshiParams<{
|
|
823
|
+
/**
|
|
824
|
+
* Command argument definitions.
|
|
825
|
+
*/
|
|
826
|
+
args: ExtractArgs<G>;
|
|
827
|
+
/**
|
|
828
|
+
* Merged command context extensions.
|
|
829
|
+
*/
|
|
830
|
+
extensions: ExtractExtensions<G> & E;
|
|
831
|
+
}>;
|
|
804
832
|
/**
|
|
805
833
|
* Command environment.
|
|
806
834
|
*
|
|
@@ -1106,7 +1134,7 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1106
1134
|
*
|
|
1107
1135
|
* @since v0.27.0
|
|
1108
1136
|
*/
|
|
1109
|
-
extensions: keyof ExtractExtensions
|
|
1137
|
+
extensions: keyof ExtractExtensions<G> extends never ? any : ExtractExtensions<G>;
|
|
1110
1138
|
/**
|
|
1111
1139
|
* Validation error from argument parsing.
|
|
1112
1140
|
* This will be set if argument validation fails during CLI execution.
|
|
@@ -1114,7 +1142,7 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
1114
1142
|
validationError?: AggregateError;
|
|
1115
1143
|
}
|
|
1116
1144
|
/**
|
|
1117
|
-
*
|
|
1145
|
+
* Readonly command context available to a command context extension factory.
|
|
1118
1146
|
*
|
|
1119
1147
|
* @typeParam G - A type extending {@linkcode GunshiParams} to specify the shape of command context.
|
|
1120
1148
|
*
|
|
@@ -1355,7 +1383,16 @@ type CommandLoader<G extends GunshiParamsConstraint = DefaultGunshiParams> = ()
|
|
|
1355
1383
|
*
|
|
1356
1384
|
* @internal
|
|
1357
1385
|
*/
|
|
1358
|
-
type
|
|
1386
|
+
type ExtractExtensionValues<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never };
|
|
1387
|
+
/**
|
|
1388
|
+
* Return type of {@link createCommandContext}
|
|
1389
|
+
*
|
|
1390
|
+
* @internal
|
|
1391
|
+
*/
|
|
1392
|
+
type CommandContextResult<G extends GunshiParamsConstraint, E extends Record<string, CommandContextExtension>> = {} extends ExtractExtensionValues<E> ? Readonly<CommandContext<G>> : Readonly<CommandContext<GunshiParams<{
|
|
1393
|
+
args: ExtractArgs<G>;
|
|
1394
|
+
extensions: ExtractExtensionValues<E>;
|
|
1395
|
+
}>>>;
|
|
1359
1396
|
/**
|
|
1360
1397
|
* Parameters of {@link createCommandContext}
|
|
1361
1398
|
*/
|
|
@@ -1442,24 +1479,27 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
|
|
|
1442
1479
|
commandPath,
|
|
1443
1480
|
omitted,
|
|
1444
1481
|
validationError
|
|
1445
|
-
}: CommandContextParams<G, V, C, E>): Promise<
|
|
1446
|
-
args: ExtractArgs<G>;
|
|
1447
|
-
extensions: ExtractExtensions<E>;
|
|
1448
|
-
}>>>>;
|
|
1482
|
+
}: CommandContextParams<G, V, C, E>): Promise<CommandContextResult<G, E>>;
|
|
1449
1483
|
//#endregion
|
|
1450
1484
|
//#region ../gunshi/src/definition.d.ts
|
|
1451
1485
|
/**
|
|
1452
|
-
*
|
|
1486
|
+
* The result type of the {@link define} function
|
|
1453
1487
|
*
|
|
1454
1488
|
* @internal
|
|
1455
1489
|
*/
|
|
1456
|
-
type
|
|
1490
|
+
type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiParams, C = {}> = Prettify<Pick<C, keyof C> & Partial<Pick<Command<G>, Exclude<keyof Command<G>, keyof C>>>>;
|
|
1457
1491
|
/**
|
|
1458
|
-
* The
|
|
1492
|
+
* The command definition accepted by {@link define} helpers.
|
|
1459
1493
|
*
|
|
1460
1494
|
* @internal
|
|
1461
1495
|
*/
|
|
1462
|
-
type
|
|
1496
|
+
type CommandDefinition<A extends Args, E extends ExtendContext, C extends Partial<Command<{
|
|
1497
|
+
args: A;
|
|
1498
|
+
extensions: E;
|
|
1499
|
+
}>>> = C & Command<{
|
|
1500
|
+
args: A;
|
|
1501
|
+
extensions: E;
|
|
1502
|
+
}>;
|
|
1463
1503
|
/**
|
|
1464
1504
|
* Define a {@link Command | command}.
|
|
1465
1505
|
*
|
|
@@ -1490,10 +1530,10 @@ type CommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
1490
1530
|
* @param definition - A {@link Command | command} definition
|
|
1491
1531
|
* @returns A defined {@link Command | command}
|
|
1492
1532
|
*/
|
|
1493
|
-
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends
|
|
1533
|
+
declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams, A extends Args = ExtractArgs<G>, C extends Partial<Command<{
|
|
1494
1534
|
args: A;
|
|
1495
|
-
extensions: ExtractExtensions
|
|
1496
|
-
}>): CommandDefinitionResult<G, C>;
|
|
1535
|
+
extensions: ExtractExtensions<G>;
|
|
1536
|
+
}>> = {}>(definition: CommandDefinition<A, ExtractExtensions<G>, C>): CommandDefinitionResult<G, C>;
|
|
1497
1537
|
/**
|
|
1498
1538
|
* Return type for defineWithTypes
|
|
1499
1539
|
*
|
|
@@ -1504,10 +1544,7 @@ declare function define<G extends GunshiParamsConstraint = DefaultGunshiParams,
|
|
|
1504
1544
|
type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs extends Args> = <A extends DefaultArgs = DefaultArgs, C extends Partial<Command<{
|
|
1505
1545
|
args: A;
|
|
1506
1546
|
extensions: DefaultExtensions;
|
|
1507
|
-
}>> = {}>(definition: C
|
|
1508
|
-
args: A;
|
|
1509
|
-
extensions: DefaultExtensions;
|
|
1510
|
-
}>) => CommandDefinitionResult<{
|
|
1547
|
+
}>> = {}>(definition: CommandDefinition<A, DefaultExtensions, C>) => CommandDefinitionResult<{
|
|
1511
1548
|
args: A;
|
|
1512
1549
|
extensions: DefaultExtensions;
|
|
1513
1550
|
}, C>;
|
|
@@ -1540,7 +1577,7 @@ type DefineWithTypesReturn<DefaultExtensions extends ExtendContext, DefaultArgs
|
|
|
1540
1577
|
*
|
|
1541
1578
|
* @since v0.27.0
|
|
1542
1579
|
*/
|
|
1543
|
-
declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWithTypesReturn<ExtractExtensions
|
|
1580
|
+
declare function defineWithTypes<G extends GunshiParamsConstraint>(): DefineWithTypesReturn<ExtractExtensions<G>, ExtractArgs<G>>;
|
|
1544
1581
|
/**
|
|
1545
1582
|
* Define a {@link LazyCommand | lazy command}.
|
|
1546
1583
|
*
|
|
@@ -1610,30 +1647,6 @@ declare function lazy<G extends GunshiParamsConstraint = DefaultGunshiParams, A
|
|
|
1610
1647
|
args: A;
|
|
1611
1648
|
extensions: {};
|
|
1612
1649
|
}, D>;
|
|
1613
|
-
/**
|
|
1614
|
-
* Normalize G to a full GunshiParams type
|
|
1615
|
-
*
|
|
1616
|
-
* @typeParam G - A {@link GunshiParamsConstraint} type
|
|
1617
|
-
*
|
|
1618
|
-
* @internal
|
|
1619
|
-
*/
|
|
1620
|
-
type NormalizeGunshiParams<G extends GunshiParamsConstraint> = G extends GunshiParams<any> ? G : G extends {
|
|
1621
|
-
args: infer A;
|
|
1622
|
-
extensions: infer E;
|
|
1623
|
-
} ? {
|
|
1624
|
-
args: A;
|
|
1625
|
-
extensions: E;
|
|
1626
|
-
} : G extends {
|
|
1627
|
-
args: infer A;
|
|
1628
|
-
} ? {
|
|
1629
|
-
args: A;
|
|
1630
|
-
extensions: {};
|
|
1631
|
-
} : G extends {
|
|
1632
|
-
extensions: infer E;
|
|
1633
|
-
} ? {
|
|
1634
|
-
args: Args;
|
|
1635
|
-
extensions: E;
|
|
1636
|
-
} : DefaultGunshiParams;
|
|
1637
1650
|
/**
|
|
1638
1651
|
* Return type for lazyWithTypes
|
|
1639
1652
|
*
|
|
@@ -1676,7 +1689,7 @@ type LazyWithTypesReturn<FullG extends GunshiParamsConstraint> = <D extends Part
|
|
|
1676
1689
|
*
|
|
1677
1690
|
* @since v0.27.0
|
|
1678
1691
|
*/
|
|
1679
|
-
declare function lazyWithTypes<G extends GunshiParamsConstraint>(): LazyWithTypesReturn<
|
|
1692
|
+
declare function lazyWithTypes<G extends GunshiParamsConstraint>(): LazyWithTypesReturn<NormalizeToGunshiParams<G>>;
|
|
1680
1693
|
//#endregion
|
|
1681
1694
|
//#region src/index.d.ts
|
|
1682
1695
|
/**
|
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.
|
|
4
|
+
"version": "0.33.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"jsr-exports-lint": "^0.4.2",
|
|
58
58
|
"publint": "^0.3.20",
|
|
59
59
|
"tsdown": "0.21.0",
|
|
60
|
-
"gunshi": "0.
|
|
60
|
+
"gunshi": "0.33.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|