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

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 (102) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +51 -27
  3. package/dist/chunk-CNktS9qV.js +17 -0
  4. package/dist/defineMacro-BLIR6k-j.d.ts +475 -0
  5. package/dist/defineMacro-BTXvS8nI.js +106 -0
  6. package/dist/defineMacro-BTXvS8nI.js.map +1 -0
  7. package/dist/defineMacro-Bv9R_9a2.cjs +123 -0
  8. package/dist/defineMacro-Bv9R_9a2.cjs.map +1 -0
  9. package/dist/extractStringsFromNodes-Cja-xxx5.js +29 -0
  10. package/dist/extractStringsFromNodes-Cja-xxx5.js.map +1 -0
  11. package/dist/extractStringsFromNodes-DKgDjFO0.cjs +34 -0
  12. package/dist/extractStringsFromNodes-DKgDjFO0.cjs.map +1 -0
  13. package/dist/extractStringsFromNodes-p4mX1TQD.d.ts +14 -0
  14. package/dist/factory-CZNOGI-N.js +283 -0
  15. package/dist/factory-CZNOGI-N.js.map +1 -0
  16. package/dist/factory-DG1CVkEb.cjs +300 -0
  17. package/dist/factory-DG1CVkEb.cjs.map +1 -0
  18. package/dist/factory.cjs +29 -0
  19. package/dist/factory.d.ts +62 -0
  20. package/dist/factory.js +3 -0
  21. package/dist/index-BzjwdK2M.d.ts +2433 -0
  22. package/dist/index.cjs +444 -2180
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +94 -3408
  25. package/dist/index.js +395 -2101
  26. package/dist/index.js.map +1 -1
  27. package/dist/macros.cjs +117 -0
  28. package/dist/macros.cjs.map +1 -0
  29. package/dist/macros.d.ts +59 -0
  30. package/dist/macros.js +115 -0
  31. package/dist/macros.js.map +1 -0
  32. package/dist/operationParams-BZ07xDm0.d.ts +204 -0
  33. package/dist/response-KUdWiDWw.js +658 -0
  34. package/dist/response-KUdWiDWw.js.map +1 -0
  35. package/dist/response-hnSw2NKE.cjs +1027 -0
  36. package/dist/response-hnSw2NKE.cjs.map +1 -0
  37. package/dist/types-DyDzizSf.d.ts +364 -0
  38. package/dist/types.cjs +0 -0
  39. package/dist/types.d.ts +6 -0
  40. package/dist/types.js +1 -0
  41. package/dist/utils-BLJwyza-.cjs +912 -0
  42. package/dist/utils-BLJwyza-.cjs.map +1 -0
  43. package/dist/utils-CF_-Pn_c.js +770 -0
  44. package/dist/utils-CF_-Pn_c.js.map +1 -0
  45. package/dist/utils.cjs +36 -0
  46. package/dist/utils.d.ts +358 -0
  47. package/dist/utils.js +4 -0
  48. package/dist/visitor-DJ6ZEJvq.js +548 -0
  49. package/dist/visitor-DJ6ZEJvq.js.map +1 -0
  50. package/dist/visitor-DpKZ9Tk0.cjs +654 -0
  51. package/dist/visitor-DpKZ9Tk0.cjs.map +1 -0
  52. package/package.json +21 -6
  53. package/src/constants.ts +19 -64
  54. package/src/dedupe.ts +239 -0
  55. package/src/defineMacro.ts +132 -0
  56. package/src/dialect.ts +53 -0
  57. package/src/factory.ts +67 -678
  58. package/src/guards.ts +10 -92
  59. package/src/index.ts +13 -44
  60. package/src/infer.ts +16 -14
  61. package/src/macros/index.ts +3 -0
  62. package/src/macros/macroDiscriminatorEnum.ts +44 -0
  63. package/src/macros/macroEnumName.ts +25 -0
  64. package/src/macros/macroSimplifyUnion.ts +50 -0
  65. package/src/mocks.ts +7 -127
  66. package/src/node.ts +128 -0
  67. package/src/nodes/base.ts +5 -12
  68. package/src/nodes/code.ts +165 -74
  69. package/src/nodes/content.ts +56 -0
  70. package/src/nodes/file.ts +97 -36
  71. package/src/nodes/function.ts +216 -156
  72. package/src/nodes/http.ts +1 -35
  73. package/src/nodes/index.ts +23 -15
  74. package/src/nodes/input.ts +140 -0
  75. package/src/nodes/operation.ts +122 -68
  76. package/src/nodes/output.ts +23 -0
  77. package/src/nodes/parameter.ts +33 -3
  78. package/src/nodes/property.ts +36 -3
  79. package/src/nodes/requestBody.ts +61 -0
  80. package/src/nodes/response.ts +58 -13
  81. package/src/nodes/schema.ts +93 -17
  82. package/src/printer.ts +48 -42
  83. package/src/registry.ts +75 -0
  84. package/src/signature.ts +207 -0
  85. package/src/types.ts +8 -68
  86. package/src/utils/codegen.ts +104 -0
  87. package/src/utils/extractStringsFromNodes.ts +34 -0
  88. package/src/utils/fileMerge.ts +184 -0
  89. package/src/utils/index.ts +11 -0
  90. package/src/utils/operationParams.ts +353 -0
  91. package/src/utils/refs.ts +138 -0
  92. package/src/utils/schemaGraph.ts +169 -0
  93. package/src/utils/schemaMerge.ts +34 -0
  94. package/src/utils/schemaTraversal.ts +86 -0
  95. package/src/utils/strings.ts +139 -0
  96. package/src/visitor.ts +227 -289
  97. package/dist/chunk--u3MIqq1.js +0 -8
  98. package/src/nodes/root.ts +0 -64
  99. package/src/refs.ts +0 -67
  100. package/src/resolvers.ts +0 -45
  101. package/src/transformers.ts +0 -159
  102. package/src/utils.ts +0 -915
