@gunshi/shared 0.27.0-beta.2 → 0.27.0-beta.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 CHANGED
@@ -1,7 +1,4 @@
1
- import en_US_default from "@gunshi/resources/en-US";
2
-
3
1
  //#region ../../node_modules/.pnpm/args-tokens@0.23.0/node_modules/args-tokens/lib/parser-C6MbpZjd.d.ts
4
-
5
2
  //#region src/parser.d.ts
6
3
  /**
7
4
  * Entry point of argument parser.
@@ -487,8 +484,8 @@ type IsFunction<T> = T extends ((...args: any[]) => any) ? true : false;
487
484
  *
488
485
  * @internal
489
486
  */
490
- 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>;
491
- 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> = A$1['multiple'] extends true ? T[] : T;
492
489
  /**
493
490
  * Resolved argument values.
494
491
  *
@@ -497,7 +494,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
497
494
  *
498
495
  * @internal
499
496
  */
500
- 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;
501
498
  /**
502
499
  * Filters the arguments based on their default values.
503
500
  *
@@ -507,7 +504,7 @@ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -r
507
504
  *
508
505
  * @internal
509
506
  */
510
- 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] };
511
508
  /**
512
509
  * Filters positional arguments from the argument schema.
513
510
  *
@@ -516,7 +513,7 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
516
513
  *
517
514
  * @internal
518
515
  */
519
- 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] };
520
517
  /**
521
518
  * An arguments for {@link resolveArgs | resolve arguments}.
522
519
  */
@@ -529,7 +526,7 @@ type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> =
529
526
  *
530
527
  * @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
531
528
  */
532
- type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
529
+ type ArgExplicitlyProvided<A$1 extends Args> = { [K in keyof A$1]: boolean };
533
530
  /**
534
531
  * Resolve command line arguments.
535
532
  *
@@ -585,7 +582,7 @@ type ExtendContext = Record<string, unknown>;
585
582
  *
586
583
  * @since v0.27.0
587
584
  */
