@kubb/ast 5.0.0-beta.6 → 5.0.0-beta.60

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 (78) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +50 -27
  3. package/dist/chunk-CNktS9qV.js +17 -0
  4. package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +82 -0
  5. package/dist/factory-Cl8Z7mcc.cjs +299 -0
  6. package/dist/factory-Cl8Z7mcc.cjs.map +1 -0
  7. package/dist/factory-Du7nEP4B.js +282 -0
  8. package/dist/factory-Du7nEP4B.js.map +1 -0
  9. package/dist/factory.cjs +29 -0
  10. package/dist/factory.d.ts +62 -0
  11. package/dist/factory.js +3 -0
  12. package/dist/index-BzjwdK2M.d.ts +2433 -0
  13. package/dist/index.cjs +442 -2180
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +93 -3408
  16. package/dist/index.js +392 -2101
  17. package/dist/index.js.map +1 -1
  18. package/dist/operationParams-BZ07xDm0.d.ts +204 -0
  19. package/dist/response-DKxTr522.js +683 -0
  20. package/dist/response-DKxTr522.js.map +1 -0
  21. package/dist/response-DS5S3IG4.cjs +1058 -0
  22. package/dist/response-DS5S3IG4.cjs.map +1 -0
  23. package/dist/types-olVl9v5p.d.ts +764 -0
  24. package/dist/types.cjs +0 -0
  25. package/dist/types.d.ts +5 -0
  26. package/dist/types.js +1 -0
  27. package/dist/utils-D83JA6Xx.cjs +1645 -0
  28. package/dist/utils-D83JA6Xx.cjs.map +1 -0
  29. package/dist/utils-Dj_KoXMv.js +1389 -0
  30. package/dist/utils-Dj_KoXMv.js.map +1 -0
  31. package/dist/utils.cjs +34 -0
  32. package/dist/utils.d.ts +332 -0
  33. package/dist/utils.js +3 -0
  34. package/package.json +17 -6
  35. package/src/constants.ts +19 -64
  36. package/src/dedupe.ts +239 -0
  37. package/src/dialect.ts +53 -0
  38. package/src/factory.ts +67 -678
  39. package/src/guards.ts +10 -92
  40. package/src/index.ts +16 -43
  41. package/src/infer.ts +16 -14
  42. package/src/mocks.ts +7 -127
  43. package/src/node.ts +128 -0
  44. package/src/nodes/base.ts +5 -12
  45. package/src/nodes/code.ts +165 -74
  46. package/src/nodes/content.ts +56 -0
  47. package/src/nodes/file.ts +97 -36
  48. package/src/nodes/function.ts +216 -156
  49. package/src/nodes/http.ts +1 -35
  50. package/src/nodes/index.ts +23 -15
  51. package/src/nodes/input.ts +140 -0
  52. package/src/nodes/operation.ts +122 -68
  53. package/src/nodes/output.ts +23 -0
  54. package/src/nodes/parameter.ts +33 -3
  55. package/src/nodes/property.ts +36 -3
  56. package/src/nodes/requestBody.ts +61 -0
  57. package/src/nodes/response.ts +58 -13
  58. package/src/nodes/schema.ts +93 -17
  59. package/src/printer.ts +48 -42
  60. package/src/registry.ts +75 -0
  61. package/src/signature.ts +207 -0
  62. package/src/transformers.ts +50 -18
  63. package/src/types.ts +7 -68
  64. package/src/utils/codegen.ts +104 -0
  65. package/src/utils/extractStringsFromNodes.ts +34 -0
  66. package/src/utils/fileMerge.ts +184 -0
  67. package/src/utils/index.ts +11 -0
  68. package/src/utils/operationParams.ts +353 -0
  69. package/src/utils/refs.ts +112 -0
  70. package/src/utils/schemaGraph.ts +169 -0
  71. package/src/utils/schemaTraversal.ts +86 -0
  72. package/src/utils/strings.ts +139 -0
  73. package/src/visitor.ts +227 -289
  74. package/dist/chunk--u3MIqq1.js +0 -8
  75. package/src/nodes/root.ts +0 -64
  76. package/src/refs.ts +0 -67
  77. package/src/resolvers.ts +0 -45
  78. package/src/utils.ts +0 -915
