@kubb/core 5.0.0-alpha.36 → 5.0.0-alpha.39

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 (42) hide show
  1. package/dist/{PluginDriver-CCdkwR14.cjs → PluginDriver-BQwm8hDd.cjs} +70 -147
  2. package/dist/PluginDriver-BQwm8hDd.cjs.map +1 -0
  3. package/dist/{PluginDriver-B_65W4fv.js → PluginDriver-CgXFtmNP.js} +36 -96
  4. package/dist/PluginDriver-CgXFtmNP.js.map +1 -0
  5. package/dist/index.cjs +23 -341
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +5 -317
  8. package/dist/index.js +23 -311
  9. package/dist/index.js.map +1 -1
  10. package/dist/mocks.cjs +2 -3
  11. package/dist/mocks.cjs.map +1 -1
  12. package/dist/mocks.d.ts +2 -2
  13. package/dist/mocks.js +2 -2
  14. package/dist/mocks.js.map +1 -1
  15. package/dist/{PluginDriver-C9iBgYbk.d.ts → types-DUc5lEUp.d.ts} +596 -714
  16. package/package.json +4 -11
  17. package/src/PluginDriver.ts +18 -17
  18. package/src/constants.ts +0 -48
  19. package/src/createKubb.ts +1 -1
  20. package/src/defineResolver.ts +3 -3
  21. package/src/index.ts +3 -20
  22. package/src/mocks.ts +3 -3
  23. package/src/storages/fsStorage.ts +27 -7
  24. package/src/types.ts +3 -11
  25. package/src/utils/TreeNode.ts +3 -3
  26. package/src/utils/executeStrategies.ts +0 -16
  27. package/dist/PluginDriver-B_65W4fv.js.map +0 -1
  28. package/dist/PluginDriver-CCdkwR14.cjs.map +0 -1
  29. package/dist/chunk-ByKO4r7w.cjs +0 -38
  30. package/dist/hooks.cjs +0 -32
  31. package/dist/hooks.cjs.map +0 -1
  32. package/dist/hooks.d.ts +0 -23
  33. package/dist/hooks.js +0 -29
  34. package/dist/hooks.js.map +0 -1
  35. package/src/hooks/index.ts +0 -3
  36. package/src/hooks/useDriver.ts +0 -9
  37. package/src/hooks/useMode.ts +0 -8
  38. package/src/hooks/usePlugin.ts +0 -9
  39. package/src/utils/FunctionParams.ts +0 -155
  40. package/src/utils/formatters.ts +0 -45
  41. package/src/utils/getFunctionParams.ts +0 -254
  42. package/src/utils/linters.ts +0 -45
