@kubb/core 2.11.1 → 2.12.0

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 (92) hide show
  1. package/dist/{chunk-4GE2JRAA.cjs → chunk-33S7A7ZE.cjs} +28 -5
  2. package/dist/chunk-33S7A7ZE.cjs.map +1 -0
  3. package/dist/{chunk-CH2676BL.js → chunk-4BZD7YTT.js} +2 -2
  4. package/dist/{chunk-G7EQ47A4.js → chunk-ALE7CO7I.js} +26 -3
  5. package/dist/chunk-ALE7CO7I.js.map +1 -0
  6. package/dist/{chunk-WAIHMG76.cjs → chunk-F4TSJHGA.cjs} +3 -3
  7. package/dist/chunk-FOWWV3PP.js +41 -0
  8. package/dist/chunk-FOWWV3PP.js.map +1 -0
  9. package/dist/{chunk-XZZ2F3LK.cjs → chunk-IBUMXAET.cjs} +3 -3
  10. package/dist/{chunk-WXV3UNEP.js → chunk-IP732R22.js} +1 -29
  11. package/dist/chunk-IP732R22.js.map +1 -0
  12. package/dist/chunk-KPXUT3DG.cjs +143 -0
  13. package/dist/chunk-KPXUT3DG.cjs.map +1 -0
  14. package/dist/{chunk-UYADU5OY.js → chunk-L2OHRGUS.js} +7 -3
  15. package/dist/chunk-L2OHRGUS.js.map +1 -0
  16. package/dist/{chunk-JDIEEDDB.cjs → chunk-OMX2RMAX.cjs} +3 -3
  17. package/dist/{chunk-TJHTFTXA.cjs → chunk-OVLOS3IJ.cjs} +267 -347
  18. package/dist/chunk-OVLOS3IJ.cjs.map +1 -0
  19. package/dist/{chunk-KOQSM5X7.cjs → chunk-VHRZO2NC.cjs} +20 -20
  20. package/dist/chunk-VHRZO2NC.cjs.map +1 -0
  21. package/dist/chunk-YYCT7ZB7.cjs +94 -0
  22. package/dist/chunk-YYCT7ZB7.cjs.map +1 -0
  23. package/dist/{chunk-H7U5WQ3I.js → chunk-Z5N655B7.js} +20 -20
  24. package/dist/chunk-Z5N655B7.js.map +1 -0
  25. package/dist/{chunk-DOELQNBO.cjs → chunk-ZS3YTJ2L.cjs} +3 -133
  26. package/dist/chunk-ZS3YTJ2L.cjs.map +1 -0
  27. package/dist/fs.cjs +5 -4
  28. package/dist/fs.cjs.map +1 -1
  29. package/dist/fs.js +3 -3
  30. package/dist/index.cjs +2672 -83
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +6 -1
  33. package/dist/index.d.ts +6 -1
  34. package/dist/index.js +1981 -52
  35. package/dist/index.js.map +1 -1
  36. package/dist/logger.cjs +4 -3
  37. package/dist/logger.js +2 -2
  38. package/dist/mocks.cjs +6 -10
  39. package/dist/mocks.cjs.map +1 -1
  40. package/dist/mocks.js +1 -6
  41. package/dist/mocks.js.map +1 -1
  42. package/dist/transformers.cjs +34 -21
  43. package/dist/transformers.cjs.map +1 -1
  44. package/dist/transformers.d.cts +4 -2
  45. package/dist/transformers.d.ts +4 -2
  46. package/dist/transformers.js +24 -11
  47. package/dist/transformers.js.map +1 -1
  48. package/dist/utils.cjs +28 -26
  49. package/dist/utils.cjs.map +1 -1
  50. package/dist/utils.js +29 -27
  51. package/dist/utils.js.map +1 -1
  52. package/package.json +4 -3
  53. package/src/BarrelManager.ts +33 -31
  54. package/src/FileManager.ts +176 -137
  55. package/src/PackageManager.ts +4 -4
  56. package/src/PluginManager.ts +62 -52
  57. package/src/build.ts +28 -9
  58. package/src/config.ts +3 -3
  59. package/src/fs/write.ts +6 -2
  60. package/src/index.ts +1 -1
  61. package/src/transformers/casing.ts +11 -5
  62. package/src/transformers/escape.ts +2 -4
  63. package/src/transformers/index.ts +3 -2
  64. package/src/transformers/stringify.ts +19 -3
  65. package/src/transformers/toNumber.ts +1 -1
  66. package/src/transformers/toRegExp.ts +1 -5
  67. package/src/types.ts +67 -71
  68. package/src/utils/FunctionParams.ts +24 -23
  69. package/src/utils/TreeNode.ts +15 -4
  70. package/src/utils/URLPath.ts +2 -6
  71. package/src/utils/executeStrategies.ts +7 -7
  72. package/src/utils/index.ts +5 -1
  73. package/dist/chunk-4GE2JRAA.cjs.map +0 -1
  74. package/dist/chunk-B7DTFNR4.js +0 -30
  75. package/dist/chunk-B7DTFNR4.js.map +0 -1
  76. package/dist/chunk-DOELQNBO.cjs.map +0 -1
  77. package/dist/chunk-G7EQ47A4.js.map +0 -1
  78. package/dist/chunk-H7U5WQ3I.js.map +0 -1
  79. package/dist/chunk-KOQSM5X7.cjs.map +0 -1
  80. package/dist/chunk-TJHTFTXA.cjs.map +0 -1
  81. package/dist/chunk-UIWHEBZA.cjs +0 -2549
  82. package/dist/chunk-UIWHEBZA.cjs.map +0 -1
  83. package/dist/chunk-UUBXTHJG.cjs +0 -30
  84. package/dist/chunk-UUBXTHJG.cjs.map +0 -1
  85. package/dist/chunk-UYADU5OY.js.map +0 -1
  86. package/dist/chunk-WXV3UNEP.js.map +0 -1
  87. package/dist/chunk-ZNYG4U5D.js +0 -1888
  88. package/dist/chunk-ZNYG4U5D.js.map +0 -1
  89. /package/dist/{chunk-CH2676BL.js.map → chunk-4BZD7YTT.js.map} +0 -0
  90. /package/dist/{chunk-WAIHMG76.cjs.map → chunk-F4TSJHGA.cjs.map} +0 -0
  91. /package/dist/{chunk-XZZ2F3LK.cjs.map → chunk-IBUMXAET.cjs.map} +0 -0
  92. /package/dist/{chunk-JDIEEDDB.cjs.map → chunk-OMX2RMAX.cjs.map} +0 -0
