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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +2 -1
  2. package/dist/defineMacro-BLIR6k-j.d.ts +475 -0
  3. package/dist/defineMacro-BTXvS8nI.js +106 -0
  4. package/dist/defineMacro-BTXvS8nI.js.map +1 -0
  5. package/dist/defineMacro-Bv9R_9a2.cjs +123 -0
  6. package/dist/defineMacro-Bv9R_9a2.cjs.map +1 -0
  7. package/dist/extractStringsFromNodes-Cja-xxx5.js +29 -0
  8. package/dist/extractStringsFromNodes-Cja-xxx5.js.map +1 -0
  9. package/dist/extractStringsFromNodes-DKgDjFO0.cjs +34 -0
  10. package/dist/extractStringsFromNodes-DKgDjFO0.cjs.map +1 -0
  11. package/dist/extractStringsFromNodes-p4mX1TQD.d.ts +14 -0
  12. package/dist/{factory-Du7nEP4B.js → factory-CZNOGI-N.js} +3 -2
  13. package/dist/{factory-Du7nEP4B.js.map → factory-CZNOGI-N.js.map} +1 -1
  14. package/dist/{factory-Cl8Z7mcc.cjs → factory-DG1CVkEb.cjs} +5 -4
  15. package/dist/{factory-Cl8Z7mcc.cjs.map → factory-DG1CVkEb.cjs.map} +1 -1
  16. package/dist/factory.cjs +2 -2
  17. package/dist/factory.js +2 -2
  18. package/dist/index.cjs +22 -20
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +18 -17
  21. package/dist/index.js +7 -4
  22. package/dist/index.js.map +1 -1
  23. package/dist/macros.cjs +117 -0
  24. package/dist/macros.cjs.map +1 -0
  25. package/dist/macros.d.ts +59 -0
  26. package/dist/macros.js +115 -0
  27. package/dist/macros.js.map +1 -0
  28. package/dist/{response-DKxTr522.js → response-KUdWiDWw.js} +36 -61
  29. package/dist/response-KUdWiDWw.js.map +1 -0
  30. package/dist/{response-DS5S3IG4.cjs → response-hnSw2NKE.cjs} +35 -66
  31. package/dist/response-hnSw2NKE.cjs.map +1 -0
  32. package/dist/{types-olVl9v5p.d.ts → types-DyDzizSf.d.ts} +3 -403
  33. package/dist/types.d.ts +4 -3
  34. package/dist/{utils-D83JA6Xx.cjs → utils-BLJwyza-.cjs} +18 -751
  35. package/dist/utils-BLJwyza-.cjs.map +1 -0
  36. package/dist/{utils-Dj_KoXMv.js → utils-CF_-Pn_c.js} +9 -628
  37. package/dist/utils-CF_-Pn_c.js.map +1 -0
  38. package/dist/utils.cjs +12 -10
  39. package/dist/utils.d.ts +28 -2
  40. package/dist/utils.js +4 -3
  41. package/dist/visitor-DJ6ZEJvq.js +548 -0
  42. package/dist/visitor-DJ6ZEJvq.js.map +1 -0
  43. package/dist/visitor-DpKZ9Tk0.cjs +654 -0
  44. package/dist/visitor-DpKZ9Tk0.cjs.map +1 -0
  45. package/package.json +5 -1
  46. package/src/defineMacro.ts +132 -0
  47. package/src/index.ts +3 -7
  48. package/src/macros/index.ts +3 -0
  49. package/src/macros/macroDiscriminatorEnum.ts +44 -0
  50. package/src/macros/macroEnumName.ts +25 -0
  51. package/src/macros/macroSimplifyUnion.ts +50 -0
  52. package/src/types.ts +2 -1
  53. package/src/utils/index.ts +2 -2
  54. package/src/utils/refs.ts +27 -1
  55. package/src/utils/schemaMerge.ts +34 -0
  56. package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +0 -82
  57. package/dist/response-DKxTr522.js.map +0 -1
  58. package/dist/response-DS5S3IG4.cjs.map +0 -1
  59. package/dist/utils-D83JA6Xx.cjs.map +0 -1
  60. package/dist/utils-Dj_KoXMv.js.map +0 -1
  61. package/src/transformers.ts +0 -191
