@kubb/ast 5.23.2 → 5.23.4

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 (167) hide show
  1. package/dist/{constants-Ckeonm-D.js → constants-BTTus9ee.js} +1 -1
  2. package/dist/{constants-Ckeonm-D.js.map → constants-BTTus9ee.js.map} +1 -1
  3. package/dist/{constants-CquR083U.cjs → constants-DztHlVmY.cjs} +1 -1
  4. package/dist/{constants-CquR083U.cjs.map → constants-DztHlVmY.cjs.map} +1 -1
  5. package/dist/factory.cjs +3 -3
  6. package/dist/factory.d.cts +4 -4
  7. package/dist/factory.d.ts +4 -4
  8. package/dist/factory.js +3 -3
  9. package/dist/{file-xJnBQPGq.d.ts → file-B269mZh4.d.cts} +96 -40
  10. package/dist/file-Bq2GPaxh.js +427 -0
  11. package/dist/file-Bq2GPaxh.js.map +1 -0
  12. package/dist/file-C4pqV8yl.cjs +469 -0
  13. package/dist/file-C4pqV8yl.cjs.map +1 -0
  14. package/dist/{file-CvlMAp_d.js → file-D_ih0x7q.js} +32 -19
  15. package/dist/file-D_ih0x7q.js.map +1 -0
  16. package/dist/{file-Dd50jPkH.cjs → file-DiPZBLSP.cjs} +32 -19
  17. package/dist/file-DiPZBLSP.cjs.map +1 -0
  18. package/dist/{file-BVqSiSvV.d.cts → file-oLlejzZV.d.ts} +96 -40
  19. package/dist/file.cjs +5 -2
  20. package/dist/file.d.cts +2 -2
  21. package/dist/file.d.ts +2 -2
  22. package/dist/file.js +3 -1
  23. package/dist/{graph-BcwFCvei.js → graph-BUEOBomo.js} +5 -5
  24. package/dist/{graph-BcwFCvei.js.map → graph-BUEOBomo.js.map} +1 -1
  25. package/dist/{graph-DcIY6tQb.cjs → graph-CFJ4wzFR.cjs} +5 -5
  26. package/dist/{graph-DcIY6tQb.cjs.map → graph-CFJ4wzFR.cjs.map} +1 -1
  27. package/dist/graph.cjs +1 -1
  28. package/dist/graph.d.cts +1 -1
  29. package/dist/graph.d.ts +1 -1
  30. package/dist/graph.js +1 -1
  31. package/dist/{guards-COVJE6TU.cjs → guards-4drgx10i.cjs} +1 -1
  32. package/dist/{guards-COVJE6TU.cjs.map → guards-4drgx10i.cjs.map} +1 -1
  33. package/dist/{guards-DlJkKsT1.js → guards-DKw4uwc5.js} +1 -1
  34. package/dist/{guards-DlJkKsT1.js.map → guards-DKw4uwc5.js.map} +1 -1
  35. package/dist/{guards-D-h9R_sV.d.ts → guards-RCnH6re9.d.ts} +1 -1
  36. package/dist/{guards-B8qDgSaT.d.cts → guards-u-dAAtl8.d.cts} +1 -1
  37. package/dist/{http-DwboM6pK.js → http-CAWf6TAJ.js} +2 -2
  38. package/dist/http-CAWf6TAJ.js.map +1 -0
  39. package/dist/{http-Bm5lhVK4.cjs → http-Dv8py6wh.cjs} +2 -2
  40. package/dist/http-Dv8py6wh.cjs.map +1 -0
  41. package/dist/http.cjs +2 -2
  42. package/dist/http.d.cts +2 -2
  43. package/dist/http.d.ts +2 -2
  44. package/dist/http.js +2 -2
  45. package/dist/{index-eGkM4FE9.d.ts → index-2TMYDLjK.d.ts} +1 -1
  46. package/dist/index-6-ZZCX9W.d.ts +24 -0
  47. package/dist/index-B2nnOQjf.d.cts +24 -0
  48. package/dist/{index-Csf8xsCc.d.cts → index-BgFaJtnv.d.ts} +11 -5
  49. package/dist/index-Bj7a0aSM.d.cts +5 -0
  50. package/dist/{index-DKJdlX1l.d.cts → index-Bw2oMIM1.d.cts} +4 -4
  51. package/dist/{index-Bb1kqq8H.d.cts → index-C1za72gL.d.cts} +1 -1
  52. package/dist/index-CW-ztJjd.d.ts +5 -0
  53. package/dist/{index-CoRdlrVx.d.ts → index-DF7CbpYW.d.ts} +3 -3
  54. package/dist/{index-CwLhqYbA.d.cts → index-D_WLsIMP.d.cts} +2 -2
  55. package/dist/{index-Dp50LM3a.d.ts → index-DbAnYRRM.d.ts} +1 -1
  56. package/dist/{index-cpjUxIik.d.ts → index-DbQ-J072.d.cts} +11 -5
  57. package/dist/{index-CFH4ZC7q.d.ts → index-DfRcRYF2.d.ts} +1 -1
  58. package/dist/{index-DU_jYpBt.d.cts → index-DpnCCtXt.d.cts} +1 -1
  59. package/dist/{index-BSf-ETQP.d.ts → index-DzHcy3vy.d.ts} +2 -2
  60. package/dist/{index-W6yFx0sy.d.ts → index-UwSVys3m.d.ts} +4 -4
  61. package/dist/{index-BVuX3-Th.d.cts → index-c9FD2S5f.d.cts} +3 -3
  62. package/dist/{index-DYDha-3I.d.cts → index-sdprVPKQ.d.cts} +1 -1
  63. package/dist/index.cjs +16 -16
  64. package/dist/index.d.cts +17 -17
  65. package/dist/index.d.ts +17 -17
  66. package/dist/index.js +16 -16
  67. package/dist/{json-DURdtz9A.cjs → json-CCWMgzJZ.cjs} +2 -2
  68. package/dist/{json-DURdtz9A.cjs.map → json-CCWMgzJZ.cjs.map} +1 -1
  69. package/dist/{json-DH7_lcWm.js → json-DyDtIZTj.js} +2 -2
  70. package/dist/{json-DH7_lcWm.js.map → json-DyDtIZTj.js.map} +1 -1
  71. package/dist/json.cjs +1 -1
  72. package/dist/json.d.cts +1 -1
  73. package/dist/json.d.ts +1 -1
  74. package/dist/json.js +1 -1
  75. package/dist/{macro-4N8vHE-2.js → macro-9WouvtZe.js} +2 -2
  76. package/dist/{macro-4N8vHE-2.js.map → macro-9WouvtZe.js.map} +1 -1
  77. package/dist/{macro-V_cNODx2.cjs → macro-BEwfGNu1.cjs} +2 -2
  78. package/dist/{macro-V_cNODx2.cjs.map → macro-BEwfGNu1.cjs.map} +1 -1
  79. package/dist/macro.cjs +1 -1
  80. package/dist/macro.d.cts +1 -1
  81. package/dist/macro.d.ts +1 -1
  82. package/dist/macro.js +1 -1
  83. package/dist/{mediaType-D8uIO8sG.cjs → mediaType-BbIfudh0.cjs} +1 -1
  84. package/dist/{mediaType-D8uIO8sG.cjs.map → mediaType-BbIfudh0.cjs.map} +1 -1
  85. package/dist/{mediaType-CRjggmoG.js → mediaType-DXQCNYdM.js} +1 -1
  86. package/dist/{mediaType-CRjggmoG.js.map → mediaType-DXQCNYdM.js.map} +1 -1
  87. package/dist/mediaType.cjs +1 -1
  88. package/dist/mediaType.d.cts +1 -1
  89. package/dist/mediaType.d.ts +1 -1
  90. package/dist/mediaType.js +1 -1
  91. package/dist/{node-Djh-mZB2.js → node-DtuO3zr8.js} +4 -4
  92. package/dist/{node-Djh-mZB2.js.map → node-DtuO3zr8.js.map} +1 -1
  93. package/dist/{node-DjcETnc8.cjs → node-vTrAIz3e.cjs} +4 -4
  94. package/dist/{node-DjcETnc8.cjs.map → node-vTrAIz3e.cjs.map} +1 -1
  95. package/dist/node.cjs +4 -4
  96. package/dist/node.d.cts +3 -3
  97. package/dist/node.d.ts +3 -3
  98. package/dist/node.js +4 -4
  99. package/dist/{nodeText-DVVDZQjF.js → nodeText-BSYvDZOH.js} +2 -2
  100. package/dist/{nodeText-DVVDZQjF.js.map → nodeText-BSYvDZOH.js.map} +1 -1
  101. package/dist/{nodeText-DRb_rVd1.cjs → nodeText-CZ7wgxu9.cjs} +2 -2
  102. package/dist/{nodeText-DRb_rVd1.cjs.map → nodeText-CZ7wgxu9.cjs.map} +1 -1
  103. package/dist/{nodes-CWMa9xhW.js → nodes-ClL1C158.js} +5 -5
  104. package/dist/nodes-ClL1C158.js.map +1 -0
  105. package/dist/{nodes-BB60Bq2H.cjs → nodes-DEQjVliP.cjs} +5 -5
  106. package/dist/nodes-DEQjVliP.cjs.map +1 -0
  107. package/dist/{operation-X7chCdL2.d.cts → operation-AFw8tzIN.d.cts} +22 -6
  108. package/dist/{operation-BgRyVS7z.d.ts → operation-Cu4XSaJQ.d.ts} +22 -6
  109. package/dist/{optionality-D-zqzVMH.cjs → optionality-C-qULYxo.cjs} +1 -1
  110. package/dist/{optionality-D-zqzVMH.cjs.map → optionality-C-qULYxo.cjs.map} +1 -1
  111. package/dist/{optionality-DISn8ytP.js → optionality-FkRredTC.js} +1 -1
  112. package/dist/{optionality-DISn8ytP.js.map → optionality-FkRredTC.js.map} +1 -1
  113. package/dist/{promise-RpnEev9D.js → promise-B3YkZ4C8.js} +1 -1
  114. package/dist/{promise-RpnEev9D.js.map → promise-B3YkZ4C8.js.map} +1 -1
  115. package/dist/{promise-BOdlgT0N.cjs → promise-DScaykew.cjs} +1 -1
  116. package/dist/{promise-BOdlgT0N.cjs.map → promise-DScaykew.cjs.map} +1 -1
  117. package/dist/{ref-P0ZLT1Bg.cjs → ref-Bh5Xo8T7.cjs} +4 -4
  118. package/dist/{ref-P0ZLT1Bg.cjs.map → ref-Bh5Xo8T7.cjs.map} +1 -1
  119. package/dist/{ref-Bu7PoHar.js → ref-DPqeS8K1.js} +4 -4
  120. package/dist/{ref-Bu7PoHar.js.map → ref-DPqeS8K1.js.map} +1 -1
  121. package/dist/ref.cjs +2 -2
  122. package/dist/ref.d.cts +1 -1
  123. package/dist/ref.d.ts +1 -1
  124. package/dist/ref.js +2 -2
  125. package/dist/{refs-YCV3CznS.js → refs-Bgf8_9Ui.js} +2 -2
  126. package/dist/{refs-YCV3CznS.js.map → refs-Bgf8_9Ui.js.map} +1 -1
  127. package/dist/{refs-CYHpRlQo.cjs → refs-rmr2LFV1.cjs} +2 -2
  128. package/dist/{refs-CYHpRlQo.cjs.map → refs-rmr2LFV1.cjs.map} +1 -1
  129. package/dist/{schema-DloctnMm.js → schema-4UcdIPQ2.js} +7 -7
  130. package/dist/{schema-DloctnMm.js.map → schema-4UcdIPQ2.js.map} +1 -1
  131. package/dist/{schema-BIErWqgc.cjs → schema-DuCY4lCG.cjs} +7 -7
  132. package/dist/{schema-BIErWqgc.cjs.map → schema-DuCY4lCG.cjs.map} +1 -1
  133. package/dist/{schema-hxMlgCrV.cjs → schema-gSjYgaCl.cjs} +2 -2
  134. package/dist/schema-gSjYgaCl.cjs.map +1 -0
  135. package/dist/{schema-2ZAQk7qE.js → schema-tH14gE6i.js} +2 -2
  136. package/dist/schema-tH14gE6i.js.map +1 -0
  137. package/dist/schema.cjs +5 -5
  138. package/dist/schema.d.cts +4 -4
  139. package/dist/schema.d.ts +4 -4
  140. package/dist/schema.js +5 -5
  141. package/dist/{visitor-DTrzvA3R.cjs → visitor-Bh1CBAOz.cjs} +4 -5
  142. package/dist/{visitor-DTrzvA3R.cjs.map → visitor-Bh1CBAOz.cjs.map} +1 -1
  143. package/dist/{visitor-1TSWTMe1.d.ts → visitor-CpmsR8o5.d.ts} +2 -2
  144. package/dist/{visitor-CUbaaX8R.d.cts → visitor-DnBK2MNl.d.cts} +2 -2
  145. package/dist/{visitor-NoQSUQTu.js → visitor-XA0W3OVv.js} +4 -5
  146. package/dist/{visitor-NoQSUQTu.js.map → visitor-XA0W3OVv.js.map} +1 -1
  147. package/package.json +1 -1
  148. package/dist/file-Cg0T6cgz.cjs +0 -319
  149. package/dist/file-Cg0T6cgz.cjs.map +0 -1
  150. package/dist/file-CnuL8oUj.js +0 -283
  151. package/dist/file-CnuL8oUj.js.map +0 -1
  152. package/dist/file-CvlMAp_d.js.map +0 -1
  153. package/dist/file-Dd50jPkH.cjs.map +0 -1
  154. package/dist/http-Bm5lhVK4.cjs.map +0 -1
  155. package/dist/http-DwboM6pK.js.map +0 -1
  156. package/dist/index-BWd95onW.d.cts +0 -5
  157. package/dist/index-BwnMIoLl.d.ts +0 -24
  158. package/dist/index-DSVef1pp.d.cts +0 -24
  159. package/dist/index-DaHsMJ_S.d.ts +0 -5
  160. package/dist/nodes-BB60Bq2H.cjs.map +0 -1
  161. package/dist/nodes-CWMa9xhW.js.map +0 -1
  162. package/dist/schema-2ZAQk7qE.js.map +0 -1
  163. package/dist/schema-hxMlgCrV.cjs.map +0 -1
  164. /package/dist/{base-IpYuh3ZP.d.cts → base-LhsPvVY1.d.ts} +0 -0
  165. /package/dist/{base-IpYuh3ZP.d.ts → base-UFBZi-FO.d.cts} +0 -0
  166. /package/dist/{index-Cc2K3OzU.d.cts → index-C-nsgwuD.d.ts} +0 -0
  167. /package/dist/{index-Cc2K3OzU.d.ts → index-DR9ahJ-x.d.cts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-D_ih0x7q.js","names":[],"sources":["../src/utils/inline.ts","../src/file/index.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport type { CodeNode } from '../nodes/code.ts'\nimport { createFile, createImport } from '../nodes/file.ts'\nimport type { FileNode, ImportNode, SourceNode } from '../nodes/file.ts'\nimport { getNames } from './moduleNames.ts'\nimport { CODE_NODE_TEXT_FIELDS, getNodeText } from './nodeText.ts'\n\ntype InlineFilesResult = {\n /**\n * Files that imported an inline name, rewritten to hold its definition.\n */\n files: Array<FileNode>\n /**\n * Paths of the virtual files, which are not written.\n */\n virtualPaths: Array<string>\n /**\n * One message per name that could not be inlined.\n */\n problems: Array<{ path: string; message: string }>\n}\n\ntype Definition = { expression: string; imports: Array<ImportNode> }\n\n/**\n * The language-specific half of {@link inlineFiles}, supplied by the parser that prints the file.\n */\nexport type InlineLanguage = {\n /**\n * Swaps in what `replace` returns for every identifier in `text` that references a name, skipping strings and comments.\n */\n replaceIdentifiers(text: string, replace: (name: string) => string | undefined): string\n /**\n * Makes `expression` safe to put where a name was, such as `(A | B)` in TypeScript.\n */\n wrap(expression: string): string\n}\n\ntype InlineFilesOptions = {\n /**\n * The inline support for a file's language, or `undefined` when it has none.\n */\n language: (file: FileNode) => InlineLanguage | undefined\n}\n\n/**\n * Replaces every name a file imports from a virtual file (one marked `inline`, so it is never written) with the body of that name's\n * declaration, until no inline names are left. The definitions' own imports move to the importing file.\n */\nexport function inlineFiles(files: ReadonlyArray<FileNode>, { language }: InlineFilesOptions): InlineFilesResult {\n const virtualFiles = new Map(files.filter(isInlineFile).map((file) => [file.path, file]))\n const result: InlineFilesResult = { files: [], virtualPaths: [...virtualFiles.keys()], problems: [] }\n if (virtualFiles.size === 0) return result\n\n // `null` marks a definition that is being resolved, so a name that reaches itself is a cycle.\n const definitions = new Map<string, Definition | null>()\n\n function define(path: string, name: string, from: string, lang: InlineLanguage): Definition | undefined {\n const key = `${path}\\0${name}`\n if (definitions.has(key)) {\n const definition = definitions.get(key)\n if (definition === null) result.problems.push({ path: from, message: `\"${name}\" from \"${path}\" is defined in terms of itself.` })\n return definition ?? undefined\n }\n\n const file = virtualFiles.get(path)!\n const expression = bodyOf(file.sources.find((source) => source.name === name))\n if (expression === undefined) {\n result.problems.push({ path: from, message: `\"${name}\" is imported from \"${path}\", which never writes it and has no inline definition for it.` })\n return undefined\n }\n\n definitions.set(key, null)\n const imports: Array<ImportNode> = []\n const { text, used } = replaceNames(expression, file, lang, imports)\n imports.push(...file.imports.flatMap((imp) => (virtualFiles.has(imp.path) ? [] : pickNames(imp, used))))\n\n const definition = { expression: text, imports }\n definitions.set(key, definition)\n return definition\n }\n\n // Pushes the imports the replaced definitions need onto `imports`; `used` holds the names left as they are.\n function replaceNames(input: string, file: FileNode, lang: InlineLanguage, imports: Array<ImportNode>) {\n const used = new Set<string>()\n const text = lang.replaceIdentifiers(input, (local) => {\n const target = findTarget(file, local)\n const definition = target && define(target.path, target.name, file.path, lang)\n if (!definition) {\n used.add(local)\n return undefined\n }\n\n imports.push(...definition.imports)\n return lang.wrap(definition.expression)\n })\n\n return { text, used }\n }\n\n function findTarget(file: FileNode, local: string): { path: string; name: string } | undefined {\n if (virtualFiles.has(file.path) && file.sources.some((source) => source.name === local)) return { path: file.path, name: local }\n\n for (const imp of file.imports) {\n const item = virtualFiles.has(imp.path) && getNames(imp).find((item) => (item.alias ?? item.name) === local)\n if (item) return { path: imp.path, name: item.name }\n }\n\n return undefined\n }\n\n for (const file of files) {\n if (virtualFiles.has(file.path) || !file.imports.some((imp) => virtualFiles.has(imp.path))) continue\n\n const lang = language(file)\n if (!lang) {\n result.problems.push({ path: file.path, message: `No parser for \"${file.extname}\" files supports inline sources.` })\n continue\n }\n\n const carried: Array<ImportNode> = []\n const sources = file.sources.map((source) => ({ ...source, nodes: rewriteNodes(source.nodes, (text) => replaceNames(text, file, lang, carried).text) }))\n\n // A carried import keeps its target; `root` moves to the importing file so the relative path is computed from there.\n const imports = [...file.imports.filter((imp) => !virtualFiles.has(imp.path)), ...carried.map((imp) => (imp.root ? { ...imp, root: file.path } : imp))]\n\n result.files.push(createFile({ ...file, sources, imports }))\n }\n\n return result\n}\n\n// A file of only deprecated per-source `inline` counts as inline too.\nfunction isInlineFile(file: FileNode): boolean {\n return !!file.inline || (file.sources.length > 0 && file.sources.every((source) => source.inline))\n}\n\n// The right-hand side of a `Const` or `Type`. A function body is not an expression, and printed text such as `Code` has none.\nfunction bodyOf(source: SourceNode | undefined): string | undefined {\n if (source?.inline) return source.inline.expression\n const node = source?.nodes?.length === 1 ? source.nodes[0] : undefined\n if (node?.kind !== nodeKinds.const && node?.kind !== nodeKinds.type) return undefined\n return getNodeText(node.nodes) || undefined\n}\n\nfunction pickNames(imp: ImportNode, used: ReadonlySet<string>): Array<ImportNode> {\n const names = getNames(imp).filter((item) => used.has(item.alias ?? item.name))\n return names.length > 0 ? [createImport({ path: imp.path, ...(imp.root != null ? { root: imp.root } : {}), names })] : []\n}\n\n// Rewrites the string fields `getNodeText` reads; JSDoc stays as written.\nfunction rewriteNodes(nodes: Array<CodeNode> | undefined, rewrite: (text: string) => string): Array<CodeNode> | undefined {\n return nodes?.map((node): CodeNode => {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') return rewrite(node) as unknown as CodeNode\n if (node.kind === nodeKinds.break) return node\n\n const next = { ...node } as unknown as Record<string, unknown>\n for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {\n const value = next[field]\n if (Array.isArray(value)) next[field] = value.map(rewrite)\n if (typeof value === 'string' && value) next[field] = rewrite(value)\n }\n if ('nodes' in node && node.nodes) next.nodes = rewriteNodes(node.nodes, rewrite)\n return next as unknown as CodeNode\n })\n}\n","export { inlineFiles as inline } from '../utils/inline.ts'\nexport { getNames, getSpace } from '../utils/moduleNames.ts'\n"],"mappings":";;;;;;;;;AAiDA,SAAgB,YAAY,OAAgC,EAAE,YAAmD;CAC/G,MAAM,e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AK,GAAG,KAAK,SAAS,MAAM,IAAI,OAAO;GACzD,IAAI,OAAO,UAAU,YAAY,OAAO,KAAK,SAAS,QAAQ,KAAK;EACrE;EACA,IAAI,WAAW,QAAQ,KAAK,OAAO,KAAK,QAAQ,aAAa,KAAK,OAAO,OAAO;EAChF,OAAO;CACT,CAAC;AACH"}
@@ -1,14 +1,14 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
2
- const require_constants = require("./constants-CquR083U.cjs");
3
- const require_file = require("./file-Cg0T6cgz.cjs");
4
- const require_nodeText = require("./nodeText-DRb_rVd1.cjs");
2
+ const require_constants = require("./constants-DztHlVmY.cjs");
3
+ const require_file = require("./file-C4pqV8yl.cjs");
4
+ const require_nodeText = require("./nodeText-CZ7wgxu9.cjs");
5
5
  // src/utils/inline.ts
6
6
  /**
7
- * Replaces every name a file imports from a virtual file (one whose sources are all inline, so it is never written) with that name's
8
- * `inline.expression`, until no inline names are left. The definitions' own imports move to the importing file.
7
+ * Replaces every name a file imports from a virtual file (one marked `inline`, so it is never written) with the body of that name's
8
+ * declaration, until no inline names are left. The definitions' own imports move to the importing file.
9
9
  */
10
10
  function inlineFiles(files, { language }) {
11
- const virtualFiles = new Map(files.filter((file) => file.sources.length > 0 && file.sources.every((source) => source.inline)).map((file) => [file.path, file]));
11
+ const virtualFiles = new Map(files.filter(isInlineFile).map((file) => [file.path, file]));
12
12
  const result = {
13
13
  files: [],
14
14
  virtualPaths: [...virtualFiles.keys()],
@@ -27,8 +27,8 @@ function inlineFiles(files, { language }) {
27
27
  return definition ?? void 0;
28
28
  }
29
29
  const file = virtualFiles.get(path);
30
- const inline = file.sources.find((source) => source.name === name)?.inline;
31
- if (!inline) {
30
+ const expression = bodyOf(file.sources.find((source) => source.name === name));
31
+ if (expression === void 0) {
32
32
  result.problems.push({
33
33
  path: from,
34
34
  message: `"${name}" is imported from "${path}", which never writes it and has no inline definition for it.`
@@ -37,7 +37,7 @@ function inlineFiles(files, { language }) {
37
37
  }
38
38
  definitions.set(key, null);
39
39
  const imports = [];
40
- const { text, used } = replaceNames(inline.expression, file, lang, imports);
40
+ const { text, used } = replaceNames(expression, file, lang, imports);
41
41
  imports.push(...file.imports.flatMap((imp) => virtualFiles.has(imp.path) ? [] : pickNames(imp, used)));
42
42
  const definition = {
43
43
  expression: text,
@@ -68,10 +68,10 @@ function inlineFiles(files, { language }) {
68
68
  name: local
69
69
  };
70
70
  for (const imp of file.imports) {
71
- const item = virtualFiles.has(imp.path) && [imp.name].flat().find((item) => require_file.importLocalName(item) === local);
71
+ const item = virtualFiles.has(imp.path) && require_file.getNames(imp).find((item) => (item.alias ?? item.name) === local);
72
72
  if (item) return {
73
73
  path: imp.path,
74
- name: typeof item === "string" ? item : item.propertyName
74
+ name: item.name
75
75
  };
76
76
  }
77
77
  }
@@ -102,13 +102,22 @@ function inlineFiles(files, { language }) {
102
102
  }
103
103
  return result;
104
104
  }
105
+ function isInlineFile(file) {
106
+ return !!file.inline || file.sources.length > 0 && file.sources.every((source) => source.inline);
107
+ }
108
+ function bodyOf(source) {
109
+ if (source?.inline) return source.inline.expression;
110
+ const node = source?.nodes?.length === 1 ? source.nodes[0] : void 0;
111
+ if (node?.kind !== require_constants.nodeKinds.const && node?.kind !== require_constants.nodeKinds.type) return void 0;
112
+ return require_nodeText.getNodeText(node.nodes) || void 0;
113
+ }
105
114
  function pickNames(imp, used) {
106
- if (!Array.isArray(imp.name)) return used.has(imp.name) ? [imp] : [];
107
- const name = imp.name.filter((item) => used.has(require_file.importLocalName(item)));
108
- return name.length > 0 ? [{
109
- ...imp,
110
- name
111
- }] : [];
115
+ const names = require_file.getNames(imp).filter((item) => used.has(item.alias ?? item.name));
116
+ return names.length > 0 ? [require_file.createImport({
117
+ path: imp.path,
118
+ ...imp.root != null ? { root: imp.root } : {},
119
+ names
120
+ })] : [];
112
121
  }
113
122
  function rewriteNodes(nodes, rewrite) {
114
123
  return nodes?.map((node) => {
@@ -125,7 +134,11 @@ function rewriteNodes(nodes, rewrite) {
125
134
  });
126
135
  }
127
136
  // src/file/index.ts
128
- var file_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ inline: () => inlineFiles });
137
+ var file_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
138
+ getNames: () => require_file.getNames,
139
+ getSpace: () => require_file.getSpace,
140
+ inline: () => inlineFiles
141
+ });
129
142
  Object.defineProperty(exports, "file_exports", {
130
143
  enumerable: true,
131
144
  get: function() {
@@ -139,4 +152,4 @@ Object.defineProperty(exports, "inlineFiles", {
139
152
  }
140
153
  });
141
154
 
142
- //# sourceMappingURL=file-Dd50jPkH.cjs.map
155
+ //# sourceMappingURL=file-DiPZBLSP.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-DiPZBLSP.cjs","names":["getNames","createFile","nodeKinds","getNodeText","createImport","CODE_NODE_TEXT_FIELDS"],"sources":["../src/utils/inline.ts","../src/file/index.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport type { CodeNode } from '../nodes/code.ts'\nimport { createFile, createImport } from '../nodes/file.ts'\nimport type { FileNode, ImportNode, SourceNode } from '../nodes/file.ts'\nimport { getNames } from './moduleNames.ts'\nimport { CODE_NODE_TEXT_FIELDS, getNodeText } from './nodeText.ts'\n\ntype InlineFilesResult = {\n /**\n * Files that imported an inline name, rewritten to hold its definition.\n */\n files: Array<FileNode>\n /**\n * Paths of the virtual files, which are not written.\n */\n virtualPaths: Array<string>\n /**\n * One message per name that could not be inlined.\n */\n problems: Array<{ path: string; message: string }>\n}\n\ntype Definition = { expression: string; imports: Array<ImportNode> }\n\n/**\n * The language-specific half of {@link inlineFiles}, supplied by the parser that prints the file.\n */\nexport type InlineLanguage = {\n /**\n * Swaps in what `replace` returns for every identifier in `text` that references a name, skipping strings and comments.\n */\n replaceIdentifiers(text: string, replace: (name: string) => string | undefined): string\n /**\n * Makes `expression` safe to put where a name was, such as `(A | B)` in TypeScript.\n */\n wrap(expression: string): string\n}\n\ntype InlineFilesOptions = {\n /**\n * The inline support for a file's language, or `undefined` when it has none.\n */\n language: (file: FileNode) => InlineLanguage | undefined\n}\n\n/**\n * Replaces every name a file imports from a virtual file (one marked `inline`, so it is never written) with the body of that name's\n * declaration, until no inline names are left. The definitions' own imports move to the importing file.\n */\nexport function inlineFiles(files: ReadonlyArray<FileNode>, { language }: InlineFilesOptions): InlineFilesResult {\n const virtualFiles = new Map(files.filter(isInlineFile).map((file) => [file.path, file]))\n const result: InlineFilesResult = { files: [], virtualPaths: [...virtualFiles.keys()], problems: [] }\n if (virtualFiles.size === 0) return result\n\n // `null` marks a definition that is being resolved, so a name that reaches itself is a cycle.\n const definitions = new Map<string, Definition | null>()\n\n function define(path: string, name: string, from: string, lang: InlineLanguage): Definition | undefined {\n const key = `${path}\\0${name}`\n if (definitions.has(key)) {\n const definition = definitions.get(key)\n if (definition === null) result.problems.push({ path: from, message: `\"${name}\" from \"${path}\" is defined in terms of itself.` })\n return definition ?? undefined\n }\n\n const file = virtualFiles.get(path)!\n const expression = bodyOf(file.sources.find((source) => source.name === name))\n if (expression === undefined) {\n result.problems.push({ path: from, message: `\"${name}\" is imported from \"${path}\", which never writes it and has no inline definition for it.` })\n return undefined\n }\n\n definitions.set(key, null)\n const imports: Array<ImportNode> = []\n const { text, used } = replaceNames(expression, file, lang, imports)\n imports.push(...file.imports.flatMap((imp) => (virtualFiles.has(imp.path) ? [] : pickNames(imp, used))))\n\n const definition = { expression: text, imports }\n definitions.set(key, definition)\n return definition\n }\n\n // Pushes the imports the replaced definitions need onto `imports`; `used` holds the names left as they are.\n function replaceNames(input: string, file: FileNode, lang: InlineLanguage, imports: Array<ImportNode>) {\n const used = new Set<string>()\n const text = lang.replaceIdentifiers(input, (local) => {\n const target = findTarget(file, local)\n const definition = target && define(target.path, target.name, file.path, lang)\n if (!definition) {\n used.add(local)\n return undefined\n }\n\n imports.push(...definition.imports)\n return lang.wrap(definition.expression)\n })\n\n return { text, used }\n }\n\n function findTarget(file: FileNode, local: string): { path: string; name: string } | undefined {\n if (virtualFiles.has(file.path) && file.sources.some((source) => source.name === local)) return { path: file.path, name: local }\n\n for (const imp of file.imports) {\n const item = virtualFiles.has(imp.path) && getNames(imp).find((item) => (item.alias ?? item.name) === local)\n if (item) return { path: imp.path, name: item.name }\n }\n\n return undefined\n }\n\n for (const file of files) {\n if (virtualFiles.has(file.path) || !file.imports.some((imp) => virtualFiles.has(imp.path))) continue\n\n const lang = language(file)\n if (!lang) {\n result.problems.push({ path: file.path, message: `No parser for \"${file.extname}\" files supports inline sources.` })\n continue\n }\n\n const carried: Array<ImportNode> = []\n const sources = file.sources.map((source) => ({ ...source, nodes: rewriteNodes(source.nodes, (text) => replaceNames(text, file, lang, carried).text) }))\n\n // A carried import keeps its target; `root` moves to the importing file so the relative path is computed from there.\n const imports = [...file.imports.filter((imp) => !virtualFiles.has(imp.path)), ...carried.map((imp) => (imp.root ? { ...imp, root: file.path } : imp))]\n\n result.files.push(createFile({ ...file, sources, imports }))\n }\n\n return result\n}\n\n// A file of only deprecated per-source `inline` counts as inline too.\nfunction isInlineFile(file: FileNode): boolean {\n return !!file.inline || (file.sources.length > 0 && file.sources.every((source) => source.inline))\n}\n\n// The right-hand side of a `Const` or `Type`. A function body is not an expression, and printed text such as `Code` has none.\nfunction bodyOf(source: SourceNode | undefined): string | undefined {\n if (source?.inline) return source.inline.expression\n const node = source?.nodes?.length === 1 ? source.nodes[0] : undefined\n if (node?.kind !== nodeKinds.const && node?.kind !== nodeKinds.type) return undefined\n return getNodeText(node.nodes) || undefined\n}\n\nfunction pickNames(imp: ImportNode, used: ReadonlySet<string>): Array<ImportNode> {\n const names = getNames(imp).filter((item) => used.has(item.alias ?? item.name))\n return names.length > 0 ? [createImport({ path: imp.path, ...(imp.root != null ? { root: imp.root } : {}), names })] : []\n}\n\n// Rewrites the string fields `getNodeText` reads; JSDoc stays as written.\nfunction rewriteNodes(nodes: Array<CodeNode> | undefined, rewrite: (text: string) => string): Array<CodeNode> | undefined {\n return nodes?.map((node): CodeNode => {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') return rewrite(node) as unknown as CodeNode\n if (node.kind === nodeKinds.break) return node\n\n const next = { ...node } as unknown as Record<string, unknown>\n for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {\n const value = next[field]\n if (Array.isArray(value)) next[field] = value.map(rewrite)\n if (typeof value === 'string' && value) next[field] = rewrite(value)\n }\n if ('nodes' in node && node.nodes) next.nodes = rewriteNodes(node.nodes, rewrite)\n return next as unknown as CodeNode\n })\n}\n","export { inlineFiles as inline } from '../utils/inline.ts'\nexport { getNames, getSpace } from '../utils/moduleNames.ts'\n"],"mappings":";;;;;;;;;AAiDA,SAAgB,YAAY,OAAgC,EAAE,YAAmD;CAC/G,MAAM,eAAe,IAAI,IAAI,MAAM,OAAO,YAAY,CAAC,CAAC,KAAK,SAAS,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC;CACxF,MAAM,SAA4B;EAAE,OAAO,CAAC;EAAG,cAAc,CAAC,GAAG,aAAa,KAAK,CAAC;EAAG,UAAU,CAAC;CAAE;CACpG,IAAI,aAAa,SAAS,GAAG,OAAO;CAGpC,MAAM,8BAAc,IAAI,IAA+B;CAEvD,SAAS,OAAO,MAAc,MAAc,MAAc,MAA8C;EACtG,MAAM,MAAM,GAAG,KAAK,IAAI;EACxB,IAAI,YAAY,IAAI,GAAG,GAAG;GACxB,MAAM,aAAa,YAAY,IAAI,GAAG;GACtC,IAAI,eAAe,MAAM,OAAO,SAAS,KAAK;IAAE,MAAM;IAAM,SAAS,IAAI,KAAK,UAAU,KAAK;GAAkC,CAAC;GAChI,OAAO,cAAc,KAAA;EACvB;EAEA,MAAM,OAAO,aAAa,IAAI,IAAI;EAClC,MAAM,aAAa,OAAO,KAAK,QAAQ,MAAM,WAAW,OAAO,SAAS,IAAI,CAAC;EAC7E,IAAI,eAAe,KAAA,GAAW;GAC5B,OAAO,SAAS,KAAK;IAAE,MAAM;I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AAG,CAAC,CAAC,QAAQ,SAAS,KAAK,IAAI,KAAK,SAAS,KAAK,IAAI,CAAC;CAC9E,OAAO,MAAM,SAAS,IAAI,CAACI,aAAAA,aAAa;EAAE,MAAM,IAAI;EAAM,GAAI,IAAI,QAAQ,OAAO,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;EAAI;CAAM,CAAC,CAAC,IAAI,CAAC;AAC1H;AAGA,SAAS,aAAa,OAAoC,SAAgE;CACxH,OAAO,OAAO,KAAK,SAAmB;EAEpC,IAAI,OAAO,SAAS,UAAU,OAAO,QAAQ,IAAI;EACjD,IAAI,KAAK,SAASF,kBAAAA,UAAU,OAAO,OAAO;EAE1C,MAAM,OAAO,EAAE,GAAG,KAAK;EACvB,KAAK,MAAM,SAASG,iBAAAA,sBAAsB,KAAK,SAAS,CAAC,GAAG;GAC1D,MAAM,QAAQ,KAAK;GACnB,IAAI,MAAM,QAAQ,KAAK,GAAG,KAAK,SAAS,MAAM,IAAI,OAAO;GACzD,IAAI,OAAO,UAAU,YAAY,OAAO,KAAK,SAAS,QAAQ,KAAK;EACrE;EACA,IAAI,WAAW,QAAQ,KAAK,OAAO,KAAK,QAAQ,aAAa,KAAK,OAAO,OAAO;EAChF,OAAO;CACT,CAAC;AACH"}
@@ -1,4 +1,4 @@
1
- import { t as BaseNode } from "./base-IpYuh3ZP.cjs";
1
+ import { t as BaseNode } from "./base-LhsPvVY1.js";
2
2
  /**
3
3
  * JSDoc documentation metadata attached to code declarations.
4
4
  */
@@ -78,6 +78,14 @@ type TypeNode = BaseNode & {
78
78
  * Whether the declaration should be exported.
79
79
  */
80
80
  export?: boolean | null;
81
+ /**
82
+ * How the declaration is written.
83
+ * - `'type'` declares `type Name = …`
84
+ * - `'interface'` declares `interface Name { … }`, so the body must be an object type
85
+ *
86
+ * @default 'type'
87
+ */
88
+ syntax?: 'type' | 'interface' | null;
81
89
  /**
82
90
  * JSDoc documentation metadata.
83
91
  */
@@ -307,39 +315,61 @@ type ImportName = string | Array<string | {
307
315
  propertyName: string;
308
316
  name?: string;
309
317
  }>;
318
+ /**
319
+ * Whether a declaration exists only at compile time (`'type'`) or also at runtime (`'value'`).
320
+ */
321
+ type Space = 'type' | 'value';
322
+ /**
323
+ * One name an import or export brings across, as in the ECMAScript `ImportEntry` record.
324
+ */
325
+ type ModuleName = {
326
+ /**
327
+ * Name in the other module: `'default'` for its default export, `'*'` for the whole module.
328
+ */
329
+ name: string;
330
+ /**
331
+ * Local name for an import, or the exported name for an export.
332
+ */
333
+ alias?: string | null;
334
+ /**
335
+ * Type or value.
336
+ * @default 'value'
337
+ */
338
+ space?: Space | null;
339
+ };
310
340
  /**
311
341
  * Represents a language-agnostic import/dependency declaration.
312
342
  *
313
343
  * @example Named import (TypeScript: `import { useState } from 'react'`)
314
344
  * ```ts
315
- * createImport({ name: ['useState'], path: 'react' })
345
+ * createImport({ names: [{ name: 'useState' }], path: 'react' })
316
346
  * ```
317
347
  *
318
348
  * @example Default import (TypeScript: `import React from 'react'`)
319
349
  * ```ts
320
- * createImport({ name: 'React', path: 'react' })
350
+ * createImport({ names: [{ name: 'default', alias: 'React' }], path: 'react' })
321
351
  * ```
322
352
  *
323
353
  * @example Type-only import (TypeScript: `import type { FC } from 'react'`)
324
354
  * ```ts
325
- * createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
355
+ * createImport({ names: [{ name: 'FC', space: 'type' }], path: 'react' })
326
356
  * ```
327
357
  *
328
358
  * @example Namespace import (TypeScript: `import * as React from 'react'`)
329
359
  * ```ts
330
- * createImport({ name: 'React', path: 'react', isNameSpace: true })
360
+ * createImport({ names: [{ name: '*', alias: 'React' }], path: 'react' })
331
361
  * ```
332
362
  */
333
363
  type ImportNode = BaseNode & {
334
364
  kind: 'Import';
365
+ /**
366
+ * The names the import brings in. `ast.file.getNames` also reads the deprecated fields.
367
+ */
368
+ names?: Array<ModuleName> | null;
335
369
  /**
336
370
  * Import name(s) to be used.
337
371
  *
338
- * @example Named imports
339
- * `['useState']`
340
- *
341
- * @example Default import
342
- * `'React'`
372
+ * @deprecated Use `names`. Removed in Kubb v6.
343
373
  */
344
374
  name: ImportName;
345
375
  /**
@@ -351,14 +381,14 @@ type ImportNode = BaseNode & {
351
381
  path: string;
352
382
  /**
353
383
  * Add a type-only import prefix.
354
- * - `true` generates `import type { Type } from './path'`
355
- * - `false` generates `import { Type } from './path'`
384
+ *
385
+ * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.
356
386
  */
357
387
  isTypeOnly?: boolean | null;
358
388
  /**
359
389
  * Import the entire module as a namespace.
360
- * - `true` generates `import * as Name from './path'`
361
- * - `false` generates a standard import
390
+ *
391
+ * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.
362
392
  */
363
393
  isNameSpace?: boolean | null;
364
394
  /**
@@ -371,34 +401,34 @@ type ImportNode = BaseNode & {
371
401
  *
372
402
  * @example Named export (TypeScript: `export { Pets } from './Pets'`)
373
403
  * ```ts
374
- * createExport({ name: ['Pets'], path: './Pets' })
404
+ * createExport({ names: [{ name: 'Pets' }], path: './Pets' })
375
405
  * ```
376
406
  *
377
407
  * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
378
408
  * ```ts
379
- * createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
409
+ * createExport({ names: [{ name: 'Pet', space: 'type' }], path: './Pet' })
380
410
  * ```
381
411
  *
382
412
  * @example Wildcard export (TypeScript: `export * from './utils'`)
383
413
  * ```ts
384
- * createExport({ path: './utils' })
414
+ * createExport({ names: [{ name: '*' }], path: './utils' })
385
415
  * ```
386
416
  *
387
417
  * @example Namespace alias (TypeScript: `export * as utils from './utils'`)
388
418
  * ```ts
389
- * createExport({ name: 'utils', path: './utils', asAlias: true })
419
+ * createExport({ names: [{ name: '*', alias: 'utils' }], path: './utils' })
390
420
  * ```
391
421
  */
392
422
  type ExportNode = BaseNode & {
393
423
  kind: 'Export';
424
+ /**
425
+ * The names the export passes on. `ast.file.getNames` also reads the deprecated fields.
426
+ */
427
+ names?: Array<ModuleName> | null;
394
428
  /**
395
429
  * Export name(s) to be used. When omitted, generates a wildcard export.
396
430
  *
397
- * @example Named exports
398
- * `['useState']`
399
- *
400
- * @example Single export
401
- * `'React'`
431
+ * @deprecated Use `names`. Removed in Kubb v6.
402
432
  */
403
433
  name?: string | Array<string> | null;
404
434
  /**
@@ -410,14 +440,14 @@ type ExportNode = BaseNode & {
410
440
  path: string;
411
441
  /**
412
442
  * Add a type-only export prefix.
413
- * - `true` generates `export type { Type } from './path'`
414
- * - `false` generates `export { Type } from './path'`
443
+ *
444
+ * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.
415
445
  */
416
446
  isTypeOnly?: boolean | null;
417
447
  /**
418
448
  * Export as an aliased namespace.
419
- * - `true` generates `export * as aliasName from './path'`
420
- * - `false` generates a standard export
449
+ *
450
+ * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.
421
451
  */
422
452
  asAlias?: boolean | null;
423
453
  };
@@ -426,7 +456,7 @@ type ExportNode = BaseNode & {
426
456
  *
427
457
  * @example Named exportable source
428
458
  * ```ts
429
- * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
459
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })
430
460
  * ```
431
461
  *
432
462
  * @example Inline unnamed code block
@@ -440,21 +470,37 @@ type SourceNode = BaseNode & {
440
470
  * Optional name identifying this source (used for deduplication and barrel generation).
441
471
  */
442
472
  name?: string | null;
473
+ /**
474
+ * Type or value. When unset, a source whose first node is a `Type` is a type.
475
+ */
476
+ space?: Space | null;
443
477
  /**
444
478
  * Mark this source as a type-only export.
479
+ *
480
+ * @deprecated Use `space: 'type'`. Removed in Kubb v6.
445
481
  */
446
482
  isTypeOnly?: boolean | null;
447
483
  /**
448
- * Mark this source as an exported declaration. The source text carries its own `export` keyword.
484
+ * Mark this source as an exported declaration, which barrels list. The source text carries its own `export` keyword.
485
+ */
486
+ export?: boolean | null;
487
+ /**
488
+ * Mark this exported source as the module's default export. Barrels skip it, since they can't re-export it by name.
489
+ */
490
+ default?: boolean | null;
491
+ /**
492
+ * @deprecated Use `export`. Removed in Kubb v6.
449
493
  */
450
494
  isExportable?: boolean | null;
451
495
  /**
452
- * Include this source in barrel/index file generation.
496
+ * @deprecated Use `export`. Removed in Kubb v6.
453
497
  */
454
498
  isIndexable?: boolean | null;
455
499
  /**
456
500
  * Marks the source as a definition that importing files absorb instead of import. `expression` is
457
501
  * the declaration's right-hand side, such as `{ body: Pet }`.
502
+ *
503
+ * @deprecated Set `inline` on the file. Removed in Kubb v6.
458
504
  */
459
505
  inline?: {
460
506
  expression: string;
@@ -476,7 +522,7 @@ type SourceNode = BaseNode & {
476
522
  * const file = createFile({
477
523
  * baseName: 'petStore.ts',
478
524
  * path: 'src/models/petStore.ts',
479
- * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],
525
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })],
480
526
  * imports: [createImport({ name: ['z'], path: 'zod' })],
481
527
  * exports: [createExport({ name: ['Pet'], path: './petStore' })],
482
528
  * })
@@ -543,37 +589,47 @@ type FileNode<TMeta extends object = object> = BaseNode & {
543
589
  *
544
590
  * Use to emit a real source file shipped inside a package (a template) into the generated
545
591
  * folder. When set, `copy` provides the file content and any `sources` nodes are ignored for
546
- * output; `sources` may still carry `name`/`isExportable`/`isIndexable` so barrel generation
592
+ * output; `sources` may still carry `name`/`export` so barrel generation
547
593
  * treats the file the same as a rendered one.
548
594
  */
549
595
  copy?: string | null;
596
+ /**
597
+ * Marks a file that is never written. Each file that imports from it gets the body of each imported declaration, such as `{ body: Pet }`, in place of its name.
598
+ */
599
+ inline?: boolean | null;
600
+ };
601
+ type ImportInput = Omit<ImportNode, 'kind' | 'name'> & {
602
+ name?: ImportName;
550
603
  };
604
+ type ExportInput = Omit<ExportNode, 'kind'>;
551
605
  /**
552
- * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
606
+ * Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
607
+ * `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.
553
608
  *
554
609
  * @example Named import
555
610
  * ```ts
556
- * createImport({ name: ['useState'], path: 'react' })
611
+ * createImport({ names: [{ name: 'useState' }], path: 'react' })
557
612
  * // import { useState } from 'react'
558
613
  * ```
559
614
  */
560
- declare const createImport: (input: Omit<ImportNode, "kind">) => ImportNode;
615
+ declare function createImport(input: ImportInput): ImportNode;
561
616
  /**
562
- * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
617
+ * Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
618
+ * `isTypeOnly` that differs from the one `names` gives overrides it.
563
619
  *
564
620
  * @example Named export
565
621
  * ```ts
566
- * createExport({ name: ['Pet'], path: './Pet' })
622
+ * createExport({ names: [{ name: 'Pet' }], path: './Pet' })
567
623
  * // export { Pet } from './Pet'
568
624
  * ```
569
625
  */
570
- declare const createExport: (input: Omit<ExportNode, "kind">) => ExportNode;
626
+ declare function createExport(input: ExportInput): ExportNode;
571
627
  /**
572
628
  * Creates a `SourceNode` representing a fragment of source code within a file.
573
629
  *
574
630
  * @example
575
631
  * ```ts
576
- * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
632
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })
577
633
  * ```
578
634
  */
579
635
  declare const createSource: (input: Omit<SourceNode, "kind">) => SourceNode;
@@ -621,4 +677,4 @@ type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind'
621
677
  * ```
622
678
  */
623
679
  declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
624
- export { createJsx as C, createFunction as S, createType as T, TextNode as _, UserFileNode as a, createBreak as b, createImport as c, BreakNode as d, CodeNode as f, JsxNode as g, JSDocNode as h, SourceNode as i, createSource as l, FunctionNode as m, FileNode as n, createExport as o, ConstNode as p, ImportNode as r, createFile as s, ExportNode as t, ArrowFunctionNode as u, TypeNode as v, createText as w, createConst as x, createArrowFunction as y };
680
+ export { createArrowFunction as C, createJsx as D, createFunction as E, createText as O, TypeNode as S, createConst as T, ConstNode as _, ImportNode as a, JsxNode as b, Space as c, createFile as d, createImport as f, CodeNode as g, BreakNode as h, ImportInput as i, createType as k, UserFileNode as l, ArrowFunctionNode as m, ExportNode as n, ModuleName as o, createSource as p, FileNode as r, SourceNode as s, ExportInput as t, createExport as u, FunctionNode as v, createBreak as w, TextNode as x, JSDocNode as y };
package/dist/file.cjs CHANGED
@@ -1,3 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_file = require("./file-Dd50jPkH.cjs");
3
- exports.inline = require_file.inlineFiles;
2
+ const require_file = require("./file-C4pqV8yl.cjs");
3
+ const require_file$1 = require("./file-DiPZBLSP.cjs");
4
+ exports.getNames = require_file.getNames;
5
+ exports.getSpace = require_file.getSpace;
6
+ exports.inline = require_file$1.inlineFiles;
package/dist/file.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { r as inlineFiles } from "./index-Csf8xsCc.cjs";
2
- export { inlineFiles as inline };
1
+ import { a as inlineFiles, n as getNames, r as getSpace } from "./index-DbQ-J072.cjs";
2
+ export { getNames, getSpace, inlineFiles as inline };
package/dist/file.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { r as inlineFiles } from "./index-cpjUxIik.js";
2
- export { inlineFiles as inline };
1
+ import { a as inlineFiles, n as getNames, r as getSpace } from "./index-BgFaJtnv.js";
2
+ export { getNames, getSpace, inlineFiles as inline };
package/dist/file.js CHANGED
@@ -1 +1,3 @@
1
- export { n as inline } from "./file-CvlMAp_d.js";
1
+ import { o as getNames, s as getSpace } from "./file-Bq2GPaxh.js";
2
+ import { n as inlineFiles } from "./file-D_ih0x7q.js";
3
+ export { getNames, getSpace, inlineFiles as inline };
@@ -1,8 +1,8 @@
1
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";
2
+ import { t as memo } from "./promise-B3YkZ4C8.js";
3
+ import { t as nodeKinds } from "./constants-BTTus9ee.js";
4
+ import { i as visitChildNodes, t as collect } from "./visitor-XA0W3OVv.js";
5
+ import { a as resolveRefName } from "./refs-Bgf8_9Ui.js";
6
6
  // src/utils/schemaGraph.ts
7
7
  const refEntries = memo.create({ weak: true });
8
8
  const checkRefEntries = memo.create({ weak: true });
@@ -141,4 +141,4 @@ var graph_exports = /* @__PURE__ */ __exportAll({
141
141
  });
142
142
  export { findCircularSchemas as a, collectUsedSchemaNames as i, collectImportedRefNames as n, collectSchemaRefs as r, graph_exports as t };
143
143
 
144
- //# sourceMappingURL=graph-BcwFCvei.js.map
144
+ //# sourceMappingURL=graph-BUEOBomo.js.map
@@ -1 +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,E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AK;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"}
1
+ {"version":3,"file":"graph-BUEOBomo.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,K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,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"}
@@ -1,8 +1,8 @@
1
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");
2
+ const require_promise = require("./promise-DScaykew.cjs");
3
+ const require_constants = require("./constants-DztHlVmY.cjs");
4
+ const require_visitor = require("./visitor-Bh1CBAOz.cjs");
5
+ const require_refs = require("./refs-rmr2LFV1.cjs");
6
6
  // src/utils/schemaGraph.ts
7
7
  const refEntries = require_promise.memo.create({ weak: true });
8
8
  const checkRefEntries = require_promise.memo.create({ weak: true });
@@ -170,4 +170,4 @@ Object.defineProperty(exports, "graph_exports", {
170
170
  }
171
171
  });
172
172
 
173
- //# sourceMappingURL=graph-DcIY6tQb.cjs.map
173
+ //# sourceMappingURL=graph-CFJ4wzFR.cjs.map
@@ -1 +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":";;;;;;AAUA,MAAM,aAAaA,gBAAAA,KAAK,OAA4C,EAAE,MAAM,KAAK,CAAC;AAClF,MAAM,kB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olveRefName","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":";;;;;;AAUA,MAAM,aAAaA,gBAAAA,KAAK,OAA4C,EAAE,MAAM,KAAK,CAAC;AAClF,MAAM,kBAAkBA,gBAAAA,KAAK,OAA4C,EAAE,MAAM,KAAK,CAAC;AACvF,MAAM,aAAaA,gBAAAA,KAAK,OAAwC,EAAE,MAAM,KAAK,CAAC;AAC9E,MAAM,mBAAmBA,gBAAAA,KAAK,OAA0C,EAAE,MAAM,KAAK,CAAC;AACtF,MAAM,wBAAwBA,gBAAAA,KAAK,OAA0C,EAAE,MAAM,KAAK,CAAC;;;;;;AAO3F,SAAS,kBAAkB,MAAkB,EAAE,UAAwD;CACrG,OAAOA,gBAAAA,KAAK,SAAS,kBAAkB,YAAY,YAAY;EA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Y,WAAW;EAC1C;CAEJ;CAEA,KAAK,MAAM,MAAM,YACf,KAAK,MAAM,UAAUI,gBAAAA,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"}
package/dist/graph.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_graph = require("./graph-DcIY6tQb.cjs");
2
+ const require_graph = require("./graph-CFJ4wzFR.cjs");
3
3
  exports.getCircularNames = require_graph.findCircularSchemas;
4
4
  exports.getImportedNames = require_graph.collectImportedRefNames;
5
5
  exports.getRefNames = require_graph.collectSchemaRefs;
package/dist/graph.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as findCircularSchemas, i as collectUsedSchemaNames, n as collectImportedRefNames, r as collectSchemaRefs } from "./index-DYDha-3I.cjs";
1
+ import { a as findCircularSchemas, i as collectUsedSchemaNames, n as collectImportedRefNames, r as collectSchemaRefs } from "./index-sdprVPKQ.cjs";
2
2
  export { findCircularSchemas as getCircularNames, collectImportedRefNames as getImportedNames, collectSchemaRefs as getRefNames, collectUsedSchemaNames as getUsedNames };
package/dist/graph.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as findCircularSchemas, i as collectUsedSchemaNames, n as collectImportedRefNames, r as collectSchemaRefs } from "./index-Dp50LM3a.js";
1
+ import { a as findCircularSchemas, i as collectUsedSchemaNames, n as collectImportedRefNames, r as collectSchemaRefs } from "./index-DbAnYRRM.js";
2
2
  export { findCircularSchemas as getCircularNames, collectImportedRefNames as getImportedNames, collectSchemaRefs as getRefNames, collectUsedSchemaNames as getUsedNames };