@kubb/ast 5.0.0-beta.57 → 5.0.0-beta.58

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 (43) hide show
  1. package/README.md +11 -7
  2. package/dist/{types-C5aVnRE1.d.ts → ast-ClnJg9BN.d.ts} +82 -836
  3. package/dist/chunk-CNktS9qV.js +17 -0
  4. package/dist/extractStringsFromNodes-Bn9cOos9.d.ts +14 -0
  5. package/dist/factory-C5gHvtLU.js +138 -0
  6. package/dist/factory-C5gHvtLU.js.map +1 -0
  7. package/dist/factory-JN-Ylfl6.cjs +155 -0
  8. package/dist/factory-JN-Ylfl6.cjs.map +1 -0
  9. package/dist/factory.cjs +31 -0
  10. package/dist/factory.d.ts +62 -0
  11. package/dist/factory.js +3 -0
  12. package/dist/index.cjs +86 -1746
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +6 -3
  15. package/dist/index.js +177 -1809
  16. package/dist/index.js.map +1 -1
  17. package/dist/types-CB2oY8Dw.d.ts +769 -0
  18. package/dist/types.d.ts +4 -2
  19. package/dist/utils-C8bWAzhv.cjs +2696 -0
  20. package/dist/utils-C8bWAzhv.cjs.map +1 -0
  21. package/dist/utils-DN4XLVqz.js +2099 -0
  22. package/dist/utils-DN4XLVqz.js.map +1 -0
  23. package/dist/utils.cjs +12 -1
  24. package/dist/utils.d.ts +21 -2
  25. package/dist/utils.js +2 -2
  26. package/package.json +5 -1
  27. package/src/factory.ts +19 -1
  28. package/src/index.ts +14 -48
  29. package/src/node.ts +1 -1
  30. package/src/nodes/base.ts +0 -10
  31. package/src/nodes/function.ts +2 -2
  32. package/src/nodes/index.ts +1 -1
  33. package/src/nodes/input.ts +14 -13
  34. package/src/printer.ts +3 -3
  35. package/src/types.ts +1 -1
  36. package/src/utils/ast.ts +3 -66
  37. package/src/utils/extractStringsFromNodes.ts +34 -0
  38. package/src/utils/index.ts +44 -0
  39. package/dist/chunk-C0LytTxp.js +0 -8
  40. package/dist/utils-0p8ZO287.js +0 -570
  41. package/dist/utils-0p8ZO287.js.map +0 -1
  42. package/dist/utils-cdQ6Pzyi.cjs +0 -726
  43. package/dist/utils-cdQ6Pzyi.cjs.map +0 -1