@@ -1,156 +1,5 @@
1
- const require_response = require("./response-DS5S3IG4.cjs");
2
- //#region src/constants.ts
3
- const visitorDepths = {
4
- shallow: "shallow",
5
- deep: "deep"
6
- };
7
- /**
8
- * Schema type discriminators used by all AST schema nodes.
9
- *
10
- * Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
11
- * Call `isScalarPrimitive()` to check for the scalar types.
12
- */
13
- const schemaTypes = {
14
- /**
15
- * Text value.
16
- */
17
- string: "string",
18
- /**
19
- * Floating-point number (`float`, `double`).
20
- */
21
- number: "number",
22
- /**
23
- * Whole number (`int32`). Use `bigint` for `int64`.
24
- */
25
- integer: "integer",
26
- /**
27
- * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
28
- */
29
- bigint: "bigint",
30
- /**
31
- * Boolean value.
32
- */
33
- boolean: "boolean",
34
- /**
35
- * Explicit null value.
36
- */
37
- null: "null",
38
- /**
39
- * Any value (no type restriction).
40
- */
41
- any: "any",
42
- /**
43
- * Unknown value (must be narrowed before usage).
44
- */
45
- unknown: "unknown",
46
- /**
47
- * No return value (`void`).
48
- */
49
- void: "void",
50
- /**
51
- * Object with named properties.
52
- */
53
- object: "object",
54
- /**
55
- * Sequential list of items.
56
- */
57
- array: "array",
58
- /**
59
- * Fixed-length list with position-specific items.
60
- */
61
- tuple: "tuple",
62
- /**
63
- * "One of" multiple schema members.
64
- */
65
- union: "union",
66
- /**
67
- * "All of" multiple schema members.
68
- */
69
- intersection: "intersection",
70
- /**
71
- * Enum schema.
72
- */
73
- enum: "enum",
74
- /**
75
- * Reference to another schema.
76
- */
77
- ref: "ref",
78
- /**
79
- * Calendar date (for example `2026-03-24`).
80
- */
81
- date: "date",
82
- /**
83
- * Date-time value (for example `2026-03-24T09:00:00Z`).
84
- */
85
- datetime: "datetime",
86
- /**
87
- * Time-only value (for example `09:00:00`).
88
- */
89
- time: "time",
90
- /**
91
- * UUID value.
92
- */
93
- uuid: "uuid",
94
- /**
95
- * Email address value.
96
- */
97
- email: "email",
98
- /**
99
- * URL value.
100
- */
101
- url: "url",
102
- /**
103
- * IPv4 address value.
104
- */
105
- ipv4: "ipv4",
106
- /**
107
- * IPv6 address value.
108
- */
109
- ipv6: "ipv6",
110
- /**
111
- * Binary/blob value.
112
- */
113
- blob: "blob",
114
- /**
115
- * Impossible value (`never`).
116
- */
117
- never: "never"
118
- };
119
- /**
120
- * Scalar primitive schema types used for union simplification and type narrowing.
121
- */
122
- const SCALAR_PRIMITIVE_TYPES = new Set([
123
- "string",
124
- "number",
125
- "integer",
126
- "bigint",
127
- "boolean"
128
- ]);
129
- /**
130
- * Returns `true` when `type` is a scalar primitive that can be assigned without wrapping
131
- * (for example `string | number | boolean`).
132
- */
133
- function isScalarPrimitive(type) {
134
- return SCALAR_PRIMITIVE_TYPES.has(type);
135
- }
136
- /**
137
- * HTTP method identifiers used by operation nodes.
138
- */
139
- const httpMethods = {
140
- get: "GET",
141
- post: "POST",
142
- put: "PUT",
143
- patch: "PATCH",
144
- delete: "DELETE",
145
- head: "HEAD",
146
- options: "OPTIONS",
147
- trace: "TRACE"
148
- };
149
- /**
150
- * One indentation level, derived from {@link INDENT_SIZE}.
151
- */
152
- const INDENT = Array.from({ length: 2 }, () => " ").join("");
153
- //#endregion
1
+ const require_response = require("./response-hnSw2NKE.cjs");
2
+ const require_visitor = require("./visitor-DpKZ9Tk0.cjs");
154
3
  //#region ../../internals/utils/src/promise.ts
155
4
  /**
156
5
  * Wraps `factory` with a keyed cache backed by the provided store.
@@ -347,7 +196,7 @@ function buildJSDoc(comments, options = {}) {
347
196
  */