package/src/build.ts CHANGED
@@ -50,7 +50,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
50
50
  } catch (e) {
51
51
  if (isInputPath(config)) {
52
52
  throw new Error(
53
- 'Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config ' + c.dim(config.input.path),
53
+ `Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${c.dim(config.input.path)}`,
54
54
  {
55
55
  cause: e,
56
56
  },
@@ -128,7 +128,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
128
128
  }
129
129
 
130
130
  if (count === 0) {
131
- logger.emit('start', `💾 Writing`)
131
+ logger.emit('start', '💾 Writing')
132
132
  }
133
133
  })
134
134
 
@@ -142,7 +142,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
142
142
 
143
143
  logger.spinner.suffixText = c.dim(text)
144
144
  }
145
- ;++count
145
+ ++count
146
146
  })
147
147
 
148
148
  pluginManager.queue.on('completed', () => {
@@ -163,7 +163,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
163
163
  if (logger.logLevel === LogLevel.debug) {
164
164
  const logs = [
165
165
  `${randomCliColour(plugin.name)} Executing ${hookName}`,
166
- parameters && `${c.bgWhite(`Parameters`)} ${randomCliColour(plugin.name)} ${hookName}`,
166
+ parameters && `${c.bgWhite('Parameters')} ${randomCliColour(plugin.name)} ${hookName}`,
167
167
  JSON.stringify(parameters, undefined, 2),
168
168
  output && `${c.bgWhite('Output')} ${randomCliColour(plugin.name)} ${hookName}`,
169
169
  output,
@@ -189,10 +189,16 @@ export async function build(options: BuildOptions): Promise<BuildOutput> {
189
189
  await pluginManager.hookParallel({ hookName: 'buildEnd' })
190
190
 
191
191
  if (logger.logLevel === LogLevel.info) {
192
- logger.emit('end', `💾 Writing completed`)
192
+ logger.emit('end', '💾 Writing completed')
193
193
  }
194
194
 
195
- return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager }
195
+ return {
196
+ files: fileManager.files.map((file) => ({
197
+ ...file,
198
+ source: FileManager.getSource(file),
199
+ })),
200
+ pluginManager,
201
+ }
196
202
  }
197
203
 
198
204
  export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
@@ -209,11 +215,24 @@ export async function safeBuild(options: BuildOptions): Promise<BuildOutput> {
209
215
  await pluginManager.hookParallel({ hookName: 'buildEnd' })
210
216
 
211
217
  if (logger.logLevel === LogLevel.info) {
212
- logger.emit('end', `💾 Writing completed`)
218
+ logger.emit('end', '💾 Writing completed')
213
219
  }
214
220
  } catch (e) {
215
- return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager, error: e as Error }
221
+ return {
222
+ files: fileManager.files.map((file) => ({
223
+ ...file,
224
+ source: FileManager.getSource(file),
225
+ })),
226
+ pluginManager,
227
+ error: e as Error,
228
+ }
216
229
  }
217
230
 
218
- return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager }
231
+ return {
232
+ files: fileManager.files.map((file) => ({
233
+ ...file,
234
+ source: FileManager.getSource(file),
235
+ })),
236
+ pluginManager,
237
+ }
219
238
  }
