@gunshi/plugin 1.0.0-beta.0 → 1.0.0-beta.1

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.
Files changed (2) hide show
  1. package/lib/index.d.ts +25 -76
  2. package/package.json +3 -3
package/lib/index.d.ts CHANGED
@@ -55,9 +55,6 @@ interface ArgToken {
55
55
  */
56
56
  inlineValue?: boolean | undefined;
57
57
  }
58
- /**
59
- * Parser Options.
60
- */
61
58
  //#endregion
62
59
  //#region ../../node_modules/.pnpm/args-tokens@1.0.0-beta.1/node_modules/args-tokens/lib/resolver.d.ts
63
60
  //#region src/resolver.d.ts
@@ -701,7 +698,7 @@ interface Args {
701
698
  *
702
699
  * @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
703
700
  */
704
- type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]> }> : {
701
+ type ArgValues<T> = T extends Args ? ResolveArgValues<T, { [Arg in keyof T]: ExtractOptionValue<T[Arg]>; }> : {
705
702
  [option: string]: string | boolean | number | (string | boolean | number)[] | undefined;
706
703
  };
707
704
  /**
@@ -733,7 +730,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
733
730
  *
734
731
  * @internal
735
732
  */
736
- type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: IsPresentArg<A[Arg]> extends true ? unknown : V[Arg] } & { -readonly [Arg in keyof A as IsPresentArg<A[Arg]> extends true ? Arg : never]: V[Arg] } extends (infer P) ? { [K in keyof P]: P[K] } : never;
733
+ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: IsPresentArg<A[Arg]> extends true ? unknown : V[Arg]; } & { -readonly [Arg in keyof A as IsPresentArg<A[Arg]> extends true ? Arg : never]: V[Arg]; } extends (infer P) ? { [K in keyof P]: P[K]; } : never;
737
734
  /**
738
735
  * Whether an argument with the schema `S` has a value: with a default, with `required: true` or as
739
736
  * a required positional argument. For a union of schemas, only when each schema of the union has
@@ -741,16 +738,6 @@ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -r
741
738
  * value, as {@link FilterArgs} does.
742
739
  */
743
740
  type IsPresentArg<S extends ArgSchema> = S extends ArgSchema ? true extends (S['default'] extends {} ? true : S['required'] extends true ? true : false) ? true : IsRequiredPositionalArg<S> : never;
744
- /**
745
- * Filters the arguments based on their default values.
746
- *
747
- * @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
748
- * @typeParam V - Resolvable argument values.
749
- * @typeParam K - Key of the {@link ArgSchema | argument schema} to filter by.
750
- *
751
- * @internal
752
- */
753
-
754
741
  type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positional' ? A['multiple'] extends true ? A['required'] extends true ? true : false : MayBeUnrequired<A> extends true ? A['default'] extends {} ? true : false : true : false;
755
742
  /**
756
743
  * Whether the `required` of `A` may be `false`. An optional `required` of type `boolean`, as in
@@ -761,10 +748,6 @@ type IsRequiredPositionalArg<A extends ArgSchema> = A['type'] extends 'positiona
761
748
  type MayBeUnrequired<A extends ArgSchema> = false extends A['required'] ? [A] extends [{
762
749
  required: unknown;
763
750
  }] ? true : boolean | undefined extends A['required'] ? false : true : false;
764
- /**
765
- * An arguments for {@link resolveArgs | resolve arguments}.
766
- */
767
-
768
751
  /**
769
752
  * Tracks which arguments were explicitly provided by the user.
770
753
  *
@@ -777,7 +760,7 @@ type MayBeUnrequired<A extends ArgSchema> = false extends A['required'] ? [A] ex
777
760
  *
778
761
  * @typeParam A - {@link Args | Arguments}, which is an object that defines the command line arguments.
779
762
  */
780
- type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
763
+ type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean; };
781
764
  //#endregion
782
765
  //#region ../gunshi/src/plugin/context.d.ts