348
197
  function indentLines(text) {
349
198
  if (!text) return "";
350
- return text.split("\n").map((line) => line.trim() ? `${INDENT}${line}` : "").join("\n");
199
+ return text.split("\n").map((line) => line.trim() ? `${require_visitor.INDENT}${line}` : "").join("\n");
351
200
  }
352
201
  /**
353
202
  * Renders an object key, quoting it with single quotes only when it is not a valid identifier.
@@ -397,181 +246,23 @@ function buildList(items, brackets = ["[", "]"]) {
397
246
  return `${open}\n${items.map((item) => `${indentLines(item)},`).join("\n")}\n${close}`;
398
247
  }
399
248
  //#endregion
400
- //#region src/guards.ts
401
- /**
402
- * Narrows a `SchemaNode` to the variant that matches `type`.
403
- *
404
- * @example
405
- * ```ts
406
- * const schema = createSchema({ type: 'string' })
407
- * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
408
- * ```
409
- */
410
- function narrowSchema(node, type) {
411
- return node?.type === type ? node : null;
412
- }
413
- /**
414
- * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
415
- *
416
- * @example
417
- * ```ts
418
- * if (isHttpOperationNode(node)) {
419
- * console.log(node.method, node.path)
420
- * }
421
- * ```
422
- */
423
- function isHttpOperationNode(node) {
424
- return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
425
- }
426
- //#endregion
427
- //#region src/utils/refs.ts
428
- const plainStringTypes = new Set([
429
- "string",
430
- "uuid",
431
- "email",
432
- "url",
433
- "datetime"
434
- ]);
249
+ //#region src/utils/schemaMerge.ts
435
250
  /**
436
- * Returns the last path segment of a reference string.
251
+ * Merges a run of adjacent anonymous object members into one. Named or non-object members break the
252
+ * run and pass through. Stays a construction-time helper, not a macro, so callers keep control of the
253
+ * member boundaries (such as keeping synthetic discriminant objects out of a run).
437
254
  *
438
255
  * @example
439
256
  * ```ts
440
- * extractRefName('#/components/schemas/Pet') // 'Pet'
441
- * ```
442
- */
443
- function extractRefName(ref) {
444
- return ref.split("/").at(-1) ?? ref;
445
- }
446
- /**
447
- * Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
448
- *
449
- * Returns `null` for non-ref nodes or when no name resolves.
450
- *
451
- * @example
452
- * ```ts
453
- * resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })
454
- * // => 'Pet'
455
- * ```
456
- */
457
- function resolveRefName(node) {
458
- if (!node || node.type !== "ref") return null;
459
- if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
460
- return node.name ?? node.schema?.name ?? null;
461
- }
462
- /**
463
- * Builds a PascalCase child schema name by joining a parent name and property name.
464
- * Returns `null` when there is no parent to nest under.
465
- *
466
- * @example
467
- * ```ts
468
- * childName('Order', 'shipping_address') // 'OrderShippingAddress'
469
- * childName(undefined, 'params') // null
470
- * ```
471
- */
472
- function childName(parentName, propName) {
473
- return parentName ? require_response.pascalCase([parentName, propName].join(" ")) : null;
474
- }
475
- /**
476
- * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
477
- * empty parts.
478
- *
479
- * @example
480
- * ```ts
481
- * enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'
482
- * ```
483
- */
484
- function enumPropName(parentName, propName, enumSuffix) {
485
- return require_response.pascalCase([
486
- parentName,
487
- propName,
488
- enumSuffix
489
- ].filter(Boolean).join(" "));
490
- }
491
- /**
492
- * Type guard that returns `true` when a schema emits as a plain `string` type.
493
- *
494
- * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
495
- * types, returns `true` only when `representation` is `'string'` rather than `'date'`.
496
- */
497
- function isStringType(node) {
498
- if (plainStringTypes.has(node.type)) return true;
499
- const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
500
- if (temporal) return temporal.representation !== "date";
501
- return false;
502
- }
503
- /**
504
- * Derives a {@link ParamGroupType} for a query or header group from the resolver.
505
- *
506
- * Returns `null` when there is no resolver, no params, or the group name equals the
507
- * individual param name (so there is no real group to emit).
508
- */
509
- function resolveGroupType({ node, params, group, resolver }) {
510
- if (!resolver || !params.length) return null;
511
- const firstParam = params[0];
512
- const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
513
- if (groupName === resolver.resolveParamName(node, firstParam)) return null;
514
- return {
515
- type: groupName,
516
- optional: params.every((p) => !p.required)
517
- };
518
- }
519
- //#endregion
520
- //#region src/transformers.ts
521
- /**
522
- * Replaces a discriminator property's schema with a string enum of allowed values.
523
- *
524
- * If `node` is not an object schema, or if the property does not exist, the input
525
- * node is returned as-is.
526
- *
527
- * @example
528
- * ```ts
529
- * const schema = createSchema({
530
- * type: 'object',
531
- * properties: [createProperty({ name: 'type', required: true, schema: createSchema({ type: 'string' }) })],
532
- * })
533
- * const result = setDiscriminatorEnum({ node: schema, propertyName: 'type', values: ['dog', 'cat'] })
534
- * ```
535
- */
536
- function setDiscriminatorEnum({ node, propertyName, values, enumName }) {
537
- const objectNode = narrowSchema(node, "object");
538
- if (!objectNode?.properties?.length) return node;
539
- if (!objectNode.properties.some((prop) => prop.name === propertyName)) return node;
540
- return require_response.createSchema({
541
- ...objectNode,
542
- properties: objectNode.properties.map((prop) => {
543
- if (prop.name !== propertyName) return prop;
544
- return require_response.createProperty({
545
- ...prop,
546
- schema: require_response.createSchema({
547
- type: "enum",
548
- primitive: "string",
549
- enumValues: values,
550
- name: enumName,
551
- readOnly: prop.schema.readOnly,
552
- writeOnly: prop.schema.writeOnly
553
- })
554
- });
555
- })
556
- });
557
- }
558
- /**
559
- * Merges adjacent anonymous object members into a single anonymous object member.
560
- *
561
- * @example
562
- * ```ts
563
- * const merged = mergeAdjacentObjects([
564
- * createSchema({ type: 'object', properties: [createProperty({ name: 'a', schema: createSchema({ type: 'string' }) })] }),
565
- * createSchema({ type: 'object', properties: [createProperty({ name: 'b', schema: createSchema({ type: 'number' }) })] }),
566
- * ])
257
+ * const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]
567
258
  * ```
568
259
  */
