@kubb/ast 5.0.0-alpha.15 → 5.0.0-alpha.17
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 +1069 -626
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +238 -52
- package/dist/index.js +1054 -624
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/visitor-BFn3X90U.d.ts +1974 -0
- package/package.json +1 -1
- package/src/constants.ts +92 -3
- package/src/factory.ts +174 -37
- package/src/guards.ts +37 -10
- package/src/index.ts +8 -6
- package/src/infer.ts +130 -0
- package/src/mocks.ts +4 -3
- package/src/nodes/base.ts +21 -3
- package/src/nodes/function.ts +34 -22
- package/src/nodes/http.ts +17 -5
- package/src/nodes/index.ts +14 -4
- package/src/nodes/operation.ts +47 -9
- package/src/nodes/parameter.ts +27 -1
- package/src/nodes/property.ts +23 -1
- package/src/nodes/response.ts +23 -3
- package/src/nodes/root.ts +29 -8
- package/src/nodes/schema.ts +298 -36
- package/src/{functionPrinter.ts → printers/functionPrinter.ts} +20 -19
- package/src/printers/index.ts +3 -0
- package/src/{printer.ts → printers/printer.ts} +58 -42
- package/src/refs.ts +36 -4
- package/src/resolvers.ts +45 -0
- package/src/transformers.ts +196 -0
- package/src/types.ts +2 -1
- package/src/utils.ts +37 -8
- package/src/visitor.ts +204 -18
- package/dist/visitor-UlWOe-In.d.ts +0 -961
package/src/nodes/schema.ts
CHANGED
|
@@ -2,236 +2,498 @@ import type { BaseNode } from './base.ts'
|
|
|
2
2
|
import type { PropertyNode } from './property.ts'
|
|
3
3
|
|
|
4
4
|
export type PrimitiveSchemaType =
|
|
5
|
+
/**
|
|
6
|
+
* Text value.
|
|
7
|
+
*/
|
|
5
8
|
| 'string'
|
|
9
|
+
/**
|
|
10
|
+
* Floating-point number.
|
|
11
|
+
*/
|
|
6
12
|
| 'number'
|
|
13
|
+
/**
|
|
14
|
+
* Integer number.
|
|
15
|
+
*/
|
|
7
16
|
| 'integer'
|
|
17
|
+
/**
|
|
18
|
+
* Big integer number.
|
|
19
|
+
*/
|
|
8
20
|
| 'bigint'
|
|
21
|
+
/**
|
|
22
|
+
* Boolean value.
|
|
23
|
+
*/
|
|
9
24
|
| 'boolean'
|
|
25
|
+
/**
|
|
26
|
+
* Null value.
|
|
27
|
+
*/
|
|
10
28
|
| 'null'
|
|
29
|
+
/**
|
|
30
|
+
* Any value.
|
|
31
|
+
*/
|
|
11
32
|
| 'any'
|
|
33
|
+
/**
|
|
34
|
+
* Unknown value.
|
|
35
|
+
*/
|
|
12
36
|
| 'unknown'
|
|
37
|
+
/**
|
|
38
|
+
* No value (`void`).
|
|
39
|
+
*/
|
|
13
40
|
| 'void'
|
|
41
|
+
/**
|
|
42
|
+
* Never value.
|
|
43
|
+
*/
|
|
14
44
|
| 'never'
|
|
45
|
+
/**
|
|
46
|
+
* Object value.
|
|
47
|
+
*/
|
|
15
48
|
| 'object'
|
|
49
|
+
/**
|
|
50
|
+
* Array value.
|
|
51
|
+
*/
|
|
16
52
|
| 'array'
|
|
53
|
+
/**
|
|
54
|
+
* Date value.
|
|
55
|
+
*/
|
|
17
56
|
| 'date'
|
|
18
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Composite schema types.
|
|
60
|
+
*/
|
|
19
61
|
export type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum'
|
|
20
62
|
|
|
21
63
|
/**
|
|
22
|
-
*
|
|
64
|
+
* Schema types that need special handling in generators.
|
|
23
65
|
*/
|
|
24
66
|
export type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'blob'
|
|
25
67
|
|
|
68
|
+
/**
|
|
69
|
+
* All schema type strings.
|
|
70
|
+
*/
|
|
26
71
|
export type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType
|
|
27
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Scalar schema types without extra object/array/ref structure.
|
|
75
|
+
*/
|
|
28
76
|
export type ScalarSchemaType = Exclude<
|
|
29
77
|
SchemaType,
|
|
30
78
|
'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint' | 'url'
|
|
31
79
|
>
|
|
32
80
|
|
|
33
81
|
/**
|
|
34
|
-
*
|
|
82
|
+
* Fields shared by all schema nodes.
|
|
35
83
|
*/
|
|
36
84
|
type SchemaNodeBase = BaseNode & {
|
|
85
|
+
/**
|
|
86
|
+
* Node kind.
|
|
87
|
+
*/
|
|
37
88
|
kind: 'Schema'
|
|
38
89
|
/**
|
|
39
|
-
*
|
|
90
|
+
* Schema name for named definitions (for example, `"Pet"`).
|
|
91
|
+
* Inline schemas omit this field.
|
|
40
92
|
*/
|
|
41
93
|
name?: string
|
|
94
|
+
/**
|
|
95
|
+
* Short schema title.
|
|
96
|
+
*/
|
|
42
97
|
title?: string
|
|
98
|
+
/**
|
|
99
|
+
* Schema description text.
|
|
100
|
+
*/
|
|
43
101
|
description?: string
|
|
102
|
+
/**
|
|
103
|
+
* Whether `null` is allowed.
|
|
104
|
+
*/
|
|
44
105
|
nullable?: boolean
|
|
106
|
+
/**
|
|
107
|
+
* Whether the field is optional.
|
|
108
|
+
*/
|
|
45
109
|
optional?: boolean
|
|
46
110
|
/**
|
|
47
111
|
* Both optional and nullable (`optional` + `nullable`).
|
|
48
112
|
*/
|
|
49
113
|
nullish?: boolean
|
|
114
|
+
/**
|
|
115
|
+
* Whether the schema is deprecated.
|
|
116
|
+
*/
|
|
50
117
|
deprecated?: boolean
|
|
118
|
+
/**
|
|
119
|
+
* Whether the schema is read-only.
|
|
120
|
+
*/
|
|
51
121
|
readOnly?: boolean
|
|
122
|
+
/**
|
|
123
|
+
* Whether the schema is write-only.
|
|
124
|
+
*/
|
|
52
125
|
writeOnly?: boolean
|
|
126
|
+
/**
|
|
127
|
+
* Default value.
|
|
128
|
+
*/
|
|
53
129
|
default?: unknown
|
|
130
|
+
/**
|
|
131
|
+
* Example value.
|
|
132
|
+
*/
|
|
54
133
|
example?: unknown
|
|
55
134
|
/**
|
|
56
|
-
*
|
|
135
|
+
* Base primitive type.
|
|
136
|
+
* For example, this is `'string'` for a `uuid` schema.
|
|
57
137
|
*/
|
|
58
138
|
primitive?: PrimitiveSchemaType
|
|
59
139
|
}
|
|
60
140
|
|
|
61
141
|
/**
|
|
62
|
-
* Object schema with ordered
|
|
142
|
+
* Object schema with ordered properties.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const objectSchema: ObjectSchemaNode = {
|
|
147
|
+
* kind: 'Schema',
|
|
148
|
+
* type: 'object',
|
|
149
|
+
* properties: [],
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
63
152
|
*/
|
|
64
153
|
export type ObjectSchemaNode = SchemaNodeBase & {
|
|
154
|
+
/**
|
|
155
|
+
* Schema type discriminator.
|
|
156
|
+
*/
|
|
65
157
|
type: 'object'
|
|
158
|
+
/**
|
|
159
|
+
* Ordered object properties.
|
|
160
|
+
*/
|
|
66
161
|
properties: Array<PropertyNode>
|
|
67
162
|
/**
|
|
68
|
-
*
|
|
163
|
+
* Additional object properties behavior:
|
|
164
|
+
* - `true`: allow any value
|
|
165
|
+
* - `SchemaNode`: allow values that match that schema
|
|
166
|
+
* - `undefined`: no additional properties
|
|
69
167
|
*/
|
|
70
168
|
additionalProperties?: SchemaNode | true
|
|
169
|
+
/**
|
|
170
|
+
* Pattern-based property schemas.
|
|
171
|
+
*/
|
|
71
172
|
patternProperties?: Record<string, SchemaNode>
|
|
72
173
|
}
|
|
73
174
|
|
|
74
175
|
/**
|
|
75
|
-
* Array or tuple
|
|
176
|
+
* Array-like schema (`array` or `tuple`).
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const arraySchema: ArraySchemaNode = {
|
|
181
|
+
* kind: 'Schema',
|
|
182
|
+
* type: 'array',
|
|
183
|
+
* items: [],
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
76
186
|
*/
|
|
77
187
|
export type ArraySchemaNode = SchemaNodeBase & {
|
|
188
|
+
/**
|
|
189
|
+
* Schema type discriminator (`array` or `tuple`).
|
|
190
|
+
*/
|
|
78
191
|
type: 'array' | 'tuple'
|
|
192
|
+
/**
|
|
193
|
+
* Item schemas.
|
|
194
|
+
*/
|
|
79
195
|
items?: Array<SchemaNode>
|
|
80
196
|
/**
|
|
81
|
-
*
|
|
197
|
+
* Tuple rest-item schema for elements beyond positional `items`.
|
|
82
198
|
*/
|
|
83
199
|
rest?: SchemaNode
|
|
200
|
+
/**
|
|
201
|
+
* Minimum item count (or tuple length).
|
|
202
|
+
*/
|
|
84
203
|
min?: number
|
|
204
|
+
/**
|
|
205
|
+
* Maximum item count (or tuple length).
|
|
206
|
+
*/
|
|
85
207
|
max?: number
|
|
208
|
+
/**
|
|
209
|
+
* Whether all items must be unique.
|
|
210
|
+
*/
|
|
86
211
|
unique?: boolean
|
|
87
212
|
}
|
|
88
213
|
|
|
89
214
|
/**
|
|
90
|
-
* Shared
|
|
215
|
+
* Shared shape for union and intersection schemas.
|
|
91
216
|
*/
|
|
92
217
|
type CompositeSchemaNodeBase = SchemaNodeBase & {
|
|
218
|
+
/**
|
|
219
|
+
* Member schemas.
|
|
220
|
+
*/
|
|
93
221
|
members?: Array<SchemaNode>
|
|
94
222
|
}
|
|
95
223
|
|
|
96
224
|
/**
|
|
97
|
-
* Union schema
|
|
225
|
+
* Union schema, often from `oneOf` or `anyOf`.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* const unionSchema: UnionSchemaNode = {
|
|
230
|
+
* kind: 'Schema',
|
|
231
|
+
* type: 'union',
|
|
232
|
+
* members: [],
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
98
235
|
*/
|
|
99
236
|
export type UnionSchemaNode = CompositeSchemaNodeBase & {
|
|
237
|
+
/**
|
|
238
|
+
* Schema type discriminator.
|
|
239
|
+
*/
|
|
100
240
|
type: 'union'
|
|
101
241
|
/**
|
|
102
|
-
* Discriminator property from
|
|
242
|
+
* Discriminator property name from OpenAPI `discriminator.propertyName`.
|
|
103
243
|
*/
|
|
104
244
|
discriminatorPropertyName?: string
|
|
105
245
|
}
|
|
106
246
|
|
|
107
247
|
/**
|
|
108
|
-
* Intersection schema
|
|
248
|
+
* Intersection schema, often from `allOf`.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* const intersectionSchema: IntersectionSchemaNode = {
|
|
253
|
+
* kind: 'Schema',
|
|
254
|
+
* type: 'intersection',
|
|
255
|
+
* members: [],
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
109
258
|
*/
|
|
110
259
|
export type IntersectionSchemaNode = CompositeSchemaNodeBase & {
|
|
260
|
+
/**
|
|
261
|
+
* Schema type discriminator.
|
|
262
|
+
*/
|
|
111
263
|
type: 'intersection'
|
|
112
264
|
}
|
|
113
265
|
|
|
114
266
|
/**
|
|
115
|
-
*
|
|
267
|
+
* One named enum item.
|
|
116
268
|
*/
|
|
117
269
|
export type EnumValueNode = {
|
|
270
|
+
/**
|
|
271
|
+
* Enum item name.
|
|
272
|
+
*/
|
|
118
273
|
name: string
|
|
274
|
+
/**
|
|
275
|
+
* Enum item value.
|
|
276
|
+
*/
|
|
119
277
|
value: string | number | boolean
|
|
120
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Primitive type of the enum value.
|
|
280
|
+
*/
|
|
281
|
+
primitive: Extract<PrimitiveSchemaType, 'string' | 'number' | 'boolean'>
|
|
121
282
|
}
|
|
122
283
|
|
|
123
284
|
/**
|
|
124
|
-
* Enum schema.
|
|
285
|
+
* Enum schema node.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* const enumSchema: EnumSchemaNode = {
|
|
290
|
+
* kind: 'Schema',
|
|
291
|
+
* type: 'enum',
|
|
292
|
+
* enumValues: ['a', 'b'],
|
|
293
|
+
* }
|
|
294
|
+
* ```
|
|
125
295
|
*/
|
|
126
296
|
export type EnumSchemaNode = SchemaNodeBase & {
|
|
127
|
-
type: 'enum'
|
|
128
297
|
/**
|
|
129
|
-
*
|
|
298
|
+
* Schema type discriminator.
|
|
130
299
|
*/
|
|
131
|
-
|
|
300
|
+
type: 'enum'
|
|
132
301
|
/**
|
|
133
|
-
*
|
|
302
|
+
* Enum values in simple form.
|
|
134
303
|
*/
|
|
135
304
|
enumValues?: Array<string | number | boolean | null>
|
|
136
305
|
/**
|
|
137
|
-
*
|
|
306
|
+
* Enum values in named form.
|
|
307
|
+
* If present, this is used instead of `enumValues`.
|
|
138
308
|
*/
|
|
139
309
|
namedEnumValues?: Array<EnumValueNode>
|
|
140
310
|
}
|
|
141
311
|
|
|
142
312
|
/**
|
|
143
|
-
*
|
|
313
|
+
* Reference schema that points to another schema definition.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* const refSchema: RefSchemaNode = {
|
|
318
|
+
* kind: 'Schema',
|
|
319
|
+
* type: 'ref',
|
|
320
|
+
* ref: '#/components/schemas/Pet',
|
|
321
|
+
* }
|
|
322
|
+
* ```
|
|
144
323
|
*/
|
|
145
324
|
export type RefSchemaNode = SchemaNodeBase & {
|
|
325
|
+
/**
|
|
326
|
+
* Schema type discriminator.
|
|
327
|
+
*/
|
|
146
328
|
type: 'ref'
|
|
329
|
+
/**
|
|
330
|
+
* Referenced schema name.
|
|
331
|
+
*/
|
|
147
332
|
name?: string
|
|
148
333
|
/**
|
|
149
|
-
* Original `$ref` path
|
|
334
|
+
* Original `$ref` path, for example, `#/components/schemas/Order`.
|
|
335
|
+
* Used to resolve names later.
|
|
150
336
|
*/
|
|
151
337
|
ref?: string
|
|
152
338
|
/**
|
|
153
|
-
* Pattern
|
|
339
|
+
* Pattern copied from a sibling `pattern` field.
|
|
154
340
|
*/
|
|
155
341
|
pattern?: string
|
|
156
342
|
}
|
|
157
343
|
|
|
158
344
|
/**
|
|
159
345
|
* Datetime schema.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* const datetimeSchema: DatetimeSchemaNode = { kind: 'Schema', type: 'datetime' }
|
|
350
|
+
* ```
|
|
160
351
|
*/
|
|
161
352
|
export type DatetimeSchemaNode = SchemaNodeBase & {
|
|
353
|
+
/**
|
|
354
|
+
* Schema type discriminator.
|
|
355
|
+
*/
|
|
162
356
|
type: 'datetime'
|
|
163
357
|
/**
|
|
164
|
-
*
|
|
358
|
+
* Whether the datetime includes a timezone offset (`dateType: 'stringOffset'`).
|
|
165
359
|
*/
|
|
166
360
|
offset?: boolean
|
|
167
361
|
/**
|
|
168
|
-
*
|
|
362
|
+
* Whether the datetime is local (no timezone, `dateType: 'stringLocal'`).
|
|
169
363
|
*/
|
|
170
364
|
local?: boolean
|
|
171
365
|
}
|
|
172
366
|
|
|
173
367
|
/**
|
|
174
|
-
*
|
|
368
|
+
* Shared base for `date` and `time` schemas.
|
|
175
369
|
*/
|
|
176
370
|
type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
|
|
371
|
+
/**
|
|
372
|
+
* Schema type discriminator.
|
|
373
|
+
*/
|
|
177
374
|
type: T
|
|
178
375
|
/**
|
|
179
|
-
*
|
|
376
|
+
* Output representation in generated code.
|
|
180
377
|
*/
|
|
181
378
|
representation: 'date' | 'string'
|
|
182
379
|
}
|
|
183
380
|
|
|
184
381
|
/**
|
|
185
|
-
* Date schema.
|
|
382
|
+
* Date schema node.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* const dateSchema: DateSchemaNode = { kind: 'Schema', type: 'date', representation: 'string' }
|
|
387
|
+
* ```
|
|
186
388
|
*/
|
|
187
389
|
export type DateSchemaNode = TemporalSchemaNodeBase<'date'>
|
|
188
390
|
|
|
189
391
|
/**
|
|
190
|
-
* Time schema.
|
|
392
|
+
* Time schema node.
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```ts
|
|
396
|
+
* const timeSchema: TimeSchemaNode = { kind: 'Schema', type: 'time', representation: 'string' }
|
|
397
|
+
* ```
|
|
191
398
|
*/
|
|
192
399
|
export type TimeSchemaNode = TemporalSchemaNodeBase<'time'>
|
|
193
400
|
|
|
194
401
|
/**
|
|
195
|
-
* String schema.
|
|
402
|
+
* String schema node.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* const stringSchema: StringSchemaNode = { kind: 'Schema', type: 'string' }
|
|
407
|
+
* ```
|
|
196
408
|
*/
|
|
197
409
|
export type StringSchemaNode = SchemaNodeBase & {
|
|
410
|
+
/**
|
|
411
|
+
* Schema type discriminator.
|
|
412
|
+
*/
|
|
198
413
|
type: 'string'
|
|
414
|
+
/**
|
|
415
|
+
* Minimum string length.
|
|
416
|
+
*/
|
|
199
417
|
min?: number
|
|
418
|
+
/**
|
|
419
|
+
* Maximum string length.
|
|
420
|
+
*/
|
|
200
421
|
max?: number
|
|
422
|
+
/**
|
|
423
|
+
* Regex pattern.
|
|
424
|
+
*/
|
|
201
425
|
pattern?: string
|
|
202
426
|
}
|
|
203
427
|
|
|
204
428
|
/**
|
|
205
|
-
*
|
|
429
|
+
* Numeric schema (`number`, `integer`, or `bigint`).
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```ts
|
|
433
|
+
* const numberSchema: NumberSchemaNode = { kind: 'Schema', type: 'number' }
|
|
434
|
+
* ```
|
|
206
435
|
*/
|
|
207
436
|
export type NumberSchemaNode = SchemaNodeBase & {
|
|
437
|
+
/**
|
|
438
|
+
* Schema type discriminator.
|
|
439
|
+
*/
|
|
208
440
|
type: 'number' | 'integer' | 'bigint'
|
|
441
|
+
/**
|
|
442
|
+
* Minimum value.
|
|
443
|
+
*/
|
|
209
444
|
min?: number
|
|
445
|
+
/**
|
|
446
|
+
* Maximum value.
|
|
447
|
+
*/
|
|
210
448
|
max?: number
|
|
449
|
+
/**
|
|
450
|
+
* Exclusive minimum value.
|
|
451
|
+
*/
|
|
211
452
|
exclusiveMinimum?: number
|
|
453
|
+
/**
|
|
454
|
+
* Exclusive maximum value.
|
|
455
|
+
*/
|
|
212
456
|
exclusiveMaximum?: number
|
|
213
457
|
}
|
|
214
458
|
|
|
215
459
|
/**
|
|
216
|
-
*
|
|
460
|
+
* Scalar schema with no extra constraints.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* const anySchema: ScalarSchemaNode = { kind: 'Schema', type: 'any' }
|
|
465
|
+
* ```
|
|
217
466
|
*/
|
|
218
467
|
export type ScalarSchemaNode = SchemaNodeBase & {
|
|
468
|
+
/**
|
|
469
|
+
* Schema type discriminator.
|
|
470
|
+
*/
|
|
219
471
|
type: ScalarSchemaType
|
|
220
472
|
}
|
|
221
473
|
|
|
222
474
|
/**
|
|
223
|
-
* URL schema
|
|
475
|
+
* URL schema node.
|
|
476
|
+
* Can include an Express-style path template for template literal types.
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```ts
|
|
480
|
+
* const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets/:petId' }
|
|
481
|
+
* ```
|
|
224
482
|
*/
|
|
225
483
|
export type UrlSchemaNode = SchemaNodeBase & {
|
|
484
|
+
/**
|
|
485
|
+
* Schema type discriminator.
|
|
486
|
+
*/
|
|
226
487
|
type: 'url'
|
|
227
488
|
/**
|
|
228
|
-
* Express-style path
|
|
489
|
+
* Express-style path template, for example, `'/pets/:petId'`.
|
|
229
490
|
*/
|
|
230
491
|
path?: string
|
|
231
492
|
}
|
|
232
493
|
|
|
233
494
|
/**
|
|
234
|
-
*
|
|
495
|
+
* Mapping from schema type literals to concrete schema node types.
|
|
496
|
+
* Used by `narrowSchema`.
|
|
235
497
|
*/
|
|
236
498
|
export type SchemaNodeByType = {
|
|
237
499
|
object: ObjectSchemaNode
|
|
@@ -261,7 +523,7 @@ export type SchemaNodeByType = {
|
|
|
261
523
|
}
|
|
262
524
|
|
|
263
525
|
/**
|
|
264
|
-
*
|
|
526
|
+
* Union of all schema node types.
|
|
265
527
|
*/
|
|
266
528
|
export type SchemaNode =
|
|
267
529
|
| ObjectSchemaNode
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { FunctionNode, FunctionNodeType } from '
|
|
2
|
-
import type { FunctionParameterNode, FunctionParametersNode, ObjectBindingParameterNode } from '
|
|
1
|
+
import type { FunctionNode, FunctionNodeType } from '../nodes/function.ts'
|
|
2
|
+
import type { FunctionParameterNode, FunctionParametersNode, ObjectBindingParameterNode } from '../nodes/index.ts'
|
|
3
3
|
import type { PrinterFactoryOptions } from './printer.ts'
|
|
4
4
|
import { createPrinterFactory } from './printer.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Maps each
|
|
7
|
+
* Maps each function-printer handler key to its concrete node type.
|
|
8
8
|
*/
|
|
9
9
|
export type FunctionNodeByType = {
|
|
10
10
|
functionParameter: FunctionParameterNode
|
|
@@ -19,8 +19,10 @@ const kindToHandlerKey = {
|
|
|
19
19
|
} satisfies Record<string, FunctionNodeType>
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Creates a
|
|
23
|
-
*
|
|
22
|
+
* Creates a function-parameter printer factory.
|
|
23
|
+
*
|
|
24
|
+
* This wrapper uses `createPrinterFactory` and dispatches handlers by `node.kind`
|
|
25
|
+
* (for function nodes) rather than by `node.type` (for schema nodes).
|
|
24
26
|
*
|
|
25
27
|
* @example
|
|
26
28
|
* ```ts
|
|
@@ -46,18 +48,17 @@ const kindToHandlerKey = {
|
|
|
46
48
|
*/
|
|
47
49
|
export const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>((node) => kindToHandlerKey[node.kind])
|
|
48
50
|
|
|
49
|
-
/**
|
|
50
|
-
* The four rendering modes for a `FunctionParametersNode`.
|
|
51
|
-
*
|
|
52
|
-
* | Mode | Output example | Use case |
|
|
53
|
-
* |---------------|---------------------------------------------|---------------------------------|
|
|
54
|
-
* | `declaration` | `id: string, config: Config = {}` | Function parameter declarations |
|
|
55
|
-
* | `call` | `id, { method, url }` | Function call arguments |
|
|
56
|
-
* | `keys` | `{ id, config }` | Key names only (destructuring) |
|
|
57
|
-
* | `values` | `{ id: id, config: config }` | Key → value pairs |
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
51
|
export type FunctionPrinterOptions = {
|
|
52
|
+
/**
|
|
53
|
+
* Rendering modes supported by `functionPrinter`.
|
|
54
|
+
*
|
|
55
|
+
* | Mode | Output example | Use case |
|
|
56
|
+
* |---------------|---------------------------------------------|---------------------------------|
|
|
57
|
+
* | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |
|
|
58
|
+
* | `call` | `id, { method, url }` | Function call arguments |
|
|
59
|
+
* | `keys` | `{ id, config }` | Key names only (destructuring) |
|
|
60
|
+
* | `values` | `{ id: id, config: config }` | Key/value object entries |
|
|
61
|
+
*/
|
|
61
62
|
mode: 'declaration' | 'call' | 'keys' | 'values'
|
|
62
63
|
/**
|
|
63
64
|
* Optional transformation applied to every parameter name before printing.
|
|
@@ -91,12 +92,12 @@ function sortChildParams(params: Array<FunctionParameterNode>): Array<FunctionPa
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
/**
|
|
94
|
-
* Default function-signature printer.
|
|
95
|
-
* used
|
|
95
|
+
* Default function-signature printer.
|
|
96
|
+
* Covers the four standard output modes used across Kubb plugins.
|
|
96
97
|
*
|
|
97
98
|
* @example
|
|
98
99
|
* ```ts
|
|
99
|
-
* const printer =
|
|
100
|
+
* const printer = functionPrinter({ mode: 'declaration' })
|
|
100
101
|
*
|
|
101
102
|
* const sig = createFunctionParameters({
|
|
102
103
|
* params: [
|