783
766
  /**
@@ -858,12 +841,12 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
858
841
  }
859
842
  //#endregion
860
843
  //#region ../gunshi/src/plugin/core.d.ts
861
- type ProcessDependency<D, A extends ExtendContext> = D extends string ? D extends keyof A ? { [K in D]: A[K] } : {} : D extends {
844
+ type ProcessDependency<D, A extends ExtendContext> = D extends string ? D extends keyof A ? { [K in D]: A[K]; } : {} : D extends {
862
845
  id: infer ID;
863
846
  optional?: any;
864
847
  } ? ID extends string ? ID extends keyof A ? D extends {
865
848
  optional: true;
866
- } ? { [K in ID]: A[K] | undefined } : { [K in ID]: A[K] } : {} : never : never;
849
+ } ? { [K in ID]: A[K] | undefined; } : { [K in ID]: A[K]; } : {} : never : never;
867
850
  /**
868
851
  * Helper type to infer dependency extensions with optional support
869
852
  *
@@ -919,7 +902,7 @@ type PluginExtension<T = Record<string, unknown>, G extends GunshiParams = Defau
919
902
  */
920
903
  type OnPluginExtension<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>, cmd: Readonly<Command<G>>) => Awaitable<void>;
921
904
  type IsStringLiteral<S extends string> = string extends S ? false : true;
922
- type MergeExtension<Id, ResolvedDepExt extends ExtendContext, PluginExt extends ExtendContext> = Id extends infer I ? I extends string ? IsStringLiteral<I> extends true ? ResolvedDepExt & { [K in I]: PluginExt } : ResolvedDepExt : ResolvedDepExt : ResolvedDepExt;
905
+ type MergeExtension<Id, ResolvedDepExt extends ExtendContext, PluginExt extends ExtendContext> = Id extends (infer I) ? I extends string ? IsStringLiteral<I> extends true ? ResolvedDepExt & { [K in I]: PluginExt; } : ResolvedDepExt : ResolvedDepExt : ResolvedDepExt;
923
906
  /**
924
907
  * Extensions resolved from the declared plugin dependencies.
925
908
  *
@@ -955,15 +938,11 @@ type MergedPluginParams<Id extends string, Deps extends ReadonlyArray<PluginDepe
955
938
  *
956
939
  * @since v0.27.0
957
940
  */
