@kubb/core 5.0.0-alpha.36 → 5.0.0-alpha.38
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/dist/{PluginDriver-CCdkwR14.cjs → PluginDriver-BQwm8hDd.cjs} +70 -147
- package/dist/PluginDriver-BQwm8hDd.cjs.map +1 -0
- package/dist/{PluginDriver-B_65W4fv.js → PluginDriver-CgXFtmNP.js} +36 -96
- package/dist/PluginDriver-CgXFtmNP.js.map +1 -0
- package/dist/index.cjs +6 -334
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -317
- package/dist/index.js +6 -304
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +2 -3
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +2 -2
- package/dist/mocks.js +2 -2
- package/dist/mocks.js.map +1 -1
- package/dist/{PluginDriver-C9iBgYbk.d.ts → types-DUc5lEUp.d.ts} +596 -714
- package/package.json +4 -11
- package/src/PluginDriver.ts +18 -17
- package/src/constants.ts +0 -48
- package/src/createKubb.ts +1 -1
- package/src/defineResolver.ts +3 -3
- package/src/index.ts +3 -20
- package/src/mocks.ts +3 -3
- package/src/types.ts +3 -11
- package/src/utils/TreeNode.ts +3 -3
- package/src/utils/executeStrategies.ts +0 -16
- package/dist/PluginDriver-B_65W4fv.js.map +0 -1
- package/dist/PluginDriver-CCdkwR14.cjs.map +0 -1
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -32
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -23
- package/dist/hooks.js +0 -29
- package/dist/hooks.js.map +0 -1
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useDriver.ts +0 -9
- package/src/hooks/useMode.ts +0 -8
- package/src/hooks/usePlugin.ts +0 -9
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/formatters.ts +0 -45
- package/src/utils/getFunctionParams.ts +0 -254
- package/src/utils/linters.ts +0 -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
|
-
}
|
package/src/utils/linters.ts
DELETED
|
@@ -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
|
-
}
|