package/src/config.ts CHANGED
@@ -10,9 +10,9 @@ export function defineConfig(
10
10
  options:
11
11
  | PossiblePromise<UserConfig | Array<UserConfig>>
12
12
  | ((
13
- /** The options derived from the CLI flags */
14
- cliOptions: CLIOptions,
15
- ) => PossiblePromise<UserConfig | Array<UserConfig>>),
13
+ /** The options derived from the CLI flags */
14
+ cliOptions: CLIOptions,
15
+ ) => PossiblePromise<UserConfig | Array<UserConfig>>),
16
16
  ): typeof options {
17
17
  return options
18
18
  }
package/src/fs/write.ts CHANGED
@@ -9,7 +9,9 @@ const writer = switcher(
9
9
  {
10
10
  node: async (path: string, data: string, { sanity }: Options) => {
11
11
  try {
12
- const oldContent = await fs.readFile(resolve(path), { encoding: 'utf-8' })
12
+ const oldContent = await fs.readFile(resolve(path), {
13
+ encoding: 'utf-8',
14
+ })
13
15
  if (oldContent?.toString() === data?.toString()) {
14
16
  return
15
17
  }
@@ -20,7 +22,9 @@ const writer = switcher(
20
22
  await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })
21
23
 
22
24
  if (sanity) {
23
- const savedData = await fs.readFile(resolve(path), { encoding: 'utf-8' })
25
+ const savedData = await fs.readFile(resolve(path), {
26
+ encoding: 'utf-8',
27
+ })
24
28
 
25
29
  if (savedData?.toString() !== data?.toString()) {
26
30
  throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
package/src/index.ts CHANGED
@@ -4,12 +4,12 @@ export { Warning } from './errors.ts'
4
4
  export { FileManager, KubbFile } from './FileManager.ts'
5
5
  export { Generator } from './Generator.ts'
6
6
  export { PackageManager } from './PackageManager.ts'
7
- // dprint-ignore
8
7
  export { createPlugin, pluginName as name, pluginName } from './plugin.ts'
9
8
  export { PluginManager } from './PluginManager.ts'
10
9
  export { PromiseManager } from './PromiseManager.ts'
11
10
  export type * from './types.ts'
12
11
 
12
+ // biome-ignore lint/suspicious/noEmptyInterface: <explanation>
13
13
  export interface _Register {}
14
14
 
15
15
  export * as Kubb from './kubb.ts'
@@ -12,25 +12,31 @@ type Options = {
12
12
  export function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {
13
13
  if (isFile) {
14
14
  const splitArray = text.split('.')
15
- return splitArray.map((item, i) => i === splitArray.length - 1 ? camelCase(item, { prefix, suffix }) : camelCase(item)).join('/')
15
+ return splitArray.map((item, i) => (i === splitArray.length - 1 ? camelCase(item, { prefix, suffix }) : camelCase(item))).join('/')
16
16
  }
17
17
 
18
- return changeCamelCase(`${prefix} ${text} ${suffix}`, { delimiter: '', mergeAmbiguousCharacters: true })
18
+ return changeCamelCase(`${prefix} ${text} ${suffix}`, {
19
+ delimiter: '',
20
+ mergeAmbiguousCharacters: true,
21
+ })
19
22
  }
20
23
 
21
24
  export function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {
22
25
  if (isFile) {
23
26
  const splitArray = text.split('.')
24
- return splitArray.map((item, i) => i === splitArray.length - 1 ? pascalCase(item, { prefix, suffix }) : camelCase(item)).join('/')
27
+ return splitArray.map((item, i) => (i === splitArray.length - 1 ? pascalCase(item, { prefix, suffix }) : camelCase(item))).join('/')
25
28
  }
26
29
 
27
- return changePascalCase(`${prefix} ${text} ${suffix}`, { delimiter: '', mergeAmbiguousCharacters: true })
30
+ return changePascalCase(`${prefix} ${text} ${suffix}`, {
31
+ delimiter: '',
32
+ mergeAmbiguousCharacters: true,
33
+ })
28
34
  }
29
35
 
30
36
  export function pathCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {
31
37
  if (isFile) {
32
38
  const splitArray = text.split('.')
33
- return splitArray.map((item, i) => i === splitArray.length - 1 ? pathCase(item, { prefix, suffix }) : camelCase(item)).join('/')
39
+ return splitArray.map((item, i) => (i === splitArray.length - 1 ? pathCase(item, { prefix, suffix }) : camelCase(item))).join('/')
34
40
  }
35
41
 
36
42
  return changePathCase(`${prefix} ${text} ${suffix}`, { delimiter: '' })
@@ -14,7 +14,7 @@ export function jsStringEscape(input: any): string {
14
14
  case '"':
15
15
  case "'":
16
16
  case '\\':
17
- return '\\' + character
17
+ return `\\${character}`
18
18
  // Four possible LineTerminator characters need to be escaped:
19
19
  case '\n':
20
20
  return '\\n'
@@ -37,7 +37,5 @@ export function escapeStringRegexp(string: string) {
37
37
 
38
38
  // Escape characters with special meaning either inside or outside character sets.
39
39
  // Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
40
- return string
41
- .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
42
- .replace(/-/g, '\\x2d')
40
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d')
43
41
  }
@@ -9,7 +9,7 @@ import { escape, jsStringEscape } from './escape.ts'
9
9
  import { createIndent } from './indent.ts'
10
10
  import { nameSorter } from './nameSorter.ts'
11
11
  import { searchAndReplace } from './searchAndReplace.ts'
12
- import { stringify } from './stringify.ts'
12
+ import { stringify, stringifyObject } from './stringify.ts'
13
13
  import { isNumber } from './toNumber.ts'
14
14
  import { toRegExp, toRegExpString } from './toRegExp.ts'
15
15
  import { transformReservedWord } from './transformReservedWord.ts'
@@ -22,7 +22,7 @@ export { escape, jsStringEscape } from './escape.ts'
22
22
  export { createIndent } from './indent.ts'
23
23
  export { nameSorter } from './nameSorter.ts'
24
24
  export { searchAndReplace } from './searchAndReplace.ts'
25
- export { stringify } from './stringify.ts'
25
+ export { stringify, stringifyObject } from './stringify.ts'
26
26
  export { isNumber } from './toNumber.ts'
27
27
  export { toRegExp, toRegExpString } from './toRegExp.ts'
28
28
  export { transformReservedWord } from './transformReservedWord.ts'
@@ -42,6 +42,7 @@ export default {
42
42
  toNumber,
43
43
  isNumber,
44
44
  stringify,
45
+ stringifyObject,
45
46
  toRegExp,
46
47
  toRegExpString,
47
48
  trim,
@@ -1,9 +1,25 @@
1
1
  import { trimQuotes } from './trim'
2
2
 
3
- export function stringify(text: string | number | undefined): string {
4
- if (text === undefined) {
3
+ export function stringify(value: string | number | undefined): string {
4
+ if (value === undefined) {
5
5
  return '""'
6
6
  }
7
7
 
8
- return JSON.stringify(trimQuotes(text.toString()))
8
+ return JSON.stringify(trimQuotes(value.toString()))
9
+ }
10
+
11
+ export function stringifyObject(value: object): string {
12
+ const items = Object.entries(value)
13
+ .map(([key, value]) => {
14
+ if (typeof value === 'object') {
15
+ return `${key}: {
16
+ ${stringifyObject(value)}
17
+ }`
18
+ }
19
+
20
+ return `${key}: ${value}`
21
+ })
22
+ .filter(Boolean)
23
+
24
+ return items.join(',\n')
9
25
  }
@@ -6,7 +6,7 @@ export function isNumber(value: unknown): value is number {
6
6
  return false
7
7
  }
8
8
 
9
- return !isNaN(toNumber(value))
9
+ return !Number.isNaN(toNumber(value))
10
10
  }
11
11
  return typeof value === 'number'
12
12
  }
@@ -25,11 +25,7 @@ export function toRegExpString(text: string): string {
25
25
  const isStartWithSlash = text.startsWith('/')
26
26
  const isEndWithSlash = text.endsWith('/')
27
27
 
28
- const regexp = `new RegExp('${
29
- jsStringEscape(
30
- text.slice(isStartWithSlash ? 1 : 0, isEndWithSlash ? -1 : undefined),
31
- )
32
- }')`
28
+ const regexp = `new RegExp('${jsStringEscape(text.slice(isStartWithSlash ? 1 : 0, isEndWithSlash ? -1 : undefined))}')`
33
29
 
34
30
  return regexp
35
31
  }
package/src/types.ts CHANGED
@@ -15,22 +15,20 @@ import type { Cache } from './utils/cache.ts'
15
15
  * ...
16
16
  * })
17
17
  */
18
- export type UserConfig =
19
- & Omit<Config, 'root' | 'plugins'>
20
- & {
21
- /**
22
- * Project root directory. Can be an absolute path, or a path relative from
23
- * the location of the config file itself.
24
- * @default process.cwd()
25
- */
26
- root?: string
27
- /**
28
- * Plugin type can be KubbJSONPlugin or Plugin
29
- * Example: ['@kubb/swagger', { output: false }]
30
- * Or: createSwagger({ output: false })
31
- */
32
- plugins?: Array<Omit<UnknownUserPlugin, 'api'> | UnionPlugins | [name: string, options: object]>
33
- }
18
+ export type UserConfig = Omit<Config, 'root' | 'plugins'> & {
19
+ /**
20
+ * Project root directory. Can be an absolute path, or a path relative from
21
+ * the location of the config file itself.
22
+ * @default process.cwd()
23
+ */
24
+ root?: string
25
+ /**
26
+ * Plugin type can be KubbJSONPlugin or Plugin
27
+ * Example: ['@kubb/swagger', { output: false }]
28
+ * Or: createSwagger({ output: false })
29
+ */
30
+ plugins?: Array<Omit<UnknownUserPlugin, 'api'> | UnionPlugins | [name: string, options: object]>
31
+ }
34
32
 
35
33
  export type InputPath = {
36
34
  /**
@@ -166,32 +164,31 @@ export type PluginFactoryOptions<
166
164
 
167
165
  export type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never
168
166
 
169
- export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
170
- & {
171
- /**
172
- * Unique name used for the plugin
173
- * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
174
- * @example @kubb/typescript
175
- */
176
- name: TOptions['name']
177
- /**
178
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
179
- */
180
- options: TOptions['resolvedOptions']
181
- /**
182
- * 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.
183
- * Can be used to validate depended plugins.
184
- */
185
- pre?: Array<string>
186
- /**
187
- * 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.
188
- */
189
- post?: Array<string>
190
- }
191
- & (TOptions['api'] extends never ? {
167
+ export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
168
+ /**
169
+ * Unique name used for the plugin
170
+ * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
171
+ * @example @kubb/typescript
172
+ */
173
+ name: TOptions['name']
174
+ /**
175
+ * Options set for a specific plugin(see kubb.config.js), passthrough of options.
176
+ */
177
+ options: TOptions['resolvedOptions']
178
+ /**
179
+ * 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.
180
+ * Can be used to validate depended plugins.
181
+ */
182
+ pre?: Array<string>
183
+ /**
184
+ * 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.
185
+ */
186
+ post?: Array<string>
187
+ } & (TOptions['api'] extends never
188
+ ? {
192
189
  api?: never
193
190
  }
194
- : {
191
+ : {
195
192
  api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api']
196
193
  })
197
194
 
@@ -199,39 +196,38 @@ export type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = Plug
199
196
 
200
197
  type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>
201
198
 
202
- export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
203
- & {
204
- /**
205
- * Unique name used for the plugin
206
- * @example @kubb/typescript
207
- */
208
- name: TOptions['name']
209
- /**
210
- * Internal key used when a developer uses more than one of the same plugin
211
- * @private
212
- */
213
- key: TOptions['key']
214
- /**
215
- * 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.
216
- * Can be used to validate depended plugins.
217
- */
218
- pre?: Array<string>
219
- /**
220
- * 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.
221
- */
222
- post?: Array<string>
223
- /**
224
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
225
- */
226
- options: TOptions['resolvedOptions']
227
- /**
228
- * Define an api that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `createPlugin`).
229
- */
230
- }
231
- & (TOptions['api'] extends never ? {
199
+ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
200
+ /**
201
+ * Unique name used for the plugin
202
+ * @example @kubb/typescript
203
+ */
204
+ name: TOptions['name']
205
+ /**
206
+ * Internal key used when a developer uses more than one of the same plugin
207
+ * @private
208
+ */
209
+ key: TOptions['key']
210
+ /**
211
+ * 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.
212
+ * Can be used to validate depended plugins.
213
+ */
214
+ pre?: Array<string>
215
+ /**
216
+ * 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.
217
+ */
218
+ post?: Array<string>
219
+ /**
220
+ * Options set for a specific plugin(see kubb.config.js), passthrough of options.
221
+ */
222
+ options: TOptions['resolvedOptions']
223
+ /**
224
+ * Define an api that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `createPlugin`).
225
+ */
226
+ } & (TOptions['api'] extends never
227
+ ? {
232
228
  api?: never
233
229
  }
234
- : {
230
+ : {
235
231
  api: TOptions['api']
236
232
  })
237
233
 
@@ -58,23 +58,24 @@ export class FunctionParams {
58
58
  return this
59
59
  }
60
60
  static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {
61
- return orderBy(items.filter(Boolean), [
62
- (v) => {
63
- if (Array.isArray(v)) {
64
- return undefined
65
- }
66
- return !v.default
67
- },
68
- (v) => {
69
- if (Array.isArray(v)) {
70
- return undefined
71
- }
72
- return v.required ?? true
73
- },
74
- ], [
75
- 'desc',
76
- 'desc',
77
- ])
61
+ return orderBy(
62
+ items.filter(Boolean),
63
+ [
64
+ (v) => {
65
+ if (Array.isArray(v)) {
66
+ return undefined
67
+ }
68
+ return !v.default
69
+ },
70
+ (v) => {
71
+ if (Array.isArray(v)) {
72
+ return undefined
73
+ }
74
+ return v.required ?? true
75
+ },
76
+ ],
77
+ ['desc', 'desc'],
78
+ )
78
79
  }
79
80
 
80
81
  static #addParams(acc: string[], item: FunctionParamsAST) {
@@ -110,12 +111,12 @@ export class FunctionParams {
110
111
  let type: string[] = []
111
112
  let name: string[] = []
112
113
 
113
- const enabled = items.every(item => item.enabled) ? items.at(0)?.enabled : true
114
- const required = items.every(item => item.required) ?? true
114
+ const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true
115
+ const required = items.every((item) => item.required) ?? true
115
116
 
116
- items.forEach(item => {
117
+ items.forEach((item) => {
117
118
  name = FunctionParams.#addParams(name, { ...item, type: undefined })
118
- if (items.some(item => item.type)) {
119
+ if (items.some((item) => item.type)) {
119
120
  type = FunctionParams.#addParams(type, item)
120
121
  }
121
122
  })
@@ -129,12 +130,12 @@ export class FunctionParams {
129
130
  }
130
131
 
131
132
  static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {
132
- const sortedData = this.#orderItems(items)
133
+ const sortedData = FunctionParams.#orderItems(items)
133
134
 
134
135
  return sortedData
135
136
  .reduce((acc, item) => {
136
137
  if (Array.isArray(item)) {
137
- const subItems = this.#orderItems(item) as FunctionParamsAST[]
138
+ const subItems = FunctionParams.#orderItems(item) as FunctionParamsAST[]
138
139
  const objectItem = FunctionParams.toObject(subItems)
139
140
 
140
141
  return FunctionParams.#addParams(acc, objectItem)
@@ -87,7 +87,7 @@ export class TreeNode<T = BarrelData> {
87
87
  // do the same for all children
88
88
  if (this.children) {
89
89
  for (let i = 0, { length } = this.children; i < length; i++) {
90
- this.children[i]!.forEach(callback)
90
+ this.children[i]?.forEach(callback)
91
91
  }
92
92
  }
93
93
 
@@ -97,16 +97,27 @@ export class TreeNode<T = BarrelData> {
97
97
  public static build(path: string, options: TreeNodeOptions = {}): TreeNode | null {
98
98
  try {
99
99
  const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean)
100
- const filteredTree = dirTree(path, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] })
100
+ const filteredTree = dirTree(path, {
101
+ extensions: options.extensions,
102
+ exclude: [/node_modules/, ...exclude],
103
+ })
101
104
 
102
105
  if (!filteredTree) {
103
106
  return null
104
107
  }
105
108
 
106
- const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) })
109
+ const treeNode = new TreeNode({
110
+ name: filteredTree.name,
111
+ path: filteredTree.path,
112
+ type: filteredTree.type || FileManager.getMode(filteredTree.path),
113
+ })
107
114
 
108
115
  const recurse = (node: typeof treeNode, item: DirectoryTree) => {
109
- const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) })
116
+ const subNode = node.addChild({
117
+ name: item.name,
118
+ path: item.path,
119
+ type: item.type || FileManager.getMode(item.path),
120
+ })
110
121
 
111
122
  if (item.children?.length) {
112
123
  item.children?.forEach((child) => {
@@ -89,9 +89,7 @@ export class URLPath {
89
89
 
90
90
  if (found) {
91
91
  newPath = found.reduce((prev, curr) => {
92
- const pathParam = replacer
93
- ? replacer(camelCase(curr))
94
- : camelCase(curr)
92
+ const pathParam = replacer ? replacer(camelCase(curr)) : camelCase(curr)
95
93
  const replacement = `\${${pathParam}}`
96
94
 
97
95
  return prev.replace(curr, replacement)
@@ -113,9 +111,7 @@ export class URLPath {
113
111
  found.forEach((item) => {
114
112
  item = item.replaceAll('{', '').replaceAll('}', '')
115
113
 
116
- const pathParam = replacer
117
- ? replacer(camelCase(item))
118
- : camelCase(item)
114
+ const pathParam = replacer ? replacer(camelCase(item)) : camelCase(item)
119
115
 
120
116
  params[pathParam] = pathParam
121
117
  }, this.path)
@@ -11,9 +11,7 @@ type SeqOutput<TInput extends Array<PromiseFunc<TValue, null>>, TValue> = Array<
11
11
  /**
12
12
  * Chains promises
13
13
  */
14
- export function hookSeq<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TOutput = SeqOutput<TInput, TValue>>(
15
- promises: TInput,
16
- ): TOutput {
14
+ export function hookSeq<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TOutput = SeqOutput<TInput, TValue>>(promises: TInput): TOutput {
17
15
  return promises.filter(Boolean).reduce(
18
16
  (promise, func) => {
19
17
  if (typeof func !== 'function') {
@@ -66,16 +64,18 @@ type HookParallelOutput<TInput extends Array<PromiseFunc<TValue, null>>, TValue>
66
64
  export function hookParallel<TInput extends Array<PromiseFunc<TValue, null>>, TValue = unknown, TOutput = HookParallelOutput<TInput, TValue>>(
67
65
  promises: TInput,
68
66
  ): TOutput {
69
- return Promise.allSettled(promises.filter(Boolean).map(promise => promise())) as TOutput
67
+ return Promise.allSettled(promises.filter(Boolean).map((promise) => promise())) as TOutput
70
68
  }
71
69
 
72
70
  export type Strategy = 'seq' | 'first' | 'parallel'
73
71
 
74
72
  export type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc<TValue, null>>, TValue> = TStrategy extends 'first'
75
73
  ? HookFirstOutput<TInput, TValue>
76
- : TStrategy extends 'seq' ? SeqOutput<TInput, TValue>
77
- : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue>
78
- : never
74
+ : TStrategy extends 'seq'
75
+ ? SeqOutput<TInput, TValue>
76
+ : TStrategy extends 'parallel'
77
+ ? HookParallelOutput<TInput, TValue>
78
+ : never
79
79
 
80
80
  // tests
81
81
 
@@ -1,6 +1,10 @@
1
1
  export type { FunctionParamsAST } from './FunctionParams.ts'
2
2
  export { FunctionParams } from './FunctionParams.ts'
3
- export { isPromise, isPromiseFulfilledResult, isPromiseRejectedResult } from './promise.ts'
3
+ export {
4
+ isPromise,
5
+ isPromiseFulfilledResult,
6
+ isPromiseRejectedResult,
7
+ } from './promise.ts'
4
8
  export { renderTemplate } from './renderTemplate.ts'
5
9
  export { timeout } from './timeout.ts'
6
10
  export { getUniqueName, setUniqueName } from './uniqueName.ts'
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/URLPath.ts"],"names":[],"mappings":";;;;;;;;AAAA;AAaO,IAAM,UAAN,MAAc;AAAA,EAGnB,YAAY,MAAc;AACxB,SAAK,OAAO;AAEZ,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,MAAc;AAChB,WAAO,KAAK,UAAU;AAAA,EACxB;AAAA,EACA,IAAI,QAAiB;AACnB,QAAI;AACF,YAAM,MAAM,IAAI,IAAI,KAAK,IAAI;AAC7B,UAAI,KAAK,MAAM;AACb,eAAO;AAAA,MACT;AAAA,IACF,SAAS,OAAO;AACd,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,WAAmB;AACrB,WAAO,KAAK,iBAAiB;AAAA,EAC/B;AAAA,EACA,IAAI,SAA6B;AAC/B,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EACA,IAAI,SAA6C;AAC/C,WAAO,KAAK,UAAU;AAAA,EACxB;AAAA,EAEA,SAAS,EAAE,OAAO,QAAQ,UAAU,UAAU,IAAmB,CAAC,GAAuB;AACvF,UAAM,SAAS;AAAA,MACb,KAAK,SAAS,SAAS,KAAK,UAAU,IAAI,KAAK,iBAAiB,QAAQ;AAAA,MACxE,QAAQ,KAAK,UAAU;AAAA,IACzB;AAEA,QAAI,WAAW;AACb,UAAI,SAAS,YAAY;AACvB,eAAO,KAAK,UAAU,MAAM,EAAE,WAAW,KAAK,EAAE,EAAE,WAAW,KAAK,EAAE;AAAA,MACtE;AAEA,UAAI,OAAO,QAAQ;AACjB,eAAO,WAAW,OAAO,GAAG,cAAc,KAAK,UAAU,OAAO,MAAM,EAAE,WAAW,KAAK,EAAE,EAAE,WAAW,KAAK,EAAE,CAAC;AAAA,MACjH;AAEA,aAAO,WAAW,OAAO,GAAG;AAAA,IAC9B;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,iBAAiB,UAAkD;AACjE,UAAM,QAAQ;AACd,UAAM,QAAQ,KAAK,KAAK,MAAM,KAAK;AACnC,QAAI,UAAU,KAAK,KAAK,WAAW,KAAK,IAAI;AAE5C,QAAI,OAAO;AACT,gBAAU,MAAM,OAAO,CAAC,MAAM,SAAS;AACrC,cAAM,YAAY,WACd,SAAS,UAAU,IAAI,CAAC,IACxB,UAAU,IAAI;AAClB,cAAM,cAAc,MAAM,SAAS;AAEnC,eAAO,KAAK,QAAQ,MAAM,WAAW;AAAA,MACvC,GAAG,KAAK,IAAI;AAAA,IACd;AAEA,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,UAAU,UAA8E;AACtF,UAAM,QAAQ;AACd,UAAM,QAAQ,KAAK,KAAK,MAAM,KAAK;AAEnC,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAEA,UAAM,SAAiC,CAAC;AACxC,UAAM,QAAQ,CAAC,SAAS;AACtB,aAAO,KAAK,WAAW,KAAK,EAAE,EAAE,WAAW,KAAK,EAAE;AAElD,YAAM,YAAY,WACd,SAAS,UAAU,IAAI,CAAC,IACxB,UAAU,IAAI;AAElB,aAAO,SAAS,IAAI;AAAA,IACtB,GAAG,KAAK,IAAI;AAEZ,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAoB;AAClB,WAAO,KAAK,KAAK,WAAW,KAAK,GAAG,EAAE,WAAW,KAAK,EAAE;AAAA,EAC1D;AACF","sourcesContent":["import { camelCase } from '../transformers/casing.ts'\n\nexport type URLObject = {\n url: string\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n type?: 'path' | 'template'\n replacer?: (pathParam: string) => string\n stringify?: boolean\n}\n\nexport class URLPath {\n path: string\n\n constructor(path: string) {\n this.path = path\n\n return this\n }\n\n /**\n * Convert Swagger path to URLPath(syntax of Express)\n * @example /pet/{petId} => /pet/:petId\n */\n get URL(): string {\n return this.toURLPath()\n }\n get isURL(): boolean {\n try {\n const url = new URL(this.path)\n if (url?.href) {\n return true\n }\n } catch (error) {\n return false\n }\n return false\n }\n\n /**\n * Convert Swagger path to template literals/ template strings(camelcase)\n * @example /pet/{petId} => `/pet/${petId}`\n * @example /account/monetary-accountID => `/account/${monetaryAccountId}`\n * @example /account/userID => `/account/${userId}`\n */\n get template(): string {\n return this.toTemplateString()\n }\n get object(): URLObject | string {\n return this.toObject()\n }\n get params(): Record<string, string> | undefined {\n return this.getParams()\n }\n\n toObject({ type = 'path', replacer, stringify }: ObjectOptions = {}): URLObject | string {\n const object = {\n url: type === 'path' ? this.toURLPath() : this.toTemplateString(replacer),\n params: this.getParams(),\n }\n\n if (stringify) {\n if (type === 'template') {\n return JSON.stringify(object).replaceAll(\"'\", '').replaceAll(`\"`, '')\n }\n\n if (object.params) {\n return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll(\"'\", '').replaceAll(`\"`, '')} }`\n }\n\n return `{ url: '${object.url}' }`\n }\n\n return object\n }\n\n /**\n * Convert Swagger path to template literals/ template strings(camelcase)\n * @example /pet/{petId} => `/pet/${petId}`\n * @example /account/monetary-accountID => `/account/${monetaryAccountId}`\n * @example /account/userID => `/account/${userId}`\n */\n toTemplateString(replacer?: (pathParam: string) => string): string {\n const regex = /{(\\w|-)*}/g\n const found = this.path.match(regex)\n let newPath = this.path.replaceAll('{', '${')\n\n if (found) {\n newPath = found.reduce((prev, curr) => {\n const pathParam = replacer\n ? replacer(camelCase(curr))\n : camelCase(curr)\n const replacement = `\\${${pathParam}}`\n\n return prev.replace(curr, replacement)\n }, this.path)\n }\n\n return `\\`${newPath}\\``\n }\n\n getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined {\n const regex = /{(\\w|-)*}/g\n const found = this.path.match(regex)\n\n if (!found) {\n return undefined\n }\n\n const params: Record<string, string> = {}\n found.forEach((item) => {\n item = item.replaceAll('{', '').replaceAll('}', '')\n\n const pathParam = replacer\n ? replacer(camelCase(item))\n : camelCase(item)\n\n params[pathParam] = pathParam\n }, this.path)\n\n return params\n }\n\n /**\n * Convert Swagger path to URLPath(syntax of Express)\n * @example /pet/{petId} => /pet/:petId\n */\n toURLPath(): string {\n return this.path.replaceAll('{', ':').replaceAll('}', '')\n }\n}\n"]}