@kubb/ast 5.29.4 → 5.30.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 (55) hide show
  1. package/dist/factory.cjs +3 -3
  2. package/dist/{file-Db_PYobC.cjs → file-BcFabTOU.cjs} +4 -4
  3. package/dist/{file-Db_PYobC.cjs.map → file-BcFabTOU.cjs.map} +1 -1
  4. package/dist/{file-DVw2Htda.cjs → file-Cw25Jrxs.cjs} +4 -4
  5. package/dist/{file-DVw2Htda.cjs.map → file-Cw25Jrxs.cjs.map} +1 -1
  6. package/dist/file.cjs +2 -2
  7. package/dist/{graph-CymJtC1M.cjs → graph-CE8A4hmx.cjs} +5 -5
  8. package/dist/{graph-CymJtC1M.cjs.map → graph-CE8A4hmx.cjs.map} +1 -1
  9. package/dist/graph.cjs +1 -1
  10. package/dist/{guards-4drgx10i.cjs → guards-C6i6KL0l.cjs} +2 -2
  11. package/dist/{guards-4drgx10i.cjs.map → guards-C6i6KL0l.cjs.map} +1 -1
  12. package/dist/{http-Dv8py6wh.cjs → http-Dn8k_gED.cjs} +3 -3
  13. package/dist/http-Dn8k_gED.cjs.map +1 -0
  14. package/dist/http.cjs +2 -2
  15. package/dist/index.cjs +17 -17
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/{isRecord-CwlfDtHp.cjs → isRecord-VQAD9N9o.cjs} +2 -2
  20. package/dist/{isRecord-CwlfDtHp.cjs.map → isRecord-VQAD9N9o.cjs.map} +1 -1
  21. package/dist/{json-mEYdjumm.cjs → json-BiA7qy0-.cjs} +3 -3
  22. package/dist/{json-mEYdjumm.cjs.map → json-BiA7qy0-.cjs.map} +1 -1
  23. package/dist/json.cjs +1 -1
  24. package/dist/{macro-h3bm9G48.cjs → macro-CzvAEb1n.cjs} +3 -3
  25. package/dist/{macro-h3bm9G48.cjs.map → macro-CzvAEb1n.cjs.map} +1 -1
  26. package/dist/macro.cjs +1 -1
  27. package/dist/{mediaType-BbIfudh0.cjs → mediaType-KZ2opR9i.cjs} +2 -2
  28. package/dist/{mediaType-BbIfudh0.cjs.map → mediaType-KZ2opR9i.cjs.map} +1 -1
  29. package/dist/mediaType.cjs +1 -1
  30. package/dist/{node-Dhh4jTDv.cjs → node-B9iQCMgg.cjs} +4 -4
  31. package/dist/{node-Dhh4jTDv.cjs.map → node-B9iQCMgg.cjs.map} +1 -1
  32. package/dist/node.cjs +3 -3
  33. package/dist/{nodeText-DH4dLGUb.cjs → nodeText-DDKtSA4q.cjs} +2 -2
  34. package/dist/{nodeText-DH4dLGUb.cjs.map → nodeText-DDKtSA4q.cjs.map} +1 -1
  35. package/dist/{nodes-BjVv21pb.cjs → nodes-BJzvlvwk.cjs} +5 -5
  36. package/dist/{nodes-BjVv21pb.cjs.map → nodes-BJzvlvwk.cjs.map} +1 -1
  37. package/dist/{optionality-C-qULYxo.cjs → optionality-DZfBHn-q.cjs} +2 -2
  38. package/dist/{optionality-C-qULYxo.cjs.map → optionality-DZfBHn-q.cjs.map} +1 -1
  39. package/dist/{promise-DMQPWp6M.cjs → promise-srRwNz0i.cjs} +2 -2
  40. package/dist/{promise-DMQPWp6M.cjs.map → promise-srRwNz0i.cjs.map} +1 -1
  41. package/dist/{ref-CGeCLkAk.cjs → ref-B4s-S3RK.cjs} +5 -5
  42. package/dist/{ref-CGeCLkAk.cjs.map → ref-B4s-S3RK.cjs.map} +1 -1
  43. package/dist/ref.cjs +2 -2
  44. package/dist/{refs-CJZBa9hL.cjs → refs-BcbdyOMu.cjs} +3 -3
  45. package/dist/{refs-CJZBa9hL.cjs.map → refs-BcbdyOMu.cjs.map} +1 -1
  46. package/dist/{rolldown-runtime-BV8xUvPy.cjs → rolldown-runtime-CbDVJ4mO.cjs} +8 -6
  47. package/dist/{schema-0YJZqRXb.cjs → schema-BNlJ7DEx.cjs} +2 -2
  48. package/dist/{schema-0YJZqRXb.cjs.map → schema-BNlJ7DEx.cjs.map} +1 -1
  49. package/dist/{schema-CMe0Dvgd.cjs → schema-aUVOrRjr.cjs} +7 -7
  50. package/dist/{schema-CMe0Dvgd.cjs.map → schema-aUVOrRjr.cjs.map} +1 -1
  51. package/dist/schema.cjs +4 -4
  52. package/dist/{visitor-DT712cxr.cjs → visitor-DVsp084s.cjs} +4 -4
  53. package/dist/{visitor-DT712cxr.cjs.map → visitor-DVsp084s.cjs.map} +1 -1
  54. package/package.json +2 -2
  55. package/dist/http-Dv8py6wh.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["createPrinter","mergeRef","createPrinterImpl","defineMacroImpl"],"sources":["../src/createPrinter.ts","../src/deprecated.ts","../src/index.ts"],"sourcesContent":["import type { ImportNode } from './nodes/file.ts'\nimport type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/schema.ts'\n\n/**\n * Runtime context passed to printer handlers, both as `this` and as the second argument.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * base: () => 'value',\n * }\n * ```\n */\nexport type PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n * The optional `options` are merged over `this.options` for that child call only.\n */\n transform: (node: SchemaNode, options?: Partial<TOptions>) => TOutput | null\n /**\n * Run the printer's built-in handler for the node, ignoring any override for its type.\n * Inside an override, `this.base(node)` returns what the printer would have emitted,\n * so the override can wrap it instead of re-implementing the handler. Nested nodes\n * still dispatch through the overrides. The optional `options` merge like `this.transform`.\n */\n base: (node: SchemaNode, options?: Partial<TOptions>) => TOutput | null\n /** Declares an import the printed code needs. The generator reads it back with `printer.drainImports()`. */\n import: (node: ImportNode) => void\n /**\n * Options for this printer instance.\n */\n options: TOptions\n /** The schema node whose handler called `this.transform`, `undefined` at the root. */\n parent?: SchemaNode\n}\n\n/**\n * Handler for one schema node type. The handler context is `this` and the second argument,\n * so an arrow function can read it as `ctx`. The second argument is typed as optional, so an\n * arrow function asserts it with `ctx!`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'array'> = (node, ctx) => `Array<${ctx!.transform(node.items[0]!)}>`\n * ```\n */\nexport type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n // Optional and without the options type, so one-argument handler types stay assignable and\n // a union of printer tables keeps its contextual `this`. Use `this.options` for typed options.\n ctx?: PrinterHandlerContext<TOutput, object>,\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n /** Returns this printer with `extra` merged over its options, sharing its handlers and imports, such as `printer.with({ keysToOmit: ['id'] })`. */\n with: (extra: Partial<T['options']>) => Printer<T>\n /** Returns the imports declared with `this.import(...)` since the last call, then clears them. */\n drainImports: () => Array<ImportNode>\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\nexport type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: PrinterPartial<T['output'], T['options']>\n /**\n * User-supplied handler overrides. An override wins over the matching `nodes` handler,\n * and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here\n * instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.\n */\n overrides?: PrinterPartial<T['output'], T['options']>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe. The root context is also the second argument.\n */\n print?: (\n this: PrinterHandlerContext<T['output'], T['options']>,\n node: SchemaNode,\n ctx: PrinterHandlerContext<T['output'], T['options']>,\n ) => T['printOutput'] | null\n}\n/**\n * Creates a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `overrides` (optional), user-supplied handlers that win over `nodes`.\n * An override can call `this.base(node)` to reuse the handler it replaced.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { ast, createPrinter } from '@kubb/kit'\n *\n * type PrinterZod = ast.PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = createPrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return (options) => {\n const { name, options: resolvedOptions, nodes, overrides, print: printOverride } = build((options ?? {}) as T['options'])\n const merged = overrides ? { ...nodes, ...overrides } : nodes\n\n const collectedImports: Array<ImportNode> = []\n const importNode = (node: ImportNode): void => {\n collectedImports.push(node)\n }\n type Context = PrinterHandlerContext<T['output'], T['options']>\n const withOptions = (current: T['options'], extra?: Partial<T['options']>): T['options'] => (extra ? { ...current, ...extra } : current)\n\n const dispatch = (table: PrinterPartial<T['output'], T['options']>, node: SchemaNode, options: T['options'], parent?: SchemaNode): T['output'] | null => {\n const handler = table[node.type]\n if (!handler) return null\n\n const context = createContext(options, node, parent)\n return (handler as (this: Context, node: SchemaNode, ctx: Context) => T['output'] | null).call(context, node, context)\n }\n\n // `current` is the node whose handler gets this context, so it becomes the parent of what that handler transforms.\n function createContext(options: T['options'], current?: SchemaNode, parent?: SchemaNode): Context {\n const context: Context = {\n options,\n parent,\n import: importNode,\n transform: (node, extra) => dispatch(merged, node, withOptions(context.options, extra), current),\n base: (node, extra) => dispatch(nodes, node, withOptions(context.options, extra), parent),\n }\n return context\n }\n\n const drainImports = () => collectedImports.splice(0)\n\n const toPrinter = (options: T['options']): Printer<T> => {\n const root = createContext(options)\n return {\n name,\n options,\n transform: (node) => root.transform(node),\n print: (printOverride ? (node: SchemaNode) => printOverride.call(root, node, root) : (node: SchemaNode) => root.transform(node)) as Printer<T>['print'],\n with: (extra) => toPrinter(withOptions(options, extra)),\n drainImports,\n }\n }\n\n return toPrinter(resolvedOptions)\n }\n}\n","import * as graph from './graph/index.ts'\nimport * as http from './http/index.ts'\nimport * as ref from './ref/index.ts'\nimport * as schema from './schema/index.ts'\nimport { mergeRefWithSchema as mergeRef } from './utils/refs.ts'\nimport { createPrinter as createPrinterImpl } from './createPrinter.ts'\nimport { defineMacro as defineMacroImpl } from './defineMacro.ts'\nimport * as macro from './macro/index.ts'\nimport * as node from './node/index.ts'\nimport * as file from './file/index.ts'\n\n/** @deprecated Use `ast.ref.isAlias`. Removed in Kubb v6. */\nexport const isBareRef = ref.isAlias\n\n/** @deprecated Use `ast.ref.mergeSchema`. Removed in Kubb v6. */\nexport const mergeRefWithSchema = mergeRef\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const refName = ref.getName\n\n/** @deprecated Use `ast.ref.getSchema`. Removed in Kubb v6. */\nexport const resolveRef = ref.getSchema\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const resolveRefName = ref.getName\n\n/** @deprecated Use `ast.graph.getImportedNames`. Removed in Kubb v6. */\nexport const collectImportedRefNames = graph.getImportedNames\n\n/** @deprecated Use `ast.graph.getRefNames`. Removed in Kubb v6. */\nexport const collectSchemaRefs = graph.getRefNames\n\n/** @deprecated Use `ast.graph.getUsedNames`. Removed in Kubb v6. */\nexport const collectUsedSchemaNames = graph.getUsedNames\n\n/** @deprecated Use `ast.graph.getCircularNames`. Removed in Kubb v6. */\nexport const findCircularSchemas = graph.getCircularNames\n\n/** @deprecated Use `ast.schema.getLiterals`. Removed in Kubb v6. */\nexport const getSchemaLiteralValues = schema.getLiterals\n\n/** @deprecated Use `ast.schema.inferDiscriminator`. Removed in Kubb v6. */\nexport const inferDiscriminatorPropertyName = schema.inferDiscriminator\n\n/** @deprecated Use `ast.schema.findProperties`. Removed in Kubb v6. */\nexport const resolveSchemaProperties = schema.findProperties\n\n/** @deprecated Use `ast.http.isOperation`. Removed in Kubb v6. */\nexport const isHttpOperationNode = http.isOperation\n\n/** @deprecated Use `ast.node.collect`, which returns the same array. Removed in Kubb v6. */\nexport const collectSync = node.collect\n\n/** @deprecated Use `ast.schema.applyOptionality`. Removed in Kubb v6. */\nexport const optionality = schema.applyOptionality\n\n/** @deprecated Use `ast.node.getText`. Removed in Kubb v6. */\nexport const extractStringsFromNodes = node.getText\n\n/** @deprecated Use `ast.macro.compareOrder`. Removed in Kubb v6. */\nexport const compareEnforce = macro.compareOrder\n\n/** @deprecated Use `createPrinter` from `@kubb/kit`. Removed in Kubb v6. */\nexport const createPrinter = createPrinterImpl\n\n/** @deprecated Use `defineMacro` from `@kubb/kit`. Removed in Kubb v6. */\nexport const defineMacro = defineMacroImpl\n\n/** @deprecated Use `ast.macro.apply`. Removed in Kubb v6. */\nexport const applyMacros = macro.apply\n\n/** @deprecated Use `ast.node.kinds`. Removed in Kubb v6. */\nexport const nodeKinds = node.kinds\n\n/** @deprecated Use `ast.schema.types`. Removed in Kubb v6. */\nexport const schemaTypes = schema.types\n\n/** @deprecated Use `ast.schema.find`. Removed in Kubb v6. */\nexport const findSchema = schema.find\n\n/** @deprecated Use `ast.schema.narrow`. Removed in Kubb v6. */\nexport const narrowSchema = schema.narrow\n\n/** @deprecated Use `ast.node.transform`. Removed in Kubb v6. */\nexport const transform = node.transform\n\n/** @deprecated Use `ast.node.collect`. Removed in Kubb v6. */\nexport const collect = node.collect\n\n/** @deprecated Use `ast.file.inline`. Removed in Kubb v6. */\nexport const inlineFiles = file.inline\n","export type { InlineLanguage } from './utils/inline.ts'\nexport * from './deprecated.ts'\n\nexport * as factory from './nodes/index.ts'\nexport * as file from './file/index.ts'\nexport * as graph from './graph/index.ts'\nexport * as http from './http/index.ts'\nexport * as json from './json/index.ts'\nexport * as macro from './macro/index.ts'\nexport * as mediaType from './mediaType/index.ts'\nexport * as node from './node/index.ts'\nexport * as ref from './ref/index.ts'\nexport * as schema from './schema/index.ts'\nexport type * from './types.ts'\nexport * as ast from './index.ts'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyNA,SAAgBA,gBAAuE,OAAkE;CACvJ,QAAQ,YAAY;EAClB,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,WAAW,OAAO,kBAAkB,MAAO,WAAW,CAAC,CAAkB;EACxH,MAAM,SAAS,YAAY;GAAE,GAAG;GAAO,GAAG;EAAU,IAAI;EAExD,MAAM,mBAAsC,CAAC;EAC7C,MAAM,cAAc,SAA2B;GAC7C,iBAAiB,KAAK,IAAI;EAC5B;EAEA,MAAM,eAAe,SAAuB,UAAiD,QAAQ;GAAE,GAAG;GAAS,GAAG;EAAM,IAAI;EAEhI,MAAM,YAAY,OAAkD,MAAkB,SAAuB,WAA4C;GACvJ,MAAM,UAAU,MAAM,KAAK;GAC3B,IAAI,CAAC,SAAS,OAAO;GAErB,MAAM,UAAU,cAAc,SAAS,MAAM,MAAM;GACnD,OAAQ,QAAkF,KAAK,SAAS,MAAM,OAAO;EACvH;EAGA,SAAS,cAAc,SAAuB,SAAsB,QAA8B;GAChG,MAAM,UAAmB;IACvB;IACA;IACA,QAAQ;IACR,YAAY,MAAM,UAAU,SAAS,QAAQ,MAAM,YAAY,QAAQ,SAAS,KAAK,GAAG,OAAO;IAC/F,OAAO,MAAM,UAAU,SAAS,OAAO,MAAM,YAAY,QAAQ,SAAS,KAAK,GAAG,MAAM;GAC1F;GACA,OAAO;EACT;EAEA,MAAM,qBAAqB,iBAAiB,OAAO,CAAC;EAEpD,MAAM,aAAa,YAAsC;GACvD,MAAM,OAAO,cAAc,OAAO;GAClC,OAAO;IACL;IACA;IACA,YAAY,SAAS,KAAK,UAAU,IAAI;IACxC,OAAQ,iBAAiB,SAAqB,cAAc,KAAK,MAAM,MAAM,IAAI,KAAK,SAAqB,KAAK,UAAU,IAAI;IAC9H,OAAO,UAAU,UAAU,YAAY,SAAS,KAAK,CAAC;IACtD;GACF;EACF;EAEA,OAAO,UAAU,eAAe;CAClC;AACF;;;;AC7PA,MAAa,YAAA,aAAA;;AAGb,MAAa,qBAAqBC,aAAAA;;AAGlC,MAAa,UAAA,YAAA;;AAGb,MAAa,aAAA,aAAA;;AAGb,MAAa,iBAAA,YAAA;;AAGb,MAAa,0BAAA,cAAA;;AAGb,MAAa,oBAAA,cAAA;;AAGb,MAAa,yBAAA,cAAA;;AAGb,MAAa,sBAAA,cAAA;;AAGb,MAAa,yBAAA,eAAA;;AAGb,MAAa,iCAAA,eAAA;;AAGb,MAAa,0BAAA,eAAA;;AAGb,MAAa,sBAAA,eAAA;;AAGb,MAAa,cAAA,gBAAA;;AAGb,MAAa,cAAA,oBAAA;;AAGb,MAAa,0BAAA,iBAAA;;AAGb,MAAa,iBAAA,cAAA;;AAGb,MAAa,gBAAgBC;;AAG7B,MAAa,cAAcC,cAAAA;;AAG3B,MAAa,cAAA,cAAA;;AAGb,MAAa,YAAA,kBAAA;;AAGb,MAAa,cAAA,kBAAA;;AAGb,MAAa,aAAA,gBAAA;;AAGb,MAAa,eAAA,eAAA;;AAGb,MAAa,YAAA,gBAAA;;AAGb,MAAa,UAAA,gBAAA;;AAGb,MAAa,cAAA,aAAA"}
