@kubb/core 2.0.0-alpha.9 → 2.0.0-beta.2

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/src/build.ts CHANGED
@@ -157,11 +157,6 @@ export async function build(options: BuildOptions): Promise<BuildOutput> {
157
157
 
158
158
  const { fileManager, logger } = pluginManager
159
159
 
160
- await pluginManager.hookParallel<'validate', true>({
161
- hookName: 'validate',
162
- parameters: [pluginManager.plugins],
163
- })
164
-
165
160
  await pluginManager.hookParallel({
166
161
  hookName: 'buildStart',
167
162
  parameters: [options.config],
@@ -183,11 +178,6 @@ export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
183
178
  const { fileManager, logger } = pluginManager
184
179
 
185
180
  try {
186
- await pluginManager.hookParallel<'validate', true>({
187
- hookName: 'validate',
188
- parameters: [pluginManager.plugins],
189
- })
190
-
191
181
  await pluginManager.hookParallel({
192
182
  hookName: 'buildStart',
193
183
  parameters: [options.config],
package/src/plugin.ts CHANGED
@@ -26,10 +26,10 @@ type Options = {
26
26
  }
27
27
 
28
28
  // not publicly exported
29
- export type CorePluginOptions = PluginFactoryOptions<'core', 'controller', Options, Options, PluginContext, never>
29
+ export type CorePluginOptions = PluginFactoryOptions<'core', Options, Options, PluginContext, never>
30
30
 
31
31
  export const pluginName = 'core' satisfies CorePluginOptions['name']
32
- export const pluginKey: CorePluginOptions['key'] = ['controller', pluginName] satisfies CorePluginOptions['key']
32
+ export const pluginKey: CorePluginOptions['key'] = [pluginName] satisfies CorePluginOptions['key']
33
33
 
34
34
  export const definePlugin = createPlugin<CorePluginOptions>((options) => {
35
35
  const { fileManager, pluginManager, resolvePath, resolveName, logger } = options
@@ -37,8 +37,8 @@ export const definePlugin = createPlugin<CorePluginOptions>((options) => {
37
37
  return {
38
38
  name: pluginName,
39
39
  options,
40
- key: ['controller', 'core'],
41
- kind: 'controller',
40
+ key: ['core'],
41
+
42
42
  api() {
43
43
  return {
44
44
  get config() {
package/src/types.ts CHANGED
@@ -123,8 +123,6 @@ export type CLIOptions = {
123
123
 
124
124
  // plugin
125
125
 
126
- export type KubbPluginKind = 'schema' | 'controller'
127
-
128
126
  export type KubbUnionPlugins = PluginUnion
129
127
 
130
128
  export type KubbObjectPlugin = keyof OptionsPlugins
@@ -134,10 +132,6 @@ export type PluginFactoryOptions<
134
132
  * Name to be used for the plugin, this will also be used for they key.
135
133
  */
136
134
  TName extends string = string,
137
- /**
138
- * @type "schema" | "controller"
139
- */
140
- TKind extends KubbPluginKind = KubbPluginKind,
141
135
  /**
142
136
  * Options of the plugin.
143
137
  */
@@ -161,18 +155,17 @@ export type PluginFactoryOptions<
161
155
  TAppMeta = unknown,
162
156
  > = {
163
157
  name: TName
164
- kind: TKind
165
158
  /**
166
159
  * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
167
160
  */
168
- key: [kind: TKind | undefined, name: TName | string, identifier?: string | number]
161
+ key: [name: TName | string, identifier?: string | number]
169
162
  options: TOptions
170
163
  resolvedOptions: TResolvedOptions
171
164
  api: TAPI
172
165
  resolvePathOptions: TResolvePathOptions
173
166
  appMeta: {
174
167
  pluginManager: PluginManager
175
- plugin: KubbPlugin<PluginFactoryOptions<TName, TKind, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>
168
+ plugin: KubbPlugin<PluginFactoryOptions<TName, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>
176
169
  } & TAppMeta
177
170
  }
178
171
 
@@ -182,18 +175,23 @@ export type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactory
182
175
  & {
183
176
  /**
184
177
  * Unique name used for the plugin
178
+ * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
185
179
  * @example @kubb/typescript
186
180
  */
187
181
  name: TOptions['name']
188
- /**
189
- * Internal key used when a developer uses more than one of the same plugin
190
- * @private
191
- */
192
- key?: TOptions['key']
193
182
  /**
194
183
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
195
184
  */
196
185
  options: TOptions['resolvedOptions']
186
+ /**
187
+ * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
188
+ * Can be used to validate depended plugins.
189
+ */
190
+ pre?: Array<string>
191
+ /**
192
+ * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
193
+ */
194
+ post?: Array<string>
197
195
  }
198
196
  & (TOptions['api'] extends never ? {
199
197
  api?: never
@@ -201,22 +199,10 @@ export type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactory
201
199
  : {
202
200
  api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api']
203
201
  })
204
- & (TOptions['kind'] extends never ? {
205
- kind?: never
206
- }
207
- : {
208
- /**
209
- * Kind/type for the plugin
210
- * Type 'schema' can be used for JSON schema's, TypeScript types, ...
211
- * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
212
- * @default undefined
213
- */
214
- kind: TOptions['kind']
215
- })
216
202
 
217
203
  export type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>
218
204
 
219
- type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any, any>>
205
+ type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any>>
220
206
 
221
207
  export type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
222
208
  & {
@@ -231,16 +217,18 @@ export type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
231
217
  */
232
218
  key: TOptions['key']
233
219
  /**
234
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
220
+ * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
221
+ * Can be used to validate depended plugins.
235
222
  */
236
- options: TOptions['resolvedOptions']
223
+ pre?: Array<string>
237
224
  /**
238
- * Kind/type for the plugin
239
- * Type 'schema' can be used for JSON schema's, TypeScript types, ...
240
- * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
241
- * @default undefined
225
+ * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
242
226
  */
243
- kind?: TOptions['kind']
227
+ post?: Array<string>
228
+ /**
229
+ * Options set for a specific plugin(see kubb.config.js), passthrough of options.
230
+ */
231
+ options: TOptions['resolvedOptions']
244
232
  /**
245
233
  * Define an api that can be used by other plugins, see `PluginManager' where we convert from `KubbUserPlugin` to `KubbPlugin`(used when calling `createPlugin`).
246
234
  */
@@ -255,11 +243,6 @@ export type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
255
243
  export type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>
256
244
 
257
245
  export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
258
- /**
259
- * Valdiate all plugins to see if their depended plugins are installed and configured.
260
- * @type hookParallel
261
- */
262
- validate?: (this: Omit<PluginContext<TOptions>, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>
263
246
  /**
264
247
  * Start of the lifecycle of a plugin.
265
248
  * @type hookParallel
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable unused-imports/no-unused-vars */
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars */
3
- type PromiseFunc<T = unknown, T2 = never> = (state: T) => T2 extends never ? Promise<T> : Promise<T> | T2
3
+ type PromiseFunc<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2
4
4
 
5
5
  export type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc<infer X, infer Y>> ? X | Y : never
6
6
 
@@ -58,11 +58,23 @@ export function hookFirst<TInput extends Array<PromiseFunc<TValue, null>>, TValu
58
58
  return promise as TOutput
59
59
  }
60
60
 
61
- export type Strategy = 'seq' | 'first' | 'parallel' | 'reduceArg0'
61
+ type HookParallelOutput<TInput extends Array<PromiseFunc<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>
62
+
63
+ /**
64
+ * Run promises in parallel with allSettled
65
+ */
66
+ export function hookParallel<TInput extends Array<PromiseFunc<TValue, null>>, TValue = unknown, TOutput = HookParallelOutput<TInput, TValue>>(
67
+ promises: TInput,
68
+ ): TOutput {
69
+ return Promise.allSettled(promises.filter(Boolean).map(promise => promise())) as TOutput
70
+ }
71
+
72
+ export type Strategy = 'seq' | 'first' | 'parallel'
62
73
 
63
74
  export type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc<TValue, null>>, TValue> = TStrategy extends 'first'
64
75
  ? HookFirstOutput<TInput, TValue>
65
76
  : TStrategy extends 'seq' ? SeqOutput<TInput, TValue>
77
+ : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue>
66
78
  : never
67
79
 
68
80
  // tests