@@ -0,0 +1,658 @@
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/nodes/code.ts
167
+ /**
168
+ * Definition for the {@link ConstNode}.
169
+ */
170
+ const constDef = defineNode({ kind: "Const" });
171
+ /**
172
+ * Creates a `ConstNode` representing a TypeScript `const` declaration.
173
+ *
174
+ * @example Exported constant with type and `as const`
175
+ * ```ts
176
+ * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
177
+ * // export const pets: Pet[] = ... as const
178
+ * ```
179
+ */
180
+ const createConst = constDef.create;
181
+ /**
182
+ * Definition for the {@link TypeNode}.
183
+ */
184
+ const typeDef = defineNode({ kind: "Type" });
185
+ /**
186
+ * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * createType({ name: 'Pet', export: true })
191
+ * // export type Pet = ...
192
+ * ```
193
+ */
194
+ const createType = typeDef.create;
195
+ /**
196
+ * Definition for the {@link FunctionNode}.
197
+ */
198
+ const functionDef = defineNode({ kind: "Function" });
199
+ /**
200
+ * Creates a `FunctionNode` representing a TypeScript `function` declaration.
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
205
+ * // export async function fetchPet(): Promise<Pet> { ... }
206
+ * ```
207
+ */
208
+ const createFunction = functionDef.create;
209
+ /**
210
+ * Definition for the {@link ArrowFunctionNode}.
211
+ */
212
+ const arrowFunctionDef = defineNode({ kind: "ArrowFunction" });
213
+ /**
214
+ * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
219
+ * // export const double = (n: number) => ...
220
+ * ```
221
+ */
222
+ const createArrowFunction = arrowFunctionDef.create;
223
+ /**
224
+ * Definition for the {@link TextNode}.
225
+ */
226
+ const textDef = defineNode({
227
+ kind: "Text",
228
+ build: (value) => ({ value })
229
+ });
230
+ /**
231
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * createText('return fetch(id)')
236
+ * // { kind: 'Text', value: 'return fetch(id)' }
237
+ * ```
238
+ */
239
+ const createText = textDef.create;
240
+ /**
241
+ * Definition for the {@link BreakNode}.
242
+ */
243
+ const breakDef = defineNode({
244
+ kind: "Break",
245
+ build: () => ({})
246
+ });
247
+ /**
248
+ * Creates a {@link BreakNode} representing a line break in the source output.
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * createBreak()
253
+ * // { kind: 'Break' }
254
+ * ```
255
+ */
256
+ function createBreak() {
257
+ return breakDef.create();
258
+ }
259
+ /**
260
+ * Definition for the {@link JsxNode}.
261
+ */
262
+ const jsxDef = defineNode({
263
+ kind: "Jsx",
264
+ build: (value) => ({ value })
265
+ });
266
+ /**
267
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
272
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
273
+ * ```
274
+ */
275
+ const createJsx = jsxDef.create;
276
+ //#endregion
277
+ //#region src/nodes/content.ts
278
+ /**
279
+ * Definition for the {@link ContentNode}.
280
+ */
281
+ const contentDef = defineNode({
282
+ kind: "Content",
283
+ children: ["schema"]
284
+ });
285
+ /**
286
+ * Creates a `ContentNode` for a single request-body or response content type.
287
+ */
288
+ const createContent = contentDef.create;
289
+ //#endregion
290
+ //#region src/nodes/file.ts
291
+ /**
292
+ * Definition for the {@link ImportNode}.
293
+ */
294
+ const importDef = defineNode({ kind: "Import" });
295
+ /**
296
+ * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
297
+ *
298
+ * @example Named import
299
+ * ```ts
300
+ * createImport({ name: ['useState'], path: 'react' })
301
+ * // import { useState } from 'react'
302
+ * ```
303
+ */
304
+ const createImport = importDef.create;
305
+ /**
306
+ * Definition for the {@link ExportNode}.
307
+ */
308
+ const exportDef = defineNode({ kind: "Export" });
309
+ /**
310
+ * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
311
+ *
312
+ * @example Named export
313
+ * ```ts
314
+ * createExport({ name: ['Pet'], path: './Pet' })
315
+ * // export { Pet } from './Pet'
316
+ * ```
317
+ */
318
+ const createExport = exportDef.create;
319
+ /**
320
+ * Definition for the {@link SourceNode}.
321
+ */
322
+ const sourceDef = defineNode({ kind: "Source" });
323
+ /**
324
+ * Creates a `SourceNode` representing a fragment of source code within a file.
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
329
+ * ```
330
+ */
331
+ const createSource = sourceDef.create;
332
+ /**
333
+ * Definition for the {@link FileNode}. The fully resolved builder lives in
334
+ * `createFile`, so this definition only supplies the guard.
335
+ */
336
+ const fileDef = defineNode({ kind: "File" });
337
+ //#endregion
338
+ //#region src/nodes/function.ts
339
+ /**
340
+ * Definition for the {@link TypeLiteralNode}.
341
+ */
342
+ const typeLiteralDef = defineNode({ kind: "TypeLiteral" });
343
+ /**
344
+ * Creates a {@link TypeLiteralNode} representing an inline anonymous object type.
345
+ *
346
+ * @example
347
+ * ```ts
348
+ * createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })
349
+ * // { petId: string }
350
+ * ```
351
+ */
352
+ const createTypeLiteral = typeLiteralDef.create;
353
+ /**
354
+ * Definition for the {@link IndexedAccessTypeNode}.
355
+ */
356
+ const indexedAccessTypeDef = defineNode({ kind: "IndexedAccessType" });
357
+ /**
358
+ * Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * createIndexedAccessType({ objectType: 'DeletePetPathParams', indexType: 'petId' })
363
+ * // DeletePetPathParams['petId']
364
+ * ```
365
+ */
366
+ const createIndexedAccessType = indexedAccessTypeDef.create;
367
+ /**
368
+ * Definition for the {@link ObjectBindingPatternNode}.
369
+ */
370
+ const objectBindingPatternDef = defineNode({ kind: "ObjectBindingPattern" });
371
+ /**
372
+ * Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.
373
+ *
374
+ * @example
375
+ * ```ts
376
+ * createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })
377
+ * // { id, name }
378
+ * ```
379
+ */
380
+ const createObjectBindingPattern = objectBindingPatternDef.create;
381
+ /**
382
+ * Definition for the {@link FunctionParameterNode}. `optional` defaults to `false`.
383
+ * Passing `properties` builds a destructured group: an {@link ObjectBindingPatternNode} name
384
+ * paired with a {@link TypeLiteralNode} type.
385
+ */
386
+ const functionParameterDef = defineNode({
387
+ kind: "FunctionParameter",
388
+ build: (input) => {
389
+ if ("properties" in input) return {
390
+ name: createObjectBindingPattern({ elements: input.properties.map((p) => ({ name: p.name })) }),
391
+ type: createTypeLiteral({ members: input.properties.map((p) => ({
392
+ name: p.name,
393
+ type: p.type,
394
+ optional: p.optional ?? false
395
+ })) }),
396
+ optional: input.optional ?? false,
397
+ ...input.default !== void 0 ? { default: input.default } : {}
398
+ };
399
+ return {
400
+ optional: false,
401
+ ...input
402
+ };
403
+ }
404
+ });
405
+ /**
406
+ * Creates a `FunctionParameterNode`. `optional` defaults to `false`.
407
+ *
408
+ * @example Optional param
409
+ * ```ts
410
+ * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
411
+ * // → params?: QueryParams
412
+ * ```
413
+ *
414
+ * @example Destructured group
415
+ * ```ts
416
+ * createFunctionParameter({ properties: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string', optional: true }], default: '{}' })
417
+ * // → { id, name }: { id: string; name?: string } = {}
418
+ * ```
419
+ */
420
+ const createFunctionParameter = functionParameterDef.create;
421
+ /**
422
+ * Definition for the {@link FunctionParametersNode}.
423
+ */
424
+ const functionParametersDef = defineNode({
425
+ kind: "FunctionParameters",
426
+ defaults: { params: [] }
427
+ });
428
+ /**
429
+ * Creates a `FunctionParametersNode` from an ordered list of parameters.
430
+ *
431
+ * @example
432
+ * ```ts
433
+ * const empty = createFunctionParameters()
434
+ * // { kind: 'FunctionParameters', params: [] }
435
+ * ```
436
+ */
437
+ function createFunctionParameters(props = {}) {
438
+ return functionParametersDef.create(props);
439
+ }
440
+ //#endregion
441
+ //#region src/nodes/input.ts
442
+ /**
443
+ * Definition for the {@link InputNode}.
444
+ */
445
+ const inputDef = defineNode({
446
+ kind: "Input",
447
+ defaults: {
448
+ schemas: [],
449
+ operations: [],
450
+ meta: {
451
+ circularNames: [],
452
+ enumNames: []
453
+ }
454
+ },
455
+ children: ["schemas", "operations"],
456
+ visitorKey: "input"
457
+ });
458
+ /**
459
+ * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and
460
+ * `operations` are `AsyncIterable` sources and whose `meta` is optional. Otherwise it builds the
461
+ * eager variant with array `schemas`/`operations` and the defaulted `meta`.
462
+ *
463
+ * @example Eager
464
+ * ```ts
465
+ * const input = createInput()
466
+ * // { kind: 'Input', schemas: [], operations: [] }
467
+ * ```
468
+ *
469
+ * @example Streaming
470
+ * ```ts
471
+ * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
472
+ * ```
473
+ */
474
+ function createInput(options = {}) {
475
+ const { stream, ...overrides } = options;
476
+ if (stream) return {
477
+ kind: "Input",
478
+ ...overrides
479
+ };
480
+ return inputDef.create(overrides);
481
+ }
482
+ //#endregion
483
+ //#region src/nodes/requestBody.ts
484
+ /**
485
+ * Definition for the {@link RequestBodyNode}, normalizing each content entry into a `ContentNode`.
486
+ */
487
+ const requestBodyDef = defineNode({
488
+ kind: "RequestBody",
489
+ build: (props) => ({
490
+ ...props,
491
+ content: props.content?.map(createContent)
492
+ }),
493
+ children: ["content"]
494
+ });
495
+ /**
496
+ * Creates a `RequestBodyNode`, normalizing each content entry into a `ContentNode`.
497
+ */
498
+ const createRequestBody = requestBodyDef.create;
499
+ //#endregion
500
+ //#region src/nodes/operation.ts
501
+ /**
502
+ * Definition for the {@link OperationNode}. HTTP operations (those carrying both
503
+ * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
504
+ * normalized into a `RequestBodyNode`.
505
+ */
506
+ const operationDef = defineNode({
507
+ kind: "Operation",
508
+ build: (props) => {
509
+ const { requestBody, ...rest } = props;
510
+ const isHttp = rest.method !== void 0 && rest.path !== void 0;
511
+ return {
512
+ tags: [],
513
+ parameters: [],
514
+ responses: [],
515
+ ...rest,
516
+ ...isHttp ? { protocol: "http" } : {},
517
+ requestBody: requestBody ? createRequestBody(requestBody) : void 0
518
+ };
519
+ },
520
+ children: [
521
+ "parameters",
522
+ "requestBody",
523
+ "responses"
524
+ ],
525
+ visitorKey: "operation"
526
+ });
527
+ function createOperation(props) {
528
+ return operationDef.create(props);
529
+ }
530
+ //#endregion
531
+ //#region src/nodes/output.ts
532
+ /**
533
+ * Definition for the {@link OutputNode}.
534
+ */
535
+ const outputDef = defineNode({
536
+ kind: "Output",
537
+ defaults: { files: [] },
538
+ visitorKey: "output"
539
+ });
540
+ /**
541
+ * Creates an `OutputNode` with a stable default for `files`.
542
+ *
543
+ * @example
544
+ * ```ts
545
+ * const output = createOutput()
546
+ * // { kind: 'Output', files: [] }
547
+ * ```
548
+ */
549
+ function createOutput(overrides = {}) {
550
+ return outputDef.create(overrides);
551
+ }
552
+ //#endregion
553
+ //#region src/nodes/parameter.ts
554
+ /**
555
+ * Definition for the {@link ParameterNode}. `required` defaults to `false` and the
556
+ * schema's `optional`/`nullish` flags are kept in sync with it.
557
+ */
558
+ const parameterDef = defineNode({
559
+ kind: "Parameter",
560
+ build: (props) => {
561
+ const required = props.required ?? false;
562
+ return {
563
+ ...props,
564
+ required,
565
+ schema: syncOptionality(props.schema, required)
566
+ };
567
+ },
568
+ children: ["schema"],
569
+ visitorKey: "parameter",
570
+ rebuild: true
571
+ });
572
+ /**
573
+ * Creates a `ParameterNode`.
574
+ *
575
+ * @example
576
+ * ```ts
577
+ * const param = createParameter({
578
+ * name: 'petId',
579
+ * in: 'path',
580
+ * required: true,
581
+ * schema: createSchema({ type: 'string' }),
582
+ * })
583
+ * ```
584
+ */
585
+ const createParameter = parameterDef.create;
586
+ //#endregion
587
+ //#region src/nodes/property.ts
588
+ /**
589
+ * Definition for the {@link PropertyNode}. `required` defaults to `false` and the
590
+ * schema's `optional`/`nullish` flags are kept in sync with it.
591
+ */
592
+ const propertyDef = defineNode({
593
+ kind: "Property",
594
+ build: (props) => {
595
+ const required = props.required ?? false;
596
+ return {
597
+ ...props,
598
+ required,
599
+ schema: syncOptionality(props.schema, required)
600
+ };
601
+ },
602
+ children: ["schema"],
603
+ visitorKey: "property",
604
+ rebuild: true
605
+ });
606
+ /**
607
+ * Creates a `PropertyNode`.
608
+ *
609
+ * @example
610
+ * ```ts
611
+ * const property = createProperty({
612
+ * name: 'status',
613
+ * required: true,
614
+ * schema: createSchema({ type: 'string', nullable: true }),
615
+ * })
616
+ * // required=true, no optional/nullish
617
+ * ```
618
+ */
619
+ const createProperty = propertyDef.create;
620
+ //#endregion
621
+ //#region src/nodes/response.ts
622
+ /**
623
+ * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
624
+ * `mediaType`/`keysToOmit`) is normalized into one `content` entry.
625
+ */
626
+ const responseDef = defineNode({
627
+ kind: "Response",
628
+ build: (props) => {
629
+ const { schema, mediaType, keysToOmit, content, ...rest } = props;
630
+ const entries = content ?? (schema ? [{
631
+ contentType: mediaType ?? "application/json",
632
+ schema,
633
+ keysToOmit: keysToOmit ?? null
634
+ }] : void 0);
635
+ return {
636
+ ...rest,
637
+ content: entries?.map(createContent)
638
+ };
639
+ },
640
+ children: ["content"],
641
+ visitorKey: "response"
642
+ });
643
+ /**
644
+ * Creates a `ResponseNode`.
645
+ *
646
+ * @example
647
+ * ```ts
648
+ * const response = createResponse({
649
+ * statusCode: '200',
650
+ * content: [{ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) }],
651
+ * })
652
+ * ```
653
+ */
654
+ const createResponse = responseDef.create;
655
+ //#endregion
656
+ export { syncOptionality as $, importDef as A, createFunction as B, objectBindingPatternDef as C, createSource as D, createImport as E, breakDef as F, jsxDef as G, createText as H, constDef as I, camelCase as J, textDef as K, createArrowFunction as L, contentDef as M, createContent as N, exportDef as O, arrowFunctionDef as P, defineNode as Q, createBreak as R, indexedAccessTypeDef as S, createExport as T, createType as U, createJsx as V, functionDef as W, createSchema as X, pascalCase as Y, schemaDef as Z, createIndexedAccessType as _, createParameter as a, functionParameterDef as b, outputDef as c, createRequestBody as d, requestBodyDef as f, createFunctionParameters as g, createFunctionParameter as h, propertyDef as i, sourceDef as j, fileDef as k, createOperation as l, inputDef as m, responseDef as n, parameterDef as o, createInput as p, typeDef as q, createProperty as r, createOutput as s, createResponse as t, operationDef as u, createObjectBindingPattern as v, typeLiteralDef as w, functionParametersDef as x, createTypeLiteral as y, createConst as z };
657
+
658
+ //# sourceMappingURL=response-KUdWiDWw.js.map