1
+ {"version":3,"file":"index.cjs","names":["createPrinter","mergeRef","createPrinterImpl","defineMacroImpl"],"sources":["../src/createPrinter.ts","../src/deprecated.ts","../src/index.ts"],"sourcesContent":["import type { ImportNode } from './nodes/file.ts'\nimport type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/schema.ts'\n\n/**\n * Runtime context passed to printer handlers, both as `this` and as the second argument.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * base: () => 'value',\n * }\n * ```\n */\nexport type PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n * The optional `options` are merged over `this.options` for that child call only.\n */\n transform: (node: SchemaNode, options?: Partial<TOptions>) => TOutput | null\n /**\n * Run the printer's built-in handler for the node, ignoring any override for its type.\n * Inside an override, `this.base(node)` returns what the printer would have emitted,\n * so the override can wrap it instead of re-implementing the handler. Nested nodes\n * still dispatch through the overrides. The optional `options` merge like `this.transform`.\n */\n base: (node: SchemaNode, options?: Partial<TOptions>) => TOutput | null\n /** Declares an import the printed code needs. The generator reads it back with `printer.drainImports()`. */\n import: (node: ImportNode) => void\n /**\n * Options for this printer instance.\n */\n options: TOptions\n /** The schema node whose handler called `this.transform`, `undefined` at the root. */\n parent?: SchemaNode\n}\n\n/**\n * Handler for one schema node type. The handler context is `this` and the second argument,\n * so an arrow function can read it as `ctx`. The second argument is typed as optional, so an\n * arrow function asserts it with `ctx!`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'array'> = (node, ctx) => `Array<${ctx!.transform(node.items[0]!)}>`\n * ```\n */\nexport type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n // Optional and without the options type, so one-argument handler types stay assignable and\n // a union of printer tables keeps its contextual `this`. Use `this.options` for typed options.\n ctx?: PrinterHandlerContext<TOutput, object>,\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n /** Returns this printer with `extra` merged over its options, sharing its handlers and imports, such as `printer.with({ keysToOmit: ['id'] })`. */\n with: (extra: Partial<T['options']>) => Printer<T>\n /** Returns the imports declared with `this.import(...)` since the last call, then clears them. */\n drainImports: () => Array<ImportNode>\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\nexport type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: PrinterPartial<T['output'], T['options']>\n /**\n * User-supplied handler overrides. An override wins over the matching `nodes` handler,\n * and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here\n * instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.\n */\n overrides?: PrinterPartial<T['output'], T['options']>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe. The root context is also the second argument.\n */\n print?: (\n this: PrinterHandlerContext<T['output'], T['options']>,\n node: SchemaNode,\n ctx: PrinterHandlerContext<T['output'], T['options']>,\n ) => T['printOutput'] | null\n}\n/**\n * Creates a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `overrides` (optional), user-supplied handlers that win over `nodes`.\n * An override can call `this.base(node)` to reuse the handler it replaced.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { ast, createPrinter } from '@kubb/kit'\n *\n * type PrinterZod = ast.PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = createPrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return (options) => {\n const { name, options: resolvedOptions, nodes, overrides, print: printOverride } = build((options ?? {}) as T['options'])\n const merged = overrides ? { ...nodes, ...overrides } : nodes\n\n const collectedImports: Array<ImportNode> = []\n const importNode = (node: ImportNode): void => {\n collectedImports.push(node)\n }\n type Context = PrinterHandlerContext<T['output'], T['options']>\n const withOptions = (current: T['options'], extra?: Partial<T['options']>): T['options'] => (extra ? { ...current, ...extra } : current)\n\n const dispatch = (table: PrinterPartial<T['output'], T['options']>, node: SchemaNode, options: T['options'], parent?: SchemaNode): T['output'] | null => {\n const handler = table[node.type]\n if (!handler) return null\n\n const context = createContext(options, node, parent)\n return (handler as (this: Context, node: SchemaNode, ctx: Context) => T['output'] | null).call(context, node, context)\n }\n\n // `current` is the node whose handler gets this context, so it becomes the parent of what that handler transforms.\n function createContext(options: T['options'], current?: SchemaNode, parent?: SchemaNode): Context {\n const context: Context = {\n options,\n parent,\n import: importNode,\n transform: (node, extra) => dispatch(merged, node, withOptions(context.options, extra), current),\n base: (node, extra) => dispatch(nodes, node, withOptions(context.options, extra), parent),\n }\n return context\n }\n\n const drainImports = () => collectedImports.splice(0)\n\n const toPrinter = (options: T['options']): Printer<T> => {\n const root = createContext(options)\n return {\n name,\n options,\n transform: (node) => root.transform(node),\n print: (printOverride ? (node: SchemaNode) => printOverride.call(root, node, root) : (node: SchemaNode) => root.transform(node)) as Printer<T>['print'],\n with: (extra) => toPrinter(withOptions(options, extra)),\n drainImports,\n }\n }\n\n return toPrinter(resolvedOptions)\n }\n}\n","import * as graph from './graph/index.ts'\nimport * as http from './http/index.ts'\nimport * as ref from './ref/index.ts'\nimport * as schema from './schema/index.ts'\nimport { mergeRefWithSchema as mergeRef } from './utils/refs.ts'\nimport { createPrinter as createPrinterImpl } from './createPrinter.ts'\nimport { defineMacro as defineMacroImpl } from './defineMacro.ts'\nimport * as macro from './macro/index.ts'\nimport * as node from './node/index.ts'\nimport * as file from './file/index.ts'\n\n/** @deprecated Use `ast.ref.isAlias`. Removed in Kubb v6. */\nexport const isBareRef = ref.isAlias\n\n/** @deprecated Use `ast.ref.mergeSchema`. Removed in Kubb v6. */\nexport const mergeRefWithSchema = mergeRef\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const refName = ref.getName\n\n/** @deprecated Use `ast.ref.getSchema`. Removed in Kubb v6. */\nexport const resolveRef = ref.getSchema\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const resolveRefName = ref.getName\n\n/** @deprecated Use `ast.graph.getImportedNames`. Removed in Kubb v6. */\nexport const collectImportedRefNames = graph.getImportedNames\n\n/** @deprecated Use `ast.graph.getRefNames`. Removed in Kubb v6. */\nexport const collectSchemaRefs = graph.getRefNames\n\n/** @deprecated Use `ast.graph.getUsedNames`. Removed in Kubb v6. */\nexport const collectUsedSchemaNames = graph.getUsedNames\n\n/** @deprecated Use `ast.graph.getCircularNames`. Removed in Kubb v6. */\nexport const findCircularSchemas = graph.getCircularNames\n\n/** @deprecated Use `ast.schema.getLiterals`. Removed in Kubb v6. */\nexport const getSchemaLiteralValues = schema.getLiterals\n\n/** @deprecated Use `ast.schema.inferDiscriminator`. Removed in Kubb v6. */\nexport const inferDiscriminatorPropertyName = schema.inferDiscriminator\n\n/** @deprecated Use `ast.schema.findProperties`. Removed in Kubb v6. */\nexport const resolveSchemaProperties = schema.findProperties\n\n/** @deprecated Use `ast.http.isOperation`. Removed in Kubb v6. */\nexport const isHttpOperationNode = http.isOperation\n\n/** @deprecated Use `ast.node.collect`, which returns the same array. Removed in Kubb v6. */\nexport const collectSync = node.collect\n\n/** @deprecated Use `ast.schema.applyOptionality`. Removed in Kubb v6. */\nexport const optionality = schema.applyOptionality\n\n/** @deprecated Use `ast.node.getText`. Removed in Kubb v6. */\nexport const extractStringsFromNodes = node.getText\n\n/** @deprecated Use `ast.macro.compareOrder`. Removed in Kubb v6. */\nexport const compareEnforce = macro.compareOrder\n\n/** @deprecated Use `createPrinter` from `@kubb/kit`. Removed in Kubb v6. */\nexport const createPrinter = createPrinterImpl\n\n/** @deprecated Use `defineMacro` from `@kubb/kit`. Removed in Kubb v6. */\nexport const defineMacro = defineMacroImpl\n\n/** @deprecated Use `ast.macro.apply`. Removed in Kubb v6. */\nexport const applyMacros = macro.apply\n\n/** @deprecated Use `ast.node.kinds`. Removed in Kubb v6. */\nexport const nodeKinds = node.kinds\n\n/** @deprecated Use `ast.schema.types`. Removed in Kubb v6. */\nexport const schemaTypes = schema.types\n\n/** @deprecated Use `ast.schema.find`. Removed in Kubb v6. */\nexport const findSchema = schema.find\n\n/** @deprecated Use `ast.schema.narrow`. Removed in Kubb v6. */\nexport const narrowSchema = schema.narrow\n\n/** @deprecated Use `ast.node.transform`. Removed in Kubb v6. */\nexport const transform = node.transform\n\n/** @deprecated Use `ast.node.collect`. Removed in Kubb v6. */\nexport const collect = node.collect\n\n/** @deprecated Use `ast.file.inline`. Removed in Kubb v6. */\nexport const inlineFiles = file.inline\n","export type { InlineLanguage } from './utils/inline.ts'\nexport * from './deprecated.ts'\n\nexport * as factory from './nodes/index.ts'\nexport * as file from './file/index.ts'\nexport * as graph from './graph/index.ts'\nexport * as http from './http/index.ts'\nexport * as json from './json/index.ts'\nexport * as macro from './macro/index.ts'\nexport * as mediaType from './mediaType/index.ts'\nexport * as node from './node/index.ts'\nexport * as ref from './ref/index.ts'\nexport * as schema from './schema/index.ts'\nexport type * from './types.ts'\nexport * as ast from './index.ts'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyNA,SAAgBA,gBAAuE,OAAkE;CACvJ,QAAQ,YAAY;EAClB,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,WAAW,OAAO,kBAAkB,MAAO,WAAW,CAAC,CAAkB;EACxH,MAAM,SAAS,YAAY;GAAE,GAAG;GAAO,GAAG;EAAU,IAAI;EAExD,MAAM,mBAAsC,CAAC;EAC7C,MAAM,cAAc,SAA2B;GAC7C,iBAAiB,KAAK,IAAI;EAC5B;EAEA,MAAM,eAAe,SAAuB,UAAiD,QAAQ;GAAE,GAAG;GAAS,GAAG;EAAM,IAAI;EAEhI,MAAM,YAAY,OAAkD,MAAkB,SAAuB,WAA4C;GACvJ,MAAM,UAAU,MAAM,KAAK;GAC3B,IAAI,CAAC,SAAS,OAAO;GAErB,MAAM,UAAU,cAAc,SAAS,MAAM,MAAM;GACnD,OAAQ,QAAkF,KAAK,SAAS,MAAM,OAAO;EACvH;EAGA,SAAS,cAAc,SAAuB,SAAsB,QAA8B;GAChG,MAAM,UAAmB;IACvB;IACA;IACA,QAAQ;IACR,YAAY,MAAM,UAAU,SAAS,QAAQ,MAAM,YAAY,QAAQ,SAAS,KAAK,GAAG,OAAO;IAC/F,OAAO,MAAM,UAAU,SAAS,OAAO,MAAM,YAAY,QAAQ,SAAS,KAAK,GAAG,MAAM;GAC1F;GACA,OAAO;EACT;EAEA,MAAM,qBAAqB,iBAAiB,OAAO,CAAC;EAEpD,MAAM,aAAa,YAAsC;GACvD,MAAM,OAAO,cAAc,OAAO;GAClC,OAAO;IACL;IACA;IACA,YAAY,SAAS,KAAK,UAAU,IAAI;IACxC,OAAQ,iBAAiB,SAAqB,cAAc,KAAK,MAAM,MAAM,IAAI,KAAK,SAAqB,KAAK,UAAU,IAAI;IAC9H,OAAO,UAAU,UAAU,YAAY,SAAS,KAAK,CAAC;IACtD;GACF;EACF;EAEA,OAAO,UAAU,eAAe;CAClC;AACF;;;AC7PA,MAAa,YAAA,aAAA;;AAGb,MAAa,qBAAqBC,aAAAA;;AAGlC,MAAa,UAAA,YAAA;;AAGb,MAAa,aAAA,aAAA;;AAGb,MAAa,iBAAA,YAAA;;AAGb,MAAa,0BAAA,cAAA;;AAGb,MAAa,oBAAA,cAAA;;AAGb,MAAa,yBAAA,cAAA;;AAGb,MAAa,sBAAA,cAAA;;AAGb,MAAa,yBAAA,eAAA;;AAGb,MAAa,iCAAA,eAAA;;AAGb,MAAa,0BAAA,eAAA;;AAGb,MAAa,sBAAA,eAAA;;AAGb,MAAa,cAAA,gBAAA;;AAGb,MAAa,cAAA,oBAAA;;AAGb,MAAa,0BAAA,iBAAA;;AAGb,MAAa,iBAAA,cAAA;;AAGb,MAAa,gBAAgBC;;AAG7B,MAAa,cAAcC,cAAAA;;AAG3B,MAAa,cAAA,cAAA;;AAGb,MAAa,YAAA,kBAAA;;AAGb,MAAa,cAAA,kBAAA;;AAGb,MAAa,aAAA,gBAAA;;AAGb,MAAa,eAAA,eAAA;;AAGb,MAAa,YAAA,gBAAA;;AAGb,MAAa,UAAA,gBAAA;;AAGb,MAAa,cAAA,aAAA"}
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ import { n as getNodeText } from "./nodeText-DFak5VpX.js";
15
15
  import { t as http_exports } from "./http-CAWf6TAJ.js";
16
16
  import { t as json_exports } from "./json-IKokiUCp.js";
17
17
  import { r as mediaType_exports } from "./mediaType-DXQCNYdM.js";
18
+ __name(createPrinter$1, "createPrinter");
18
19
  // src/createPrinter.ts
19
20
  /**
20
21
  * Creates a schema printer: a function that takes a `SchemaNode` and emits
@@ -103,7 +104,6 @@ function createPrinter$1(build) {
103
104
  return toPrinter(resolvedOptions);
104
105
  };
105
106
  }
106
- __name(createPrinter$1, "createPrinter");
107
107
  // src/deprecated.ts
108
108
  /** @deprecated Use `ast.ref.isAlias`. Removed in Kubb v6. */
109
109
  const isBareRef = isBareRef$1;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["createPrinter","ref.isAlias","mergeRef","ref.getName","ref.getSchema","graph.getImportedNames","graph.getRefNames","graph.getUsedNames","graph.getCircularNames","schema.getLiterals","schema.inferDiscriminator","schema.findProperties","http.isOperation","node.collect","schema.applyOptionality","node.getText","macro.compareOrder","createPrinterImpl","defineMacroImpl","macro.apply","node.kinds","schema.types","schema.find","schema.narrow","node.transform","file.inline"],"sources":["../src/createPrinter.ts","../src/deprecated.ts","../src/index.ts"],"sourcesContent":["import type { ImportNode } from './nodes/file.ts'\nimport type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/schema.ts'\n\n/**\n * Runtime context passed to printer handlers, both as `this` and as the second argument.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * base: () => 'value',\n * }\n * ```\n */\nexport type PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n * The optional `options` are merged over `this.options` for that child call only.\n */\n transform: (node: SchemaNode, options?: Partial<TOptions>) => TOutput | null\n /**\n * Run the printer's built-in handler for the node, ignoring any override for its type.\n * Inside an override, `this.base(node)` returns what the printer would have emitted,\n * so the override can wrap it instead of re-implementing the handler. Nested nodes\n * still dispatch through the overrides. The optional `options` merge like `this.transform`.\n */\n base: (node: SchemaNode, options?: Partial<TOptions>) => TOutput | null\n /** Declares an import the printed code needs. The generator reads it back with `printer.drainImports()`. */\n import: (node: ImportNode) => void\n /**\n * Options for this printer instance.\n */\n options: TOptions\n /** The schema node whose handler called `this.transform`, `undefined` at the root. */\n parent?: SchemaNode\n}\n\n/**\n * Handler for one schema node type. The handler context is `this` and the second argument,\n * so an arrow function can read it as `ctx`. The second argument is typed as optional, so an\n * arrow function asserts it with `ctx!`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'array'> = (node, ctx) => `Array<${ctx!.transform(node.items[0]!)}>`\n * ```\n */\nexport type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n // Optional and without the options type, so one-argument handler types stay assignable and\n // a union of printer tables keeps its contextual `this`. Use `this.options` for typed options.\n ctx?: PrinterHandlerContext<TOutput, object>,\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n /** Returns this printer with `extra` merged over its options, sharing its handlers and imports, such as `printer.with({ keysToOmit: ['id'] })`. */\n with: (extra: Partial<T['options']>) => Printer<T>\n /** Returns the imports declared with `this.import(...)` since the last call, then clears them. */\n drainImports: () => Array<ImportNode>\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\nexport type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: PrinterPartial<T['output'], T['options']>\n /**\n * User-supplied handler overrides. An override wins over the matching `nodes` handler,\n * and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here\n * instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.\n */\n overrides?: PrinterPartial<T['output'], T['options']>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe. The root context is also the second argument.\n */\n print?: (\n this: PrinterHandlerContext<T['output'], T['options']>,\n node: SchemaNode,\n ctx: PrinterHandlerContext<T['output'], T['options']>,\n ) => T['printOutput'] | null\n}\n/**\n * Creates a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `overrides` (optional), user-supplied handlers that win over `nodes`.\n * An override can call `this.base(node)` to reuse the handler it replaced.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { ast, createPrinter } from '@kubb/kit'\n *\n * type PrinterZod = ast.PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = createPrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return (options) => {\n const { name, options: resolvedOptions, nodes, overrides, print: printOverride } = build((options ?? {}) as T['options'])\n const merged = overrides ? { ...nodes, ...overrides } : nodes\n\n const collectedImports: Array<ImportNode> = []\n const importNode = (node: ImportNode): void => {\n collectedImports.push(node)\n }\n type Context = PrinterHandlerContext<T['output'], T['options']>\n const withOptions = (current: T['options'], extra?: Partial<T['options']>): T['options'] => (extra ? { ...current, ...extra } : current)\n\n const dispatch = (table: PrinterPartial<T['output'], T['options']>, node: SchemaNode, options: T['options'], parent?: SchemaNode): T['output'] | null => {\n const handler = table[node.type]\n if (!handler) return null\n\n const context = createContext(options, node, parent)\n return (handler as (this: Context, node: SchemaNode, ctx: Context) => T['output'] | null).call(context, node, context)\n }\n\n // `current` is the node whose handler gets this context, so it becomes the parent of what that handler transforms.\n function createContext(options: T['options'], current?: SchemaNode, parent?: SchemaNode): Context {\n const context: Context = {\n options,\n parent,\n import: importNode,\n transform: (node, extra) => dispatch(merged, node, withOptions(context.options, extra), current),\n base: (node, extra) => dispatch(nodes, node, withOptions(context.options, extra), parent),\n }\n return context\n }\n\n const drainImports = () => collectedImports.splice(0)\n\n const toPrinter = (options: T['options']): Printer<T> => {\n const root = createContext(options)\n return {\n name,\n options,\n transform: (node) => root.transform(node),\n print: (printOverride ? (node: SchemaNode) => printOverride.call(root, node, root) : (node: SchemaNode) => root.transform(node)) as Printer<T>['print'],\n with: (extra) => toPrinter(withOptions(options, extra)),\n drainImports,\n }\n }\n\n return toPrinter(resolvedOptions)\n }\n}\n","import * as graph from './graph/index.ts'\nimport * as http from './http/index.ts'\nimport * as ref from './ref/index.ts'\nimport * as schema from './schema/index.ts'\nimport { mergeRefWithSchema as mergeRef } from './utils/refs.ts'\nimport { createPrinter as createPrinterImpl } from './createPrinter.ts'\nimport { defineMacro as defineMacroImpl } from './defineMacro.ts'\nimport * as macro from './macro/index.ts'\nimport * as node from './node/index.ts'\nimport * as file from './file/index.ts'\n\n/** @deprecated Use `ast.ref.isAlias`. Removed in Kubb v6. */\nexport const isBareRef = ref.isAlias\n\n/** @deprecated Use `ast.ref.mergeSchema`. Removed in Kubb v6. */\nexport const mergeRefWithSchema = mergeRef\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const refName = ref.getName\n\n/** @deprecated Use `ast.ref.getSchema`. Removed in Kubb v6. */\nexport const resolveRef = ref.getSchema\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const resolveRefName = ref.getName\n\n/** @deprecated Use `ast.graph.getImportedNames`. Removed in Kubb v6. */\nexport const collectImportedRefNames = graph.getImportedNames\n\n/** @deprecated Use `ast.graph.getRefNames`. Removed in Kubb v6. */\nexport const collectSchemaRefs = graph.getRefNames\n\n/** @deprecated Use `ast.graph.getUsedNames`. Removed in Kubb v6. */\nexport const collectUsedSchemaNames = graph.getUsedNames\n\n/** @deprecated Use `ast.graph.getCircularNames`. Removed in Kubb v6. */\nexport const findCircularSchemas = graph.getCircularNames\n\n/** @deprecated Use `ast.schema.getLiterals`. Removed in Kubb v6. */\nexport const getSchemaLiteralValues = schema.getLiterals\n\n/** @deprecated Use `ast.schema.inferDiscriminator`. Removed in Kubb v6. */\nexport const inferDiscriminatorPropertyName = schema.inferDiscriminator\n\n/** @deprecated Use `ast.schema.findProperties`. Removed in Kubb v6. */\nexport const resolveSchemaProperties = schema.findProperties\n\n/** @deprecated Use `ast.http.isOperation`. Removed in Kubb v6. */\nexport const isHttpOperationNode = http.isOperation\n\n/** @deprecated Use `ast.node.collect`, which returns the same array. Removed in Kubb v6. */\nexport const collectSync = node.collect\n\n/** @deprecated Use `ast.schema.applyOptionality`. Removed in Kubb v6. */\nexport const optionality = schema.applyOptionality\n\n/** @deprecated Use `ast.node.getText`. Removed in Kubb v6. */\nexport const extractStringsFromNodes = node.getText\n\n/** @deprecated Use `ast.macro.compareOrder`. Removed in Kubb v6. */\nexport const compareEnforce = macro.compareOrder\n\n/** @deprecated Use `createPrinter` from `@kubb/kit`. Removed in Kubb v6. */\nexport const createPrinter = createPrinterImpl\n\n/** @deprecated Use `defineMacro` from `@kubb/kit`. Removed in Kubb v6. */\nexport const defineMacro = defineMacroImpl\n\n/** @deprecated Use `ast.macro.apply`. Removed in Kubb v6. */\nexport const applyMacros = macro.apply\n\n/** @deprecated Use `ast.node.kinds`. Removed in Kubb v6. */\nexport const nodeKinds = node.kinds\n\n/** @deprecated Use `ast.schema.types`. Removed in Kubb v6. */\nexport const schemaTypes = schema.types\n\n/** @deprecated Use `ast.schema.find`. Removed in Kubb v6. */\nexport const findSchema = schema.find\n\n/** @deprecated Use `ast.schema.narrow`. Removed in Kubb v6. */\nexport const narrowSchema = schema.narrow\n\n/** @deprecated Use `ast.node.transform`. Removed in Kubb v6. */\nexport const transform = node.transform\n\n/** @deprecated Use `ast.node.collect`. Removed in Kubb v6. */\nexport const collect = node.collect\n\n/** @deprecated Use `ast.file.inline`. Removed in Kubb v6. */\nexport const inlineFiles = file.inline\n","export type { InlineLanguage } from './utils/inline.ts'\nexport * from './deprecated.ts'\n\nexport * as factory from './nodes/index.ts'\nexport * as file from './file/index.ts'\nexport * as graph from './graph/index.ts'\nexport * as http from './http/index.ts'\nexport * as json from './json/index.ts'\nexport * as macro from './macro/index.ts'\nexport * as mediaType from './mediaType/index.ts'\nexport * as node from './node/index.ts'\nexport * as ref from './ref/index.ts'\nexport * as schema from './schema/index.ts'\nexport type * from './types.ts'\nexport * as ast from './index.ts'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyNA,SAAgBA,gBAAuE,OAAkE;CACvJ,QAAQ,YAAY;EAClB,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,WAAW,OAAO,kBAAkB,MAAO,WAAW,CAAC,CAAkB;EACxH,MAAM,SAAS,YAAY;GAAE,GAAG;GAAO,GAAG;EAAU,IAAI;EAExD,MAAM,mBAAsC,CAAC;EAC7C,MAAM,cAAc,SAA2B;GAC7C,iBAAiB,KAAK,IAAI;EAC5B;EAEA,MAAM,eAAe,SAAuB,UAAiD,QAAQ;GAAE,GAAG;GAAS,GAAG;EAAM,IAAI;EAEhI,MAAM,YAAY,OAAkD,MAAkB,SAAuB,WAA4C;GACvJ,MAAM,UAAU,MAAM,KAAK;GAC3B,IAAI,CAAC,SAAS,OAAO;GAErB,MAAM,UAAU,cAAc,SAAS,MAAM,MAAM;GACnD,OAAQ,QAAkF,KAAK,SAAS,MAAM,OAAO;EACvH;EAGA,SAAS,cAAc,SAAuB,SAAsB,QAA8B;GAChG,MAAM,UAAmB;IACvB;IACA;IACA,QAAQ;IACR,YAAY,MAAM,UAAU,SAAS,QAAQ,MAAM,YAAY,QAAQ,SAAS,KAAK,GAAG,OAAO;IAC/F,OAAO,MAAM,UAAU,SAAS,OAAO,MAAM,YAAY,QAAQ,SAAS,KAAK,GAAG,MAAM;GAC1F;GACA,OAAO;EACT;EAEA,MAAM,qBAAqB,iBAAiB,OAAO,CAAC;EAEpD,MAAM,aAAa,YAAsC;GACvD,MAAM,OAAO,cAAc,OAAO;GAClC,OAAO;IACL;IACA;IACA,YAAY,SAAS,KAAK,UAAU,IAAI;IACxC,OAAQ,iBAAiB,SAAqB,cAAc,KAAK,MAAM,MAAM,IAAI,KAAK,SAAqB,KAAK,UAAU,IAAI;IAC9H,OAAO,UAAU,UAAU,YAAY,SAAS,KAAK,CAAC;IACtD;GACF;EACF;EAEA,OAAO,UAAU,eAAe;CAClC;AACF;;;;AC7PA,MAAa,YAAYC;;AAGzB,MAAa,qBAAqBC;;AAGlC,MAAa,UAAUC;;AAGvB,MAAa,aAAaC;;AAG1B,MAAa,iBAAiBD;;AAG9B,MAAa,0BAA0BE;;AAGvC,MAAa,oBAAoBC;;AAGjC,MAAa,yBAAyBC;;AAGtC,MAAa,sBAAsBC;;AAGnC,MAAa,yBAAyBC;;AAGtC,MAAa,iCAAiCC;;AAG9C,MAAa,0BAA0BC;;AAGvC,MAAa,sBAAsBC;;AAGnC,MAAa,cAAcC;;AAG3B,MAAa,cAAcC;;AAG3B,MAAa,0BAA0BC;;AAGvC,MAAa,iBAAiBC;;AAG9B,MAAa,gBAAgBC;;AAG7B,MAAa,cAAcC;;AAG3B,MAAa,cAAcC;;AAG3B,MAAa,YAAYC;;AAGzB,MAAa,cAAcC;;AAG3B,MAAa,aAAaC;;AAG1B,MAAa,eAAeC;;AAG5B,MAAa,YAAYC;;AAGzB,MAAa,UAAUX;;AAGvB,MAAa,cAAcY"}
1
+ {"version":3,"file":"index.js","names":["createPrinter","ref.isAlias","mergeRef","ref.getName","ref.getSchema","graph.getImportedNames","graph.getRefNames","graph.getUsedNames","graph.getCircularNames","schema.getLiterals","schema.inferDiscriminator","schema.findProperties","http.isOperation","node.collect","schema.applyOptionality","node.getText","macro.compareOrder","createPrinterImpl","defineMacroImpl","macro.apply","node.kinds","schema.types","schema.find","schema.narrow","node.transform","file.inline"],"sources":["../src/createPrinter.ts","../src/deprecated.ts","../src/index.ts"],"sourcesContent":["import type { ImportNode } from './nodes/file.ts'\nimport type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/schema.ts'\n\n/**\n * Runtime context passed to printer handlers, both as `this` and as the second argument.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * base: () => 'value',\n * }\n * ```\n */\nexport type PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n * The optional `options` are merged over `this.options` for that child call only.\n */\n transform: (node: SchemaNode, options?: Partial<TOptions>) => TOutput | null\n /**\n * Run the printer's built-in handler for the node, ignoring any override for its type.\n * Inside an override, `this.base(node)` returns what the printer would have emitted,\n * so the override can wrap it instead of re-implementing the handler. Nested nodes\n * still dispatch through the overrides. The optional `options` merge like `this.transform`.\n */\n base: (node: SchemaNode, options?: Partial<TOptions>) => TOutput | null\n /** Declares an import the printed code needs. The generator reads it back with `printer.drainImports()`. */\n import: (node: ImportNode) => void\n /**\n * Options for this printer instance.\n */\n options: TOptions\n /** The schema node whose handler called `this.transform`, `undefined` at the root. */\n parent?: SchemaNode\n}\n\n/**\n * Handler for one schema node type. The handler context is `this` and the second argument,\n * so an arrow function can read it as `ctx`. The second argument is typed as optional, so an\n * arrow function asserts it with `ctx!`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'array'> = (node, ctx) => `Array<${ctx!.transform(node.items[0]!)}>`\n * ```\n */\nexport type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n // Optional and without the options type, so one-argument handler types stay assignable and\n // a union of printer tables keeps its contextual `this`. Use `this.options` for typed options.\n ctx?: PrinterHandlerContext<TOutput, object>,\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n /** Returns this printer with `extra` merged over its options, sharing its handlers and imports, such as `printer.with({ keysToOmit: ['id'] })`. */\n with: (extra: Partial<T['options']>) => Printer<T>\n /** Returns the imports declared with `this.import(...)` since the last call, then clears them. */\n drainImports: () => Array<ImportNode>\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\nexport type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: PrinterPartial<T['output'], T['options']>\n /**\n * User-supplied handler overrides. An override wins over the matching `nodes` handler,\n * and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here\n * instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.\n */\n overrides?: PrinterPartial<T['output'], T['options']>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe. The root context is also the second argument.\n */\n print?: (\n this: PrinterHandlerContext<T['output'], T['options']>,\n node: SchemaNode,\n ctx: PrinterHandlerContext<T['output'], T['options']>,\n ) => T['printOutput'] | null\n}\n/**\n * Creates a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `overrides` (optional), user-supplied handlers that win over `nodes`.\n * An override can call `this.base(node)` to reuse the handler it replaced.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { ast, createPrinter } from '@kubb/kit'\n *\n * type PrinterZod = ast.PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = createPrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return (options) => {\n const { name, options: resolvedOptions, nodes, overrides, print: printOverride } = build((options ?? {}) as T['options'])\n const merged = overrides ? { ...nodes, ...overrides } : nodes\n\n const collectedImports: Array<ImportNode> = []\n const importNode = (node: ImportNode): void => {\n collectedImports.push(node)\n }\n type Context = PrinterHandlerContext<T['output'], T['options']>\n const withOptions = (current: T['options'], extra?: Partial<T['options']>): T['options'] => (extra ? { ...current, ...extra } : current)\n\n const dispatch = (table: PrinterPartial<T['output'], T['options']>, node: SchemaNode, options: T['options'], parent?: SchemaNode): T['output'] | null => {\n const handler = table[node.type]\n if (!handler) return null\n\n const context = createContext(options, node, parent)\n return (handler as (this: Context, node: SchemaNode, ctx: Context) => T['output'] | null).call(context, node, context)\n }\n\n // `current` is the node whose handler gets this context, so it becomes the parent of what that handler transforms.\n function createContext(options: T['options'], current?: SchemaNode, parent?: SchemaNode): Context {\n const context: Context = {\n options,\n parent,\n import: importNode,\n transform: (node, extra) => dispatch(merged, node, withOptions(context.options, extra), current),\n base: (node, extra) => dispatch(nodes, node, withOptions(context.options, extra), parent),\n }\n return context\n }\n\n const drainImports = () => collectedImports.splice(0)\n\n const toPrinter = (options: T['options']): Printer<T> => {\n const root = createContext(options)\n return {\n name,\n options,\n transform: (node) => root.transform(node),\n print: (printOverride ? (node: SchemaNode) => printOverride.call(root, node, root) : (node: SchemaNode) => root.transform(node)) as Printer<T>['print'],\n with: (extra) => toPrinter(withOptions(options, extra)),\n drainImports,\n }\n }\n\n return toPrinter(resolvedOptions)\n }\n}\n","import * as graph from './graph/index.ts'\nimport * as http from './http/index.ts'\nimport * as ref from './ref/index.ts'\nimport * as schema from './schema/index.ts'\nimport { mergeRefWithSchema as mergeRef } from './utils/refs.ts'\nimport { createPrinter as createPrinterImpl } from './createPrinter.ts'\nimport { defineMacro as defineMacroImpl } from './defineMacro.ts'\nimport * as macro from './macro/index.ts'\nimport * as node from './node/index.ts'\nimport * as file from './file/index.ts'\n\n/** @deprecated Use `ast.ref.isAlias`. Removed in Kubb v6. */\nexport const isBareRef = ref.isAlias\n\n/** @deprecated Use `ast.ref.mergeSchema`. Removed in Kubb v6. */\nexport const mergeRefWithSchema = mergeRef\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const refName = ref.getName\n\n/** @deprecated Use `ast.ref.getSchema`. Removed in Kubb v6. */\nexport const resolveRef = ref.getSchema\n\n/** @deprecated Use `ast.ref.getName`. Removed in Kubb v6. */\nexport const resolveRefName = ref.getName\n\n/** @deprecated Use `ast.graph.getImportedNames`. Removed in Kubb v6. */\nexport const collectImportedRefNames = graph.getImportedNames\n\n/** @deprecated Use `ast.graph.getRefNames`. Removed in Kubb v6. */\nexport const collectSchemaRefs = graph.getRefNames\n\n/** @deprecated Use `ast.graph.getUsedNames`. Removed in Kubb v6. */\nexport const collectUsedSchemaNames = graph.getUsedNames\n\n/** @deprecated Use `ast.graph.getCircularNames`. Removed in Kubb v6. */\nexport const findCircularSchemas = graph.getCircularNames\n\n/** @deprecated Use `ast.schema.getLiterals`. Removed in Kubb v6. */\nexport const getSchemaLiteralValues = schema.getLiterals\n\n/** @deprecated Use `ast.schema.inferDiscriminator`. Removed in Kubb v6. */\nexport const inferDiscriminatorPropertyName = schema.inferDiscriminator\n\n/** @deprecated Use `ast.schema.findProperties`. Removed in Kubb v6. */\nexport const resolveSchemaProperties = schema.findProperties\n\n/** @deprecated Use `ast.http.isOperation`. Removed in Kubb v6. */\nexport const isHttpOperationNode = http.isOperation\n\n/** @deprecated Use `ast.node.collect`, which returns the same array. Removed in Kubb v6. */\nexport const collectSync = node.collect\n\n/** @deprecated Use `ast.schema.applyOptionality`. Removed in Kubb v6. */\nexport const optionality = schema.applyOptionality\n\n/** @deprecated Use `ast.node.getText`. Removed in Kubb v6. */\nexport const extractStringsFromNodes = node.getText\n\n/** @deprecated Use `ast.macro.compareOrder`. Removed in Kubb v6. */\nexport const compareEnforce = macro.compareOrder\n\n/** @deprecated Use `createPrinter` from `@kubb/kit`. Removed in Kubb v6. */\nexport const createPrinter = createPrinterImpl\n\n/** @deprecated Use `defineMacro` from `@kubb/kit`. Removed in Kubb v6. */\nexport const defineMacro = defineMacroImpl\n\n/** @deprecated Use `ast.macro.apply`. Removed in Kubb v6. */\nexport const applyMacros = macro.apply\n\n/** @deprecated Use `ast.node.kinds`. Removed in Kubb v6. */\nexport const nodeKinds = node.kinds\n\n/** @deprecated Use `ast.schema.types`. Removed in Kubb v6. */\nexport const schemaTypes = schema.types\n\n/** @deprecated Use `ast.schema.find`. Removed in Kubb v6. */\nexport const findSchema = schema.find\n\n/** @deprecated Use `ast.schema.narrow`. Removed in Kubb v6. */\nexport const narrowSchema = schema.narrow\n\n/** @deprecated Use `ast.node.transform`. Removed in Kubb v6. */\nexport const transform = node.transform\n\n/** @deprecated Use `ast.node.collect`. Removed in Kubb v6. */\nexport const collect = node.collect\n\n/** @deprecated Use `ast.file.inline`. Removed in Kubb v6. */\nexport const inlineFiles = file.inline\n","export type { InlineLanguage } from './utils/inline.ts'\nexport * from './deprecated.ts'\n\nexport * as factory from './nodes/index.ts'\nexport * as file from './file/index.ts'\nexport * as graph from './graph/index.ts'\nexport * as http from './http/index.ts'\nexport * as json from './json/index.ts'\nexport * as macro from './macro/index.ts'\nexport * as mediaType from './mediaType/index.ts'\nexport * as node from './node/index.ts'\nexport * as ref from './ref/index.ts'\nexport * as schema from './schema/index.ts'\nexport type * from './types.ts'\nexport * as ast from './index.ts'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyNA,SAAgBA,gBAAuE,OAAkE;CACvJ,QAAQ,YAAY;EAClB,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,WAAW,OAAO,kBAAkB,MAAO,WAAW,CAAC,CAAkB;EACxH,MAAM,SAAS,YAAY;GAAE,GAAG;GAAO,GAAG;EAAU,IAAI;EAExD,MAAM,mBAAsC,CAAC;EAC7C,MAAM,cAAc,SAA2B;GAC7C,iBAAiB,KAAK,IAAI;EAC5B;EAEA,MAAM,eAAe,SAAuB,UAAiD,QAAQ;GAAE,GAAG;GAAS,GAAG;EAAM,IAAI;EAEhI,MAAM,YAAY,OAAkD,MAAkB,SAAuB,WAA4C;GACvJ,MAAM,UAAU,MAAM,KAAK;GAC3B,IAAI,CAAC,SAAS,OAAO;GAErB,MAAM,UAAU,cAAc,SAAS,MAAM,MAAM;GACnD,OAAQ,QAAkF,KAAK,SAAS,MAAM,OAAO;EACvH;EAGA,SAAS,cAAc,SAAuB,SAAsB,QAA8B;GAChG,MAAM,UAAmB;IACvB;IACA;IACA,QAAQ;IACR,YAAY,MAAM,UAAU,SAAS,QAAQ,MAAM,YAAY,QAAQ,SAAS,KAAK,GAAG,OAAO;IAC/F,OAAO,MAAM,UAAU,SAAS,OAAO,MAAM,YAAY,QAAQ,SAAS,KAAK,GAAG,MAAM;GAC1F;GACA,OAAO;EACT;EAEA,MAAM,qBAAqB,iBAAiB,OAAO,CAAC;EAEpD,MAAM,aAAa,YAAsC;GACvD,MAAM,OAAO,cAAc,OAAO;GAClC,OAAO;IACL;IACA;IACA,YAAY,SAAS,KAAK,UAAU,IAAI;IACxC,OAAQ,iBAAiB,SAAqB,cAAc,KAAK,MAAM,MAAM,IAAI,KAAK,SAAqB,KAAK,UAAU,IAAI;IAC9H,OAAO,UAAU,UAAU,YAAY,SAAS,KAAK,CAAC;IACtD;GACF;EACF;EAEA,OAAO,UAAU,eAAe;CAClC;AACF;;;AC7PA,MAAa,YAAYC;;AAGzB,MAAa,qBAAqBC;;AAGlC,MAAa,UAAUC;;AAGvB,MAAa,aAAaC;;AAG1B,MAAa,iBAAiBD;;AAG9B,MAAa,0BAA0BE;;AAGvC,MAAa,oBAAoBC;;AAGjC,MAAa,yBAAyBC;;AAGtC,MAAa,sBAAsBC;;AAGnC,MAAa,yBAAyBC;;AAGtC,MAAa,iCAAiCC;;AAG9C,MAAa,0BAA0BC;;AAGvC,MAAa,sBAAsBC;;AAGnC,MAAa,cAAcC;;AAG3B,MAAa,cAAcC;;AAG3B,MAAa,0BAA0BC;;AAGvC,MAAa,iBAAiBC;;AAG9B,MAAa,gBAAgBC;;AAG7B,MAAa,cAAcC;;AAG3B,MAAa,cAAcC;;AAG3B,MAAa,YAAYC;;AAGzB,MAAa,cAAcC;;AAG3B,MAAa,aAAaC;;AAG1B,MAAa,eAAeC;;AAG5B,MAAa,YAAYC;;AAGzB,MAAa,UAAUX;;AAGvB,MAAa,cAAcY"}
@@ -1,4 +1,4 @@
1
- require("./rolldown-runtime-BV8xUvPy.cjs");
1
+ require("./rolldown-runtime-CbDVJ4mO.cjs");
2
2
  // src/utils/isRecord.ts
3
3
  /**
4
4
  * Returns `true` for an object that is not an array.
@@ -13,4 +13,4 @@ Object.defineProperty(exports, "isRecord", {
13
13
  }
14
14
  });
15
15
 
16
- //# sourceMappingURL=isRecord-CwlfDtHp.cjs.map
16
+ //# sourceMappingURL=isRecord-VQAD9N9o.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"isRecord-CwlfDtHp.cjs","names":[],"sources":["../src/utils/isRecord.ts"],"sourcesContent":["/**\n * Returns `true` for an object that is not an array.\n */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n"],"mappings":";;;;;AAGA,SAAgB,SAAS,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E"}
1
+ {"version":3,"file":"isRecord-VQAD9N9o.cjs","names":[],"sources":["../src/utils/isRecord.ts"],"sourcesContent":["/**\n * Returns `true` for an object that is not an array.\n */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n"],"mappings":";;;;;AAGA,SAAgB,SAAS,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E"}
@@ -1,6 +1,6 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-CbDVJ4mO.cjs");
2
2
  const require_constants = require("./constants-BCRkFAiy.cjs");
3
- const require_isRecord = require("./isRecord-CwlfDtHp.cjs");
3
+ const require_isRecord = require("./isRecord-VQAD9N9o.cjs");
4
4
  // src/json/index.ts
5
5
  var json_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
6
6
  parse: () => parse,
@@ -103,4 +103,4 @@ Object.defineProperty(exports, "stringify", {
103
103
  }
104
104
  });
105
105
 
106
- //# sourceMappingURL=json-mEYdjumm.cjs.map
106
+ //# sourceMappingURL=json-BiA7qy0-.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-mEYdjumm.cjs","names":["isRecord","nodeKinds","schemaTypes"],"sources":["../src/json/index.ts"],"sourcesContent":["import { nodeKinds, schemaTypes } from '../constants.ts'\nimport type { InputNode } from '../nodes/input.ts'\nimport { isRecord } from '../utils/isRecord.ts'\n\nconst version = 1\n\nfunction isInputNode(value: unknown): value is InputNode {\n return isRecord(value) && value.kind === nodeKinds.input && Array.isArray(value.schemas) && Array.isArray(value.operations)\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\nfunction readDocument(parsed: unknown): { input: InputNode; targets: Array<unknown> } {\n const document = isRecord(parsed) ? parsed : {}\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 const { input, targets } = document\n if (!input || !Array.isArray(targets)) {\n throw new Error('Cannot read this AST JSON: `input` or `targets` is missing.')\n }\n if (!isInputNode(input)) {\n throw new Error('Cannot read this AST JSON: `input` is not an Input node with `schemas` and `operations` arrays.')\n }\n // A target is usually a Schema node, but spec data shaped like a ref, such as an example, writes a plain object.\n const badTarget = targets.findIndex((target) => typeof target !== 'object' || target === null)\n if (badTarget !== -1) {\n throw new Error(`Cannot read this AST JSON: target ${badTarget} is not an object.`)\n }\n return { input, targets }\n}\n\n// A wrapped value is spec data that only looks like a ref. A bare number is an index into `targets`.\nfunction refSchema({ stored, targets }: { stored: Array<unknown> | number; targets: Array<unknown> }): unknown {\n if (Array.isArray(stored)) return stored[0]\n const target = targets[stored]\n if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${stored}, which is missing.`)\n return target\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, a malformed `input` or `targets`, or 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 { input, targets } = readDocument(JSON.parse(text))\n\n const stack: Array<unknown> = [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' && (Array.isArray(child) || typeof child === 'number')) {\n value.schema = refSchema({ stored: child, targets })\n continue\n }\n if (typeof child === 'object' && child !== null) stack.push(child)\n }\n }\n\n return input\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,UAAU;AAEhB,SAAS,YAAY,OAAoC;CACvD,OAAOA,iBAAAA,SAAS,KAAK,KAAK,MAAM,SAASC,kBAAAA,UAAU,SAAS,MAAM,QAAQ,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM,UAAU;AAC5H;AAEA,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;AAEA,SAAS,aAAa,QAAgE;CACpF,MAAM,WAAWF,iBAAAA,SAAS,MAAM,IAAI,SAAS,CAAC;CAC9C,IAAI,SAAS,YAAY,SACvB,MAAM,IAAI,MAAM,sDAAsD,QAAQ,QAAQ,KAAK,UAAU,SAAS,OAAO,EAAE,EAAE;CAE3H,MAAM,EAAE,OAAO,YAAY;CAC3B,IAAI,CAAC,SAAS,CAAC,MAAM,QAAQ,OAAO,GAClC,MAAM,IAAI,MAAM,6DAA6D;CAE/E,IAAI,CAAC,YAAY,KAAK,GACpB,MAAM,IAAI,MAAM,iGAAiG;CAGnH,MAAM,YAAY,QAAQ,WAAW,WAAW,OAAO,WAAW,YAAY,WAAW,IAAI;CAC7F,IAAI,cAAc,IAChB,MAAM,IAAI,MAAM,qCAAqC,UAAU,mBAAmB;CAEpF,OAAO;EAAE;EAAO;CAAQ;AAC1B;AAGA,SAAS,UAAU,EAAE,QAAQ,WAAkF;CAC7G,IAAI,MAAM,QAAQ,MAAM,GAAG,OAAO,OAAO;CACzC,MAAM,SAAS,QAAQ;CACvB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD,OAAO,oBAAoB;CAC7G,OAAO;AACT;;;;;AAMA,SAAgB,MAAM,MAAyB;CAE7C,MAAM,EAAE,OAAO,YAAY,aAAa,KAAK,MAAM,IAAI,CAAC;CAExD,MAAM,QAAwB,CAAC,OAAO,GAAG,OAAO;CAChD,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,aAAa,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU,WAAW;IAClF,MAAM,SAAS,UAAU;KAAE,QAAQ;KAAO;IAAQ,CAAC;IACnD;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,KAAK,KAAK;EACnE;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"json-BiA7qy0-.cjs","names":["isRecord","nodeKinds","schemaTypes"],"sources":["../src/json/index.ts"],"sourcesContent":["import { nodeKinds, schemaTypes } from '../constants.ts'\nimport type { InputNode } from '../nodes/input.ts'\nimport { isRecord } from '../utils/isRecord.ts'\n\nconst version = 1\n\nfunction isInputNode(value: unknown): value is InputNode {\n return isRecord(value) && value.kind === nodeKinds.input && Array.isArray(value.schemas) && Array.isArray(value.operations)\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\nfunction readDocument(parsed: unknown): { input: InputNode; targets: Array<unknown> } {\n const document = isRecord(parsed) ? parsed : {}\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 const { input, targets } = document\n if (!input || !Array.isArray(targets)) {\n throw new Error('Cannot read this AST JSON: `input` or `targets` is missing.')\n }\n if (!isInputNode(input)) {\n throw new Error('Cannot read this AST JSON: `input` is not an Input node with `schemas` and `operations` arrays.')\n }\n // A target is usually a Schema node, but spec data shaped like a ref, such as an example, writes a plain object.\n const badTarget = targets.findIndex((target) => typeof target !== 'object' || target === null)\n if (badTarget !== -1) {\n throw new Error(`Cannot read this AST JSON: target ${badTarget} is not an object.`)\n }\n return { input, targets }\n}\n\n// A wrapped value is spec data that only looks like a ref. A bare number is an index into `targets`.\nfunction refSchema({ stored, targets }: { stored: Array<unknown> | number; targets: Array<unknown> }): unknown {\n if (Array.isArray(stored)) return stored[0]\n const target = targets[stored]\n if (!target) throw new Error(`Cannot read this AST JSON: a ref points at target ${stored}, which is missing.`)\n return target\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, a malformed `input` or `targets`, or 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 { input, targets } = readDocument(JSON.parse(text))\n\n const stack: Array<unknown> = [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' && (Array.isArray(child) || typeof child === 'number')) {\n value.schema = refSchema({ stored: child, targets })\n continue\n }\n if (typeof child === 'object' && child !== null) stack.push(child)\n }\n }\n\n return input\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,UAAU;AAEhB,SAAS,YAAY,OAAoC;CACvD,OAAOA,iBAAAA,SAAS,KAAK,KAAK,MAAM,SAASC,kBAAAA,UAAU,SAAS,MAAM,QAAQ,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM,UAAU;AAC5H;AAEA,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;AAEA,SAAS,aAAa,QAAgE;CACpF,MAAM,WAAWF,iBAAAA,SAAS,MAAM,IAAI,SAAS,CAAC;CAC9C,IAAI,SAAS,YAAY,SACvB,MAAM,IAAI,MAAM,sDAAsD,QAAQ,QAAQ,KAAK,UAAU,SAAS,OAAO,EAAE,EAAE;CAE3H,MAAM,EAAE,OAAO,YAAY;CAC3B,IAAI,CAAC,SAAS,CAAC,MAAM,QAAQ,OAAO,GAClC,MAAM,IAAI,MAAM,6DAA6D;CAE/E,IAAI,CAAC,YAAY,KAAK,GACpB,MAAM,IAAI,MAAM,iGAAiG;CAGnH,MAAM,YAAY,QAAQ,WAAW,WAAW,OAAO,WAAW,YAAY,WAAW,IAAI;CAC7F,IAAI,cAAc,IAChB,MAAM,IAAI,MAAM,qCAAqC,UAAU,mBAAmB;CAEpF,OAAO;EAAE;EAAO;CAAQ;AAC1B;AAGA,SAAS,UAAU,EAAE,QAAQ,WAAkF;CAC7G,IAAI,MAAM,QAAQ,MAAM,GAAG,OAAO,OAAO;CACzC,MAAM,SAAS,QAAQ;CACvB,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD,OAAO,oBAAoB;CAC7G,OAAO;AACT;;;;;AAMA,SAAgB,MAAM,MAAyB;CAE7C,MAAM,EAAE,OAAO,YAAY,aAAa,KAAK,MAAM,IAAI,CAAC;CAExD,MAAM,QAAwB,CAAC,OAAO,GAAG,OAAO;CAChD,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,aAAa,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU,WAAW;IAClF,MAAM,SAAS,UAAU;KAAE,QAAQ;KAAO;IAAQ,CAAC;IACnD;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,KAAK,KAAK;EACnE;CACF;CAEA,OAAO;AACT"}
package/dist/json.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_json = require("./json-mEYdjumm.cjs");
2
+ const require_json = require("./json-BiA7qy0-.cjs");
3
3
  exports.parse = require_json.parse;
4
4
  exports.stringify = require_json.stringify;
@@ -1,5 +1,5 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
2
- const require_visitor = require("./visitor-DT712cxr.cjs");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-CbDVJ4mO.cjs");
2
+ const require_visitor = require("./visitor-DVsp084s.cjs");
3
3
  // src/defineMacro.ts
4
4
  /**
5
5
  * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
@@ -124,4 +124,4 @@ Object.defineProperty(exports, "macro_exports", {
124
124
  }
125
125
  });
126
126
 
127
- //# sourceMappingURL=macro-h3bm9G48.cjs.map
127
+ //# sourceMappingURL=macro-CzvAEb1n.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"macro-h3bm9G48.cjs","names":["visitorKeys","transform"],"sources":["../src/defineMacro.ts","../src/macro/index.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext, VisitorDepth, VisitorKey } from './visitor.ts'\nimport { transform, visitorKeys } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * Compares two `enforce` hints for `Array.prototype.sort`: `pre` first, unmarked next, `post`\n * last. Equal hints compare as `0`, so a stable sort keeps authored order within a bucket.\n *\n * @example\n * `plugins.sort((a, b) => compareMacroOrder(a.enforce, b.enforce))`\n */\nexport function compareMacroOrder(a?: Enforce, b?: Enforce): number {\n return enforceWeight(a) - enforceWeight(b)\n}\n\n/**\n * The {@link Visitor} callbacks with `this` typed as the {@link VisitorContext}. A macro callback gets\n * the context both as `this` and as its second argument.\n */\nexport type MacroCallbacks = {\n [K in VisitorKey]?: (this: VisitorContext, ...args: Parameters<NonNullable<Visitor[K]>>) => ReturnType<NonNullable<Visitor[K]>>\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `match` predicate. Macros run on the shared AST, so the same macro works across every\n * adapter and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = MacroCallbacks & {\n /**\n * Macro identifier used to tell macros apart, for example `'dedupe-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Predicate checked against the current node before any callback runs. Returning `false`\n * skips the macro for that node.\n */\n match?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `defineExtension`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (this: VisitorContext, node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.match && !macro.match(current)) continue\n\n const next = callback.call(context, current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} for `transform`. Macros are\n * stable-sorted by `enforce`, then applied sequentially per node so later macros see earlier output.\n */\nfunction composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => compareMacroOrder(a.enforce, b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to skip the children of every schema node; non-schema nodes, such as an operation's parameters and responses, are still rewritten.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Rewrite a schema without walking its children\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n","export { applyMacros as apply, compareMacroOrder as compareOrder } from '../defineMacro.ts'\n"],"mappings":";;;;;;;AAcA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;AASA,SAAgB,kBAAkB,GAAa,GAAqB;CAClE,OAAO,cAAc,CAAC,IAAI,cAAc,CAAC;AAC3C;;;;;;;;;;;;;;;AA+CA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,SAAS,CAAC,MAAM,MAAM,OAAO,GAAG;EAE1C,MAAM,OAAO,SAAS,KAAK,SAAS,SAAS,OAAO;EACpD,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;AAMA,SAAS,cAAc,QAAuC;CAC5D,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,kBAAkB,EAAE,SAAS,EAAE,OAAO,CAAC;CAElF,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAOA,gBAAAA,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACrG,QAA8C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAOC,gBAAAA,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
1
+ {"version":3,"file":"macro-CzvAEb1n.cjs","names":["visitorKeys","transform"],"sources":["../src/defineMacro.ts","../src/macro/index.ts"],"sourcesContent":["import type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext, VisitorDepth, VisitorKey } from './visitor.ts'\nimport { transform, visitorKeys } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * Compares two `enforce` hints for `Array.prototype.sort`: `pre` first, unmarked next, `post`\n * last. Equal hints compare as `0`, so a stable sort keeps authored order within a bucket.\n *\n * @example\n * `plugins.sort((a, b) => compareMacroOrder(a.enforce, b.enforce))`\n */\nexport function compareMacroOrder(a?: Enforce, b?: Enforce): number {\n return enforceWeight(a) - enforceWeight(b)\n}\n\n/**\n * The {@link Visitor} callbacks with `this` typed as the {@link VisitorContext}. A macro callback gets\n * the context both as `this` and as its second argument.\n */\nexport type MacroCallbacks = {\n [K in VisitorKey]?: (this: VisitorContext, ...args: Parameters<NonNullable<Visitor[K]>>) => ReturnType<NonNullable<Visitor[K]>>\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `match` predicate. Macros run on the shared AST, so the same macro works across every\n * adapter and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = MacroCallbacks & {\n /**\n * Macro identifier used to tell macros apart, for example `'dedupe-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Predicate checked against the current node before any callback runs. Returning `false`\n * skips the macro for that node.\n */\n match?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `defineExtension`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (this: VisitorContext, node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.match && !macro.match(current)) continue\n\n const next = callback.call(context, current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} for `transform`. Macros are\n * stable-sorted by `enforce`, then applied sequentially per node so later macros see earlier output.\n */\nfunction composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => compareMacroOrder(a.enforce, b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to skip the children of every schema node; non-schema nodes, such as an operation's parameters and responses, are still rewritten.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Rewrite a schema without walking its children\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n","export { applyMacros as apply, compareMacroOrder as compareOrder } from '../defineMacro.ts'\n"],"mappings":";;;;;;;AAcA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;AASA,SAAgB,kBAAkB,GAAa,GAAqB;CAClE,OAAO,cAAc,CAAC,IAAI,cAAc,CAAC;AAC3C;;;;;;;;;;;;;;;AA+CA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,SAAS,CAAC,MAAM,MAAM,OAAO,GAAG;EAE1C,MAAM,OAAO,SAAS,KAAK,SAAS,SAAS,OAAO;EACpD,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;AAMA,SAAS,cAAc,QAAuC;CAC5D,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,kBAAkB,EAAE,SAAS,EAAE,OAAO,CAAC;CAElF,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAOA,gBAAAA,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACrG,QAA8C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAOC,gBAAAA,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
package/dist/macro.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_macro = require("./macro-h3bm9G48.cjs");
2
+ const require_macro = require("./macro-CzvAEb1n.cjs");
3
3
  exports.apply = require_macro.applyMacros;
4
4
  exports.compareOrder = require_macro.compareMacroOrder;
@@ -1,5 +1,5 @@
1
1
  // src/mediaType/index.ts
2
- var mediaType_exports = /* @__PURE__ */ require("./rolldown-runtime-BV8xUvPy.cjs").__exportAll({
2
+ var mediaType_exports = /* @__PURE__ */ require("./rolldown-runtime-CbDVJ4mO.cjs").__exportAll({
3
3
  getBase: () => getBase,
4
4
  isJson: () => isJson
5
5
  });
@@ -32,4 +32,4 @@ Object.defineProperty(exports, "mediaType_exports", {
32
32
  }
33
33
  });
34
34
 
35
- //# sourceMappingURL=mediaType-BbIfudh0.cjs.map
35
+ //# sourceMappingURL=mediaType-KZ2opR9i.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mediaType-BbIfudh0.cjs","names":[],"sources":["../src/mediaType/index.ts"],"sourcesContent":["export type MediaTypeInput = string | { contentType: string }\n\nconst jsonMediaTypes = new Set(['application/json', 'text/json'])\n\n/** The media type without its parameters, in lower case: `Text/Plain; charset=utf-8` gives `text/plain`. */\nexport function getBase(mediaType: MediaTypeInput): string {\n const value = typeof mediaType === 'string' ? mediaType : mediaType.contentType\n return value.split(';')[0]!.trim().toLowerCase()\n}\n\n/** Whether the media type is `application/json`, `text/json`, or has a `+json` suffix. */\nexport function isJson(mediaType: MediaTypeInput): boolean {\n const baseType = getBase(mediaType)\n return jsonMediaTypes.has(baseType) || baseType.endsWith('+json')\n}\n"],"mappings":";;;;;AAEA,MAAM,iCAAiB,IAAI,IAAI,CAAC,oBAAoB,WAAW,CAAC;;AAGhE,SAAgB,QAAQ,WAAmC;CAEzD,QADc,OAAO,cAAc,WAAW,YAAY,UAAU,YAAA,CACvD,MAAM,GAAG,CAAC,CAAC,EAAE,CAAE,KAAK,CAAC,CAAC,YAAY;AACjD;;AAGA,SAAgB,OAAO,WAAoC;CACzD,MAAM,WAAW,QAAQ,SAAS;CAClC,OAAO,eAAe,IAAI,QAAQ,KAAK,SAAS,SAAS,OAAO;AAClE"}
1
+ {"version":3,"file":"mediaType-KZ2opR9i.cjs","names":[],"sources":["../src/mediaType/index.ts"],"sourcesContent":["export type MediaTypeInput = string | { contentType: string }\n\nconst jsonMediaTypes = new Set(['application/json', 'text/json'])\n\n/** The media type without its parameters, in lower case: `Text/Plain; charset=utf-8` gives `text/plain`. */\nexport function getBase(mediaType: MediaTypeInput): string {\n const value = typeof mediaType === 'string' ? mediaType : mediaType.contentType\n return value.split(';')[0]!.trim().toLowerCase()\n}\n\n/** Whether the media type is `application/json`, `text/json`, or has a `+json` suffix. */\nexport function isJson(mediaType: MediaTypeInput): boolean {\n const baseType = getBase(mediaType)\n return jsonMediaTypes.has(baseType) || baseType.endsWith('+json')\n}\n"],"mappings":";;;;;AAEA,MAAM,iCAAiB,IAAI,IAAI,CAAC,oBAAoB,WAAW,CAAC;;AAGhE,SAAgB,QAAQ,WAAmC;CAEzD,QADc,OAAO,cAAc,WAAW,YAAY,UAAU,YAAA,CACvD,MAAM,GAAG,CAAC,CAAC,EAAE,CAAE,KAAK,CAAC,CAAC,YAAY;AACjD;;AAGA,SAAgB,OAAO,WAAoC;CACzD,MAAM,WAAW,QAAQ,SAAS;CAClC,OAAO,eAAe,IAAI,QAAQ,KAAK,SAAS,SAAS,OAAO;AAClE"}
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_mediaType = require("./mediaType-BbIfudh0.cjs");
2
+ const require_mediaType = require("./mediaType-KZ2opR9i.cjs");
3
3
  exports.getBase = require_mediaType.getBase;
4
4
  exports.isJson = require_mediaType.isJson;
@@ -1,7 +1,7 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-CbDVJ4mO.cjs");
2
2
  const require_constants = require("./constants-BCRkFAiy.cjs");
3
- const require_nodeText = require("./nodeText-DH4dLGUb.cjs");
4
- const require_visitor = require("./visitor-DT712cxr.cjs");
3
+ const require_nodeText = require("./nodeText-DDKtSA4q.cjs");
4
+ const require_visitor = require("./visitor-DVsp084s.cjs");
5
5
  // src/node/index.ts
6
6
  var node_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
7
7
  collect: () => require_visitor.collect,
@@ -16,4 +16,4 @@ Object.defineProperty(exports, "node_exports", {
16
16
  }
17
17
  });
18
18
 
19
- //# sourceMappingURL=node-Dhh4jTDv.cjs.map
19
+ //# sourceMappingURL=node-B9iQCMgg.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-Dhh4jTDv.cjs","names":[],"sources":["../src/node/index.ts"],"sourcesContent":["export { nodeKinds as kinds } from '../constants.ts'\nexport { getNodeText as getText } from '../utils/nodeText.ts'\nexport { collect, transform } from '../visitor.ts'\n"],"mappings":""}
1
+ {"version":3,"file":"node-B9iQCMgg.cjs","names":[],"sources":["../src/node/index.ts"],"sourcesContent":["export { nodeKinds as kinds } from '../constants.ts'\nexport { getNodeText as getText } from '../utils/nodeText.ts'\nexport { collect, transform } from '../visitor.ts'\n"],"mappings":""}
package/dist/node.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_constants = require("./constants-BCRkFAiy.cjs");
3
- const require_visitor = require("./visitor-DT712cxr.cjs");
4
- const require_nodeText = require("./nodeText-DH4dLGUb.cjs");
5
- require("./node-Dhh4jTDv.cjs");
3
+ const require_visitor = require("./visitor-DVsp084s.cjs");
4
+ const require_nodeText = require("./nodeText-DDKtSA4q.cjs");
5
+ require("./node-B9iQCMgg.cjs");
6
6
  exports.collect = require_visitor.collect;
7
7
  exports.getText = require_nodeText.getNodeText;
8
8
  exports.kinds = require_constants.nodeKinds;
@@ -1,4 +1,4 @@
1
- require("./rolldown-runtime-BV8xUvPy.cjs");
1
+ require("./rolldown-runtime-CbDVJ4mO.cjs");
2
2
  const require_constants = require("./constants-BCRkFAiy.cjs");
3
3
  // src/utils/nodeText.ts
4
4
  const CODE_NODE_TEXT_FIELDS = {
@@ -55,4 +55,4 @@ Object.defineProperty(exports, "getNodeText", {
55
55
  }
56
56
  });
57
57
 
58
- //# sourceMappingURL=nodeText-DH4dLGUb.cjs.map
58
+ //# sourceMappingURL=nodeText-DDKtSA4q.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodeText-DH4dLGUb.cjs","names":["nodeKinds"],"sources":["../src/utils/nodeText.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport type { NodeKind } from '../nodes/base.ts'\nimport type { CodeNode } from '../nodes/code.ts'\n\nexport const CODE_NODE_TEXT_FIELDS: Partial<Record<NodeKind, ReadonlyArray<string>>> = {\n Text: ['value'],\n Jsx: ['value'],\n Function: ['params', 'generics', 'returnType'],\n ArrowFunction: ['params', 'generics', 'returnType'],\n Const: ['type'],\n}\n\n/**\n * Extracts all string content from a `CodeNode` tree recursively.\n * Collects the text fields and nested node content, to build the source string for import filtering.\n */\nexport function getNodeText(nodes: Array<CodeNode> | undefined): string {\n if (!nodes?.length) return ''\n\n // One flat pass: this runs over every code node during file assembly, so it skips `map().filter().join()` allocations.\n const collected: Array<string> = []\n\n for (const node of nodes) {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') {\n if (node) collected.push(node as string)\n continue\n }\n if (node.kind === nodeKinds.break) continue\n\n const parts: Array<string> = []\n const record = node as unknown as Record<string, unknown>\n for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {\n const value = record[field]\n if (Array.isArray(value)) parts.push(value.join(', '))\n if (typeof value === 'string' && value) parts.push(value)\n }\n\n const nested = 'nodes' in node ? getNodeText(node.nodes) : ''\n if (nested) parts.push(nested)\n\n if (parts.length) collected.push(parts.join('\\n'))\n }\n\n return collected.join('\\n')\n}\n"],"mappings":";;;AAIA,MAAa,wBAA0E;CACrF,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,OAAO;CACb,UAAU;EAAC;EAAU;EAAY;CAAY;CAC7C,eAAe;EAAC;EAAU;EAAY;CAAY;CAClD,OAAO,CAAC,MAAM;AAChB;;;;;AAMA,SAAgB,YAAY,OAA4C;CACtE,IAAI,CAAC,OAAO,QAAQ,OAAO;CAG3B,MAAM,YAA2B,CAAC;CAElC,KAAK,MAAM,QAAQ,OAAO;EAExB,IAAI,OAAO,SAAS,UAAU;GAC5B,IAAI,MAAM,UAAU,KAAK,IAAc;GACvC;EACF;EACA,IAAI,KAAK,SAASA,kBAAAA,UAAU,OAAO;EAEnC,MAAM,QAAuB,CAAC;EAC9B,MAAM,SAAS;EACf,KAAK,MAAM,SAAS,sBAAsB,KAAK,SAAS,CAAC,GAAG;GAC1D,MAAM,QAAQ,OAAO;GACrB,IAAI,MAAM,QAAQ,KAAK,GAAG,MAAM,KAAK,MAAM,KAAK,IAAI,CAAC;GACrD,IAAI,OAAO,UAAU,YAAY,OAAO,MAAM,KAAK,KAAK;EAC1D;EAEA,MAAM,SAAS,WAAW,OAAO,YAAY,KAAK,KAAK,IAAI;EAC3D,IAAI,QAAQ,MAAM,KAAK,MAAM;EAE7B,IAAI,MAAM,QAAQ,UAAU,KAAK,MAAM,KAAK,IAAI,CAAC;CACnD;CAEA,OAAO,UAAU,KAAK,IAAI;AAC5B"}
1
+ {"version":3,"file":"nodeText-DDKtSA4q.cjs","names":["nodeKinds"],"sources":["../src/utils/nodeText.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport type { NodeKind } from '../nodes/base.ts'\nimport type { CodeNode } from '../nodes/code.ts'\n\nexport const CODE_NODE_TEXT_FIELDS: Partial<Record<NodeKind, ReadonlyArray<string>>> = {\n Text: ['value'],\n Jsx: ['value'],\n Function: ['params', 'generics', 'returnType'],\n ArrowFunction: ['params', 'generics', 'returnType'],\n Const: ['type'],\n}\n\n/**\n * Extracts all string content from a `CodeNode` tree recursively.\n * Collects the text fields and nested node content, to build the source string for import filtering.\n */\nexport function getNodeText(nodes: Array<CodeNode> | undefined): string {\n if (!nodes?.length) return ''\n\n // One flat pass: this runs over every code node during file assembly, so it skips `map().filter().join()` allocations.\n const collected: Array<string> = []\n\n for (const node of nodes) {\n // Backward-compat: compiled plugins may still pass bare strings at runtime\n if (typeof node === 'string') {\n if (node) collected.push(node as string)\n continue\n }\n if (node.kind === nodeKinds.break) continue\n\n const parts: Array<string> = []\n const record = node as unknown as Record<string, unknown>\n for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {\n const value = record[field]\n if (Array.isArray(value)) parts.push(value.join(', '))\n if (typeof value === 'string' && value) parts.push(value)\n }\n\n const nested = 'nodes' in node ? getNodeText(node.nodes) : ''\n if (nested) parts.push(nested)\n\n if (parts.length) collected.push(parts.join('\\n'))\n }\n\n return collected.join('\\n')\n}\n"],"mappings":";;;AAIA,MAAa,wBAA0E;CACrF,MAAM,CAAC,OAAO;CACd,KAAK,CAAC,OAAO;CACb,UAAU;EAAC;EAAU;EAAY;CAAY;CAC7C,eAAe;EAAC;EAAU;EAAY;CAAY;CAClD,OAAO,CAAC,MAAM;AAChB;;;;;AAMA,SAAgB,YAAY,OAA4C;CACtE,IAAI,CAAC,OAAO,QAAQ,OAAO;CAG3B,MAAM,YAA2B,CAAC;CAElC,KAAK,MAAM,QAAQ,OAAO;EAExB,IAAI,OAAO,SAAS,UAAU;GAC5B,IAAI,MAAM,UAAU,KAAK,IAAc;GACvC;EACF;EACA,IAAI,KAAK,SAASA,kBAAAA,UAAU,OAAO;EAEnC,MAAM,QAAuB,CAAC;EAC9B,MAAM,SAAS;EACf,KAAK,MAAM,SAAS,sBAAsB,KAAK,SAAS,CAAC,GAAG;GAC1D,MAAM,QAAQ,OAAO;GACrB,IAAI,MAAM,QAAQ,KAAK,GAAG,MAAM,KAAK,MAAM,KAAK,IAAI,CAAC;GACrD,IAAI,OAAO,UAAU,YAAY,OAAO,MAAM,KAAK,KAAK;EAC1D;EAEA,MAAM,SAAS,WAAW,OAAO,YAAY,KAAK,KAAK,IAAI;EAC3D,IAAI,QAAQ,MAAM,KAAK,MAAM;EAE7B,IAAI,MAAM,QAAQ,UAAU,KAAK,MAAM,KAAK,IAAI,CAAC;CACnD;CAEA,OAAO,UAAU,KAAK,IAAI;AAC5B"}
@@ -1,8 +1,8 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-CbDVJ4mO.cjs");
2
2
  const require_constants = require("./constants-BCRkFAiy.cjs");
3
- const require_file = require("./file-Db_PYobC.cjs");
4
- const require_optionality = require("./optionality-C-qULYxo.cjs");
5
- const require_schema = require("./schema-0YJZqRXb.cjs");
3
+ const require_file = require("./file-BcFabTOU.cjs");
4
+ const require_optionality = require("./optionality-DZfBHn-q.cjs");
5
+ const require_schema = require("./schema-BNlJ7DEx.cjs");
6
6
  // src/nodes/code.ts
7
7
  /**
8
8
  * Creates a `ConstNode` representing a TypeScript `const` declaration.
@@ -339,4 +339,4 @@ Object.defineProperty(exports, "nodes_exports", {
339
339
  }
340
340
  });
341
341
 
342
- //# sourceMappingURL=nodes-BjVv21pb.cjs.map
342
+ //# sourceMappingURL=nodes-BJzvlvwk.cjs.map