package/dist/hooks.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { N as PluginFactoryOptions, j as Plugin, t as PluginDriver } from "./PluginDriver-C9iBgYbk.js";
3
-
4
- //#region src/hooks/useDriver.d.ts
5
- /**
6
- * @deprecated use `driver` from the generator component props instead
7
- */
8
- declare function useDriver(): PluginDriver;
9
- //#endregion
10
- //#region src/hooks/useMode.d.ts
11
- /**
12
- * @deprecated use `mode` from the generator component props instead
13
- */
14
- declare function useMode(): 'single' | 'split';
15
- //#endregion
16
- //#region src/hooks/usePlugin.d.ts
17
- /**
18
- * @deprecated use `plugin` from the generator component props instead
19
- */
20
- declare function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions>;
21
- //#endregion
22
- export { useDriver, useMode, usePlugin };
23
- //# sourceMappingURL=hooks.d.ts.map
package/dist/hooks.js DELETED
@@ -1,29 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { KubbContext, inject } from "@kubb/renderer-jsx";
3
- //#region src/hooks/useDriver.ts
4
- /**
5
- * @deprecated use `driver` from the generator component props instead
6
- */
7
- function useDriver() {
8
- return inject(KubbContext).driver;
9
- }
10
- //#endregion
11
- //#region src/hooks/useMode.ts
12
- /**
13
- * @deprecated use `mode` from the generator component props instead
14
- */
15
- function useMode() {
16
- return inject(KubbContext).mode;
17
- }
18
- //#endregion
19
- //#region src/hooks/usePlugin.ts
20
- /**
21
- * @deprecated use `plugin` from the generator component props instead
22
- */
23
- function usePlugin() {
24
- return inject(KubbContext).plugin;
25
- }
26
- //#endregion
27
- export { useDriver, useMode, usePlugin };
28
-
29
- //# sourceMappingURL=hooks.js.map
package/dist/hooks.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useDriver.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts"],"sourcesContent":["import { inject, KubbContext } from '@kubb/renderer-jsx'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `driver` from the generator component props instead\n */\nexport function useDriver(): PluginDriver {\n return inject(KubbContext)!.driver as PluginDriver\n}\n","import { inject, KubbContext } from '@kubb/renderer-jsx'\n\n/**\n * @deprecated use `mode` from the generator component props instead\n */\nexport function useMode(): 'single' | 'split' {\n return inject(KubbContext)!.mode\n}\n","import { inject, KubbContext } from '@kubb/renderer-jsx'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use `plugin` from the generator component props instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n return inject(KubbContext)!.plugin as Plugin<TOptions>\n}\n"],"mappings":";;;;;;AAMA,SAAgB,YAA0B;AACxC,QAAO,OAAO,YAAY,CAAE;;;;;;;ACF9B,SAAgB,UAA8B;AAC5C,QAAO,OAAO,YAAY,CAAE;;;;;;;ACA9B,SAAgB,YAA4F;AAC1G,QAAO,OAAO,YAAY,CAAE"}
@@ -1,3 +0,0 @@
1
- export { useDriver } from './useDriver.ts'
2
- export { useMode } from './useMode.ts'
3
- export { usePlugin } from './usePlugin.ts'
@@ -1,9 +0,0 @@
1
- import { inject, KubbContext } from '@kubb/renderer-jsx'
2
- import type { PluginDriver } from '../PluginDriver.ts'
3
-
4
- /**
5
- * @deprecated use `driver` from the generator component props instead
6
- */
7
- export function useDriver(): PluginDriver {
8
- return inject(KubbContext)!.driver as PluginDriver
9
- }
@@ -1,8 +0,0 @@
1
- import { inject, KubbContext } from '@kubb/renderer-jsx'
2
-
3
- /**
4
- * @deprecated use `mode` from the generator component props instead
5
- */
6
- export function useMode(): 'single' | 'split' {
7
- return inject(KubbContext)!.mode
8
- }
@@ -1,9 +0,0 @@
1
- import { inject, KubbContext } from '@kubb/renderer-jsx'
2
- import type { Plugin, PluginFactoryOptions } from '../types.ts'
3
-
4
- /**
5
- * @deprecated use `plugin` from the generator component props instead
6
- */
7
- export function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {
8
- return inject(KubbContext)!.plugin as Plugin<TOptions>
9
- }
@@ -1,155 +0,0 @@
1
- import { camelCase } from '@internals/utils'
2
- // TODO replace with @internals/utils
3
- import { sortBy } from 'remeda'
4
-
5
- type FunctionParamsASTWithoutType = {
6
- name?: string
7
- type?: string
8
- /**
9
- * @default true
10
- */
11
- required?: boolean
12
- /**
13
- * @default true
14
- */
15
- enabled?: boolean
16
- default?: string
17
- }
18
-
19
- type FunctionParamsASTWithType = {
20
- name?: never
21
- type: string
22
- /**
23
- * @default true
24
- */
25
- required?: boolean
26
- /**
27
- * @default true
28
- */
29
- enabled?: boolean
30
- default?: string
31
- }
32
- /**
33
- * @deprecated use ast package instead
34
- */
35
- export type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType
36
-
37
- /**
38
- * @deprecated use ast package instead
39
- */
40
- export class FunctionParams {
41
- #items: Array<FunctionParamsAST | FunctionParamsAST[]> = []
42
-
43
- get items(): FunctionParamsAST[] {
44
- return this.#items.flat()
45
- }
46
-
47
- add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams {
48
- if (!item) {
49
- return this
50
- }
51
-
52
- if (Array.isArray(item)) {
53
- item
54
- .filter((x): x is FunctionParamsAST | FunctionParamsAST[] => x !== undefined)
55
- .forEach((it) => {
56
- this.#items.push(it)
57
- })
58
- return this
59
- }
60
- this.#items.push(item)
61
-
62
- return this
63
- }
64
- static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {
65
- return sortBy(
66
- items.filter(Boolean),
67
- [(item) => Array.isArray(item), 'desc'], // arrays (rest params) first
68
- [(item) => !Array.isArray(item) && (item as FunctionParamsAST).default !== undefined, 'asc'], // no-default before has-default
69
- [(item) => Array.isArray(item) || ((item as FunctionParamsAST).required ?? true), 'desc'], // required before optional
70
- )
71
- }
72
-
73
- static #addParams(acc: string[], item: FunctionParamsAST) {
74
- const { enabled = true, name, type, required = true, ...rest } = item
75
-
76
- if (!enabled) {
77
- return acc
78
- }
79
-
80
- if (!name) {
81
- // when name is not se we uses TypeScript generics
82
- acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)
83
-
84
- return acc
85
- }
86
- // TODO check why we still need the camelcase here
87
- const parameterName = name.startsWith('{') ? name : camelCase(name)
88
-
89
- if (type) {
90
- if (required) {
91
- acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)
92
- } else {
93
- acc.push(`${parameterName}?: ${type}`)
94
- }
95
- } else {
96
- acc.push(`${parameterName}`)
97
- }
98
-
99
- return acc
100
- }
101
-
102
- static toObject(items: FunctionParamsAST[]): FunctionParamsAST {
103
- let type: string[] = []
104
- let name: string[] = []
105
-
106
- const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true
107
- const required = items.every((item) => item.required) ?? true
108
-
109
- items.forEach((item) => {
110
- name = FunctionParams.#addParams(name, { ...item, type: undefined })
111
- if (items.some((item) => item.type)) {
112
- type = FunctionParams.#addParams(type, item)
113
- }
114
- })
115
-
116
- return {
117
- name: `{ ${name.join(', ')} }`,
118
- type: type.length ? `{ ${type.join('; ')} }` : undefined,
119
- enabled,
120
- required,
121
- }
122
- }
123
-
124
- toObject(): FunctionParamsAST {
125
- const items = FunctionParams.#orderItems(this.#items).flat()
126
-
127
- return FunctionParams.toObject(items)
128
- }
129
-
130
- static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {
131
- const sortedData = FunctionParams.#orderItems(items)
132
-
133
- return sortedData
134
- .reduce((acc, item) => {
135
- if (Array.isArray(item)) {
136
- if (item.length <= 0) {
137
- return acc
138
- }
139
- const subItems = FunctionParams.#orderItems(item) as FunctionParamsAST[]
140
- const objectItem = FunctionParams.toObject(subItems)
141
-
142
- return FunctionParams.#addParams(acc, objectItem)
143
- }
144
-
145
- return FunctionParams.#addParams(acc, item)
146
- }, [] as string[])
147
- .join(', ')
148
- }
149
-
150
- toString(): string {
151
- const items = FunctionParams.#orderItems(this.#items)
152
-
153
- return FunctionParams.toString(items)
154
- }
155
- }
@@ -1,45 +0,0 @@
1
- import { x } from 'tinyexec'
2
- import type { formatters } from '../constants.ts'
3
-
4
- type Formatter = keyof typeof formatters
5
-
6
- /**
7
- * Returns `true` when the given formatter is installed and callable.
8
- *
9
- * Availability is detected by running `<formatter> --version` and checking
10
- * that the process exits without error.
11
- */
12
- async function isFormatterAvailable(formatter: Formatter): Promise<boolean> {
13
- try {
14
- await x(formatter, ['--version'], { nodeOptions: { stdio: 'ignore' } })
15
- return true
16
- } catch {
17
- return false
18
- }
19
- }
20
-
21
- /**
22
- * Detects the first available code formatter on the current system.
23
- *
24
- * - Checks in preference order: `biome`, `oxfmt`, `prettier`.
25
- * - Returns `null` when none are found.
26
- *
27
- * @example
28
- * ```ts
29
- * const formatter = await detectFormatter()
30
- * if (formatter) {
31
- * console.log(`Using ${formatter} for formatting`)
32
- * }
33
- * ```
34
- */
35
- export async function detectFormatter(): Promise<Formatter | null> {
36
- const formatterNames = new Set(['biome', 'oxfmt', 'prettier'] as const)
37
-
38
- for (const formatter of formatterNames) {
39
- if (await isFormatterAvailable(formatter)) {
40
- return formatter
41
- }
42
- }
43
-
44
- return null
45
- }
@@ -1,254 +0,0 @@
1
- import { sortBy } from 'remeda'
2
-
3
- export type Param = {
4
- /**
5
- * Controls how path parameters are emitted in the function signature.
6
- * - `'object'` groups them as a single destructured parameter.
7
- * - `'inline'` spreads them as individual comma-separated parameters.
8
- * - `'inlineSpread'` emits a single rest parameter.
9
- *
10
- * @default 'inline'
11
- * @internal
12
- */
13
- mode?: 'object' | 'inline' | 'inlineSpread'
14
- type?: 'string' | 'number' | (string & {})
15
- optional?: boolean
16
- /**
17
- * Default value expression for the parameter.
18
- *
19
- * @example Assignment syntax
20
- * `test = "default"`
21
- */
22
- default?: string
23
- /**
24
- * Used for no TypeScript (with mode object).
25
- *
26
- * @example Value syntax
27
- * `test: "default"`
28
- */
29
- value?: string
30
- children?: Params
31
- }
32
-
33
- type ParamItem =
34
- | (Pick<Param, 'mode' | 'type' | 'value'> & {
35
- optional?: true
36
- default?: never
37
- children?: Params
38
- })
39
- | (Pick<Param, 'mode' | 'type' | 'value'> & {
40
- optional?: false
41
- default?: string
42
- children?: Params
43
- })
44
-
45
- export type Params = Record<string, Param | undefined>
46
-
47
- type Options = {
48
- type: 'constructor' | 'call' | 'object' | 'objectValue'
49
- transformName?: (name: string) => string
50
- transformType?: (type: string) => string
51
- }
52
-
53
- function order(items: Array<[key: string, item?: ParamItem]>) {
54
- return sortBy(items.filter(Boolean) as Array<[key: string, item?: ParamItem]>, ([_key, item]) => {
55
- if (item?.children) {
56
- return 0 // Treat items with children as required (they'll get = {} if all children are optional)
57
- }
58
- // Priority order: required (0) → optional (1) → default-only (2)
59
- if (item?.optional) {
60
- return 1 // Optional parameters (with or without default)
61
- }
62
- if (item?.default) {
63
- // Parameters with default only (not marked as optional)
64
- // Note: While the ParamItem type suggests optional and default are mutually exclusive,
65
- // this handles the case where a parameter has a default value but isn't explicitly marked as optional
66
- return 2
67
- }
68
- return 0 // Required parameters
69
- })
70
- }
71
-
72
- function parseChild(key: string, item: ParamItem, options: Options): string | null {
73
- // @ts-expect-error
74
- const entries = order(Object.entries(item.children))
75
-
76
- const types: string[] = []
77
- const names: string[] = []
78
-
79
- const optional = entries.every(([_key, item]) => item?.optional || !!item?.default)
80
-
81
- entries.forEach(([key, entryItem]) => {
82
- if (entryItem) {
83
- const name = parseItem(key, { ...entryItem, type: undefined }, options)
84
- if (entryItem.children) {
85
- const subTypes = Object.entries(entryItem.children)
86
- .map(([key]) => {
87
- return key
88
- })
89
- .join(', ')
90
-
91
- if (subTypes) {
92
- names.push(`${name}: { ${subTypes} }`)
93
- } else {
94
- names.push(name)
95
- }
96
- } else {
97
- if (options.type === 'call' && options.transformName) {
98
- names.push(`${key}: ${name}`)
99
- } else {
100
- names.push(name)
101
- }
102
- }
103
-
104
- if (entries.some(([_key, item]) => item?.type)) {
105
- types.push(parseItem(key, { ...entryItem, default: undefined }, options))
106
- }
107
- }
108
- })
109
-
110
- const name = item.mode === 'inline' ? key : names.length ? `{ ${names.join(', ')} }` : undefined
111
- const type = item.type ? item.type : types.length ? `{ ${types.join('; ')} }` : undefined
112
-
113
- if (!name) {
114
- return null
115
- }
116
-
117
- return parseItem(
118
- name,
119
- {
120
- type,
121
- default: item.default,
122
- optional: !item.default ? optional : undefined,
123
- } as ParamItem,
124
- options,
125
- )
126
- }
127
-
128
- function parseItem(name: string, item: ParamItem, options: Options): string {
129
- const acc: string[] = []
130
- const transformedName = options.transformName ? options.transformName(name) : name
131
- const transformedType = options.transformType && item.type ? options.transformType(item.type) : item.type
132
-
133
- if (options.type === 'object') {
134
- return transformedName
135
- }
136
-
137
- if (options.type === 'objectValue') {
138
- return item.value ? `${transformedName}: ${item.value}` : transformedName
139
- }
140
-
141
- //LEGACY
142
- if (item.type && options.type === 'constructor') {
143
- if (item.optional) {
144
- // Check if this is a destructured parameter (object mode)
145
- const isDestructured = transformedName.startsWith('{')
146
- if (isDestructured) {
147
- // For destructured parameters, use ": type = {}" syntax to make it optional
148
- acc.push(`${transformedName}: ${transformedType} = {}`)
149
- } else {
150
- // For inline parameters, use "?: type" syntax
151
- acc.push(`${transformedName}?: ${transformedType}`)
152
- }
153
- } else {
154
- acc.push(`${transformedName}: ${transformedType}${item.default ? ` = ${item.default}` : ''}`)
155
- }
156
- } else if (item.default && options.type === 'constructor') {
157
- acc.push(`${transformedName} = ${item.default}`)
158
- } else if (item.value) {
159
- acc.push(`${transformedName} : ${item.value}`)
160
- } else if (item.mode === 'inlineSpread') {
161
- acc.push(`... ${transformedName}`)
162
- } else {
163
- acc.push(transformedName)
164
- }
165
-
166
- return acc[0] as string
167
- }
168
-
169
- export function getFunctionParams(params: Params, options: Options): string {
170
- const entries = order(Object.entries(params as Record<string, ParamItem | undefined>))
171
-
172
- return entries
173
- .reduce((acc, [key, item]) => {
174
- if (!item) {
175
- return acc
176
- }
177
-
178
- if (item.children) {
179
- if (Object.keys(item.children).length === 0) {
180
- return acc
181
- }
182
-
183
- if (item.mode === 'inlineSpread') {
184
- return [...acc, getFunctionParams(item.children, options)]
185
- }
186
-
187
- const parsedItem = parseChild(key, item, options)
188
- if (!parsedItem) {
189
- return acc
190
- }
191
-
192
- return [...acc, parsedItem]
193
- }
194
-
195
- const parsedItem = parseItem(key, item, options)
196
-
197
- return [...acc, parsedItem]
198
- }, [] as string[])
199
- .join(', ')
200
- }
201
-
202
- /**
203
- * @deprecated use @kubb/ast
204
- */
205
- export function createFunctionParams(params: Params): Params {
206
- return params
207
- }
208
-
209
- /**
210
- * @deprecated use @kubb/ast
211
- */
212
- export class FunctionParams {
213
- #params: Params
214
-
215
- static factory(params: Params) {
216
- return new FunctionParams(params)
217
- }
218
- constructor(params: Params) {
219
- this.#params = params
220
- }
221
-
222
- get params(): Params {
223
- return this.#params
224
- }
225
-
226
- get flatParams(): Params {
227
- const flatter = (acc: Params, [key, item]: [key: string, item?: Param]): Params => {
228
- if (item?.children) {
229
- return Object.entries(item.children).reduce(flatter, acc)
230
- }
231
- if (item) {
232
- acc[key] = item
233
- }
234
-
235
- return acc
236
- }
237
- return Object.entries(this.#params).reduce(flatter, {} as Params)
238
- }
239
-
240
- toCall({ transformName, transformType }: Pick<Options, 'transformName' | 'transformType'> = {}): string {
241
- return getFunctionParams(this.#params, { type: 'call', transformName, transformType })
242
- }
243
-
244
- toObject(): string {
245
- return getFunctionParams(this.#params, { type: 'object' })
246
- }
247
- toObjectValue(): string {
248
- return getFunctionParams(this.#params, { type: 'objectValue' })
249
- }
250
-
251
- toConstructor(): string {
252
- return getFunctionParams(this.#params, { type: 'constructor' })
253
- }
254
- }
@@ -1,45 +0,0 @@
1
- import { x } from 'tinyexec'
2
- import type { linters } from '../constants.ts'
3
-
4
- type Linter = keyof typeof linters
5
-
6
- /**
7
- * Returns `true` when the given linter is installed and callable.
8
- *
9
- * Availability is detected by running `<linter> --version` and checking
10
- * that the process exits without error.
11
- */
12
- async function isLinterAvailable(linter: Linter): Promise<boolean> {
13
- try {
14
- await x(linter, ['--version'], { nodeOptions: { stdio: 'ignore' } })
15
- return true
16
- } catch {
17
- return false
18
- }
19
- }
20
-
21
- /**
22
- * Detects the first available linter on the current system.
23
- *
24
- * - Checks in preference order: `biome`, `oxlint`, `eslint`.
25
- * - Returns `null` when none are found.
26
- *
27
- * @example
28
- * ```ts
29
- * const linter = await detectLinter()
30
- * if (linter) {
31
- * console.log(`Using ${linter} for linting`)
32
- * }
33
- * ```
34
- */
35
- export async function detectLinter(): Promise<Linter | null> {
36
- const linterNames = new Set(['biome', 'oxlint', 'eslint'] as const)
37
-
38
- for (const linter of linterNames) {
39
- if (await isLinterAvailable(linter)) {
40
- return linter
41
- }
42
- }
43
-
44
- return null
45
- }