569
260
  function* mergeAdjacentObjectsLazy(members) {
570
261
  let acc;
571
262
  for (const member of members) {
572
- const objectMember = narrowSchema(member, "object");
263
+ const objectMember = require_visitor.narrowSchema(member, "object");
573
264
  if (objectMember && !objectMember.name && acc !== void 0) {
574
- const accObject = narrowSchema(acc, "object");
265
+ const accObject = require_visitor.narrowSchema(acc, "object");
575
266
  if (accObject && !accObject.name) {
576
267
  acc = require_response.createSchema({
577
268
  ...accObject,
@@ -585,68 +276,6 @@ function* mergeAdjacentObjectsLazy(members) {
585
276
  }
586
277
  if (acc !== void 0) yield acc;
587
278
  }
588
- /**
589
- * Removes enum members that are covered by broader scalar primitives in the same union.
590
- *
591
- * @example
592
- * ```ts
593
- * const simplified = simplifyUnion([
594
- * createSchema({ type: 'enum', primitive: 'string', enumValues: ['active'] }),
595
- * createSchema({ type: 'string' }),
596
- * ])
597
- * // keeps only string member
598
- * ```
599
- */
600
- function simplifyUnion(members) {
601
- const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type));
602
- if (!scalarPrimitives.size) return members;
603
- return members.filter((member) => {
604
- const enumNode = narrowSchema(member, "enum");
605
- if (!enumNode) return true;
606
- const primitive = enumNode.primitive;
607
- if (!primitive) return true;
608
- if ((enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0) <= 1) return true;
609
- if (scalarPrimitives.has(primitive)) return false;
610
- if ((primitive === "integer" || primitive === "number") && (scalarPrimitives.has("integer") || scalarPrimitives.has("number"))) return false;
611
- return true;
612
- });
613
- }
614
- function setEnumName(propNode, parentName, propName, enumSuffix) {
615
- const enumNode = narrowSchema(propNode, "enum");
616
- if (enumNode?.primitive === "boolean") return {
617
- ...propNode,
618
- name: null
619
- };
620
- if (enumNode) return {
621
- ...propNode,
622
- name: enumPropName(parentName, propName, enumSuffix)
623
- };
624
- return propNode;
625
- }
626
- /**
627
- * Merges a ref node with its resolved schema, giving usage-site fields precedence.
628
- *
629
- * Usage-site fields (`description`, `readOnly`, `nullable`, `deprecated`) on the ref node override
630
- * the same fields in the resolved `node.schema`. Non-ref nodes are returned unchanged.
631
- *
632
- * @example
633
- * ```ts
634
- * // Ref with description override
635
- * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
636
- * const merged = syncSchemaRef(ref) // merges with resolved Pet schema
637
- * ```
638
- */
639
- function syncSchemaRef(node) {
640
- const ref = narrowSchema(node, "ref");
641
- if (!ref) return node;
642
- if (!ref.schema) return node;
643
- const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
644
- const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
645
- return require_response.createSchema({
646
- ...ref.schema,
647
- ...definedOverrides
648
- });
649
- }
650
279
  //#endregion
651
280
  //#region src/utils/strings.ts
652
281
  /**
@@ -762,254 +391,6 @@ function getNestedAccessor(param, accessor) {
762
391
  return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
763
392
  }
764
393
  //#endregion
765
- //#region src/registry.ts
766
- /**
767
- * Every node definition. Adding a node means adding its `defineNode` to one
768
- * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
769
- */
770
- const nodeDefs = [
771
- require_response.inputDef,
772
- require_response.outputDef,
773
- require_response.operationDef,
774
- require_response.requestBodyDef,
775
- require_response.contentDef,
776
- require_response.responseDef,
777
- require_response.schemaDef,
778
- require_response.propertyDef,
779
- require_response.parameterDef,
780
- require_response.functionParameterDef,
781
- require_response.functionParametersDef,
782
- require_response.typeLiteralDef,
783
- require_response.indexedAccessTypeDef,
784
- require_response.objectBindingPatternDef,
785
- require_response.constDef,
786
- require_response.typeDef,
787
- require_response.functionDef,
788
- require_response.arrowFunctionDef,
789
- require_response.textDef,
790
- require_response.breakDef,
791
- require_response.jsxDef,
792
- require_response.importDef,
793
- require_response.exportDef,
794
- require_response.sourceDef,
795
- require_response.fileDef
796
- ];
797
- //#endregion
798
- //#region src/visitor.ts
799
- /**
800
- * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).
801
- * Derived from each definition's `children`.
802
- */
803
- const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : []));
804
- /**
805
- * Maps a node kind to the matching visitor callback name. Derived from each
806
- * definition's `visitorKey`.
807
- */
808
- const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : []));
809
- /**
810
- * Per-kind builders rerun after children are rebuilt. Derived from each
811
- * definition's `rebuild` flag.
812
- */
813
- const nodeRebuilders = Object.fromEntries(nodeDefs.flatMap((def) => def.rebuild ? [[def.kind, def.create]] : []));
814
- /**
815
- * Creates a small async concurrency limiter.
816
- *
817
- * At most `concurrency` tasks are in flight at once. Extra tasks are queued.
818
- *
819
- * @example
820
- * ```ts
821
- * const limit = createLimit(2)
822
- * for (const task of [taskA, taskB, taskC]) {
823
- * await limit(() => task())
824
- * }
825
- * // only 2 tasks run at the same time
826
- * ```
827
- */
828
- function createLimit(concurrency) {
829
- let active = 0;
830
- const queue = [];
831
- function next() {
832
- if (active < concurrency && queue.length > 0) {
833
- active++;
834
- queue.shift()();
835
- }
836
- }
837
- return function limit(fn) {
838
- return new Promise((resolve, reject) => {
839
- queue.push(() => {
840
- Promise.resolve(fn()).then(resolve, reject).finally(() => {
841
- active--;
842
- next();
843
- });
844
- });
845
- next();
846
- });
847
- };
848
- }
849
- const visitorKeysByKind = VISITOR_KEYS;
850
- /**
851
- * Returns `true` when `value` is an AST node (an object carrying a `kind`).
852
- */
853
- function isNode(value) {
854
- return typeof value === "object" && value !== null && "kind" in value;
855
- }
856
- /**
857
- * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.
858
- *
859
- * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.
860
- *
861
- * @example
862
- * ```ts
863
- * const children = getChildren(operationNode, true)
864
- * // returns parameters, the request body, and responses
865
- * ```
866
- */
867
- function* getChildren(node, recurse) {
868
- if (node.kind === "Schema" && !recurse) return;
869
- const keys = visitorKeysByKind[node.kind];
870
- if (!keys) return;
871
- const record = node;
872
- for (const key of keys) {
873
- const value = record[key];
874
- if (Array.isArray(value)) {
875
- for (const item of value) if (isNode(item)) yield item;
876
- } else if (isNode(value)) yield value;
877
- }
878
- }
879
- /**
880
- * Runs the visitor callback that matches `node.kind` with the traversal
881
- * context. The result is a replacement node, a collected value, or `undefined`
882
- * when no callback is registered for the kind.
883
- *
884
- * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives
885
- * in one place. `TResult` is the caller's expected return: the same node type
886
- * for `transform`, the collected value type for `collectLazy`, ignored for `walk`.
887
- */
888
- function applyVisitor(node, visitor, parent) {
889
- const key = VISITOR_KEY_BY_KIND[node.kind];
890
- if (!key) return void 0;
891
- const fn = visitor[key];
892
- return fn?.(node, { parent });
893
- }
894
- /**
895
- * Async depth-first traversal for side effects. Visitor return values are
896
- * ignored. Use `transform` when you want to rewrite nodes.
897
- *
898
- * Sibling nodes at each depth run concurrently up to `options.concurrency`
899
- * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
900
- * work. Lower values reduce memory pressure.
901
- *
902
- * @example Log every operation
903
- * ```ts
904
- * await walk(root, {
905
- * operation(node) {
906
- * console.log(node.operationId)
907
- * },
908
- * })
909
- * ```
910
- *
911
- * @example Only visit the root node
912
- * ```ts
913
- * await walk(root, { depth: 'shallow', input: () => {} })
914
- * ```
915
- */
916
- async function walk(node, options) {
917
- return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0);
918
- }
919
- async function _walk(node, visitor, recurse, limit, parent) {
920
- await limit(() => applyVisitor(node, visitor, parent));
921
- const children = Array.from(getChildren(node, recurse));
922
- if (children.length === 0) return;
923
- await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)));
924
- }
925
- function transform(node, options) {
926
- const { depth, parent, ...visitor } = options;
927
- const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
928
- const rebuilt = transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse);
929
- if (rebuilt === node) return node;
930
- const rebuild = nodeRebuilders[rebuilt.kind];
931
- return rebuild ? rebuild(rebuilt) : rebuilt;
932
- }
933
- /**
934
- * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming
935
- * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact.
936
- * `Schema` children are skipped in shallow mode.
937
- */
938
- function transformChildren(node, options, recurse) {
939
- if (node.kind === "Schema" && !recurse) return node;
940
- const keys = visitorKeysByKind[node.kind];
941
- if (!keys) return node;
942
- const record = node;
943
- const childOptions = {
944
- ...options,
945
- parent: node
946
- };
947
- let updates;
948
- for (const key of keys) {
949
- if (!(key in record)) continue;
950
- const value = record[key];
951
- if (Array.isArray(value)) {
952
- let changed = false;
953
- const mapped = value.map((item) => {
954
- if (!isNode(item)) return item;
955
- const next = transform(item, childOptions);
956
- if (next !== item) changed = true;
957
- return next;
958
- });
959
- if (changed) (updates ??= {})[key] = mapped;
960
- } else if (isNode(value)) {
961
- const next = transform(value, childOptions);
962
- if (next !== value) (updates ??= {})[key] = next;
963
- }
964
- }
965
- return updates ? {
966
- ...node,
967
- ...updates
968
- } : node;
969
- }
970
- /**
971
- * Lazy depth-first collection pass. Yields every non-null value returned by
972
- * the visitor callbacks. Use `collect` for the eager array form.
973
- *
974
- * @example Collect every operationId
975
- * ```ts
976
- * const ids: string[] = []
977
- * for (const id of collectLazy<string>(root, {
978
- * operation(node) {
979
- * return node.operationId
980
- * },
981
- * })) {
982
- * ids.push(id)
983
- * }
984
- * ```
985
- */
986
- function* collectLazy(node, options) {
987
- const { depth, parent, ...visitor } = options;
988
- const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
989
- const v = applyVisitor(node, visitor, parent);
990
- if (v != null) yield v;
991
- for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
992
- ...options,
993
- parent: node
994
- });
995
- }
996
- /**
997
- * Eager depth-first collection pass. Gathers every non-null value the visitor
998
- * callbacks return into an array.
999
- *
1000
- * @example Collect every operationId
1001
- * ```ts
1002
- * const ids = collect<string>(root, {
1003
- * operation(node) {
1004
- * return node.operationId
1005
- * },
1006
- * })
1007
- * ```
1008
- */
1009
- function collect(node, options) {
1010
- return Array.from(collectLazy(node, options));
1011
- }
1012
- //#endregion
1013
394
  //#region src/utils/schemaGraph.ts
