@kubb/ast 5.28.6 → 5.29.0

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 (102) hide show
  1. package/README.md +19 -10
  2. package/dist/factory.cjs +6 -6
  3. package/dist/factory.d.cts +2 -2
  4. package/dist/factory.d.ts +2 -2
  5. package/dist/factory.js +2 -2
  6. package/dist/{combineFileMembers-B-mdjXrG.js → file-AcKQt60j.js} +137 -123
  7. package/dist/file-AcKQt60j.js.map +1 -0
  8. package/dist/{file-DJqd2j3y.d.cts → file-CLh8vdcR.d.cts} +20 -29
  9. package/dist/{file-lssk85C8.cjs → file-DVw2Htda.cjs} +13 -13
  10. package/dist/{file-lssk85C8.cjs.map → file-DVw2Htda.cjs.map} +1 -1
  11. package/dist/{combineFileMembers-DZCKxAN0.cjs → file-Db_PYobC.cjs} +136 -122
  12. package/dist/file-Db_PYobC.cjs.map +1 -0
  13. package/dist/{file-Dg70hXm3.d.ts → file-VRwu7Set.d.ts} +20 -29
  14. package/dist/{file-CO9KnOvT.js → file-pjdyWLJ0.js} +2 -2
  15. package/dist/{file-CO9KnOvT.js.map → file-pjdyWLJ0.js.map} +1 -1
  16. package/dist/file.cjs +6 -6
  17. package/dist/file.d.cts +1 -1
  18. package/dist/file.d.ts +1 -1
  19. package/dist/file.js +2 -2
  20. package/dist/{graph-DWlCmvm6.js → graph-Cu2-NiKi.js} +78 -15
  21. package/dist/graph-Cu2-NiKi.js.map +1 -0
  22. package/dist/{graph-D6Ffy9YD.cjs → graph-CymJtC1M.cjs} +78 -15
  23. package/dist/graph-CymJtC1M.cjs.map +1 -0
  24. package/dist/graph.cjs +1 -1
  25. package/dist/graph.d.cts +1 -1
  26. package/dist/graph.d.ts +1 -1
  27. package/dist/graph.js +1 -1
  28. package/dist/{index-BGhhO3z8.d.ts → index-B4DY8ewx.d.ts} +2 -2
  29. package/dist/{index-DjwCRndP.d.ts → index-BEvWuiSq.d.ts} +1 -1
  30. package/dist/{index-DphKh9u9.d.ts → index-BXHrCLGe.d.ts} +1 -1
  31. package/dist/{index-C4ZZnf_X.d.cts → index-BgmSdJKJ.d.cts} +2 -2
  32. package/dist/{index-CKd3ogUZ.d.cts → index-C0YF5kEb.d.cts} +2 -2
  33. package/dist/{index-Ck6nqnxZ.d.cts → index-CGvAotBX.d.cts} +2 -2
  34. package/dist/{index-DVX6E3vZ.d.ts → index-CHilsNw-.d.ts} +2 -2
  35. package/dist/{index-C0_Y9yA1.d.ts → index-CsySa8TT.d.ts} +2 -2
  36. package/dist/{index-BM3jzSca.d.ts → index-DA-Ztg07.d.ts} +1 -1
  37. package/dist/{index-CiVsdeOh.d.cts → index-DPGecgel.d.cts} +1 -1
  38. package/dist/{index-DdD4PIY8.d.cts → index-Dbtc7izw.d.cts} +1 -1
  39. package/dist/{index-DSW89P6k.d.cts → index-QDfAzfWY.d.cts} +1 -1
  40. package/dist/{index-B8ZxUpy4.d.ts → index-QZa0vqFW.d.ts} +1 -1
  41. package/dist/{index-7A3j-6Np.d.cts → index-oY3-BSwC.d.cts} +1 -1
  42. package/dist/index.cjs +8 -8
  43. package/dist/index.d.cts +9 -9
  44. package/dist/index.d.ts +9 -9
  45. package/dist/index.js +8 -8
  46. package/dist/isRecord-CwlfDtHp.cjs +16 -0
  47. package/dist/isRecord-CwlfDtHp.cjs.map +1 -0
  48. package/dist/isRecord-DaSp13D_.js +11 -0
  49. package/dist/isRecord-DaSp13D_.js.map +1 -0
  50. package/dist/{json-DeqPhPUQ.js → json-IKokiUCp.js} +34 -19
  51. package/dist/json-IKokiUCp.js.map +1 -0
  52. package/dist/{json-KV2VhBue.cjs → json-mEYdjumm.cjs} +34 -19
  53. package/dist/json-mEYdjumm.cjs.map +1 -0
  54. package/dist/json.cjs +1 -1
  55. package/dist/json.d.cts +1 -1
  56. package/dist/json.d.ts +1 -1
  57. package/dist/json.js +1 -1
  58. package/dist/{macro-3uGSg-ic.js → macro-DhgoqDs6.js} +2 -2
  59. package/dist/{macro-3uGSg-ic.js.map → macro-DhgoqDs6.js.map} +1 -1
  60. package/dist/{macro-Ywn4-0s5.cjs → macro-h3bm9G48.cjs} +2 -2
  61. package/dist/{macro-Ywn4-0s5.cjs.map → macro-h3bm9G48.cjs.map} +1 -1
  62. package/dist/macro.cjs +1 -1
  63. package/dist/macro.d.cts +1 -1
  64. package/dist/macro.d.ts +1 -1
  65. package/dist/macro.js +1 -1
  66. package/dist/{node-BeccjrHH.cjs → node-Dhh4jTDv.cjs} +2 -2
  67. package/dist/{node-BeccjrHH.cjs.map → node-Dhh4jTDv.cjs.map} +1 -1
  68. package/dist/{node-Dm56432_.js → node-Dy0mq_hi.js} +2 -2
  69. package/dist/{node-Dm56432_.js.map → node-Dy0mq_hi.js.map} +1 -1
  70. package/dist/node.cjs +2 -2
  71. package/dist/node.d.cts +2 -2
  72. package/dist/node.d.ts +2 -2
  73. package/dist/node.js +2 -2
  74. package/dist/{nodes-KgbYiyJQ.js → nodes-B-MW8yk-.js} +2 -2
  75. package/dist/{nodes-KgbYiyJQ.js.map → nodes-B-MW8yk-.js.map} +1 -1
  76. package/dist/{nodes-BGxHocS_.cjs → nodes-BjVv21pb.cjs} +12 -12
  77. package/dist/{nodes-BGxHocS_.cjs.map → nodes-BjVv21pb.cjs.map} +1 -1
  78. package/dist/promise-DMQPWp6M.cjs.map +1 -1
  79. package/dist/promise-bi4pc8Xr.js.map +1 -1
  80. package/dist/{schema-XGRiAvok.cjs → schema-CMe0Dvgd.cjs} +2 -2
  81. package/dist/{schema-XGRiAvok.cjs.map → schema-CMe0Dvgd.cjs.map} +1 -1
  82. package/dist/{schema-B05JSQRq.js → schema-CVIk19Mh.js} +2 -2
  83. package/dist/{schema-B05JSQRq.js.map → schema-CVIk19Mh.js.map} +1 -1
  84. package/dist/schema.cjs +2 -2
  85. package/dist/schema.d.cts +2 -2
  86. package/dist/schema.d.ts +2 -2
  87. package/dist/schema.js +2 -2
  88. package/dist/{visitor-xxcbpM5-.d.ts → visitor-BWHpwRgc.d.ts} +2 -2
  89. package/dist/{visitor-BIldddZd.d.cts → visitor-CPlsMCPZ.d.cts} +2 -2
  90. package/dist/{visitor-DA5yfOJz.js → visitor-CitcdWu0.js} +5 -10
  91. package/dist/visitor-CitcdWu0.js.map +1 -0
  92. package/dist/{visitor-DhuKS-7x.cjs → visitor-DT712cxr.cjs} +5 -10
  93. package/dist/visitor-DT712cxr.cjs.map +1 -0
  94. package/package.json +1 -1
  95. package/dist/combineFileMembers-B-mdjXrG.js.map +0 -1
  96. package/dist/combineFileMembers-DZCKxAN0.cjs.map +0 -1
  97. package/dist/graph-D6Ffy9YD.cjs.map +0 -1
  98. package/dist/graph-DWlCmvm6.js.map +0 -1
  99. package/dist/json-DeqPhPUQ.js.map +0 -1
  100. package/dist/json-KV2VhBue.cjs.map +0 -1
  101. package/dist/visitor-DA5yfOJz.js.map +0 -1
  102. package/dist/visitor-DhuKS-7x.cjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"combineFileMembers-B-mdjXrG.js","names":[],"sources":["../src/utils/moduleNames.ts","../src/nodes/base.ts","../src/nodes/file.ts","../src/utils/combineFileMembers.ts"],"sourcesContent":["import type { ExportNode, ImportNode, ModuleName, SourceNode, Space } from '../nodes/file.ts'\n\n/**\n * Returns the names an import or export brings across. A node built with the deprecated fields gets them from\n * those, each with an explicit `space`, so it prints exactly as before.\n */\nexport function getNames(node: ImportNode | ExportNode): Array<ModuleName> {\n if (node.names) return node.names\n return node.kind === 'Import' ? fromDeprecatedImport(node) : fromDeprecatedExport(node)\n}\n\n/**\n * Returns `true` when a source is an exported declaration. Reads the deprecated `isIndexable` and `isExportable`, in that order, when `export` is unset.\n */\nexport function isExported(source: Pick<SourceNode, 'export' | 'isIndexable' | 'isExportable'>): boolean {\n return !!(source.export ?? source.isIndexable ?? source.isExportable)\n}\n\nexport function getSpace(source: SourceNode): Space {\n if (source.space) return source.space\n if (source.isTypeOnly != null) return source.isTypeOnly ? 'type' : 'value'\n return source.nodes?.[0]?.kind === 'Type' ? 'type' : 'value'\n}\n\nexport type DeprecatedImport = Pick<ImportNode, 'name' | 'isTypeOnly' | 'isNameSpace'>\nexport type DeprecatedExport = Pick<ExportNode, 'name' | 'isTypeOnly' | 'asAlias'>\n\n/**\n * @deprecated Converts a node built with `name`, `isTypeOnly` and `isNameSpace` to `names`. Removed in Kubb v6.\n */\nfunction fromDeprecatedImport({ name, isTypeOnly, isNameSpace }: DeprecatedImport): Array<ModuleName> {\n const space: Space = isTypeOnly ? 'type' : 'value'\n if (!Array.isArray(name)) return [{ name: isNameSpace ? '*' : 'default', alias: name, space }]\n return name.map((item) => (typeof item === 'string' ? { name: item, space } : { name: item.propertyName, ...(item.name ? { alias: item.name } : {}), space }))\n}\n\n/**\n * @deprecated Converts a node built with `name`, `isTypeOnly` and `asAlias` to `names`. Removed in Kubb v6.\n */\nfunction fromDeprecatedExport({ name, isTypeOnly, asAlias }: DeprecatedExport): Array<ModuleName> {\n const space: Space = isTypeOnly ? 'type' : 'value'\n if (name == null) return [{ name: '*', space }]\n if (!Array.isArray(name)) return [asAlias ? { name: '*', alias: name, space } : { name, space }]\n return name.map((item) => ({ name: item, space }))\n}\n\n/**\n * @deprecated The old import fields for `names`, for code that still reads them. Removed in Kubb v6.\n */\nexport function toDeprecatedImport(names: ReadonlyArray<ModuleName>): DeprecatedImport {\n const isTypeOnly = names.length > 0 && names.every((item) => item.space === 'type')\n const [first] = names\n if (names.length === 1 && first?.alias && (first.name === '*' || first.name === 'default')) {\n return { name: first.alias, isTypeOnly, isNameSpace: first.name === '*' }\n }\n return { name: names.map((item) => (item.alias ? { propertyName: item.name, name: item.alias } : item.name)), isTypeOnly, isNameSpace: false }\n}\n\n/**\n * @deprecated The old export fields for `names`; an alias stands in for its name. Removed in Kubb v6.\n */\nexport function toDeprecatedExport(names: ReadonlyArray<ModuleName>): DeprecatedExport {\n const isTypeOnly = names.length > 0 && names.every((item) => item.space === 'type')\n const [first] = names\n if (names.length === 1 && first?.name === '*') {\n return first.alias ? { name: first.alias, isTypeOnly, asAlias: true } : { isTypeOnly, asAlias: false }\n }\n return { name: names.map((item) => item.alias ?? item.name), isTypeOnly, asAlias: false }\n}\n","import type { ValueOf } from '@internals/utils'\nimport type { nodeKinds } from '../constants.ts'\n\n/**\n * `kind` values used by AST nodes.\n *\n * @example\n * ```ts\n * const kind: NodeKind = 'Schema'\n * ```\n */\nexport type NodeKind = ValueOf<typeof nodeKinds>\n\n/**\n * Base shape shared by all AST nodes.\n *\n * @example\n * ```ts\n * const base: BaseNode = { kind: 'Input' }\n * ```\n */\nexport type BaseNode = {\n /**\n * Node discriminator.\n */\n kind: NodeKind\n /**\n * Where the node comes from in the input, in the form the adapter's `locate` reads. Document\n * adapters such as OpenAPI and AsyncAPI use an RFC 6901 JSON pointer, for example\n * `#/components/schemas/Pet`. Plugins can copy it to the code nodes they emit.\n */\n pointer?: string\n}\n\n/** `Omit` applied to each member of a union, so the union survives. */\nexport type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\n/** Builds a `createX` factory for a node whose only computed field is `kind`. */\nexport function nodeFactory<T extends BaseNode>(kind: T['kind']): (input: Omit<T, 'kind'>) => T {\n return (input) => {\n const node = { ...input, kind }\n return node as T\n }\n}\n","import { hash } from 'node:crypto'\nimport path from 'node:path'\nimport { nodeKinds } from '../constants.ts'\nimport { combineExports, combineImports, combineSources } from '../utils/combineFileMembers.ts'\nimport { getNames, toDeprecatedExport, toDeprecatedImport } from '../utils/moduleNames.ts'\nimport { getNodeText } from '../utils/nodeText.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\nimport type { CodeNode } from './code.ts'\n\n/**\n * Supported file extensions.\n */\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type ImportName = string | Array<string | { propertyName: string; name?: string }>\n\n/**\n * Whether a declaration exists only at compile time (`'type'`) or also at runtime (`'value'`).\n */\nexport type Space = 'type' | 'value'\n\n/**\n * One name an import or export brings across, as in the ECMAScript `ImportEntry` record.\n */\nexport type ModuleName = {\n /**\n * Name in the other module: `'default'` for its default export, `'*'` for the whole module.\n */\n name: string\n /**\n * Local name for an import, or the exported name for an export.\n */\n alias?: string | null\n /**\n * Type or value.\n * @default 'value'\n */\n space?: Space | null\n}\n\n/**\n * Represents a language-agnostic import/dependency declaration.\n *\n * @example Named import (TypeScript: `import { useState } from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'useState' }], path: 'react' })\n * ```\n *\n * @example Default import (TypeScript: `import React from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'default', alias: 'React' }], path: 'react' })\n * ```\n *\n * @example Type-only import (TypeScript: `import type { FC } from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'FC', space: 'type' }], path: 'react' })\n * ```\n *\n * @example Namespace import (TypeScript: `import * as React from 'react'`)\n * ```ts\n * createImport({ names: [{ name: '*', alias: 'React' }], path: 'react' })\n * ```\n */\nexport type ImportNode = BaseNode & {\n kind: 'Import'\n /**\n * The names the import brings in. `ast.file.getNames` also reads the deprecated fields.\n */\n names?: Array<ModuleName> | null\n /**\n * Import name(s) to be used.\n *\n * @deprecated Use `names`. Removed in Kubb v6.\n */\n name: ImportName\n /**\n * Path for the import.\n *\n * @example\n * `'@kubb/core'`\n */\n path: string\n /**\n * Add a type-only import prefix.\n *\n * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Import the entire module as a namespace.\n *\n * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.\n */\n isNameSpace?: boolean | null\n /**\n * When set, the import path is resolved relative to this root.\n */\n root?: string | null\n}\n\n/**\n * Represents a language-agnostic export/public API declaration.\n *\n * @example Named export (TypeScript: `export { Pets } from './Pets'`)\n * ```ts\n * createExport({ names: [{ name: 'Pets' }], path: './Pets' })\n * ```\n *\n * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)\n * ```ts\n * createExport({ names: [{ name: 'Pet', space: 'type' }], path: './Pet' })\n * ```\n *\n * @example Wildcard export (TypeScript: `export * from './utils'`)\n * ```ts\n * createExport({ names: [{ name: '*' }], path: './utils' })\n * ```\n *\n * @example Namespace alias (TypeScript: `export * as utils from './utils'`)\n * ```ts\n * createExport({ names: [{ name: '*', alias: 'utils' }], path: './utils' })\n * ```\n */\nexport type ExportNode = BaseNode & {\n kind: 'Export'\n /**\n * The names the export passes on. `ast.file.getNames` also reads the deprecated fields.\n */\n names?: Array<ModuleName> | null\n /**\n * Export name(s) to be used. When omitted, generates a wildcard export.\n *\n * @deprecated Use `names`. Removed in Kubb v6.\n */\n name?: string | Array<string> | null\n /**\n * Path for the export.\n *\n * @example\n * `'@kubb/core'`\n */\n path: string\n /**\n * Add a type-only export prefix.\n *\n * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Export as an aliased namespace.\n *\n * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.\n */\n asAlias?: boolean | null\n}\n\n/**\n * Represents a fragment of source code within a file.\n *\n * @example Named exportable source\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })\n * ```\n *\n * @example Inline unnamed code block\n * ```ts\n * createSource({ nodes: [createText('const x = 1')] })\n * ```\n */\nexport type SourceNode = BaseNode & {\n kind: 'Source'\n /**\n * Optional name identifying this source (used for deduplication and barrel generation).\n */\n name?: string | null\n /**\n * Type or value. When unset, a source whose first node is a `Type` is a type.\n */\n space?: Space | null\n /**\n * Mark this source as a type-only export.\n *\n * @deprecated Use `space: 'type'`. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Mark this source as an exported declaration, which barrels list. The source text carries its own `export` keyword.\n */\n export?: boolean | null\n /**\n * Mark this exported source as the module's default export. Barrels skip it, since they can't re-export it by name.\n */\n default?: boolean | null\n /**\n * @deprecated Use `export`. Removed in Kubb v6.\n */\n isExportable?: boolean | null\n /**\n * @deprecated Use `export`. Removed in Kubb v6.\n */\n isIndexable?: boolean | null\n /**\n * Marks the source as a definition that importing files absorb instead of import. `expression` is\n * the declaration's right-hand side, such as `{ body: Pet }`.\n *\n * @deprecated Set `inline` on the file. Removed in Kubb v6.\n */\n inline?: { expression: string } | null\n /**\n * Child nodes that make up this source fragment, in DOM order.\n * Use a {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * Represents a fully resolved file in the AST.\n *\n * Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input\n * and deduplicates `imports`, `exports`, and `sources`.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of the path\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n */\nexport type FileNode<TMeta extends object = object> = BaseNode & {\n kind: 'File'\n /**\n * Unique identifier derived from a SHA256 hash of the file path. `createFile`\n * computes it, so callers do not need to provide it.\n */\n id: string\n /**\n * File name without extension, derived from `baseName`.\n *\n * @see https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n /**\n * File base name, including extension, shaped like `${name}${extname}`.\n *\n * @see https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: `${string}.${string}`\n /**\n * Full qualified path to the file.\n */\n path: string\n /**\n * File extension extracted from `baseName`.\n */\n extname: Extname\n /**\n * Deduplicated list of source code fragments.\n */\n sources: Array<SourceNode>\n /**\n * Deduplicated list of import declarations.\n */\n imports: Array<ImportNode>\n /**\n * Deduplicated list of export declarations.\n */\n exports: Array<ExportNode>\n /**\n * Optional metadata attached to this file, read by plugins during barrel generation.\n */\n meta?: TMeta\n /**\n * Optional banner prepended to the generated file content.\n * Accepts `null` so `resolver.default.banner()` results can be passed directly.\n */\n banner?: string | null\n /**\n * Optional footer appended to the generated file content.\n * Accepts `null` so `resolver.default.footer()` results can be passed directly.\n */\n footer?: string | null\n /**\n * Absolute on-disk path to copy into the output, through the parser's `copy` hook when it has one.\n *\n * Use to emit a real source file shipped inside a package (a template) into the generated\n * folder. When set, `copy` provides the file content and any `sources` nodes are ignored for\n * output; `sources` may still carry `name`/`export` so barrel generation\n * treats the file the same as a rendered one.\n */\n copy?: string | null\n /**\n * 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.\n */\n inline?: boolean | null\n}\n\nexport type ImportInput = Omit<ImportNode, 'kind' | 'name'> & { name?: ImportName }\n\nexport type ExportInput = Omit<ExportNode, 'kind'>\n\n// A spread node carries the deprecated fields derived from its `names`, so only a value that differs is an override.\ntype Override<TValue> = { value: TValue | null | undefined; derived: TValue | null | undefined }\n\nfunction overrideSpace(names: Array<ModuleName>, { value, derived }: Override<boolean>): Array<ModuleName> {\n if (value == null || value === derived) return names\n const space = value ? 'type' : 'value'\n return names.map((item) => ({ ...item, space }))\n}\n\nconst isOverride = ({ value, derived }: Override<unknown>): boolean => value !== undefined && JSON.stringify(value) !== JSON.stringify(derived)\n\n// Object spread copies symbol keys, so `{ ...imp, names }` carries the fields `imp` derived and they can be told apart from an override.\nconst DERIVED = Symbol.for('kubb.ast.derived')\n// `name` is stored as JSON, so changing the node's `name` array in place still counts as an override.\ntype Derived = { name: string | undefined; isTypeOnly?: boolean | null }\ntype WithDerived = { [DERIVED]?: Derived }\n\n/** The deprecated fields the caller set: a value equal to the one the spread node derived is dropped, so `names` decides it. */\nfunction ownFields<TName>(input: { name?: TName; isTypeOnly?: boolean | null } & WithDerived): { name?: TName; isTypeOnly?: boolean | null } {\n const snapshot = input[DERIVED]\n if (!snapshot) return { name: input.name, isTypeOnly: input.isTypeOnly }\n return {\n name: JSON.stringify(input.name) === snapshot.name ? undefined : input.name,\n isTypeOnly: input.isTypeOnly === snapshot.isTypeOnly ? undefined : input.isTypeOnly,\n }\n}\n\nfunction withoutDerived<T extends object>(input: T): T {\n const { [DERIVED]: _, ...rest } = input as T & WithDerived\n return rest as T\n}\n\n/**\n * Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or\n * `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.\n * Fields a spread copies over unchanged are not overrides, so `{ ...imp, names }` uses the new `names`.\n *\n * @example Named import\n * ```ts\n * createImport({ names: [{ name: 'useState' }], path: 'react' })\n * // import { useState } from 'react'\n * ```\n */\nexport function createImport(input: ImportInput): ImportNode {\n if (!input.names) return { ...withoutDerived(input), name: input.name ?? [], kind: nodeKinds.import }\n const own = ownFields(input)\n const derived = toDeprecatedImport(input.names)\n if (isOverride({ value: own.name, derived: derived.name })) return { ...withoutDerived(input), names: null, name: own.name ?? [], kind: nodeKinds.import }\n const names = overrideSpace(input.names, { value: own.isTypeOnly, derived: derived.isTypeOnly })\n const fields = toDeprecatedImport(names)\n const node: ImportNode & WithDerived = {\n ...input,\n ...fields,\n names,\n [DERIVED]: { name: JSON.stringify(fields.name), isTypeOnly: fields.isTypeOnly },\n kind: nodeKinds.import,\n }\n return node\n}\n\n/**\n * Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or\n * `isTypeOnly` that differs from the one `names` gives overrides it. Fields a spread copies over unchanged are not\n * overrides, so `{ ...exp, names }` uses the new `names`.\n *\n * @example Named export\n * ```ts\n * createExport({ names: [{ name: 'Pet' }], path: './Pet' })\n * // export { Pet } from './Pet'\n * ```\n */\nexport function createExport(input: ExportInput): ExportNode {\n if (!input.names) return { ...withoutDerived(input), kind: nodeKinds.export }\n const own = ownFields(input)\n const derived = toDeprecatedExport(input.names)\n if (isOverride({ value: own.name, derived: derived.name })) return { ...withoutDerived(input), name: own.name, names: null, kind: nodeKinds.export }\n const names = overrideSpace(input.names, { value: own.isTypeOnly, derived: derived.isTypeOnly })\n const fields = toDeprecatedExport(names)\n const node: ExportNode & WithDerived = {\n ...input,\n ...fields,\n name: fields.name,\n names,\n [DERIVED]: { name: JSON.stringify(fields.name), isTypeOnly: fields.isTypeOnly },\n kind: nodeKinds.export,\n }\n return node\n}\n\n/**\n * Creates a `SourceNode` representing a fragment of source code within a file.\n *\n * @example\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })\n * ```\n */\nexport const createSource = nodeFactory<SourceNode>(nodeKinds.source)\n\n/**\n * Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed\n * and `imports`/`exports`/`sources` are deduplicated.\n */\nexport type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> &\n Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>\n\n/**\n * Creates a fully resolved `FileNode` from a file input descriptor.\n *\n * Computes:\n * - `id` SHA256 hash of the file path\n * - `name` `baseName` without extension\n * - `extname` extension extracted from `baseName`\n *\n * Deduplicates:\n * - `sources` via `combineSources`\n * - `exports` via `combineExports`\n * - `imports` via `combineImports` (also filters unused imports)\n *\n * @throws {Error} when `baseName` has no extension.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of 'src/models/petStore.ts'\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n *\n * @example Copy a real file into the output\n * ```ts\n * const file = createFile({\n * baseName: 'client.ts',\n * path: 'src/gen/client.ts',\n * copy: '/abs/path/to/templates/client.ts',\n * })\n * ```\n */\nexport function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta> {\n const extname = path.extname(input.baseName) as `.${string}`\n if (!extname) {\n throw new Error(`No extname found for ${input.baseName}`)\n }\n\n const resolvedExports = input.exports?.length ? combineExports(input.exports) : []\n const resolvedSources = input.sources?.length ? combineSources(input.sources) : []\n\n // Skip building the source text and local-name set when there are no imports to resolve against them.\n const resolvedImports: Array<ImportNode> = (() => {\n if (!input.imports?.length) return []\n\n const sourceParts: Array<string> = []\n const localNames = new Set<string>()\n // Only the sources the file keeps count: an import used just by a dropped duplicate is unused.\n for (const item of resolvedSources) {\n const extracted = item.nodes && getNodeText(item.nodes)\n if (extracted) sourceParts.push(extracted)\n if (item.name) localNames.add(item.name)\n }\n const source = sourceParts.join('\\n') || undefined\n const combinedImports = combineImports(input.imports, resolvedExports, source)\n // Consolidating output (`mode: 'file'`) can put a symbol's definition and an import of it in the\n // same file: by path when the import still targets this file, by name when consolidation moved it.\n return combinedImports.flatMap((imp) => {\n if (imp.path === input.path) return []\n const names = getNames(imp)\n const kept = names.filter((item) => !localNames.has(item.alias ?? item.name))\n if (!kept.length) return []\n return [kept.length === names.length ? imp : createImport({ path: imp.path, ...(imp.root != null ? { root: imp.root } : {}), names: kept })]\n })\n })()\n\n return {\n ...input,\n kind: nodeKinds.file,\n id: hash('sha256', input.path, 'hex'),\n name: path.basename(input.baseName, extname),\n extname,\n imports: resolvedImports,\n exports: resolvedExports,\n sources: resolvedSources,\n meta: (input.meta ?? {}) as TMeta,\n }\n}\n","/**\n * File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and\n * export entries of one file, while `combineSources` deduplicates source entries in original order.\n * `combineImports` also drops imports nothing references. This works on a file's members, not on\n * schema content.\n */\nimport path from 'node:path'\nimport process from 'node:process'\nimport { memo } from '@internals/utils'\nimport { createExport, createImport, type ExportNode, type ImportNode, type ModuleName, type SourceNode, type Space } from '../nodes/file.ts'\nimport { getNames, getSpace, isExported } from './moduleNames.ts'\n\nconst IDENTIFIER_RUN = /[\\w$]+/g\n\n/**\n * How many imports a file needs before indexing the source beats scanning it once per name.\n */\nconst INDEX_ABOVE_IMPORTS = 128\n\ntype Form = 'named' | 'default' | '*'\n\ntype Statement = { path: string; root?: string | null; form: Form; space: Space; names: Array<ModuleName> }\n\nconst importForm = (item: ModuleName): Form => (item.alias && (item.name === '*' || item.name === 'default') ? item.name : 'named')\nconst exportForm = (item: ModuleName): Form => (item.name === '*' ? '*' : 'named')\nconst label = (item: ModuleName): string => (item.alias ? `${item.name} as ${item.alias}` : item.name)\n\nfunction statementKey({ path, form, space, names }: Statement): string {\n return form === 'named' ? `${path}\\0named\\0${space}` : `${path}\\0${form}\\0${names[0]?.alias ?? ''}\\0${space}`\n}\n\nfunction toStatements(nodes: ReadonlyArray<ImportNode | ExportNode>, formOf: (item: ModuleName) => Form): Array<Statement> {\n return nodes.flatMap((node) => {\n const statements = new Map<string, Statement>()\n for (const item of getNames(node)) {\n const statement: Statement = {\n path: node.path,\n root: node.kind === 'Import' ? node.root : undefined,\n form: formOf(item),\n space: item.space ?? 'value',\n names: [],\n }\n const key = statementKey({ ...statement, names: [item] })\n const existing = statements.get(key) ?? statement\n statements.set(key, existing)\n existing.names.push(item)\n }\n return [...statements.values()]\n })\n}\n\n/**\n * Relative specifiers by `root`, then `path`. `createFile` sorts a file's imports again on every\n * merge, and the path math dominated that sort on large specs. Two levels keep the existing strings\n * as keys, so lookups reuse their hashes instead of hashing a new joined key each time.\n */\nconst specifierCache = memo.create<string, Map<string, string>>({ max: 10_000 })\n\n/**\n * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.\n *\n * @example\n * ```ts\n * getRelativePath('/root/src/models/pet.ts', '/root/lib/client.ts') // '../../lib/client.ts'\n * ```\n */\nexport function getRelativePath(root: string, filePath: string): string {\n // A relative input resolves against the working directory, so that directory is part of its key.\n const rootKey = path.isAbsolute(root) && path.isAbsolute(filePath) ? root : `${process.cwd()}\\u0000${root}`\n const byPath = memo(specifierCache, rootKey, () => new Map<string, string>())\n return memo(byPath, filePath, () => {\n const relative = path.relative(path.dirname(root), filePath).replaceAll('\\\\', '/')\n return relative.startsWith('../') ? relative : `./${relative}`\n })\n}\n\n/** The specifier a member is written with, so sorting on it gives the same order on every OS. */\nfunction specifier(node: { path: string; root?: string | null }): string {\n return node.root ? getRelativePath(node.root, node.path) : node.path\n}\n\nfunction sortKey(statement: Statement): string {\n const form = statement.form === 'named' ? '1' : '0'\n const space = statement.space === 'type' ? '0' : '1'\n return `${form}:${space}:${specifier(statement)}:${statement.names.map(label).toSorted().join('\\0')}`\n}\n\nfunction mergeStatements(statements: Array<Statement>, keep: (item: ModuleName, statement: Statement) => boolean = () => true): Array<Statement> {\n const merged = new Map<string, { statement: Statement; seen: Set<string> }>()\n const sorted = statements.map((statement) => ({ statement, key: sortKey(statement) })).sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))\n\n for (const { statement } of sorted) {\n const key = statementKey(statement)\n const entry = merged.get(key) ?? { statement: { ...statement, names: [] }, seen: new Set<string>() }\n merged.set(key, entry)\n for (const item of statement.names) {\n const id = item.alias ?? item.name\n if (entry.seen.has(id) || !keep(item, statement)) continue\n entry.seen.add(id)\n entry.statement.names.push(item)\n }\n }\n\n const result = [...merged.values()].map(({ statement }) => statement)\n // A name kept as a value also serves its type uses, so a type statement from the same path must not bind it again.\n const bound = ({ path, item }: { path: string; item: ModuleName }) => `${path}\\0${item.alias ?? item.name}`\n const values = new Set(result.filter(({ space }) => space === 'value').flatMap(({ path, names }) => names.map((item) => bound({ path, item }))))\n return result\n .map((statement) =>\n statement.space === 'type' ? { ...statement, names: statement.names.filter((item) => !values.has(bound({ path: statement.path, item }))) } : statement,\n )\n .filter((statement) => statement.names.length > 0)\n}\n\n/**\n * Deduplicates `SourceNode` objects by `name + export + space`, keeping the first of each\n * key. An unnamed source only drops when the same node appears twice, so markdown can repeat a\n * paragraph or a table. Returns the deduplicated array in original order.\n */\nexport function combineSources(sources: Array<SourceNode>): Array<SourceNode> {\n const seen = new Set<SourceNode | string>()\n return sources.filter((source) => {\n const key = source.name != null ? `${source.name}:${isExported(source)}:${getSpace(source)}` : source\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n}\n\n/**\n * Deduplicates and merges `ExportNode` objects: one export per path, form and space. Returns a sorted array.\n */\nexport function combineExports(exports: Array<ExportNode>): Array<ExportNode> {\n // Built through `createExport`, so a later `{ ...exp, names }` keeps the new names.\n return mergeStatements(toStatements(exports, exportForm)).map(({ path, names }) => createExport({ path, names }))\n}\n\n/**\n * Deduplicates and merges `ImportNode` objects, filtering out unused imports.\n *\n * Retains imports that are referenced in `source` or re-exported. One import per path, form and space. Returns\n * a sorted, deduplicated, filtered array.\n */\nexport function combineImports(imports: Array<ImportNode>, exports: Array<ExportNode>, source?: string): Array<ImportNode> {\n // Build a lookup of all exported names to retain imports that are re-exported\n const exportedNames = new Set(exports.flatMap((node) => getNames(node).map((item) => item.alias ?? item.name)))\n // `createFile` re-runs on every merge into a file, so scanning the source once per import name\n // costs a heavily merged file that scan again for every fragment it already holds. Indexing pays\n // for itself there, and costs more than it saves on the small files the default output produces.\n const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? new Set(source.match(IDENTIFIER_RUN)) : null\n\n // A name in the index is used. One that is not still might be, inside a longer identifier, so the\n // substring test stays behind it.\n const isUsed = (importName: string): boolean => !source || identifiers?.has(importName) || source.includes(importName) || exportedNames.has(importName)\n\n const statements = toStatements(\n imports.filter((node) => node.path !== node.root),\n importForm,\n )\n\n // Paths that keep at least one used named import. A default import from such a path is retained\n // even when its binding can't be found in `source` e.g. a generated `client` default import\n // alongside `import type { Client } from <same path>`, where merged grouped output omits the body.\n const pathsWithUsedNamedImport = new Set(\n statements.filter(({ form, names }) => form === 'named' && names.some((item) => isUsed(item.alias ?? item.name))).map(({ path }) => path),\n )\n const keep = (item: ModuleName, { form, path }: Statement) => isUsed(item.alias ?? item.name) || (form !== 'named' && pathsWithUsedNamedImport.has(path))\n\n return mergeStatements(statements, keep).map(({ path, root, names }) => createImport({ path, ...(root != null ? { root } : {}), names }))\n}\n"],"mappings":";;;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KxAN0.cjs","names":["nodeKinds","path","getNodeText","hash","memo","path","process"],"sources":["../src/utils/moduleNames.ts","../src/nodes/base.ts","../src/nodes/file.ts","../src/utils/combineFileMembers.ts"],"sourcesContent":["import type { ExportNode, ImportNode, ModuleName, SourceNode, Space } from '../nodes/file.ts'\n\n/**\n * Returns the names an import or export brings across. A node built with the deprecated fields gets them from\n * those, each with an explicit `space`, so it prints exactly as before.\n */\nexport function getNames(node: ImportNode | ExportNode): Array<ModuleName> {\n if (node.names) return node.names\n return node.kind === 'Import' ? fromDeprecatedImport(node) : fromDeprecatedExport(node)\n}\n\n/**\n * Returns `true` when a source is an exported declaration. Reads the deprecated `isIndexable` and `isExportable`, in that order, when `export` is unset.\n */\nexport function isExported(source: Pick<SourceNode, 'export' | 'isIndexable' | 'isExportable'>): boolean {\n return !!(source.export ?? source.isIndexable ?? source.isExportable)\n}\n\nexport function getSpace(source: SourceNode): Space {\n if (source.space) return source.space\n if (source.isTypeOnly != null) return source.isTypeOnly ? 'type' : 'value'\n return source.nodes?.[0]?.kind === 'Type' ? 'type' : 'value'\n}\n\nexport type DeprecatedImport = Pick<ImportNode, 'name' | 'isTypeOnly' | 'isNameSpace'>\nexport type DeprecatedExport = Pick<ExportNode, 'name' | 'isTypeOnly' | 'asAlias'>\n\n/**\n * @deprecated Converts a node built with `name`, `isTypeOnly` and `isNameSpace` to `names`. Removed in Kubb v6.\n */\nfunction fromDeprecatedImport({ name, isTypeOnly, isNameSpace }: DeprecatedImport): Array<ModuleName> {\n const space: Space = isTypeOnly ? 'type' : 'value'\n if (!Array.isArray(name)) return [{ name: isNameSpace ? '*' : 'default', alias: name, space }]\n return name.map((item) => (typeof item === 'string' ? { name: item, space } : { name: item.propertyName, ...(item.name ? { alias: item.name } : {}), space }))\n}\n\n/**\n * @deprecated Converts a node built with `name`, `isTypeOnly` and `asAlias` to `names`. Removed in Kubb v6.\n */\nfunction fromDeprecatedExport({ name, isTypeOnly, asAlias }: DeprecatedExport): Array<ModuleName> {\n const space: Space = isTypeOnly ? 'type' : 'value'\n if (name == null) return [{ name: '*', space }]\n if (!Array.isArray(name)) return [asAlias ? { name: '*', alias: name, space } : { name, space }]\n return name.map((item) => ({ name: item, space }))\n}\n\n/**\n * @deprecated The old import fields for `names`, for code that still reads them. Removed in Kubb v6.\n */\nexport function toDeprecatedImport(names: ReadonlyArray<ModuleName>): DeprecatedImport {\n const isTypeOnly = names.length > 0 && names.every((item) => item.space === 'type')\n const [first] = names\n if (names.length === 1 && first?.alias && (first.name === '*' || first.name === 'default')) {\n return { name: first.alias, isTypeOnly, isNameSpace: first.name === '*' }\n }\n return { name: names.map((item) => (item.alias ? { propertyName: item.name, name: item.alias } : item.name)), isTypeOnly, isNameSpace: false }\n}\n\n/**\n * @deprecated The old export fields for `names`; an alias stands in for its name. Removed in Kubb v6.\n */\nexport function toDeprecatedExport(names: ReadonlyArray<ModuleName>): DeprecatedExport {\n const isTypeOnly = names.length > 0 && names.every((item) => item.space === 'type')\n const [first] = names\n if (names.length === 1 && first?.name === '*') {\n return first.alias ? { name: first.alias, isTypeOnly, asAlias: true } : { isTypeOnly, asAlias: false }\n }\n return { name: names.map((item) => item.alias ?? item.name), isTypeOnly, asAlias: false }\n}\n","import type { ValueOf } from '@internals/utils'\nimport type { nodeKinds } from '../constants.ts'\n\n/**\n * `kind` values used by AST nodes.\n *\n * @example\n * ```ts\n * const kind: NodeKind = 'Schema'\n * ```\n */\nexport type NodeKind = ValueOf<typeof nodeKinds>\n\n/**\n * Base shape shared by all AST nodes.\n *\n * @example\n * ```ts\n * const base: BaseNode = { kind: 'Input' }\n * ```\n */\nexport type BaseNode = {\n /**\n * Node discriminator.\n */\n kind: NodeKind\n /**\n * Where the node comes from in the input, in the form the adapter's `locate` reads. Document\n * adapters such as OpenAPI and AsyncAPI use an RFC 6901 JSON pointer, for example\n * `#/components/schemas/Pet`. Plugins can copy it to the code nodes they emit.\n */\n pointer?: string\n}\n\n/** `Omit` applied to each member of a union, so the union survives. */\nexport type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\n/** Builds a `createX` factory for a node whose only computed field is `kind`. */\nexport function nodeFactory<T extends BaseNode>(kind: T['kind']): (input: Omit<T, 'kind'>) => T {\n return (input) => {\n const node = { ...input, kind }\n return node as T\n }\n}\n","import { hash } from 'node:crypto'\nimport path from 'node:path'\nimport { nodeKinds } from '../constants.ts'\nimport { combineExports, combineImports, combineSources } from '../utils/combineFileMembers.ts'\nimport { getNames, toDeprecatedExport, toDeprecatedImport } from '../utils/moduleNames.ts'\nimport { getNodeText } from '../utils/nodeText.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\nimport type { CodeNode } from './code.ts'\n\n/**\n * Supported file extensions.\n */\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type ImportName = string | Array<string | { propertyName: string; name?: string }>\n\n/**\n * Whether a declaration exists only at compile time (`'type'`) or also at runtime (`'value'`).\n */\nexport type Space = 'type' | 'value'\n\n/**\n * One name an import or export brings across, as in the ECMAScript `ImportEntry` record.\n */\nexport type ModuleName = {\n /**\n * Name in the other module: `'default'` for its default export, `'*'` for the whole module.\n */\n name: string\n /**\n * Local name for an import, or the exported name for an export.\n */\n alias?: string | null\n /**\n * Type or value.\n * @default 'value'\n */\n space?: Space | null\n}\n\n/**\n * Represents a language-agnostic import/dependency declaration.\n *\n * @example Named import (TypeScript: `import { useState } from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'useState' }], path: 'react' })\n * ```\n *\n * @example Default import (TypeScript: `import React from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'default', alias: 'React' }], path: 'react' })\n * ```\n *\n * @example Type-only import (TypeScript: `import type { FC } from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'FC', space: 'type' }], path: 'react' })\n * ```\n *\n * @example Namespace import (TypeScript: `import * as React from 'react'`)\n * ```ts\n * createImport({ names: [{ name: '*', alias: 'React' }], path: 'react' })\n * ```\n */\nexport type ImportNode = BaseNode & {\n kind: 'Import'\n /**\n * The names the import brings in. `ast.file.getNames` also reads the deprecated fields.\n */\n names?: Array<ModuleName> | null\n /**\n * Import name(s) to be used.\n *\n * @deprecated Use `names`. Removed in Kubb v6.\n */\n name: ImportName\n /**\n * Path for the import.\n *\n * @example\n * `'@kubb/core'`\n */\n path: string\n /**\n * Add a type-only import prefix.\n *\n * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Import the entire module as a namespace.\n *\n * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.\n */\n isNameSpace?: boolean | null\n /**\n * When set, the import path is resolved relative to this root.\n */\n root?: string | null\n}\n\n/**\n * Represents a language-agnostic export/public API declaration.\n *\n * @example Named export (TypeScript: `export { Pets } from './Pets'`)\n * ```ts\n * createExport({ names: [{ name: 'Pets' }], path: './Pets' })\n * ```\n *\n * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)\n * ```ts\n * createExport({ names: [{ name: 'Pet', space: 'type' }], path: './Pet' })\n * ```\n *\n * @example Wildcard export (TypeScript: `export * from './utils'`)\n * ```ts\n * createExport({ names: [{ name: '*' }], path: './utils' })\n * ```\n *\n * @example Namespace alias (TypeScript: `export * as utils from './utils'`)\n * ```ts\n * createExport({ names: [{ name: '*', alias: 'utils' }], path: './utils' })\n * ```\n */\nexport type ExportNode = BaseNode & {\n kind: 'Export'\n /**\n * The names the export passes on. `ast.file.getNames` also reads the deprecated fields.\n */\n names?: Array<ModuleName> | null\n /**\n * Export name(s) to be used. When omitted, generates a wildcard export.\n *\n * @deprecated Use `names`. Removed in Kubb v6.\n */\n name?: string | Array<string> | null\n /**\n * Path for the export.\n *\n * @example\n * `'@kubb/core'`\n */\n path: string\n /**\n * Add a type-only export prefix.\n *\n * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Export as an aliased namespace.\n *\n * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.\n */\n asAlias?: boolean | null\n}\n\n/**\n * Represents a fragment of source code within a file.\n *\n * @example Named exportable source\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })\n * ```\n *\n * @example Inline unnamed code block\n * ```ts\n * createSource({ nodes: [createText('const x = 1')] })\n * ```\n */\nexport type SourceNode = BaseNode & {\n kind: 'Source'\n /**\n * Optional name identifying this source (used for deduplication and barrel generation).\n */\n name?: string | null\n /**\n * Type or value. When unset, a source whose first node is a `Type` is a type.\n */\n space?: Space | null\n /**\n * Mark this source as a type-only export.\n *\n * @deprecated Use `space: 'type'`. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Mark this source as an exported declaration, which barrels list. The source text carries its own `export` keyword.\n */\n export?: boolean | null\n /**\n * Mark this exported source as the module's default export. Barrels skip it, since they can't re-export it by name.\n */\n default?: boolean | null\n /**\n * @deprecated Use `export`. Removed in Kubb v6.\n */\n isExportable?: boolean | null\n /**\n * @deprecated Use `export`. Removed in Kubb v6.\n */\n isIndexable?: boolean | null\n /**\n * Marks the source as a definition that importing files absorb instead of import. `expression` is\n * the declaration's right-hand side, such as `{ body: Pet }`.\n *\n * @deprecated Set `inline` on the file. Removed in Kubb v6.\n */\n inline?: { expression: string } | null\n /**\n * Child nodes that make up this source fragment, in DOM order.\n * Use a {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * Represents a fully resolved file in the AST.\n *\n * Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input\n * and deduplicates `imports`, `exports`, and `sources`.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of the path\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n */\nexport type FileNode<TMeta extends object = object> = BaseNode & {\n kind: 'File'\n /**\n * Unique identifier derived from a SHA256 hash of the file path. `createFile`\n * computes it, so callers do not need to provide it.\n */\n id: string\n /**\n * File name without extension, derived from `baseName`.\n *\n * @see https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n /**\n * File base name, including extension, shaped like `${name}${extname}`.\n *\n * @see https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: `${string}.${string}`\n /**\n * Full qualified path to the file.\n */\n path: string\n /**\n * File extension extracted from `baseName`.\n */\n extname: Extname\n /**\n * Deduplicated list of source code fragments.\n */\n sources: Array<SourceNode>\n /**\n * Deduplicated list of import declarations.\n */\n imports: Array<ImportNode>\n /**\n * Deduplicated list of export declarations.\n */\n exports: Array<ExportNode>\n /**\n * Optional metadata attached to this file, read by plugins during barrel generation.\n */\n meta?: TMeta\n /**\n * Optional banner prepended to the generated file content.\n * Accepts `null` so `resolver.default.banner()` results can be passed directly.\n */\n banner?: string | null\n /**\n * Optional footer appended to the generated file content.\n * Accepts `null` so `resolver.default.footer()` results can be passed directly.\n */\n footer?: string | null\n /**\n * Absolute on-disk path to copy into the output, through the parser's `copy` hook when it has one.\n *\n * Use to emit a real source file shipped inside a package (a template) into the generated\n * folder. When set, `copy` provides the file content and any `sources` nodes are ignored for\n * output; `sources` may still carry `name`/`export` so barrel generation\n * treats the file the same as a rendered one.\n */\n copy?: string | null\n /**\n * 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.\n */\n inline?: boolean | null\n}\n\nexport type ImportInput = Omit<ImportNode, 'kind' | 'name'> & { name?: ImportName }\n\nexport type ExportInput = Omit<ExportNode, 'kind'>\n\n// A spread node carries the deprecated fields derived from its `names`, so only a value that differs is an override.\ntype Override<TValue> = { value: TValue | null | undefined; derived: TValue | null | undefined }\n\nfunction overrideSpace(names: Array<ModuleName>, { value, derived }: Override<boolean>): Array<ModuleName> {\n if (value == null || value === derived) return names\n const space = value ? 'type' : 'value'\n return names.map((item) => ({ ...item, space }))\n}\n\nconst isOverride = ({ value, derived }: Override<unknown>): boolean => value !== undefined && JSON.stringify(value) !== JSON.stringify(derived)\n\n// Object spread copies symbol keys, so `{ ...imp, names }` carries the fields `imp` derived and they can be told apart from an override.\nconst DERIVED = Symbol.for('kubb.ast.derived')\n// `name` is stored as JSON, so changing the node's `name` array in place still counts as an override.\ntype Derived = { name: string | undefined; isTypeOnly?: boolean | null }\ntype WithDerived = { [DERIVED]?: Derived }\n\n/** The deprecated fields the caller set: a value equal to the one the spread node derived is dropped, so `names` decides it. */\nfunction ownFields<TName>(input: { name?: TName; isTypeOnly?: boolean | null } & WithDerived): { name?: TName; isTypeOnly?: boolean | null } {\n const snapshot = input[DERIVED]\n if (!snapshot) return { name: input.name, isTypeOnly: input.isTypeOnly }\n return {\n name: JSON.stringify(input.name) === snapshot.name ? undefined : input.name,\n isTypeOnly: input.isTypeOnly === snapshot.isTypeOnly ? undefined : input.isTypeOnly,\n }\n}\n\nfunction withoutDerived<T extends object>(input: T): T {\n const { [DERIVED]: _, ...rest } = input as T & WithDerived\n return rest as T\n}\n\n/**\n * Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or\n * `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.\n * Fields a spread copies over unchanged are not overrides, so `{ ...imp, names }` uses the new `names`.\n *\n * @example Named import\n * ```ts\n * createImport({ names: [{ name: 'useState' }], path: 'react' })\n * // import { useState } from 'react'\n * ```\n */\nexport function createImport(input: ImportInput): ImportNode {\n if (!input.names) return { ...withoutDerived(input), name: input.name ?? [], kind: nodeKinds.import }\n const own = ownFields(input)\n const derived = toDeprecatedImport(input.names)\n if (isOverride({ value: own.name, derived: derived.name })) return { ...withoutDerived(input), names: null, name: own.name ?? [], kind: nodeKinds.import }\n const names = overrideSpace(input.names, { value: own.isTypeOnly, derived: derived.isTypeOnly })\n const fields = toDeprecatedImport(names)\n const node: ImportNode & WithDerived = {\n ...input,\n ...fields,\n names,\n [DERIVED]: { name: JSON.stringify(fields.name), isTypeOnly: fields.isTypeOnly },\n kind: nodeKinds.import,\n }\n return node\n}\n\n/**\n * Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or\n * `isTypeOnly` that differs from the one `names` gives overrides it. Fields a spread copies over unchanged are not\n * overrides, so `{ ...exp, names }` uses the new `names`.\n *\n * @example Named export\n * ```ts\n * createExport({ names: [{ name: 'Pet' }], path: './Pet' })\n * // export { Pet } from './Pet'\n * ```\n */\nexport function createExport(input: ExportInput): ExportNode {\n if (!input.names) return { ...withoutDerived(input), kind: nodeKinds.export }\n const own = ownFields(input)\n const derived = toDeprecatedExport(input.names)\n if (isOverride({ value: own.name, derived: derived.name })) return { ...withoutDerived(input), name: own.name, names: null, kind: nodeKinds.export }\n const names = overrideSpace(input.names, { value: own.isTypeOnly, derived: derived.isTypeOnly })\n const fields = toDeprecatedExport(names)\n const node: ExportNode & WithDerived = {\n ...input,\n ...fields,\n name: fields.name,\n names,\n [DERIVED]: { name: JSON.stringify(fields.name), isTypeOnly: fields.isTypeOnly },\n kind: nodeKinds.export,\n }\n return node\n}\n\n/**\n * Creates a `SourceNode` representing a fragment of source code within a file.\n *\n * @example\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })\n * ```\n */\nexport const createSource = nodeFactory<SourceNode>(nodeKinds.source)\n\n/**\n * Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed\n * and `imports`/`exports`/`sources` are deduplicated.\n */\nexport type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> &\n Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>\n\n/**\n * Creates a fully resolved `FileNode` from a file input descriptor.\n *\n * Computes:\n * - `id` SHA256 hash of the file path\n * - `name` `baseName` without extension\n * - `extname` extension extracted from `baseName`\n *\n * Deduplicates:\n * - `sources` via `combineSources`\n * - `exports` via `combineExports`\n * - `imports` via `combineImports` (also filters unused imports)\n *\n * @throws {Error} when `baseName` has no extension.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of 'src/models/petStore.ts'\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n *\n * @example Copy a real file into the output\n * ```ts\n * const file = createFile({\n * baseName: 'client.ts',\n * path: 'src/gen/client.ts',\n * copy: '/abs/path/to/templates/client.ts',\n * })\n * ```\n */\nexport function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta> {\n const extname = path.extname(input.baseName) as `.${string}`\n if (!extname) {\n throw new Error(`No extname found for ${input.baseName}`)\n }\n\n const resolvedExports = input.exports?.length ? combineExports(input.exports) : []\n const resolvedSources = input.sources?.length ? combineSources(input.sources) : []\n\n // Skip building the source text and local-name set when there are no imports to resolve against them.\n const resolvedImports: Array<ImportNode> = (() => {\n if (!input.imports?.length) return []\n\n const sourceParts: Array<string> = []\n const localNames = new Set<string>()\n // Only the sources the file keeps count: an import used just by a dropped duplicate is unused.\n for (const item of resolvedSources) {\n const extracted = item.nodes && getNodeText(item.nodes)\n if (extracted) sourceParts.push(extracted)\n if (item.name) localNames.add(item.name)\n }\n const source = sourceParts.join('\\n') || undefined\n const combinedImports = combineImports(input.imports, resolvedExports, source)\n // Consolidating output (`mode: 'file'`) can put a symbol's definition and an import of it in the\n // same file: by path when the import still targets this file, by name when consolidation moved it.\n return combinedImports.flatMap((imp) => {\n if (imp.path === input.path) return []\n const names = getNames(imp)\n const kept = names.filter((item) => !localNames.has(item.alias ?? item.name))\n if (!kept.length) return []\n return [kept.length === names.length ? imp : createImport({ path: imp.path, ...(imp.root != null ? { root: imp.root } : {}), names: kept })]\n })\n })()\n\n return {\n ...input,\n kind: nodeKinds.file,\n id: hash('sha256', input.path, 'hex'),\n name: path.basename(input.baseName, extname),\n extname,\n imports: resolvedImports,\n exports: resolvedExports,\n sources: resolvedSources,\n meta: (input.meta ?? {}) as TMeta,\n }\n}\n","/**\n * File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and\n * export entries of one file, while `combineSources` deduplicates source entries in original order.\n * `combineImports` also drops imports nothing references. This works on a file's members, not on\n * schema content.\n */\nimport path from 'node:path'\nimport process from 'node:process'\nimport { memo } from '@internals/utils'\nimport { createExport, createImport, type ExportNode, type ImportNode, type ModuleName, type SourceNode, type Space } from '../nodes/file.ts'\nimport { getNames, getSpace, isExported } from './moduleNames.ts'\n\nconst IDENTIFIER_RUN = /[\\w$]+/g\n\n/**\n * How many imports a file needs before indexing the source beats scanning it once per name.\n */\nconst INDEX_ABOVE_IMPORTS = 128\n\ntype Form = 'named' | 'default' | '*'\n\ntype Statement = { path: string; root?: string | null; form: Form; space: Space; names: Array<ModuleName> }\n\nconst importForm = (item: ModuleName): Form => (item.alias && (item.name === '*' || item.name === 'default') ? item.name : 'named')\nconst exportForm = (item: ModuleName): Form => (item.name === '*' ? '*' : 'named')\nconst label = (item: ModuleName): string => (item.alias ? `${item.name} as ${item.alias}` : item.name)\n\nfunction statementKey({ path, form, space, names }: Statement): string {\n return form === 'named' ? `${path}\\0named\\0${space}` : `${path}\\0${form}\\0${names[0]?.alias ?? ''}\\0${space}`\n}\n\nfunction toStatements(nodes: ReadonlyArray<ImportNode | ExportNode>, formOf: (item: ModuleName) => Form): Array<Statement> {\n return nodes.flatMap((node) => {\n const statements = new Map<string, Statement>()\n for (const item of getNames(node)) {\n const statement: Statement = {\n path: node.path,\n root: node.kind === 'Import' ? node.root : undefined,\n form: formOf(item),\n space: item.space ?? 'value',\n names: [],\n }\n const key = statementKey({ ...statement, names: [item] })\n const existing = statements.get(key) ?? statement\n statements.set(key, existing)\n existing.names.push(item)\n }\n return [...statements.values()]\n })\n}\n\n/**\n * Relative specifiers by `root`, then `path`. `createFile` sorts a file's imports again on every\n * merge, and the path math dominated that sort on large specs. Two levels keep the existing strings\n * as keys, so lookups reuse their hashes instead of hashing a new joined key each time.\n */\nconst specifierCache = memo.create<string, Map<string, string>>({ max: 10_000 })\n\n/**\n * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.\n *\n * @example\n * ```ts\n * getRelativePath('/root/src/models/pet.ts', '/root/lib/client.ts') // '../../lib/client.ts'\n * ```\n */\nexport function getRelativePath(root: string, filePath: string): string {\n // A relative input resolves against the working directory, so that directory is part of its key.\n const rootKey = path.isAbsolute(root) && path.isAbsolute(filePath) ? root : `${process.cwd()}\\u0000${root}`\n const byPath = memo(specifierCache, rootKey, () => new Map<string, string>())\n return memo(byPath, filePath, () => {\n const relative = path.relative(path.dirname(root), filePath).replaceAll('\\\\', '/')\n return relative.startsWith('../') ? relative : `./${relative}`\n })\n}\n\n/** The specifier a member is written with, so sorting on it gives the same order on every OS. */\nfunction specifier(node: { path: string; root?: string | null }): string {\n return node.root ? getRelativePath(node.root, node.path) : node.path\n}\n\nfunction sortKey(statement: Statement): string {\n const form = statement.form === 'named' ? '1' : '0'\n const space = statement.space === 'type' ? '0' : '1'\n return `${form}:${space}:${specifier(statement)}:${statement.names.map(label).toSorted().join('\\0')}`\n}\n\nfunction mergeStatements(statements: Array<Statement>, keep: (item: ModuleName, statement: Statement) => boolean = () => true): Array<Statement> {\n const merged = new Map<string, { statement: Statement; seen: Set<string> }>()\n const sorted = statements.map((statement) => ({ statement, key: sortKey(statement) })).sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))\n\n for (const { statement } of sorted) {\n const key = statementKey(statement)\n const entry = merged.get(key) ?? { statement: { ...statement, names: [] }, seen: new Set<string>() }\n merged.set(key, entry)\n for (const item of statement.names) {\n const id = item.alias ?? item.name\n if (entry.seen.has(id) || !keep(item, statement)) continue\n entry.seen.add(id)\n entry.statement.names.push(item)\n }\n }\n\n const result = [...merged.values()].map(({ statement }) => statement)\n // A name kept as a value also serves its type uses, so a type statement from the same path must not bind it again.\n const bound = ({ path, item }: { path: string; item: ModuleName }) => `${path}\\0${item.alias ?? item.name}`\n const values = new Set(result.filter(({ space }) => space === 'value').flatMap(({ path, names }) => names.map((item) => bound({ path, item }))))\n return result\n .map((statement) =>\n statement.space === 'type' ? { ...statement, names: statement.names.filter((item) => !values.has(bound({ path: statement.path, item }))) } : statement,\n )\n .filter((statement) => statement.names.length > 0)\n}\n\n/**\n * Deduplicates `SourceNode` objects by `name + export + space`, keeping the first of each\n * key. An unnamed source only drops when the same node appears twice, so markdown can repeat a\n * paragraph or a table. Returns the deduplicated array in original order.\n */\nexport function combineSources(sources: Array<SourceNode>): Array<SourceNode> {\n const seen = new Set<SourceNode | string>()\n return sources.filter((source) => {\n const key = source.name != null ? `${source.name}:${isExported(source)}:${getSpace(source)}` : source\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n}\n\n/**\n * Deduplicates and merges `ExportNode` objects: one export per path, form and space. Returns a sorted array.\n */\nexport function combineExports(exports: Array<ExportNode>): Array<ExportNode> {\n // Built through `createExport`, so a later `{ ...exp, names }` keeps the new names.\n return mergeStatements(toStatements(exports, exportForm)).map(({ path, names }) => createExport({ path, names }))\n}\n\n/**\n * Deduplicates and merges `ImportNode` objects, filtering out unused imports.\n *\n * Retains imports that are referenced in `source` or re-exported. One import per path, form and space. Returns\n * a sorted, deduplicated, filtered array.\n */\nexport function combineImports(imports: Array<ImportNode>, exports: Array<ExportNode>, source?: string): Array<ImportNode> {\n // Build a lookup of all exported names to retain imports that are re-exported\n const exportedNames = new Set(exports.flatMap((node) => getNames(node).map((item) => item.alias ?? item.name)))\n // `createFile` re-runs on every merge into a file, so scanning the source once per import name\n // costs a heavily merged file that scan again for every fragment it already holds. Indexing pays\n // for itself there, and costs more than it saves on the small files the default output produces.\n const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? new Set(source.match(IDENTIFIER_RUN)) : null\n\n // A name in the index is used. One that is not still might be, inside a longer identifier, so the\n // substring test stays behind it.\n const isUsed = (importName: string): boolean => !source || identifiers?.has(importName) || source.includes(importName) || exportedNames.has(importName)\n\n const statements = toStatements(\n imports.filter((node) => node.path !== node.root),\n importForm,\n )\n\n // Paths that keep at least one used named import. A default import from such a path is retained\n // even when its binding can't be found in `source` e.g. a generated `client` default import\n // alongside `import type { Client } from <same path>`, where merged grouped output omits the body.\n const pathsWithUsedNamedImport = new Set(\n statements.filter(({ form, names }) => form === 'named' && names.some((item) => isUsed(item.alias ?? item.name))).map(({ path }) => path),\n )\n const keep = (item: ModuleName, { form, path }: Statement) => isUsed(item.alias ?? item.name) || (form !== 'named' && pathsWithUsedNamedImport.has(path))\n\n return mergeStatements(statements, keep).map(({ path, root, names }) => createImport({ path, ...(root != null ? { root } : {}), names }))\n}\n"],"mappings":";;;;;;;;;;;;;;AAMA,SAAgB,SAAS,MAAkD;CACzE,IAAI,KAAK,OAAO,OAAO,KAAK;CAC5B,OAAO,KAAK,SAAS,WAAW,qBAAqB,IAAI,IAAI,qBAAqB,IAAI;AACxF;;;;AAKA,SAAgB,WAAW,QAA8E;CACvG,OAAO,CAAC,EAAE,OAAO,UAAU,OAAO,eAAe,OAAO;AAC1D;AAEA,SAAgB,SAAS,QAA2B;CAClD,IAAI,OAAO,OAAO,OAAO,OAAO;CAChC,IAAI,OAAO,cAAc,MAAM,OAAO,OAAO,aAAa,SAAS;CACnE,OAAO,OAAO,QAAQ,EAAE,EAAE,SAAS,SAAS,SAAS;AACvD;;;;AAQA,SAAS,qBAAqB,EAAE,MAAM,YAAY,eAAoD;CACpG,MAAM,QAAe,aAAa,SAAS;CAC3C,IAAI,CAAC,MAAM,QAAQ,IAAI,GAAG,OAAO,CAAC;EAAE,MAAM,cAAc,MAAM;EAAW,OAAO;EAA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KAAK,SAAS,KAAK,SAAS,KAAK,IAAI,CAAC,CAAC;CAI9G,MAAM,cAAc,UAAU,QAAQ,SAAS,sBAAsB,IAAI,IAAI,OAAO,MAAM,cAAc,CAAC,IAAI;CAI7G,MAAM,UAAU,eAAgC,CAAC,UAAU,aAAa,IAAI,UAAU,KAAK,OAAO,SAAS,UAAU,KAAK,cAAc,IAAI,UAAU;CAEtJ,MAAM,aAAa,aACjB,QAAQ,QAAQ,SAAS,KAAK,SAAS,KAAK,IAAI,GAChD,UACF;CAKA,MAAM,2BAA2B,IAAI,IACnC,WAAW,QAAQ,EAAE,MAAM,YAAY,SAAS,WAAW,MAAM,MAAM,SAAS,OAAO,KAAK,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,WAAW,IAAI,CAC1I;CACA,MAAM,QAAQ,MAAkB,EAAE,MAAM,WAAsB,OAAO,KAAK,SAAS,KAAK,IAAI,KAAM,SAAS,WAAW,yBAAyB,IAAI,IAAI;CAEvJ,OAAO,gBAAgB,YAAY,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,MAAM,YAAY,aAAa;EAAE;EAAM,GAAI,QAAQ,OAAO,EAAE,KAAK,IAAI,CAAC;EAAI;CAAM,CAAC,CAAC;AAC1I"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"graph-D6Ffy9YD.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 or schemas.\n * A schema root counts the schemas it references, not itself.\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(roots: ReadonlyArray<OperationNode | SchemaNode>, 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 root of roots) {\n for (const schema of collect<SchemaNode>(root, { 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 return new Set([...graph.keys()].filter((start) => reachesItself(graph, start)))\n}\n\nfunction reachesItself(graph: ReadonlyMap<string, ReadonlySet<string>>, start: string): boolean {\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) return true\n if (visited.has(node)) continue\n visited.add(node)\n for (const next of graph.get(node) ?? []) stack.push(next)\n }\n\n return false\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;EAC7D,MAAM,UAA2B,CAAC;EAClC,MAAM,QAAQ,YAA2B;GACvC,IAAI,QAAQ,SAASC,kBAAAA,UAAU,UAAU,QAAQ,SAAS,OAAO;IAC/D,MAAM,OAAOC,aAAAA,eAAe,OAAO;IACnC,IAAI,MAAM,QAAQ,KAAK;KAAE;KAAM,YAAY,QAAQ,QAAQ,GAAG;IAAE,CAAC;GACnE;GACAC,gBAAAA,gBAAgB,SAAS,MAAM,EAAE,OAAO,CAAC;GACzC,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AAI,OAAO,MAAM,kBAAkB,MAAM,CAAC;CAGnE,OAAO,IAAI,IAAI,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,QAAQ,UAAU,cAAc,OAAO,KAAK,CAAC,CAAC;AACjF;AAEA,SAAS,cAAc,OAAiD,OAAwB;CAC9F,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,QAAuB,CAAC,GAAI,MAAM,IAAI,KAAK,KAAK,CAAC,CAAE;CACzD,OAAO,MAAM,SAAS,GAAG;EACvB,MAAM,OAAO,MAAM,IAAI;EACvB,IAAI,SAAS,OAAO,OAAO;EAC3B,IAAI,QAAQ,IAAI,IAAI,GAAG;EACvB,QAAQ,IAAI,IAAI;EAChB,KAAK,MAAM,QAAQ,MAAM,IAAI,IAAI,KAAK,CAAC,GAAG,MAAM,KAAK,IAAI;CAC3D;CAEA,OAAO;AACT"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"graph-DWlCmvm6.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 or schemas.\n * A schema root counts the schemas it references, not itself.\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(roots: ReadonlyArray<OperationNode | SchemaNode>, 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 root of roots) {\n for (const schema of collect<SchemaNode>(root, { 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 return new Set([...graph.keys()].filter((start) => reachesItself(graph, start)))\n}\n\nfunction reachesItself(graph: ReadonlyMap<string, ReadonlySet<string>>, start: string): boolean {\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) return true\n if (visited.has(node)) continue\n visited.add(node)\n for (const next of graph.get(node) ?? []) stack.push(next)\n }\n\n return false\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,C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AQ,IAAI,IAAI,GAAG;EACvB,QAAQ,IAAI,IAAI;EAChB,KAAK,MAAM,QAAQ,MAAM,IAAI,IAAI,KAAK,CAAC,GAAG,MAAM,KAAK,IAAI;CAC3D;CAEA,OAAO;AACT"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-DeqPhPUQ.js","names":[],"sources":["../src/json/index.ts"],"sourcesContent":["import { nodeKinds, schemaTypes } from '../constants.ts'\nimport type { InputNode } from '../nodes/input.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\nconst version = 1\n\ntype JsonDocument = {\n version: number\n input: InputNode\n targets: Array<SchemaNode>\n}\n\nfunction isRef(value: unknown): value is { schema: unknown } {\n const node = value as { kind?: unknown; type?: unknown } | null\n return node?.kind === nodeKinds.schema && node.type === schemaTypes.ref\n}\n\n/**\n * Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,\n * where a plain `JSON.stringify(input)` writes it again at every ref.\n *\n * @example\n * ```ts\n * await writeFile('input.json', ast.json.stringify(input))\n * ```\n */\nexport function stringify(input: InputNode): string {\n const ids = new Map<unknown, number>()\n const targets: Array<unknown> = []\n\n function replacer(this: unknown, key: string, value: unknown): unknown {\n if (key !== 'schema' || !isRef(this)) return value\n // Spec data such as a `default` can look like a ref node. Its number is wrapped, so `parse` does not read it as a target.\n if (typeof value === 'number') return [value]\n if (typeof value !== 'object' || value === null) return value\n if (!ids.has(value)) {\n ids.set(value, targets.length)\n targets.push(value)\n }\n return ids.get(value)\n }\n\n const root = JSON.stringify(input, replacer)\n const encoded: Array<string> = []\n // A target can hold refs to targets not seen yet, so the list grows while this loop reads it.\n for (const target of targets) encoded.push(JSON.stringify(target, replacer))\n\n return `{\"version\":${version},\"input\":${root},\"targets\":[${encoded.join(',')}]}`\n}\n\n/**\n * Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.\n * Throws on another format version, or on a ref whose target is missing.\n */\nexport function parse(text: string): InputNode {\n // Plain `JSON.parse` and one loop over the tree: a reviver made this about 5 times slower on a large spec.\n const document = JSON.parse(text) as Partial<JsonDocument> | null\n\n if (document?.version !== version) {\n throw new Error(`Cannot read this AST JSON: expected format version ${version}, got ${JSON.stringify(document?.version)}.`)\n }\n if (!document.input || !Array.isArray(document.targets)) {\n throw new Error('Cannot read this AST JSON: `input` or `targets` is missing.')\n }\n\n const targets = document.targets\n const stack: Array<unknown> = [document.input, ...targets]\n while (stack.length) {\n const value = stack.pop() as Record<string, unknown>\n const ref = isRef(value)\n for (const key in value) {\n const child = value[key]\n if (ref && key === 'schema') {\n if (Array.isArray(child)) {\n value.schema = child[0]\n continue\n }\n if (typeof child === 'number') {\n const target = targets[child]\n if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${child}, which is missing.`)\n value.schema = target\n continue\n }\n }\n if (typeof child === 'object' && child !== null) stack.push(child)\n }\n }\n\n return document.input\n}\n"],"mappings":";;;;;;;AAIA,MAAM,UAAU;AAQhB,SAAS,MAAM,OAA8C;CAC3D,MAAM,OAAO;CACb,OAAO,MAAM,SAAS,UAAU,UAAU,KAAK,SAAS,YAAY;AACtE;;;;;;;;;;AAWA,SAAgB,UAAU,OAA0B;CAClD,MAAM,sBAAM,IAAI,IAAqB;CACrC,MAAM,UAA0B,CAAC;CAEjC,SAAS,SAAwB,KAAa,OAAyB;EACrE,IAAI,QAAQ,YAAY,CAAC,MAAM,IAAI,GAAG,OAAO;EAE7C,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;EAC5C,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;EACxD,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG;GACnB,IAAI,IAAI,OAAO,QAAQ,MAAM;GAC7B,QAAQ,KAAK,KAAK;EACpB;EACA,OAAO,IAAI,IAAI,KAAK;CACtB;CAEA,MAAM,OAAO,KAAK,UAAU,OAAO,QAAQ;CAC3C,MAAM,UAAyB,CAAC;CAEhC,KAAK,MAAM,UAAU,SAAS,QAAQ,KAAK,KAAK,UAAU,QAAQ,QAAQ,CAAC;CAE3E,OAAO,cAAc,QAAQ,WAAW,KAAK,cAAc,QAAQ,KAAK,GAAG,EAAE;AAC/E;;;;;AAMA,SAAgB,MAAM,MAAyB;CAE7C,MAAM,WAAW,KAAK,MAAM,IAAI;CAEhC,IAAI,UAAU,YAAY,SACxB,MAAM,IAAI,MAAM,sDAAsD,QAAQ,QAAQ,KAAK,UAAU,UAAU,OAAO,EAAE,EAAE;CAE5H,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,QAAQ,SAAS,OAAO,GACpD,MAAM,IAAI,MAAM,6DAA6D;CAG/E,MAAM,UAAU,SAAS;CACzB,MAAM,QAAwB,CAAC,SAAS,OAAO,GAAG,OAAO;CACzD,OAAO,MAAM,QAAQ;EACnB,MAAM,QAAQ,MAAM,IAAI;EACxB,MAAM,MAAM,MAAM,KAAK;EACvB,KAAK,MAAM,OAAO,OAAO;GACvB,MAAM,QAAQ,MAAM;GACpB,IAAI,OAAO,QAAQ,UAAU;IAC3B,IAAI,MAAM,QAAQ,KAAK,GAAG;KACxB,MAAM,SAAS,MAAM;KACrB;IACF;IACA,IAAI,OAAO,UAAU,UAAU;KAC7B,MAAM,SAAS,QAAQ;KACvB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD,MAAM,oBAAoB;KAC5G,MAAM,SAAS;KACf;IACF;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,KAAK,KAAK;EACnE;CACF;CAEA,OAAO,SAAS;AAClB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-KV2VhBue.cjs","names":["nodeKinds","schemaTypes"],"sources":["../src/json/index.ts"],"sourcesContent":["import { nodeKinds, schemaTypes } from '../constants.ts'\nimport type { InputNode } from '../nodes/input.ts'\nimport type { SchemaNode } from '../nodes/schema.ts'\n\nconst version = 1\n\ntype JsonDocument = {\n version: number\n input: InputNode\n targets: Array<SchemaNode>\n}\n\nfunction isRef(value: unknown): value is { schema: unknown } {\n const node = value as { kind?: unknown; type?: unknown } | null\n return node?.kind === nodeKinds.schema && node.type === schemaTypes.ref\n}\n\n/**\n * Turns an `InputNode` into JSON text that `parse` reads back. Every schema a ref points at is written once,\n * where a plain `JSON.stringify(input)` writes it again at every ref.\n *\n * @example\n * ```ts\n * await writeFile('input.json', ast.json.stringify(input))\n * ```\n */\nexport function stringify(input: InputNode): string {\n const ids = new Map<unknown, number>()\n const targets: Array<unknown> = []\n\n function replacer(this: unknown, key: string, value: unknown): unknown {\n if (key !== 'schema' || !isRef(this)) return value\n // Spec data such as a `default` can look like a ref node. Its number is wrapped, so `parse` does not read it as a target.\n if (typeof value === 'number') return [value]\n if (typeof value !== 'object' || value === null) return value\n if (!ids.has(value)) {\n ids.set(value, targets.length)\n targets.push(value)\n }\n return ids.get(value)\n }\n\n const root = JSON.stringify(input, replacer)\n const encoded: Array<string> = []\n // A target can hold refs to targets not seen yet, so the list grows while this loop reads it.\n for (const target of targets) encoded.push(JSON.stringify(target, replacer))\n\n return `{\"version\":${version},\"input\":${root},\"targets\":[${encoded.join(',')}]}`\n}\n\n/**\n * Reads the text `stringify` wrote back into an `InputNode`. Refs to one schema share one object again.\n * Throws on another format version, or on a ref whose target is missing.\n */\nexport function parse(text: string): InputNode {\n // Plain `JSON.parse` and one loop over the tree: a reviver made this about 5 times slower on a large spec.\n const document = JSON.parse(text) as Partial<JsonDocument> | null\n\n if (document?.version !== version) {\n throw new Error(`Cannot read this AST JSON: expected format version ${version}, got ${JSON.stringify(document?.version)}.`)\n }\n if (!document.input || !Array.isArray(document.targets)) {\n throw new Error('Cannot read this AST JSON: `input` or `targets` is missing.')\n }\n\n const targets = document.targets\n const stack: Array<unknown> = [document.input, ...targets]\n while (stack.length) {\n const value = stack.pop() as Record<string, unknown>\n const ref = isRef(value)\n for (const key in value) {\n const child = value[key]\n if (ref && key === 'schema') {\n if (Array.isArray(child)) {\n value.schema = child[0]\n continue\n }\n if (typeof child === 'number') {\n const target = targets[child]\n if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${child}, which is missing.`)\n value.schema = target\n continue\n }\n }\n if (typeof child === 'object' && child !== null) stack.push(child)\n }\n }\n\n return document.input\n}\n"],"mappings":";;;;;;;AAIA,MAAM,UAAU;AAQhB,SAAS,MAAM,OAA8C;CAC3D,MAAM,OAAO;CACb,OAAO,MAAM,SAASA,kBAAAA,UAAU,UAAU,KAAK,SAASC,kBAAAA,YAAY;AACtE;;;;;;;;;;AAWA,SAAgB,UAAU,OAA0B;CAClD,MAAM,sBAAM,IAAI,IAAqB;CACrC,MAAM,UAA0B,CAAC;CAEjC,SAAS,SAAwB,KAAa,OAAyB;EACrE,IAAI,QAAQ,YAAY,CAAC,MAAM,IAAI,GAAG,OAAO;EAE7C,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC,KAAK;EAC5C,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;EACxD,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG;GACnB,IAAI,IAAI,OAAO,QAAQ,MAAM;GAC7B,QAAQ,KAAK,KAAK;EACpB;EACA,OAAO,IAAI,IAAI,KAAK;CACtB;CAEA,MAAM,OAAO,KAAK,UAAU,OAAO,QAAQ;CAC3C,MAAM,UAAyB,CAAC;CAEhC,KAAK,MAAM,UAAU,SAAS,QAAQ,KAAK,KAAK,UAAU,QAAQ,QAAQ,CAAC;CAE3E,OAAO,cAAc,QAAQ,WAAW,KAAK,cAAc,QAAQ,KAAK,GAAG,EAAE;AAC/E;;;;;AAMA,SAAgB,MAAM,MAAyB;CAE7C,MAAM,WAAW,KAAK,MAAM,IAAI;CAEhC,IAAI,UAAU,YAAY,SACxB,MAAM,IAAI,MAAM,sDAAsD,QAAQ,QAAQ,KAAK,UAAU,UAAU,OAAO,EAAE,EAAE;CAE5H,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,QAAQ,SAAS,OAAO,GACpD,MAAM,IAAI,MAAM,6DAA6D;CAG/E,MAAM,UAAU,SAAS;CACzB,MAAM,QAAwB,CAAC,SAAS,OAAO,GAAG,OAAO;CACzD,OAAO,MAAM,QAAQ;EACnB,MAAM,QAAQ,MAAM,IAAI;EACxB,MAAM,MAAM,MAAM,KAAK;EACvB,KAAK,MAAM,OAAO,OAAO;GACvB,MAAM,QAAQ,MAAM;GACpB,IAAI,OAAO,QAAQ,UAAU;IAC3B,IAAI,MAAM,QAAQ,KAAK,GAAG;KACxB,MAAM,SAAS,MAAM;KACrB;IACF;IACA,IAAI,OAAO,UAAU,UAAU;KAC7B,MAAM,SAAS,QAAQ;KACvB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD,MAAM,oBAAoB;KAC5G,MAAM,SAAS;KACf;IACF;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,KAAK,KAAK;EACnE;CACF;CAEA,OAAO,SAAS;AAClB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"visitor-DA5yfOJz.js","names":[],"sources":["../src/schema/embeddedJson.ts","../src/visitor.ts"],"sourcesContent":["import { isJson } from '../mediaType/index.ts'\nimport type { SchemaNode, StringSchemaNode } from '../nodes/schema.ts'\n\n/** The schema of the JSON document a string holds (`contentMediaType` with `contentSchema`), else `undefined`. */\nexport function getEmbeddedJson({ content }: Pick<StringSchemaNode, 'content'>): SchemaNode | undefined {\n // shortcut: an encoded document (`contentEncoding`) is not decoded, so only its encoding is checked; decode it once a spec needs both.\n if (!content?.schema || content.encoding || !content.mediaType) return undefined\n return isJson(content.mediaType) ? content.schema : undefined\n}\n","import { nodeKinds } from './constants.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { InputNode } from './nodes/input.ts'\nimport type { NodeKind } from './nodes/base.ts'\nimport type { OperationNode } from './nodes/operation.ts'\nimport type { ParameterNode } from './nodes/parameter.ts'\nimport type { PropertyNode } from './nodes/property.ts'\nimport type { ResponseNode } from './nodes/response.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { getEmbeddedJson } from './schema/embeddedJson.ts'\n\n/**\n * Traversal depth for AST visitor utilities.\n *\n * - `'shallow'` recurses through every node except nested `Schema` subtrees, which it treats as\n * leaves: a schema node itself is visited, but its children are not.\n * - `'deep'` recursively visits all descendant nodes, including schema subtrees.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\n/**\n * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).\n */\nconst VISITOR_KEYS: Partial<Record<NodeKind, ReadonlyArray<string>>> = {\n Input: ['schemas', 'operations'],\n Operations: ['operations'],\n Operation: ['parameters', 'requestBody', 'responses'],\n RequestBody: ['content'],\n Content: ['schema', 'stream'],\n Response: ['content', 'headers'],\n Schema: ['properties', 'items', 'members', 'additionalProperties', 'patternProperties', 'propertyNames', 'rest'],\n Property: ['schema'],\n Parameter: ['schema'],\n}\n\n/**\n * Schema fields that hold checks rather than shape: the `conditionals` entries, `contains` and a string's `content`.\n * `transform` and `collect` skip them, and `visitChildNodes` walks them with `checks: true`.\n */\nconst schemaCheckKeys = ['conditionals', 'contains', 'content'] as const\n\n/** Visitor callback names in traversal order, the keys of {@link Visitor}. */\nexport const visitorKeys = ['input', 'operation', 'schema', 'property', 'parameter', 'response'] as const\n\nexport type VisitorKey = (typeof visitorKeys)[number]\n\n/**\n * Maps a node kind to the matching visitor callback name.\n */\nconst VISITOR_KEY_BY_KIND: Partial<Record<NodeKind, VisitorKey>> = {\n Input: 'input',\n Operation: 'operation',\n Schema: 'schema',\n Property: 'property',\n Parameter: 'parameter',\n Response: 'response',\n}\n\n/**\n * Traversal context passed as the second argument to every visitor callback.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * schema(node, { parent }) {\n * // parent is the node that holds this schema, or undefined at the root\n * },\n * }\n * ```\n */\nexport type VisitorContext = {\n /**\n * Parent node of the currently visited node. For the root node, this is `undefined`.\n */\n parent?: Node\n}\n\n/**\n * Synchronous visitor consumed by `transform`. Each optional callback runs\n * for the matching node type. Return a new node to replace it, or `undefined`\n * to leave it untouched.\n *\n * Plugins typically expose `transformer` so users can supply a `Visitor` that\n * rewrites the AST before printing.\n *\n * @example Prefix every operationId\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `api_${node.operationId}` }\n * },\n * }\n * ```\n *\n * @example Strip schema descriptions\n * ```ts\n * const visitor: Visitor = {\n * schema(node) {\n * return { ...node, description: undefined }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n input?(node: InputNode, context: VisitorContext): undefined | null | InputNode\n operation?(node: OperationNode, context: VisitorContext): undefined | null | OperationNode\n schema?(node: SchemaNode, context: VisitorContext): undefined | null | SchemaNode\n property?(node: PropertyNode, context: VisitorContext): undefined | null | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext): undefined | null | ParameterNode\n response?(node: ResponseNode, context: VisitorContext): undefined | null | ResponseNode\n}\n\n/**\n * The callbacks of {@link Visitor} with every return type replaced by `TResult`. `collect` uses it\n * so a visitor can yield values instead of replacement nodes.\n *\n * @example\n * ```ts\n * const visitor: VisitorOf<string> = {\n * operation(node) {\n * return node.operationId\n * },\n * }\n * ```\n */\nexport type VisitorOf<TResult> = {\n [K in keyof Visitor]?: (node: Parameters<NonNullable<Visitor[K]>>[0], context: Parameters<NonNullable<Visitor[K]>>[1]) => TResult | null | undefined\n}\n\nexport type TraversalOptions = {\n /**\n * Traversal depth.\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\n/**\n * Options for `transform`.\n *\n * @example\n * ```ts\n * const options: TransformOptions = { depth: 'deep', schema: (node) => node }\n * ```\n *\n * @example\n * ```ts\n * // Only transform the current node, not nested children\n * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }\n * ```\n */\nexport type TransformOptions = Visitor & TraversalOptions\n\n/**\n * Options for `collect`.\n *\n * @example\n * ```ts\n * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }\n * ```\n */\nexport type CollectOptions<T> = VisitorOf<T> & TraversalOptions\n\n/**\n * Returns `true` when `value` is an AST node (an object carrying a `kind`).\n */\nfunction isNode(value: unknown): value is Node {\n return typeof value === 'object' && value !== null && typeof (value as { kind?: unknown }).kind === 'string'\n}\n\n/**\n * Returns `true` for a plain object that maps names to nodes, such as `patternProperties`.\n */\nfunction isNodeRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n// A check no printer emits: a `contains` that any array meets (`min: 0`, no `max`), or `content` that is not JSON.\nfunction isNeverPrinted({ node, key }: { node: Node; key: string }): boolean {\n if (node.kind !== nodeKinds.schema) return false\n if (key === 'contains' && (node.type === 'array' || node.type === 'tuple')) return node.contains?.min === 0 && node.contains.max === undefined\n if (key === 'content' && node.type === 'string') return !getEmbeddedJson(node)\n return false\n}\n\n/**\n * Child keys of a schema walked with `checks: true`: the shape keys, then {@link schemaCheckKeys}.\n */\nconst SCHEMA_CHECK_VISITOR_KEYS: ReadonlyArray<string> = [...VISITOR_KEYS.Schema!, ...schemaCheckKeys]\n\n/**\n * Children a node already passed to `visit`. A node under two keys, such as a stream item under `schema` and\n * `stream`, is visited once. The `Set` is only created once a node has a second child.\n */\ntype SeenChildren = { first: Node | undefined; rest: Set<Node> | undefined }\n\nfunction visitOnce(child: Node, seen: SeenChildren, visit: (child: Node) => boolean): boolean {\n if (seen.first === undefined) {\n seen.first = child\n return visit(child)\n }\n if (seen.first === child || seen.rest?.has(child)) return false\n ;(seen.rest ??= new Set()).add(child)\n return visit(child)\n}\n\nfunction visitRecord(value: Record<string, unknown>, seen: SeenChildren, visit: (child: Node) => boolean): boolean {\n for (const name in value) {\n if (!Object.hasOwn(value, name)) continue\n const item = value[name]\n if (isNode(item) && visitOnce(item, seen, visit)) return true\n }\n return false\n}\n\n/**\n * Calls `visit` for each direct child node and stops at the first call that returns `true`.\n * With `checks: true`, a schema's {@link schemaCheckKeys} fields are walked too, except checks that cannot fail.\n */\nexport function visitChildNodes(node: Node, visit: (child: Node) => boolean, { checks = false }: { checks?: boolean } = {}): boolean {\n const withChecks = checks && node.kind === nodeKinds.schema\n const keys = withChecks ? SCHEMA_CHECK_VISITOR_KEYS : VISITOR_KEYS[node.kind]\n if (!keys) return false\n\n const record = node as unknown as Record<string, unknown>\n let seen: SeenChildren | undefined\n for (const key of keys) {\n const value = record[key]\n if (value === undefined || value === null) continue\n if (withChecks && isNeverPrinted({ node, key })) continue\n seen ??= { first: undefined, rest: undefined }\n if (Array.isArray(value)) {\n // Items can be plain objects that hold nodes, such as the `{ if, then, else }` entries of `conditionals`.\n for (const item of value) if (isNode(item) ? visitOnce(item, seen, visit) : isNodeRecord(item) && visitRecord(item, seen, visit)) return true\n continue\n }\n if (isNode(value)) {\n if (visitOnce(value, seen, visit)) return true\n continue\n }\n if (isNodeRecord(value) && visitRecord(value, seen, visit)) return true\n }\n return false\n}\n\ntype FindResult = { found: SchemaNode | undefined; low: number }\n\nconst notFound: FindResult = { found: undefined, low: Number.POSITIVE_INFINITY }\n\n/**\n * Finds the first schema that matches `predicate` in depth-first order. Pass `follow: ['ref']` to include resolved ref targets.\n *\n * @example\n * ```ts\n * const firstString = findSchema(operationNode, {\n * predicate: (schema) => schema.type === 'string',\n * })\n * ```\n */\nexport function findSchema(\n node: Node,\n {\n predicate,\n follow,\n followRefs = false,\n cache,\n }: {\n predicate: (schema: SchemaNode) => boolean\n /**\n * Links to follow on top of the walk over every child. `['ref']` also walks a resolved ref's target.\n * @default []\n */\n follow?: ReadonlyArray<'ref'>\n /**\n * @deprecated Use `follow: ['ref']`. Removed in Kubb v6.\n */\n followRefs?: boolean\n /**\n * Remembers the match below each schema (`null` for none), so later calls skip the parts of the graph they share.\n * Keep one cache per `predicate` and ref-following mode (`follow`, or the deprecated `followRefs`), for example one per build.\n * In a cyclic graph, a cached call can return a different match than the first one in depth-first order.\n */\n cache?: WeakMap<SchemaNode, SchemaNode | null>\n },\n): SchemaNode | undefined {\n const followsRefs = followRefs || (follow?.includes('ref') ?? false)\n // When following refs, as in Tarjan's algorithm: the visit order of a schema still being walked, or for a finished\n // schema without a match the lowest visit order of an unfinished schema its subtree reached. Only a schema whose\n // subtree reached nothing visited before it has a final no-match; until then it waits in `pending`.\n const state = followsRefs ? new Map<SchemaNode, number>() : undefined\n const pending: Array<SchemaNode> = []\n let order = 0\n\n const walkChildren = (current: Node, initial: FindResult): FindResult => {\n let result = initial\n visitChildNodes(current, (child) => {\n const next = walk(child)\n result = next.found || next.low < result.low ? next : result\n return next.found !== undefined\n })\n return result\n }\n\n const walkSchema = (current: SchemaNode): FindResult => {\n const target = state && current.type === 'ref' && current.schema ? walk(current.schema) : notFound\n if (target.found) return target\n return walkChildren(current, target)\n }\n\n const walk = (current: Node): FindResult => {\n if (current.kind !== nodeKinds.schema) return walkChildren(current, notFound)\n\n const cached = cache?.get(current)\n if (cached === null) return notFound\n if (cached) return { found: cached, low: Number.POSITIVE_INFINITY }\n if (predicate(current)) {\n cache?.set(current, current)\n return { found: current, low: Number.POSITIVE_INFINITY }\n }\n const known = state?.get(current)\n if (known !== undefined) return { found: undefined, low: known }\n\n const index = order++\n const start = pending.length\n state?.set(current, index)\n const result = walkSchema(current)\n if (result.found) {\n cache?.set(current, result.found)\n return result\n }\n if (!state) {\n cache?.set(current, null)\n return notFound\n }\n if (result.low < index) {\n state.set(current, result.low)\n pending.push(current)\n return result\n }\n for (const done of [...pending.splice(start), current]) {\n state.set(done, Number.POSITIVE_INFINITY)\n cache?.set(done, null)\n }\n return notFound\n }\n\n return walk(node).found\n}\n\n/**\n * Runs the visitor callback that matches `node.kind` with the traversal\n * context. The result is a replacement node, a collected value, or `undefined`\n * when no callback is registered for the kind.\n *\n * Shared by `transform` and `collect` so node-kind dispatch lives in one place.\n * `TResult` is the caller's expected return: the same node type for `transform`,\n * the collected value type for `collect`.\n */\nfunction applyVisitor<TResult>(node: Node, visitor: Visitor | VisitorOf<unknown>, parent: Node | undefined): TResult | null | undefined {\n const key = VISITOR_KEY_BY_KIND[node.kind]\n if (!key) return undefined\n\n const fn = visitor[key] as ((node: Node, context: VisitorContext) => TResult | null | undefined) | undefined\n\n return fn?.(node, { parent })\n}\n\n/**\n * Synchronous depth-first transform. Each visitor callback can return a\n * replacement node. Returning `undefined` keeps the original.\n *\n * The original tree is never mutated, a new tree is returned. Pass\n * `depth: 'shallow'` to skip the children of every schema node; other nodes are still walked.\n *\n * @example Prefix every operationId\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example Rewrite the root node without walking its schemas\n * ```ts\n * const next = transform(root, {\n * depth: 'shallow',\n * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),\n * })\n * ```\n */\nexport function transform<T extends Node>(node: T, options: TransformOptions): T {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? 'deep') === 'deep'\n\n // Split the visitor object out once here, then thread it plus `recurse`/`parent` as plain\n // arguments through the recursion. The previous code re-ran the `...visitor` rest-destructure on\n // every recursive `transform` call and rebuilt a `{ ...options, parent }` object per node, so the\n // options shape (which callbacks are present) varied call to call and the hot recursion churned.\n return transformNode(node, visitor, recurse, parent) as T\n}\n\n/**\n * Visits a single node, then immutably rebuilds its children. Returns the original\n * reference when neither the visitor nor the child rebuild changed anything, so callers\n * can detect \"nothing changed\" by identity and ancestors avoid reallocating.\n */\nfunction transformNode(node: Node, visitor: Visitor, recurse: boolean, parent: Node | undefined): Node {\n const visited = applyVisitor<Node>(node, visitor, parent) ?? node\n return transformChildren(visited, visitor, recurse)\n}\n\n/**\n * Immutably rebuilds a node's children, transforming each child node and leaving non-node values\n * (e.g. `additionalProperties: true`) intact.\n */\nfunction transformChildren(node: Node, visitor: Visitor, recurse: boolean): Node {\n const keys = node.kind === nodeKinds.schema && !recurse ? undefined : VISITOR_KEYS[node.kind]\n if (!keys) return node\n\n const record = node as unknown as Record<string, unknown>\n let updates: Record<string, unknown> | undefined\n // A node under two keys is transformed once, so both keys keep pointing at one node. Leaves never create the map.\n let done: Map<Node, Node> | undefined\n const transformOnce = (child: Node) => {\n done ??= new Map()\n const next = done.get(child) ?? transformNode(child, visitor, recurse, node)\n done.set(child, next)\n return next\n }\n\n for (const key of keys) {\n const value = record[key]\n if (value === undefined || value === null) continue\n if (Array.isArray(value)) {\n // Rebuild the array lazily: allocate a new array only once a child actually changes, copying\n // the unchanged prefix at that point. An unchanged array keeps its original reference and\n // allocates nothing. This also drops the per-array `.map` closure that ran on every node.\n let mapped: Array<unknown> | undefined\n for (const [i, item] of value.entries()) {\n const next = isNode(item) ? transformOnce(item) : item\n if (mapped) {\n mapped.push(next)\n continue\n }\n if (next !== item) mapped = [...value.slice(0, i), next]\n }\n if (mapped) (updates ??= {})[key] = mapped\n continue\n }\n if (isNode(value)) {\n const next = transformOnce(value)\n if (next !== value) (updates ??= {})[key] = next\n continue\n }\n if (isNodeRecord(value)) {\n let mapped: Record<string, unknown> | undefined\n for (const [name, item] of Object.entries(value)) {\n const next = isNode(item) ? transformOnce(item) : item\n if (next !== item) (mapped ??= { ...value })[name] = next\n }\n if (mapped) (updates ??= {})[key] = mapped\n }\n }\n\n if (!updates) return node\n const merged = { ...node, ...updates }\n return merged as Node\n}\n\n/**\n * Depth-first collection pass. Gathers every non-null value the visitor\n * callbacks return into an array.\n *\n * @example Collect every operationId\n * ```ts\n * const ids = collect<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n const { depth, parent, ...visitor } = options\n const result: Array<T> = []\n // Plain recursion: draining nested generators costs a `yield*` hop per level for every value.\n collectInto<T>(node, visitor, (depth ?? 'deep') === 'deep', parent, result)\n return result\n}\n\nfunction collectInto<T>(node: Node, visitor: VisitorOf<T>, recurse: boolean, parent: Node | undefined, result: Array<T>): void {\n const v = applyVisitor<T>(node, visitor, parent)\n if (v != null) result.push(v)\n\n if (node.kind === nodeKinds.schema && !recurse) return\n visitChildNodes(node, (child) => {\n collectInto<T>(child, visit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AM,EAAE,OAAO,QAAQ,GAAG,YAAY;CACtC,MAAM,SAAmB,CAAC;CAE1B,YAAe,MAAM,UAAU,SAAS,YAAY,QAAQ,QAAQ,MAAM;CAC1E,OAAO;AACT;AAEA,SAAS,YAAe,MAAY,SAAuB,SAAkB,QAA0B,QAAwB;CAC7H,MAAM,IAAI,aAAgB,MAAM,SAAS,MAAM;CAC/C,IAAI,KAAK,MAAM,OAAO,KAAK,CAAC;CAE5B,IAAI,KAAK,SAAS,UAAU,UAAU,CAAC,SAAS;CAChD,gBAAgB,OAAO,UAAU;EAC/B,YAAe,OAAO,SAAS,SAAS,MAAM,MAAM;EACpD,OAAO;CACT,CAAC;AACH"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"visitor-DhuKS-7x.cjs","names":["isJson","nodeKinds"],"sources":["../src/schema/embeddedJson.ts","../src/visitor.ts"],"sourcesContent":["import { isJson } from '../mediaType/index.ts'\nimport type { SchemaNode, StringSchemaNode } from '../nodes/schema.ts'\n\n/** The schema of the JSON document a string holds (`contentMediaType` with `contentSchema`), else `undefined`. */\nexport function getEmbeddedJson({ content }: Pick<StringSchemaNode, 'content'>): SchemaNode | undefined {\n // shortcut: an encoded document (`contentEncoding`) is not decoded, so only its encoding is checked; decode it once a spec needs both.\n if (!content?.schema || content.encoding || !content.mediaType) return undefined\n return isJson(content.mediaType) ? content.schema : undefined\n}\n","import { nodeKinds } from './constants.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { InputNode } from './nodes/input.ts'\nimport type { NodeKind } from './nodes/base.ts'\nimport type { OperationNode } from './nodes/operation.ts'\nimport type { ParameterNode } from './nodes/parameter.ts'\nimport type { PropertyNode } from './nodes/property.ts'\nimport type { ResponseNode } from './nodes/response.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { getEmbeddedJson } from './schema/embeddedJson.ts'\n\n/**\n * Traversal depth for AST visitor utilities.\n *\n * - `'shallow'` recurses through every node except nested `Schema` subtrees, which it treats as\n * leaves: a schema node itself is visited, but its children are not.\n * - `'deep'` recursively visits all descendant nodes, including schema subtrees.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\n/**\n * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).\n */\nconst VISITOR_KEYS: Partial<Record<NodeKind, ReadonlyArray<string>>> = {\n Input: ['schemas', 'operations'],\n Operations: ['operations'],\n Operation: ['parameters', 'requestBody', 'responses'],\n RequestBody: ['content'],\n Content: ['schema', 'stream'],\n Response: ['content', 'headers'],\n Schema: ['properties', 'items', 'members', 'additionalProperties', 'patternProperties', 'propertyNames', 'rest'],\n Property: ['schema'],\n Parameter: ['schema'],\n}\n\n/**\n * Schema fields that hold checks rather than shape: the `conditionals` entries, `contains` and a string's `content`.\n * `transform` and `collect` skip them, and `visitChildNodes` walks them with `checks: true`.\n */\nconst schemaCheckKeys = ['conditionals', 'contains', 'content'] as const\n\n/** Visitor callback names in traversal order, the keys of {@link Visitor}. */\nexport const visitorKeys = ['input', 'operation', 'schema', 'property', 'parameter', 'response'] as const\n\nexport type VisitorKey = (typeof visitorKeys)[number]\n\n/**\n * Maps a node kind to the matching visitor callback name.\n */\nconst VISITOR_KEY_BY_KIND: Partial<Record<NodeKind, VisitorKey>> = {\n Input: 'input',\n Operation: 'operation',\n Schema: 'schema',\n Property: 'property',\n Parameter: 'parameter',\n Response: 'response',\n}\n\n/**\n * Traversal context passed as the second argument to every visitor callback.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * schema(node, { parent }) {\n * // parent is the node that holds this schema, or undefined at the root\n * },\n * }\n * ```\n */\nexport type VisitorContext = {\n /**\n * Parent node of the currently visited node. For the root node, this is `undefined`.\n */\n parent?: Node\n}\n\n/**\n * Synchronous visitor consumed by `transform`. Each optional callback runs\n * for the matching node type. Return a new node to replace it, or `undefined`\n * to leave it untouched.\n *\n * Plugins typically expose `transformer` so users can supply a `Visitor` that\n * rewrites the AST before printing.\n *\n * @example Prefix every operationId\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `api_${node.operationId}` }\n * },\n * }\n * ```\n *\n * @example Strip schema descriptions\n * ```ts\n * const visitor: Visitor = {\n * schema(node) {\n * return { ...node, description: undefined }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n input?(node: InputNode, context: VisitorContext): undefined | null | InputNode\n operation?(node: OperationNode, context: VisitorContext): undefined | null | OperationNode\n schema?(node: SchemaNode, context: VisitorContext): undefined | null | SchemaNode\n property?(node: PropertyNode, context: VisitorContext): undefined | null | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext): undefined | null | ParameterNode\n response?(node: ResponseNode, context: VisitorContext): undefined | null | ResponseNode\n}\n\n/**\n * The callbacks of {@link Visitor} with every return type replaced by `TResult`. `collect` uses it\n * so a visitor can yield values instead of replacement nodes.\n *\n * @example\n * ```ts\n * const visitor: VisitorOf<string> = {\n * operation(node) {\n * return node.operationId\n * },\n * }\n * ```\n */\nexport type VisitorOf<TResult> = {\n [K in keyof Visitor]?: (node: Parameters<NonNullable<Visitor[K]>>[0], context: Parameters<NonNullable<Visitor[K]>>[1]) => TResult | null | undefined\n}\n\nexport type TraversalOptions = {\n /**\n * Traversal depth.\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\n/**\n * Options for `transform`.\n *\n * @example\n * ```ts\n * const options: TransformOptions = { depth: 'deep', schema: (node) => node }\n * ```\n *\n * @example\n * ```ts\n * // Only transform the current node, not nested children\n * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }\n * ```\n */\nexport type TransformOptions = Visitor & TraversalOptions\n\n/**\n * Options for `collect`.\n *\n * @example\n * ```ts\n * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }\n * ```\n */\nexport type CollectOptions<T> = VisitorOf<T> & TraversalOptions\n\n/**\n * Returns `true` when `value` is an AST node (an object carrying a `kind`).\n */\nfunction isNode(value: unknown): value is Node {\n return typeof value === 'object' && value !== null && typeof (value as { kind?: unknown }).kind === 'string'\n}\n\n/**\n * Returns `true` for a plain object that maps names to nodes, such as `patternProperties`.\n */\nfunction isNodeRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n// A check no printer emits: a `contains` that any array meets (`min: 0`, no `max`), or `content` that is not JSON.\nfunction isNeverPrinted({ node, key }: { node: Node; key: string }): boolean {\n if (node.kind !== nodeKinds.schema) return false\n if (key === 'contains' && (node.type === 'array' || node.type === 'tuple')) return node.contains?.min === 0 && node.contains.max === undefined\n if (key === 'content' && node.type === 'string') return !getEmbeddedJson(node)\n return false\n}\n\n/**\n * Child keys of a schema walked with `checks: true`: the shape keys, then {@link schemaCheckKeys}.\n */\nconst SCHEMA_CHECK_VISITOR_KEYS: ReadonlyArray<string> = [...VISITOR_KEYS.Schema!, ...schemaCheckKeys]\n\n/**\n * Children a node already passed to `visit`. A node under two keys, such as a stream item under `schema` and\n * `stream`, is visited once. The `Set` is only created once a node has a second child.\n */\ntype SeenChildren = { first: Node | undefined; rest: Set<Node> | undefined }\n\nfunction visitOnce(child: Node, seen: SeenChildren, visit: (child: Node) => boolean): boolean {\n if (seen.first === undefined) {\n seen.first = child\n return visit(child)\n }\n if (seen.first === child || seen.rest?.has(child)) return false\n ;(seen.rest ??= new Set()).add(child)\n return visit(child)\n}\n\nfunction visitRecord(value: Record<string, unknown>, seen: SeenChildren, visit: (child: Node) => boolean): boolean {\n for (const name in value) {\n if (!Object.hasOwn(value, name)) continue\n const item = value[name]\n if (isNode(item) && visitOnce(item, seen, visit)) return true\n }\n return false\n}\n\n/**\n * Calls `visit` for each direct child node and stops at the first call that returns `true`.\n * With `checks: true`, a schema's {@link schemaCheckKeys} fields are walked too, except checks that cannot fail.\n */\nexport function visitChildNodes(node: Node, visit: (child: Node) => boolean, { checks = false }: { checks?: boolean } = {}): boolean {\n const withChecks = checks && node.kind === nodeKinds.schema\n const keys = withChecks ? SCHEMA_CHECK_VISITOR_KEYS : VISITOR_KEYS[node.kind]\n if (!keys) return false\n\n const record = node as unknown as Record<string, unknown>\n let seen: SeenChildren | undefined\n for (const key of keys) {\n const value = record[key]\n if (value === undefined || value === null) continue\n if (withChecks && isNeverPrinted({ node, key })) continue\n seen ??= { first: undefined, rest: undefined }\n if (Array.isArray(value)) {\n // Items can be plain objects that hold nodes, such as the `{ if, then, else }` entries of `conditionals`.\n for (const item of value) if (isNode(item) ? visitOnce(item, seen, visit) : isNodeRecord(item) && visitRecord(item, seen, visit)) return true\n continue\n }\n if (isNode(value)) {\n if (visitOnce(value, seen, visit)) return true\n continue\n }\n if (isNodeRecord(value) && visitRecord(value, seen, visit)) return true\n }\n return false\n}\n\ntype FindResult = { found: SchemaNode | undefined; low: number }\n\nconst notFound: FindResult = { found: undefined, low: Number.POSITIVE_INFINITY }\n\n/**\n * Finds the first schema that matches `predicate` in depth-first order. Pass `follow: ['ref']` to include resolved ref targets.\n *\n * @example\n * ```ts\n * const firstString = findSchema(operationNode, {\n * predicate: (schema) => schema.type === 'string',\n * })\n * ```\n */\nexport function findSchema(\n node: Node,\n {\n predicate,\n follow,\n followRefs = false,\n cache,\n }: {\n predicate: (schema: SchemaNode) => boolean\n /**\n * Links to follow on top of the walk over every child. `['ref']` also walks a resolved ref's target.\n * @default []\n */\n follow?: ReadonlyArray<'ref'>\n /**\n * @deprecated Use `follow: ['ref']`. Removed in Kubb v6.\n */\n followRefs?: boolean\n /**\n * Remembers the match below each schema (`null` for none), so later calls skip the parts of the graph they share.\n * Keep one cache per `predicate` and ref-following mode (`follow`, or the deprecated `followRefs`), for example one per build.\n * In a cyclic graph, a cached call can return a different match than the first one in depth-first order.\n */\n cache?: WeakMap<SchemaNode, SchemaNode | null>\n },\n): SchemaNode | undefined {\n const followsRefs = followRefs || (follow?.includes('ref') ?? false)\n // When following refs, as in Tarjan's algorithm: the visit order of a schema still being walked, or for a finished\n // schema without a match the lowest visit order of an unfinished schema its subtree reached. Only a schema whose\n // subtree reached nothing visited before it has a final no-match; until then it waits in `pending`.\n const state = followsRefs ? new Map<SchemaNode, number>() : undefined\n const pending: Array<SchemaNode> = []\n let order = 0\n\n const walkChildren = (current: Node, initial: FindResult): FindResult => {\n let result = initial\n visitChildNodes(current, (child) => {\n const next = walk(child)\n result = next.found || next.low < result.low ? next : result\n return next.found !== undefined\n })\n return result\n }\n\n const walkSchema = (current: SchemaNode): FindResult => {\n const target = state && current.type === 'ref' && current.schema ? walk(current.schema) : notFound\n if (target.found) return target\n return walkChildren(current, target)\n }\n\n const walk = (current: Node): FindResult => {\n if (current.kind !== nodeKinds.schema) return walkChildren(current, notFound)\n\n const cached = cache?.get(current)\n if (cached === null) return notFound\n if (cached) return { found: cached, low: Number.POSITIVE_INFINITY }\n if (predicate(current)) {\n cache?.set(current, current)\n return { found: current, low: Number.POSITIVE_INFINITY }\n }\n const known = state?.get(current)\n if (known !== undefined) return { found: undefined, low: known }\n\n const index = order++\n const start = pending.length\n state?.set(current, index)\n const result = walkSchema(current)\n if (result.found) {\n cache?.set(current, result.found)\n return result\n }\n if (!state) {\n cache?.set(current, null)\n return notFound\n }\n if (result.low < index) {\n state.set(current, result.low)\n pending.push(current)\n return result\n }\n for (const done of [...pending.splice(start), current]) {\n state.set(done, Number.POSITIVE_INFINITY)\n cache?.set(done, null)\n }\n return notFound\n }\n\n return walk(node).found\n}\n\n/**\n * Runs the visitor callback that matches `node.kind` with the traversal\n * context. The result is a replacement node, a collected value, or `undefined`\n * when no callback is registered for the kind.\n *\n * Shared by `transform` and `collect` so node-kind dispatch lives in one place.\n * `TResult` is the caller's expected return: the same node type for `transform`,\n * the collected value type for `collect`.\n */\nfunction applyVisitor<TResult>(node: Node, visitor: Visitor | VisitorOf<unknown>, parent: Node | undefined): TResult | null | undefined {\n const key = VISITOR_KEY_BY_KIND[node.kind]\n if (!key) return undefined\n\n const fn = visitor[key] as ((node: Node, context: VisitorContext) => TResult | null | undefined) | undefined\n\n return fn?.(node, { parent })\n}\n\n/**\n * Synchronous depth-first transform. Each visitor callback can return a\n * replacement node. Returning `undefined` keeps the original.\n *\n * The original tree is never mutated, a new tree is returned. Pass\n * `depth: 'shallow'` to skip the children of every schema node; other nodes are still walked.\n *\n * @example Prefix every operationId\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example Rewrite the root node without walking its schemas\n * ```ts\n * const next = transform(root, {\n * depth: 'shallow',\n * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),\n * })\n * ```\n */\nexport function transform<T extends Node>(node: T, options: TransformOptions): T {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? 'deep') === 'deep'\n\n // Split the visitor object out once here, then thread it plus `recurse`/`parent` as plain\n // arguments through the recursion. The previous code re-ran the `...visitor` rest-destructure on\n // every recursive `transform` call and rebuilt a `{ ...options, parent }` object per node, so the\n // options shape (which callbacks are present) varied call to call and the hot recursion churned.\n return transformNode(node, visitor, recurse, parent) as T\n}\n\n/**\n * Visits a single node, then immutably rebuilds its children. Returns the original\n * reference when neither the visitor nor the child rebuild changed anything, so callers\n * can detect \"nothing changed\" by identity and ancestors avoid reallocating.\n */\nfunction transformNode(node: Node, visitor: Visitor, recurse: boolean, parent: Node | undefined): Node {\n const visited = applyVisitor<Node>(node, visitor, parent) ?? node\n return transformChildren(visited, visitor, recurse)\n}\n\n/**\n * Immutably rebuilds a node's children, transforming each child node and leaving non-node values\n * (e.g. `additionalProperties: true`) intact.\n */\nfunction transformChildren(node: Node, visitor: Visitor, recurse: boolean): Node {\n const keys = node.kind === nodeKinds.schema && !recurse ? undefined : VISITOR_KEYS[node.kind]\n if (!keys) return node\n\n const record = node as unknown as Record<string, unknown>\n let updates: Record<string, unknown> | undefined\n // A node under two keys is transformed once, so both keys keep pointing at one node. Leaves never create the map.\n let done: Map<Node, Node> | undefined\n const transformOnce = (child: Node) => {\n done ??= new Map()\n const next = done.get(child) ?? transformNode(child, visitor, recurse, node)\n done.set(child, next)\n return next\n }\n\n for (const key of keys) {\n const value = record[key]\n if (value === undefined || value === null) continue\n if (Array.isArray(value)) {\n // Rebuild the array lazily: allocate a new array only once a child actually changes, copying\n // the unchanged prefix at that point. An unchanged array keeps its original reference and\n // allocates nothing. This also drops the per-array `.map` closure that ran on every node.\n let mapped: Array<unknown> | undefined\n for (const [i, item] of value.entries()) {\n const next = isNode(item) ? transformOnce(item) : item\n if (mapped) {\n mapped.push(next)\n continue\n }\n if (next !== item) mapped = [...value.slice(0, i), next]\n }\n if (mapped) (updates ??= {})[key] = mapped\n continue\n }\n if (isNode(value)) {\n const next = transformOnce(value)\n if (next !== value) (updates ??= {})[key] = next\n continue\n }\n if (isNodeRecord(value)) {\n let mapped: Record<string, unknown> | undefined\n for (const [name, item] of Object.entries(value)) {\n const next = isNode(item) ? transformOnce(item) : item\n if (next !== item) (mapped ??= { ...value })[name] = next\n }\n if (mapped) (updates ??= {})[key] = mapped\n }\n }\n\n if (!updates) return node\n const merged = { ...node, ...updates }\n return merged as Node\n}\n\n/**\n * Depth-first collection pass. Gathers every non-null value the visitor\n * callbacks return into an array.\n *\n * @example Collect every operationId\n * ```ts\n * const ids = collect<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n const { depth, parent, ...visitor } = options\n const result: Array<T> = []\n // Plain recursion: draining nested generators costs a `yield*` hop per level for every value.\n collectInto<T>(node, visitor, (depth ?? 'deep') === 'deep', parent, result)\n return result\n}\n\nfunction collectInto<T>(node: Node, visitor: VisitorOf<T>, recurse: boolean, parent: Node | undefined, result: Array<T>): void {\n const v = applyVisitor<T>(node, visitor, parent)\n if (v != null) result.push(v)\n\n if (node.kind === nodeKinds.schema && !recurse) return\n visitChildNodes(node, (child) => {\n collectInto<T>(child, visitor, recurse, node, result)\n return false\n })\n}\n"],"mappings":";;;;;AAIA,SAAgB,gBAAgB,EAAE,WAAsE;CAEtG,IAAI,CAAC,SAAS,UAAU,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