@kubb/ast 5.0.0-alpha.22 → 5.0.0-alpha.23
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/index.cjs +471 -441
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +159 -160
- package/dist/index.js +467 -426
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/{visitor-COwfCgLK.d.ts → visitor-DsdLcLjR.d.ts} +206 -117
- package/package.json +1 -1
- package/src/constants.ts +15 -2
- package/src/factory.ts +69 -49
- package/src/guards.ts +3 -3
- package/src/index.ts +13 -20
- package/src/nodes/base.ts +2 -1
- package/src/nodes/function.ts +104 -34
- package/src/nodes/index.ts +1 -1
- package/src/nodes/operation.ts +7 -2
- package/src/nodes/schema.ts +3 -3
- package/src/{printers/printer.ts → printer.ts} +1 -1
- package/src/transformers.ts +2 -42
- package/src/types.ts +3 -2
- package/src/utils.ts +364 -13
- package/src/visitor.ts +6 -4
- package/src/printers/functionPrinter.ts +0 -196
- package/src/printers/index.ts +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as syncOptionality, C as createParameter, Ct as httpMethods, D as createRoot, E as createResponse, Et as schemaTypes, N as ParserOptions, O as createSchema, R as OperationNode, S as createOperation, T as createProperty, Tt as mediaTypes, W as ParameterNode, _ as createPrinterFactory, _t as ParameterGroupNode, at as SchemaNodeByType, b as createFunctionParameter, d as transform, f as walk, g as PrinterFactoryOptions, gt as FunctionParametersNode, ht as FunctionParameterNode, it as SchemaNode, k as createTypeNode, l as collect, m as extractRefName, u as composeTransformers, v as definePrinter, w as createParameterGroup, wt as isScalarPrimitive, x as createFunctionParameters, xt as ScalarPrimitive } from "./visitor-DsdLcLjR.js";
|
|
3
3
|
|
|
4
4
|
//#region src/guards.d.ts
|
|
5
5
|
/**
|
|
@@ -12,17 +12,6 @@ import { A as createRoot, B as ResponseNode, C as createFunctionParameter, Ct as
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* Returns `true` when the input is a `RootNode`.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* if (isRootNode(node)) {
|
|
21
|
-
* console.log(node.schemas.length)
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
declare const isRootNode: (node: unknown) => node is RootNode;
|
|
26
15
|
/**
|
|
27
16
|
* Returns `true` when the input is an `OperationNode`.
|
|
28
17
|
*
|
|
@@ -45,132 +34,6 @@ declare const isOperationNode: (node: unknown) => node is OperationNode;
|
|
|
45
34
|
* ```
|
|
46
35
|
*/
|
|
47
36
|
declare const isSchemaNode: (node: unknown) => node is SchemaNode;
|
|
48
|
-
/**
|
|
49
|
-
* Returns `true` when the input is a `PropertyNode`.
|
|
50
|
-
*/
|
|
51
|
-
declare const isPropertyNode: (node: unknown) => node is PropertyNode;
|
|
52
|
-
/**
|
|
53
|
-
* Returns `true` when the input is a `ParameterNode`.
|
|
54
|
-
*/
|
|
55
|
-
declare const isParameterNode: (node: unknown) => node is ParameterNode;
|
|
56
|
-
/**
|
|
57
|
-
* Returns `true` when the input is a `ResponseNode`.
|
|
58
|
-
*/
|
|
59
|
-
declare const isResponseNode: (node: unknown) => node is ResponseNode;
|
|
60
|
-
/**
|
|
61
|
-
* Returns `true` when the input is a `FunctionParameterNode`.
|
|
62
|
-
*/
|
|
63
|
-
declare const isFunctionParameterNode: (node: unknown) => node is FunctionParameterNode;
|
|
64
|
-
/**
|
|
65
|
-
* Returns `true` when the input is an `ObjectBindingParameterNode`.
|
|
66
|
-
*/
|
|
67
|
-
declare const isObjectBindingParameterNode: (node: unknown) => node is ObjectBindingParameterNode;
|
|
68
|
-
/**
|
|
69
|
-
* Returns `true` when the input is a `FunctionParametersNode`.
|
|
70
|
-
*/
|
|
71
|
-
declare const isFunctionParametersNode: (node: unknown) => node is FunctionParametersNode;
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/printers/functionPrinter.d.ts
|
|
74
|
-
/**
|
|
75
|
-
* Creates a function-parameter printer factory.
|
|
76
|
-
*
|
|
77
|
-
* This wrapper uses `createPrinterFactory` and dispatches handlers by `node.kind`
|
|
78
|
-
* (for function nodes) rather than by `node.type` (for schema nodes).
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* type MyPrinter = PrinterFactoryOptions<'my', { mode: 'declaration' | 'call' }, string>
|
|
83
|
-
*
|
|
84
|
-
* export const myPrinter = defineFunctionPrinter<MyPrinter>((options) => ({
|
|
85
|
-
* name: 'my',
|
|
86
|
-
* options,
|
|
87
|
-
* nodes: {
|
|
88
|
-
* functionParameter(node) {
|
|
89
|
-
* return options.mode === 'declaration' && node.type ? `${node.name}: ${node.type}` : node.name
|
|
90
|
-
* },
|
|
91
|
-
* objectBindingParameter(node) {
|
|
92
|
-
* const inner = node.properties.map(p => this.transform(p)).filter(Boolean).join(', ')
|
|
93
|
-
* return `{ ${inner} }`
|
|
94
|
-
* },
|
|
95
|
-
* functionParameters(node) {
|
|
96
|
-
* return node.params.map(p => this.transform(p)).filter(Boolean).join(', ')
|
|
97
|
-
* },
|
|
98
|
-
* },
|
|
99
|
-
* }))
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare const defineFunctionPrinter: <T extends PrinterFactoryOptions>(build: (options: T["options"]) => {
|
|
103
|
-
name: T["name"];
|
|
104
|
-
options: T["options"];
|
|
105
|
-
nodes: Partial<{
|
|
106
|
-
functionParameter: (this: {
|
|
107
|
-
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
108
|
-
options: T["options"];
|
|
109
|
-
}, node: FunctionParameterNode) => T["output"] | null | undefined;
|
|
110
|
-
objectBindingParameter: (this: {
|
|
111
|
-
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
112
|
-
options: T["options"];
|
|
113
|
-
}, node: ObjectBindingParameterNode) => T["output"] | null | undefined;
|
|
114
|
-
functionParameters: (this: {
|
|
115
|
-
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
116
|
-
options: T["options"];
|
|
117
|
-
}, node: FunctionParametersNode) => T["output"] | null | undefined;
|
|
118
|
-
}>;
|
|
119
|
-
print?: ((this: {
|
|
120
|
-
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
121
|
-
options: T["options"];
|
|
122
|
-
}, node: FunctionNode) => T["printOutput"] | null | undefined) | undefined;
|
|
123
|
-
}) => (options?: T["options"] | undefined) => {
|
|
124
|
-
name: T["name"];
|
|
125
|
-
options: T["options"];
|
|
126
|
-
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
127
|
-
print: (node: FunctionNode) => T["printOutput"] | null | undefined;
|
|
128
|
-
};
|
|
129
|
-
type FunctionPrinterOptions = {
|
|
130
|
-
/**
|
|
131
|
-
* Rendering modes supported by `functionPrinter`.
|
|
132
|
-
*
|
|
133
|
-
* | Mode | Output example | Use case |
|
|
134
|
-
* |---------------|---------------------------------------------|---------------------------------|
|
|
135
|
-
* | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |
|
|
136
|
-
* | `call` | `id, { method, url }` | Function call arguments |
|
|
137
|
-
* | `keys` | `{ id, config }` | Key names only (destructuring) |
|
|
138
|
-
* | `values` | `{ id: id, config: config }` | Key/value object entries |
|
|
139
|
-
*/
|
|
140
|
-
mode: 'declaration' | 'call' | 'keys' | 'values';
|
|
141
|
-
/**
|
|
142
|
-
* Optional transformation applied to every parameter name before printing.
|
|
143
|
-
*/
|
|
144
|
-
transformName?: (name: string) => string;
|
|
145
|
-
/**
|
|
146
|
-
* Optional transformation applied to every type string before printing.
|
|
147
|
-
*/
|
|
148
|
-
transformType?: (type: string) => string;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Default function-signature printer.
|
|
152
|
-
* Covers the four standard output modes used across Kubb plugins.
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```ts
|
|
156
|
-
* const printer = functionPrinter({ mode: 'declaration' })
|
|
157
|
-
*
|
|
158
|
-
* const sig = createFunctionParameters({
|
|
159
|
-
* params: [
|
|
160
|
-
* createFunctionParameter({ name: 'petId', type: 'string', optional: false }),
|
|
161
|
-
* createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),
|
|
162
|
-
* ],
|
|
163
|
-
* })
|
|
164
|
-
*
|
|
165
|
-
* printer.print(sig) // → "petId: string, config: Config = {}"
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
|
|
169
|
-
name: "functionParameters";
|
|
170
|
-
options: FunctionPrinterOptions;
|
|
171
|
-
transform: (node: FunctionNode) => string | null | undefined;
|
|
172
|
-
print: (node: FunctionNode) => string | null | undefined;
|
|
173
|
-
};
|
|
174
37
|
//#endregion
|
|
175
38
|
//#region src/resolvers.d.ts
|
|
176
39
|
declare function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null;
|
|
@@ -242,32 +105,18 @@ declare function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaN
|
|
|
242
105
|
*/
|
|
243
106
|
declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
244
107
|
declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
|
|
245
|
-
/**
|
|
246
|
-
* Walks a schema tree and resolves `ref`/`enum` names through callbacks.
|
|
247
|
-
*/
|
|
248
|
-
declare function resolveNames({
|
|
249
|
-
node,
|
|
250
|
-
nameMapping,
|
|
251
|
-
resolveName,
|
|
252
|
-
resolveEnumName
|
|
253
|
-
}: {
|
|
254
|
-
node: SchemaNode;
|
|
255
|
-
nameMapping: Map<string, string>;
|
|
256
|
-
resolveName: (ref: string) => string | undefined;
|
|
257
|
-
resolveEnumName?: (name: string) => string | undefined;
|
|
258
|
-
}): SchemaNode;
|
|
259
108
|
//#endregion
|
|
260
109
|
//#region src/utils.d.ts
|
|
261
110
|
/**
|
|
262
|
-
* Returns `true` when a schema is emitted as a plain
|
|
111
|
+
* Returns `true` when a schema is emitted as a plain `string` type.
|
|
263
112
|
*
|
|
264
113
|
* - `string`, `uuid`, `email`, `url`, `datetime` are always plain strings.
|
|
265
114
|
* - `date` and `time` are plain strings when their `representation` is `'string'` rather than `'date'`.
|
|
266
115
|
*
|
|
267
116
|
* @example
|
|
268
117
|
* ```ts
|
|
269
|
-
* isStringType(createSchema({ type: 'uuid' }))
|
|
270
|
-
* isStringType(createSchema({ type: 'date', representation: 'date' }))
|
|
118
|
+
* isStringType(createSchema({ type: 'uuid' })) // true
|
|
119
|
+
* isStringType(createSchema({ type: 'date', representation: 'date' })) // false
|
|
271
120
|
* ```
|
|
272
121
|
*/
|
|
273
122
|
declare function isStringType(node: SchemaNode): boolean;
|
|
@@ -290,12 +139,162 @@ declare function isStringType(node: SchemaNode): boolean;
|
|
|
290
139
|
*/
|
|
291
140
|
declare function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode>;
|
|
292
141
|
/**
|
|
293
|
-
*
|
|
142
|
+
* Creates a single-property object schema used as a discriminator literal.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* createDiscriminantNode({ propertyName: 'type', value: 'dog' })
|
|
147
|
+
* // -> { type: 'object', properties: [{ name: 'type', required: true, schema: enum('dog') }] }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function createDiscriminantNode({
|
|
151
|
+
propertyName,
|
|
152
|
+
value
|
|
153
|
+
}: {
|
|
154
|
+
propertyName: string;
|
|
155
|
+
value: string;
|
|
156
|
+
}): SchemaNode;
|
|
157
|
+
/**
|
|
158
|
+
* Resolver interface for {@link createOperationParams}.
|
|
159
|
+
*
|
|
160
|
+
* `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.
|
|
161
|
+
*/
|
|
162
|
+
type OperationParamsResolver = {
|
|
163
|
+
/**
|
|
164
|
+
* Resolves the type name for an individual parameter.
|
|
165
|
+
*
|
|
166
|
+
* @example Individual path parameter name
|
|
167
|
+
* `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`
|
|
168
|
+
*/
|
|
169
|
+
resolveParamName(node: OperationNode, param: ParameterNode): string;
|
|
170
|
+
/**
|
|
171
|
+
* Resolves the request body type name.
|
|
172
|
+
*
|
|
173
|
+
* @example Request body type name
|
|
174
|
+
* `resolver.resolveDataName(node) // → 'CreatePetData'`
|
|
175
|
+
*/
|
|
176
|
+
resolveDataName(node: OperationNode): string;
|
|
177
|
+
/**
|
|
178
|
+
* Resolves the grouped path parameters type name.
|
|
179
|
+
* When the return value equals `resolveParamName`, no indexed access is emitted.
|
|
180
|
+
*
|
|
181
|
+
* @example Grouped path params type name
|
|
182
|
+
* `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`
|
|
183
|
+
*/
|
|
184
|
+
resolvePathParamsName(node: OperationNode, param: ParameterNode): string;
|
|
185
|
+
/**
|
|
186
|
+
* Resolves the grouped query parameters type name.
|
|
187
|
+
* When the return value equals `resolveParamName`, an inline struct type is emitted instead.
|
|
188
|
+
*
|
|
189
|
+
* @example Grouped query params type name
|
|
190
|
+
* `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`
|
|
191
|
+
*/
|
|
192
|
+
resolveQueryParamsName(node: OperationNode, param: ParameterNode): string;
|
|
193
|
+
/**
|
|
194
|
+
* Resolves the grouped header parameters type name.
|
|
195
|
+
* When the return value equals `resolveParamName`, an inline struct type is emitted instead.
|
|
196
|
+
*
|
|
197
|
+
* @example Grouped header params type name
|
|
198
|
+
* `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`
|
|
199
|
+
*/
|
|
200
|
+
resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Options for {@link createOperationParams}.
|
|
204
|
+
*/
|
|
205
|
+
type CreateOperationParamsOptions = {
|
|
206
|
+
/**
|
|
207
|
+
* How all operation parameters are grouped in the function signature.
|
|
208
|
+
* - `'object'` wraps all params into a single destructured object `{ petId, data, params }`
|
|
209
|
+
* - `'inline'` emits each param category as a separate top-level parameter
|
|
210
|
+
*/
|
|
211
|
+
paramsType: 'object' | 'inline';
|
|
212
|
+
/**
|
|
213
|
+
* How path parameters are emitted when `paramsType` is `'inline'`.
|
|
214
|
+
* - `'object'` groups them as `{ petId, storeId }: PathParams`
|
|
215
|
+
* - `'inline'` spreads them as individual parameters `petId: string, storeId: string`
|
|
216
|
+
* - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`
|
|
217
|
+
*/
|
|
218
|
+
pathParamsType: 'object' | 'inline' | 'inlineSpread';
|
|
219
|
+
/**
|
|
220
|
+
* Converts parameter names to camelCase before output.
|
|
221
|
+
*/
|
|
222
|
+
paramsCasing?: 'camelcase';
|
|
223
|
+
/**
|
|
224
|
+
* Resolver for parameter and request body type names.
|
|
225
|
+
* Pass `ResolverTs` from `@kubb/plugin-ts` directly.
|
|
226
|
+
* When omitted, falls back to the schema primitive or `'unknown'`.
|
|
227
|
+
*/
|
|
228
|
+
resolver?: OperationParamsResolver;
|
|
229
|
+
/**
|
|
230
|
+
* Default value for the path parameters binding when `pathParamsType` is `'object'`.
|
|
231
|
+
* Falls back to `'{}'` when all path params are optional.
|
|
232
|
+
*/
|
|
233
|
+
pathParamsDefault?: string;
|
|
234
|
+
/**
|
|
235
|
+
* Extra parameters appended after the standard operation parameters.
|
|
236
|
+
*
|
|
237
|
+
* @example Plugin-specific trailing parameter
|
|
238
|
+
* ```ts
|
|
239
|
+
* extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
extraParams?: Array<FunctionParameterNode | ParameterGroupNode>;
|
|
243
|
+
/**
|
|
244
|
+
* Override the default parameter names used for body, query, header, and rest-path groups.
|
|
245
|
+
*
|
|
246
|
+
* Useful when targeting languages or frameworks with different naming conventions.
|
|
247
|
+
*
|
|
248
|
+
* @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }
|
|
249
|
+
*/
|
|
250
|
+
paramNames?: {
|
|
251
|
+
/**
|
|
252
|
+
* Name for the request body parameter.
|
|
253
|
+
* @default 'data'
|
|
254
|
+
*/
|
|
255
|
+
data?: string;
|
|
256
|
+
/**
|
|
257
|
+
* Name for the query parameters group parameter.
|
|
258
|
+
* @default 'params'
|
|
259
|
+
*/
|
|
260
|
+
params?: string;
|
|
261
|
+
/**
|
|
262
|
+
* Name for the header parameters group parameter.
|
|
263
|
+
* @default 'headers'
|
|
264
|
+
*/
|
|
265
|
+
headers?: string;
|
|
266
|
+
/**
|
|
267
|
+
* Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.
|
|
268
|
+
* @default 'pathParams'
|
|
269
|
+
*/
|
|
270
|
+
path?: string;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Applies a uniform transformation to every resolved type name before it is used
|
|
274
|
+
* in a parameter node. Use this for framework-level type wrappers.
|
|
275
|
+
*
|
|
276
|
+
* @example Vue Query — wrap every parameter type with `MaybeRefOrGetter`
|
|
277
|
+
* `typeWrapper: (t) => \`MaybeRefOrGetter<${t}>\``
|
|
278
|
+
*/
|
|
279
|
+
typeWrapper?: (type: string) => string;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Converts an {@link OperationNode} into a {@link FunctionParametersNode}.
|
|
294
283
|
*
|
|
295
|
-
* - `
|
|
296
|
-
*
|
|
284
|
+
* Centralizes the per-plugin `getParams()` pattern. Provide a `resolver` for
|
|
285
|
+
* type resolution and `extraParams` for plugin-specific trailing parameters.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* const params = createOperationParams(node, {
|
|
290
|
+
* paramsType: 'inline',
|
|
291
|
+
* pathParamsType: 'inline',
|
|
292
|
+
* resolver: tsResolver,
|
|
293
|
+
* extraParams: [createFunctionParameter({ name: 'options', type: createTypeNode({ variant: 'reference', name: 'Partial<RequestOptions>' }), default: '{}' })],
|
|
294
|
+
* })
|
|
295
|
+
* ```
|
|
297
296
|
*/
|
|
298
|
-
declare function
|
|
297
|
+
declare function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
|
|
299
298
|
//#endregion
|
|
300
|
-
export { type
|
|
299
|
+
export { type OperationParamsResolver, type ParserOptions, type PrinterFactoryOptions, type ScalarPrimitive, caseParams, childName, collect, collectImports, composeTransformers, createDiscriminantNode, createFunctionParameter, createFunctionParameters, createOperation, createOperationParams, createParameter, createParameterGroup, createPrinterFactory, createProperty, createResponse, createRoot, createSchema, createTypeNode, definePrinter, enumPropName, extractRefName, findDiscriminator, httpMethods, isOperationNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, transform, walk };
|
|
301
300
|
//# sourceMappingURL=index.d.ts.map
|