1014
395
  /**
1015
396
  * Collects every named schema referenced transitively from a node through its ref edges.
@@ -1032,9 +413,9 @@ function collect(node, options) {
1032
413
  */
1033
414
  const collectSchemaRefs = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
1034
415
  const refs = /* @__PURE__ */ new Set();
1035
- collect(node, { schema(child) {
416
+ require_visitor.collect(node, { schema(child) {
1036
417
  if (child.type === "ref") {
1037
- const name = resolveRefName(child);
418
+ const name = require_visitor.resolveRefName(child);
1038
419
  if (name) refs.add(name);
1039
420
  }
1040
421
  } });
@@ -1077,7 +458,7 @@ function computeUsedSchemaNames(operations, schemas) {
1077
458
  if (namedSchema) visitSchema(namedSchema);
1078
459
  }
1079
460
  }
1080
- for (const op of operations) for (const schema of collectLazy(op, {
461
+ for (const op of operations) for (const schema of require_visitor.collectLazy(op, {
1081
462
  depth: "shallow",
1082
463
  schema: (node) => node
1083
464
  })) visitSchema(schema);
@@ -1134,9 +515,9 @@ function findCircularSchemas(schemas) {
1134
515
  */
1135
516
  function containsCircularRef(node, { circularSchemas, excludeName }) {
1136
517
  if (!node || circularSchemas.size === 0) return false;
1137
- for (const _ of collectLazy(node, { schema(child) {
518
+ for (const _ of require_visitor.collectLazy(node, { schema(child) {
1138
519
  if (child.type !== "ref") return null;
1139
- const name = resolveRefName(child);
520
+ const name = require_visitor.resolveRefName(child);
1140
521
  return name && name !== excludeName && circularSchemas.has(name) ? true : null;
1141
522
  } })) return true;
1142
523
  return false;
@@ -1277,7 +658,7 @@ function createOperationParams(node, options) {
1277
658
  name: paramsName,
1278
659
  node,
1279
660
  params: queryParams,
1280
- groupType: resolveGroupType({
661
+ groupType: require_visitor.resolveGroupType({
1281
662
  node,
1282
663
  params: queryParams,
1283
664
  group: "query",
@@ -1289,7 +670,7 @@ function createOperationParams(node, options) {
1289
670
  name: headersName,
1290
671
  node,
1291
672
  params: headerParams,
1292
- groupType: resolveGroupType({
673
+ groupType: require_visitor.resolveGroupType({
1293
674
  node,
1294
675
  params: headerParams,
1295
676
  group: "header",
@@ -1419,24 +800,6 @@ Object.defineProperty(exports, "caseParams", {
1419
800
  return caseParams;
1420
801
  }
1421
802
  });
1422
- Object.defineProperty(exports, "childName", {
1423
- enumerable: true,
1424
- get: function() {
1425
- return childName;
1426
- }
1427
- });
1428
- Object.defineProperty(exports, "collect", {
1429
- enumerable: true,
1430
- get: function() {
1431
- return collect;
1432
- }
1433
- });
1434
- Object.defineProperty(exports, "collectLazy", {
1435
- enumerable: true,
1436
- get: function() {
1437
- return collectLazy;
1438
- }
1439
- });
1440
803
  Object.defineProperty(exports, "collectUsedSchemaNames", {
1441
804
  enumerable: true,
1442
805
  get: function() {
@@ -1455,18 +818,6 @@ Object.defineProperty(exports, "createOperationParams", {
1455
818
  return createOperationParams;
1456
819
  }
1457
820
  });
1458
- Object.defineProperty(exports, "enumPropName", {
1459
- enumerable: true,
1460
- get: function() {
1461
- return enumPropName;
1462
- }
1463
- });
1464
- Object.defineProperty(exports, "extractRefName", {
1465
- enumerable: true,
1466
- get: function() {
1467
- return extractRefName;
1468
- }
1469
- });
1470
821
  Object.defineProperty(exports, "findCircularSchemas", {
1471
822
  enumerable: true,
1472
823
  get: function() {
@@ -1479,24 +830,6 @@ Object.defineProperty(exports, "getNestedAccessor", {
1479
830
  return getNestedAccessor;
1480
831
  }
1481
832
  });
1482
- Object.defineProperty(exports, "httpMethods", {
1483
- enumerable: true,
1484
- get: function() {
1485
- return httpMethods;
1486
- }
1487
- });
1488
- Object.defineProperty(exports, "isHttpOperationNode", {
1489
- enumerable: true,
1490
- get: function() {
1491
- return isHttpOperationNode;
1492
- }
1493
- });
1494
- Object.defineProperty(exports, "isStringType", {
1495
- enumerable: true,
1496
- get: function() {
1497
- return isStringType;
1498
- }
1499
- });
1500
833
  Object.defineProperty(exports, "isValidVarName", {
1501
834
  enumerable: true,
1502
835
  get: function() {
@@ -1539,66 +872,18 @@ Object.defineProperty(exports, "mergeAdjacentObjectsLazy", {
1539
872
  return mergeAdjacentObjectsLazy;
1540
873
  }
1541
874
  });
1542
- Object.defineProperty(exports, "narrowSchema", {
1543
- enumerable: true,
1544
- get: function() {
1545
- return narrowSchema;
1546
- }
1547
- });
1548
- Object.defineProperty(exports, "nodeDefs", {
1549
- enumerable: true,
1550
- get: function() {
1551
- return nodeDefs;
1552
- }
1553
- });
1554
875
  Object.defineProperty(exports, "objectKey", {
1555
876
  enumerable: true,
1556
877
  get: function() {
1557
878
  return objectKey;
1558
879
  }
1559
880
  });
1560
- Object.defineProperty(exports, "resolveGroupType", {
1561
- enumerable: true,
1562
- get: function() {
1563
- return resolveGroupType;
1564
- }
1565
- });
1566
881
  Object.defineProperty(exports, "resolveParamType", {
1567
882
  enumerable: true,
1568
883
  get: function() {
1569
884
  return resolveParamType;
1570
885
  }
1571
886
  });
1572
- Object.defineProperty(exports, "resolveRefName", {
1573
- enumerable: true,
1574
- get: function() {
1575
- return resolveRefName;
1576
- }
1577
- });
1578
- Object.defineProperty(exports, "schemaTypes", {
1579
- enumerable: true,
1580
- get: function() {
1581
- return schemaTypes;
1582
- }
1583
- });
1584
- Object.defineProperty(exports, "setDiscriminatorEnum", {
1585
- enumerable: true,
1586
- get: function() {
1587
- return setDiscriminatorEnum;
1588
- }
1589
- });
1590
- Object.defineProperty(exports, "setEnumName", {
1591
- enumerable: true,
1592
- get: function() {
1593
- return setEnumName;
1594
- }
1595
- });
1596
- Object.defineProperty(exports, "simplifyUnion", {
1597
- enumerable: true,
1598
- get: function() {
1599
- return simplifyUnion;
1600
- }
1601
- });
1602
887
  Object.defineProperty(exports, "stringify", {
1603
888
  enumerable: true,
1604
889
  get: function() {
@@ -1611,35 +896,17 @@ Object.defineProperty(exports, "stringifyObject", {
1611
896
  return stringifyObject;
1612
897
  }
1613
898
  });
1614
- Object.defineProperty(exports, "syncSchemaRef", {
1615
- enumerable: true,
1616
- get: function() {
1617
- return syncSchemaRef;
1618
- }
1619
- });
1620
899
  Object.defineProperty(exports, "toRegExpString", {
1621
900
  enumerable: true,
1622
901
  get: function() {
1623
902
  return toRegExpString;
1624
903
  }
1625
904
  });
1626
- Object.defineProperty(exports, "transform", {
1627
- enumerable: true,
1628
- get: function() {
1629
- return transform;
1630
- }
1631
- });
1632
905
  Object.defineProperty(exports, "trimQuotes", {
1633
906
  enumerable: true,
1634
907
  get: function() {
1635
908
  return trimQuotes;
1636
909
  }
1637
910
  });
1638
- Object.defineProperty(exports, "walk", {
1639
- enumerable: true,
1640
- get: function() {
1641
- return walk;
1642
- }
1643
- });
1644
911
 
1645
- //# sourceMappingURL=utils-D83JA6Xx.cjs.map
912
+ //# sourceMappingURL=utils-BLJwyza-.cjs.map