@kubb/ast 5.0.0-beta.8 → 5.0.0-beta.80

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 (64) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +53 -27
  3. package/dist/defineMacro-CqX4m8Dq.js +98 -0
  4. package/dist/defineMacro-CqX4m8Dq.js.map +1 -0
  5. package/dist/defineMacro-DmGR7vfu.cjs +114 -0
  6. package/dist/defineMacro-DmGR7vfu.cjs.map +1 -0
  7. package/dist/defineMacro-DzsACbFo.d.ts +466 -0
  8. package/dist/index-Cu2zmNxv.d.ts +2188 -0
  9. package/dist/index.cjs +194 -2239
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +88 -3405
  12. package/dist/index.js +150 -2160
  13. package/dist/index.js.map +1 -1
  14. package/dist/macros.cjs +130 -0
  15. package/dist/macros.cjs.map +1 -0
  16. package/dist/macros.d.ts +61 -0
  17. package/dist/macros.js +128 -0
  18. package/dist/macros.js.map +1 -0
  19. package/dist/refs-Bg3rmujP.cjs +135 -0
  20. package/dist/refs-Bg3rmujP.cjs.map +1 -0
  21. package/dist/refs-BjBHwunY.js +101 -0
  22. package/dist/refs-BjBHwunY.js.map +1 -0
  23. package/dist/rolldown-runtime-CNktS9qV.js +17 -0
  24. package/dist/types-CWF7DV0f.d.ts +259 -0
  25. package/dist/types.cjs +0 -0
  26. package/dist/types.d.ts +4 -0
  27. package/dist/types.js +1 -0
  28. package/dist/utils.cjs +613 -0
  29. package/dist/utils.cjs.map +1 -0
  30. package/dist/utils.d.ts +353 -0
  31. package/dist/utils.js +589 -0
  32. package/dist/utils.js.map +1 -0
  33. package/dist/visitor-Dk0DNLfC.js +1203 -0
  34. package/dist/visitor-Dk0DNLfC.js.map +1 -0
  35. package/dist/visitor-h6dEM3vR.cjs +1567 -0
  36. package/dist/visitor-h6dEM3vR.cjs.map +1 -0
  37. package/package.json +17 -5
  38. package/dist/chunk--u3MIqq1.js +0 -8
  39. package/src/constants.ts +0 -228
  40. package/src/factory.ts +0 -742
  41. package/src/guards.ts +0 -110
  42. package/src/index.ts +0 -46
  43. package/src/infer.ts +0 -130
  44. package/src/mocks.ts +0 -176
  45. package/src/nodes/base.ts +0 -56
  46. package/src/nodes/code.ts +0 -304
  47. package/src/nodes/file.ts +0 -230
  48. package/src/nodes/function.ts +0 -223
  49. package/src/nodes/http.ts +0 -119
  50. package/src/nodes/index.ts +0 -86
  51. package/src/nodes/operation.ts +0 -111
  52. package/src/nodes/output.ts +0 -26
  53. package/src/nodes/parameter.ts +0 -41
  54. package/src/nodes/property.ts +0 -34
  55. package/src/nodes/response.ts +0 -43
  56. package/src/nodes/root.ts +0 -64
  57. package/src/nodes/schema.ts +0 -656
  58. package/src/printer.ts +0 -250
  59. package/src/refs.ts +0 -67
  60. package/src/resolvers.ts +0 -45
  61. package/src/transformers.ts +0 -159
  62. package/src/types.ts +0 -70
  63. package/src/utils.ts +0 -915
  64. package/src/visitor.ts +0 -592