@@ -0,0 +1,683 @@
1
+ import "./chunk-CNktS9qV.js";
2
+ //#region src/node.ts
3
+ /**
4
+ * Builds a type guard that matches nodes of the given `kind`.
5
+ */
6
+ function isKind(kind) {
7
+ return (node) => node.kind === kind;
8
+ }
9
+ /**
10
+ * Updates a schema's `optional` and `nullish` flags from a parent's `required`
11
+ * value and the schema's own `nullable`. Mirrors how OpenAPI parameters and
12
+ * object properties combine "required" and "nullable" into a single AST.
13
+ *
14
+ * - Non-required + non-nullable → `optional: true`.
15
+ * - Non-required + nullable → `nullish: true`.
16
+ * - Required → both flags cleared.
17
+ */
18
+ function syncOptionality(schema, required) {
19
+ const nullable = schema.nullable ?? false;
20
+ return {
21
+ ...schema,
22
+ optional: !required && !nullable ? true : void 0,
23
+ nullish: !required && nullable ? true : void 0
24
+ };
25
+ }
26
+ /**
27
+ * Defines a node once and derives its `create` builder, `is` guard, and traversal
28
+ * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the
29
+ * `kind`, so node construction lives in one place without scattered `as` casts.
30
+ *
31
+ * Set `rebuild: true` when the `build` hook derives fields from children. After a
32
+ * transform rewrites those children, the registry reruns `create` so the derived
33
+ * fields stay correct.
34
+ *
35
+ * @example Simple node
36
+ * ```ts
37
+ * const importDef = defineNode<ImportNode>({ kind: 'Import' })
38
+ * const createImport = importDef.create
39
+ * ```
40
+ *
41
+ * @example Node with a build hook that is rerun on transform
42
+ * ```ts
43
+ * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({
44
+ * kind: 'Property',
45
+ * build: (props) => ({ ...props, required: props.required ?? false }),
46
+ * children: ['schema'],
47
+ * visitorKey: 'property',
48
+ * rebuild: true,
49
+ * })
50
+ * ```
51
+ */
52
+ function defineNode(config) {
53
+ const { kind, defaults, build, children, visitorKey, rebuild } = config;
54
+ function create(input) {
55
+ const base = build ? build(input) : input;
56
+ return {
57
+ ...defaults,
58
+ ...base,
59
+ kind
60
+ };
61
+ }
62
+ return {
63
+ kind,
64
+ create,
65
+ is: isKind(kind),
66
+ children,
67
+ visitorKey,
68
+ rebuild
69
+ };
70
+ }
71
+ //#endregion
72
+ //#region src/nodes/schema.ts
73
+ /**
74
+ * Maps schema `type` to its underlying `primitive`.
75
+ * Primitive types map to themselves. Special string formats map to `'string'`.
76
+ * Complex types (`ref`, `enum`, `union`, `intersection`, `tuple`, `blob`) are left unset.
77
+ */
78
+ const TYPE_TO_PRIMITIVE = {
79
+ string: "string",
80
+ number: "number",
81
+ integer: "integer",
82
+ bigint: "bigint",
83
+ boolean: "boolean",
84
+ null: "null",
85
+ any: "any",
86
+ unknown: "unknown",
87
+ void: "void",
88
+ never: "never",
89
+ object: "object",
90
+ array: "array",
91
+ date: "date",
92
+ uuid: "string",
93
+ email: "string",
94
+ url: "string",
95
+ datetime: "string",
96
+ time: "string"
97
+ };
98
+ /**
99
+ * Definition for the {@link SchemaNode}. Object schemas default `properties` to an
100
+ * empty array, and `primitive` is inferred from `type` when not explicitly provided.
101
+ */
102
+ const schemaDef = defineNode({
103
+ kind: "Schema",
104
+ build: (props) => {
105
+ if (props.type === "object") return {
106
+ properties: [],
107
+ primitive: "object",
108
+ ...props
109
+ };
110
+ return {
111
+ primitive: TYPE_TO_PRIMITIVE[props.type],
112
+ ...props
113
+ };
114
+ },
115
+ children: [
116
+ "properties",
117
+ "items",
118
+ "members",
119
+ "additionalProperties"
120
+ ],
121
+ visitorKey: "schema"
122
+ });
123
+ function createSchema(props) {
124
+ return schemaDef.create(props);
125
+ }
126
+ //#endregion
127
+ //#region ../../internals/utils/src/casing.ts
128
+ /**
129
+ * Shared implementation for camelCase and PascalCase conversion.
130
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
131
+ * and capitalizes each word according to `pascal`.
132
+ *
133
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
134
+ */
135
+ function toCamelOrPascal(text, pascal) {
136
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
137
+ if (word.length > 1 && word === word.toUpperCase()) return word;
138
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
139
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
140
+ }
141
+ /**
142
+ * Converts `text` to camelCase.
143
+ *
144
+ * @example Word boundaries
145
+ * `camelCase('hello-world') // 'helloWorld'`
146
+ *
147
+ * @example With a prefix
148
+ * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
149
+ */
150
+ function camelCase(text, { prefix = "", suffix = "" } = {}) {
151
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
152
+ }
153
+ /**
154
+ * Converts `text` to PascalCase.
155
+ *
156
+ * @example Word boundaries
157
+ * `pascalCase('hello-world') // 'HelloWorld'`
158
+ *
159
+ * @example With a suffix
160
+ * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
161
+ */
162
+ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
163
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
164
+ }
165
+ //#endregion
166
+ //#region src/utils/extractStringsFromNodes.ts
167
+ /**
168
+ * Extracts all string content from a `CodeNode` tree recursively.
169
+ *
170
+ * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
171
+ * and nested node content. Used to build the full source string for import filtering.
172
+ */
173
+ function extractStringsFromNodes(nodes) {
174
+ if (!nodes?.length) return "";
175
+ return nodes.map((node) => {
176
+ if (typeof node === "string") return node;
177
+ if (node.kind === "Text") return node.value;
178
+ if (node.kind === "Break") return "";
179
+ if (node.kind === "Jsx") return node.value;
180
+ const parts = [];
181
+ if ("params" in node && node.params) parts.push(node.params);
182
+ if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics);
183
+ if ("returnType" in node && node.returnType) parts.push(node.returnType);
184
+ if ("type" in node && typeof node.type === "string") parts.push(node.type);
185
+ const nested = extractStringsFromNodes(node.nodes);
186
+ if (nested) parts.push(nested);
187
+ return parts.join("\n");
188
+ }).filter(Boolean).join("\n");
189
+ }
190
+ //#endregion
191
+ //#region src/nodes/property.ts
192
+ /**
193
+ * Definition for the {@link PropertyNode}. `required` defaults to `false` and the
194
+ * schema's `optional`/`nullish` flags are kept in sync with it.
195
+ */
196
+ const propertyDef = defineNode({
197
+ kind: "Property",
198
+ build: (props) => {
199
+ const required = props.required ?? false;
200
+ return {
201
+ ...props,
202
+ required,
203
+ schema: syncOptionality(props.schema, required)
204
+ };
205
+ },
206
+ children: ["schema"],
207
+ visitorKey: "property",
208
+ rebuild: true
209
+ });
210
+ /**
211
+ * Creates a `PropertyNode`.
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * const property = createProperty({
216
+ * name: 'status',
217
+ * required: true,
218
+ * schema: createSchema({ type: 'string', nullable: true }),
219
+ * })
220
+ * // required=true, no optional/nullish
221
+ * ```
222
+ */
223
+ const createProperty = propertyDef.create;
224
+ //#endregion
225
+ //#region src/nodes/code.ts
226
+ /**
227
+ * Definition for the {@link ConstNode}.
228
+ */
229
+ const constDef = defineNode({ kind: "Const" });
230
+ /**
231
+ * Creates a `ConstNode` representing a TypeScript `const` declaration.
232
+ *
233
+ * @example Exported constant with type and `as const`
234
+ * ```ts
235
+ * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
236
+ * // export const pets: Pet[] = ... as const
237
+ * ```
238
+ */
239
+ const createConst = constDef.create;
240
+ /**
241
+ * Definition for the {@link TypeNode}.
242
+ */
243
+ const typeDef = defineNode({ kind: "Type" });
244
+ /**
245
+ * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
246
+ *
247
+ * @example
248
+ * ```ts
249
+ * createType({ name: 'Pet', export: true })
250
+ * // export type Pet = ...
251
+ * ```
252
+ */
253
+ const createType = typeDef.create;
254
+ /**
255
+ * Definition for the {@link FunctionNode}.
256
+ */
257
+ const functionDef = defineNode({ kind: "Function" });
258
+ /**
259
+ * Creates a `FunctionNode` representing a TypeScript `function` declaration.
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
264
+ * // export async function fetchPet(): Promise<Pet> { ... }
265
+ * ```
266
+ */
267
+ const createFunction = functionDef.create;
268
+ /**
269
+ * Definition for the {@link ArrowFunctionNode}.
270
+ */
271
+ const arrowFunctionDef = defineNode({ kind: "ArrowFunction" });
272
+ /**
273
+ * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
278
+ * // export const double = (n: number) => ...
279
+ * ```
280
+ */
281
+ const createArrowFunction = arrowFunctionDef.create;
282
+ /**
283
+ * Definition for the {@link TextNode}.
284
+ */
285
+ const textDef = defineNode({
286
+ kind: "Text",
287
+ build: (value) => ({ value })
288
+ });
289
+ /**
290
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
291
+ *
292
+ * @example
293
+ * ```ts
294
+ * createText('return fetch(id)')
295
+ * // { kind: 'Text', value: 'return fetch(id)' }
296
+ * ```
297
+ */
298
+ const createText = textDef.create;
299
+ /**
300
+ * Definition for the {@link BreakNode}.
301
+ */
302
+ const breakDef = defineNode({
303
+ kind: "Break",
304
+ build: () => ({})
305
+ });
306
+ /**
307
+ * Creates a {@link BreakNode} representing a line break in the source output.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * createBreak()
312
+ * // { kind: 'Break' }
313
+ * ```
314
+ */
315
+ function createBreak() {
316
+ return breakDef.create();
317
+ }
318
+ /**
319
+ * Definition for the {@link JsxNode}.
320
+ */
321
+ const jsxDef = defineNode({
322
+ kind: "Jsx",
323
+ build: (value) => ({ value })
324
+ });
325
+ /**
326
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
331
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
332
+ * ```
333
+ */
334
+ const createJsx = jsxDef.create;
335
+ //#endregion
336
+ //#region src/nodes/content.ts
337
+ /**
338
+ * Definition for the {@link ContentNode}.
339
+ */
340
+ const contentDef = defineNode({
341
+ kind: "Content",
342
+ children: ["schema"]
343
+ });
344
+ /**
345
+ * Creates a `ContentNode` for a single request-body or response content type.
346
+ */
347
+ const createContent = contentDef.create;
348
+ //#endregion
349
+ //#region src/nodes/file.ts
350
+ /**
351
+ * Definition for the {@link ImportNode}.
352
+ */
353
+ const importDef = defineNode({ kind: "Import" });
354
+ /**
355
+ * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
356
+ *
357
+ * @example Named import
358
+ * ```ts
359
+ * createImport({ name: ['useState'], path: 'react' })
360
+ * // import { useState } from 'react'
361
+ * ```
362
+ */
363
+ const createImport = importDef.create;
364
+ /**
365
+ * Definition for the {@link ExportNode}.
366
+ */
367
+ const exportDef = defineNode({ kind: "Export" });
368
+ /**
369
+ * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
370
+ *
371
+ * @example Named export
372
+ * ```ts
373
+ * createExport({ name: ['Pet'], path: './Pet' })
374
+ * // export { Pet } from './Pet'
375
+ * ```
376
+ */
377
+ const createExport = exportDef.create;
378
+ /**
379
+ * Definition for the {@link SourceNode}.
380
+ */
381
+ const sourceDef = defineNode({ kind: "Source" });
382
+ /**
383
+ * Creates a `SourceNode` representing a fragment of source code within a file.
384
+ *
385
+ * @example
386
+ * ```ts
387
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
388
+ * ```
389
+ */
390
+ const createSource = sourceDef.create;
391
+ /**
392
+ * Definition for the {@link FileNode}. The fully resolved builder lives in
393
+ * `createFile`, so this definition only supplies the guard.
394
+ */
395
+ const fileDef = defineNode({ kind: "File" });
396
+ //#endregion
397
+ //#region src/nodes/function.ts
398
+ /**
399
+ * Definition for the {@link TypeLiteralNode}.
400
+ */
401
+ const typeLiteralDef = defineNode({ kind: "TypeLiteral" });
402
+ /**
403
+ * Creates a {@link TypeLiteralNode} representing an inline anonymous object type.
404
+ *
405
+ * @example
406
+ * ```ts
407
+ * createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })
408
+ * // { petId: string }
409
+ * ```
410
+ */
411
+ const createTypeLiteral = typeLiteralDef.create;
412
+ /**
413
+ * Definition for the {@link IndexedAccessTypeNode}.
414
+ */
415
+ const indexedAccessTypeDef = defineNode({ kind: "IndexedAccessType" });
416
+ /**
417
+ * Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.
418
+ *
419
+ * @example
420
+ * ```ts
421
+ * createIndexedAccessType({ objectType: 'DeletePetPathParams', indexType: 'petId' })
422
+ * // DeletePetPathParams['petId']
423
+ * ```
424
+ */
425
+ const createIndexedAccessType = indexedAccessTypeDef.create;
426
+ /**
427
+ * Definition for the {@link ObjectBindingPatternNode}.
428
+ */
429
+ const objectBindingPatternDef = defineNode({ kind: "ObjectBindingPattern" });
430
+ /**
431
+ * Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.
432
+ *
433
+ * @example
434
+ * ```ts
435
+ * createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })
436
+ * // { id, name }
437
+ * ```
438
+ */
439
+ const createObjectBindingPattern = objectBindingPatternDef.create;
440
+ /**
441
+ * Definition for the {@link FunctionParameterNode}. `optional` defaults to `false`.
442
+ * Passing `properties` builds a destructured group: an {@link ObjectBindingPatternNode} name
443
+ * paired with a {@link TypeLiteralNode} type.
444
+ */
445
+ const functionParameterDef = defineNode({
446
+ kind: "FunctionParameter",
447
+ build: (input) => {
448
+ if ("properties" in input) return {
449
+ name: createObjectBindingPattern({ elements: input.properties.map((p) => ({ name: p.name })) }),
450
+ type: createTypeLiteral({ members: input.properties.map((p) => ({
451
+ name: p.name,
452
+ type: p.type,
453
+ optional: p.optional ?? false
454
+ })) }),
455
+ optional: input.optional ?? false,
456
+ ...input.default !== void 0 ? { default: input.default } : {}
457
+ };
458
+ return {
459
+ optional: false,
460
+ ...input
461
+ };
462
+ }
463
+ });
464
+ /**
465
+ * Creates a `FunctionParameterNode`. `optional` defaults to `false`.
466
+ *
467
+ * @example Optional param
468
+ * ```ts
469
+ * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
470
+ * // → params?: QueryParams
471
+ * ```
472
+ *
473
+ * @example Destructured group
474
+ * ```ts
475
+ * createFunctionParameter({ properties: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string', optional: true }], default: '{}' })
476
+ * // → { id, name }: { id: string; name?: string } = {}
477
+ * ```
478
+ */
479
+ const createFunctionParameter = functionParameterDef.create;
480
+ /**
481
+ * Definition for the {@link FunctionParametersNode}.
482
+ */
483
+ const functionParametersDef = defineNode({
484
+ kind: "FunctionParameters",
485
+ defaults: { params: [] }
486
+ });
487
+ /**
488
+ * Creates a `FunctionParametersNode` from an ordered list of parameters.
489
+ *
490
+ * @example
491
+ * ```ts
492
+ * const empty = createFunctionParameters()
493
+ * // { kind: 'FunctionParameters', params: [] }
494
+ * ```
495
+ */
496
+ function createFunctionParameters(props = {}) {
497
+ return functionParametersDef.create(props);
498
+ }
499
+ //#endregion
500
+ //#region src/nodes/input.ts
501
+ /**
502
+ * Definition for the {@link InputNode}.
503
+ */
504
+ const inputDef = defineNode({
505
+ kind: "Input",
506
+ defaults: {
507
+ schemas: [],
508
+ operations: [],
509
+ meta: {
510
+ circularNames: [],
511
+ enumNames: []
512
+ }
513
+ },
514
+ children: ["schemas", "operations"],
515
+ visitorKey: "input"
516
+ });
517
+ /**
518
+ * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and
519
+ * `operations` are `AsyncIterable` sources and whose `meta` is optional. Otherwise it builds the
520
+ * eager variant with array `schemas`/`operations` and the defaulted `meta`.
521
+ *
522
+ * @example Eager
523
+ * ```ts
524
+ * const input = createInput()
525
+ * // { kind: 'Input', schemas: [], operations: [] }
526
+ * ```
527
+ *
528
+ * @example Streaming
529
+ * ```ts
530
+ * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
531
+ * ```
532
+ */
533
+ function createInput(options = {}) {
534
+ const { stream, ...overrides } = options;
535
+ if (stream) return {
536
+ kind: "Input",
537
+ ...overrides
538
+ };
539
+ return inputDef.create(overrides);
540
+ }
541
+ //#endregion
542
+ //#region src/nodes/requestBody.ts
543
+ /**
544
+ * Definition for the {@link RequestBodyNode}, normalizing each content entry into a `ContentNode`.
545
+ */
546
+ const requestBodyDef = defineNode({
547
+ kind: "RequestBody",
548
+ build: (props) => ({
549
+ ...props,
550
+ content: props.content?.map(createContent)
551
+ }),
552
+ children: ["content"]
553
+ });
554
+ /**
555
+ * Creates a `RequestBodyNode`, normalizing each content entry into a `ContentNode`.
556
+ */
557
+ const createRequestBody = requestBodyDef.create;
558
+ //#endregion
559
+ //#region src/nodes/operation.ts
560
+ /**
561
+ * Definition for the {@link OperationNode}. HTTP operations (those carrying both
562
+ * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
563
+ * normalized into a `RequestBodyNode`.
564
+ */
565
+ const operationDef = defineNode({
566
+ kind: "Operation",
567
+ build: (props) => {
568
+ const { requestBody, ...rest } = props;
569
+ const isHttp = rest.method !== void 0 && rest.path !== void 0;
570
+ return {
571
+ tags: [],
572
+ parameters: [],
573
+ responses: [],
574
+ ...rest,
575
+ ...isHttp ? { protocol: "http" } : {},
576
+ requestBody: requestBody ? createRequestBody(requestBody) : void 0
577
+ };
578
+ },
579
+ children: [
580
+ "parameters",
581
+ "requestBody",
582
+ "responses"
583
+ ],
584
+ visitorKey: "operation"
585
+ });
586
+ function createOperation(props) {
587
+ return operationDef.create(props);
588
+ }
589
+ //#endregion
590
+ //#region src/nodes/output.ts
591
+ /**
592
+ * Definition for the {@link OutputNode}.
593
+ */
594
+ const outputDef = defineNode({
595
+ kind: "Output",
596
+ defaults: { files: [] },
597
+ visitorKey: "output"
598
+ });
599
+ /**
600
+ * Creates an `OutputNode` with a stable default for `files`.
601
+ *
602
+ * @example
603
+ * ```ts
604
+ * const output = createOutput()
605
+ * // { kind: 'Output', files: [] }
606
+ * ```
607
+ */
608
+ function createOutput(overrides = {}) {
609
+ return outputDef.create(overrides);
610
+ }
611
+ //#endregion
612
+ //#region src/nodes/parameter.ts
613
+ /**
614
+ * Definition for the {@link ParameterNode}. `required` defaults to `false` and the
615
+ * schema's `optional`/`nullish` flags are kept in sync with it.
616
+ */
617
+ const parameterDef = defineNode({
618
+ kind: "Parameter",
619
+ build: (props) => {
620
+ const required = props.required ?? false;
621
+ return {
622
+ ...props,
623
+ required,
624
+ schema: syncOptionality(props.schema, required)
625
+ };
626
+ },
627
+ children: ["schema"],
628
+ visitorKey: "parameter",
629
+ rebuild: true
630
+ });
631
+ /**
632
+ * Creates a `ParameterNode`.
633
+ *
634
+ * @example
635
+ * ```ts
636
+ * const param = createParameter({
637
+ * name: 'petId',
638
+ * in: 'path',
639
+ * required: true,
640
+ * schema: createSchema({ type: 'string' }),
641
+ * })
642
+ * ```
643
+ */
644
+ const createParameter = parameterDef.create;
645
+ //#endregion
646
+ //#region src/nodes/response.ts
647
+ /**
648
+ * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
649
+ * `mediaType`/`keysToOmit`) is normalized into one `content` entry.
650
+ */
651
+ const responseDef = defineNode({
652
+ kind: "Response",
653
+ build: (props) => {
654
+ const { schema, mediaType, keysToOmit, content, ...rest } = props;
655
+ const entries = content ?? (schema ? [{
656
+ contentType: mediaType ?? "application/json",
657
+ schema,
658
+ keysToOmit: keysToOmit ?? null
659
+ }] : void 0);
660
+ return {
661
+ ...rest,
662
+ content: entries?.map(createContent)
663
+ };
664
+ },
665
+ children: ["content"],
666
+ visitorKey: "response"
667
+ });
668
+ /**
669
+ * Creates a `ResponseNode`.
670
+ *
671
+ * @example
672
+ * ```ts
673
+ * const response = createResponse({
674
+ * statusCode: '200',
675
+ * content: [{ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) }],
676
+ * })
677
+ * ```
678
+ */
679
+ const createResponse = responseDef.create;
680
+ //#endregion
681
+ export { defineNode as $, contentDef as A, createText as B, createExport as C, fileDef as D, exportDef as E, createArrowFunction as F, typeDef as G, functionDef as H, createBreak as I, extractStringsFromNodes as J, createProperty as K, createConst as L, arrowFunctionDef as M, breakDef as N, importDef as O, constDef as P, schemaDef as Q, createFunction as R, typeLiteralDef as S, createSource as T, jsxDef as U, createType as V, textDef as W, pascalCase as X, camelCase as Y, createSchema as Z, createTypeLiteral as _, createOutput as a, indexedAccessTypeDef as b, operationDef as c, createInput as d, syncOptionality as et, inputDef as f, createObjectBindingPattern as g, createIndexedAccessType as h, parameterDef as i, createContent as j, sourceDef as k, createRequestBody as l, createFunctionParameters as m, responseDef as n, outputDef as o, createFunctionParameter as p, propertyDef as q, createParameter as r, createOperation as s, createResponse as t, requestBodyDef as u, functionParameterDef as v, createImport as w, objectBindingPatternDef as x, functionParametersDef as y, createJsx as z };
682
+
683
+ //# sourceMappingURL=response-DKxTr522.js.map