958
- interface PluginOptions<DepExt extends ExtendContext = DefaultGunshiParams['extensions'],
959
- // for plugin dependency extensions
960
- Id extends string = string,
961
- // for plugin id
962
- Deps extends ReadonlyArray<PluginDependency | string> = (PluginDependency | string)[],
963
- // for plugin dependencies
964
- Ext extends Record<string, unknown> = {},
965
- // for plugin extension type
966
- ResolvedDepExt extends GunshiParams = DependencyParams<Deps, DepExt>, PluginExt extends PluginExtension<Ext, ResolvedDepExt> = PluginExtension<Ext, ResolvedDepExt>, MergedExt extends GunshiParams = MergedPluginParams<Id, Deps, DepExt, Awaited<ReturnType<PluginExt>>>> {
941
+ interface PluginOptions<DepExt extends ExtendContext = DefaultGunshiParams['extensions'] // for plugin dependency extensions
942
+ , Id extends string = string // for plugin id
943
+ , Deps extends ReadonlyArray<PluginDependency | string> = (PluginDependency | string)[] // for plugin dependencies
944
+ , Ext extends Record<string, unknown> = {} // for plugin extension type
945
+ , ResolvedDepExt extends GunshiParams = DependencyParams<Deps, DepExt>, PluginExt extends PluginExtension<Ext, ResolvedDepExt> = PluginExtension<Ext, ResolvedDepExt>, MergedExt extends GunshiParams = MergedPluginParams<Id, Deps, DepExt, Awaited<ReturnType<PluginExt>>>> {
967
946
  /**
968
947
  * Plugin unique identifier.
969
948
  *
@@ -1066,15 +1045,11 @@ interface PluginWithoutExtension<E extends GunshiParams['extensions'] = DefaultG
1066
1045
  *
1067
1046
  * @since v0.27.0
1068
1047
  */
1069
- declare function plugin<Context extends ExtendContext = DefaultGunshiParams['extensions'],
1070
- // for plugin dependency extensions
1071
- Id extends string = string,
1072
- // for plugin id
1073
- Deps extends ReadonlyArray<PluginDependency | string> = [],
1074
- // for plugin dependencies
1075
- Extension extends {} = {},
1076
- // for plugin extension type
1077
- ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>(options: {
1048
+ declare function plugin<Context extends ExtendContext = DefaultGunshiParams['extensions'] // for plugin dependency extensions
1049
+ , Id extends string = string // for plugin id
1050
+ , Deps extends ReadonlyArray<PluginDependency | string> = [] // for plugin dependencies
1051
+ , Extension extends {} = {} // for plugin extension type
1052
+ , ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>(options: {
1078
1053
  id: Id;
1079
1054
  name?: string;
1080
1055
  dependencies?: Deps;
@@ -1095,15 +1070,11 @@ ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, Pl
1095
1070
  *
1096
1071
  * @since v0.27.0
1097
1072
  */
1098
- declare function plugin<Context extends ExtendContext = DefaultGunshiParams['extensions'],
1099
- // for plugin dependency extensions
1100
- Id extends string = string,
1101
- // for plugin id
1102
- Deps extends ReadonlyArray<PluginDependency | string> = [],
1103
- // for plugin dependencies
1104
- Extension extends Record<string, unknown> = {},
1105
- // for plugin extension type
1106
- ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>(options: {
1073
+ declare function plugin<Context extends ExtendContext = DefaultGunshiParams['extensions'] // for plugin dependency extensions
1074
+ , Id extends string = string // for plugin id
1075
+ , Deps extends ReadonlyArray<PluginDependency | string> = [] // for plugin dependencies
1076
+ , Extension extends Record<string, unknown> = {} // for plugin extension type
1077
+ , ResolvedDepExtensions extends GunshiParams = DependencyParams<Deps, Context>, PluginExt extends PluginExtension<Extension, DefaultGunshiParams> = PluginExtension<Extension, ResolvedDepExtensions>, MergedExtensions extends GunshiParams = MergedPluginParams<Id, Deps, Context, Awaited<ReturnType<PluginExt>>>>(options: {
1107
1078
  id: Id;
1108
1079
  name?: string;
1109
1080
  dependencies?: Deps;
@@ -1123,7 +1094,7 @@ type Awaitable<T> = T | Promise<T>;
1123
1094
  *
1124
1095
  * @typeParam T - The type to be prettified.
1125
1096
  */
1126
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
1097
+ type Prettify<T> = { [K in keyof T]: T[K]; } & {};
1127
1098
  /**
1128
1099
  * Extend command context type. This type is used to extend the command context with additional properties at {@linkcode CommandContext.extensions}.
1129
1100
  *
@@ -1876,7 +1847,7 @@ declare const CLI_OPTIONS_DEFAULT: CliOptions<DefaultGunshiParams>;
1876
1847
  *
1877
1848
  * @internal
1878
1849
  */
1879
- type ExtractExtensionValues<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never };
1850
+ type ExtractExtensionValues<E extends Record<string, CommandContextExtension>> = { [K in keyof E]: E[K] extends CommandContextExtension<infer T> ? T : never; };
1880
1851
  /**
1881
1852
  * Return type of {@link createCommandContext}
1882
1853
  *
@@ -1957,22 +1928,7 @@ interface CommandContextParams<G extends GunshiParams | {
1957
1928
  * @param param - A {@link CommandContextParams | parameters} to create a command context.
1958
1929
  * @returns A {@link CommandContext | command context}, which is readonly.
1959
1930
  */
1960
- 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> = {}>({
1961
- args,
1962
- explicit,
1963
- values,
1964
- positionals,
1965
- rest,
1966
- argv,
1967
- tokens,
1968
- command,
1969
- extensions,
1970
- cliOptions,
1971
- callMode,
1972
- commandPath,
1973
- omitted,
1974
- validationError
1975
- }: CommandContextParams<G, V, C, E>): Promise<CommandContextResult<G, E>>;
1931
+ 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> = {}>({ args, explicit, values, positionals, rest, argv, tokens, command, extensions, cliOptions, callMode, commandPath, omitted, validationError }: CommandContextParams<G, V, C, E>): Promise<CommandContextResult<G, E>>;
1976
1932
  //#endregion
1977
1933
  //#region ../gunshi/src/error.d.ts
1978
1934
  /**
@@ -2128,11 +2084,4 @@ declare function isArgsValidationError(error: unknown): error is ArgsValidationE
2128
2084
  */
2129
2085
  declare function hasPriorityValidationError(error: AggregateError | undefined): boolean;
2130
2086
  //#endregion
2131
- //#region src/index.d.ts
2132
- /**
2133
- * @author kazuya kawaguchi (a.k.a. kazupon)
2134
- * @license MIT
2135
- */
2136
-
2137
- //#endregion
2138
- export { ANONYMOUS_COMMAND_NAME, type ArgSchema, type ArgToken, type ArgValues, type Args, ArgsValidationError, ArgsValidationErrorCode, ArgsValidationErrorKeys, Awaitable, CLI_OPTIONS_DEFAULT, Command, CommandContext, CommandContextCore, CommandContextExtension, CommandContextParams, CommandDecorator, CommandExamplesFetcher, CommandNotFoundError, CommandNotFoundErrorCode, CommandNotFoundErrorKeys, CommandNotFoundErrorOptions, CommandResolutionError, CommandResolutionErrorCode, CommandResolutionErrorKeys, CommandResolutionErrorOptions, CommandRunner, DefaultGunshiParams, ExtendContext, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, LazyCommand, MergeGunshiExtensions, NormalizeToGunshiParams, OnPluginExtension, Plugin, PluginContext, PluginDependency, PluginExtension, PluginFunction, PluginOptions, PluginWithExtension, PluginWithoutExtension, Prettify, RendererDecorator, ValidationErrorsDecorator, createCommandContext, hasPriorityValidationError, isArgsValidationError, isCommandNotFoundError, isCommandResolutionError, plugin };
2087
+ export { ANONYMOUS_COMMAND_NAME, type ArgSchema, type ArgToken, type ArgValues, type Args, ArgsValidationError, type ArgsValidationErrorCode, ArgsValidationErrorKeys, type Awaitable, CLI_OPTIONS_DEFAULT, type Command, type CommandContext, type CommandContextCore, type CommandContextExtension, type CommandContextParams, type CommandDecorator, type CommandExamplesFetcher, CommandNotFoundError, type CommandNotFoundErrorCode, CommandNotFoundErrorKeys, type CommandNotFoundErrorOptions, CommandResolutionError, type CommandResolutionErrorCode, CommandResolutionErrorKeys, type CommandResolutionErrorOptions, type CommandRunner, type DefaultGunshiParams, type ExtendContext, type ExtractArgs, type ExtractExtensions, type GunshiParams, type GunshiParamsConstraint, type LazyCommand, type MergeGunshiExtensions, type NormalizeToGunshiParams, type OnPluginExtension, type Plugin, type PluginContext, type PluginDependency, type PluginExtension, type PluginFunction, type PluginOptions, type PluginWithExtension, type PluginWithoutExtension, type Prettify, type RendererDecorator, type ValidationErrorsDecorator, createCommandContext, hasPriorityValidationError, isArgsValidationError, isCommandNotFoundError, isCommandResolutionError, 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": "1.0.0-beta.0",
4
+ "version": "1.0.0-beta.1",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -52,11 +52,11 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "deno": "^2.7.14",
55
+ "gunshi": "1.0.0-beta.1",
55
56
  "jsr": "^0.14.3",
56
57
  "jsr-exports-lint": "^0.4.2",
57
58
  "publint": "^0.3.20",
58
- "tsdown": "0.21.0",
59
- "gunshi": "1.0.0-beta.0"
59
+ "tsdown": "0.22.14"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "tsdown",