@@ -0,0 +1,2696 @@
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/constants.ts
37
+ const visitorDepths = {
38
+ shallow: "shallow",
39
+ deep: "deep"
40
+ };
41
+ /**
42
+ * Schema type discriminators used by all AST schema nodes.
43
+ *
44
+ * These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).
45
+ * Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),
46
+ * and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.
47
+ */
48
+ const schemaTypes = {
49
+ /**
50
+ * Text value.
51
+ */
52
+ string: "string",
53
+ /**
54
+ * Floating-point number (`float`, `double`).
55
+ */
56
+ number: "number",
57
+ /**
58
+ * Whole number (`int32`). Use `bigint` for `int64`.
59
+ */
60
+ integer: "integer",
61
+ /**
62
+ * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
63
+ */
64
+ bigint: "bigint",
65
+ /**
66
+ * Boolean value
67
+ */
68
+ boolean: "boolean",
69
+ /**
70
+ * Explicit null value.
71
+ */
72
+ null: "null",
73
+ /**
74
+ * Any value (no type restriction).
75
+ */
76
+ any: "any",
77
+ /**
78
+ * Unknown value (must be narrowed before usage).
79
+ */
80
+ unknown: "unknown",
81
+ /**
82
+ * No return value (`void`).
83
+ */
84
+ void: "void",
85
+ /**
86
+ * Object with named properties.
87
+ */
88
+ object: "object",
89
+ /**
90
+ * Sequential list of items.
91
+ */
92
+ array: "array",
93
+ /**
94
+ * Fixed-length list with position-specific items.
95
+ */
96
+ tuple: "tuple",
97
+ /**
98
+ * "One of" multiple schema members.
99
+ */
100
+ union: "union",
101
+ /**
102
+ * "All of" multiple schema members.
103
+ */
104
+ intersection: "intersection",
105
+ /**
106
+ * Enum schema.
107
+ */
108
+ enum: "enum",
109
+ /**
110
+ * Reference to another schema.
111
+ */
112
+ ref: "ref",
113
+ /**
114
+ * Calendar date (for example `2026-03-24`).
115
+ */
116
+ date: "date",
117
+ /**
118
+ * Date-time value (for example `2026-03-24T09:00:00Z`).
119
+ */
120
+ datetime: "datetime",
121
+ /**
122
+ * Time-only value (for example `09:00:00`).
123
+ */
124
+ time: "time",
125
+ /**
126
+ * UUID value.
127
+ */
128
+ uuid: "uuid",
129
+ /**
130
+ * Email address value.
131
+ */
132
+ email: "email",
133
+ /**
134
+ * URL value.
135
+ */
136
+ url: "url",
137
+ /**
138
+ * IPv4 address value.
139
+ */
140
+ ipv4: "ipv4",
141
+ /**
142
+ * IPv6 address value.
143
+ */
144
+ ipv6: "ipv6",
145
+ /**
146
+ * Binary/blob value.
147
+ */
148
+ blob: "blob",
149
+ /**
150
+ * Impossible value (`never`).
151
+ */
152
+ never: "never"
153
+ };
154
+ /**
155
+ * Scalar primitive schema types used for union simplification and type narrowing.
156
+ *
157
+ * Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.
158
+ */
159
+ const SCALAR_PRIMITIVE_TYPES = new Set([
160
+ "string",
161
+ "number",
162
+ "integer",
163
+ "bigint",
164
+ "boolean"
165
+ ]);
166
+ /**
167
+ * Type guard that returns `true` when `type` is a scalar primitive schema type.
168
+ *
169
+ * Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).
170
+ */
171
+ function isScalarPrimitive(type) {
172
+ return SCALAR_PRIMITIVE_TYPES.has(type);
173
+ }
174
+ /**
175
+ * HTTP method identifiers used by operation nodes.
176
+ *
177
+ * Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).
178
+ */
179
+ const httpMethods = {
180
+ get: "GET",
181
+ post: "POST",
182
+ put: "PUT",
183
+ patch: "PATCH",
184
+ delete: "DELETE",
185
+ head: "HEAD",
186
+ options: "OPTIONS",
187
+ trace: "TRACE"
188
+ };
189
+ /**
190
+ * One indentation level, derived from {@link INDENT_SIZE}.
191
+ */
192
+ const INDENT = Array.from({ length: 2 }, () => " ").join("");
193
+ //#endregion
194
+ //#region src/node.ts
195
+ /**
196
+ * Builds a type guard that matches nodes of the given `kind`.
197
+ */
198
+ function isKind(kind) {
199
+ return (node) => node.kind === kind;
200
+ }
201
+ /**
202
+ * Updates a schema's `optional` and `nullish` flags from a parent's `required`
203
+ * value and the schema's own `nullable`. Mirrors how OpenAPI parameters and
204
+ * object properties combine "required" and "nullable" into a single AST.
205
+ *
206
+ * - Non-required + non-nullable → `optional: true`.
207
+ * - Non-required + nullable → `nullish: true`.
208
+ * - Required → both flags cleared.
209
+ */
210
+ function syncOptionality(schema, required) {
211
+ const nullable = schema.nullable ?? false;
212
+ return {
213
+ ...schema,
214
+ optional: !required && !nullable ? true : void 0,
215
+ nullish: !required && nullable ? true : void 0
216
+ };
217
+ }
218
+ /**
219
+ * Defines a node once and derives its `create` builder, `is` guard, and traversal
220
+ * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the
221
+ * `kind`, so node construction lives in one place without scattered `as` casts.
222
+ *
223
+ * Set `rebuild: true` when the `build` hook derives fields from children. After a
224
+ * transform rewrites those children, the registry reruns `create` so the derived
225
+ * fields stay correct.
226
+ *
227
+ * @example Simple node
228
+ * ```ts
229
+ * const importDef = defineNode<ImportNode>({ kind: 'Import' })
230
+ * const createImport = importDef.create
231
+ * ```
232
+ *
233
+ * @example Node with a build hook that is rerun on transform
234
+ * ```ts
235
+ * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({
236
+ * kind: 'Property',
237
+ * build: (props) => ({ ...props, required: props.required ?? false }),
238
+ * children: ['schema'],
239
+ * visitorKey: 'property',
240
+ * rebuild: true,
241
+ * })
242
+ * ```
243
+ */
244
+ function defineNode(config) {
245
+ const { kind, defaults, build, children, visitorKey, rebuild } = config;
246
+ function create(input) {
247
+ const base = build ? build(input) : input;
248
+ return {
249
+ ...defaults,
250
+ ...base,
251
+ kind
252
+ };
253
+ }
254
+ return {
255
+ kind,
256
+ create,
257
+ is: isKind(kind),
258
+ children,
259
+ visitorKey,
260
+ rebuild
261
+ };
262
+ }
263
+ //#endregion
264
+ //#region src/nodes/schema.ts
265
+ /**
266
+ * Maps schema `type` to its underlying `primitive`.
267
+ * Primitive types map to themselves. Special string formats map to `'string'`.
268
+ * Complex types (`ref`, `enum`, `union`, `intersection`, `tuple`, `blob`) are left unset.
269
+ */
270
+ const TYPE_TO_PRIMITIVE = {
271
+ string: "string",
272
+ number: "number",
273
+ integer: "integer",
274
+ bigint: "bigint",
275
+ boolean: "boolean",
276
+ null: "null",
277
+ any: "any",
278
+ unknown: "unknown",
279
+ void: "void",
280
+ never: "never",
281
+ object: "object",
282
+ array: "array",
283
+ date: "date",
284
+ uuid: "string",
285
+ email: "string",
286
+ url: "string",
287
+ datetime: "string",
288
+ time: "string"
289
+ };
290
+ /**
291
+ * Definition for the {@link SchemaNode}. Object schemas default `properties` to an
292
+ * empty array, and `primitive` is inferred from `type` when not explicitly provided.
293
+ */
294
+ const schemaDef = defineNode({
295
+ kind: "Schema",
296
+ build: (props) => {
297
+ if (props.type === "object") return {
298
+ properties: [],
299
+ primitive: "object",
300
+ ...props
301
+ };
302
+ return {
303
+ primitive: TYPE_TO_PRIMITIVE[props.type],
304
+ ...props
305
+ };
306
+ },
307
+ children: [
308
+ "properties",
309
+ "items",
310
+ "members",
311
+ "additionalProperties"
312
+ ],
313
+ visitorKey: "schema"
314
+ });
315
+ function createSchema(props) {
316
+ return schemaDef.create(props);
317
+ }
318
+ //#endregion
319
+ //#region ../../internals/utils/src/casing.ts
320
+ /**
321
+ * Shared implementation for camelCase and PascalCase conversion.
322
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
323
+ * and capitalizes each word according to `pascal`.
324
+ *
325
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
326
+ */
327
+ function toCamelOrPascal(text, pascal) {
328
+ 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) => {
329
+ if (word.length > 1 && word === word.toUpperCase()) return word;
330
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
331
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
332
+ }
333
+ /**
334
+ * Converts `text` to camelCase.
335
+ *
336
+ * @example Word boundaries
337
+ * `camelCase('hello-world') // 'helloWorld'`
338
+ *
339
+ * @example With a prefix
340
+ * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
341
+ */
342
+ function camelCase(text, { prefix = "", suffix = "" } = {}) {
343
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
344
+ }
345
+ /**
346
+ * Converts `text` to PascalCase.
347
+ *
348
+ * @example Word boundaries
349
+ * `pascalCase('hello-world') // 'HelloWorld'`
350
+ *
351
+ * @example With a suffix
352
+ * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
353
+ */
354
+ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
355
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
356
+ }
357
+ //#endregion
358
+ //#region ../../internals/utils/src/promise.ts
359
+ /**
360
+ * Wraps `factory` with a keyed cache backed by the provided store.
361
+ *
362
+ * Pass a `WeakMap` for object keys (results are GC-eligible when the key is
363
+ * collected) or a `Map` for primitive keys. For multi-argument functions,
364
+ * nest two `memoize` calls — the outer keyed by the first argument, the
365
+ * inner (created once per outer miss) keyed by the second.
366
+ *
367
+ * Because the cache is owned by the caller, it can be shared, inspected, or
368
+ * cleared independently of the memoized function.
369
+ *
370
+ * @example Single WeakMap key
371
+ * ```ts
372
+ * const cache = new WeakMap<SchemaNode, Set<string>>()
373
+ * const getRefs = memoize(cache, (node) => collectRefs(node))
374
+ * ```
375
+ *
376
+ * @example Single Map key (primitive)
377
+ * ```ts
378
+ * const cache = new Map<string, Resolver>()
379
+ * const getResolver = memoize(cache, (name) => buildResolver(name))
380
+ * ```
381
+ *
382
+ * @example Two-level (object + primitive)
383
+ * ```ts
384
+ * const outer = new WeakMap<Params[], Map<string, Params[]>>()
385
+ * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))
386
+ * fn(params)('camelcase')
387
+ * ```
388
+ */
389
+ function memoize(store, factory) {
390
+ return (key) => {
391
+ if (store.has(key)) return store.get(key);
392
+ const value = factory(key);
393
+ store.set(key, value);
394
+ return value;
395
+ };
396
+ }
397
+ //#endregion
398
+ //#region ../../internals/utils/src/reserved.ts
399
+ /**
400
+ * JavaScript and Java reserved words.
401
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
402
+ */
403
+ const reservedWords = new Set([
404
+ "abstract",
405
+ "arguments",
406
+ "boolean",
407
+ "break",
408
+ "byte",
409
+ "case",
410
+ "catch",
411
+ "char",
412
+ "class",
413
+ "const",
414
+ "continue",
415
+ "debugger",
416
+ "default",
417
+ "delete",
418
+ "do",
419
+ "double",
420
+ "else",
421
+ "enum",
422
+ "eval",
423
+ "export",
424
+ "extends",
425
+ "false",
426
+ "final",
427
+ "finally",
428
+ "float",
429
+ "for",
430
+ "function",
431
+ "goto",
432
+ "if",
433
+ "implements",
434
+ "import",
435
+ "in",
436
+ "instanceof",
437
+ "int",
438
+ "interface",
439
+ "let",
440
+ "long",
441
+ "native",
442
+ "new",
443
+ "null",
444
+ "package",
445
+ "private",
446
+ "protected",
447
+ "public",
448
+ "return",
449
+ "short",
450
+ "static",
451
+ "super",
452
+ "switch",
453
+ "synchronized",
454
+ "this",
455
+ "throw",
456
+ "throws",
457
+ "transient",
458
+ "true",
459
+ "try",
460
+ "typeof",
461
+ "var",
462
+ "void",
463
+ "volatile",
464
+ "while",
465
+ "with",
466
+ "yield",
467
+ "Array",
468
+ "Date",
469
+ "hasOwnProperty",
470
+ "Infinity",
471
+ "isFinite",
472
+ "isNaN",
473
+ "isPrototypeOf",
474
+ "length",
475
+ "Math",
476
+ "name",
477
+ "NaN",
478
+ "Number",
479
+ "Object",
480
+ "prototype",
481
+ "String",
482
+ "toString",
483
+ "undefined",
484
+ "valueOf"
485
+ ]);
486
+ /**
487
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
488
+ *
489
+ * @example
490
+ * ```ts
491
+ * isValidVarName('status') // true
492
+ * isValidVarName('class') // false (reserved word)
493
+ * isValidVarName('42foo') // false (starts with digit)
494
+ * ```
495
+ */
496
+ function isValidVarName(name) {
497
+ if (!name || reservedWords.has(name)) return false;
498
+ return isIdentifier(name);
499
+ }
500
+ /**
501
+ * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
502
+ *
503
+ * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
504
+ * even though they are not valid variable names, so use this (not {@link isValidVarName}) when
505
+ * deciding whether an object key needs quoting.
506
+ *
507
+ * @example
508
+ * ```ts
509
+ * isIdentifier('name') // true
510
+ * isIdentifier('x-total')// false
511
+ * ```
512
+ */
513
+ function isIdentifier(name) {
514
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
515
+ }
516
+ //#endregion
517
+ //#region ../../internals/utils/src/string.ts
518
+ /**
519
+ * Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping
520
+ * any backslash or single quote in the content.
521
+ *
522
+ * @example
523
+ * ```ts
524
+ * singleQuote('foo') // "'foo'"
525
+ * singleQuote("o'clock") // "'o\\'clock'"
526
+ * ```
527
+ */
528
+ function singleQuote(value) {
529
+ if (value === void 0 || value === null) return "''";
530
+ return `'${String(value).replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
531
+ }
532
+ //#endregion
533
+ //#region src/utils/extractStringsFromNodes.ts
534
+ /**
535
+ * Extracts all string content from a `CodeNode` tree recursively.
536
+ *
537
+ * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
538
+ * and nested node content. Used to build the full source string for import filtering.
539
+ */
540
+ function extractStringsFromNodes(nodes) {
541
+ if (!nodes?.length) return "";
542
+ return nodes.map((node) => {
543
+ if (typeof node === "string") return node;
544
+ if (node.kind === "Text") return node.value;
545
+ if (node.kind === "Break") return "";
546
+ if (node.kind === "Jsx") return node.value;
547
+ const parts = [];
548
+ if ("params" in node && node.params) parts.push(node.params);
549
+ if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics);
550
+ if ("returnType" in node && node.returnType) parts.push(node.returnType);
551
+ if ("type" in node && typeof node.type === "string") parts.push(node.type);
552
+ const nested = extractStringsFromNodes(node.nodes);
553
+ if (nested) parts.push(nested);
554
+ return parts.join("\n");
555
+ }).filter(Boolean).join("\n");
556
+ }
557
+ //#endregion
558
+ //#region src/guards.ts
559
+ /**
560
+ * Narrows a `SchemaNode` to the variant that matches `type`.
561
+ *
562
+ * @example
563
+ * ```ts
564
+ * const schema = createSchema({ type: 'string' })
565
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
566
+ * ```
567
+ */
568
+ function narrowSchema(node, type) {
569
+ return node?.type === type ? node : null;
570
+ }
571
+ /**
572
+ * Narrows an `OperationNode` to an `HttpOperationNode`, guaranteeing `method` and `path`.
573
+ *
574
+ * @example
575
+ * ```ts
576
+ * if (isHttpOperationNode(node)) {
577
+ * console.log(node.method, node.path)
578
+ * }
579
+ * ```
580
+ */
581
+ function isHttpOperationNode(node) {
582
+ return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
583
+ }
584
+ //#endregion
585
+ //#region src/nodes/function.ts
586
+ /**
587
+ * Definition for the {@link TypeLiteralNode}.
588
+ */
589
+ const typeLiteralDef = defineNode({ kind: "TypeLiteral" });
590
+ /**
591
+ * Creates a {@link TypeLiteralNode} representing an inline anonymous object type.
592
+ *
593
+ * @example
594
+ * ```ts
595
+ * createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })
596
+ * // { petId: string }
597
+ * ```
598
+ */
599
+ const createTypeLiteral = typeLiteralDef.create;
600
+ /**
601
+ * Definition for the {@link IndexedAccessTypeNode}.
602
+ */
603
+ const indexedAccessTypeDef = defineNode({ kind: "IndexedAccessType" });
604
+ /**
605
+ * Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.
606
+ *
607
+ * @example
608
+ * ```ts
609
+ * createIndexedAccessType({ objectType: 'DeletePetPathParams', indexType: 'petId' })
610
+ * // DeletePetPathParams['petId']
611
+ * ```
612
+ */
613
+ const createIndexedAccessType = indexedAccessTypeDef.create;
614
+ /**
615
+ * Definition for the {@link ObjectBindingPatternNode}.
616
+ */
617
+ const objectBindingPatternDef = defineNode({ kind: "ObjectBindingPattern" });
618
+ /**
619
+ * Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.
620
+ *
621
+ * @example
622
+ * ```ts
623
+ * createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })
624
+ * // { id, name }
625
+ * ```
626
+ */
627
+ const createObjectBindingPattern = objectBindingPatternDef.create;
628
+ /**
629
+ * Definition for the {@link FunctionParameterNode}. `optional` defaults to `false`.
630
+ * Passing `properties` builds a destructured group: an {@link ObjectBindingPatternNode} name
631
+ * paired with a {@link TypeLiteralNode} type.
632
+ */
633
+ const functionParameterDef = defineNode({
634
+ kind: "FunctionParameter",
635
+ build: (input) => {
636
+ if ("properties" in input) return {
637
+ name: createObjectBindingPattern({ elements: input.properties.map((p) => ({ name: p.name })) }),
638
+ type: createTypeLiteral({ members: input.properties.map((p) => ({
639
+ name: p.name,
640
+ type: p.type,
641
+ optional: p.optional ?? false
642
+ })) }),
643
+ optional: input.optional ?? false,
644
+ ...input.default !== void 0 ? { default: input.default } : {}
645
+ };
646
+ return {
647
+ optional: false,
648
+ ...input
649
+ };
650
+ }
651
+ });
652
+ /**
653
+ * Creates a `FunctionParameterNode`. `optional` defaults to `false`.
654
+ *
655
+ * @example Optional param
656
+ * ```ts
657
+ * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
658
+ * // → params?: QueryParams
659
+ * ```
660
+ *
661
+ * @example Destructured group
662
+ * ```ts
663
+ * createFunctionParameter({ properties: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string', optional: true }], default: '{}' })
664
+ * // → { id, name }: { id: string; name?: string } = {}
665
+ * ```
666
+ */
667
+ const createFunctionParameter = functionParameterDef.create;
668
+ /**
669
+ * Definition for the {@link FunctionParametersNode}.
670
+ */
671
+ const functionParametersDef = defineNode({
672
+ kind: "FunctionParameters",
673
+ defaults: { params: [] }
674
+ });
675
+ /**
676
+ * Creates a `FunctionParametersNode` from an ordered list of parameters.
677
+ *
678
+ * @example
679
+ * ```ts
680
+ * const empty = createFunctionParameters()
681
+ * // { kind: 'FunctionParameters', params: [] }
682
+ * ```
683
+ */
684
+ function createFunctionParameters(props = {}) {
685
+ return functionParametersDef.create(props);
686
+ }
687
+ //#endregion
688
+ //#region src/nodes/property.ts
689
+ /**
690
+ * Definition for the {@link PropertyNode}. `required` defaults to `false` and the
691
+ * schema's `optional`/`nullish` flags are kept in sync with it.
692
+ */
693
+ const propertyDef = defineNode({
694
+ kind: "Property",
695
+ build: (props) => {
696
+ const required = props.required ?? false;
697
+ return {
698
+ ...props,
699
+ required,
700
+ schema: syncOptionality(props.schema, required)
701
+ };
702
+ },
703
+ children: ["schema"],
704
+ visitorKey: "property",
705
+ rebuild: true
706
+ });
707
+ /**
708
+ * Creates a `PropertyNode`.
709
+ *
710
+ * @example
711
+ * ```ts
712
+ * const property = createProperty({
713
+ * name: 'status',
714
+ * required: true,
715
+ * schema: createSchema({ type: 'string', nullable: true }),
716
+ * })
717
+ * // required=true, no optional/nullish
718
+ * ```
719
+ */
720
+ const createProperty = propertyDef.create;
721
+ //#endregion
722
+ //#region src/nodes/code.ts
723
+ /**
724
+ * Definition for the {@link ConstNode}.
725
+ */
726
+ const constDef = defineNode({ kind: "Const" });
727
+ /**
728
+ * Creates a `ConstNode` representing a TypeScript `const` declaration.
729
+ *
730
+ * @example Exported constant with type and `as const`
731
+ * ```ts
732
+ * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
733
+ * // export const pets: Pet[] = ... as const
734
+ * ```
735
+ */
736
+ const createConst = constDef.create;
737
+ /**
738
+ * Definition for the {@link TypeNode}.
739
+ */
740
+ const typeDef = defineNode({ kind: "Type" });
741
+ /**
742
+ * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
743
+ *
744
+ * @example
745
+ * ```ts
746
+ * createType({ name: 'Pet', export: true })
747
+ * // export type Pet = ...
748
+ * ```
749
+ */
750
+ const createType = typeDef.create;
751
+ /**
752
+ * Definition for the {@link FunctionNode}.
753
+ */
754
+ const functionDef = defineNode({ kind: "Function" });
755
+ /**
756
+ * Creates a `FunctionNode` representing a TypeScript `function` declaration.
757
+ *
758
+ * @example
759
+ * ```ts
760
+ * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
761
+ * // export async function fetchPet(): Promise<Pet> { ... }
762
+ * ```
763
+ */
764
+ const createFunction = functionDef.create;
765
+ /**
766
+ * Definition for the {@link ArrowFunctionNode}.
767
+ */
768
+ const arrowFunctionDef = defineNode({ kind: "ArrowFunction" });
769
+ /**
770
+ * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
771
+ *
772
+ * @example
773
+ * ```ts
774
+ * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
775
+ * // export const double = (n: number) => ...
776
+ * ```
777
+ */
778
+ const createArrowFunction = arrowFunctionDef.create;
779
+ /**
780
+ * Definition for the {@link TextNode}.
781
+ */
782
+ const textDef = defineNode({
783
+ kind: "Text",
784
+ build: (value) => ({ value })
785
+ });
786
+ /**
787
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
788
+ *
789
+ * @example
790
+ * ```ts
791
+ * createText('return fetch(id)')
792
+ * // { kind: 'Text', value: 'return fetch(id)' }
793
+ * ```
794
+ */
795
+ const createText = textDef.create;
796
+ /**
797
+ * Definition for the {@link BreakNode}.
798
+ */
799
+ const breakDef = defineNode({
800
+ kind: "Break",
801
+ build: () => ({})
802
+ });
803
+ /**
804
+ * Creates a {@link BreakNode} representing a line break in the source output.
805
+ *
806
+ * @example
807
+ * ```ts
808
+ * createBreak()
809
+ * // { kind: 'Break' }
810
+ * ```
811
+ */
812
+ function createBreak() {
813
+ return breakDef.create();
814
+ }
815
+ /**
816
+ * Definition for the {@link JsxNode}.
817
+ */
818
+ const jsxDef = defineNode({
819
+ kind: "Jsx",
820
+ build: (value) => ({ value })
821
+ });
822
+ /**
823
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
824
+ *
825
+ * @example
826
+ * ```ts
827
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
828
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
829
+ * ```
830
+ */
831
+ const createJsx = jsxDef.create;
832
+ //#endregion
833
+ //#region src/nodes/content.ts
834
+ /**
835
+ * Definition for the {@link ContentNode}.
836
+ */
837
+ const contentDef = defineNode({
838
+ kind: "Content",
839
+ children: ["schema"]
840
+ });
841
+ /**
842
+ * Creates a `ContentNode` for a single request-body or response content type.
843
+ */
844
+ const createContent = contentDef.create;
845
+ //#endregion
846
+ //#region src/nodes/file.ts
847
+ /**
848
+ * Definition for the {@link ImportNode}.
849
+ */
850
+ const importDef = defineNode({ kind: "Import" });
851
+ /**
852
+ * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
853
+ *
854
+ * @example Named import
855
+ * ```ts
856
+ * createImport({ name: ['useState'], path: 'react' })
857
+ * // import { useState } from 'react'
858
+ * ```
859
+ */
860
+ const createImport = importDef.create;
861
+ /**
862
+ * Definition for the {@link ExportNode}.
863
+ */
864
+ const exportDef = defineNode({ kind: "Export" });
865
+ /**
866
+ * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
867
+ *
868
+ * @example Named export
869
+ * ```ts
870
+ * createExport({ name: ['Pet'], path: './Pet' })
871
+ * // export { Pet } from './Pet'
872
+ * ```
873
+ */
874
+ const createExport = exportDef.create;
875
+ /**
876
+ * Definition for the {@link SourceNode}.
877
+ */
878
+ const sourceDef = defineNode({ kind: "Source" });
879
+ /**
880
+ * Creates a `SourceNode` representing a fragment of source code within a file.
881
+ *
882
+ * @example
883
+ * ```ts
884
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
885
+ * ```
886
+ */
887
+ const createSource = sourceDef.create;
888
+ /**
889
+ * Definition for the {@link FileNode}. The fully resolved builder lives in
890
+ * `createFile`, so this definition only supplies the guard.
891
+ */
892
+ const fileDef = defineNode({ kind: "File" });
893
+ //#endregion
894
+ //#region src/nodes/input.ts
895
+ /**
896
+ * Definition for the {@link InputNode}.
897
+ */
898
+ const inputDef = defineNode({
899
+ kind: "Input",
900
+ defaults: {
901
+ schemas: [],
902
+ operations: [],
903
+ meta: {
904
+ circularNames: [],
905
+ enumNames: []
906
+ }
907
+ },
908
+ children: ["schemas", "operations"],
909
+ visitorKey: "input"
910
+ });
911
+ /**
912
+ * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and
913
+ * `operations` are `AsyncIterable` sources and whose `meta` is optional. Otherwise it builds the
914
+ * eager variant with array `schemas`/`operations` and the defaulted `meta`.
915
+ *
916
+ * @example Eager
917
+ * ```ts
918
+ * const input = createInput()
919
+ * // { kind: 'Input', schemas: [], operations: [] }
920
+ * ```
921
+ *
922
+ * @example Streaming
923
+ * ```ts
924
+ * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
925
+ * ```
926
+ */
927
+ function createInput(options = {}) {
928
+ const { stream, ...overrides } = options;
929
+ if (stream) return {
930
+ kind: "Input",
931
+ ...overrides
932
+ };
933
+ return inputDef.create(overrides);
934
+ }
935
+ //#endregion
936
+ //#region src/nodes/requestBody.ts
937
+ /**
938
+ * Definition for the {@link RequestBodyNode}, normalizing each content entry into a `ContentNode`.
939
+ */
940
+ const requestBodyDef = defineNode({
941
+ kind: "RequestBody",
942
+ build: (props) => ({
943
+ ...props,
944
+ content: props.content?.map(createContent)
945
+ }),
946
+ children: ["content"]
947
+ });
948
+ /**
949
+ * Creates a `RequestBodyNode`, normalizing each content entry into a `ContentNode`.
950
+ */
951
+ const createRequestBody = requestBodyDef.create;
952
+ //#endregion
953
+ //#region src/nodes/operation.ts
954
+ /**
955
+ * Definition for the {@link OperationNode}. HTTP operations (those carrying both
956
+ * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
957
+ * normalized into a `RequestBodyNode`.
958
+ */
959
+ const operationDef = defineNode({
960
+ kind: "Operation",
961
+ build: (props) => {
962
+ const { requestBody, ...rest } = props;
963
+ const isHttp = rest.method !== void 0 && rest.path !== void 0;
964
+ return {
965
+ tags: [],
966
+ parameters: [],
967
+ responses: [],
968
+ ...rest,
969
+ ...isHttp ? { protocol: "http" } : {},
970
+ requestBody: requestBody ? createRequestBody(requestBody) : void 0
971
+ };
972
+ },
973
+ children: [
974
+ "parameters",
975
+ "requestBody",
976
+ "responses"
977
+ ],
978
+ visitorKey: "operation"
979
+ });
980
+ function createOperation(props) {
981
+ return operationDef.create(props);
982
+ }
983
+ //#endregion
984
+ //#region src/nodes/output.ts
985
+ /**
986
+ * Definition for the {@link OutputNode}.
987
+ */
988
+ const outputDef = defineNode({
989
+ kind: "Output",
990
+ defaults: { files: [] },
991
+ visitorKey: "output"
992
+ });
993
+ /**
994
+ * Creates an `OutputNode` with a stable default for `files`.
995
+ *
996
+ * @example
997
+ * ```ts
998
+ * const output = createOutput()
999
+ * // { kind: 'Output', files: [] }
1000
+ * ```
1001
+ */
1002
+ function createOutput(overrides = {}) {
1003
+ return outputDef.create(overrides);
1004
+ }
1005
+ //#endregion
1006
+ //#region src/nodes/parameter.ts
1007
+ /**
1008
+ * Definition for the {@link ParameterNode}. `required` defaults to `false` and the
1009
+ * schema's `optional`/`nullish` flags are kept in sync with it.
1010
+ */
1011
+ const parameterDef = defineNode({
1012
+ kind: "Parameter",
1013
+ build: (props) => {
1014
+ const required = props.required ?? false;
1015
+ return {
1016
+ ...props,
1017
+ required,
1018
+ schema: syncOptionality(props.schema, required)
1019
+ };
1020
+ },
1021
+ children: ["schema"],
1022
+ visitorKey: "parameter",
1023
+ rebuild: true
1024
+ });
1025
+ /**
1026
+ * Creates a `ParameterNode`.
1027
+ *
1028
+ * @example
1029
+ * ```ts
1030
+ * const param = createParameter({
1031
+ * name: 'petId',
1032
+ * in: 'path',
1033
+ * required: true,
1034
+ * schema: createSchema({ type: 'string' }),
1035
+ * })
1036
+ * ```
1037
+ */
1038
+ const createParameter = parameterDef.create;
1039
+ //#endregion
1040
+ //#region src/nodes/response.ts
1041
+ /**
1042
+ * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
1043
+ * `mediaType`/`keysToOmit`) is normalized into one `content` entry.
1044
+ */
1045
+ const responseDef = defineNode({
1046
+ kind: "Response",
1047
+ build: (props) => {
1048
+ const { schema, mediaType, keysToOmit, content, ...rest } = props;
1049
+ const entries = content ?? (schema ? [{
1050
+ contentType: mediaType ?? "application/json",
1051
+ schema,
1052
+ keysToOmit: keysToOmit ?? null
1053
+ }] : void 0);
1054
+ return {
1055
+ ...rest,
1056
+ content: entries?.map(createContent)
1057
+ };
1058
+ },
1059
+ children: ["content"],
1060
+ visitorKey: "response"
1061
+ });
1062
+ /**
1063
+ * Creates a `ResponseNode`.
1064
+ *
1065
+ * @example
1066
+ * ```ts
1067
+ * const response = createResponse({
1068
+ * statusCode: '200',
1069
+ * content: [{ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) }],
1070
+ * })
1071
+ * ```
1072
+ */
1073
+ const createResponse = responseDef.create;
1074
+ //#endregion
1075
+ //#region src/registry.ts
1076
+ /**
1077
+ * Every node definition. Adding a node means adding its `defineNode` to one
1078
+ * `nodes/*.ts` file and listing it here. The visitor tables below derive from it.
1079
+ */
1080
+ const nodeDefs = [
1081
+ inputDef,
1082
+ outputDef,
1083
+ operationDef,
1084
+ requestBodyDef,
1085
+ contentDef,
1086
+ responseDef,
1087
+ schemaDef,
1088
+ propertyDef,
1089
+ parameterDef,
1090
+ functionParameterDef,
1091
+ functionParametersDef,
1092
+ typeLiteralDef,
1093
+ indexedAccessTypeDef,
1094
+ objectBindingPatternDef,
1095
+ constDef,
1096
+ typeDef,
1097
+ functionDef,
1098
+ arrowFunctionDef,
1099
+ textDef,
1100
+ breakDef,
1101
+ jsxDef,
1102
+ importDef,
1103
+ exportDef,
1104
+ sourceDef,
1105
+ fileDef
1106
+ ];
1107
+ /**
1108
+ * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).
1109
+ * Derived from each definition's `children`.
1110
+ */
1111
+ const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : []));
1112
+ /**
1113
+ * Maps a node kind to the matching visitor callback name. Derived from each
1114
+ * definition's `visitorKey`.
1115
+ */
1116
+ const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : []));
1117
+ /**
1118
+ * Per-kind builders rerun after children are rebuilt. Derived from each
1119
+ * definition's `rebuild` flag.
1120
+ */
1121
+ const nodeRebuilders = Object.fromEntries(nodeDefs.flatMap((def) => def.rebuild ? [[def.kind, def.create]] : []));
1122
+ //#endregion
1123
+ //#region src/visitor.ts
1124
+ /**
1125
+ * Creates a small async concurrency limiter.
1126
+ *
1127
+ * At most `concurrency` tasks are in flight at once. Extra tasks are queued.
1128
+ *
1129
+ * @example
1130
+ * ```ts
1131
+ * const limit = createLimit(2)
1132
+ * for (const task of [taskA, taskB, taskC]) {
1133
+ * await limit(() => task())
1134
+ * }
1135
+ * // only 2 tasks run at the same time
1136
+ * ```
1137
+ */
1138
+ function createLimit(concurrency) {
1139
+ let active = 0;
1140
+ const queue = [];
1141
+ function next() {
1142
+ if (active < concurrency && queue.length > 0) {
1143
+ active++;
1144
+ queue.shift()();
1145
+ }
1146
+ }
1147
+ return function limit(fn) {
1148
+ return new Promise((resolve, reject) => {
1149
+ queue.push(() => {
1150
+ Promise.resolve(fn()).then(resolve, reject).finally(() => {
1151
+ active--;
1152
+ next();
1153
+ });
1154
+ });
1155
+ next();
1156
+ });
1157
+ };
1158
+ }
1159
+ const visitorKeysByKind = VISITOR_KEYS;
1160
+ /**
1161
+ * Returns `true` when `value` is an AST node (an object carrying a `kind`).
1162
+ */
1163
+ function isNode(value) {
1164
+ return typeof value === "object" && value !== null && "kind" in value;
1165
+ }
1166
+ /**
1167
+ * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.
1168
+ *
1169
+ * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.
1170
+ *
1171
+ * @example
1172
+ * ```ts
1173
+ * const children = getChildren(operationNode, true)
1174
+ * // returns parameters, the request body, and responses
1175
+ * ```
1176
+ */
1177
+ function* getChildren(node, recurse) {
1178
+ if (node.kind === "Schema" && !recurse) return;
1179
+ const keys = visitorKeysByKind[node.kind];
1180
+ if (!keys) return;
1181
+ const record = node;
1182
+ for (const key of keys) {
1183
+ const value = record[key];
1184
+ if (Array.isArray(value)) {
1185
+ for (const item of value) if (isNode(item)) yield item;
1186
+ } else if (isNode(value)) yield value;
1187
+ }
1188
+ }
1189
+ /**
1190
+ * Invokes the visitor callback that matches `node.kind`, passing the traversal
1191
+ * context. Returns the callback's result (a replacement node, a collected
1192
+ * value, or `undefined` when no callback is registered for the kind).
1193
+ *
1194
+ * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives
1195
+ * in one place. `TResult` is the caller's expected return: the same node type
1196
+ * for `transform`, the collected value type for `collectLazy`, ignored for `walk`.
1197
+ */
1198
+ function applyVisitor(node, visitor, parent) {
1199
+ const key = VISITOR_KEY_BY_KIND[node.kind];
1200
+ if (!key) return void 0;
1201
+ const fn = visitor[key];
1202
+ return fn?.(node, { parent });
1203
+ }
1204
+ /**
1205
+ * Async depth-first traversal for side effects. Visitor return values are
1206
+ * ignored. Use `transform` when you want to rewrite nodes.
1207
+ *
1208
+ * Sibling nodes at each depth run concurrently up to `options.concurrency`
1209
+ * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
1210
+ * work. Lower values reduce memory pressure.
1211
+ *
1212
+ * @example Log every operation
1213
+ * ```ts
1214
+ * await walk(root, {
1215
+ * operation(node) {
1216
+ * console.log(node.operationId)
1217
+ * },
1218
+ * })
1219
+ * ```
1220
+ *
1221
+ * @example Only visit the root node
1222
+ * ```ts
1223
+ * await walk(root, { depth: 'shallow', input: () => {} })
1224
+ * ```
1225
+ */
1226
+ async function walk(node, options) {
1227
+ return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0);
1228
+ }
1229
+ async function _walk(node, visitor, recurse, limit, parent) {
1230
+ await limit(() => applyVisitor(node, visitor, parent));
1231
+ const children = Array.from(getChildren(node, recurse));
1232
+ if (children.length === 0) return;
1233
+ await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)));
1234
+ }
1235
+ function transform(node, options) {
1236
+ const { depth, parent, ...visitor } = options;
1237
+ const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
1238
+ const rebuilt = transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse);
1239
+ if (rebuilt === node) return node;
1240
+ const rebuild = nodeRebuilders[rebuilt.kind];
1241
+ return rebuild ? rebuild(rebuilt) : rebuilt;
1242
+ }
1243
+ /**
1244
+ * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming
1245
+ * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact.
1246
+ * `Schema` children are skipped in shallow mode.
1247
+ */
1248
+ function transformChildren(node, options, recurse) {
1249
+ if (node.kind === "Schema" && !recurse) return node;
1250
+ const keys = visitorKeysByKind[node.kind];
1251
+ if (!keys) return node;
1252
+ const record = node;
1253
+ const childOptions = {
1254
+ ...options,
1255
+ parent: node
1256
+ };
1257
+ let updates;
1258
+ for (const key of keys) {
1259
+ if (!(key in record)) continue;
1260
+ const value = record[key];
1261
+ if (Array.isArray(value)) {
1262
+ let changed = false;
1263
+ const mapped = value.map((item) => {
1264
+ if (!isNode(item)) return item;
1265
+ const next = transform(item, childOptions);
1266
+ if (next !== item) changed = true;
1267
+ return next;
1268
+ });
1269
+ if (changed) (updates ??= {})[key] = mapped;
1270
+ } else if (isNode(value)) {
1271
+ const next = transform(value, childOptions);
1272
+ if (next !== value) (updates ??= {})[key] = next;
1273
+ }
1274
+ }
1275
+ return updates ? {
1276
+ ...node,
1277
+ ...updates
1278
+ } : node;
1279
+ }
1280
+ /**
1281
+ * Lazy depth-first collection pass. Yields every non-null value returned by
1282
+ * the visitor callbacks. Use `collect` for the eager array form.
1283
+ *
1284
+ * @example Collect every operationId
1285
+ * ```ts
1286
+ * const ids: string[] = []
1287
+ * for (const id of collectLazy<string>(root, {
1288
+ * operation(node) {
1289
+ * return node.operationId
1290
+ * },
1291
+ * })) {
1292
+ * ids.push(id)
1293
+ * }
1294
+ * ```
1295
+ */
1296
+ function* collectLazy(node, options) {
1297
+ const { depth, parent, ...visitor } = options;
1298
+ const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
1299
+ const v = applyVisitor(node, visitor, parent);
1300
+ if (v != null) yield v;
1301
+ for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
1302
+ ...options,
1303
+ parent: node
1304
+ });
1305
+ }
1306
+ /**
1307
+ * Eager depth-first collection pass. Returns an array of every non-null value
1308
+ * the visitor callbacks return.
1309
+ *
1310
+ * @example Collect every operationId
1311
+ * ```ts
1312
+ * const ids = collect<string>(root, {
1313
+ * operation(node) {
1314
+ * return node.operationId
1315
+ * },
1316
+ * })
1317
+ * ```
1318
+ */
1319
+ function collect(node, options) {
1320
+ return Array.from(collectLazy(node, options));
1321
+ }
1322
+ //#endregion
1323
+ //#region src/utils/ast.ts
1324
+ const plainStringTypes = new Set([
1325
+ "string",
1326
+ "uuid",
1327
+ "email",
1328
+ "url",
1329
+ "datetime"
1330
+ ]);
1331
+ /**
1332
+ * Merges a ref node with its resolved schema, giving usage-site fields precedence.
1333
+ *
1334
+ * Usage-site fields (`description`, `readOnly`, `nullable`, `deprecated`) on the ref node
1335
+ * override the same fields in the resolved `node.schema`. Non-ref nodes are returned unchanged.
1336
+ *
1337
+ * @example
1338
+ * ```ts
1339
+ * // Ref with description override
1340
+ * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
1341
+ * const merged = syncSchemaRef(ref) // merges with resolved Pet schema
1342
+ * ```
1343
+ */
1344
+ function syncSchemaRef(node) {
1345
+ const ref = narrowSchema(node, "ref");
1346
+ if (!ref) return node;
1347
+ if (!ref.schema) return node;
1348
+ const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
1349
+ const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
1350
+ return createSchema({
1351
+ ...ref.schema,
1352
+ ...definedOverrides
1353
+ });
1354
+ }
1355
+ /**
1356
+ * Type guard that returns `true` when a schema emits as a plain `string` type.
1357
+ *
1358
+ * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
1359
+ * types, returns `true` only when `representation` is `'string'` rather than `'date'`.
1360
+ */
1361
+ function isStringType(node) {
1362
+ if (plainStringTypes.has(node.type)) return true;
1363
+ const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
1364
+ if (temporal) return temporal.representation !== "date";
1365
+ return false;
1366
+ }
1367
+ /**
1368
+ * Applies casing rules to parameter names and returns a new parameter array.
1369
+ *
1370
+ * Use this before passing parameters to schema builders so output property keys match
1371
+ * the desired casing while preserving `OperationNode.parameters` for other consumers.
1372
+ * The input array is not mutated. When `casing` is not set, the original array is returned unchanged.
1373
+ */
1374
+ const caseParamsMemo = memoize(/* @__PURE__ */ new WeakMap(), (params) => memoize(/* @__PURE__ */ new Map(), (casing) => params.map((param) => {
1375
+ const transformed = casing === "camelcase" || !isValidVarName(param.name) ? camelCase(param.name) : param.name;
1376
+ return {
1377
+ ...param,
1378
+ name: transformed
1379
+ };
1380
+ })));
1381
+ function caseParams(params, casing) {
1382
+ if (!casing) return params;
1383
+ return caseParamsMemo(params)(casing);
1384
+ }
1385
+ /**
1386
+ * Creates a single-property object schema used as a discriminator literal.
1387
+ *
1388
+ * @example
1389
+ * ```ts
1390
+ * createDiscriminantNode({ propertyName: 'type', value: 'dog' })
1391
+ * // -> { type: 'object', properties: [{ name: 'type', required: true, schema: enum('dog') }] }
1392
+ * ```
1393
+ */
1394
+ function createDiscriminantNode({ propertyName, value }) {
1395
+ return createSchema({
1396
+ type: "object",
1397
+ primitive: "object",
1398
+ properties: [createProperty({
1399
+ name: propertyName,
1400
+ schema: createSchema({
1401
+ type: "enum",
1402
+ primitive: "string",
1403
+ enumValues: [value]
1404
+ }),
1405
+ required: true
1406
+ })]
1407
+ });
1408
+ }
1409
+ /**
1410
+ * Resolves the {@link TypeExpression} for an individual parameter.
1411
+ *
1412
+ * Without a resolver, falls back to the schema primitive (a plain type-name string).
1413
+ * When the parameter belongs to a named group, emits an {@link IndexedAccessTypeNode}
1414
+ * (`GroupParams['petId']`); otherwise the resolved individual name as a plain string.
1415
+ */
1416
+ function resolveParamType({ node, param, resolver }) {
1417
+ if (!resolver) return param.schema.primitive ?? "unknown";
1418
+ const individualName = resolver.resolveParamName(node, param);
1419
+ const groupLocation = param.in === "path" || param.in === "query" || param.in === "header" ? param.in : void 0;
1420
+ const groupResolvers = {
1421
+ path: resolver.resolvePathParamsName,
1422
+ query: resolver.resolveQueryParamsName,
1423
+ header: resolver.resolveHeaderParamsName
1424
+ };
1425
+ const groupName = groupLocation ? groupResolvers[groupLocation].call(resolver, node, param) : void 0;
1426
+ if (groupName && groupName !== individualName) return createIndexedAccessType({
1427
+ objectType: groupName,
1428
+ indexType: param.name
1429
+ });
1430
+ return individualName;
1431
+ }
1432
+ /**
1433
+ * Converts an `OperationNode` into function parameters for code generation.
1434
+ *
1435
+ * Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one
1436
+ * destructured object parameter (`object`) and separate top-level parameters (`inline`), while
1437
+ * `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type
1438
+ * name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.
1439
+ */
1440
+ function createOperationParams(node, options) {
1441
+ const { paramsType, pathParamsType, paramsCasing, resolver, pathParamsDefault, extraParams = [], paramNames, typeWrapper } = options;
1442
+ const dataName = paramNames?.data ?? "data";
1443
+ const paramsName = paramNames?.params ?? "params";
1444
+ const headersName = paramNames?.headers ?? "headers";
1445
+ const pathName = paramNames?.path ?? "pathParams";
1446
+ const wrapType = (type) => typeWrapper ? typeWrapper(type) : type;
1447
+ const wrapTypeExpression = (type) => typeof type === "string" ? wrapType(type) : type;
1448
+ const casedParams = caseParams(node.parameters, paramsCasing);
1449
+ const pathParams = casedParams.filter((p) => p.in === "path");
1450
+ const queryParams = casedParams.filter((p) => p.in === "query");
1451
+ const headerParams = casedParams.filter((p) => p.in === "header");
1452
+ const toProperty = (param) => ({
1453
+ name: param.name,
1454
+ type: wrapTypeExpression(resolveParamType({
1455
+ node,
1456
+ param,
1457
+ resolver
1458
+ })),
1459
+ optional: !param.required
1460
+ });
1461
+ const emptyObjectDefault = (props) => props.every((p) => p.optional) ? "{}" : void 0;
1462
+ const bodyType = node.requestBody?.content?.[0]?.schema ? wrapType(resolver?.resolveDataName(node) ?? "unknown") : void 0;
1463
+ const bodyProperty = bodyType ? [{
1464
+ name: dataName,
1465
+ type: bodyType,
1466
+ optional: !(node.requestBody?.required ?? false)
1467
+ }] : [];
1468
+ const trailingGroups = [{
1469
+ name: paramsName,
1470
+ node,
1471
+ params: queryParams,
1472
+ groupType: resolveGroupType({
1473
+ node,
1474
+ params: queryParams,
1475
+ group: "query",
1476
+ resolver
1477
+ }),
1478
+ resolver,
1479
+ wrapType
1480
+ }, {
1481
+ name: headersName,
1482
+ node,
1483
+ params: headerParams,
1484
+ groupType: resolveGroupType({
1485
+ node,
1486
+ params: headerParams,
1487
+ group: "header",
1488
+ resolver
1489
+ }),
1490
+ resolver,
1491
+ wrapType
1492
+ }];
1493
+ const params = [];
1494
+ if (paramsType === "object") {
1495
+ const children = [
1496
+ ...pathParams.map(toProperty),
1497
+ ...bodyProperty,
1498
+ ...trailingGroups.flatMap(buildGroupProperty)
1499
+ ];
1500
+ if (children.length) params.push(createFunctionParameter({
1501
+ properties: children,
1502
+ default: emptyObjectDefault(children)
1503
+ }));
1504
+ } else {
1505
+ if (pathParamsType === "inlineSpread" && pathParams.length) {
1506
+ const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]);
1507
+ params.push(createFunctionParameter({
1508
+ name: pathName,
1509
+ type: spreadType ? wrapType(spreadType) : void 0,
1510
+ rest: true
1511
+ }));
1512
+ } else if (pathParamsType === "inline") params.push(...pathParams.map((p) => createFunctionParameter(toProperty(p))));
1513
+ else if (pathParams.length) {
1514
+ const pathChildren = pathParams.map(toProperty);
1515
+ params.push(createFunctionParameter({
1516
+ properties: pathChildren,
1517
+ default: pathParamsDefault ?? emptyObjectDefault(pathChildren)
1518
+ }));
1519
+ }
1520
+ params.push(...bodyProperty.map((p) => createFunctionParameter(p)));
1521
+ params.push(...trailingGroups.flatMap(buildGroupParam));
1522
+ }
1523
+ params.push(...extraParams);
1524
+ return createFunctionParameters({ params });
1525
+ }
1526
+ /**
1527
+ * Builds the property descriptor for a query or header group.
1528
+ * Returns an empty array when there are no params to emit.
1529
+ *
1530
+ * A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline
1531
+ * {@link TypeLiteralNode} from the individual params.
1532
+ */
1533
+ function buildGroupProperty({ name, node, params, groupType, resolver, wrapType }) {
1534
+ if (groupType) return [{
1535
+ name,
1536
+ type: typeof groupType.type === "string" ? wrapType(groupType.type) : groupType.type,
1537
+ optional: groupType.optional
1538
+ }];
1539
+ if (params.length) return [{
1540
+ name,
1541
+ type: buildTypeLiteral({
1542
+ node,
1543
+ params,
1544
+ resolver
1545
+ }),
1546
+ optional: params.every((p) => !p.required)
1547
+ }];
1548
+ return [];
1549
+ }
1550
+ /**
1551
+ * Builds a single {@link FunctionParameterNode} for a query or header group.
1552
+ * Returns an empty array when there are no params to emit.
1553
+ *
1554
+ * A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline
1555
+ * {@link TypeLiteralNode} from the individual params.
1556
+ */
1557
+ function buildGroupParam(args) {
1558
+ return buildGroupProperty(args).map((p) => createFunctionParameter(p));
1559
+ }
1560
+ /**
1561
+ * Builds a {@link TypeLiteralNode} for an inline anonymous type grouping named fields.
1562
+ *
1563
+ * Used when query or header parameters have no dedicated group type name.
1564
+ * Each language printer renders this appropriately (TypeScript: `{ petId: string; name?: string }`).
1565
+ */
1566
+ function buildTypeLiteral({ node, params, resolver }) {
1567
+ return createTypeLiteral({ members: params.map((p) => ({
1568
+ name: p.name,
1569
+ type: resolveParamType({
1570
+ node,
1571
+ param: p,
1572
+ resolver
1573
+ }),
1574
+ optional: !p.required
1575
+ })) });
1576
+ }
1577
+ function sourceKey(source) {
1578
+ return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`;
1579
+ }
1580
+ function pathTypeKey(path, isTypeOnly) {
1581
+ return `${path}:${isTypeOnly ?? false}`;
1582
+ }
1583
+ function exportKey(path, name, isTypeOnly, asAlias) {
1584
+ return `${path}:${name ?? ""}:${isTypeOnly ?? false}:${asAlias ?? ""}`;
1585
+ }
1586
+ function importKey(path, name, isTypeOnly) {
1587
+ return `${path}:${name ?? ""}:${isTypeOnly ?? false}`;
1588
+ }
1589
+ /**
1590
+ * Computes a multi-level sort key for exports and imports:
1591
+ * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named.
1592
+ */
1593
+ function sortKey(node) {
1594
+ const isArray = Array.isArray(node.name) ? "1" : "0";
1595
+ const typeOnly = node.isTypeOnly ? "0" : "1";
1596
+ const hasName = node.name != null ? "1" : "0";
1597
+ const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? "";
1598
+ return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`;
1599
+ }
1600
+ /**
1601
+ * Deduplicates and merges `SourceNode` objects by `name + isExportable + isTypeOnly`.
1602
+ *
1603
+ * Unnamed sources are deduplicated by object reference. Returns a deduplicated array in original order.
1604
+ */
1605
+ function combineSources(sources) {
1606
+ const seen = /* @__PURE__ */ new Map();
1607
+ for (const source of sources) {
1608
+ const key = sourceKey(source);
1609
+ if (!seen.has(key)) seen.set(key, source);
1610
+ }
1611
+ return [...seen.values()];
1612
+ }
1613
+ /**
1614
+ * Merges `incoming` names into `existing`, preserving order and dropping duplicates.
1615
+ *
1616
+ * Shared by `combineExports` and `combineImports` for the same-path name-merge case.
1617
+ */
1618
+ function mergeNameArrays(existing, incoming) {
1619
+ const merged = new Set(existing);
1620
+ for (const name of incoming) merged.add(name);
1621
+ return [...merged];
1622
+ }
1623
+ /**
1624
+ * Deduplicates and merges `ExportNode` objects by path and type.
1625
+ *
1626
+ * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export.
1627
+ * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array.
1628
+ */
1629
+ function combineExports(exports) {
1630
+ const result = [];
1631
+ const namedByPath = /* @__PURE__ */ new Map();
1632
+ const seen = /* @__PURE__ */ new Set();
1633
+ const keyed = exports.map((node) => ({
1634
+ node,
1635
+ key: sortKey(node)
1636
+ }));
1637
+ keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
1638
+ for (const { node: curr } of keyed) {
1639
+ const { name, path, isTypeOnly, asAlias } = curr;
1640
+ if (Array.isArray(name)) {
1641
+ if (!name.length) continue;
1642
+ const key = pathTypeKey(path, isTypeOnly);
1643
+ const existing = namedByPath.get(key);
1644
+ if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name);
1645
+ else {
1646
+ const newItem = {
1647
+ ...curr,
1648
+ name: [...new Set(name)]
1649
+ };
1650
+ result.push(newItem);
1651
+ namedByPath.set(key, newItem);
1652
+ }
1653
+ } else {
1654
+ const key = exportKey(path, name, isTypeOnly, asAlias);
1655
+ if (!seen.has(key)) {
1656
+ result.push(curr);
1657
+ seen.add(key);
1658
+ }
1659
+ }
1660
+ }
1661
+ return result;
1662
+ }
1663
+ /**
1664
+ * Deduplicates and merges `ImportNode` objects, filtering out unused imports.
1665
+ *
1666
+ * Retains imports that are referenced in `source` or re-exported. Imports with the same path and
1667
+ * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array.
1668
+ *
1669
+ * @note Use this when combining imports from multiple files to avoid duplicate declarations.
1670
+ */
1671
+ function combineImports(imports, exports, source) {
1672
+ const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : []));
1673
+ const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName);
1674
+ const importNameMemo = /* @__PURE__ */ new Map();
1675
+ const canonicalizeName = (n) => {
1676
+ if (typeof n === "string") return n;
1677
+ const key = `${n.propertyName}:${n.name ?? ""}`;
1678
+ if (!importNameMemo.has(key)) importNameMemo.set(key, n);
1679
+ return importNameMemo.get(key);
1680
+ };
1681
+ const pathsWithUsedNamedImport = /* @__PURE__ */ new Set();
1682
+ for (const node of imports) {
1683
+ if (!Array.isArray(node.name)) continue;
1684
+ if (node.name.some((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName))) pathsWithUsedNamedImport.add(node.path);
1685
+ }
1686
+ const result = [];
1687
+ const namedByPath = /* @__PURE__ */ new Map();
1688
+ const seen = /* @__PURE__ */ new Set();
1689
+ const keyed = imports.map((node) => ({
1690
+ node,
1691
+ key: sortKey(node)
1692
+ }));
1693
+ keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
1694
+ for (const { node: curr } of keyed) {
1695
+ if (curr.path === curr.root) continue;
1696
+ const { path, isTypeOnly } = curr;
1697
+ let { name } = curr;
1698
+ if (Array.isArray(name)) {
1699
+ name = [...new Set(name.map(canonicalizeName))].filter((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName));
1700
+ if (!name.length) continue;
1701
+ const key = pathTypeKey(path, isTypeOnly);
1702
+ const existing = namedByPath.get(key);
1703
+ if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name);
1704
+ else {
1705
+ const newItem = {
1706
+ ...curr,
1707
+ name
1708
+ };
1709
+ result.push(newItem);
1710
+ namedByPath.set(key, newItem);
1711
+ }
1712
+ } else {
1713
+ if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue;
1714
+ const key = importKey(path, name, isTypeOnly);
1715
+ if (!seen.has(key)) {
1716
+ result.push(curr);
1717
+ seen.add(key);
1718
+ }
1719
+ }
1720
+ }
1721
+ return result;
1722
+ }
1723
+ /**
1724
+ * Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
1725
+ *
1726
+ * Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's
1727
+ * identifier for type definitions or error messages.
1728
+ *
1729
+ * @example
1730
+ * ```ts
1731
+ * resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })
1732
+ * // => 'Pet'
1733
+ * ```
1734
+ */
1735
+ function resolveRefName(node) {
1736
+ if (!node || node.type !== "ref") return null;
1737
+ if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
1738
+ return node.name ?? node.schema?.name ?? null;
1739
+ }
1740
+ /**
1741
+ * Collects every named schema referenced (transitively) from a node via ref edges.
1742
+ *
1743
+ * Refs are followed by name only, the resolved `node.schema` is not traversed inline.
1744
+ * Use this to determine schema dependencies, build reference graphs, or detect what schemas need to be emitted.
1745
+ *
1746
+ * @example Collect refs from a single schema
1747
+ * ```ts
1748
+ * const names = collectReferencedSchemaNames(petSchema)
1749
+ * // → Set { 'Category', 'Tag' }
1750
+ * ```
1751
+ *
1752
+ * @example Accumulate refs from multiple schemas into one set
1753
+ * ```ts
1754
+ * const out = new Set<string>()
1755
+ * for (const schema of schemas) {
1756
+ * collectReferencedSchemaNames(schema, out)
1757
+ * }
1758
+ * ```
1759
+ */
1760
+ const collectSchemaRefs = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
1761
+ const refs = /* @__PURE__ */ new Set();
1762
+ collect(node, { schema(child) {
1763
+ if (child.type === "ref") {
1764
+ const name = resolveRefName(child);
1765
+ if (name) refs.add(name);
1766
+ }
1767
+ } });
1768
+ return refs;
1769
+ });
1770
+ function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
1771
+ if (!node) return out;
1772
+ for (const name of collectSchemaRefs(node)) out.add(name);
1773
+ return out;
1774
+ }
1775
+ /**
1776
+ * Collects the names of all top-level schemas transitively used by a set of operations.
1777
+ *
1778
+ * An operation uses a schema when any of its parameters, request body content, or responses
1779
+ * reference it, directly or indirectly through other named schemas.
1780
+ * The walk is iterative and safe against reference cycles.
1781
+ *
1782
+ * Use this together with `include` filters to determine which schemas from `components/schemas`
1783
+ * are reachable from the allowed operations, so that schemas used only by excluded operations
1784
+ * are not generated.
1785
+ *
1786
+ * @example Only generate schemas referenced by included operations
1787
+ * ```ts
1788
+ * const includedOps = operations.filter(op => resolver.resolveOptions(op, { options, include }) !== null)
1789
+ * const allowed = collectUsedSchemaNames(includedOps, schemas)
1790
+ *
1791
+ * for (const schema of schemas) {
1792
+ * if (schema.name && !allowed.has(schema.name)) continue
1793
+ * // … generate schema
1794
+ * }
1795
+ * ```
1796
+ *
1797
+ * @example Check whether a specific schema is needed
1798
+ * ```ts
1799
+ * const allowed = collectUsedSchemaNames(includedOps, schemas)
1800
+ * allowed.has('OrderStatus') // false when no included operation references OrderStatus
1801
+ * ```
1802
+ */
1803
+ const collectUsedSchemaNamesMemo = memoize(/* @__PURE__ */ new WeakMap(), (ops) => memoize(/* @__PURE__ */ new WeakMap(), (schemas) => computeUsedSchemaNames(ops, schemas)));
1804
+ function computeUsedSchemaNames(operations, schemas) {
1805
+ const schemaMap = /* @__PURE__ */ new Map();
1806
+ for (const schema of schemas) if (schema.name) schemaMap.set(schema.name, schema);
1807
+ const result = /* @__PURE__ */ new Set();
1808
+ function visitSchema(schema) {
1809
+ const directRefs = collectReferencedSchemaNames(schema);
1810
+ for (const name of directRefs) if (!result.has(name)) {
1811
+ result.add(name);
1812
+ const namedSchema = schemaMap.get(name);
1813
+ if (namedSchema) visitSchema(namedSchema);
1814
+ }
1815
+ }
1816
+ for (const op of operations) for (const schema of collectLazy(op, {
1817
+ depth: "shallow",
1818
+ schema: (node) => node
1819
+ })) visitSchema(schema);
1820
+ return result;
1821
+ }
1822
+ function collectUsedSchemaNames(operations, schemas) {
1823
+ return collectUsedSchemaNamesMemo(operations)(schemas);
1824
+ }
1825
+ const EMPTY_CIRCULAR_SET = /* @__PURE__ */ new Set();
1826
+ const findCircularSchemasMemo = memoize(/* @__PURE__ */ new WeakMap(), (schemas) => {
1827
+ const graph = /* @__PURE__ */ new Map();
1828
+ for (const schema of schemas) {
1829
+ if (!schema.name) continue;
1830
+ graph.set(schema.name, collectReferencedSchemaNames(schema));
1831
+ }
1832
+ const circular = /* @__PURE__ */ new Set();
1833
+ for (const start of graph.keys()) {
1834
+ const visited = /* @__PURE__ */ new Set();
1835
+ const stack = [...graph.get(start) ?? []];
1836
+ while (stack.length > 0) {
1837
+ const node = stack.pop();
1838
+ if (node === start) {
1839
+ circular.add(start);
1840
+ break;
1841
+ }
1842
+ if (visited.has(node)) continue;
1843
+ visited.add(node);
1844
+ const next = graph.get(node);
1845
+ if (next) for (const r of next) stack.push(r);
1846
+ }
1847
+ }
1848
+ return circular;
1849
+ });
1850
+ /**
1851
+ * Identifies all schemas that participate in circular dependency chains, including direct self-loops.
1852
+ *
1853
+ * Returns a Set of schema names with circular dependencies. Use this to wrap recursive schema positions
1854
+ * in deferred constructs (lazy getter, `z.lazy(() => …)`) to prevent infinite recursion when generated code runs.
1855
+ * Refs are followed by name only, keeping the algorithm linear in the schema graph size.
1856
+ *
1857
+ * @note Call this once on the full schema graph, then use `containsCircularRef()` to check individual schemas.
1858
+ */
1859
+ function findCircularSchemas(schemas) {
1860
+ if (schemas.length === 0) return EMPTY_CIRCULAR_SET;
1861
+ return findCircularSchemasMemo(schemas);
1862
+ }
1863
+ /**
1864
+ * Type guard returning `true` when a schema or anything nested within it contains a ref to a circular schema.
1865
+ *
1866
+ * Use `excludeName` to ignore refs to specific schemas (useful when self-references are handled separately).
1867
+ * Commonly used with `findCircularSchemas()` to detect where lazy wrappers are needed in code generation.
1868
+ *
1869
+ * @note Returns `true` for the first matching circular ref found. Use for fast dependency checks.
1870
+ */
1871
+ function containsCircularRef(node, { circularSchemas, excludeName }) {
1872
+ if (!node || circularSchemas.size === 0) return false;
1873
+ for (const _ of collectLazy(node, { schema(child) {
1874
+ if (child.type !== "ref") return null;
1875
+ const name = resolveRefName(child);
1876
+ return name && name !== excludeName && circularSchemas.has(name) ? true : null;
1877
+ } })) return true;
1878
+ return false;
1879
+ }
1880
+ //#endregion
1881
+ //#region src/utils/index.ts
1882
+ /**
1883
+ * Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
1884
+ * Returns the string unchanged when no balanced quote pair is found.
1885
+ *
1886
+ * @example
1887
+ * ```ts
1888
+ * trimQuotes('"hello"') // 'hello'
1889
+ * trimQuotes('hello') // 'hello'
1890
+ * ```
1891
+ */
1892
+ function trimQuotes(text) {
1893
+ if (text.length >= 2) {
1894
+ const first = text[0];
1895
+ const last = text[text.length - 1];
1896
+ if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
1897
+ }
1898
+ return text;
1899
+ }
1900
+ /**
1901
+ * Serializes a primitive value to a single-quoted string literal, stripping any surrounding quote
1902
+ * characters first. Escaping comes from `JSON.stringify`, then the quote style switches to single
1903
+ * quotes so generated code matches the repo style without a formatter.
1904
+ *
1905
+ * @example
1906
+ * ```ts
1907
+ * stringify('hello') // "'hello'"
1908
+ * stringify('"hello"') // "'hello'"
1909
+ * ```
1910
+ */
1911
+ function stringify(value) {
1912
+ if (value === void 0 || value === null) return "''";
1913
+ return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
1914
+ }
1915
+ /**
1916
+ * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,
1917
+ * and the Unicode line terminators U+2028 and U+2029.
1918
+ *
1919
+ * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
1920
+ *
1921
+ * @example
1922
+ * ```ts
1923
+ * jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
1924
+ * ```
1925
+ */
1926
+ function jsStringEscape(input) {
1927
+ return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
1928
+ switch (character) {
1929
+ case "\"":
1930
+ case "'":
1931
+ case "\\": return `\\${character}`;
1932
+ case "\n": return "\\n";
1933
+ case "\r": return "\\r";
1934
+ case "\u2028": return "\\u2028";
1935
+ case "\u2029": return "\\u2029";
1936
+ default: return "";
1937
+ }
1938
+ });
1939
+ }
1940
+ /**
1941
+ * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
1942
+ * Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.
1943
+ * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.
1944
+ *
1945
+ * @example
1946
+ * ```ts
1947
+ * toRegExpString('^(?im)foo') // 'new RegExp("^foo", "im")'
1948
+ * toRegExpString('^(?im)foo', null) // '/^foo/im'
1949
+ * ```
1950
+ */
1951
+ function toRegExpString(text, func = "RegExp") {
1952
+ const raw = trimQuotes(text);
1953
+ const match = raw.match(/^\^(\(\?([igmsuy]+)\))/i);
1954
+ const replacementTarget = match?.[1] ?? "";
1955
+ const matchedFlags = match?.[2];
1956
+ const cleaned = raw.replace(/^\\?\//, "").replace(/\\?\/$/, "").replace(replacementTarget, "");
1957
+ const { source, flags } = new RegExp(cleaned, matchedFlags);
1958
+ if (func === null) return `/${source}/${flags}`;
1959
+ return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ""})`;
1960
+ }
1961
+ /**
1962
+ * Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested
1963
+ * objects recurse with fixed indentation, so the result drops straight into an object literal
1964
+ * without re-parsing.
1965
+ *
1966
+ * @example
1967
+ * ```ts
1968
+ * stringifyObject({ foo: 'bar', nested: { a: 1 } })
1969
+ * // 'foo: bar,\nnested: {\n a: 1\n }'
1970
+ * ```
1971
+ */
1972
+ function stringifyObject(value) {
1973
+ return Object.entries(value).map(([key, val]) => {
1974
+ if (val !== null && typeof val === "object") return `${key}: {\n ${stringifyObject(val)}\n }`;
1975
+ return `${key}: ${val}`;
1976
+ }).filter(Boolean).join(",\n");
1977
+ }
1978
+ /**
1979
+ * Renders a dotted path or string array as an optional-chaining accessor expression rooted at
1980
+ * `accessor`. Returns `null` for an empty path.
1981
+ *
1982
+ * @example
1983
+ * ```ts
1984
+ * getNestedAccessor('pagination.next.id', 'lastPage')
1985
+ * // "lastPage?.['pagination']?.['next']?.['id']"
1986
+ * ```
1987
+ */
1988
+ function getNestedAccessor(param, accessor) {
1989
+ const parts = Array.isArray(param) ? param : param.split(".");
1990
+ if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
1991
+ return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
1992
+ }
1993
+ /**
1994
+ * Builds a JSDoc comment block from an array of lines, returning `fallback` when there are no
1995
+ * comments so callers always get a usable string.
1996
+ *
1997
+ * @example
1998
+ * ```ts
1999
+ * buildJSDoc(['@type string', '@example hello'])
2000
+ * // '/**\n * @type string\n * @example hello\n *\/\n '
2001
+ * ```
2002
+ */
2003
+ function buildJSDoc(comments, options = {}) {
2004
+ const { indent = " * ", suffix = "\n ", fallback = " " } = options;
2005
+ if (comments.length === 0) return fallback;
2006
+ return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
2007
+ }
2008
+ /**
2009
+ * Indents every non-empty line of `text` by one indent level, leaving blank lines empty.
2010
+ */
2011
+ function indentLines(text) {
2012
+ if (!text) return "";
2013
+ return text.split("\n").map((line) => line.trim() ? `${INDENT}${line}` : "").join("\n");
2014
+ }
2015
+ /**
2016
+ * Renders an object key, quoting it with single quotes only when it is not a valid identifier.
2017
+ * Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.
2018
+ *
2019
+ * @example
2020
+ * ```ts
2021
+ * objectKey('name') // 'name'
2022
+ * objectKey('x-total') // "'x-total'"
2023
+ * ```
2024
+ */
2025
+ function objectKey(name) {
2026
+ return isIdentifier(name) ? name : singleQuote(name);
2027
+ }
2028
+ /**
2029
+ * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
2030
+ * level and closing the brace at column zero. Nested objects built the same way indent cumulatively,
2031
+ * so callers never re-parse the generated code. A trailing comma is added per entry to match the
2032
+ * formatter's multi-line style.
2033
+ *
2034
+ * @example
2035
+ * ```ts
2036
+ * buildObject(['id: z.number()', 'name: z.string()'])
2037
+ * // '{\n id: z.number(),\n name: z.string(),\n}'
2038
+ * ```
2039
+ */
2040
+ function buildObject(entries) {
2041
+ if (entries.length === 0) return "{}";
2042
+ return `{\n${entries.map((entry) => `${indentLines(entry)},`).join("\n")}\n}`;
2043
+ }
2044
+ /**
2045
+ * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
2046
+ * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
2047
+ * one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,
2048
+ * `z.array([…])`, and similar member lists so objects inside them nest correctly.
2049
+ *
2050
+ * @example
2051
+ * ```ts
2052
+ * buildList(['z.string()', 'z.number()'])
2053
+ * // '[z.string(), z.number()]'
2054
+ * ```
2055
+ */
2056
+ function buildList(items, brackets = ["[", "]"]) {
2057
+ const [open, close] = brackets;
2058
+ if (items.length === 0) return `${open}${close}`;
2059
+ if (!items.some((item) => item.includes("\n"))) return `${open}${items.join(", ")}${close}`;
2060
+ return `${open}\n${items.map((item) => `${indentLines(item)},`).join("\n")}\n${close}`;
2061
+ }
2062
+ /**
2063
+ * Returns the last path segment of a reference string.
2064
+ *
2065
+ * @example
2066
+ * ```ts
2067
+ * extractRefName('#/components/schemas/Pet') // 'Pet'
2068
+ * ```
2069
+ */
2070
+ function extractRefName(ref) {
2071
+ return ref.split("/").at(-1) ?? ref;
2072
+ }
2073
+ /**
2074
+ * Builds a PascalCase child schema name by joining a parent name and property name.
2075
+ * Returns `null` when there is no parent to nest under.
2076
+ *
2077
+ * @example
2078
+ * ```ts
2079
+ * childName('Order', 'shipping_address') // 'OrderShippingAddress'
2080
+ * childName(undefined, 'params') // null
2081
+ * ```
2082
+ */
2083
+ function childName(parentName, propName) {
2084
+ return parentName ? pascalCase([parentName, propName].join(" ")) : null;
2085
+ }
2086
+ /**
2087
+ * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
2088
+ * empty parts.
2089
+ *
2090
+ * @example
2091
+ * ```ts
2092
+ * enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'
2093
+ * ```
2094
+ */
2095
+ function enumPropName(parentName, propName, enumSuffix) {
2096
+ return pascalCase([
2097
+ parentName,
2098
+ propName,
2099
+ enumSuffix
2100
+ ].filter(Boolean).join(" "));
2101
+ }
2102
+ /**
2103
+ * Returns the discriminator key whose mapping value matches `ref`, or `null` when there is no match.
2104
+ *
2105
+ * @example
2106
+ * ```ts
2107
+ * findDiscriminator({ dog: '#/components/schemas/Dog' }, '#/components/schemas/Dog') // 'dog'
2108
+ * ```
2109
+ */
2110
+ function findDiscriminator(mapping, ref) {
2111
+ if (!mapping || !ref) return null;
2112
+ return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null;
2113
+ }
2114
+ /**
2115
+ * Derives a {@link ParamGroupType} for a query or header group from the resolver.
2116
+ *
2117
+ * Returns `null` when there is no resolver, no params, or the group name equals the
2118
+ * individual param name (so there is no real group to emit).
2119
+ */
2120
+ function resolveGroupType({ node, params, group, resolver }) {
2121
+ if (!resolver || !params.length) return null;
2122
+ const firstParam = params[0];
2123
+ const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
2124
+ if (groupName === resolver.resolveParamName(node, firstParam)) return null;
2125
+ return {
2126
+ type: groupName,
2127
+ optional: params.every((p) => !p.required)
2128
+ };
2129
+ }
2130
+ //#endregion
2131
+ Object.defineProperty(exports, "__exportAll", {
2132
+ enumerable: true,
2133
+ get: function() {
2134
+ return __exportAll;
2135
+ }
2136
+ });
2137
+ Object.defineProperty(exports, "__name", {
2138
+ enumerable: true,
2139
+ get: function() {
2140
+ return __name;
2141
+ }
2142
+ });
2143
+ Object.defineProperty(exports, "__toESM", {
2144
+ enumerable: true,
2145
+ get: function() {
2146
+ return __toESM;
2147
+ }
2148
+ });
2149
+ Object.defineProperty(exports, "arrowFunctionDef", {
2150
+ enumerable: true,
2151
+ get: function() {
2152
+ return arrowFunctionDef;
2153
+ }
2154
+ });
2155
+ Object.defineProperty(exports, "breakDef", {
2156
+ enumerable: true,
2157
+ get: function() {
2158
+ return breakDef;
2159
+ }
2160
+ });
2161
+ Object.defineProperty(exports, "buildGroupParam", {
2162
+ enumerable: true,
2163
+ get: function() {
2164
+ return buildGroupParam;
2165
+ }
2166
+ });
2167
+ Object.defineProperty(exports, "buildJSDoc", {
2168
+ enumerable: true,
2169
+ get: function() {
2170
+ return buildJSDoc;
2171
+ }
2172
+ });
2173
+ Object.defineProperty(exports, "buildList", {
2174
+ enumerable: true,
2175
+ get: function() {
2176
+ return buildList;
2177
+ }
2178
+ });
2179
+ Object.defineProperty(exports, "buildObject", {
2180
+ enumerable: true,
2181
+ get: function() {
2182
+ return buildObject;
2183
+ }
2184
+ });
2185
+ Object.defineProperty(exports, "buildTypeLiteral", {
2186
+ enumerable: true,
2187
+ get: function() {
2188
+ return buildTypeLiteral;
2189
+ }
2190
+ });
2191
+ Object.defineProperty(exports, "caseParams", {
2192
+ enumerable: true,
2193
+ get: function() {
2194
+ return caseParams;
2195
+ }
2196
+ });
2197
+ Object.defineProperty(exports, "childName", {
2198
+ enumerable: true,
2199
+ get: function() {
2200
+ return childName;
2201
+ }
2202
+ });
2203
+ Object.defineProperty(exports, "collect", {
2204
+ enumerable: true,
2205
+ get: function() {
2206
+ return collect;
2207
+ }
2208
+ });
2209
+ Object.defineProperty(exports, "collectLazy", {
2210
+ enumerable: true,
2211
+ get: function() {
2212
+ return collectLazy;
2213
+ }
2214
+ });
2215
+ Object.defineProperty(exports, "collectUsedSchemaNames", {
2216
+ enumerable: true,
2217
+ get: function() {
2218
+ return collectUsedSchemaNames;
2219
+ }
2220
+ });
2221
+ Object.defineProperty(exports, "combineExports", {
2222
+ enumerable: true,
2223
+ get: function() {
2224
+ return combineExports;
2225
+ }
2226
+ });
2227
+ Object.defineProperty(exports, "combineImports", {
2228
+ enumerable: true,
2229
+ get: function() {
2230
+ return combineImports;
2231
+ }
2232
+ });
2233
+ Object.defineProperty(exports, "combineSources", {
2234
+ enumerable: true,
2235
+ get: function() {
2236
+ return combineSources;
2237
+ }
2238
+ });
2239
+ Object.defineProperty(exports, "constDef", {
2240
+ enumerable: true,
2241
+ get: function() {
2242
+ return constDef;
2243
+ }
2244
+ });
2245
+ Object.defineProperty(exports, "containsCircularRef", {
2246
+ enumerable: true,
2247
+ get: function() {
2248
+ return containsCircularRef;
2249
+ }
2250
+ });
2251
+ Object.defineProperty(exports, "contentDef", {
2252
+ enumerable: true,
2253
+ get: function() {
2254
+ return contentDef;
2255
+ }
2256
+ });
2257
+ Object.defineProperty(exports, "createArrowFunction", {
2258
+ enumerable: true,
2259
+ get: function() {
2260
+ return createArrowFunction;
2261
+ }
2262
+ });
2263
+ Object.defineProperty(exports, "createBreak", {
2264
+ enumerable: true,
2265
+ get: function() {
2266
+ return createBreak;
2267
+ }
2268
+ });
2269
+ Object.defineProperty(exports, "createConst", {
2270
+ enumerable: true,
2271
+ get: function() {
2272
+ return createConst;
2273
+ }
2274
+ });
2275
+ Object.defineProperty(exports, "createContent", {
2276
+ enumerable: true,
2277
+ get: function() {
2278
+ return createContent;
2279
+ }
2280
+ });
2281
+ Object.defineProperty(exports, "createDiscriminantNode", {
2282
+ enumerable: true,
2283
+ get: function() {
2284
+ return createDiscriminantNode;
2285
+ }
2286
+ });
2287
+ Object.defineProperty(exports, "createExport", {
2288
+ enumerable: true,
2289
+ get: function() {
2290
+ return createExport;
2291
+ }
2292
+ });
2293
+ Object.defineProperty(exports, "createFunction", {
2294
+ enumerable: true,
2295
+ get: function() {
2296
+ return createFunction;
2297
+ }
2298
+ });
2299
+ Object.defineProperty(exports, "createFunctionParameter", {
2300
+ enumerable: true,
2301
+ get: function() {
2302
+ return createFunctionParameter;
2303
+ }
2304
+ });
2305
+ Object.defineProperty(exports, "createFunctionParameters", {
2306
+ enumerable: true,
2307
+ get: function() {
2308
+ return createFunctionParameters;
2309
+ }
2310
+ });
2311
+ Object.defineProperty(exports, "createImport", {
2312
+ enumerable: true,
2313
+ get: function() {
2314
+ return createImport;
2315
+ }
2316
+ });
2317
+ Object.defineProperty(exports, "createIndexedAccessType", {
2318
+ enumerable: true,
2319
+ get: function() {
2320
+ return createIndexedAccessType;
2321
+ }
2322
+ });
2323
+ Object.defineProperty(exports, "createInput", {
2324
+ enumerable: true,
2325
+ get: function() {
2326
+ return createInput;
2327
+ }
2328
+ });
2329
+ Object.defineProperty(exports, "createJsx", {
2330
+ enumerable: true,
2331
+ get: function() {
2332
+ return createJsx;
2333
+ }
2334
+ });
2335
+ Object.defineProperty(exports, "createObjectBindingPattern", {
2336
+ enumerable: true,
2337
+ get: function() {
2338
+ return createObjectBindingPattern;
2339
+ }
2340
+ });
2341
+ Object.defineProperty(exports, "createOperation", {
2342
+ enumerable: true,
2343
+ get: function() {
2344
+ return createOperation;
2345
+ }
2346
+ });
2347
+ Object.defineProperty(exports, "createOperationParams", {
2348
+ enumerable: true,
2349
+ get: function() {
2350
+ return createOperationParams;
2351
+ }
2352
+ });
2353
+ Object.defineProperty(exports, "createOutput", {
2354
+ enumerable: true,
2355
+ get: function() {
2356
+ return createOutput;
2357
+ }
2358
+ });
2359
+ Object.defineProperty(exports, "createParameter", {
2360
+ enumerable: true,
2361
+ get: function() {
2362
+ return createParameter;
2363
+ }
2364
+ });
2365
+ Object.defineProperty(exports, "createProperty", {
2366
+ enumerable: true,
2367
+ get: function() {
2368
+ return createProperty;
2369
+ }
2370
+ });
2371
+ Object.defineProperty(exports, "createRequestBody", {
2372
+ enumerable: true,
2373
+ get: function() {
2374
+ return createRequestBody;
2375
+ }
2376
+ });
2377
+ Object.defineProperty(exports, "createResponse", {
2378
+ enumerable: true,
2379
+ get: function() {
2380
+ return createResponse;
2381
+ }
2382
+ });
2383
+ Object.defineProperty(exports, "createSchema", {
2384
+ enumerable: true,
2385
+ get: function() {
2386
+ return createSchema;
2387
+ }
2388
+ });
2389
+ Object.defineProperty(exports, "createSource", {
2390
+ enumerable: true,
2391
+ get: function() {
2392
+ return createSource;
2393
+ }
2394
+ });
2395
+ Object.defineProperty(exports, "createText", {
2396
+ enumerable: true,
2397
+ get: function() {
2398
+ return createText;
2399
+ }
2400
+ });
2401
+ Object.defineProperty(exports, "createType", {
2402
+ enumerable: true,
2403
+ get: function() {
2404
+ return createType;
2405
+ }
2406
+ });
2407
+ Object.defineProperty(exports, "createTypeLiteral", {
2408
+ enumerable: true,
2409
+ get: function() {
2410
+ return createTypeLiteral;
2411
+ }
2412
+ });
2413
+ Object.defineProperty(exports, "defineNode", {
2414
+ enumerable: true,
2415
+ get: function() {
2416
+ return defineNode;
2417
+ }
2418
+ });
2419
+ Object.defineProperty(exports, "enumPropName", {
2420
+ enumerable: true,
2421
+ get: function() {
2422
+ return enumPropName;
2423
+ }
2424
+ });
2425
+ Object.defineProperty(exports, "exportDef", {
2426
+ enumerable: true,
2427
+ get: function() {
2428
+ return exportDef;
2429
+ }
2430
+ });
2431
+ Object.defineProperty(exports, "extractRefName", {
2432
+ enumerable: true,
2433
+ get: function() {
2434
+ return extractRefName;
2435
+ }
2436
+ });
2437
+ Object.defineProperty(exports, "extractStringsFromNodes", {
2438
+ enumerable: true,
2439
+ get: function() {
2440
+ return extractStringsFromNodes;
2441
+ }
2442
+ });
2443
+ Object.defineProperty(exports, "fileDef", {
2444
+ enumerable: true,
2445
+ get: function() {
2446
+ return fileDef;
2447
+ }
2448
+ });
2449
+ Object.defineProperty(exports, "findCircularSchemas", {
2450
+ enumerable: true,
2451
+ get: function() {
2452
+ return findCircularSchemas;
2453
+ }
2454
+ });
2455
+ Object.defineProperty(exports, "findDiscriminator", {
2456
+ enumerable: true,
2457
+ get: function() {
2458
+ return findDiscriminator;
2459
+ }
2460
+ });
2461
+ Object.defineProperty(exports, "functionDef", {
2462
+ enumerable: true,
2463
+ get: function() {
2464
+ return functionDef;
2465
+ }
2466
+ });
2467
+ Object.defineProperty(exports, "functionParameterDef", {
2468
+ enumerable: true,
2469
+ get: function() {
2470
+ return functionParameterDef;
2471
+ }
2472
+ });
2473
+ Object.defineProperty(exports, "functionParametersDef", {
2474
+ enumerable: true,
2475
+ get: function() {
2476
+ return functionParametersDef;
2477
+ }
2478
+ });
2479
+ Object.defineProperty(exports, "getNestedAccessor", {
2480
+ enumerable: true,
2481
+ get: function() {
2482
+ return getNestedAccessor;
2483
+ }
2484
+ });
2485
+ Object.defineProperty(exports, "httpMethods", {
2486
+ enumerable: true,
2487
+ get: function() {
2488
+ return httpMethods;
2489
+ }
2490
+ });
2491
+ Object.defineProperty(exports, "importDef", {
2492
+ enumerable: true,
2493
+ get: function() {
2494
+ return importDef;
2495
+ }
2496
+ });
2497
+ Object.defineProperty(exports, "indexedAccessTypeDef", {
2498
+ enumerable: true,
2499
+ get: function() {
2500
+ return indexedAccessTypeDef;
2501
+ }
2502
+ });
2503
+ Object.defineProperty(exports, "inputDef", {
2504
+ enumerable: true,
2505
+ get: function() {
2506
+ return inputDef;
2507
+ }
2508
+ });
2509
+ Object.defineProperty(exports, "isHttpOperationNode", {
2510
+ enumerable: true,
2511
+ get: function() {
2512
+ return isHttpOperationNode;
2513
+ }
2514
+ });
2515
+ Object.defineProperty(exports, "isScalarPrimitive", {
2516
+ enumerable: true,
2517
+ get: function() {
2518
+ return isScalarPrimitive;
2519
+ }
2520
+ });
2521
+ Object.defineProperty(exports, "isStringType", {
2522
+ enumerable: true,
2523
+ get: function() {
2524
+ return isStringType;
2525
+ }
2526
+ });
2527
+ Object.defineProperty(exports, "isValidVarName", {
2528
+ enumerable: true,
2529
+ get: function() {
2530
+ return isValidVarName;
2531
+ }
2532
+ });
2533
+ Object.defineProperty(exports, "jsStringEscape", {
2534
+ enumerable: true,
2535
+ get: function() {
2536
+ return jsStringEscape;
2537
+ }
2538
+ });
2539
+ Object.defineProperty(exports, "jsxDef", {
2540
+ enumerable: true,
2541
+ get: function() {
2542
+ return jsxDef;
2543
+ }
2544
+ });
2545
+ Object.defineProperty(exports, "narrowSchema", {
2546
+ enumerable: true,
2547
+ get: function() {
2548
+ return narrowSchema;
2549
+ }
2550
+ });
2551
+ Object.defineProperty(exports, "objectBindingPatternDef", {
2552
+ enumerable: true,
2553
+ get: function() {
2554
+ return objectBindingPatternDef;
2555
+ }
2556
+ });
2557
+ Object.defineProperty(exports, "objectKey", {
2558
+ enumerable: true,
2559
+ get: function() {
2560
+ return objectKey;
2561
+ }
2562
+ });
2563
+ Object.defineProperty(exports, "operationDef", {
2564
+ enumerable: true,
2565
+ get: function() {
2566
+ return operationDef;
2567
+ }
2568
+ });
2569
+ Object.defineProperty(exports, "outputDef", {
2570
+ enumerable: true,
2571
+ get: function() {
2572
+ return outputDef;
2573
+ }
2574
+ });
2575
+ Object.defineProperty(exports, "parameterDef", {
2576
+ enumerable: true,
2577
+ get: function() {
2578
+ return parameterDef;
2579
+ }
2580
+ });
2581
+ Object.defineProperty(exports, "propertyDef", {
2582
+ enumerable: true,
2583
+ get: function() {
2584
+ return propertyDef;
2585
+ }
2586
+ });
2587
+ Object.defineProperty(exports, "requestBodyDef", {
2588
+ enumerable: true,
2589
+ get: function() {
2590
+ return requestBodyDef;
2591
+ }
2592
+ });
2593
+ Object.defineProperty(exports, "resolveGroupType", {
2594
+ enumerable: true,
2595
+ get: function() {
2596
+ return resolveGroupType;
2597
+ }
2598
+ });
2599
+ Object.defineProperty(exports, "resolveParamType", {
2600
+ enumerable: true,
2601
+ get: function() {
2602
+ return resolveParamType;
2603
+ }
2604
+ });
2605
+ Object.defineProperty(exports, "responseDef", {
2606
+ enumerable: true,
2607
+ get: function() {
2608
+ return responseDef;
2609
+ }
2610
+ });
2611
+ Object.defineProperty(exports, "schemaDef", {
2612
+ enumerable: true,
2613
+ get: function() {
2614
+ return schemaDef;
2615
+ }
2616
+ });
2617
+ Object.defineProperty(exports, "schemaTypes", {
2618
+ enumerable: true,
2619
+ get: function() {
2620
+ return schemaTypes;
2621
+ }
2622
+ });
2623
+ Object.defineProperty(exports, "sourceDef", {
2624
+ enumerable: true,
2625
+ get: function() {
2626
+ return sourceDef;
2627
+ }
2628
+ });
2629
+ Object.defineProperty(exports, "stringify", {
2630
+ enumerable: true,
2631
+ get: function() {
2632
+ return stringify;
2633
+ }
2634
+ });
2635
+ Object.defineProperty(exports, "stringifyObject", {
2636
+ enumerable: true,
2637
+ get: function() {
2638
+ return stringifyObject;
2639
+ }
2640
+ });
2641
+ Object.defineProperty(exports, "syncOptionality", {
2642
+ enumerable: true,
2643
+ get: function() {
2644
+ return syncOptionality;
2645
+ }
2646
+ });
2647
+ Object.defineProperty(exports, "syncSchemaRef", {
2648
+ enumerable: true,
2649
+ get: function() {
2650
+ return syncSchemaRef;
2651
+ }
2652
+ });
2653
+ Object.defineProperty(exports, "textDef", {
2654
+ enumerable: true,
2655
+ get: function() {
2656
+ return textDef;
2657
+ }
2658
+ });
2659
+ Object.defineProperty(exports, "toRegExpString", {
2660
+ enumerable: true,
2661
+ get: function() {
2662
+ return toRegExpString;
2663
+ }
2664
+ });
2665
+ Object.defineProperty(exports, "transform", {
2666
+ enumerable: true,
2667
+ get: function() {
2668
+ return transform;
2669
+ }
2670
+ });
2671
+ Object.defineProperty(exports, "trimQuotes", {
2672
+ enumerable: true,
2673
+ get: function() {
2674
+ return trimQuotes;
2675
+ }
2676
+ });
2677
+ Object.defineProperty(exports, "typeDef", {
2678
+ enumerable: true,
2679
+ get: function() {
2680
+ return typeDef;
2681
+ }
2682
+ });
2683
+ Object.defineProperty(exports, "typeLiteralDef", {
2684
+ enumerable: true,
2685
+ get: function() {
2686
+ return typeLiteralDef;
2687
+ }
2688
+ });
2689
+ Object.defineProperty(exports, "walk", {
2690
+ enumerable: true,
2691
+ get: function() {
2692
+ return walk;
2693
+ }
2694
+ });
2695
+
2696
+ //# sourceMappingURL=utils-C8bWAzhv.cjs.map