588
- interface GunshiParams<P extends {
585
+ interface GunshiParams<P$1 extends {
589
586
  args?: Args;
590
587
  extensions?: ExtendContext;
591
588
  } = {
@@ -595,13 +592,13 @@ interface GunshiParams<P extends {
595
592
  /**
596
593
  * Command argument definitions.
597
594
  */
598
- args: P extends {
595
+ args: P$1 extends {
599
596
  args: infer A extends Args;
600
597
  } ? A : Args;
601
598
  /**
602
599
  * Command context extensions.
603
600
  */
604
- extensions: P extends {
601
+ extensions: P$1 extends {
605
602
  extensions: infer E extends ExtendContext;
606
603
  } ? E : {};
607
604
  }
@@ -1026,7 +1023,7 @@ declare function isLazyCommand<G extends GunshiParamsConstraint = DefaultGunshiP
1026
1023
  * @param needRunResolving - Whether to run the resolving function of the lazy command.
1027
1024
  * @returns A resolved {@link Command}
1028
1025
  */
1029
- declare function resolveLazyCommand<G extends GunshiParamsConstraint = DefaultGunshiParams>(cmd: Commandable<G>, name?: string | undefined, needRunResolving?: boolean): Promise<Command<G>>;
1026
+ declare function resolveLazyCommand<G extends GunshiParamsConstraint = DefaultGunshiParams>(cmd: Commandable<G>, name?: string, needRunResolving?: boolean): Promise<Command<G>>;
1030
1027
  /**
1031
1028
  * Create an object with the specified prototype. A shorthand for `Object.create`.
1032
1029
  *
@@ -1091,7 +1088,7 @@ type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T]: T[K] }>;
1091
1088
  /**
1092
1089
  * Resolve a key on {@link Args}.
1093
1090
  */
1094
- 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];
1091
+ type KeyOfArgs<A$1 extends Args> = keyof A$1 | { [K in keyof A$1]: A$1[K]['type'] extends 'boolean' ? A$1[K]['negatable'] extends true ? `no-${Extract<K, string>}` : never : never }[keyof A$1];
1095
1092
  /**
1096
1093
  * Generate a namespaced key.
1097
1094
  */
@@ -1116,28 +1113,28 @@ type CommandBuiltinKeys = GenerateNamespacedKey<BuiltinResourceKeys>;
1116
1113
  * Command i18n option keys.
1117
1114
  * The command i18n option keys are used by the i18n plugin for translation.
1118
1115
  */
1119
- type CommandArgKeys<A extends Args, C = {}, K extends string = GenerateNamespacedKey<Extract<KeyOfArgs<RemovedIndex<A>>, string>, typeof ARG_PREFIX>> = C extends {
1116
+ type CommandArgKeys<A$1 extends Args, C = {}, K$1 extends string = GenerateNamespacedKey<Extract<KeyOfArgs<RemovedIndex<A$1>>, string>, typeof ARG_PREFIX>> = C extends {
1120
1117
  name: infer N;
1121
- } ? (N extends string ? GenerateNamespacedKey<K, N> : K) : K;
1118
+ } ? (N extends string ? GenerateNamespacedKey<K$1, N> : K$1) : K$1;
1122
1119
  /**
1123
1120
  * Resolve translation keys for command context.
1124
1121
  */
1125
- type ResolveTranslationKeys<A extends Args, C = {},
1122
+ type ResolveTranslationKeys<A$1 extends Args, C = {},
1126
1123
  // for CommandContext
1127
- E extends Record<string, string> = {},
1124
+ E$1 extends Record<string, string> = {},
1128
1125
  // for extended resources
1129
- R extends string = keyof RemovedIndex<E>, T extends string = (C extends {
1126
+ R extends string = keyof RemovedIndex<E$1>, T extends string = (C extends {
1130
1127
  name: infer N;
1131
- } ? N extends string ? GenerateNamespacedKey<R, N> : R : R | CommandBuiltinKeys), O = CommandArgKeys<A, C>> = CommandBuiltinKeys | O | T;
1128
+ } ? N extends string ? GenerateNamespacedKey<R, N> : R : R | CommandBuiltinKeys), O = CommandArgKeys<A$1, C>> = CommandBuiltinKeys | O | T;
1132
1129
  /**
1133
1130
  * Translation function interface
1134
1131
  */
1135
- interface Translation<A extends Args, C = {},
1132
+ interface Translation<A$1 extends Args, C = {},
1136
1133
  // for CommandContext
1137
- E extends Record<string, string> = {},
1134
+ E$1 extends Record<string, string> = {},
1138
1135
  // for extended resources
1139
- K = ResolveTranslationKeys<A, C, E>> {
1140
- (key: K, values?: Record<string, unknown>): string;
1136
+ K$1 = ResolveTranslationKeys<A$1, C, E$1>> {
1137
+ (key: K$1, values?: Record<string, unknown>): string;
1141
1138
  }
1142
1139
  //#endregion
1143
1140
  //#region src/localization.d.ts
@@ -1148,10 +1145,10 @@ K = ResolveTranslationKeys<A, C, E>> {
1148
1145
  * @typeParam C - Additional context type for command localization.
1149
1146
  * @typeParam E - Extended resource keys type.
1150
1147
  */
1151
- interface Localization<A extends Args, C = {},
1148
+ interface Localization<A$1 extends Args, C = {},
1152
1149
  // for CommandContext
1153
- E extends Record<string, string> = {}> {
1154
- <K = ResolveTranslationKeys<A, C, E>>(key: K, values?: Record<string, unknown>): string;
1150
+ E$1 extends Record<string, string> = {}> {
1151
+ <K$1 = ResolveTranslationKeys<A$1, C, E$1>>(key: K$1, values?: Record<string, unknown>): Promise<string>;
1155
1152
  }
1156
1153
  /**
1157
1154
  * Create a localizable function for a command.
@@ -1167,11 +1164,29 @@ E extends Record<string, string> = {}> {
1167
1164
  * @param translate - Translation function
1168
1165
  * @returns Localizable function
1169
1166
  */
1170
- declare function localizable<A extends Args, C = {},
1167
+ declare function localizable<A$1 extends Args, C = {},
1171
1168
  // for CommandContext
1172
- E extends Record<string, string> = {},
1169
+ E$1 extends Record<string, string> = {},
1173
1170
  // for extended resources
1174
- K = ResolveTranslationKeys<A, C, E>>(ctx: CommandContext, cmd: Command, translate?: Translation<A, C, E, K>): Localization<A, C, E>;
1171
+ K$1 = ResolveTranslationKeys<A$1, C, E$1>>(ctx: CommandContext, cmd: Command, translate?: Translation<A$1, C, E$1, K$1>): Localization<A$1, C, E$1>;
1172
+ //#endregion
1173
+ //#region ../resources/locales/en-US.d.ts
1174
+ declare let COMMAND: string;
1175
+ declare let COMMANDS: string;
1176
+ declare let SUBCOMMAND: string;
1177
+ declare let USAGE: string;
1178
+ declare let ARGUMENTS: string;
1179
+ declare let OPTIONS: string;
1180
+ declare let EXAMPLES: string;
1181
+ declare let FORMORE: string;
1182
+ declare let NEGATABLE: string;
1183
+ declare let DEFAULT: string;
1184
+ declare let CHOICES: string;
1185
+ declare let help: string;
1186
+ declare let version: string;
1187
+ declare namespace __json_default_export {
1188
+ export { COMMAND, COMMANDS, SUBCOMMAND, USAGE, ARGUMENTS, OPTIONS, EXAMPLES, FORMORE, NEGATABLE, DEFAULT, CHOICES, help, version };
1189
+ }
1175
1190
  //#endregion
1176
1191
  //#region src/utils.d.ts
1177
1192
  /**
@@ -1184,7 +1199,7 @@ K = ResolveTranslationKeys<A, C, E>>(ctx: CommandContext, cmd: Command, translat
1184
1199
  * @param key - The built-in key to resolve.
1185
1200
  * @returns Prefixed built-in key.
1186
1201
  */
1187
- declare function resolveBuiltInKey<K extends string = CommandBuiltinResourceKeys>(key: K): GenerateNamespacedKey<K>;
1202
+ declare function resolveBuiltInKey<K$1 extends string = CommandBuiltinResourceKeys>(key: K$1): GenerateNamespacedKey<K$1>;
1188
1203
  /**
1189
1204
  * Resolve a namespaced key for argument resources.
1190
1205
  *
@@ -1197,7 +1212,7 @@ declare function resolveBuiltInKey<K extends string = CommandBuiltinResourceKeys
1197
1212
  * @param name - The command name.
1198
1213
  * @returns Prefixed argument key.
1199
1214
  */
1200
- declare function resolveArgKey<A extends Args = DefaultGunshiParams['args'], K extends string = KeyOfArgs<RemovedIndex<A>>>(key: K, name?: string): string;
1215
+ declare function resolveArgKey<A$1 extends Args = DefaultGunshiParams['args'], K$1 extends string = KeyOfArgs<RemovedIndex<A$1>>>(key: K$1, name?: string): string;
1201
1216
  /**
1202
1217
  * Resolve a namespaced key for non-built-in resources.
1203
1218
  *
@@ -1209,7 +1224,7 @@ declare function resolveArgKey<A extends Args = DefaultGunshiParams['args'], K e
1209
1224
  * @param name - The command name.
1210
1225
  * @returns Prefixed non-built-in key.
1211
1226
  */
1212
- declare function resolveKey<T extends Record<string, string> = {}, K = (keyof T extends string ? keyof T : string)>(key: K, name?: string): string;
1227
+ declare function resolveKey<T extends Record<string, string> = {}, K$1 extends string = (keyof T extends string ? keyof T : string)>(key: K$1, name?: string): string;
1213
1228
  /**
1214
1229
  * Resolve command examples.
1215
1230
  *
@@ -1228,7 +1243,7 @@ declare function resolveExamples<G extends GunshiParamsConstraint = DefaultGunsh
1228
1243
  * @param id - A plugin id to generate a namespaced key.
1229
1244
  * @returns A namespaced key for the plugin.
1230
1245
  */
1231
- declare function namespacedId<K extends string>(id: K): GenerateNamespacedKey<K, typeof PLUGIN_PREFIX>;
1246
+ declare function namespacedId<K$1 extends string>(id: K$1): GenerateNamespacedKey<K$1, typeof PLUGIN_PREFIX>;
1232
1247
  /**
1233
1248
  * Generate a short and long option pair for command arguments.
1234
1249
  *
@@ -1239,4 +1254,4 @@ declare function namespacedId<K extends string>(id: K): GenerateNamespacedKey<K,
1239
1254
  */
1240
1255
  declare function makeShortLongOptionPair(schema: ArgSchema, name: string, toKebab?: boolean): string;
1241
1256
  //#endregion
1242
- export { ARG_NEGATABLE_PREFIX, ARG_PREFIX, ARG_PREFIX_AND_KEY_SEPARATOR, BUILD_IN_PREFIX_AND_KEY_SEPARATOR, BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, BuiltinResourceKeys, COMMAND_BUILTIN_RESOURCE_KEYS, COMMON_ARGS, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, DeepWriteable, en_US_default as DefaultResource, GenerateNamespacedKey, KeyOfArgs, Localization, PLUGIN_PREFIX, RemovedIndex, ResolveTranslationKeys, Translation, create, deepFreeze, isLazyCommand, kebabnize, localizable, log, makeShortLongOptionPair, namespacedId, resolveArgKey, resolveBuiltInKey, resolveExamples, resolveKey, resolveLazyCommand };
1257
+ export { ARG_NEGATABLE_PREFIX, ARG_PREFIX, ARG_PREFIX_AND_KEY_SEPARATOR, BUILD_IN_PREFIX_AND_KEY_SEPARATOR, BUILT_IN_KEY_SEPARATOR, BUILT_IN_PREFIX, BuiltinResourceKeys, COMMAND_BUILTIN_RESOURCE_KEYS, COMMON_ARGS, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, DeepWriteable, __json_default_export as DefaultResource, GenerateNamespacedKey, KeyOfArgs, Localization, PLUGIN_PREFIX, RemovedIndex, ResolveTranslationKeys, Translation, create, deepFreeze, isLazyCommand, kebabnize, localizable, log, makeShortLongOptionPair, namespacedId, resolveArgKey, resolveBuiltInKey, resolveExamples, resolveKey, resolveLazyCommand };
package/lib/index.js CHANGED
@@ -146,38 +146,30 @@ const COMMAND_BUILTIN_RESOURCE_KEYS = [
146
146
 
147
147
  //#endregion
148
148
  //#region ../resources/locales/en-US.json
149
- var COMMAND = "COMMAND";
150
- var COMMANDS = "COMMANDS";
151
- var SUBCOMMAND = "SUBCOMMAND";
152
- var USAGE = "USAGE";
153
- var ARGUMENTS = "ARGUMENTS";
154
- var OPTIONS = "OPTIONS";
155
- var EXAMPLES = "EXAMPLES";
156
- var FORMORE = "For more info, run any command with the `--help` flag";
157
149
  var NEGATABLE = "Negatable of";
158
- var DEFAULT = "default";
159
- var CHOICES = "choices";
160
- var help = "Display this help message";
161
- var version = "Display this version";
162
150
  var en_US_default = {
163
- COMMAND,
164
- COMMANDS,
165
- SUBCOMMAND,
166
- USAGE,
167
- ARGUMENTS,
168
- OPTIONS,
169
- EXAMPLES,
170
- FORMORE,
151
+ COMMAND: "COMMAND",
152
+ COMMANDS: "COMMANDS",
153
+ SUBCOMMAND: "SUBCOMMAND",
154
+ USAGE: "USAGE",
155
+ ARGUMENTS: "ARGUMENTS",
156
+ OPTIONS: "OPTIONS",
157
+ EXAMPLES: "EXAMPLES",
158
+ FORMORE: "For more info, run any command with the `--help` flag",
171
159
  NEGATABLE,
172
- DEFAULT,
173
- CHOICES,
174
- help,
175
- version
160
+ DEFAULT: "default",
161
+ CHOICES: "choices",
162
+ help: "Display this help message",
163
+ version: "Display this version"
176
164
  };
177
165
 
178
166
  //#endregion
179
167
  //#region src/utils.ts
180
168
  /**
169
+ * @author kazuya kawaguchi (a.k.a. kazupon)
170
+ * @license MIT
171
+ */
172
+ /**
181
173
  * Resolve a namespaced key for built-in resources.
182
174
  *
183
175
  * Built-in keys are prefixed with "_:".
@@ -259,6 +251,10 @@ function makeShortLongOptionPair(schema, name, toKebab) {
259
251
  //#endregion
260
252
  //#region src/localization.ts
261
253
  /**
254
+ * @author kazuya kawaguchi (a.k.a. kazupon)
255
+ * @license MIT
256
+ */
257
+ /**
262
258
  * Create a localizable function for a command.
263
259
  *
264
260
  * This function will resolve the translation key based on the command context and the provided translation function.
@@ -286,7 +282,7 @@ function localizable(ctx, cmd, translate) {
286
282
  }
287
283
  const schema = ctx.args[argKey];
288
284
  if (!schema) return argKey;
289
- return negatable && schema.type === "boolean" && schema.negatable ? `${en_US_default["NEGATABLE"]} ${makeShortLongOptionPair(schema, argKey, ctx.toKebab)}` : schema.description || "";
285
+ return negatable && schema.type === "boolean" && schema.negatable ? `${NEGATABLE} ${makeShortLongOptionPair(schema, argKey, ctx.toKebab)}` : schema.description || "";
290
286
  }
291
287
  if (key === resolveKey("description", ctx.name)) return "";
292
288
  else if (key === resolveKey("examples", ctx.name)) return await resolveExamples(ctx, cmd.examples);
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.0-beta.2",
4
+ "version": "0.27.0-beta.4",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -50,13 +50,13 @@
50
50
  }
51
51
  },
52
52
  "devDependencies": {
53
- "deno": "^2.5.4",
53
+ "deno": "^2.5.6",
54
54
  "jsr": "^0.13.5",
55
55
  "jsr-exports-lint": "^0.4.1",
56
- "publint": "^0.3.14",
57
- "tsdown": "^0.15.6",
58
- "@gunshi/resources": "0.27.0-beta.2",
59
- "gunshi": "0.27.0-beta.2"
56
+ "publint": "^0.3.15",
57
+ "tsdown": "0.15.12",
58
+ "@gunshi/resources": "0.27.0-beta.4",
59
+ "gunshi": "0.27.0-beta.4"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "tsdown",