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