@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,1058 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", {
5
+ value,
6
+ configurable: true
7
+ });
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __exportAll = (all, no_symbols) => {
13
+ let target = {};
14
+ for (var name in all) __defProp(target, name, {
15
+ get: all[name],
16
+ enumerable: true
17
+ });
18
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
19
+ return target;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
23
+ key = keys[i];
24
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
25
+ get: ((k) => from[k]).bind(null, key),
26
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
+ });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
32
+ value: mod,
33
+ enumerable: true
34
+ }) : target, mod));
35
+ //#endregion
36
+ //#region src/node.ts
37
+ /**
38
+ * Builds a type guard that matches nodes of the given `kind`.
39
+ */
40
+ function isKind(kind) {
41
+ return (node) => node.kind === kind;
42
+ }
43
+ /**
44
+ * Updates a schema's `optional` and `nullish` flags from a parent's `required`
45
+ * value and the schema's own `nullable`. Mirrors how OpenAPI parameters and
46
+ * object properties combine "required" and "nullable" into a single AST.
47
+ *
48
+ * - Non-required + non-nullable → `optional: true`.
49
+ * - Non-required + nullable → `nullish: true`.
50
+ * - Required → both flags cleared.
51
+ */
52
+ function syncOptionality(schema, required) {
53
+ const nullable = schema.nullable ?? false;
54
+ return {
55
+ ...schema,
56
+ optional: !required && !nullable ? true : void 0,
57
+ nullish: !required && nullable ? true : void 0
58
+ };
59
+ }
60
+ /**
61
+ * Defines a node once and derives its `create` builder, `is` guard, and traversal
62
+ * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the
63
+ * `kind`, so node construction lives in one place without scattered `as` casts.
64
+ *
65
+ * Set `rebuild: true` when the `build` hook derives fields from children. After a
66
+ * transform rewrites those children, the registry reruns `create` so the derived
67
+ * fields stay correct.
68
+ *
69
+ * @example Simple node
70
+ * ```ts
71
+ * const importDef = defineNode<ImportNode>({ kind: 'Import' })
72
+ * const createImport = importDef.create
73
+ * ```
74
+ *
75
+ * @example Node with a build hook that is rerun on transform
76
+ * ```ts
77
+ * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({
78
+ * kind: 'Property',
79
+ * build: (props) => ({ ...props, required: props.required ?? false }),
80
+ * children: ['schema'],
81
+ * visitorKey: 'property',
82
+ * rebuild: true,
83
+ * })
84
+ * ```
85
+ */
86
+ function defineNode(config) {
87
+ const { kind, defaults, build, children, visitorKey, rebuild } = config;
88
+ function create(input) {
89
+ const base = build ? build(input) : input;
90
+ return {
91
+ ...defaults,
92
+ ...base,
93
+ kind
94
+ };
95
+ }
96
+ return {
97
+ kind,
98
+ create,
99
+ is: isKind(kind),
100
+ children,
101
+ visitorKey,
102
+ rebuild
103
+ };
104
+ }
105
+ //#endregion
106
+ //#region src/nodes/schema.ts
107
+ /**
108
+ * Maps schema `type` to its underlying `primitive`.
109
+ * Primitive types map to themselves. Special string formats map to `'string'`.
110
+ * Complex types (`ref`, `enum`, `union`, `intersection`, `tuple`, `blob`) are left unset.
111
+ */
112
+ const TYPE_TO_PRIMITIVE = {
113
+ string: "string",
114
+ number: "number",
115
+ integer: "integer",
116
+ bigint: "bigint",
117
+ boolean: "boolean",
118
+ null: "null",
119
+ any: "any",
120
+ unknown: "unknown",
121
+ void: "void",
122
+ never: "never",
123
+ object: "object",
124
+ array: "array",
125
+ date: "date",
126
+ uuid: "string",
127
+ email: "string",
128
+ url: "string",
129
+ datetime: "string",
130
+ time: "string"
131
+ };
132
+ /**
133
+ * Definition for the {@link SchemaNode}. Object schemas default `properties` to an
134
+ * empty array, and `primitive` is inferred from `type` when not explicitly provided.
135
+ */
136
+ const schemaDef = defineNode({
137
+ kind: "Schema",
138
+ build: (props) => {
139
+ if (props.type === "object") return {
140
+ properties: [],
141
+ primitive: "object",
142
+ ...props
143
+ };
144
+ return {
145
+ primitive: TYPE_TO_PRIMITIVE[props.type],
146
+ ...props
147
+ };
148
+ },
149
+ children: [
150
+ "properties",
151
+ "items",
152
+ "members",
153
+ "additionalProperties"
154
+ ],
155
+ visitorKey: "schema"
156
+ });
157
+ function createSchema(props) {
158
+ return schemaDef.create(props);
159
+ }
160
+ //#endregion
161
+ //#region ../../internals/utils/src/casing.ts
162
+ /**
163
+ * Shared implementation for camelCase and PascalCase conversion.
164
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
165
+ * and capitalizes each word according to `pascal`.
166
+ *
167
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
168
+ */
169
+ function toCamelOrPascal(text, pascal) {
170
+ 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) => {
171
+ if (word.length > 1 && word === word.toUpperCase()) return word;
172
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
173
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
174
+ }
175
+ /**
176
+ * Converts `text` to camelCase.
177
+ *
178
+ * @example Word boundaries
179
+ * `camelCase('hello-world') // 'helloWorld'`
180
+ *
181
+ * @example With a prefix
182
+ * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
183
+ */
184
+ function camelCase(text, { prefix = "", suffix = "" } = {}) {
185
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
186
+ }
187
+ /**
188
+ * Converts `text` to PascalCase.
189
+ *
190
+ * @example Word boundaries
191
+ * `pascalCase('hello-world') // 'HelloWorld'`
192
+ *
193
+ * @example With a suffix
194
+ * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
195
+ */
196
+ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
197
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
198
+ }
199
+ //#endregion
200
+ //#region src/utils/extractStringsFromNodes.ts
201
+ /**
202
+ * Extracts all string content from a `CodeNode` tree recursively.
203
+ *
204
+ * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
205
+ * and nested node content. Used to build the full source string for import filtering.
206
+ */
207
+ function extractStringsFromNodes(nodes) {
208
+ if (!nodes?.length) return "";
209
+ return nodes.map((node) => {
210
+ if (typeof node === "string") return node;
211
+ if (node.kind === "Text") return node.value;
212
+ if (node.kind === "Break") return "";
213
+ if (node.kind === "Jsx") return node.value;
214
+ const parts = [];
215
+ if ("params" in node && node.params) parts.push(node.params);
216
+ if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics);
217
+ if ("returnType" in node && node.returnType) parts.push(node.returnType);
218
+ if ("type" in node && typeof node.type === "string") parts.push(node.type);
219
+ const nested = extractStringsFromNodes(node.nodes);
220
+ if (nested) parts.push(nested);
221
+ return parts.join("\n");
222
+ }).filter(Boolean).join("\n");
223
+ }
224
+ //#endregion
225
+ //#region src/nodes/property.ts
226
+ /**
227
+ * Definition for the {@link PropertyNode}. `required` defaults to `false` and the
228
+ * schema's `optional`/`nullish` flags are kept in sync with it.
229
+ */
230
+ const propertyDef = defineNode({
231
+ kind: "Property",
232
+ build: (props) => {
233
+ const required = props.required ?? false;
234
+ return {
235
+ ...props,
236
+ required,
237
+ schema: syncOptionality(props.schema, required)
238
+ };
239
+ },
240
+ children: ["schema"],
241
+ visitorKey: "property",
242
+ rebuild: true
243
+ });
244
+ /**
245
+ * Creates a `PropertyNode`.
246
+ *
247
+ * @example
248
+ * ```ts
249
+ * const property = createProperty({
250
+ * name: 'status',
251
+ * required: true,
252
+ * schema: createSchema({ type: 'string', nullable: true }),
253
+ * })
254
+ * // required=true, no optional/nullish
255
+ * ```
256
+ */
257
+ const createProperty = propertyDef.create;
258
+ //#endregion
259
+ //#region src/nodes/code.ts
260
+ /**
261
+ * Definition for the {@link ConstNode}.
262
+ */
263
+ const constDef = defineNode({ kind: "Const" });
264
+ /**
265
+ * Creates a `ConstNode` representing a TypeScript `const` declaration.
266
+ *
267
+ * @example Exported constant with type and `as const`
268
+ * ```ts
269
+ * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
270
+ * // export const pets: Pet[] = ... as const
271
+ * ```
272
+ */
273
+ const createConst = constDef.create;
274
+ /**
275
+ * Definition for the {@link TypeNode}.
276
+ */
277
+ const typeDef = defineNode({ kind: "Type" });
278
+ /**
279
+ * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
280
+ *
281
+ * @example
282
+ * ```ts
283
+ * createType({ name: 'Pet', export: true })
284
+ * // export type Pet = ...
285
+ * ```
286
+ */
287
+ const createType = typeDef.create;
288
+ /**
289
+ * Definition for the {@link FunctionNode}.
290
+ */
291
+ const functionDef = defineNode({ kind: "Function" });
292
+ /**
293
+ * Creates a `FunctionNode` representing a TypeScript `function` declaration.
294
+ *
295
+ * @example
296
+ * ```ts
297
+ * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
298
+ * // export async function fetchPet(): Promise<Pet> { ... }
299
+ * ```
300
+ */
301
+ const createFunction = functionDef.create;
302
+ /**
303
+ * Definition for the {@link ArrowFunctionNode}.
304
+ */
305
+ const arrowFunctionDef = defineNode({ kind: "ArrowFunction" });
306
+ /**
307
+ * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
312
+ * // export const double = (n: number) => ...
313
+ * ```
314
+ */
315
+ const createArrowFunction = arrowFunctionDef.create;
316
+ /**
317
+ * Definition for the {@link TextNode}.
318
+ */
319
+ const textDef = defineNode({
320
+ kind: "Text",
321
+ build: (value) => ({ value })
322
+ });
323
+ /**
324
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * createText('return fetch(id)')
329
+ * // { kind: 'Text', value: 'return fetch(id)' }
330
+ * ```
331
+ */
332
+ const createText = textDef.create;
333
+ /**
334
+ * Definition for the {@link BreakNode}.
335
+ */
336
+ const breakDef = defineNode({
337
+ kind: "Break",
338
+ build: () => ({})
339
+ });
340
+ /**
341
+ * Creates a {@link BreakNode} representing a line break in the source output.
342
+ *
343
+ * @example
344
+ * ```ts
345
+ * createBreak()
346
+ * // { kind: 'Break' }
347
+ * ```
348
+ */
349
+ function createBreak() {
350
+ return breakDef.create();
351
+ }
352
+ /**
353
+ * Definition for the {@link JsxNode}.
354
+ */
355
+ const jsxDef = defineNode({
356
+ kind: "Jsx",
357
+ build: (value) => ({ value })
358
+ });
359
+ /**
360
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
365
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
366
+ * ```
367
+ */
368
+ const createJsx = jsxDef.create;
369
+ //#endregion
370
+ //#region src/nodes/content.ts
371
+ /**
372
+ * Definition for the {@link ContentNode}.
373
+ */
374
+ const contentDef = defineNode({
375
+ kind: "Content",
376
+ children: ["schema"]
377
+ });
378
+ /**
379
+ * Creates a `ContentNode` for a single request-body or response content type.
380
+ */
381
+ const createContent = contentDef.create;
382
+ //#endregion
383
+ //#region src/nodes/file.ts
384
+ /**
385
+ * Definition for the {@link ImportNode}.
386
+ */
387
+ const importDef = defineNode({ kind: "Import" });
388
+ /**
389
+ * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
390
+ *
391
+ * @example Named import
392
+ * ```ts
393
+ * createImport({ name: ['useState'], path: 'react' })
394
+ * // import { useState } from 'react'
395
+ * ```
396
+ */
397
+ const createImport = importDef.create;
398
+ /**
399
+ * Definition for the {@link ExportNode}.
400
+ */
401
+ const exportDef = defineNode({ kind: "Export" });
402
+ /**
403
+ * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
404
+ *
405
+ * @example Named export
406
+ * ```ts
407
+ * createExport({ name: ['Pet'], path: './Pet' })
408
+ * // export { Pet } from './Pet'
409
+ * ```
410
+ */
411
+ const createExport = exportDef.create;
412
+ /**
413
+ * Definition for the {@link SourceNode}.
414
+ */
415
+ const sourceDef = defineNode({ kind: "Source" });
416
+ /**
417
+ * Creates a `SourceNode` representing a fragment of source code within a file.
418
+ *
419
+ * @example
420
+ * ```ts
421
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
422
+ * ```
423
+ */
424
+ const createSource = sourceDef.create;
425
+ /**
426
+ * Definition for the {@link FileNode}. The fully resolved builder lives in
427
+ * `createFile`, so this definition only supplies the guard.
428
+ */
429
+ const fileDef = defineNode({ kind: "File" });
430
+ //#endregion
431
+ //#region src/nodes/function.ts
432
+ /**
433
+ * Definition for the {@link TypeLiteralNode}.
434
+ */
435
+ const typeLiteralDef = defineNode({ kind: "TypeLiteral" });
436
+ /**
437
+ * Creates a {@link TypeLiteralNode} representing an inline anonymous object type.
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })
442
+ * // { petId: string }
443
+ * ```
444
+ */
445
+ const createTypeLiteral = typeLiteralDef.create;
446
+ /**
447
+ * Definition for the {@link IndexedAccessTypeNode}.
448
+ */
449
+ const indexedAccessTypeDef = defineNode({ kind: "IndexedAccessType" });
450
+ /**
451
+ * Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.
452
+ *
453
+ * @example
454
+ * ```ts
455
+ * createIndexedAccessType({ objectType: 'DeletePetPathParams', indexType: 'petId' })
456
+ * // DeletePetPathParams['petId']
457
+ * ```
458
+ */
459
+ const createIndexedAccessType = indexedAccessTypeDef.create;
460
+ /**
461
+ * Definition for the {@link ObjectBindingPatternNode}.
462
+ */
463
+ const objectBindingPatternDef = defineNode({ kind: "ObjectBindingPattern" });
464
+ /**
465
+ * Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.
466
+ *
467
+ * @example
468
+ * ```ts
469
+ * createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })
470
+ * // { id, name }
471
+ * ```
472
+ */
473
+ const createObjectBindingPattern = objectBindingPatternDef.create;
474
+ /**
475
+ * Definition for the {@link FunctionParameterNode}. `optional` defaults to `false`.
476
+ * Passing `properties` builds a destructured group: an {@link ObjectBindingPatternNode} name
477
+ * paired with a {@link TypeLiteralNode} type.
478
+ */
479
+ const functionParameterDef = defineNode({
480
+ kind: "FunctionParameter",
481
+ build: (input) => {
482
+ if ("properties" in input) return {
483
+ name: createObjectBindingPattern({ elements: input.properties.map((p) => ({ name: p.name })) }),
484
+ type: createTypeLiteral({ members: input.properties.map((p) => ({
485
+ name: p.name,
486
+ type: p.type,
487
+ optional: p.optional ?? false
488
+ })) }),
489
+ optional: input.optional ?? false,
490
+ ...input.default !== void 0 ? { default: input.default } : {}
491
+ };
492
+ return {
493
+ optional: false,
494
+ ...input
495
+ };
496
+ }
497
+ });
498
+ /**
499
+ * Creates a `FunctionParameterNode`. `optional` defaults to `false`.
500
+ *
501
+ * @example Optional param
502
+ * ```ts
503
+ * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
504
+ * // → params?: QueryParams
505
+ * ```
506
+ *
507
+ * @example Destructured group
508
+ * ```ts
509
+ * createFunctionParameter({ properties: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string', optional: true }], default: '{}' })
510
+ * // → { id, name }: { id: string; name?: string } = {}
511
+ * ```
512
+ */
513
+ const createFunctionParameter = functionParameterDef.create;
514
+ /**
515
+ * Definition for the {@link FunctionParametersNode}.
516
+ */
517
+ const functionParametersDef = defineNode({
518
+ kind: "FunctionParameters",
519
+ defaults: { params: [] }
520
+ });
521
+ /**
522
+ * Creates a `FunctionParametersNode` from an ordered list of parameters.
523
+ *
524
+ * @example
525
+ * ```ts
526
+ * const empty = createFunctionParameters()
527
+ * // { kind: 'FunctionParameters', params: [] }
528
+ * ```
529
+ */
530
+ function createFunctionParameters(props = {}) {
531
+ return functionParametersDef.create(props);
532
+ }
533
+ //#endregion
534
+ //#region src/nodes/input.ts
535
+ /**
536
+ * Definition for the {@link InputNode}.
537
+ */
538
+ const inputDef = defineNode({
539
+ kind: "Input",
540
+ defaults: {
541
+ schemas: [],
542
+ operations: [],
543
+ meta: {
544
+ circularNames: [],
545
+ enumNames: []
546
+ }
547
+ },
548
+ children: ["schemas", "operations"],
549
+ visitorKey: "input"
550
+ });
551
+ /**
552
+ * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and
553
+ * `operations` are `AsyncIterable` sources and whose `meta` is optional. Otherwise it builds the
554
+ * eager variant with array `schemas`/`operations` and the defaulted `meta`.
555
+ *
556
+ * @example Eager
557
+ * ```ts
558
+ * const input = createInput()
559
+ * // { kind: 'Input', schemas: [], operations: [] }
560
+ * ```
561
+ *
562
+ * @example Streaming
563
+ * ```ts
564
+ * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
565
+ * ```
566
+ */
567
+ function createInput(options = {}) {
568
+ const { stream, ...overrides } = options;
569
+ if (stream) return {
570
+ kind: "Input",
571
+ ...overrides
572
+ };
573
+ return inputDef.create(overrides);
574
+ }
575
+ //#endregion
576
+ //#region src/nodes/requestBody.ts
577
+ /**
578
+ * Definition for the {@link RequestBodyNode}, normalizing each content entry into a `ContentNode`.
579
+ */
580
+ const requestBodyDef = defineNode({
581
+ kind: "RequestBody",
582
+ build: (props) => ({
583
+ ...props,
584
+ content: props.content?.map(createContent)
585
+ }),
586
+ children: ["content"]
587
+ });
588
+ /**
589
+ * Creates a `RequestBodyNode`, normalizing each content entry into a `ContentNode`.
590
+ */
591
+ const createRequestBody = requestBodyDef.create;
592
+ //#endregion
593
+ //#region src/nodes/operation.ts
594
+ /**
595
+ * Definition for the {@link OperationNode}. HTTP operations (those carrying both
596
+ * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
597
+ * normalized into a `RequestBodyNode`.
598
+ */
599
+ const operationDef = defineNode({
600
+ kind: "Operation",
601
+ build: (props) => {
602
+ const { requestBody, ...rest } = props;
603
+ const isHttp = rest.method !== void 0 && rest.path !== void 0;
604
+ return {
605
+ tags: [],
606
+ parameters: [],
607
+ responses: [],
608
+ ...rest,
609
+ ...isHttp ? { protocol: "http" } : {},
610
+ requestBody: requestBody ? createRequestBody(requestBody) : void 0
611
+ };
612
+ },
613
+ children: [
614
+ "parameters",
615
+ "requestBody",
616
+ "responses"
617
+ ],
618
+ visitorKey: "operation"
619
+ });
620
+ function createOperation(props) {
621
+ return operationDef.create(props);
622
+ }
623
+ //#endregion
624
+ //#region src/nodes/output.ts
625
+ /**
626
+ * Definition for the {@link OutputNode}.
627
+ */
628
+ const outputDef = defineNode({
629
+ kind: "Output",
630
+ defaults: { files: [] },
631
+ visitorKey: "output"
632
+ });
633
+ /**
634
+ * Creates an `OutputNode` with a stable default for `files`.
635
+ *
636
+ * @example
637
+ * ```ts
638
+ * const output = createOutput()
639
+ * // { kind: 'Output', files: [] }
640
+ * ```
641
+ */
642
+ function createOutput(overrides = {}) {
643
+ return outputDef.create(overrides);
644
+ }
645
+ //#endregion
646
+ //#region src/nodes/parameter.ts
647
+ /**
648
+ * Definition for the {@link ParameterNode}. `required` defaults to `false` and the
649
+ * schema's `optional`/`nullish` flags are kept in sync with it.
650
+ */
651
+ const parameterDef = defineNode({
652
+ kind: "Parameter",
653
+ build: (props) => {
654
+ const required = props.required ?? false;
655
+ return {
656
+ ...props,
657
+ required,
658
+ schema: syncOptionality(props.schema, required)
659
+ };
660
+ },
661
+ children: ["schema"],
662
+ visitorKey: "parameter",
663
+ rebuild: true
664
+ });
665
+ /**
666
+ * Creates a `ParameterNode`.
667
+ *
668
+ * @example
669
+ * ```ts
670
+ * const param = createParameter({
671
+ * name: 'petId',
672
+ * in: 'path',
673
+ * required: true,
674
+ * schema: createSchema({ type: 'string' }),
675
+ * })
676
+ * ```
677
+ */
678
+ const createParameter = parameterDef.create;
679
+ //#endregion
680
+ //#region src/nodes/response.ts
681
+ /**
682
+ * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
683
+ * `mediaType`/`keysToOmit`) is normalized into one `content` entry.
684
+ */
685
+ const responseDef = defineNode({
686
+ kind: "Response",
687
+ build: (props) => {
688
+ const { schema, mediaType, keysToOmit, content, ...rest } = props;
689
+ const entries = content ?? (schema ? [{
690
+ contentType: mediaType ?? "application/json",
691
+ schema,
692
+ keysToOmit: keysToOmit ?? null
693
+ }] : void 0);
694
+ return {
695
+ ...rest,
696
+ content: entries?.map(createContent)
697
+ };
698
+ },
699
+ children: ["content"],
700
+ visitorKey: "response"
701
+ });
702
+ /**
703
+ * Creates a `ResponseNode`.
704
+ *
705
+ * @example
706
+ * ```ts
707
+ * const response = createResponse({
708
+ * statusCode: '200',
709
+ * content: [{ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) }],
710
+ * })
711
+ * ```
712
+ */
713
+ const createResponse = responseDef.create;
714
+ //#endregion
715
+ Object.defineProperty(exports, "__exportAll", {
716
+ enumerable: true,
717
+ get: function() {
718
+ return __exportAll;
719
+ }
720
+ });
721
+ Object.defineProperty(exports, "__name", {
722
+ enumerable: true,
723
+ get: function() {
724
+ return __name;
725
+ }
726
+ });
727
+ Object.defineProperty(exports, "__toESM", {
728
+ enumerable: true,
729
+ get: function() {
730
+ return __toESM;
731
+ }
732
+ });
733
+ Object.defineProperty(exports, "arrowFunctionDef", {
734
+ enumerable: true,
735
+ get: function() {
736
+ return arrowFunctionDef;
737
+ }
738
+ });
739
+ Object.defineProperty(exports, "breakDef", {
740
+ enumerable: true,
741
+ get: function() {
742
+ return breakDef;
743
+ }
744
+ });
745
+ Object.defineProperty(exports, "camelCase", {
746
+ enumerable: true,
747
+ get: function() {
748
+ return camelCase;
749
+ }
750
+ });
751
+ Object.defineProperty(exports, "constDef", {
752
+ enumerable: true,
753
+ get: function() {
754
+ return constDef;
755
+ }
756
+ });
757
+ Object.defineProperty(exports, "contentDef", {
758
+ enumerable: true,
759
+ get: function() {
760
+ return contentDef;
761
+ }
762
+ });
763
+ Object.defineProperty(exports, "createArrowFunction", {
764
+ enumerable: true,
765
+ get: function() {
766
+ return createArrowFunction;
767
+ }
768
+ });
769
+ Object.defineProperty(exports, "createBreak", {
770
+ enumerable: true,
771
+ get: function() {
772
+ return createBreak;
773
+ }
774
+ });
775
+ Object.defineProperty(exports, "createConst", {
776
+ enumerable: true,
777
+ get: function() {
778
+ return createConst;
779
+ }
780
+ });
781
+ Object.defineProperty(exports, "createContent", {
782
+ enumerable: true,
783
+ get: function() {
784
+ return createContent;
785
+ }
786
+ });
787
+ Object.defineProperty(exports, "createExport", {
788
+ enumerable: true,
789
+ get: function() {
790
+ return createExport;
791
+ }
792
+ });
793
+ Object.defineProperty(exports, "createFunction", {
794
+ enumerable: true,
795
+ get: function() {
796
+ return createFunction;
797
+ }
798
+ });
799
+ Object.defineProperty(exports, "createFunctionParameter", {
800
+ enumerable: true,
801
+ get: function() {
802
+ return createFunctionParameter;
803
+ }
804
+ });
805
+ Object.defineProperty(exports, "createFunctionParameters", {
806
+ enumerable: true,
807
+ get: function() {
808
+ return createFunctionParameters;
809
+ }
810
+ });
811
+ Object.defineProperty(exports, "createImport", {
812
+ enumerable: true,
813
+ get: function() {
814
+ return createImport;
815
+ }
816
+ });
817
+ Object.defineProperty(exports, "createIndexedAccessType", {
818
+ enumerable: true,
819
+ get: function() {
820
+ return createIndexedAccessType;
821
+ }
822
+ });
823
+ Object.defineProperty(exports, "createInput", {
824
+ enumerable: true,
825
+ get: function() {
826
+ return createInput;
827
+ }
828
+ });
829
+ Object.defineProperty(exports, "createJsx", {
830
+ enumerable: true,
831
+ get: function() {
832
+ return createJsx;
833
+ }
834
+ });
835
+ Object.defineProperty(exports, "createObjectBindingPattern", {
836
+ enumerable: true,
837
+ get: function() {
838
+ return createObjectBindingPattern;
839
+ }
840
+ });
841
+ Object.defineProperty(exports, "createOperation", {
842
+ enumerable: true,
843
+ get: function() {
844
+ return createOperation;
845
+ }
846
+ });
847
+ Object.defineProperty(exports, "createOutput", {
848
+ enumerable: true,
849
+ get: function() {
850
+ return createOutput;
851
+ }
852
+ });
853
+ Object.defineProperty(exports, "createParameter", {
854
+ enumerable: true,
855
+ get: function() {
856
+ return createParameter;
857
+ }
858
+ });
859
+ Object.defineProperty(exports, "createProperty", {
860
+ enumerable: true,
861
+ get: function() {
862
+ return createProperty;
863
+ }
864
+ });
865
+ Object.defineProperty(exports, "createRequestBody", {
866
+ enumerable: true,
867
+ get: function() {
868
+ return createRequestBody;
869
+ }
870
+ });
871
+ Object.defineProperty(exports, "createResponse", {
872
+ enumerable: true,
873
+ get: function() {
874
+ return createResponse;
875
+ }
876
+ });
877
+ Object.defineProperty(exports, "createSchema", {
878
+ enumerable: true,
879
+ get: function() {
880
+ return createSchema;
881
+ }
882
+ });
883
+ Object.defineProperty(exports, "createSource", {
884
+ enumerable: true,
885
+ get: function() {
886
+ return createSource;
887
+ }
888
+ });
889
+ Object.defineProperty(exports, "createText", {
890
+ enumerable: true,
891
+ get: function() {
892
+ return createText;
893
+ }
894
+ });
895
+ Object.defineProperty(exports, "createType", {
896
+ enumerable: true,
897
+ get: function() {
898
+ return createType;
899
+ }
900
+ });
901
+ Object.defineProperty(exports, "createTypeLiteral", {
902
+ enumerable: true,
903
+ get: function() {
904
+ return createTypeLiteral;
905
+ }
906
+ });
907
+ Object.defineProperty(exports, "defineNode", {
908
+ enumerable: true,
909
+ get: function() {
910
+ return defineNode;
911
+ }
912
+ });
913
+ Object.defineProperty(exports, "exportDef", {
914
+ enumerable: true,
915
+ get: function() {
916
+ return exportDef;
917
+ }
918
+ });
919
+ Object.defineProperty(exports, "extractStringsFromNodes", {
920
+ enumerable: true,
921
+ get: function() {
922
+ return extractStringsFromNodes;
923
+ }
924
+ });
925
+ Object.defineProperty(exports, "fileDef", {
926
+ enumerable: true,
927
+ get: function() {
928
+ return fileDef;
929
+ }
930
+ });
931
+ Object.defineProperty(exports, "functionDef", {
932
+ enumerable: true,
933
+ get: function() {
934
+ return functionDef;
935
+ }
936
+ });
937
+ Object.defineProperty(exports, "functionParameterDef", {
938
+ enumerable: true,
939
+ get: function() {
940
+ return functionParameterDef;
941
+ }
942
+ });
943
+ Object.defineProperty(exports, "functionParametersDef", {
944
+ enumerable: true,
945
+ get: function() {
946
+ return functionParametersDef;
947
+ }
948
+ });
949
+ Object.defineProperty(exports, "importDef", {
950
+ enumerable: true,
951
+ get: function() {
952
+ return importDef;
953
+ }
954
+ });
955
+ Object.defineProperty(exports, "indexedAccessTypeDef", {
956
+ enumerable: true,
957
+ get: function() {
958
+ return indexedAccessTypeDef;
959
+ }
960
+ });
961
+ Object.defineProperty(exports, "inputDef", {
962
+ enumerable: true,
963
+ get: function() {
964
+ return inputDef;
965
+ }
966
+ });
967
+ Object.defineProperty(exports, "jsxDef", {
968
+ enumerable: true,
969
+ get: function() {
970
+ return jsxDef;
971
+ }
972
+ });
973
+ Object.defineProperty(exports, "objectBindingPatternDef", {
974
+ enumerable: true,
975
+ get: function() {
976
+ return objectBindingPatternDef;
977
+ }
978
+ });
979
+ Object.defineProperty(exports, "operationDef", {
980
+ enumerable: true,
981
+ get: function() {
982
+ return operationDef;
983
+ }
984
+ });
985
+ Object.defineProperty(exports, "outputDef", {
986
+ enumerable: true,
987
+ get: function() {
988
+ return outputDef;
989
+ }
990
+ });
991
+ Object.defineProperty(exports, "parameterDef", {
992
+ enumerable: true,
993
+ get: function() {
994
+ return parameterDef;
995
+ }
996
+ });
997
+ Object.defineProperty(exports, "pascalCase", {
998
+ enumerable: true,
999
+ get: function() {
1000
+ return pascalCase;
1001
+ }
1002
+ });
1003
+ Object.defineProperty(exports, "propertyDef", {
1004
+ enumerable: true,
1005
+ get: function() {
1006
+ return propertyDef;
1007
+ }
1008
+ });
1009
+ Object.defineProperty(exports, "requestBodyDef", {
1010
+ enumerable: true,
1011
+ get: function() {
1012
+ return requestBodyDef;
1013
+ }
1014
+ });
1015
+ Object.defineProperty(exports, "responseDef", {
1016
+ enumerable: true,
1017
+ get: function() {
1018
+ return responseDef;
1019
+ }
1020
+ });
1021
+ Object.defineProperty(exports, "schemaDef", {
1022
+ enumerable: true,
1023
+ get: function() {
1024
+ return schemaDef;
1025
+ }
1026
+ });
1027
+ Object.defineProperty(exports, "sourceDef", {
1028
+ enumerable: true,
1029
+ get: function() {
1030
+ return sourceDef;
1031
+ }
1032
+ });
1033
+ Object.defineProperty(exports, "syncOptionality", {
1034
+ enumerable: true,
1035
+ get: function() {
1036
+ return syncOptionality;
1037
+ }
1038
+ });
1039
+ Object.defineProperty(exports, "textDef", {
1040
+ enumerable: true,
1041
+ get: function() {
1042
+ return textDef;
1043
+ }
1044
+ });
1045
+ Object.defineProperty(exports, "typeDef", {
1046
+ enumerable: true,
1047
+ get: function() {
1048
+ return typeDef;
1049
+ }
1050
+ });
1051
+ Object.defineProperty(exports, "typeLiteralDef", {
1052
+ enumerable: true,
1053
+ get: function() {
1054
+ return typeLiteralDef;
1055
+ }
1056
+ });
1057
+
1058
+ //# sourceMappingURL=response-DS5S3IG4.cjs.map