@kubb/ast 5.22.0 → 5.23.1

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 (155) hide show
  1. package/dist/base-IpYuh3ZP.d.cts +173 -0
  2. package/dist/base-IpYuh3ZP.d.ts +173 -0
  3. package/dist/constants-Ckeonm-D.js +141 -0
  4. package/dist/constants-Ckeonm-D.js.map +1 -0
  5. package/dist/constants-CquR083U.cjs +152 -0
  6. package/dist/constants-CquR083U.cjs.map +1 -0
  7. package/dist/factory.cjs +23 -0
  8. package/dist/factory.d.cts +4 -0
  9. package/dist/factory.d.ts +4 -0
  10. package/dist/factory.js +4 -0
  11. package/dist/file-BVqSiSvV.d.cts +624 -0
  12. package/dist/file-Cg0T6cgz.cjs +319 -0
  13. package/dist/file-Cg0T6cgz.cjs.map +1 -0
  14. package/dist/file-CnuL8oUj.js +283 -0
  15. package/dist/file-CnuL8oUj.js.map +1 -0
  16. package/dist/file-CvlMAp_d.js +131 -0
  17. package/dist/file-CvlMAp_d.js.map +1 -0
  18. package/dist/file-Dd50jPkH.cjs +142 -0
  19. package/dist/file-Dd50jPkH.cjs.map +1 -0
  20. package/dist/file-xJnBQPGq.d.ts +624 -0
  21. package/dist/file.cjs +3 -0
  22. package/dist/file.d.cts +2 -0
  23. package/dist/file.d.ts +2 -0
  24. package/dist/file.js +1 -0
  25. package/dist/graph-BcwFCvei.js +144 -0
  26. package/dist/graph-BcwFCvei.js.map +1 -0
  27. package/dist/graph-DcIY6tQb.cjs +173 -0
  28. package/dist/graph-DcIY6tQb.cjs.map +1 -0
  29. package/dist/graph.cjs +6 -0
  30. package/dist/graph.d.cts +2 -0
  31. package/dist/graph.d.ts +2 -0
  32. package/dist/graph.js +1 -0
  33. package/dist/guards-B8qDgSaT.d.cts +23 -0
  34. package/dist/guards-COVJE6TU.cjs +41 -0
  35. package/dist/guards-COVJE6TU.cjs.map +1 -0
  36. package/dist/guards-D-h9R_sV.d.ts +23 -0
  37. package/dist/guards-DlJkKsT1.js +30 -0
  38. package/dist/guards-DlJkKsT1.js.map +1 -0
  39. package/dist/http-Bm5lhVK4.cjs +12 -0
  40. package/dist/http-Bm5lhVK4.cjs.map +1 -0
  41. package/dist/http-DwboM6pK.js +7 -0
  42. package/dist/http-DwboM6pK.js.map +1 -0
  43. package/dist/http.cjs +4 -0
  44. package/dist/http.d.cts +3 -0
  45. package/dist/http.d.ts +3 -0
  46. package/dist/http.js +2 -0
  47. package/dist/index-BWd95onW.d.cts +5 -0
  48. package/dist/index-Bb1kqq8H.d.cts +20 -0
  49. package/dist/index-BngGJux5.d.cts +12 -0
  50. package/dist/index-BwnMIoLl.d.ts +24 -0
  51. package/dist/index-C-vhkzwR.d.cts +79 -0
  52. package/dist/index-CAGuKv6t.d.ts +74 -0
  53. package/dist/index-CFH4ZC7q.d.ts +44 -0
  54. package/dist/index-CIqwy4EE.d.cts +74 -0
  55. package/dist/index-Cc2K3OzU.d.cts +11 -0
  56. package/dist/index-Cc2K3OzU.d.ts +11 -0
  57. package/dist/index-Csf8xsCc.d.cts +46 -0
  58. package/dist/index-D3M2spDR.d.ts +12 -0
  59. package/dist/index-DNiIem0x.d.ts +79 -0
  60. package/dist/index-DSVef1pp.d.cts +24 -0
  61. package/dist/index-DU_jYpBt.d.cts +44 -0
  62. package/dist/index-DYDha-3I.d.cts +67 -0
  63. package/dist/index-DaHsMJ_S.d.ts +5 -0
  64. package/dist/index-Dp50LM3a.d.ts +67 -0
  65. package/dist/index-cpjUxIik.d.ts +46 -0
  66. package/dist/index-eGkM4FE9.d.ts +20 -0
  67. package/dist/index.cjs +87 -2131
  68. package/dist/index.cjs.map +1 -1
  69. package/dist/index.d.cts +25 -2745
  70. package/dist/index.d.ts +25 -2745
  71. package/dist/index.js +40 -2052
  72. package/dist/index.js.map +1 -1
  73. package/dist/json-DH7_lcWm.js +74 -0
  74. package/dist/json-DH7_lcWm.js.map +1 -0
  75. package/dist/json-DURdtz9A.cjs +91 -0
  76. package/dist/json-DURdtz9A.cjs.map +1 -0
  77. package/dist/json.cjs +4 -0
  78. package/dist/json.d.cts +2 -0
  79. package/dist/json.d.ts +2 -0
  80. package/dist/json.js +1 -0
  81. package/dist/macro-D0KfNtff.js +104 -0
  82. package/dist/macro-D0KfNtff.js.map +1 -0
  83. package/dist/macro-DrTBT7fh.cjs +127 -0
  84. package/dist/macro-DrTBT7fh.cjs.map +1 -0
  85. package/dist/macro.cjs +4 -0
  86. package/dist/macro.d.cts +2 -0
  87. package/dist/macro.d.ts +2 -0
  88. package/dist/macro.js +1 -0
  89. package/dist/mediaType-CRjggmoG.js +19 -0
  90. package/dist/mediaType-CRjggmoG.js.map +1 -0
  91. package/dist/mediaType-D8uIO8sG.cjs +35 -0
  92. package/dist/mediaType-D8uIO8sG.cjs.map +1 -0
  93. package/dist/mediaType.cjs +4 -0
  94. package/dist/mediaType.d.cts +2 -0
  95. package/dist/mediaType.d.ts +2 -0
  96. package/dist/mediaType.js +1 -0
  97. package/dist/node-DjcETnc8.cjs +19 -0
  98. package/dist/node-DjcETnc8.cjs.map +1 -0
  99. package/dist/node-Djh-mZB2.js +14 -0
  100. package/dist/node-Djh-mZB2.js.map +1 -0
  101. package/dist/node.cjs +9 -0
  102. package/dist/node.d.cts +4 -0
  103. package/dist/node.d.ts +4 -0
  104. package/dist/node.js +5 -0
  105. package/dist/nodeText-DRb_rVd1.cjs +58 -0
  106. package/dist/nodeText-DRb_rVd1.cjs.map +1 -0
  107. package/dist/nodeText-DVVDZQjF.js +47 -0
  108. package/dist/nodeText-DVVDZQjF.js.map +1 -0
  109. package/dist/nodes-BB60Bq2H.cjs +320 -0
  110. package/dist/nodes-BB60Bq2H.cjs.map +1 -0
  111. package/dist/nodes-CWMa9xhW.js +231 -0
  112. package/dist/nodes-CWMa9xhW.js.map +1 -0
  113. package/dist/operation-BgRyVS7z.d.ts +1272 -0
  114. package/dist/operation-X7chCdL2.d.cts +1272 -0
  115. package/dist/optionality-D-zqzVMH.cjs +22 -0
  116. package/dist/optionality-D-zqzVMH.cjs.map +1 -0
  117. package/dist/optionality-DISn8ytP.js +17 -0
  118. package/dist/optionality-DISn8ytP.js.map +1 -0
  119. package/dist/promise-BOdlgT0N.cjs +50 -0
  120. package/dist/promise-BOdlgT0N.cjs.map +1 -0
  121. package/dist/promise-RpnEev9D.js +45 -0
  122. package/dist/promise-RpnEev9D.js.map +1 -0
  123. package/dist/ref-Bu7PoHar.js +22 -0
  124. package/dist/ref-Bu7PoHar.js.map +1 -0
  125. package/dist/ref-P0ZLT1Bg.cjs +39 -0
  126. package/dist/ref-P0ZLT1Bg.cjs.map +1 -0
  127. package/dist/ref.cjs +7 -0
  128. package/dist/ref.d.cts +2 -0
  129. package/dist/ref.d.ts +2 -0
  130. package/dist/ref.js +3 -0
  131. package/dist/refs-CYHpRlQo.cjs +131 -0
  132. package/dist/refs-CYHpRlQo.cjs.map +1 -0
  133. package/dist/refs-YCV3CznS.js +102 -0
  134. package/dist/refs-YCV3CznS.js.map +1 -0
  135. package/dist/rolldown-runtime-BV8xUvPy.cjs +52 -0
  136. package/dist/rolldown-runtime-BYyVTPww.js +16 -0
  137. package/dist/schema-2ZAQk7qE.js +44 -0
  138. package/dist/schema-2ZAQk7qE.js.map +1 -0
  139. package/dist/schema-BIErWqgc.cjs +214 -0
  140. package/dist/schema-BIErWqgc.cjs.map +1 -0
  141. package/dist/schema-DloctnMm.js +179 -0
  142. package/dist/schema-DloctnMm.js.map +1 -0
  143. package/dist/schema-hxMlgCrV.cjs +49 -0
  144. package/dist/schema-hxMlgCrV.cjs.map +1 -0
  145. package/dist/schema.cjs +16 -0
  146. package/dist/schema.d.cts +5 -0
  147. package/dist/schema.d.ts +5 -0
  148. package/dist/schema.js +6 -0
  149. package/dist/visitor-BZozlXBF.d.ts +179 -0
  150. package/dist/visitor-Bw_opzjF.d.cts +179 -0
  151. package/dist/visitor-DTrzvA3R.cjs +382 -0
  152. package/dist/visitor-DTrzvA3R.cjs.map +1 -0
  153. package/dist/visitor-NoQSUQTu.js +347 -0
  154. package/dist/visitor-NoQSUQTu.js.map +1 -0
  155. package/package.json +101 -1
