@kubb/core 2.0.0-alpha.8 → 2.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.
- package/README.md +1 -1
- package/dist/index.cjs +10 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -12
- package/dist/index.d.ts +20 -12
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +11 -12
- package/src/FileManager.ts +7 -7
- package/src/PluginManager.ts +8 -23
- package/src/PromiseManager.ts +5 -1
- package/src/types.ts +7 -0
- package/src/utils/executeStrategies.ts +14 -2
package/dist/index.d.cts
CHANGED
|
@@ -111,7 +111,7 @@ declare class PluginManager {
|
|
|
111
111
|
readonly executed: Executer[];
|
|
112
112
|
readonly logger: Logger;
|
|
113
113
|
constructor(config: KubbConfig, options: Options$2);
|
|
114
|
-
resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
|
|
114
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
115
115
|
resolveName: (params: ResolveNameParams) => string;
|
|
116
116
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
117
117
|
/**
|
|
@@ -355,7 +355,9 @@ type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions
|
|
|
355
355
|
} : {
|
|
356
356
|
/**
|
|
357
357
|
* Kind/type for the plugin
|
|
358
|
+
*
|
|
358
359
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
360
|
+
*
|
|
359
361
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
360
362
|
* @default undefined
|
|
361
363
|
*/
|
|
@@ -452,6 +454,11 @@ type ResolvePathParams<TOptions = object> = {
|
|
|
452
454
|
type ResolveNameParams = {
|
|
453
455
|
name: string;
|
|
454
456
|
pluginKey?: KubbPlugin['key'];
|
|
457
|
+
/**
|
|
458
|
+
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
459
|
+
* `function` can be used used to customize the exported functions(use of camelCase)
|
|
460
|
+
* `type` is a special type for TypeScript(use of PascalCase)
|
|
461
|
+
*/
|
|
455
462
|
type?: 'file' | 'function' | 'type';
|
|
456
463
|
};
|
|
457
464
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
@@ -480,7 +487,7 @@ declare namespace KubbFile {
|
|
|
480
487
|
/**
|
|
481
488
|
* Import name to be used
|
|
482
489
|
* @example ["useState"]
|
|
483
|
-
* @
|
|
490
|
+
* @example "React"
|
|
484
491
|
*/
|
|
485
492
|
name: string | Array<string>;
|
|
486
493
|
/**
|
|
@@ -489,28 +496,28 @@ declare namespace KubbFile {
|
|
|
489
496
|
*/
|
|
490
497
|
path: string;
|
|
491
498
|
/**
|
|
492
|
-
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'
|
|
499
|
+
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
493
500
|
*/
|
|
494
501
|
isTypeOnly?: boolean;
|
|
495
502
|
};
|
|
496
503
|
type Export = {
|
|
497
504
|
/**
|
|
498
|
-
* Export name to be used
|
|
505
|
+
* Export name to be used.
|
|
499
506
|
* @example ["useState"]
|
|
500
|
-
* @
|
|
507
|
+
* @example "React"
|
|
501
508
|
*/
|
|
502
509
|
name?: string | Array<string>;
|
|
503
510
|
/**
|
|
504
|
-
* Path for the import
|
|
511
|
+
* Path for the import.
|
|
505
512
|
* @xample '@kubb/core'
|
|
506
513
|
*/
|
|
507
514
|
path: string;
|
|
508
515
|
/**
|
|
509
|
-
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'
|
|
516
|
+
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
510
517
|
*/
|
|
511
518
|
isTypeOnly?: boolean;
|
|
512
519
|
/**
|
|
513
|
-
* Make it possible to override the name, this will result in: `export * as aliasName from './path'
|
|
520
|
+
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
514
521
|
*/
|
|
515
522
|
asAlias?: boolean;
|
|
516
523
|
};
|
|
@@ -697,12 +704,13 @@ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
697
704
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
698
705
|
declare const pluginName = "core";
|
|
699
706
|
|
|
700
|
-
type PromiseFunc$1<T = unknown, T2 = never> = (state
|
|
707
|
+
type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
701
708
|
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
|
|
702
709
|
type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
|
|
703
710
|
type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
|
|
704
|
-
type
|
|
705
|
-
type
|
|
711
|
+
type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
|
|
712
|
+
type Strategy = 'seq' | 'first' | 'parallel';
|
|
713
|
+
type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never;
|
|
706
714
|
|
|
707
715
|
type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
708
716
|
type Options<TState = any> = {
|
|
@@ -731,4 +739,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
731
739
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
732
740
|
type Plugin = keyof Plugins;
|
|
733
741
|
|
|
734
|
-
export { CLIOptions, FileManager, Generator, GetPluginFactoryOptions, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbPluginWithLifeCycle, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, KubbUserPluginWithLifeCycle, OptionsOfPlugin, OptionsPlugins, PackageManager, Plugin, PluginCache, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginUnion, Plugins, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, TransformResult, ValidationPluginError, Warning, _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
|
742
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginKind, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, SchemaGenerator, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
package/dist/index.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ declare class PluginManager {
|
|
|
111
111
|
readonly executed: Executer[];
|
|
112
112
|
readonly logger: Logger;
|
|
113
113
|
constructor(config: KubbConfig, options: Options$2);
|
|
114
|
-
resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
|
|
114
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
115
115
|
resolveName: (params: ResolveNameParams) => string;
|
|
116
116
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
117
117
|
/**
|
|
@@ -355,7 +355,9 @@ type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions
|
|
|
355
355
|
} : {
|
|
356
356
|
/**
|
|
357
357
|
* Kind/type for the plugin
|
|
358
|
+
*
|
|
358
359
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
360
|
+
*
|
|
359
361
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
360
362
|
* @default undefined
|
|
361
363
|
*/
|
|
@@ -452,6 +454,11 @@ type ResolvePathParams<TOptions = object> = {
|
|
|
452
454
|
type ResolveNameParams = {
|
|
453
455
|
name: string;
|
|
454
456
|
pluginKey?: KubbPlugin['key'];
|
|
457
|
+
/**
|
|
458
|
+
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
459
|
+
* `function` can be used used to customize the exported functions(use of camelCase)
|
|
460
|
+
* `type` is a special type for TypeScript(use of PascalCase)
|
|
461
|
+
*/
|
|
455
462
|
type?: 'file' | 'function' | 'type';
|
|
456
463
|
};
|
|
457
464
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
@@ -480,7 +487,7 @@ declare namespace KubbFile {
|
|
|
480
487
|
/**
|
|
481
488
|
* Import name to be used
|
|
482
489
|
* @example ["useState"]
|
|
483
|
-
* @
|
|
490
|
+
* @example "React"
|
|
484
491
|
*/
|
|
485
492
|
name: string | Array<string>;
|
|
486
493
|
/**
|
|
@@ -489,28 +496,28 @@ declare namespace KubbFile {
|
|
|
489
496
|
*/
|
|
490
497
|
path: string;
|
|
491
498
|
/**
|
|
492
|
-
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'
|
|
499
|
+
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
493
500
|
*/
|
|
494
501
|
isTypeOnly?: boolean;
|
|
495
502
|
};
|
|
496
503
|
type Export = {
|
|
497
504
|
/**
|
|
498
|
-
* Export name to be used
|
|
505
|
+
* Export name to be used.
|
|
499
506
|
* @example ["useState"]
|
|
500
|
-
* @
|
|
507
|
+
* @example "React"
|
|
501
508
|
*/
|
|
502
509
|
name?: string | Array<string>;
|
|
503
510
|
/**
|
|
504
|
-
* Path for the import
|
|
511
|
+
* Path for the import.
|
|
505
512
|
* @xample '@kubb/core'
|
|
506
513
|
*/
|
|
507
514
|
path: string;
|
|
508
515
|
/**
|
|
509
|
-
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'
|
|
516
|
+
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
510
517
|
*/
|
|
511
518
|
isTypeOnly?: boolean;
|
|
512
519
|
/**
|
|
513
|
-
* Make it possible to override the name, this will result in: `export * as aliasName from './path'
|
|
520
|
+
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
514
521
|
*/
|
|
515
522
|
asAlias?: boolean;
|
|
516
523
|
};
|
|
@@ -697,12 +704,13 @@ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
697
704
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
698
705
|
declare const pluginName = "core";
|
|
699
706
|
|
|
700
|
-
type PromiseFunc$1<T = unknown, T2 = never> = (state
|
|
707
|
+
type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
701
708
|
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
|
|
702
709
|
type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
|
|
703
710
|
type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
|
|
704
|
-
type
|
|
705
|
-
type
|
|
711
|
+
type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
|
|
712
|
+
type Strategy = 'seq' | 'first' | 'parallel';
|
|
713
|
+
type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never;
|
|
706
714
|
|
|
707
715
|
type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
708
716
|
type Options<TState = any> = {
|
|
@@ -731,4 +739,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
731
739
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
732
740
|
type Plugin = keyof Plugins;
|
|
733
741
|
|
|
734
|
-
export { CLIOptions, FileManager, Generator, GetPluginFactoryOptions, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbPluginWithLifeCycle, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, KubbUserPluginWithLifeCycle, OptionsOfPlugin, OptionsPlugins, PackageManager, Plugin, PluginCache, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginUnion, Plugins, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, TransformResult, ValidationPluginError, Warning, _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
|
742
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginKind, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, SchemaGenerator, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
package/dist/index.js
CHANGED
|
@@ -1195,6 +1195,9 @@ function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
|
1195
1195
|
}
|
|
1196
1196
|
return promise;
|
|
1197
1197
|
}
|
|
1198
|
+
function hookParallel(promises) {
|
|
1199
|
+
return Promise.allSettled(promises.filter(Boolean).map((promise) => promise()));
|
|
1200
|
+
}
|
|
1198
1201
|
|
|
1199
1202
|
// src/PromiseManager.ts
|
|
1200
1203
|
var _options2;
|
|
@@ -1211,6 +1214,9 @@ var PromiseManager = class {
|
|
|
1211
1214
|
if (strategy === "first") {
|
|
1212
1215
|
return hookFirst(promises, __privateGet(this, _options2).nullCheck);
|
|
1213
1216
|
}
|
|
1217
|
+
if (strategy === "parallel") {
|
|
1218
|
+
return hookParallel(promises);
|
|
1219
|
+
}
|
|
1214
1220
|
throw new Error(`${strategy} not implemented`);
|
|
1215
1221
|
}
|
|
1216
1222
|
};
|
|
@@ -1415,14 +1421,10 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1415
1421
|
hookName,
|
|
1416
1422
|
parameters
|
|
1417
1423
|
}) {
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
parallelPromises.push(promise);
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
const results = await Promise.allSettled(parallelPromises);
|
|
1424
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1425
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1426
|
+
});
|
|
1427
|
+
const results = await __privateGet(this, _promiseManager).run("parallel", promises);
|
|
1426
1428
|
results.forEach((result, index) => {
|
|
1427
1429
|
if (isPromiseRejectedResult(result)) {
|
|
1428
1430
|
const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
|