@@ -0,0 +1,1567 @@
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
+ let node_crypto = require("node:crypto");
37
+ let node_path = require("node:path");
38
+ node_path = __toESM(node_path, 1);
39
+ //#region src/constants.ts
40
+ const visitorDepths = {
41
+ shallow: "shallow",
42
+ deep: "deep"
43
+ };
44
+ /**
45
+ * Schema type discriminators used by all AST schema nodes.
46
+ *
47
+ * Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
48
+ */
49
+ const schemaTypes = {
50
+ /**
51
+ * Text value.
52
+ */
53
+ string: "string",
54
+ /**
55
+ * Floating-point number (`float`, `double`).
56
+ */
57
+ number: "number",
58
+ /**
59
+ * Whole number (`int32`). Use `bigint` for `int64`.
60
+ */
61
+ integer: "integer",
62
+ /**
63
+ * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
64
+ */
65
+ bigint: "bigint",
66
+ /**
67
+ * Boolean value.
68
+ */
69
+ boolean: "boolean",
70
+ /**
71
+ * Explicit null value.
72
+ */
73
+ null: "null",
74
+ /**
75
+ * Any value (no type restriction).
76
+ */
77
+ any: "any",
78
+ /**
79
+ * Unknown value (must be narrowed before usage).
80
+ */
81
+ unknown: "unknown",
82
+ /**
83
+ * No return value (`void`).
84
+ */
85
+ void: "void",
86
+ /**
87
+ * Object with named properties.
88
+ */
89
+ object: "object",
90
+ /**
91
+ * Sequential list of items.
92
+ */
93
+ array: "array",
94
+ /**
95
+ * Fixed-length list with position-specific items.
96
+ */
97
+ tuple: "tuple",
98
+ /**
99
+ * "One of" multiple schema members.
100
+ */
101
+ union: "union",
102
+ /**
103
+ * "All of" multiple schema members.
104
+ */
105
+ intersection: "intersection",
106
+ /**
107
+ * Enum schema.
108
+ */
109
+ enum: "enum",
110
+ /**
111
+ * Reference to another schema.
112
+ */
113
+ ref: "ref",
114
+ /**
115
+ * Calendar date (for example `2026-03-24`).
116
+ */
117
+ date: "date",
118
+ /**
119
+ * Date-time value (for example `2026-03-24T09:00:00Z`).
120
+ */
121
+ datetime: "datetime",
122
+ /**
123
+ * Time-only value (for example `09:00:00`).
124
+ */
125
+ time: "time",
126
+ /**
127
+ * UUID value.
128
+ */
129
+ uuid: "uuid",
130
+ /**
131
+ * Email address value.
132
+ */
133
+ email: "email",
134
+ /**
135
+ * URL value.
136
+ */
137
+ url: "url",
138
+ /**
139
+ * IPv4 address value.
140
+ */
141
+ ipv4: "ipv4",
142
+ /**
143
+ * IPv6 address value.
144
+ */
145
+ ipv6: "ipv6",
146
+ /**
147
+ * Binary/blob value.
148
+ */
149
+ blob: "blob",
150
+ /**
151
+ * Impossible value (`never`).
152
+ */
153
+ never: "never"
154
+ };
155
+ //#endregion
156
+ //#region src/guards.ts
157
+ /**
158
+ * Narrows a `SchemaNode` to the variant that matches `type`.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const schema = createSchema({ type: 'string' })
163
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
164
+ * ```
165
+ */
166
+ function narrowSchema(node, type) {
167
+ return node?.type === type ? node : null;
168
+ }
169
+ /**
170
+ * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * if (isHttpOperationNode(node)) {
175
+ * console.log(node.method, node.path)
176
+ * }
177
+ * ```
178
+ */
179
+ function isHttpOperationNode(node) {
180
+ return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
181
+ }
182
+ //#endregion
183
+ //#region src/defineNode.ts
184
+ /**
185
+ * Visitor callback names, one per traversable node kind, in traversal order.
186
+ * Kept in sync with the keys of `Visitor` in `visitor.ts`.
187
+ */
188
+ const visitorKeys = [
189
+ "input",
190
+ "output",
191
+ "operation",
192
+ "schema",
193
+ "property",
194
+ "parameter",
195
+ "response"
196
+ ];
197
+ /**
198
+ * Builds a type guard that matches nodes of the given `kind`.
199
+ */
200
+ function isKind(kind) {
201
+ return (node) => node?.kind === kind;
202
+ }
203
+ /**
204
+ * Defines a node once and derives its `create` builder, `is` guard, and traversal
205
+ * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the
206
+ * `kind`, so node construction lives in one place without scattered `as` casts.
207
+ *
208
+ * @example Simple node
209
+ * ```ts
210
+ * const importDef = defineNode<ImportNode>({ kind: 'Import' })
211
+ * const createImport = importDef.create
212
+ * ```
213
+ *
214
+ * @example Node with a build hook
215
+ * ```ts
216
+ * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({
217
+ * kind: 'Property',
218
+ * build: (props) => ({ ...props, required: props.required ?? false }),
219
+ * children: ['schema'],
220
+ * visitorKey: 'property',
221
+ * })
222
+ * ```
223
+ */
224
+ function defineNode(config) {
225
+ const { kind, defaults, build, children, visitorKey } = config;
226
+ function create(input) {
227
+ const base = build ? build(input) : input;
228
+ const node = {
229
+ kind,
230
+ ...defaults,
231
+ ...base
232
+ };
233
+ node.kind = kind;
234
+ return node;
235
+ }
236
+ return {
237
+ kind,
238
+ create,
239
+ is: isKind(kind),
240
+ children,
241
+ visitorKey
242
+ };
243
+ }
244
+ //#endregion
245
+ //#region src/nodes/code.ts
246
+ /**
247
+ * Definition for the {@link ConstNode}.
248
+ */
249
+ const constDef = defineNode({ kind: "Const" });
250
+ /**
251
+ * Definition for the {@link TypeNode}.
252
+ */
253
+ const typeDef = defineNode({ kind: "Type" });
254
+ /**
255
+ * Definition for the {@link FunctionNode}.
256
+ */
257
+ const functionDef = defineNode({ kind: "Function" });
258
+ /**
259
+ * Definition for the {@link ArrowFunctionNode}.
260
+ */
261
+ const arrowFunctionDef = defineNode({ kind: "ArrowFunction" });
262
+ /**
263
+ * Definition for the {@link TextNode}.
264
+ */
265
+ const textDef = defineNode({
266
+ kind: "Text",
267
+ build: (value) => ({ value })
268
+ });
269
+ /**
270
+ * Definition for the {@link BreakNode}.
271
+ */
272
+ const breakDef = defineNode({
273
+ kind: "Break",
274
+ build: () => ({})
275
+ });
276
+ /**
277
+ * Definition for the {@link JsxNode}.
278
+ */
279
+ const jsxDef = defineNode({
280
+ kind: "Jsx",
281
+ build: (value) => ({ value })
282
+ });
283
+ /**
284
+ * Creates a `ConstNode` representing a TypeScript `const` declaration.
285
+ *
286
+ * @example Exported constant with type and `as const`
287
+ * ```ts
288
+ * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
289
+ * // export const pets: Pet[] = ... as const
290
+ * ```
291
+ */
292
+ const createConst = constDef.create;
293
+ /**
294
+ * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
295
+ *
296
+ * @example
297
+ * ```ts
298
+ * createType({ name: 'Pet', export: true })
299
+ * // export type Pet = ...
300
+ * ```
301
+ */
302
+ const createType = typeDef.create;
303
+ /**
304
+ * Creates a `FunctionNode` representing a TypeScript `function` declaration.
305
+ *
306
+ * @example
307
+ * ```ts
308
+ * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
309
+ * // export async function fetchPet(): Promise<Pet> { ... }
310
+ * ```
311
+ */
312
+ const createFunction = functionDef.create;
313
+ /**
314
+ * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
315
+ *
316
+ * @example
317
+ * ```ts
318
+ * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
319
+ * // export const double = (n: number) => ...
320
+ * ```
321
+ */
322
+ const createArrowFunction = arrowFunctionDef.create;
323
+ /**
324
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * createText('return fetch(id)')
329
+ * // { kind: 'Text', value: 'return fetch(id)' }
330
+ * ```
331
+ */
332
+ const createText = textDef.create;
333
+ /**
334
+ * Creates a {@link BreakNode} representing a line break in the source output.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * createBreak()
339
+ * // { kind: 'Break' }
340
+ * ```
341
+ */
342
+ function createBreak() {
343
+ return breakDef.create();
344
+ }
345
+ /**
346
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
347
+ *
348
+ * @example
349
+ * ```ts
350
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
351
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
352
+ * ```
353
+ */
354
+ const createJsx = jsxDef.create;
355
+ //#endregion
356
+ //#region src/nodes/content.ts
357
+ /**
358
+ * Definition for the {@link ContentNode}.
359
+ */
360
+ const contentDef = defineNode({
361
+ kind: "Content",
362
+ children: ["schema"]
363
+ });
364
+ /**
365
+ * Creates a `ContentNode` for a single request-body or response content type.
366
+ */
367
+ const createContent = contentDef.create;
368
+ //#endregion
369
+ //#region ../../internals/utils/src/casing.ts
370
+ /**
371
+ * Shared implementation for camelCase and PascalCase conversion.
372
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
373
+ * and capitalizes each word according to `pascal`.
374
+ *
375
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
376
+ */
377
+ function toCamelOrPascal(text, pascal) {
378
+ 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) => {
379
+ if (word.length > 1 && word === word.toUpperCase()) return word;
380
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
381
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
382
+ }
383
+ /**
384
+ * Converts `text` to PascalCase.
385
+ *
386
+ * @example Word boundaries
387
+ * `pascalCase('hello-world') // 'HelloWorld'`
388
+ *
389
+ * @example With a suffix
390
+ * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
391
+ */
392
+ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
393
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
394
+ }
395
+ //#endregion
396
+ //#region ../../internals/utils/src/fs.ts
397
+ /**
398
+ * Strips the file extension from a path or file name.
399
+ * Only removes the last `.ext` segment when the dot is not part of a directory name.
400
+ *
401
+ * @example
402
+ * trimExtName('petStore.ts') // 'petStore'
403
+ * trimExtName('/src/models/pet.ts') // '/src/models/pet'
404
+ * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
405
+ * trimExtName('noExtension') // 'noExtension'
406
+ */
407
+ function trimExtName(text) {
408
+ const dotIndex = text.lastIndexOf(".");
409
+ if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
410
+ return text;
411
+ }
412
+ //#endregion
413
+ //#region src/utils/extractStringsFromNodes.ts
414
+ /**
415
+ * Extracts all string content from a `CodeNode` tree recursively.
416
+ *
417
+ * Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
418
+ * and nested node content. Used to build the full source string for import filtering.
419
+ */
420
+ function extractStringsFromNodes(nodes) {
421
+ if (!nodes?.length) return "";
422
+ const collected = [];
423
+ for (const node of nodes) {
424
+ if (typeof node === "string") {
425
+ if (node) collected.push(node);
426
+ continue;
427
+ }
428
+ if (node.kind === "Text") {
429
+ if (node.value) collected.push(node.value);
430
+ continue;
431
+ }
432
+ if (node.kind === "Break") continue;
433
+ if (node.kind === "Jsx") {
434
+ if (node.value) collected.push(node.value);
435
+ continue;
436
+ }
437
+ const parts = [];
438
+ if ("params" in node && node.params) parts.push(node.params);
439
+ if ("generics" in node && node.generics) parts.push(Array.isArray(node.generics) ? node.generics.join(", ") : node.generics);
440
+ if ("returnType" in node && node.returnType) parts.push(node.returnType);
441
+ if ("type" in node && typeof node.type === "string") parts.push(node.type);
442
+ const nested = extractStringsFromNodes(node.nodes);
443
+ if (nested) parts.push(nested);
444
+ if (parts.length) collected.push(parts.join("\n"));
445
+ }
446
+ return collected.join("\n");
447
+ }
448
+ //#endregion
449
+ //#region src/utils/fileMerge.ts
450
+ function sourceKey(source) {
451
+ return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`;
452
+ }
453
+ function pathTypeKey(path, isTypeOnly) {
454
+ return `${path}:${isTypeOnly ?? false}`;
455
+ }
456
+ function exportKey(path, name, isTypeOnly, asAlias) {
457
+ return `${path}:${name ?? ""}:${isTypeOnly ?? false}:${asAlias ?? ""}`;
458
+ }
459
+ function importKey(path, name, isTypeOnly) {
460
+ return `${path}:${name ?? ""}:${isTypeOnly ?? false}`;
461
+ }
462
+ /**
463
+ * Computes a multi-level sort key for exports and imports:
464
+ * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named.
465
+ */
466
+ function sortKey(node) {
467
+ const isArray = Array.isArray(node.name) ? "1" : "0";
468
+ const typeOnly = node.isTypeOnly ? "0" : "1";
469
+ const hasName = node.name != null ? "1" : "0";
470
+ const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? "";
471
+ return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`;
472
+ }
473
+ /**
474
+ * Deduplicates `SourceNode` objects by `name + isExportable + isTypeOnly`, keeping the first of each
475
+ * key. Unnamed sources fall back to their extracted node strings as the name part of the key. Returns
476
+ * the deduplicated array in original order.
477
+ */
478
+ function combineSources(sources) {
479
+ const seen = /* @__PURE__ */ new Map();
480
+ for (const source of sources) {
481
+ const key = sourceKey(source);
482
+ if (!seen.has(key)) seen.set(key, source);
483
+ }
484
+ return [...seen.values()];
485
+ }
486
+ /**
487
+ * Merges `incoming` names into `existing`, preserving order and dropping duplicates.
488
+ *
489
+ * Shared by `combineExports` and `combineImports` for the same-path name-merge case.
490
+ */
491
+ function mergeNameArrays(existing, incoming) {
492
+ const merged = new Set(existing);
493
+ for (const name of incoming) merged.add(name);
494
+ return [...merged];
495
+ }
496
+ /**
497
+ * Deduplicates and merges `ExportNode` objects by path and type.
498
+ *
499
+ * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export.
500
+ * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array.
501
+ */
502
+ function combineExports(exports) {
503
+ const result = [];
504
+ const namedByPath = /* @__PURE__ */ new Map();
505
+ const seen = /* @__PURE__ */ new Set();
506
+ const keyed = exports.map((node) => ({
507
+ node,
508
+ key: sortKey(node)
509
+ }));
510
+ keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
511
+ for (const { node: curr } of keyed) {
512
+ const { name, path, isTypeOnly, asAlias } = curr;
513
+ if (Array.isArray(name)) {
514
+ if (!name.length) continue;
515
+ const key = pathTypeKey(path, isTypeOnly);
516
+ const existing = namedByPath.get(key);
517
+ if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name);
518
+ else {
519
+ const newItem = {
520
+ ...curr,
521
+ name: [...new Set(name)]
522
+ };
523
+ result.push(newItem);
524
+ namedByPath.set(key, newItem);
525
+ }
526
+ } else {
527
+ const key = exportKey(path, name, isTypeOnly, asAlias);
528
+ if (!seen.has(key)) {
529
+ result.push(curr);
530
+ seen.add(key);
531
+ }
532
+ }
533
+ }
534
+ return result;
535
+ }
536
+ /**
537
+ * Deduplicates and merges `ImportNode` objects, filtering out unused imports.
538
+ *
539
+ * Retains imports that are referenced in `source` or re-exported. Imports with the same path and
540
+ * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array.
541
+ */
542
+ function combineImports(imports, exports, source) {
543
+ const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : []));
544
+ const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName);
545
+ const importNameMemo = /* @__PURE__ */ new Map();
546
+ const canonicalizeName = (n) => {
547
+ if (typeof n === "string") return n;
548
+ const key = `${n.propertyName}:${n.name ?? ""}`;
549
+ if (!importNameMemo.has(key)) importNameMemo.set(key, n);
550
+ return importNameMemo.get(key);
551
+ };
552
+ const pathsWithUsedNamedImport = /* @__PURE__ */ new Set();
553
+ for (const node of imports) {
554
+ if (!Array.isArray(node.name)) continue;
555
+ if (node.name.some((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName))) pathsWithUsedNamedImport.add(node.path);
556
+ }
557
+ const result = [];
558
+ const namedByPath = /* @__PURE__ */ new Map();
559
+ const seen = /* @__PURE__ */ new Set();
560
+ const keyed = imports.map((node) => ({
561
+ node,
562
+ key: sortKey(node)
563
+ }));
564
+ keyed.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
565
+ for (const { node: curr } of keyed) {
566
+ if (curr.path === curr.root) continue;
567
+ const { path, isTypeOnly } = curr;
568
+ let { name } = curr;
569
+ if (Array.isArray(name)) {
570
+ name = [...new Set(name.map(canonicalizeName))].filter((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName));
571
+ if (!name.length) continue;
572
+ const key = pathTypeKey(path, isTypeOnly);
573
+ const existing = namedByPath.get(key);
574
+ if (existing && Array.isArray(existing.name)) existing.name = mergeNameArrays(existing.name, name);
575
+ else {
576
+ const newItem = {
577
+ ...curr,
578
+ name
579
+ };
580
+ result.push(newItem);
581
+ namedByPath.set(key, newItem);
582
+ }
583
+ } else {
584
+ if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue;
585
+ const key = importKey(path, name, isTypeOnly);
586
+ if (!seen.has(key)) {
587
+ result.push(curr);
588
+ seen.add(key);
589
+ }
590
+ }
591
+ }
592
+ return result;
593
+ }
594
+ //#endregion
595
+ //#region src/nodes/file.ts
596
+ /**
597
+ * Definition for the {@link ImportNode}.
598
+ */
599
+ const importDef = defineNode({ kind: "Import" });
600
+ /**
601
+ * Definition for the {@link ExportNode}.
602
+ */
603
+ const exportDef = defineNode({ kind: "Export" });
604
+ /**
605
+ * Definition for the {@link SourceNode}.
606
+ */
607
+ const sourceDef = defineNode({ kind: "Source" });
608
+ /**
609
+ * Definition for the {@link FileNode}. The fully resolved builder lives in
610
+ * `createFile`, so this definition only supplies the guard.
611
+ */
612
+ const fileDef = defineNode({ kind: "File" });
613
+ /**
614
+ * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
615
+ *
616
+ * @example Named import
617
+ * ```ts
618
+ * createImport({ name: ['useState'], path: 'react' })
619
+ * // import { useState } from 'react'
620
+ * ```
621
+ */
622
+ const createImport = importDef.create;
623
+ /**
624
+ * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
625
+ *
626
+ * @example Named export
627
+ * ```ts
628
+ * createExport({ name: ['Pet'], path: './Pet' })
629
+ * // export { Pet } from './Pet'
630
+ * ```
631
+ */
632
+ const createExport = exportDef.create;
633
+ /**
634
+ * Creates a `SourceNode` representing a fragment of source code within a file.
635
+ *
636
+ * @example
637
+ * ```ts
638
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
639
+ * ```
640
+ */
641
+ const createSource = sourceDef.create;
642
+ /**
643
+ * Creates a fully resolved `FileNode` from a file input descriptor.
644
+ *
645
+ * Computes:
646
+ * - `id` SHA256 hash of the file path
647
+ * - `name` `baseName` without extension
648
+ * - `extname` extension extracted from `baseName`
649
+ *
650
+ * Deduplicates:
651
+ * - `sources` via `combineSources`
652
+ * - `exports` via `combineExports`
653
+ * - `imports` via `combineImports` (also filters unused imports)
654
+ *
655
+ * @throws {Error} when `baseName` has no extension.
656
+ *
657
+ * @example
658
+ * ```ts
659
+ * const file = createFile({
660
+ * baseName: 'petStore.ts',
661
+ * path: 'src/models/petStore.ts',
662
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
663
+ * imports: [createImport({ name: ['z'], path: 'zod' })],
664
+ * exports: [createExport({ name: ['Pet'], path: './petStore' })],
665
+ * })
666
+ * // file.id = SHA256 hash of 'src/models/petStore.ts'
667
+ * // file.name = 'petStore'
668
+ * // file.extname = '.ts'
669
+ * ```
670
+ *
671
+ * @example Copy a real file into the output verbatim
672
+ * ```ts
673
+ * const file = createFile({
674
+ * baseName: 'client.ts',
675
+ * path: 'src/gen/client.ts',
676
+ * copy: '/abs/path/to/templates/client.ts',
677
+ * })
678
+ * ```
679
+ */
680
+ function createFile(input) {
681
+ const extname = node_path.default.extname(input.baseName) || (input.baseName.startsWith(".") ? input.baseName : "");
682
+ if (!extname) throw new Error(`No extname found for ${input.baseName}`);
683
+ const resolvedExports = input.exports?.length ? combineExports(input.exports) : [];
684
+ let resolvedImports = [];
685
+ if (input.imports?.length) {
686
+ const source = extractStringsFromNodes((input.sources ?? []).flatMap((item) => item.nodes ?? [])) || void 0;
687
+ const combinedImports = combineImports(input.imports, resolvedExports, source);
688
+ const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name) => Boolean(name)));
689
+ const nameOf = (item) => typeof item === "string" ? item : item.name ?? item.propertyName;
690
+ resolvedImports = combinedImports.filter((imp) => imp.path !== input.path).flatMap((imp) => {
691
+ if (!Array.isArray(imp.name)) return typeof imp.name === "string" && localNames.has(imp.name) ? [] : [imp];
692
+ const kept = imp.name.filter((item) => !localNames.has(nameOf(item)));
693
+ if (!kept.length) return [];
694
+ return [kept.length === imp.name.length ? imp : {
695
+ ...imp,
696
+ name: kept
697
+ }];
698
+ });
699
+ }
700
+ const resolvedSources = input.sources?.length ? combineSources(input.sources) : [];
701
+ return {
702
+ kind: "File",
703
+ ...input,
704
+ id: (0, node_crypto.hash)("sha256", input.path, "hex"),
705
+ name: trimExtName(input.baseName),
706
+ extname,
707
+ imports: resolvedImports,
708
+ exports: resolvedExports,
709
+ sources: resolvedSources,
710
+ meta: input.meta ?? {}
711
+ };
712
+ }
713
+ //#endregion
714
+ //#region src/nodes/input.ts
715
+ /**
716
+ * Definition for the {@link InputNode}.
717
+ */
718
+ const inputDef = defineNode({
719
+ kind: "Input",
720
+ defaults: {
721
+ schemas: [],
722
+ operations: [],
723
+ meta: {
724
+ circularNames: [],
725
+ enumNames: []
726
+ }
727
+ },
728
+ children: ["schemas", "operations"],
729
+ visitorKey: "input"
730
+ });
731
+ /**
732
+ * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and
733
+ * `operations` are `AsyncIterable` sources. Otherwise it builds the eager variant with array
734
+ * `schemas`/`operations`. Both variants get the defaulted `meta`.
735
+ *
736
+ * @example Eager
737
+ * ```ts
738
+ * const input = createInput()
739
+ * // { kind: 'Input', schemas: [], operations: [] }
740
+ * ```
741
+ *
742
+ * @example Streaming
743
+ * ```ts
744
+ * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
745
+ * ```
746
+ */
747
+ function createInput(options = {}) {
748
+ const { stream, ...overrides } = options;
749
+ if (stream) return {
750
+ kind: "Input",
751
+ meta: {
752
+ circularNames: [],
753
+ enumNames: []
754
+ },
755
+ ...overrides
756
+ };
757
+ return inputDef.create(overrides);
758
+ }
759
+ //#endregion
760
+ //#region src/nodes/requestBody.ts
761
+ /**
762
+ * Definition for the {@link RequestBodyNode}. Content entries are built upfront with
763
+ * {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes.
764
+ */
765
+ const requestBodyDef = defineNode({
766
+ kind: "RequestBody",
767
+ children: ["content"]
768
+ });
769
+ /**
770
+ * Creates a `RequestBodyNode`.
771
+ */
772
+ const createRequestBody = requestBodyDef.create;
773
+ //#endregion
774
+ //#region src/nodes/operation.ts
775
+ /**
776
+ * Definition for the {@link OperationNode}. HTTP operations (those carrying both
777
+ * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
778
+ * normalized into a `RequestBodyNode`.
779
+ */
780
+ const operationDef = defineNode({
781
+ kind: "Operation",
782
+ build: (props) => {
783
+ const { requestBody, ...rest } = props;
784
+ const isHttp = rest.method !== void 0 && rest.path !== void 0;
785
+ return {
786
+ tags: [],
787
+ parameters: [],
788
+ responses: [],
789
+ ...rest,
790
+ ...isHttp ? { protocol: "http" } : {},
791
+ requestBody: requestBody ? createRequestBody(requestBody) : void 0
792
+ };
793
+ },
794
+ children: [
795
+ "parameters",
796
+ "requestBody",
797
+ "responses"
798
+ ],
799
+ visitorKey: "operation"
800
+ });
801
+ function createOperation(props) {
802
+ return operationDef.create(props);
803
+ }
804
+ //#endregion
805
+ //#region src/nodes/output.ts
806
+ /**
807
+ * Definition for the {@link OutputNode}.
808
+ */
809
+ const outputDef = defineNode({
810
+ kind: "Output",
811
+ defaults: { files: [] },
812
+ visitorKey: "output"
813
+ });
814
+ /**
815
+ * Creates an `OutputNode` with a stable default for `files`.
816
+ *
817
+ * @example
818
+ * ```ts
819
+ * const output = createOutput()
820
+ * // { kind: 'Output', files: [] }
821
+ * ```
822
+ */
823
+ function createOutput(overrides = {}) {
824
+ return outputDef.create(overrides);
825
+ }
826
+ //#endregion
827
+ //#region src/optionality.ts
828
+ /**
829
+ * Generic JSON Schema optionality: a non-required field is optional, and a
830
+ * non-required nullable field is nullish.
831
+ */
832
+ function optionality(schema, required) {
833
+ const nullable = schema.nullable ?? false;
834
+ return {
835
+ ...schema,
836
+ optional: !required && !nullable ? true : void 0,
837
+ nullish: !required && nullable ? true : void 0
838
+ };
839
+ }
840
+ //#endregion
841
+ //#region src/nodes/parameter.ts
842
+ /**
843
+ * Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's
844
+ * `optional`/`nullish` flags are derived from it through {@link optionality}.
845
+ */
846
+ const parameterDef = defineNode({
847
+ kind: "Parameter",
848
+ build: (props) => {
849
+ const required = props.required ?? false;
850
+ return {
851
+ ...props,
852
+ required,
853
+ schema: optionality(props.schema, required)
854
+ };
855
+ },
856
+ children: ["schema"],
857
+ visitorKey: "parameter"
858
+ });
859
+ /**
860
+ * Creates a `ParameterNode`.
861
+ *
862
+ * @example
863
+ * ```ts
864
+ * const param = createParameter({
865
+ * name: 'petId',
866
+ * in: 'path',
867
+ * required: true,
868
+ * schema: createSchema({ type: 'string' }),
869
+ * })
870
+ * ```
871
+ */
872
+ const createParameter = parameterDef.create;
873
+ //#endregion
874
+ //#region src/nodes/property.ts
875
+ /**
876
+ * Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's
877
+ * `optional`/`nullish` flags are derived from it through {@link optionality}.
878
+ */
879
+ const propertyDef = defineNode({
880
+ kind: "Property",
881
+ build: (props) => {
882
+ const required = props.required ?? false;
883
+ return {
884
+ ...props,
885
+ required,
886
+ schema: optionality(props.schema, required)
887
+ };
888
+ },
889
+ children: ["schema"],
890
+ visitorKey: "property"
891
+ });
892
+ /**
893
+ * Creates a `PropertyNode`.
894
+ *
895
+ * @example
896
+ * ```ts
897
+ * const property = createProperty({
898
+ * name: 'status',
899
+ * required: true,
900
+ * schema: createSchema({ type: 'string', nullable: true }),
901
+ * })
902
+ * // required=true, no optional/nullish
903
+ * ```
904
+ */
905
+ const createProperty = propertyDef.create;
906
+ //#endregion
907
+ //#region src/nodes/response.ts
908
+ /**
909
+ * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
910
+ * `mediaType`/`keysToOmit`) is normalized into one `content` entry.
911
+ */
912
+ const responseDef = defineNode({
913
+ kind: "Response",
914
+ build: (props) => {
915
+ const { schema, mediaType, keysToOmit, content, ...rest } = props;
916
+ const entries = content ?? (schema ? [createContent({
917
+ contentType: mediaType ?? "application/json",
918
+ schema,
919
+ keysToOmit: keysToOmit ?? null
920
+ })] : void 0);
921
+ return {
922
+ ...rest,
923
+ content: entries
924
+ };
925
+ },
926
+ children: ["content"],
927
+ visitorKey: "response"
928
+ });
929
+ /**
930
+ * Creates a `ResponseNode`.
931
+ *
932
+ * @example
933
+ * ```ts
934
+ * const response = createResponse({
935
+ * statusCode: '200',
936
+ * content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })],
937
+ * })
938
+ * ```
939
+ */
940
+ const createResponse = responseDef.create;
941
+ //#endregion
942
+ //#region src/nodes/schema.ts
943
+ /**
944
+ * Maps schema `type` to its underlying `primitive`.
945
+ * Primitive types map to themselves and special string formats map to `'string'`.
946
+ * Any type not listed here (such as `ref`, `enum`, `union`, `intersection`, `tuple`, `ipv4`, `ipv6`, `blob`) has no `primitive`.
947
+ */
948
+ const TYPE_TO_PRIMITIVE = {
949
+ string: "string",
950
+ number: "number",
951
+ integer: "integer",
952
+ bigint: "bigint",
953
+ boolean: "boolean",
954
+ null: "null",
955
+ any: "any",
956
+ unknown: "unknown",
957
+ void: "void",
958
+ never: "never",
959
+ object: "object",
960
+ array: "array",
961
+ date: "date",
962
+ uuid: "string",
963
+ email: "string",
964
+ url: "string",
965
+ datetime: "string",
966
+ time: "string"
967
+ };
968
+ /**
969
+ * Definition for the {@link SchemaNode}. Object schemas default `properties` to an
970
+ * empty array, and `primitive` is inferred from `type` when not explicitly provided.
971
+ */
972
+ const schemaDef = defineNode({
973
+ kind: "Schema",
974
+ build: (props) => {
975
+ if (props.type === "object") return {
976
+ properties: [],
977
+ primitive: "object",
978
+ ...props
979
+ };
980
+ return {
981
+ primitive: TYPE_TO_PRIMITIVE[props.type],
982
+ ...props
983
+ };
984
+ },
985
+ children: [
986
+ "properties",
987
+ "items",
988
+ "members",
989
+ "additionalProperties"
990
+ ],
991
+ visitorKey: "schema"
992
+ });
993
+ function createSchema(props) {
994
+ return schemaDef.create(props);
995
+ }
996
+ //#endregion
997
+ //#region src/registry.ts
998
+ /**
999
+ * Every node definition. Adding a node means adding its `defineNode` to one
1000
+ * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
1001
+ */
1002
+ const nodeDefs = [
1003
+ inputDef,
1004
+ outputDef,
1005
+ operationDef,
1006
+ requestBodyDef,
1007
+ contentDef,
1008
+ responseDef,
1009
+ schemaDef,
1010
+ propertyDef,
1011
+ parameterDef,
1012
+ constDef,
1013
+ typeDef,
1014
+ functionDef,
1015
+ arrowFunctionDef,
1016
+ textDef,
1017
+ breakDef,
1018
+ jsxDef,
1019
+ importDef,
1020
+ exportDef,
1021
+ sourceDef,
1022
+ fileDef
1023
+ ];
1024
+ //#endregion
1025
+ //#region src/visitor.ts
1026
+ /**
1027
+ * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).
1028
+ * Derived from each definition's `children`.
1029
+ */
1030
+ const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : []));
1031
+ /**
1032
+ * Maps a node kind to the matching visitor callback name. Derived from each
1033
+ * definition's `visitorKey`.
1034
+ */
1035
+ const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : []));
1036
+ /**
1037
+ * Creates a small async concurrency limiter.
1038
+ *
1039
+ * At most `concurrency` tasks are in flight at once. Extra tasks are queued.
1040
+ *
1041
+ * @example
1042
+ * ```ts
1043
+ * const limit = createLimit(2)
1044
+ * for (const task of [taskA, taskB, taskC]) {
1045
+ * await limit(() => task())
1046
+ * }
1047
+ * // only 2 tasks run at the same time
1048
+ * ```
1049
+ */
1050
+ function createLimit(concurrency) {
1051
+ let active = 0;
1052
+ const queue = [];
1053
+ function next() {
1054
+ if (active < concurrency && queue.length > 0) {
1055
+ active++;
1056
+ queue.shift()();
1057
+ }
1058
+ }
1059
+ return function limit(fn) {
1060
+ return new Promise((resolve, reject) => {
1061
+ queue.push(() => {
1062
+ Promise.resolve(fn()).then(resolve, reject).finally(() => {
1063
+ active--;
1064
+ next();
1065
+ });
1066
+ });
1067
+ next();
1068
+ });
1069
+ };
1070
+ }
1071
+ const visitorKeysByKind = VISITOR_KEYS;
1072
+ /**
1073
+ * Returns `true` when `value` is an AST node (an object carrying a `kind`).
1074
+ */
1075
+ function isNode(value) {
1076
+ return typeof value === "object" && value !== null && typeof value.kind === "string";
1077
+ }
1078
+ /**
1079
+ * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.
1080
+ *
1081
+ * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.
1082
+ *
1083
+ * @example
1084
+ * ```ts
1085
+ * const children = getChildren(operationNode, true)
1086
+ * // returns parameters, the request body, and responses
1087
+ * ```
1088
+ */
1089
+ function* getChildren(node, recurse) {
1090
+ if (node.kind === "Schema" && !recurse) return;
1091
+ const keys = visitorKeysByKind[node.kind];
1092
+ if (!keys) return;
1093
+ const record = node;
1094
+ for (const key of keys) {
1095
+ const value = record[key];
1096
+ if (Array.isArray(value)) {
1097
+ for (const item of value) if (isNode(item)) yield item;
1098
+ } else if (isNode(value)) yield value;
1099
+ }
1100
+ }
1101
+ /**
1102
+ * Runs the visitor callback that matches `node.kind` with the traversal
1103
+ * context. The result is a replacement node, a collected value, or `undefined`
1104
+ * when no callback is registered for the kind.
1105
+ *
1106
+ * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives
1107
+ * in one place. `TResult` is the caller's expected return: the same node type
1108
+ * for `transform`, the collected value type for `collectLazy`, ignored for `walk`.
1109
+ */
1110
+ function applyVisitor(node, visitor, parent) {
1111
+ const key = VISITOR_KEY_BY_KIND[node.kind];
1112
+ if (!key) return void 0;
1113
+ const fn = visitor[key];
1114
+ return fn?.(node, { parent });
1115
+ }
1116
+ /**
1117
+ * Async depth-first traversal for side effects. Visitor return values are
1118
+ * ignored. Use `transform` when you want to rewrite nodes.
1119
+ *
1120
+ * Sibling nodes at each depth run concurrently up to `options.concurrency`
1121
+ * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
1122
+ * work. Lower values reduce memory pressure.
1123
+ *
1124
+ * @example Log every operation
1125
+ * ```ts
1126
+ * await walk(root, {
1127
+ * operation(node) {
1128
+ * console.log(node.operationId)
1129
+ * },
1130
+ * })
1131
+ * ```
1132
+ *
1133
+ * @example Only visit the root node
1134
+ * ```ts
1135
+ * await walk(root, { depth: 'shallow', input: () => {} })
1136
+ * ```
1137
+ */
1138
+ async function walk(node, options) {
1139
+ return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0);
1140
+ }
1141
+ async function _walk(node, visitor, recurse, limit, parent) {
1142
+ await limit(() => applyVisitor(node, visitor, parent));
1143
+ let pending;
1144
+ for (const child of getChildren(node, recurse)) (pending ??= []).push(_walk(child, visitor, recurse, limit, node));
1145
+ if (pending) await Promise.all(pending);
1146
+ }
1147
+ function transform(node, options) {
1148
+ const { depth, parent, ...visitor } = options;
1149
+ return transformNode(node, visitor, (depth ?? visitorDepths.deep) === visitorDepths.deep, parent);
1150
+ }
1151
+ /**
1152
+ * Visits a single node, then immutably rebuilds its children. Returns the original
1153
+ * reference when neither the visitor nor the child rebuild changed anything, so callers
1154
+ * can detect "nothing changed" by identity and ancestors avoid reallocating.
1155
+ */
1156
+ function transformNode(node, visitor, recurse, parent) {
1157
+ return transformChildren(applyVisitor(node, visitor, parent) ?? node, visitor, recurse);
1158
+ }
1159
+ /**
1160
+ * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming
1161
+ * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact.
1162
+ * `Schema` children are skipped in shallow mode.
1163
+ */
1164
+ function transformChildren(node, visitor, recurse) {
1165
+ if (node.kind === "Schema" && !recurse) return node;
1166
+ const keys = visitorKeysByKind[node.kind];
1167
+ if (!keys) return node;
1168
+ const record = node;
1169
+ let updates;
1170
+ for (const key of keys) {
1171
+ if (!(key in record)) continue;
1172
+ const value = record[key];
1173
+ if (Array.isArray(value)) {
1174
+ let mapped;
1175
+ for (const [i, item] of value.entries()) {
1176
+ const next = isNode(item) ? transformNode(item, visitor, recurse, node) : item;
1177
+ if (mapped) {
1178
+ mapped.push(next);
1179
+ continue;
1180
+ }
1181
+ if (next !== item) mapped = [...value.slice(0, i), next];
1182
+ }
1183
+ if (mapped) (updates ??= {})[key] = mapped;
1184
+ } else if (isNode(value)) {
1185
+ const next = transformNode(value, visitor, recurse, node);
1186
+ if (next !== value) (updates ??= {})[key] = next;
1187
+ }
1188
+ }
1189
+ return updates ? {
1190
+ ...node,
1191
+ ...updates
1192
+ } : node;
1193
+ }
1194
+ /**
1195
+ * Lazy depth-first collection pass. Yields every non-null value returned by
1196
+ * the visitor callbacks. Use `collect` for the eager array form.
1197
+ *
1198
+ * @example Collect every operationId
1199
+ * ```ts
1200
+ * const ids: string[] = []
1201
+ * for (const id of collectLazy<string>(root, {
1202
+ * operation(node) {
1203
+ * return node.operationId
1204
+ * },
1205
+ * })) {
1206
+ * ids.push(id)
1207
+ * }
1208
+ * ```
1209
+ */
1210
+ function* collectLazy(node, options) {
1211
+ const { depth, parent, ...visitor } = options;
1212
+ yield* collectNode(node, visitor, (depth ?? visitorDepths.deep) === visitorDepths.deep, parent);
1213
+ }
1214
+ function* collectNode(node, visitor, recurse, parent) {
1215
+ const v = applyVisitor(node, visitor, parent);
1216
+ if (v != null) yield v;
1217
+ for (const child of getChildren(node, recurse)) yield* collectNode(child, visitor, recurse, node);
1218
+ }
1219
+ /**
1220
+ * Eager depth-first collection pass. Gathers every non-null value the visitor
1221
+ * callbacks return into an array.
1222
+ *
1223
+ * @example Collect every operationId
1224
+ * ```ts
1225
+ * const ids = collect<string>(root, {
1226
+ * operation(node) {
1227
+ * return node.operationId
1228
+ * },
1229
+ * })
1230
+ * ```
1231
+ */
1232
+ function collect(node, options) {
1233
+ return Array.from(collectLazy(node, options));
1234
+ }
1235
+ //#endregion
1236
+ Object.defineProperty(exports, "__exportAll", {
1237
+ enumerable: true,
1238
+ get: function() {
1239
+ return __exportAll;
1240
+ }
1241
+ });
1242
+ Object.defineProperty(exports, "__name", {
1243
+ enumerable: true,
1244
+ get: function() {
1245
+ return __name;
1246
+ }
1247
+ });
1248
+ Object.defineProperty(exports, "arrowFunctionDef", {
1249
+ enumerable: true,
1250
+ get: function() {
1251
+ return arrowFunctionDef;
1252
+ }
1253
+ });
1254
+ Object.defineProperty(exports, "breakDef", {
1255
+ enumerable: true,
1256
+ get: function() {
1257
+ return breakDef;
1258
+ }
1259
+ });
1260
+ Object.defineProperty(exports, "collect", {
1261
+ enumerable: true,
1262
+ get: function() {
1263
+ return collect;
1264
+ }
1265
+ });
1266
+ Object.defineProperty(exports, "collectLazy", {
1267
+ enumerable: true,
1268
+ get: function() {
1269
+ return collectLazy;
1270
+ }
1271
+ });
1272
+ Object.defineProperty(exports, "constDef", {
1273
+ enumerable: true,
1274
+ get: function() {
1275
+ return constDef;
1276
+ }
1277
+ });
1278
+ Object.defineProperty(exports, "contentDef", {
1279
+ enumerable: true,
1280
+ get: function() {
1281
+ return contentDef;
1282
+ }
1283
+ });
1284
+ Object.defineProperty(exports, "createArrowFunction", {
1285
+ enumerable: true,
1286
+ get: function() {
1287
+ return createArrowFunction;
1288
+ }
1289
+ });
1290
+ Object.defineProperty(exports, "createBreak", {
1291
+ enumerable: true,
1292
+ get: function() {
1293
+ return createBreak;
1294
+ }
1295
+ });
1296
+ Object.defineProperty(exports, "createConst", {
1297
+ enumerable: true,
1298
+ get: function() {
1299
+ return createConst;
1300
+ }
1301
+ });
1302
+ Object.defineProperty(exports, "createContent", {
1303
+ enumerable: true,
1304
+ get: function() {
1305
+ return createContent;
1306
+ }
1307
+ });
1308
+ Object.defineProperty(exports, "createExport", {
1309
+ enumerable: true,
1310
+ get: function() {
1311
+ return createExport;
1312
+ }
1313
+ });
1314
+ Object.defineProperty(exports, "createFile", {
1315
+ enumerable: true,
1316
+ get: function() {
1317
+ return createFile;
1318
+ }
1319
+ });
1320
+ Object.defineProperty(exports, "createFunction", {
1321
+ enumerable: true,
1322
+ get: function() {
1323
+ return createFunction;
1324
+ }
1325
+ });
1326
+ Object.defineProperty(exports, "createImport", {
1327
+ enumerable: true,
1328
+ get: function() {
1329
+ return createImport;
1330
+ }
1331
+ });
1332
+ Object.defineProperty(exports, "createInput", {
1333
+ enumerable: true,
1334
+ get: function() {
1335
+ return createInput;
1336
+ }
1337
+ });
1338
+ Object.defineProperty(exports, "createJsx", {
1339
+ enumerable: true,
1340
+ get: function() {
1341
+ return createJsx;
1342
+ }
1343
+ });
1344
+ Object.defineProperty(exports, "createOperation", {
1345
+ enumerable: true,
1346
+ get: function() {
1347
+ return createOperation;
1348
+ }
1349
+ });
1350
+ Object.defineProperty(exports, "createOutput", {
1351
+ enumerable: true,
1352
+ get: function() {
1353
+ return createOutput;
1354
+ }
1355
+ });
1356
+ Object.defineProperty(exports, "createParameter", {
1357
+ enumerable: true,
1358
+ get: function() {
1359
+ return createParameter;
1360
+ }
1361
+ });
1362
+ Object.defineProperty(exports, "createProperty", {
1363
+ enumerable: true,
1364
+ get: function() {
1365
+ return createProperty;
1366
+ }
1367
+ });
1368
+ Object.defineProperty(exports, "createRequestBody", {
1369
+ enumerable: true,
1370
+ get: function() {
1371
+ return createRequestBody;
1372
+ }
1373
+ });
1374
+ Object.defineProperty(exports, "createResponse", {
1375
+ enumerable: true,
1376
+ get: function() {
1377
+ return createResponse;
1378
+ }
1379
+ });
1380
+ Object.defineProperty(exports, "createSchema", {
1381
+ enumerable: true,
1382
+ get: function() {
1383
+ return createSchema;
1384
+ }
1385
+ });
1386
+ Object.defineProperty(exports, "createSource", {
1387
+ enumerable: true,
1388
+ get: function() {
1389
+ return createSource;
1390
+ }
1391
+ });
1392
+ Object.defineProperty(exports, "createText", {
1393
+ enumerable: true,
1394
+ get: function() {
1395
+ return createText;
1396
+ }
1397
+ });
1398
+ Object.defineProperty(exports, "createType", {
1399
+ enumerable: true,
1400
+ get: function() {
1401
+ return createType;
1402
+ }
1403
+ });
1404
+ Object.defineProperty(exports, "defineNode", {
1405
+ enumerable: true,
1406
+ get: function() {
1407
+ return defineNode;
1408
+ }
1409
+ });
1410
+ Object.defineProperty(exports, "exportDef", {
1411
+ enumerable: true,
1412
+ get: function() {
1413
+ return exportDef;
1414
+ }
1415
+ });
1416
+ Object.defineProperty(exports, "extractStringsFromNodes", {
1417
+ enumerable: true,
1418
+ get: function() {
1419
+ return extractStringsFromNodes;
1420
+ }
1421
+ });
1422
+ Object.defineProperty(exports, "fileDef", {
1423
+ enumerable: true,
1424
+ get: function() {
1425
+ return fileDef;
1426
+ }
1427
+ });
1428
+ Object.defineProperty(exports, "functionDef", {
1429
+ enumerable: true,
1430
+ get: function() {
1431
+ return functionDef;
1432
+ }
1433
+ });
1434
+ Object.defineProperty(exports, "importDef", {
1435
+ enumerable: true,
1436
+ get: function() {
1437
+ return importDef;
1438
+ }
1439
+ });
1440
+ Object.defineProperty(exports, "inputDef", {
1441
+ enumerable: true,
1442
+ get: function() {
1443
+ return inputDef;
1444
+ }
1445
+ });
1446
+ Object.defineProperty(exports, "isHttpOperationNode", {
1447
+ enumerable: true,
1448
+ get: function() {
1449
+ return isHttpOperationNode;
1450
+ }
1451
+ });
1452
+ Object.defineProperty(exports, "jsxDef", {
1453
+ enumerable: true,
1454
+ get: function() {
1455
+ return jsxDef;
1456
+ }
1457
+ });
1458
+ Object.defineProperty(exports, "narrowSchema", {
1459
+ enumerable: true,
1460
+ get: function() {
1461
+ return narrowSchema;
1462
+ }
1463
+ });
1464
+ Object.defineProperty(exports, "nodeDefs", {
1465
+ enumerable: true,
1466
+ get: function() {
1467
+ return nodeDefs;
1468
+ }
1469
+ });
1470
+ Object.defineProperty(exports, "operationDef", {
1471
+ enumerable: true,
1472
+ get: function() {
1473
+ return operationDef;
1474
+ }
1475
+ });
1476
+ Object.defineProperty(exports, "optionality", {
1477
+ enumerable: true,
1478
+ get: function() {
1479
+ return optionality;
1480
+ }
1481
+ });
1482
+ Object.defineProperty(exports, "outputDef", {
1483
+ enumerable: true,
1484
+ get: function() {
1485
+ return outputDef;
1486
+ }
1487
+ });
1488
+ Object.defineProperty(exports, "parameterDef", {
1489
+ enumerable: true,
1490
+ get: function() {
1491
+ return parameterDef;
1492
+ }
1493
+ });
1494
+ Object.defineProperty(exports, "pascalCase", {
1495
+ enumerable: true,
1496
+ get: function() {
1497
+ return pascalCase;
1498
+ }
1499
+ });
1500
+ Object.defineProperty(exports, "propertyDef", {
1501
+ enumerable: true,
1502
+ get: function() {
1503
+ return propertyDef;
1504
+ }
1505
+ });
1506
+ Object.defineProperty(exports, "requestBodyDef", {
1507
+ enumerable: true,
1508
+ get: function() {
1509
+ return requestBodyDef;
1510
+ }
1511
+ });
1512
+ Object.defineProperty(exports, "responseDef", {
1513
+ enumerable: true,
1514
+ get: function() {
1515
+ return responseDef;
1516
+ }
1517
+ });
1518
+ Object.defineProperty(exports, "schemaDef", {
1519
+ enumerable: true,
1520
+ get: function() {
1521
+ return schemaDef;
1522
+ }
1523
+ });
1524
+ Object.defineProperty(exports, "schemaTypes", {
1525
+ enumerable: true,
1526
+ get: function() {
1527
+ return schemaTypes;
1528
+ }
1529
+ });
1530
+ Object.defineProperty(exports, "sourceDef", {
1531
+ enumerable: true,
1532
+ get: function() {
1533
+ return sourceDef;
1534
+ }
1535
+ });
1536
+ Object.defineProperty(exports, "textDef", {
1537
+ enumerable: true,
1538
+ get: function() {
1539
+ return textDef;
1540
+ }
1541
+ });
1542
+ Object.defineProperty(exports, "transform", {
1543
+ enumerable: true,
1544
+ get: function() {
1545
+ return transform;
1546
+ }
1547
+ });
1548
+ Object.defineProperty(exports, "typeDef", {
1549
+ enumerable: true,
1550
+ get: function() {
1551
+ return typeDef;
1552
+ }
1553
+ });
1554
+ Object.defineProperty(exports, "visitorKeys", {
1555
+ enumerable: true,
1556
+ get: function() {
1557
+ return visitorKeys;
1558
+ }
1559
+ });
1560
+ Object.defineProperty(exports, "walk", {
1561
+ enumerable: true,
1562
+ get: function() {
1563
+ return walk;
1564
+ }
1565
+ });
1566
+
1567
+ //# sourceMappingURL=visitor-h6dEM3vR.cjs.map