@@ -0,0 +1,144 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
2
+ import { t as memo } from "./promise-RpnEev9D.js";
3
+ import { t as nodeKinds } from "./constants-Ckeonm-D.js";
4
+ import { i as visitChildNodes, t as collect } from "./visitor-NoQSUQTu.js";
5
+ import { a as resolveRefName } from "./refs-YCV3CznS.js";
6
+ // src/utils/schemaGraph.ts
7
+ const refEntries = memo.create({ weak: true });
8
+ const checkRefEntries = memo.create({ weak: true });
9
+ const schemaRefs = memo.create({ weak: true });
10
+ const importedRefNames = memo.create({ weak: true });
11
+ const importedCheckRefNames = memo.create({ weak: true });
12
+ /**
13
+ * Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved
14
+ * name plus whether the ref carries a `$ref` pointer. Memoized per node and per `checks` mode, so
15
+ * each helper below scans a schema once.
16
+ */
17
+ function collectRefEntries(node, { checks }) {
18
+ return memo(checks ? checkRefEntries : refEntries, node, () => {
19
+ const entries = [];
20
+ const walk = (current) => {
21
+ if (current.kind === nodeKinds.schema && current.type === "ref") {
22
+ const name = resolveRefName(current);
23
+ if (name) entries.push({
24
+ name,
25
+ hasPointer: Boolean(current.ref)
26
+ });
27
+ }
28
+ visitChildNodes(current, walk, { checks });
29
+ return false;
30
+ };
31
+ walk(node);
32
+ return entries;
33
+ });
34
+ }
35
+ /**
36
+ * Collects the names of every schema a node's subtree references, resolved with `ast.ref.getName`.
37
+ * Each ref contributes its name only, so the schema it points to is never traversed. Memoized by
38
+ * node identity, so repeated calls on one schema scan it once.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * collectSchemaRefs(petSchema)
43
+ * // Set { 'Category', 'Tag' }
44
+ * ```
45
+ */
46
+ function collectSchemaRefs(node) {
47
+ return memo(schemaRefs, node, () => new Set(collectRefEntries(node, { checks: true }).map((entry) => entry.name)));
48
+ }
49
+ /**
50
+ * Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
51
+ * first-occurrence order. Memoized by node identity, so `resolver.imports` reads the same result
52
+ * across the ts, zod, and faker plugins instead of re-scanning the same schema per plugin.
53
+ *
54
+ * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
55
+ * same file (a union member created by name) is left out. That leaves exactly the set
56
+ * `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with
57
+ * `checks: true`, for a plugin that prints those checks.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * collectImportedRefNames(petSchema)
62
+ * // ['Category', 'Tag']
63
+ * ```
64
+ */
65
+ function collectImportedRefNames(node, { checks = false } = {}) {
66
+ return memo(checks ? importedCheckRefNames : importedRefNames, node, () => [...new Set(collectRefEntries(node, { checks }).flatMap((entry) => entry.hasPointer ? [entry.name] : []))]);
67
+ }
68
+ /**
69
+ * Collects the names of all top-level schemas transitively used by a set of operations.
70
+ *
71
+ * An operation uses a schema when its parameters, request body, or responses reference it, directly
72
+ * or through other named schemas. Once a name is added to the result it is not revisited, so
73
+ * reference cycles terminate.
74
+ *
75
+ * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
76
+ *
77
+ * @example Only generate schemas referenced by included operations
78
+ * ```ts
79
+ * const includedOps = operations.filter((op) => resolver.default.options(op, { options, include }) !== null)
80
+ * const allowed = collectUsedSchemaNames(includedOps, schemas)
81
+ *
82
+ * for (const schema of schemas) {
83
+ * if (schema.name && !allowed.has(schema.name)) continue
84
+ * // generate schema
85
+ * }
86
+ * ```
87
+ */
88
+ function collectUsedSchemaNames(operations, schemas) {
89
+ const schemaMap = /* @__PURE__ */ new Map();
90
+ for (const schema of schemas) if (schema.name) schemaMap.set(schema.name, schema);
91
+ const result = /* @__PURE__ */ new Set();
92
+ function visitSchema(schema) {
93
+ for (const name of collectSchemaRefs(schema)) if (!result.has(name)) {
94
+ result.add(name);
95
+ const namedSchema = schemaMap.get(name);
96
+ if (namedSchema) visitSchema(namedSchema);
97
+ }
98
+ }
99
+ for (const op of operations) for (const schema of collect(op, {
100
+ depth: "shallow",
101
+ schema: (node) => node
102
+ })) visitSchema(schema);
103
+ return result;
104
+ }
105
+ /**
106
+ * Finds every schema that takes part in a circular dependency chain, including direct self-loops.
107
+ *
108
+ * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so
109
+ * the generated code does not recurse forever. Refs are followed by name only, so the walk stays
110
+ * linear in the size of the schema graph.
111
+ *
112
+ * @note Call this once on the full graph, then check a schema's `ast.graph.getRefNames` against the result.
113
+ */
114
+ function findCircularSchemas(schemas) {
115
+ const graph = /* @__PURE__ */ new Map();
116
+ for (const schema of schemas) if (schema.name) graph.set(schema.name, collectSchemaRefs(schema));
117
+ const circular = /* @__PURE__ */ new Set();
118
+ for (const start of graph.keys()) {
119
+ const visited = /* @__PURE__ */ new Set();
120
+ const stack = [...graph.get(start) ?? []];
121
+ while (stack.length > 0) {
122
+ const node = stack.pop();
123
+ if (node === start) {
124
+ circular.add(start);
125
+ break;
126
+ }
127
+ if (visited.has(node)) continue;
128
+ visited.add(node);
129
+ const next = graph.get(node);
130
+ if (next) for (const r of next) stack.push(r);
131
+ }
132
+ }
133
+ return circular;
134
+ }
135
+ // src/graph/index.ts
136
+ var graph_exports = /* @__PURE__ */ __exportAll({
137
+ getCircularNames: () => findCircularSchemas,
138
+ getImportedNames: () => collectImportedRefNames,
139
+ getRefNames: () => collectSchemaRefs,
140
+ getUsedNames: () => collectUsedSchemaNames
141
+ });
142
+ export { findCircularSchemas as a, collectUsedSchemaNames as i, collectImportedRefNames as n, collectSchemaRefs as r, graph_exports as t };
143
+
144
+ //# sourceMappingURL=graph-BcwFCvei.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-BcwFCvei.js","names":[],"sources":["../src/utils/schemaGraph.ts","../src/graph/index.ts"],"sourcesContent":["import { memo } from '@internals/utils'\nimport { nodeKinds } from '../constants.ts'\nimport type { Node } from '../nodes/index.ts'\nimport type { OperationNode } from '../nodes/operation.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\nimport { collect, visitChildNodes } from '../visitor.ts'\nimport { resolveRefName } from './refs.ts'\n\ntype RefEntry = { name: string; hasPointer: boolean }\n\nconst refEntries = memo.create<SchemaNode, ReadonlyArray<RefEntry>>({ weak: true })\nconst checkRefEntries = memo.create<SchemaNode, ReadonlyArray<RefEntry>>({ weak: true })\nconst schemaRefs = memo.create<SchemaNode, ReadonlySet<string>>({ weak: true })\nconst importedRefNames = memo.create<SchemaNode, ReadonlyArray<string>>({ weak: true })\nconst importedCheckRefNames = memo.create<SchemaNode, ReadonlyArray<string>>({ weak: true })\n\n/**\n * Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved\n * name plus whether the ref carries a `$ref` pointer. Memoized per node and per `checks` mode, so\n * each helper below scans a schema once.\n */\nfunction collectRefEntries(node: SchemaNode, { checks }: { checks: boolean }): ReadonlyArray<RefEntry> {\n return memo(checks ? checkRefEntries : refEntries, node, () => {\n const entries: Array<RefEntry> = []\n const walk = (current: Node): boolean => {\n if (current.kind === nodeKinds.schema && current.type === 'ref') {\n const name = resolveRefName(current)\n if (name) entries.push({ name, hasPointer: Boolean(current.ref) })\n }\n visitChildNodes(current, walk, { checks })\n return false\n }\n walk(node)\n return entries\n })\n}\n\n/**\n * Collects the names of every schema a node's subtree references, resolved with `ast.ref.getName`.\n * Each ref contributes its name only, so the schema it points to is never traversed. Memoized by\n * node identity, so repeated calls on one schema scan it once.\n *\n * @example\n * ```ts\n * collectSchemaRefs(petSchema)\n * // Set { 'Category', 'Tag' }\n * ```\n */\nexport function collectSchemaRefs(node: SchemaNode): ReadonlySet<string> {\n return memo(schemaRefs, node, () => new Set(collectRefEntries(node, { checks: true }).map((entry) => entry.name)))\n}\n\n/**\n * Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in\n * first-occurrence order. Memoized by node identity, so `resolver.imports` reads the same result\n * across the ts, zod, and faker plugins instead of re-scanning the same schema per plugin.\n *\n * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the\n * same file (a union member created by name) is left out. That leaves exactly the set\n * `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with\n * `checks: true`, for a plugin that prints those checks.\n *\n * @example\n * ```ts\n * collectImportedRefNames(petSchema)\n * // ['Category', 'Tag']\n * ```\n */\nexport function collectImportedRefNames(node: SchemaNode, { checks = false }: { checks?: boolean } = {}): ReadonlyArray<string> {\n return memo(checks ? importedCheckRefNames : importedRefNames, node, () => [\n ...new Set(collectRefEntries(node, { checks }).flatMap((entry) => (entry.hasPointer ? [entry.name] : []))),\n ])\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when its parameters, request body, or responses reference it, directly\n * or through other named schemas. Once a name is added to the result it is not revisited, so\n * reference cycles terminate.\n *\n * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter((op) => resolver.default.options(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // generate schema\n * }\n * ```\n */\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n for (const name of collectSchemaRefs(schema)) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collect<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\n/**\n * Finds every schema that takes part in a circular dependency chain, including direct self-loops.\n *\n * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so\n * the generated code does not recurse forever. Refs are followed by name only, so the walk stays\n * linear in the size of the schema graph.\n *\n * @note Call this once on the full graph, then check a schema's `ast.graph.getRefNames` against the result.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const graph = new Map<string, ReadonlySet<string>>()\n for (const schema of schemas) {\n if (schema.name) graph.set(schema.name, collectSchemaRefs(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n}\n","export {\n collectImportedRefNames as getImportedNames,\n collectSchemaRefs as getRefNames,\n collectUsedSchemaNames as getUsedNames,\n findCircularSchemas as getCircularNames,\n} from '../utils/schemaGraph.ts'\n"],"mappings":";;;;;;AAUA,MAAM,aAAa,KAAK,OAA4C,EAAE,MAAM,KAAK,CAAC;AAClF,MAAM,kBAAkB,KAAK,OAA4C,EAAE,MAAM,KAAK,CAAC;AACvF,MAAM,aAAa,KAAK,OAAwC,EAAE,MAAM,KAAK,CAAC;AAC9E,MAAM,mBAAmB,KAAK,OAA0C,EAAE,MAAM,KAAK,CAAC;AACtF,MAAM,wBAAwB,KAAK,OAA0C,EAAE,MAAM,KAAK,CAAC;;;;;;AAO3F,SAAS,kBAAkB,MAAkB,EAAE,UAAwD;CACrG,OAAO,KAAK,SAAS,kBAAkB,YAAY,YAAY;EAC7D,MAAM,UAA2B,CAAC;EAClC,MAAM,QAAQ,YAA2B;GACvC,IAAI,QAAQ,SAAS,UAAU,UAAU,QAAQ,SAAS,OAAO;IAC/D,MAAM,OAAO,eAAe,OAAO;IACnC,IAAI,MAAM,QAAQ,KAAK;KAAE;KAAM,YAAY,QAAQ,QAAQ,GAAG;IAAE,CAAC;GACnE;GACA,gBAAgB,SAAS,MAAM,EAAE,OAAO,CAAC;GACzC,OAAO;EACT;EACA,KAAK,IAAI;EACT,OAAO;CACT,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,kBAAkB,MAAuC;CACvE,OAAO,KAAK,YAAY,YAAY,IAAI,IAAI,kBAAkB,MAAM,EAAE,QAAQ,KAAK,CAAC,CAAC,CAAC,KAAK,UAAU,MAAM,IAAI,CAAC,CAAC;AACnH;;;;;;;;;;;;;;;;;AAkBA,SAAgB,wBAAwB,MAAkB,EAAE,SAAS,UAAgC,CAAC,GAA0B;CAC9H,OAAO,KAAK,SAAS,wBAAwB,kBAAkB,YAAY,CACzE,GAAG,IAAI,IAAI,kBAAkB,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,UAAW,MAAM,aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,CAAE,CAAC,CAC3G,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,uBAAuB,YAA0C,SAAiD;CAChI,MAAM,4BAAY,IAAI,IAAwB;CAC9C,KAAK,MAAM,UAAU,SACnB,IAAI,OAAO,MAAM,UAAU,IAAI,OAAO,MAAM,MAAM;CAGpD,MAAM,yBAAS,IAAI,IAAY;CAE/B,SAAS,YAAY,QAA0B;EAC7C,KAAK,MAAM,QAAQ,kBAAkB,MAAM,GACzC,IAAI,CAAC,OAAO,IAAI,IAAI,GAAG;GACrB,OAAO,IAAI,IAAI;GACf,MAAM,cAAc,UAAU,IAAI,IAAI;GACtC,IAAI,aAAa,YAAY,WAAW;EAC1C;CAEJ;CAEA,KAAK,MAAM,MAAM,YACf,KAAK,MAAM,UAAU,QAAoB,IAAI;EAAE,OAAO;EAAW,SAAS,SAAS;CAAK,CAAC,GACvF,YAAY,MAAM;CAItB,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,oBAAoB,SAAiD;CACnF,MAAM,wBAAQ,IAAI,IAAiC;CACnD,KAAK,MAAM,UAAU,SACnB,IAAI,OAAO,MAAM,MAAM,IAAI,OAAO,MAAM,kBAAkB,MAAM,CAAC;CAGnE,MAAM,2BAAW,IAAI,IAAY;CACjC,KAAK,MAAM,SAAS,MAAM,KAAK,GAAG;EAChC,MAAM,0BAAU,IAAI,IAAY;EAChC,MAAM,QAAuB,CAAC,GAAI,MAAM,IAAI,KAAK,KAAK,CAAC,CAAE;EACzD,OAAO,MAAM,SAAS,GAAG;GACvB,MAAM,OAAO,MAAM,IAAI;GACvB,IAAI,SAAS,OAAO;IAClB,SAAS,IAAI,KAAK;IAClB;GACF;GACA,IAAI,QAAQ,IAAI,IAAI,GAAG;GACvB,QAAQ,IAAI,IAAI;GAEhB,MAAM,OAAO,MAAM,IAAI,IAAI;GAC3B,IAAI,MAAM,KAAK,MAAM,KAAK,MAAM,MAAM,KAAK,CAAC;EAC9C;CACF;CAEA,OAAO;AACT"}
@@ -0,0 +1,173 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
2
+ const require_promise = require("./promise-BOdlgT0N.cjs");
3
+ const require_constants = require("./constants-CquR083U.cjs");
4
+ const require_visitor = require("./visitor-DTrzvA3R.cjs");
5
+ const require_refs = require("./refs-CYHpRlQo.cjs");
6
+ // src/utils/schemaGraph.ts
7
+ const refEntries = require_promise.memo.create({ weak: true });
8
+ const checkRefEntries = require_promise.memo.create({ weak: true });
9
+ const schemaRefs = require_promise.memo.create({ weak: true });
10
+ const importedRefNames = require_promise.memo.create({ weak: true });
11
+ const importedCheckRefNames = require_promise.memo.create({ weak: true });
12
+ /**
13
+ * Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved
14
+ * name plus whether the ref carries a `$ref` pointer. Memoized per node and per `checks` mode, so
15
+ * each helper below scans a schema once.
16
+ */
17
+ function collectRefEntries(node, { checks }) {
18
+ return require_promise.memo(checks ? checkRefEntries : refEntries, node, () => {
19
+ const entries = [];
20
+ const walk = (current) => {
21
+ if (current.kind === require_constants.nodeKinds.schema && current.type === "ref") {
22
+ const name = require_refs.resolveRefName(current);
23
+ if (name) entries.push({
24
+ name,
25
+ hasPointer: Boolean(current.ref)
26
+ });
27
+ }
28
+ require_visitor.visitChildNodes(current, walk, { checks });
29
+ return false;
30
+ };
31
+ walk(node);
32
+ return entries;
33
+ });
34
+ }
35
+ /**
36
+ * Collects the names of every schema a node's subtree references, resolved with `ast.ref.getName`.
37
+ * Each ref contributes its name only, so the schema it points to is never traversed. Memoized by
38
+ * node identity, so repeated calls on one schema scan it once.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * collectSchemaRefs(petSchema)
43
+ * // Set { 'Category', 'Tag' }
44
+ * ```
45
+ */
46
+ function collectSchemaRefs(node) {
47
+ return require_promise.memo(schemaRefs, node, () => new Set(collectRefEntries(node, { checks: true }).map((entry) => entry.name)));
48
+ }
49
+ /**
50
+ * Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
51
+ * first-occurrence order. Memoized by node identity, so `resolver.imports` reads the same result
52
+ * across the ts, zod, and faker plugins instead of re-scanning the same schema per plugin.
53
+ *
54
+ * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
55
+ * same file (a union member created by name) is left out. That leaves exactly the set
56
+ * `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with
57
+ * `checks: true`, for a plugin that prints those checks.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * collectImportedRefNames(petSchema)
62
+ * // ['Category', 'Tag']
63
+ * ```
64
+ */
65
+ function collectImportedRefNames(node, { checks = false } = {}) {
66
+ return require_promise.memo(checks ? importedCheckRefNames : importedRefNames, node, () => [...new Set(collectRefEntries(node, { checks }).flatMap((entry) => entry.hasPointer ? [entry.name] : []))]);
67
+ }
68
+ /**
69
+ * Collects the names of all top-level schemas transitively used by a set of operations.
70
+ *
71
+ * An operation uses a schema when its parameters, request body, or responses reference it, directly
72
+ * or through other named schemas. Once a name is added to the result it is not revisited, so
73
+ * reference cycles terminate.
74
+ *
75
+ * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
76
+ *
77
+ * @example Only generate schemas referenced by included operations
78
+ * ```ts
79
+ * const includedOps = operations.filter((op) => resolver.default.options(op, { options, include }) !== null)
80
+ * const allowed = collectUsedSchemaNames(includedOps, schemas)
81
+ *
82
+ * for (const schema of schemas) {
83
+ * if (schema.name && !allowed.has(schema.name)) continue
84
+ * // generate schema
85
+ * }
86
+ * ```
87
+ */
88
+ function collectUsedSchemaNames(operations, schemas) {
89
+ const schemaMap = /* @__PURE__ */ new Map();
90
+ for (const schema of schemas) if (schema.name) schemaMap.set(schema.name, schema);
91
+ const result = /* @__PURE__ */ new Set();
92
+ function visitSchema(schema) {
93
+ for (const name of collectSchemaRefs(schema)) if (!result.has(name)) {
94
+ result.add(name);
95
+ const namedSchema = schemaMap.get(name);
96
+ if (namedSchema) visitSchema(namedSchema);
97
+ }
98
+ }
99
+ for (const op of operations) for (const schema of require_visitor.collect(op, {
100
+ depth: "shallow",
101
+ schema: (node) => node
102
+ })) visitSchema(schema);
103
+ return result;
104
+ }
105
+ /**
106
+ * Finds every schema that takes part in a circular dependency chain, including direct self-loops.
107
+ *
108
+ * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so
109
+ * the generated code does not recurse forever. Refs are followed by name only, so the walk stays
110
+ * linear in the size of the schema graph.
111
+ *
112
+ * @note Call this once on the full graph, then check a schema's `ast.graph.getRefNames` against the result.
113
+ */
114
+ function findCircularSchemas(schemas) {
115
+ const graph = /* @__PURE__ */ new Map();
116
+ for (const schema of schemas) if (schema.name) graph.set(schema.name, collectSchemaRefs(schema));
117
+ const circular = /* @__PURE__ */ new Set();
118
+ for (const start of graph.keys()) {
119
+ const visited = /* @__PURE__ */ new Set();
120
+ const stack = [...graph.get(start) ?? []];
121
+ while (stack.length > 0) {
122
+ const node = stack.pop();
123
+ if (node === start) {
124
+ circular.add(start);
125
+ break;
126
+ }
127
+ if (visited.has(node)) continue;
128
+ visited.add(node);
129
+ const next = graph.get(node);
130
+ if (next) for (const r of next) stack.push(r);
131
+ }
132
+ }
133
+ return circular;
134
+ }
135
+ // src/graph/index.ts
136
+ var graph_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
137
+ getCircularNames: () => findCircularSchemas,
138
+ getImportedNames: () => collectImportedRefNames,
139
+ getRefNames: () => collectSchemaRefs,
140
+ getUsedNames: () => collectUsedSchemaNames
141
+ });
142
+ Object.defineProperty(exports, "collectImportedRefNames", {
143
+ enumerable: true,
144
+ get: function() {
145
+ return collectImportedRefNames;
146
+ }
147
+ });
148
+ Object.defineProperty(exports, "collectSchemaRefs", {
149
+ enumerable: true,
150
+ get: function() {
151
+ return collectSchemaRefs;
152
+ }
153
+ });
154
+ Object.defineProperty(exports, "collectUsedSchemaNames", {
155
+ enumerable: true,
156
+ get: function() {
157
+ return collectUsedSchemaNames;
158
+ }
159
+ });
160
+ Object.defineProperty(exports, "findCircularSchemas", {
161
+ enumerable: true,
162
+ get: function() {
163
+ return findCircularSchemas;
164
+ }
165
+ });
166
+ Object.defineProperty(exports, "graph_exports", {
167
+ enumerable: true,
168
+ get: function() {
169
+ return graph_exports;
170
+ }
171
+ });
172
+
173
+ //# sourceMappingURL=graph-DcIY6tQb.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-DcIY6tQb.cjs","names":["memo","nodeKinds","resolveRefName","visitChildNodes","collect"],"sources":["../src/utils/schemaGraph.ts","../src/graph/index.ts"],"sourcesContent":["import { memo } from '@internals/utils'\nimport { nodeKinds } from '../constants.ts'\nimport type { Node } from '../nodes/index.ts'\nimport type { OperationNode } from '../nodes/operation.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\nimport { collect, visitChildNodes } from '../visitor.ts'\nimport { resolveRefName } from './refs.ts'\n\ntype RefEntry = { name: string; hasPointer: boolean }\n\nconst refEntries = memo.create<SchemaNode, ReadonlyArray<RefEntry>>({ weak: true })\nconst checkRefEntries = memo.create<SchemaNode, ReadonlyArray<RefEntry>>({ weak: true })\nconst schemaRefs = memo.create<SchemaNode, ReadonlySet<string>>({ weak: true })\nconst importedRefNames = memo.create<SchemaNode, ReadonlyArray<string>>({ weak: true })\nconst importedCheckRefNames = memo.create<SchemaNode, ReadonlyArray<string>>({ weak: true })\n\n/**\n * Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved\n * name plus whether the ref carries a `$ref` pointer. Memoized per node and per `checks` mode, so\n * each helper below scans a schema once.\n */\nfunction collectRefEntries(node: SchemaNode, { checks }: { checks: boolean }): ReadonlyArray<RefEntry> {\n return memo(checks ? checkRefEntries : refEntries, node, () => {\n const entries: Array<RefEntry> = []\n const walk = (current: Node): boolean => {\n if (current.kind === nodeKinds.schema && current.type === 'ref') {\n const name = resolveRefName(current)\n if (name) entries.push({ name, hasPointer: Boolean(current.ref) })\n }\n visitChildNodes(current, walk, { checks })\n return false\n }\n walk(node)\n return entries\n })\n}\n\n/**\n * Collects the names of every schema a node's subtree references, resolved with `ast.ref.getName`.\n * Each ref contributes its name only, so the schema it points to is never traversed. Memoized by\n * node identity, so repeated calls on one schema scan it once.\n *\n * @example\n * ```ts\n * collectSchemaRefs(petSchema)\n * // Set { 'Category', 'Tag' }\n * ```\n */\nexport function collectSchemaRefs(node: SchemaNode): ReadonlySet<string> {\n return memo(schemaRefs, node, () => new Set(collectRefEntries(node, { checks: true }).map((entry) => entry.name)))\n}\n\n/**\n * Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in\n * first-occurrence order. Memoized by node identity, so `resolver.imports` reads the same result\n * across the ts, zod, and faker plugins instead of re-scanning the same schema per plugin.\n *\n * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the\n * same file (a union member created by name) is left out. That leaves exactly the set\n * `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with\n * `checks: true`, for a plugin that prints those checks.\n *\n * @example\n * ```ts\n * collectImportedRefNames(petSchema)\n * // ['Category', 'Tag']\n * ```\n */\nexport function collectImportedRefNames(node: SchemaNode, { checks = false }: { checks?: boolean } = {}): ReadonlyArray<string> {\n return memo(checks ? importedCheckRefNames : importedRefNames, node, () => [\n ...new Set(collectRefEntries(node, { checks }).flatMap((entry) => (entry.hasPointer ? [entry.name] : []))),\n ])\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when its parameters, request body, or responses reference it, directly\n * or through other named schemas. Once a name is added to the result it is not revisited, so\n * reference cycles terminate.\n *\n * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter((op) => resolver.default.options(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // generate schema\n * }\n * ```\n */\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n for (const name of collectSchemaRefs(schema)) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collect<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\n/**\n * Finds every schema that takes part in a circular dependency chain, including direct self-loops.\n *\n * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so\n * the generated code does not recurse forever. Refs are followed by name only, so the walk stays\n * linear in the size of the schema graph.\n *\n * @note Call this once on the full graph, then check a schema's `ast.graph.getRefNames` against the result.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const graph = new Map<string, ReadonlySet<string>>()\n for (const schema of schemas) {\n if (schema.name) graph.set(schema.name, collectSchemaRefs(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n}\n","export {\n collectImportedRefNames as getImportedNames,\n collectSchemaRefs as getRefNames,\n collectUsedSchemaNames as getUsedNames,\n findCircularSchemas as getCircularNames,\n} from '../utils/schemaGraph.ts'\n"],"mappings":"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"}
package/dist/graph.cjs ADDED
@@ -0,0 +1,6 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_graph = require("./graph-DcIY6tQb.cjs");
3
+ exports.getCircularNames = require_graph.findCircularSchemas;
4
+ exports.getImportedNames = require_graph.collectImportedRefNames;
5
+ exports.getRefNames = require_graph.collectSchemaRefs;
6
+ exports.getUsedNames = require_graph.collectUsedSchemaNames;
@@ -0,0 +1,2 @@
1
+ import { a as findCircularSchemas, i as collectUsedSchemaNames, n as collectImportedRefNames, r as collectSchemaRefs } from "./index-DYDha-3I.cjs";
2
+ export { findCircularSchemas as getCircularNames, collectImportedRefNames as getImportedNames, collectSchemaRefs as getRefNames, collectUsedSchemaNames as getUsedNames };
@@ -0,0 +1,2 @@
1
+ import { a as findCircularSchemas, i as collectUsedSchemaNames, n as collectImportedRefNames, r as collectSchemaRefs } from "./index-Dp50LM3a.js";
2
+ export { findCircularSchemas as getCircularNames, collectImportedRefNames as getImportedNames, collectSchemaRefs as getRefNames, collectUsedSchemaNames as getUsedNames };
package/dist/graph.js ADDED
@@ -0,0 +1 @@
1
+ export { a as getCircularNames, n as getImportedNames, r as getRefNames, i as getUsedNames } from "./graph-BcwFCvei.js";
@@ -0,0 +1,23 @@
1
+ import { H as SchemaNode, U as SchemaNodeByType, i as OperationNode, r as HttpOperationNode } from "./operation-X7chCdL2.cjs";
2
+ /**
3
+ * Narrows a `SchemaNode` to the variant that matches `type`.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const schema = createSchema({ type: 'string' })
8
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
9
+ * ```
10
+ */
11
+ declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null;
12
+ /**
13
+ * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * if (ast.http.isOperation(node)) {
18
+ * console.log(node.method, node.path)
19
+ * }
20
+ * ```
21
+ */
22
+ declare function isHttpOperationNode(node: OperationNode): node is HttpOperationNode;
23
+ export { narrowSchema as n, isHttpOperationNode as t };
@@ -0,0 +1,41 @@
1
+ require("./rolldown-runtime-BV8xUvPy.cjs");
2
+ // src/guards.ts
3
+ /**
4
+ * Narrows a `SchemaNode` to the variant that matches `type`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const schema = createSchema({ type: 'string' })
9
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
10
+ * ```
11
+ */
12
+ function narrowSchema(node, type) {
13
+ return node?.type === type ? node : null;
14
+ }
15
+ /**
16
+ * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * if (ast.http.isOperation(node)) {
21
+ * console.log(node.method, node.path)
22
+ * }
23
+ * ```
24
+ */
25
+ function isHttpOperationNode(node) {
26
+ return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
27
+ }
28
+ Object.defineProperty(exports, "isHttpOperationNode", {
29
+ enumerable: true,
30
+ get: function() {
31
+ return isHttpOperationNode;
32
+ }
33
+ });
34
+ Object.defineProperty(exports, "narrowSchema", {
35
+ enumerable: true,
36
+ get: function() {
37
+ return narrowSchema;
38
+ }
39
+ });
40
+
41
+ //# sourceMappingURL=guards-COVJE6TU.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards-COVJE6TU.cjs","names":[],"sources":["../src/guards.ts"],"sourcesContent":["import type { HttpOperationNode, OperationNode } from './nodes/operation.ts'\nimport type { SchemaNode, SchemaNodeByType } from './nodes/schema.ts'\n\n/**\n * Narrows a `SchemaNode` to the variant that matches `type`.\n *\n * @example\n * ```ts\n * const schema = createSchema({ type: 'string' })\n * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null {\n return node?.type === type ? (node as SchemaNodeByType[T]) : null\n}\n\n/**\n * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.\n *\n * @example\n * ```ts\n * if (ast.http.isOperation(node)) {\n * console.log(node.method, node.path)\n * }\n * ```\n */\nexport function isHttpOperationNode(node: OperationNode): node is HttpOperationNode {\n return node.protocol === 'http' || (node.method !== undefined && node.path !== undefined)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,aAA2C,MAA8B,MAAqC;CAC5H,OAAO,MAAM,SAAS,OAAQ,OAA+B;AAC/D;;;;;;;;;;;AAYA,SAAgB,oBAAoB,MAAgD;CAClF,OAAO,KAAK,aAAa,UAAW,KAAK,WAAW,KAAA,KAAa,KAAK,SAAS,KAAA;AACjF"}
@@ -0,0 +1,23 @@
1
+ import { H as SchemaNode, U as SchemaNodeByType, i as OperationNode, r as HttpOperationNode } from "./operation-BgRyVS7z.js";
2
+ /**
3
+ * Narrows a `SchemaNode` to the variant that matches `type`.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const schema = createSchema({ type: 'string' })
8
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
9
+ * ```
10
+ */
11
+ declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null;
12
+ /**
13
+ * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * if (ast.http.isOperation(node)) {
18
+ * console.log(node.method, node.path)
19
+ * }
20
+ * ```
21
+ */
22
+ declare function isHttpOperationNode(node: OperationNode): node is HttpOperationNode;
23
+ export { narrowSchema as n, isHttpOperationNode as t };
@@ -0,0 +1,30 @@
1
+ import "./rolldown-runtime-BYyVTPww.js";
2
+ // src/guards.ts
3
+ /**
4
+ * Narrows a `SchemaNode` to the variant that matches `type`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const schema = createSchema({ type: 'string' })
9
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
10
+ * ```
11
+ */
12
+ function narrowSchema(node, type) {
13
+ return node?.type === type ? node : null;
14
+ }
15
+ /**
16
+ * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * if (ast.http.isOperation(node)) {
21
+ * console.log(node.method, node.path)
22
+ * }
23
+ * ```
24
+ */
25
+ function isHttpOperationNode(node) {
26
+ return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
27
+ }
28
+ export { narrowSchema as n, isHttpOperationNode as t };
29
+
30
+ //# sourceMappingURL=guards-DlJkKsT1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards-DlJkKsT1.js","names":[],"sources":["../src/guards.ts"],"sourcesContent":["import type { HttpOperationNode, OperationNode } from './nodes/operation.ts'\nimport type { SchemaNode, SchemaNodeByType } from './nodes/schema.ts'\n\n/**\n * Narrows a `SchemaNode` to the variant that matches `type`.\n *\n * @example\n * ```ts\n * const schema = createSchema({ type: 'string' })\n * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null {\n return node?.type === type ? (node as SchemaNodeByType[T]) : null\n}\n\n/**\n * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.\n *\n * @example\n * ```ts\n * if (ast.http.isOperation(node)) {\n * console.log(node.method, node.path)\n * }\n * ```\n */\nexport function isHttpOperationNode(node: OperationNode): node is HttpOperationNode {\n return node.protocol === 'http' || (node.method !== undefined && node.path !== undefined)\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,aAA2C,MAA8B,MAAqC;CAC5H,OAAO,MAAM,SAAS,OAAQ,OAA+B;AAC/D;;;;;;;;;;;AAYA,SAAgB,oBAAoB,MAAgD;CAClF,OAAO,KAAK,aAAa,UAAW,KAAK,WAAW,KAAA,KAAa,KAAK,SAAS,KAAA;AACjF"}
@@ -0,0 +1,12 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
2
+ const require_guards = require("./guards-COVJE6TU.cjs");
3
+ // src/http/index.ts
4
+ var http_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ isOperation: () => require_guards.isHttpOperationNode });
5
+ Object.defineProperty(exports, "http_exports", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return http_exports;
9
+ }
10
+ });
11
+
12
+ //# sourceMappingURL=http-Bm5lhVK4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-Bm5lhVK4.cjs","names":[],"sources":["../src/http/index.ts"],"sourcesContent":["export { isHttpOperationNode as isOperation } from '../guards.ts'\n"],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
2
+ import { t as isHttpOperationNode } from "./guards-DlJkKsT1.js";
3
+ // src/http/index.ts
4
+ var http_exports = /* @__PURE__ */ __exportAll({ isOperation: () => isHttpOperationNode });
5
+ export { http_exports as t };
6
+
7
+ //# sourceMappingURL=http-DwboM6pK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-DwboM6pK.js","names":[],"sources":["../src/http/index.ts"],"sourcesContent":["export { isHttpOperationNode as isOperation } from '../guards.ts'\n"],"mappings":""}
package/dist/http.cjs ADDED
@@ -0,0 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_guards = require("./guards-COVJE6TU.cjs");
3
+ require("./http-Bm5lhVK4.cjs");
4
+ exports.isOperation = require_guards.isHttpOperationNode;
@@ -0,0 +1,3 @@
1
+ import { t as isHttpOperationNode } from "./guards-B8qDgSaT.cjs";
2
+ import "./index-BWd95onW.cjs";
3
+ export { isHttpOperationNode as isOperation };
package/dist/http.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { t as isHttpOperationNode } from "./guards-D-h9R_sV.js";
2
+ import "./index-DaHsMJ_S.js";
3
+ export { isHttpOperationNode as isOperation };
package/dist/http.js ADDED
@@ -0,0 +1,2 @@
1
+ export { t as isOperation } from "./guards-DlJkKsT1.js";
2
+ import "./http-DwboM6pK.js";
@@ -0,0 +1,5 @@
1
+ import { t as isHttpOperationNode } from "./guards-B8qDgSaT.cjs";
2
+ declare namespace index_d_exports {
3
+ export { isHttpOperationNode as isOperation };
4
+ }
5
+ export { index_d_exports as t };
@@ -0,0 +1,20 @@
1
+ import { T as InputNode } from "./operation-X7chCdL2.cjs";
2
+ declare namespace index_d_exports {
3
+ export { parse, stringify };
4
+ }
5
+ /**
6
+ * Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,
7
+ * where a plain `JSON.stringify(input)` writes it again at every ref.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * await writeFile('input.json', ast.json.stringify(input))
12
+ * ```
13
+ */
14
+ declare function stringify(input: InputNode): string;
15
+ /**
16
+ * Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.
17
+ * Throws on another format version, or on a ref whose target is missing.
18
+ */
19
+ declare function parse(text: string): InputNode;
20
+ export { parse as n, stringify as r, index_d_exports as t };
@@ -0,0 +1,12 @@
1
+ import { i as nodeKinds } from "./base-IpYuh3ZP.cjs";
2
+ import { f as CodeNode } from "./file-BVqSiSvV.cjs";
3
+ import { i as collect, o as transform } from "./visitor-Bw_opzjF.cjs";
4
+ /**
5
+ * Extracts all string content from a `CodeNode` tree recursively.
6
+ * Collects the text fields and nested node content, to build the source string for import filtering.
7
+ */
8
+ declare function getNodeText(nodes: Array<CodeNode> | undefined): string;
9
+ declare namespace index_d_exports {
10
+ export { collect, getNodeText as getText, nodeKinds as kinds, transform };
11
+ }
12
+ export { getNodeText as n, index_d_exports as t };
@@ -0,0 +1,24 @@
1
+ import { C as createJsx, S as createFunction, T as createType, _ as TextNode, a as UserFileNode, b as createBreak, c as createImport, d as BreakNode, g as JsxNode, i as SourceNode, l as createSource, m as FunctionNode, n as FileNode, o as createExport, p as ConstNode, r as ImportNode, s as createFile, t as ExportNode, u as ArrowFunctionNode, v as TypeNode, w as createText, x as createConst, y as createArrowFunction } from "./file-xJnBQPGq.js";
2
+ import { H as SchemaNode, T as InputNode, X as PropertyNode, Y as createSchema, Z as createProperty, a as createOperation, d as createRequestBody, g as ContentNode, h as createParameter, i as OperationNode, k as createInput, l as createResponse, p as ParameterNode, s as ResponseNode, u as RequestBodyNode, y as createContent } from "./operation-BgRyVS7z.js";
3
+ declare namespace index_d_exports {
4
+ export { Node, UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
5
+ }
6
+ /**
7
+ * Union of all AST node types.
8
+ *
9
+ * This lets TypeScript narrow types in `switch (node.kind)` blocks.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * function getKind(node: Node): string {
14
+ * switch (node.kind) {
15
+ * case nodeKinds.input:
16
+ * return 'input'
17
+ * default:
18
+ * return 'other'
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ type Node = InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | RequestBodyNode | ContentNode | FileNode | ImportNode | ExportNode | SourceNode | ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
24
+ export { index_d_exports as n, Node as t };