@gunshi/shared 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 +23 -25
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -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
|
|
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> = A$1['multiple'] extends true
|
|
|
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
|
*
|
|
@@ -1044,9 +1044,7 @@ declare function log(...args: unknown[]): void;
|
|
|
1044
1044
|
* @param ignores - Properties to ignore during freezing
|
|
1045
1045
|
* @returns A frozen object
|
|
1046
1046
|
*/
|
|
1047
|
-
declare function deepFreeze<T extends Record<string, any>>(
|
|
1048
|
-
// eslint-disable-line @typescript-eslint/no-explicit-any -- NOTE(kazupon): generic type for deepFreeze
|
|
1049
|
-
obj: T, ignores?: string[]): Readonly<T>;
|
|
1047
|
+
declare function deepFreeze<T extends Record<string, any>>(obj: T, ignores?: string[]): Readonly<T>;
|
|
1050
1048
|
//#endregion
|
|
1051
1049
|
//#region src/constants.d.ts
|
|
1052
1050
|
/**
|
|
@@ -1088,7 +1086,7 @@ type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T]: T[K] }>;
|
|
|
1088
1086
|
/**
|
|
1089
1087
|
* Resolve a key on {@link Args}.
|
|
1090
1088
|
*/
|
|
1091
|
-
type KeyOfArgs<A
|
|
1089
|
+
type KeyOfArgs<A extends Args> = keyof A | { [K in keyof A]: A[K]['type'] extends 'boolean' ? A[K]['negatable'] extends true ? `no-${Extract<K, string>}` : never : never }[keyof A];
|
|
1092
1090
|
/**
|
|
1093
1091
|
* Generate a namespaced key.
|
|
1094
1092
|
*/
|
|
@@ -1113,27 +1111,27 @@ type CommandBuiltinKeys = GenerateNamespacedKey<BuiltinResourceKeys>;
|
|
|
1113
1111
|
* Command i18n option keys.
|
|
1114
1112
|
* The command i18n option keys are used by the i18n plugin for translation.
|
|
1115
1113
|
*/
|
|
1116
|
-
type CommandArgKeys<A
|
|
1114
|
+
type CommandArgKeys<A extends Args, C = {}, K$1 extends string = GenerateNamespacedKey<Extract<KeyOfArgs<RemovedIndex<A>>, string>, typeof ARG_PREFIX>> = C extends {
|
|
1117
1115
|
name: infer N;
|
|
1118
1116
|
} ? (N extends string ? GenerateNamespacedKey<K$1, N> : K$1) : K$1;
|
|
1119
1117
|
/**
|
|
1120
1118
|
* Resolve translation keys for command context.
|
|
1121
1119
|
*/
|
|
1122
|
-
type ResolveTranslationKeys<A
|
|
1120
|
+
type ResolveTranslationKeys<A extends Args, C = {},
|
|
1123
1121
|
// for CommandContext
|
|
1124
|
-
E
|
|
1122
|
+
E extends Record<string, string> = {},
|
|
1125
1123
|
// for extended resources
|
|
1126
|
-
R extends string = keyof RemovedIndex<E
|
|
1124
|
+
R extends string = keyof RemovedIndex<E>, T extends string = (C extends {
|
|
1127
1125
|
name: infer N;
|
|
1128
|
-
} ? N extends string ? GenerateNamespacedKey<R, N> : R : R | CommandBuiltinKeys), O = CommandArgKeys<A
|
|
1126
|
+
} ? N extends string ? GenerateNamespacedKey<R, N> : R : R | CommandBuiltinKeys), O = CommandArgKeys<A, C>> = CommandBuiltinKeys | O | T;
|
|
1129
1127
|
/**
|
|
1130
1128
|
* Translation function interface
|
|
1131
1129
|
*/
|
|
1132
|
-
interface Translation<A
|
|
1130
|
+
interface Translation<A extends Args, C = {},
|
|
1133
1131
|
// for CommandContext
|
|
1134
|
-
E
|
|
1132
|
+
E extends Record<string, string> = {},
|
|
1135
1133
|
// for extended resources
|
|
1136
|
-
K$1 = ResolveTranslationKeys<A
|
|
1134
|
+
K$1 = ResolveTranslationKeys<A, C, E>> {
|
|
1137
1135
|
(key: K$1, values?: Record<string, unknown>): string;
|
|
1138
1136
|
}
|
|
1139
1137
|
//#endregion
|
|
@@ -1145,10 +1143,10 @@ K$1 = ResolveTranslationKeys<A$1, C, E$1>> {
|
|
|
1145
1143
|
* @typeParam C - Additional context type for command localization.
|
|
1146
1144
|
* @typeParam E - Extended resource keys type.
|
|
1147
1145
|
*/
|
|
1148
|
-
interface Localization<A
|
|
1146
|
+
interface Localization<A extends Args, C = {},
|
|
1149
1147
|
// for CommandContext
|
|
1150
|
-
E
|
|
1151
|
-
<K$1 = ResolveTranslationKeys<A
|
|
1148
|
+
E extends Record<string, string> = {}> {
|
|
1149
|
+
<K$1 = ResolveTranslationKeys<A, C, E>>(key: K$1, values?: Record<string, unknown>): Promise<string>;
|
|
1152
1150
|
}
|
|
1153
1151
|
/**
|
|
1154
1152
|
* Create a localizable function for a command.
|
|
@@ -1164,11 +1162,11 @@ E$1 extends Record<string, string> = {}> {
|
|
|
1164
1162
|
* @param translate - Translation function
|
|
1165
1163
|
* @returns Localizable function
|
|
1166
1164
|
*/
|
|
1167
|
-
declare function localizable<A
|
|
1165
|
+
declare function localizable<A extends Args, C = {},
|
|
1168
1166
|
// for CommandContext
|
|
1169
|
-
E
|
|
1167
|
+
E extends Record<string, string> = {},
|
|
1170
1168
|
// for extended resources
|
|
1171
|
-
K$1 = ResolveTranslationKeys<A
|
|
1169
|
+
K$1 = ResolveTranslationKeys<A, C, E>>(ctx: CommandContext, cmd: Command, translate?: Translation<A, C, E, K$1>): Localization<A, C, E>;
|
|
1172
1170
|
//#endregion
|
|
1173
1171
|
//#region ../resources/locales/en-US.d.ts
|
|
1174
1172
|
declare let COMMAND: string;
|
|
@@ -1212,7 +1210,7 @@ declare function resolveBuiltInKey<K$1 extends string = CommandBuiltinResourceKe
|
|
|
1212
1210
|
* @param name - The command name.
|
|
1213
1211
|
* @returns Prefixed argument key.
|
|
1214
1212
|
*/
|
|
1215
|
-
declare function resolveArgKey<A
|
|
1213
|
+
declare function resolveArgKey<A extends Args = DefaultGunshiParams['args'], K$1 extends string = KeyOfArgs<RemovedIndex<A>>>(key: K$1, name?: string): string;
|
|
1216
1214
|
/**
|
|
1217
1215
|
* Resolve a namespaced key for non-built-in resources.
|
|
1218
1216
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/shared",
|
|
3
3
|
"description": "shared utils 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"
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"jsr-exports-lint": "^0.4.1",
|
|
56
56
|
"publint": "^0.3.16",
|
|
57
57
|
"tsdown": "0.15.12",
|
|
58
|
-
"@gunshi/resources": "0.27.
|
|
59
|
-
"gunshi": "0.27.
|
|
58
|
+
"@gunshi/resources": "0.27.4",
|
|
59
|
+
"gunshi": "0.27.4"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsdown",
|