@kubb/ast 5.25.0 → 5.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{file-3gsgXreK.js → combineFileMembers-DJHNAZBN.js} +204 -161
- package/dist/combineFileMembers-DJHNAZBN.js.map +1 -0
- package/dist/{file-D73XubVb.cjs → combineFileMembers-DmmuOmY8.cjs} +216 -160
- package/dist/combineFileMembers-DmmuOmY8.cjs.map +1 -0
- package/dist/factory.cjs +6 -6
- package/dist/factory.d.cts +2 -2
- package/dist/factory.d.ts +2 -2
- package/dist/factory.js +2 -2
- package/dist/{file-CMHRNuMX.d.cts → file-DJqd2j3y.d.cts} +3 -1
- package/dist/{file-D67ITWja.d.ts → file-Dg70hXm3.d.ts} +3 -1
- package/dist/{file-1YtTOZeL.js → file-HwCmj--S.js} +5 -3
- package/dist/file-HwCmj--S.js.map +1 -0
- package/dist/{file-azmmZwDb.cjs → file-z3xToonr.cjs} +11 -9
- package/dist/file-z3xToonr.cjs.map +1 -0
- package/dist/file.cjs +7 -5
- package/dist/file.d.cts +2 -2
- package/dist/file.d.ts +2 -2
- package/dist/file.js +3 -3
- package/dist/{index-DNZgWmNq.d.cts → index-BjmAaymt.d.cts} +1 -1
- package/dist/{index-CIUD99Ft.d.ts → index-Br4bwEnS.d.ts} +2 -2
- package/dist/{index-CGmrJThc.d.ts → index-Bz33tfQo.d.ts} +1 -1
- package/dist/{index-Bcxj7FqZ.d.cts → index-C5SXJAtZ.d.cts} +2 -2
- package/dist/{index-bkTCYnZj.d.cts → index-CCUB1hoV.d.cts} +1 -1
- package/dist/{index-C-nsgwuD.d.ts → index-D3yqgtiN.d.ts} +2 -2
- package/dist/{index-84453BaS.d.cts → index-DBKL6vyC.d.cts} +16 -3
- package/dist/{index-BvdIGsVr.d.cts → index-DNDNDzyJ.d.cts} +2 -2
- package/dist/{index-C7U9EiIP.d.ts → index-DXdwkq7X.d.ts} +2 -2
- package/dist/{index-B3o1AkNE.d.ts → index-MzcNxet1.d.ts} +1 -1
- package/dist/{index-DR9ahJ-x.d.cts → index-OfWkiJ5O.d.cts} +2 -2
- package/dist/{index-BFwAhPp8.d.ts → index-VPq6RwTm.d.ts} +16 -3
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/macro-3uGSg-ic.js.map +1 -1
- package/dist/macro-Ywn4-0s5.cjs.map +1 -1
- package/dist/macro.d.cts +1 -1
- package/dist/macro.d.ts +1 -1
- package/dist/mediaType-BbIfudh0.cjs.map +1 -1
- package/dist/mediaType-DXQCNYdM.js.map +1 -1
- package/dist/mediaType.d.cts +2 -2
- package/dist/mediaType.d.ts +2 -2
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/{nodes-BdZfapPI.cjs → nodes-TtDfZ9qf.cjs} +12 -12
- package/dist/{nodes-BdZfapPI.cjs.map → nodes-TtDfZ9qf.cjs.map} +1 -1
- package/dist/{nodes-D9nwroV5.js → nodes-u9i-tqFp.js} +2 -2
- package/dist/{nodes-D9nwroV5.js.map → nodes-u9i-tqFp.js.map} +1 -1
- package/dist/promise-B3YkZ4C8.js.map +1 -1
- package/dist/promise-DScaykew.cjs.map +1 -1
- package/dist/schema-0YJZqRXb.cjs.map +1 -1
- package/dist/schema-BvUrXIoX.js.map +1 -1
- package/dist/schema-CC008xgK.js.map +1 -1
- package/dist/schema-DfLGJ-oh.cjs.map +1 -1
- package/dist/schema.d.cts +2 -2
- package/dist/schema.d.ts +2 -2
- package/dist/{visitor-VYLe7Q4m.d.cts → visitor-BN5QJX7-.d.cts} +1 -1
- package/dist/{visitor-CqI8T9Qa.d.ts → visitor-BNGMMmpe.d.ts} +1 -1
- package/dist/visitor-DA5yfOJz.js.map +1 -1
- package/dist/visitor-DhuKS-7x.cjs.map +1 -1
- package/package.json +1 -1
- package/dist/file-1YtTOZeL.js.map +0 -1
- package/dist/file-3gsgXreK.js.map +0 -1
- package/dist/file-D73XubVb.cjs.map +0 -1
- package/dist/file-azmmZwDb.cjs.map +0 -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 */\ntype 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 */\ntype 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 */\ntype 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macro-3uGSg-ic.js","names":[],"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 */\
|
|
1
|
+
{"version":3,"file":"macro-3uGSg-ic.js","names":[],"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,OAAO,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,OAAO,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"macro-Ywn4-0s5.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 */\
|
|
1
|
+
{"version":3,"file":"macro-Ywn4-0s5.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.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as compareMacroOrder, i as applyMacros } from "./index-
|
|
1
|
+
import { a as compareMacroOrder, i as applyMacros } from "./index-DNDNDzyJ.cjs";
|
|
2
2
|
export { applyMacros as apply, compareMacroOrder as compareOrder };
|
package/dist/macro.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as compareMacroOrder, i as applyMacros } from "./index-
|
|
1
|
+
import { a as compareMacroOrder, i as applyMacros } from "./index-DXdwkq7X.js";
|
|
2
2
|
export { applyMacros as apply, compareMacroOrder as compareOrder };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mediaType-BbIfudh0.cjs","names":[],"sources":["../src/mediaType/index.ts"],"sourcesContent":["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-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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mediaType-DXQCNYdM.js","names":[],"sources":["../src/mediaType/index.ts"],"sourcesContent":["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-DXQCNYdM.js","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"}
|
package/dist/mediaType.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { getBase, isJson };
|
|
1
|
+
import { i as isJson, n as getBase, t as MediaTypeInput } from "./index-OfWkiJ5O.cjs";
|
|
2
|
+
export { MediaTypeInput, getBase, isJson };
|
package/dist/mediaType.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { getBase, isJson };
|
|
1
|
+
import { i as isJson, n as getBase, t as MediaTypeInput } from "./index-D3yqgtiN.js";
|
|
2
|
+
export { MediaTypeInput, getBase, isJson };
|
package/dist/node.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { i as nodeKinds } from "./base-CyJhBRMi.cjs";
|
|
2
|
-
import { a as collect, s as transform } from "./visitor-
|
|
3
|
-
import { n as getNodeText } from "./index-
|
|
2
|
+
import { a as collect, s as transform } from "./visitor-BN5QJX7-.cjs";
|
|
3
|
+
import { n as getNodeText } from "./index-C5SXJAtZ.cjs";
|
|
4
4
|
export { collect, getNodeText as getText, nodeKinds as kinds, transform };
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { i as nodeKinds } from "./base-A-xF4pUL.js";
|
|
2
|
-
import { a as collect, s as transform } from "./visitor-
|
|
3
|
-
import { n as getNodeText } from "./index-
|
|
2
|
+
import { a as collect, s as transform } from "./visitor-BNGMMmpe.js";
|
|
3
|
+
import { n as getNodeText } from "./index-Br4bwEnS.js";
|
|
4
4
|
export { collect, getNodeText as getText, nodeKinds as kinds, transform };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
|
|
2
2
|
const require_constants = require("./constants-BCRkFAiy.cjs");
|
|
3
|
-
const
|
|
3
|
+
const require_combineFileMembers = require("./combineFileMembers-DmmuOmY8.cjs");
|
|
4
4
|
const require_optionality = require("./optionality-C-qULYxo.cjs");
|
|
5
5
|
const require_schema = require("./schema-0YJZqRXb.cjs");
|
|
6
6
|
// src/nodes/code.ts
|
|
@@ -13,7 +13,7 @@ const require_schema = require("./schema-0YJZqRXb.cjs");
|
|
|
13
13
|
* // export const pets: Pet[] = ... as const
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
|
-
const createConst =
|
|
16
|
+
const createConst = require_combineFileMembers.nodeFactory(require_constants.nodeKinds.const);
|
|
17
17
|
/**
|
|
18
18
|
* Creates a `TypeNode` representing a TypeScript `type` alias declaration.
|
|
19
19
|
*
|
|
@@ -23,7 +23,7 @@ const createConst = require_file.nodeFactory(require_constants.nodeKinds.const);
|
|
|
23
23
|
* // export type Pet = ...
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
const createType =
|
|
26
|
+
const createType = require_combineFileMembers.nodeFactory(require_constants.nodeKinds.type);
|
|
27
27
|
/**
|
|
28
28
|
* Creates a `FunctionNode` representing a TypeScript `function` declaration.
|
|
29
29
|
*
|
|
@@ -33,7 +33,7 @@ const createType = require_file.nodeFactory(require_constants.nodeKinds.type);
|
|
|
33
33
|
* // export async function fetchPet(): Promise<Pet> { ... }
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
const createFunction =
|
|
36
|
+
const createFunction = require_combineFileMembers.nodeFactory(require_constants.nodeKinds.function);
|
|
37
37
|
/**
|
|
38
38
|
* Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
|
|
39
39
|
*
|
|
@@ -43,7 +43,7 @@ const createFunction = require_file.nodeFactory(require_constants.nodeKinds.func
|
|
|
43
43
|
* // export const double = (n: number) => ...
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
const createArrowFunction =
|
|
46
|
+
const createArrowFunction = require_combineFileMembers.nodeFactory(require_constants.nodeKinds.arrowFunction);
|
|
47
47
|
/**
|
|
48
48
|
* Creates a {@link TextNode} representing a raw string fragment in the source output.
|
|
49
49
|
*
|
|
@@ -90,7 +90,7 @@ function createJsx(value) {
|
|
|
90
90
|
/**
|
|
91
91
|
* Creates a `ContentNode` for a single request-body or response content type.
|
|
92
92
|
*/
|
|
93
|
-
const createContent =
|
|
93
|
+
const createContent = require_combineFileMembers.nodeFactory(require_constants.nodeKinds.content);
|
|
94
94
|
// src/nodes/input.ts
|
|
95
95
|
/**
|
|
96
96
|
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to an empty
|
|
@@ -115,7 +115,7 @@ function createInput(overrides = {}) {
|
|
|
115
115
|
/**
|
|
116
116
|
* Creates a `RequestBodyNode`.
|
|
117
117
|
*/
|
|
118
|
-
const createRequestBody =
|
|
118
|
+
const createRequestBody = require_combineFileMembers.nodeFactory(require_constants.nodeKinds.requestBody);
|
|
119
119
|
// src/nodes/operation.ts
|
|
120
120
|
function createOperation(props) {
|
|
121
121
|
const { requestBody, ...rest } = props;
|
|
@@ -225,10 +225,10 @@ var nodes_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
|
225
225
|
createBreak: () => createBreak,
|
|
226
226
|
createConst: () => createConst,
|
|
227
227
|
createContent: () => createContent,
|
|
228
|
-
createExport: () =>
|
|
229
|
-
createFile: () =>
|
|
228
|
+
createExport: () => require_combineFileMembers.createExport,
|
|
229
|
+
createFile: () => require_combineFileMembers.createFile,
|
|
230
230
|
createFunction: () => createFunction,
|
|
231
|
-
createImport: () =>
|
|
231
|
+
createImport: () => require_combineFileMembers.createImport,
|
|
232
232
|
createInput: () => createInput,
|
|
233
233
|
createJsx: () => createJsx,
|
|
234
234
|
createOperation: () => createOperation,
|
|
@@ -238,7 +238,7 @@ var nodes_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
|
238
238
|
createRequestBody: () => createRequestBody,
|
|
239
239
|
createResponse: () => createResponse,
|
|
240
240
|
createSchema: () => require_schema.createSchema,
|
|
241
|
-
createSource: () =>
|
|
241
|
+
createSource: () => require_combineFileMembers.createSource,
|
|
242
242
|
createText: () => createText,
|
|
243
243
|
createType: () => createType
|
|
244
244
|
});
|
|
@@ -339,4 +339,4 @@ Object.defineProperty(exports, "nodes_exports", {
|
|
|
339
339
|
}
|
|
340
340
|
});
|
|
341
341
|
|
|
342
|
-
//# sourceMappingURL=nodes-
|
|
342
|
+
//# sourceMappingURL=nodes-TtDfZ9qf.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes-BdZfapPI.cjs","names":["nodeFactory","nodeKinds","nodeFactory","nodeKinds","nodeKinds","nodeFactory","nodeKinds","nodeKinds","applyOptionality","nodeKinds","applyOptionality","nodeKinds","nodeKinds"],"sources":["../src/nodes/code.ts","../src/nodes/content.ts","../src/nodes/input.ts","../src/nodes/requestBody.ts","../src/nodes/operation.ts","../src/nodes/parameter.ts","../src/nodes/property.ts","../src/nodes/response.ts","../src/nodes/index.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\n\n/**\n * JSDoc documentation metadata attached to code declarations.\n */\nexport type JSDocNode = {\n /**\n * JSDoc comment lines. `undefined` entries are filtered out during rendering.\n *\n * @example\n * ```ts\n * ['@description A pet resource', '@deprecated']\n * ```\n */\n comments?: Array<string | undefined>\n}\n\n/**\n * AST node representing a TypeScript `const` declaration.\n *\n * Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createConst({ name: 'pet', export: true, asConst: true })\n * // export const pet = ... as const\n * ```\n */\nexport type ConstNode = BaseNode & {\n kind: 'Const'\n /**\n * Name of the constant declaration.\n */\n name: string\n /**\n * Whether the declaration should be exported.\n */\n export?: boolean | null\n /**\n * Explicit type annotation.\n *\n * @example Type reference\n * `'Pet'`\n */\n type?: string | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Whether to append `as const` to the declaration.\n */\n asConst?: boolean | null\n /**\n * Child nodes representing the value of the constant (children of the `Const` component).\n * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript `type` alias declaration.\n *\n * Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createType({ name: 'Pet', export: true })\n * // export type Pet = ...\n * ```\n */\nexport type TypeNode = BaseNode & {\n kind: 'Type'\n /**\n * Name of the type alias.\n */\n name: string\n /**\n * Whether the declaration should be exported.\n */\n export?: boolean | null\n /**\n * How the declaration is written.\n * - `'type'` declares `type Name = …`\n * - `'interface'` declares `interface Name { … }`, so the body must be an object type\n *\n * @default 'type'\n */\n syntax?: 'type' | 'interface' | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Child nodes representing the type body (children of the `Type` component).\n * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript `function` declaration.\n *\n * Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createFunction({ name: 'getPet', export: true, async: true, returnType: 'Pet' })\n * // export async function getPet(): Promise<Pet> { ... }\n * ```\n */\nexport type FunctionNode = BaseNode & {\n kind: 'Function'\n /**\n * Name of the function.\n */\n name: string\n /**\n * Whether the function is a default export.\n */\n default?: boolean | null\n /**\n * Function parameter list as a pre-rendered string, written verbatim between the parentheses.\n *\n * @example\n * `'id: string, config: Config = {}'`\n */\n params?: string | null\n /**\n * Whether the function should be exported.\n */\n export?: boolean | null\n /**\n * Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.\n */\n async?: boolean | null\n /**\n * TypeScript generic type parameters.\n *\n * @example Constrained generics\n * `['T', 'U extends string']`\n */\n generics?: string | Array<string> | null\n /**\n * Return type annotation.\n *\n * @example Type reference\n * `'Pet'`\n */\n returnType?: string | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Child nodes representing the function body (children of the `Function` component).\n * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript arrow function (`const name = () => { ... }`).\n *\n * Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createArrowFunction({ name: 'getPet', export: true, singleLine: true })\n * // export const getPet = () => ...\n * ```\n */\nexport type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {\n kind: 'ArrowFunction'\n /**\n * Render the arrow function body as a single-line expression.\n */\n singleLine?: boolean | null\n}\n\n/**\n * AST node representing a raw text/string fragment in the source output.\n *\n * Used instead of bare `string` values so that all entries in `nodes` arrays\n * are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.\n *\n * @example\n * ```ts\n * createText('return fetch(id)')\n * // { kind: 'Text', value: 'return fetch(id)' }\n * ```\n */\nexport type TextNode = BaseNode & {\n kind: 'Text'\n /**\n * The raw string content.\n */\n value: string\n}\n\n/**\n * AST node representing a blank line in the source output.\n *\n * Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two\n * statements into one blank line. Consecutive breaks, and breaks at the start or end of\n * the list, are folded away, so a `Break` never produces more than one blank line.\n *\n * @example\n * ```ts\n * createBreak()\n * // { kind: 'Break' }\n * ```\n */\nexport type BreakNode = BaseNode & {\n kind: 'Break'\n}\n\n/**\n * AST node representing a raw JSX fragment in the source output.\n *\n * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup\n * (including fragments `<>…</>`) directly in generated code.\n *\n * @example\n * ```ts\n * createJsx('<>\\n <a href={href}>Open</a>\\n</>')\n * // { kind: 'Jsx', value: '<>\\n <a href={href}>Open</a>\\n</>' }\n * ```\n */\nexport type JsxNode = BaseNode & {\n kind: 'Jsx'\n /**\n * The raw JSX string content.\n */\n value: string\n}\n\n/**\n * Union of all code-generation AST nodes.\n *\n * These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as\n * structured children in {@link SourceNode.nodes}.\n */\nexport type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode\n\n/**\n * Creates a `ConstNode` representing a TypeScript `const` declaration.\n *\n * @example Exported constant with type and `as const`\n * ```ts\n * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })\n * // export const pets: Pet[] = ... as const\n * ```\n */\nexport const createConst = nodeFactory<ConstNode>(nodeKinds.const)\n\n/**\n * Creates a `TypeNode` representing a TypeScript `type` alias declaration.\n *\n * @example\n * ```ts\n * createType({ name: 'Pet', export: true })\n * // export type Pet = ...\n * ```\n */\nexport const createType = nodeFactory<TypeNode>(nodeKinds.type)\n\n/**\n * Creates a `FunctionNode` representing a TypeScript `function` declaration.\n *\n * @example\n * ```ts\n * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })\n * // export async function fetchPet(): Promise<Pet> { ... }\n * ```\n */\nexport const createFunction = nodeFactory<FunctionNode>(nodeKinds.function)\n\n/**\n * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.\n *\n * @example\n * ```ts\n * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })\n * // export const double = (n: number) => ...\n * ```\n */\nexport const createArrowFunction = nodeFactory<ArrowFunctionNode>(nodeKinds.arrowFunction)\n\n/**\n * Creates a {@link TextNode} representing a raw string fragment in the source output.\n *\n * @example\n * ```ts\n * createText('return fetch(id)')\n * // { kind: 'Text', value: 'return fetch(id)' }\n * ```\n */\nexport function createText(value: string): TextNode {\n return { kind: nodeKinds.text, value }\n}\n\n/**\n * Creates a {@link BreakNode} representing a line break in the source output.\n *\n * @example\n * ```ts\n * createBreak()\n * // { kind: 'Break' }\n * ```\n */\nexport function createBreak(): BreakNode {\n return { kind: nodeKinds.break }\n}\n\n/**\n * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.\n *\n * @example\n * ```ts\n * createJsx('<>\\n <a href={href}>Open</a>\\n</>')\n * // { kind: 'Jsx', value: '<>\\n <a href={href}>Open</a>\\n</>' }\n * ```\n */\nexport function createJsx(value: string): JsxNode {\n return { kind: nodeKinds.jsx, value }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\nimport type { ParameterStyle } from './parameter.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * How one body property is serialized, from the `encoding` entry of its media type.\n */\nexport type EncodingNode = {\n /**\n * Content type of the part, for example `'application/json'` for a multipart property.\n */\n contentType?: string\n /**\n * Serialization style of the property.\n */\n style?: ParameterStyle\n /**\n * Whether array and object values expand into separate values.\n */\n explode?: boolean\n /**\n * Whether reserved characters are sent as-is instead of percent-encoded.\n */\n allowReserved?: boolean\n encoding?: Record<string, EncodingNode>\n prefixEncoding?: Array<EncodingNode>\n itemEncoding?: EncodingNode\n}\n\nexport type ExampleNode = {\n name?: string\n summary?: string\n description?: string\n value?: unknown\n serializedValue?: string\n}\n\n/**\n * AST node representing one content-type entry of a request body or response.\n *\n * There is one entry per content type declared in the spec (e.g. `application/json`,\n * `multipart/form-data`), and each entry holds its own body schema.\n *\n * @example\n * ```ts\n * const content: ContentNode = {\n * kind: 'Content',\n * contentType: 'application/json',\n * schema: createSchema({ type: 'string' }),\n * }\n * ```\n */\nexport type ContentNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Content'\n /**\n * The content type for this entry (e.g. `'application/json'`), or `''` for a response without a body.\n */\n contentType: string\n /**\n * Body schema for this content type. For a stream it is the same node as `stream.schema`.\n */\n schema?: SchemaNode\n /**\n * Set when the content is a stream of items (an event stream, JSON Lines, a channel of messages) instead of one body.\n */\n stream?: {\n /**\n * Schema of one item, such as one event of `text/event-stream` or one line of JSON Lines.\n */\n schema?: SchemaNode\n /**\n * What `schema` describes for an event stream.\n * - `'event'` the parsed event with its `event`, `data`, `id` and `retry` fields\n * - `'data'` only the `data` payload, which the client wraps in its own event type\n */\n shape?: 'event' | 'data'\n }\n /**\n * Property keys to exclude from the generated type via `Omit<Type, Keys>`.\n * Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.\n */\n keysToOmit?: Array<string> | null\n /**\n * Serialization settings per body property that sets at least one field in the spec's `encoding`.\n */\n encoding?: Record<string, EncodingNode>\n examples?: Array<ExampleNode>\n /**\n * Serialization of the first parts by position, for a body sent as an array of parts such as `multipart/mixed`.\n */\n prefixEncoding?: Array<EncodingNode>\n /**\n * Serialization of every part after `prefixEncoding`, for a body sent as an array of parts such as `multipart/mixed`.\n */\n itemEncoding?: EncodingNode\n /** Vendor extensions (`x-*` keys) from the source media type, copied as-is. */\n extensions?: Record<string, unknown>\n}\n\n/**\n * Creates a `ContentNode` for a single request-body or response content type.\n */\nexport const createContent = nodeFactory<ContentNode>(nodeKinds.content)\n","import { nodeKinds } from '../constants.ts'\nimport type { BaseNode } from './base.ts'\nimport type { OperationNode } from './operation.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * A variable declared by a server URL template.\n */\nexport type InputServerVariable = {\n default?: string\n enum?: Array<string>\n description?: string\n}\n\n/**\n * A server from the source document, with `{variable}` placeholders filled from their defaults.\n */\nexport type InputServer = {\n url: string\n name?: string\n description?: string\n /**\n * Variables of the source URL template, copied as-is. `url` already has their defaults filled in, so\n * this tells a templated server apart from a literal one. Absent when the server declares none.\n */\n variables?: Record<string, InputServerVariable>\n}\n\nexport type ExternalDocs = { url: string; description?: string }\n\nexport type InputTag = {\n name: string\n summary?: string\n description?: string\n /**\n * Name of the tag this tag nests under. `group: { type: 'tag' }` places its files in the parent's folder.\n */\n parent?: string\n kind?: string\n externalDocs?: ExternalDocs\n}\n\nexport type OAuthFlow = {\n authorizationUrl?: string\n deviceAuthorizationUrl?: string\n tokenUrl?: string\n refreshUrl?: string\n scopes?: Record<string, string>\n}\n\n/**\n * How a client sends a credential, in the same shape as the `Auth` object the generated clients pass to `auth`.\n */\nexport type AuthCredential =\n | { type: 'http'; scheme: 'bearer' | 'basic' | (string & {}); bearerFormat?: string }\n | { type: 'apiKey'; in: 'header' | 'query' | 'cookie'; name: string }\n | { type: 'oauth2'; flows: Record<string, OAuthFlow>; metadataUrl?: string }\n | { type: 'openIdConnect'; url?: string }\n | { type: 'mutualTLS' }\n\n/**\n * One way to authenticate, keyed by `name`, which operations refer to in `auth`.\n */\nexport type AuthScheme = {\n name: string\n description?: string\n deprecated?: boolean\n credential: AuthCredential\n}\n\n/**\n * One way to meet an operation's auth. Every scheme in it applies together. `scopes` are the OAuth2 or OpenID\n * Connect scopes the call needs. An empty list means the call may be sent without credentials.\n */\nexport type AuthRequirement = Array<{ scheme: string; scopes?: Array<string> }>\n\n/**\n * Metadata for an API document, populated by the adapter and available to every generator.\n * Every field is a plain JSON value.\n *\n * @example\n * ```ts\n * const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://api.example.com/v2' }\n * ```\n */\nexport type InputMeta = {\n /**\n * API title from `info.title` in the source document.\n */\n title?: string\n /**\n * API description from `info.description` in the source document.\n */\n description?: string\n /**\n * API version string from `info.version` in the source document.\n */\n version?: string\n summary?: string\n termsOfService?: string\n contact?: { name?: string; url?: string; email?: string }\n license?: { name: string; identifier?: string; url?: string }\n externalDocs?: ExternalDocs\n /**\n * Resolved base URL from the first matching server entry in the source document.\n */\n baseURL?: string | null\n /**\n * The server index the adapter was configured with. A plugin uses it to pick the server at the same position in an\n * operation's or a path's own `servers`. It counts the source document's entries, including any without a URL.\n * Absent when the adapter was given no index.\n */\n serverIndex?: number\n servers?: Array<InputServer>\n tags?: Array<InputTag>\n auth?: Array<AuthScheme>\n /**\n * Vendor extensions (`x-*` keys) from the document root, copied as-is. Absent when the root has none.\n */\n extensions?: Record<string, unknown>\n}\n\n/**\n * Input AST node that contains all schemas and operations for one API document.\n * Produced by the adapter and consumed by all Kubb plugins.\n *\n * @example\n * ```ts\n * const input: InputNode = {\n * kind: 'Input',\n * schemas: [],\n * operations: [],\n * meta: {},\n * }\n * ```\n */\nexport type InputNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Input'\n /**\n * All schema nodes in the document.\n */\n schemas: Array<SchemaNode>\n /**\n * All operation nodes in the document.\n */\n operations: Array<OperationNode>\n /**\n * Document metadata populated by the adapter.\n */\n meta: InputMeta\n}\n\n/**\n * Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to an empty\n * object. Every call allocates fresh defaults so no two inputs share them.\n *\n * @example\n * ```ts\n * const input = createInput()\n * // { kind: 'Input', schemas: [], operations: [] }\n * ```\n */\nexport function createInput(overrides: Partial<Omit<InputNode, 'kind'>> = {}): InputNode {\n return { schemas: [], operations: [], meta: {}, ...overrides, kind: nodeKinds.input }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\nimport type { ContentNode } from './content.ts'\n\n/**\n * AST node representing an operation request body.\n *\n * Body schemas live exclusively inside the `content` array (one entry per content type),\n * mirroring {@link ResponseNode}.\n *\n * @example\n * ```ts\n * const requestBody: RequestBodyNode = {\n * kind: 'RequestBody',\n * required: true,\n * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],\n * }\n * ```\n */\nexport type RequestBodyNode = BaseNode & {\n kind: 'RequestBody'\n /**\n * Request body description carried over from the spec.\n */\n description?: string\n /**\n * Whether the request body is required (`requestBody.required: true` in the spec).\n * When `false` or absent, the generated `data` parameter should be optional.\n */\n required?: boolean\n /**\n * Content type entries for this request body.\n *\n * When the adapter `contentType` option is set, this array contains exactly one entry for\n * that content type. Otherwise it contains one entry per content type declared in the spec,\n * so plugins can generate code for every variant (for example, separate hooks for\n * `application/json` and `multipart/form-data`).\n */\n content?: Array<ContentNode>\n /** Vendor extensions (`x-*` keys) from the source request body, copied as-is. */\n extensions?: Record<string, unknown>\n}\n\n/**\n * Creates a `RequestBodyNode`.\n */\nexport const createRequestBody = nodeFactory<RequestBodyNode>(nodeKinds.requestBody)\n","import { nodeKinds } from '../constants.ts'\nimport type { BaseNode } from './base.ts'\nimport type { AuthRequirement, ExternalDocs, InputServer } from './input.ts'\nimport type { ParameterNode } from './parameter.ts'\nimport { createRequestBody, type RequestBodyNode } from './requestBody.ts'\nimport type { ResponseNode } from './response.ts'\n\n/**\n * HTTP method an operation responds to. `QUERY` is the safe, idempotent method with a request body\n * from RFC 10008, declared with the `query` field of an OpenAPI 3.2 path item. Any other name is a\n * method the source declares outside this fixed set, in the capitalization it is sent with.\n */\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'QUERY' | (string & {})\n\n/**\n * Fields shared by every operation, regardless of transport.\n */\ntype OperationNodeBase = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Operation'\n /**\n * Stable identifier for the operation.\n */\n operationId: string\n /**\n * Group labels for the operation.\n */\n tags: Array<string>\n /**\n * Short one-line operation summary.\n */\n summary?: string\n /**\n * Full operation description.\n */\n description?: string\n /**\n * Marks the operation as deprecated.\n */\n deprecated?: boolean\n externalDocs?: ExternalDocs\n /**\n * Query, path, header, and cookie parameters for the operation.\n */\n parameters: Array<ParameterNode>\n /**\n * Request body for the operation.\n */\n requestBody?: RequestBodyNode\n /**\n * Operation responses.\n */\n responses: Array<ResponseNode>\n /**\n * Vendor extensions (`x-*` keys) from the source operation, copied as-is. Absent when the source has none.\n */\n extensions?: Record<string, unknown>\n /** The operation's own `servers`, else its path item's, such as an upload host. Absent when neither declares any. */\n servers?: Array<InputServer>\n /**\n * Ways to authenticate, from the operation or else the document. Any one entry is enough. `[]` means no auth.\n */\n auth?: Array<AuthRequirement>\n}\n\n/**\n * Operation served over HTTP. `method` and `path` are guaranteed.\n *\n * @example\n * ```ts\n * const operation: HttpOperationNode = {\n * kind: 'Operation',\n * operationId: 'listPets',\n * protocol: 'http',\n * method: 'GET',\n * path: '/pets',\n * tags: [],\n * parameters: [],\n * responses: [],\n * }\n * ```\n */\nexport type HttpOperationNode = OperationNodeBase & {\n /**\n * Transport the operation belongs to.\n */\n protocol?: 'http'\n /**\n * HTTP method like `'GET'`.\n */\n method: HttpMethod\n /**\n * Path string, for example `/pets/{petId}`, with `{param}` notation preserved.\n */\n path: string\n}\n\n/**\n * Operation for a non-HTTP transport. HTTP-only fields are forbidden.\n */\nexport type GenericOperationNode = OperationNodeBase & {\n protocol?: never\n method?: never\n path?: never\n}\n\n/**\n * AST node representing one API operation.\n *\n * Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees\n * `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with\n * `ast.http.isOperation(node)` or `node.protocol === 'http'` before reading `method`/`path`.\n */\nexport type OperationNode = HttpOperationNode | GenericOperationNode\n\ntype OperationInput = {\n operationId: string\n method?: HttpOperationNode['method']\n path?: HttpOperationNode['path']\n requestBody?: Omit<RequestBodyNode, 'kind'>\n [key: string]: unknown\n}\n\n/**\n * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.\n * HTTP operations (those carrying both `method` and `path`) are tagged with `protocol: 'http'`,\n * and the request body is normalized into a `RequestBodyNode`.\n *\n * @example\n * ```ts\n * const operation = createOperation({ operationId: 'getPetById', method: 'GET', path: '/pet/{petId}' })\n * // tags, parameters, and responses are []\n * ```\n */\nexport function createOperation(\n props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> &\n Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {\n requestBody?: Omit<RequestBodyNode, 'kind'>\n },\n): HttpOperationNode\nexport function createOperation(\n props: Pick<GenericOperationNode, 'operationId'> &\n Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {\n requestBody?: Omit<RequestBodyNode, 'kind'>\n },\n): GenericOperationNode\nexport function createOperation(props: OperationInput): OperationNode {\n const { requestBody, ...rest } = props\n const isHttp = rest.method !== undefined && rest.path !== undefined\n\n const node = {\n tags: [],\n parameters: [],\n responses: [],\n ...rest,\n kind: nodeKinds.operation,\n ...(isHttp ? { protocol: 'http' as const } : {}),\n requestBody: requestBody ? createRequestBody(requestBody) : undefined,\n }\n\n return node as OperationNode\n}\n\n/**\n * The operations a plugin keeps, as one node. A template with `kind: 'Operations'` gets it once, after every operation.\n */\nexport type OperationsNode = BaseNode & {\n kind: 'Operations'\n operations: Array<OperationNode>\n}\n\n/**\n * Creates an `OperationsNode` for a list of operations.\n *\n * @example\n * ```ts\n * const node = createOperations({ operations: [listPets, getPetById] })\n * // { kind: 'Operations', operations: [...] }\n * ```\n */\nexport function createOperations({ operations }: { operations: Array<OperationNode> }): OperationsNode {\n return { kind: nodeKinds.operations, operations }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { applyOptionality } from '../optionality.ts'\nimport type { BaseNode } from './base.ts'\nimport type { EncodingNode, ExampleNode } from './content.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * Where a parameter is sent. `querystring` carries the whole query string as one value, serialized per `contentType`.\n */\nexport type ParameterLocation = 'path' | 'query' | 'header' | 'cookie' | 'querystring'\n\n/**\n * Parameter serialization style, controlling how a parameter value is rendered into the request.\n */\nexport type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject' | 'cookie'\n\n/**\n * AST node representing one operation parameter.\n *\n * @example\n * ```ts\n * const param: ParameterNode = {\n * kind: 'Parameter',\n * name: 'petId',\n * in: 'path',\n * schema: createSchema({ type: 'string' }),\n * required: true,\n * }\n * ```\n */\nexport type ParameterNode = BaseNode & {\n kind: 'Parameter'\n /**\n * Parameter name.\n */\n name: string\n /**\n * Parameter location (`path`, `query`, `header`, `cookie`, or `querystring`).\n */\n in: ParameterLocation\n /**\n * Parameter schema.\n */\n schema: SchemaNode\n /**\n * Whether the parameter is required.\n */\n required: boolean\n /**\n * Serialization style. Absent when the source omits it, leaving consumers to apply the\n * per-location default.\n */\n style?: ParameterStyle\n /**\n * Whether array and object values expand into separate values. Absent when the source omits it,\n * leaving consumers to apply the default for the style.\n */\n explode?: boolean\n /**\n * Whether reserved characters (RFC 3986 `:/?#[]@!$&'()*+,;=`) are sent as-is instead of\n * percent-encoded. Absent when the source omits it.\n */\n allowReserved?: boolean\n /**\n * Media type of a parameter described with `content` instead of `schema`, for example\n * `application/json` when the value is sent as a JSON-encoded string. Absent for `schema` parameters.\n */\n contentType?: string\n /**\n * Serialization settings per property of a `content` parameter, from the `encoding` of its media type. An OpenAPI 3.2\n * `querystring` parameter sent as `application/x-www-form-urlencoded` uses it to set `style` and `explode` per field.\n */\n encoding?: Record<string, EncodingNode>\n examples?: Array<ExampleNode>\n deprecated?: boolean\n allowEmptyValue?: boolean\n /** Vendor extensions (`x-*` keys) from the source parameter, copied as-is. */\n extensions?: Record<string, unknown>\n}\n\ntype UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>\n\n/**\n * Creates a `ParameterNode`. `required` defaults to `false`, and the schema's\n * `optional`/`nullish` flags are derived from it.\n *\n * @example\n * ```ts\n * const param = createParameter({\n * name: 'petId',\n * in: 'path',\n * required: true,\n * schema: createSchema({ type: 'string' }),\n * })\n * ```\n */\nexport function createParameter(input: UserParameterNode): ParameterNode {\n const required = input.required ?? false\n\n return { ...input, required, schema: applyOptionality(input.schema, required), kind: nodeKinds.parameter }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { applyOptionality } from '../optionality.ts'\nimport type { BaseNode } from './base.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * AST node representing one named object property.\n *\n * @example\n * ```ts\n * const property: PropertyNode = {\n * kind: 'Property',\n * name: 'id',\n * schema: createSchema({ type: 'integer' }),\n * required: true,\n * }\n * ```\n */\nexport type PropertyNode = BaseNode & {\n kind: 'Property'\n /**\n * Property key.\n */\n name: string\n /**\n * Property schema.\n */\n schema: SchemaNode\n /**\n * Whether the property is required.\n */\n required: boolean\n}\n\n/**\n * Loosely-typed property accepted by `createProperty`, with `required` optional.\n */\ntype UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>\n\n/**\n * Creates a `PropertyNode`. `required` defaults to `false`, and the schema's\n * `optional`/`nullish` flags are derived from it.\n *\n * @example\n * ```ts\n * const property = createProperty({\n * name: 'status',\n * required: true,\n * schema: createSchema({ type: 'string', nullable: true }),\n * })\n * // required=true, no optional/nullish\n * ```\n */\nexport function createProperty(input: UserPropertyNode): PropertyNode {\n const required = input.required ?? false\n\n return { ...input, required, schema: applyOptionality(input.schema, required), kind: nodeKinds.property }\n}\n","import { nodeKinds } from '../constants.ts'\nimport type { BaseNode } from './base.ts'\nimport { type ContentNode, createContent } from './content.ts'\nimport type { InputServer } from './input.ts'\nimport type { ParameterNode } from './parameter.ts'\nimport type { SchemaNode } from './schema.ts'\n\ntype Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n\n/**\n * Response status code literal used by operations.\n *\n * Includes three-digit HTTP status code strings, ranges such as `\"2xx\"`, and `\"default\"` for catch-all responses.\n *\n * @example\n * ```ts\n * const status: StatusCode = '200'\n * const fallback: StatusCode = 'default'\n * ```\n */\nexport type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | `${1 | 2 | 3 | 4 | 5}xx` | 'default'\n\n/**\n * AST node representing one operation response variant.\n *\n * Mirrors {@link OperationNode.requestBody}: the response body schemas live exclusively inside\n * the `content` array (one entry per content type), so the same schema is never duplicated at the\n * node root and inside `content`.\n *\n * @example\n * ```ts\n * const response: ResponseNode = {\n * kind: 'Response',\n * statusCode: '200',\n * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],\n * }\n * ```\n */\nexport type ResponseNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Response'\n /**\n * HTTP status code or `'default'` for a fallback response.\n */\n statusCode: StatusCode\n summary?: string\n /**\n * Optional response description.\n */\n description?: string\n /**\n * All available content type entries for this response.\n *\n * For a response that declares content, the array holds exactly one entry for the adapter\n * `contentType` option when it is set. Otherwise it holds one entry per content type declared in\n * the spec, so that plugins can generate a union of response types (e.g. `application/json` and\n * `application/xml`). A body-less response always keeps a single entry whose `contentType` is `''`\n * and whose `schema` is the empty/`void` placeholder, even when the option is set.\n *\n * @example\n * ```ts\n * // spec response declares both application/json and application/xml\n * response.content[0].contentType // 'application/json'\n * response.content[1].contentType // 'application/xml'\n * ```\n */\n content?: Array<ContentNode>\n /**\n * Response headers, as `in: 'header'` parameters. `Content-Type` is left out.\n */\n headers?: Array<ParameterNode>\n links?: Record<string, ResponseLink>\n /** Vendor extensions (`x-*` keys) from the source response, copied as-is. */\n extensions?: Record<string, unknown>\n}\n\n/**\n * A link to another operation. `parameters` and `requestBody` hold runtime expressions such as `$response.body#/id`.\n */\nexport type ResponseLink = {\n operationId?: string\n operationRef?: string\n parameters?: Record<string, unknown>\n requestBody?: unknown\n description?: string\n server?: InputServer\n}\n\ntype ResponseInput = Pick<ResponseNode, 'statusCode'> &\n Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {\n content?: Array<ContentNode>\n schema?: SchemaNode\n mediaType?: string | null\n keysToOmit?: Array<string> | null\n }\n\n/**\n * Creates a `ResponseNode`. A single legacy `schema` (with optional `mediaType`/`keysToOmit`)\n * is normalized into one `content` entry.\n *\n * @example\n * ```ts\n * const response = createResponse({\n * statusCode: '200',\n * content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })],\n * })\n * ```\n */\nexport function createResponse(props: ResponseInput): ResponseNode {\n const { schema, mediaType, keysToOmit, content, ...rest } = props\n const entries = content ?? (schema ? [createContent({ contentType: mediaType ?? 'application/json', schema, keysToOmit: keysToOmit ?? null })] : undefined)\n\n return { ...rest, content: entries, kind: nodeKinds.response }\n}\n","import type { ArrowFunctionNode, BreakNode, ConstNode, FunctionNode, JsxNode, TextNode, TypeNode } from './code.ts'\nimport type { ContentNode } from './content.ts'\nimport type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'\nimport type { InputNode } from './input.ts'\nimport type { OperationNode, OperationsNode } from './operation.ts'\nimport type { ParameterNode } from './parameter.ts'\nimport type { PropertyNode } from './property.ts'\nimport type { RequestBodyNode } from './requestBody.ts'\nimport type { ResponseNode } from './response.ts'\nimport type { SchemaNode } from './schema.ts'\n\nexport { createArrowFunction, createBreak, createConst, createFunction, createJsx, createText, createType } from './code.ts'\nexport { createContent } from './content.ts'\nexport { createExport, createFile, createImport, createSource } from './file.ts'\nexport type { ExportInput, ImportInput, ModuleName, Space, UserFileNode } from './file.ts'\nexport { createInput } from './input.ts'\nexport { createOperation, createOperations } from './operation.ts'\nexport { createParameter } from './parameter.ts'\nexport { createProperty } from './property.ts'\nexport { createRequestBody } from './requestBody.ts'\nexport { createResponse } from './response.ts'\nexport { createSchema } from './schema.ts'\n\n/**\n * Union of all AST node types.\n *\n * This lets TypeScript narrow types in `switch (node.kind)` blocks.\n *\n * @example\n * ```ts\n * function getKind(node: Node): string {\n * switch (node.kind) {\n * case nodeKinds.input:\n * return 'input'\n * default:\n * return 'other'\n * }\n * }\n * ```\n */\nexport type Node =\n | InputNode\n | OperationNode\n | OperationsNode\n | SchemaNode\n | PropertyNode\n | ParameterNode\n | ResponseNode\n | RequestBodyNode\n | ContentNode\n | FileNode\n | ImportNode\n | ExportNode\n | SourceNode\n | ConstNode\n | TypeNode\n | FunctionNode\n | ArrowFunctionNode\n | TextNode\n | BreakNode\n | JsxNode\n"],"mappings":";;;;;;;;;;;;;;;AAmQA,MAAa,cAAcA,aAAAA,YAAuBC,kBAAAA,UAAU,KAAK;;;;;;;;;;AAWjE,MAAa,aAAaD,aAAAA,YAAsBC,kBAAAA,UAAU,IAAI;;;;;;;;;;AAW9D,MAAa,iBAAiBD,aAAAA,YAA0BC,kBAAAA,UAAU,QAAQ;;;;;;;;;;AAW1E,MAAa,sBAAsBD,aAAAA,YAA+BC,kBAAAA,UAAU,aAAa;;;;;;;;;;AAWzF,SAAgB,WAAW,OAAyB;CAClD,OAAO;EAAE,MAAMA,kBAAAA,UAAU;EAAM;CAAM;AACvC;;;;;;;;;;AAWA,SAAgB,cAAyB;CACvC,OAAO,EAAE,MAAMA,kBAAAA,UAAU,MAAM;AACjC;;;;;;;;;;AAWA,SAAgB,UAAU,OAAwB;CAChD,OAAO;EAAE,MAAMA,kBAAAA,UAAU;EAAK;CAAM;AACtC;;;;;ACjOA,MAAa,gBAAgBC,aAAAA,YAAyBC,kBAAAA,UAAU,OAAO;;;;;;;;;;;;AC2DvE,SAAgB,YAAY,YAA8C,CAAC,GAAc;CACvF,OAAO;EAAE,SAAS,CAAC;EAAG,YAAY,CAAC;EAAG,MAAM,CAAC;EAAG,GAAG;EAAW,MAAMC,kBAAAA,UAAU;CAAM;AACtF;;;;;ACzHA,MAAa,oBAAoBC,aAAAA,YAA6BC,kBAAAA,UAAU,WAAW;;ACsGnF,SAAgB,gBAAgB,OAAsC;CACpE,MAAM,EAAE,aAAa,GAAG,SAAS;CACjC,MAAM,SAAS,KAAK,WAAW,KAAA,KAAa,KAAK,SAAS,KAAA;CAY1D,OAAO;EATL,MAAM,CAAC;EACP,YAAY,CAAC;EACb,WAAW,CAAC;EACZ,GAAG;EACH,MAAMC,kBAAAA,UAAU;EAChB,GAAI,SAAS,EAAE,UAAU,OAAgB,IAAI,CAAC;EAC9C,aAAa,cAAc,kBAAkB,WAAW,IAAI,KAAA;CAGpD;AACZ;;;;;;;;;;AAmBA,SAAgB,iBAAiB,EAAE,cAAoE;CACrG,OAAO;EAAE,MAAMA,kBAAAA,UAAU;EAAY;CAAW;AAClD;;;;;;;;;;;;;;;;ACxFA,SAAgB,gBAAgB,OAAyC;CACvE,MAAM,WAAW,MAAM,YAAY;CAEnC,OAAO;EAAE,GAAG;EAAO;EAAU,QAAQC,oBAAAA,iBAAiB,MAAM,QAAQ,QAAQ;EAAG,MAAMC,kBAAAA,UAAU;CAAU;AAC3G;;;;;;;;;;;;;;;;AC/CA,SAAgB,eAAe,OAAuC;CACpE,MAAM,WAAW,MAAM,YAAY;CAEnC,OAAO;EAAE,GAAG;EAAO;EAAU,QAAQC,oBAAAA,iBAAiB,MAAM,QAAQ,QAAQ;EAAG,MAAMC,kBAAAA,UAAU;CAAS;AAC1G;;;;;;;;;;;;;;ACqDA,SAAgB,eAAe,OAAoC;CACjE,MAAM,EAAE,QAAQ,WAAW,YAAY,SAAS,GAAG,SAAS;CAC5D,MAAM,UAAU,YAAY,SAAS,CAAC,cAAc;EAAE,aAAa,aAAa;EAAoB;EAAQ,YAAY,cAAc;CAAK,CAAC,CAAC,IAAI,KAAA;CAEjJ,OAAO;EAAE,GAAG;EAAM,SAAS;EAAS,MAAMC,kBAAAA,UAAU;CAAS;AAC/D"}
|
|
1
|
+
{"version":3,"file":"nodes-TtDfZ9qf.cjs","names":["nodeFactory","nodeKinds","nodeFactory","nodeKinds","nodeKinds","nodeFactory","nodeKinds","nodeKinds","applyOptionality","nodeKinds","applyOptionality","nodeKinds","nodeKinds"],"sources":["../src/nodes/code.ts","../src/nodes/content.ts","../src/nodes/input.ts","../src/nodes/requestBody.ts","../src/nodes/operation.ts","../src/nodes/parameter.ts","../src/nodes/property.ts","../src/nodes/response.ts","../src/nodes/index.ts"],"sourcesContent":["import { nodeKinds } from '../constants.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\n\n/**\n * JSDoc documentation metadata attached to code declarations.\n */\nexport type JSDocNode = {\n /**\n * JSDoc comment lines. `undefined` entries are filtered out during rendering.\n *\n * @example\n * ```ts\n * ['@description A pet resource', '@deprecated']\n * ```\n */\n comments?: Array<string | undefined>\n}\n\n/**\n * AST node representing a TypeScript `const` declaration.\n *\n * Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createConst({ name: 'pet', export: true, asConst: true })\n * // export const pet = ... as const\n * ```\n */\nexport type ConstNode = BaseNode & {\n kind: 'Const'\n /**\n * Name of the constant declaration.\n */\n name: string\n /**\n * Whether the declaration should be exported.\n */\n export?: boolean | null\n /**\n * Explicit type annotation.\n *\n * @example Type reference\n * `'Pet'`\n */\n type?: string | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Whether to append `as const` to the declaration.\n */\n asConst?: boolean | null\n /**\n * Child nodes representing the value of the constant (children of the `Const` component).\n * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript `type` alias declaration.\n *\n * Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createType({ name: 'Pet', export: true })\n * // export type Pet = ...\n * ```\n */\nexport type TypeNode = BaseNode & {\n kind: 'Type'\n /**\n * Name of the type alias.\n */\n name: string\n /**\n * Whether the declaration should be exported.\n */\n export?: boolean | null\n /**\n * How the declaration is written.\n * - `'type'` declares `type Name = …`\n * - `'interface'` declares `interface Name { … }`, so the body must be an object type\n *\n * @default 'type'\n */\n syntax?: 'type' | 'interface' | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Child nodes representing the type body (children of the `Type` component).\n * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript `function` declaration.\n *\n * Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createFunction({ name: 'getPet', export: true, async: true, returnType: 'Pet' })\n * // export async function getPet(): Promise<Pet> { ... }\n * ```\n */\nexport type FunctionNode = BaseNode & {\n kind: 'Function'\n /**\n * Name of the function.\n */\n name: string\n /**\n * Whether the function is a default export.\n */\n default?: boolean | null\n /**\n * Function parameter list as a pre-rendered string, written verbatim between the parentheses.\n *\n * @example\n * `'id: string, config: Config = {}'`\n */\n params?: string | null\n /**\n * Whether the function should be exported.\n */\n export?: boolean | null\n /**\n * Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.\n */\n async?: boolean | null\n /**\n * TypeScript generic type parameters.\n *\n * @example Constrained generics\n * `['T', 'U extends string']`\n */\n generics?: string | Array<string> | null\n /**\n * Return type annotation.\n *\n * @example Type reference\n * `'Pet'`\n */\n returnType?: string | null\n /**\n * JSDoc documentation metadata.\n */\n JSDoc?: JSDocNode | null\n /**\n * Child nodes representing the function body (children of the `Function` component).\n * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * AST node representing a TypeScript arrow function (`const name = () => { ... }`).\n *\n * Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.\n * The `children` prop of the component is represented as `nodes`.\n *\n * @example\n * ```ts\n * createArrowFunction({ name: 'getPet', export: true, singleLine: true })\n * // export const getPet = () => ...\n * ```\n */\nexport type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {\n kind: 'ArrowFunction'\n /**\n * Render the arrow function body as a single-line expression.\n */\n singleLine?: boolean | null\n}\n\n/**\n * AST node representing a raw text/string fragment in the source output.\n *\n * Used instead of bare `string` values so that all entries in `nodes` arrays\n * are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.\n *\n * @example\n * ```ts\n * createText('return fetch(id)')\n * // { kind: 'Text', value: 'return fetch(id)' }\n * ```\n */\nexport type TextNode = BaseNode & {\n kind: 'Text'\n /**\n * The raw string content.\n */\n value: string\n}\n\n/**\n * AST node representing a blank line in the source output.\n *\n * Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two\n * statements into one blank line. Consecutive breaks, and breaks at the start or end of\n * the list, are folded away, so a `Break` never produces more than one blank line.\n *\n * @example\n * ```ts\n * createBreak()\n * // { kind: 'Break' }\n * ```\n */\nexport type BreakNode = BaseNode & {\n kind: 'Break'\n}\n\n/**\n * AST node representing a raw JSX fragment in the source output.\n *\n * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup\n * (including fragments `<>…</>`) directly in generated code.\n *\n * @example\n * ```ts\n * createJsx('<>\\n <a href={href}>Open</a>\\n</>')\n * // { kind: 'Jsx', value: '<>\\n <a href={href}>Open</a>\\n</>' }\n * ```\n */\nexport type JsxNode = BaseNode & {\n kind: 'Jsx'\n /**\n * The raw JSX string content.\n */\n value: string\n}\n\n/**\n * Union of all code-generation AST nodes.\n *\n * These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as\n * structured children in {@link SourceNode.nodes}.\n */\nexport type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode\n\n/**\n * Creates a `ConstNode` representing a TypeScript `const` declaration.\n *\n * @example Exported constant with type and `as const`\n * ```ts\n * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })\n * // export const pets: Pet[] = ... as const\n * ```\n */\nexport const createConst = nodeFactory<ConstNode>(nodeKinds.const)\n\n/**\n * Creates a `TypeNode` representing a TypeScript `type` alias declaration.\n *\n * @example\n * ```ts\n * createType({ name: 'Pet', export: true })\n * // export type Pet = ...\n * ```\n */\nexport const createType = nodeFactory<TypeNode>(nodeKinds.type)\n\n/**\n * Creates a `FunctionNode` representing a TypeScript `function` declaration.\n *\n * @example\n * ```ts\n * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })\n * // export async function fetchPet(): Promise<Pet> { ... }\n * ```\n */\nexport const createFunction = nodeFactory<FunctionNode>(nodeKinds.function)\n\n/**\n * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.\n *\n * @example\n * ```ts\n * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })\n * // export const double = (n: number) => ...\n * ```\n */\nexport const createArrowFunction = nodeFactory<ArrowFunctionNode>(nodeKinds.arrowFunction)\n\n/**\n * Creates a {@link TextNode} representing a raw string fragment in the source output.\n *\n * @example\n * ```ts\n * createText('return fetch(id)')\n * // { kind: 'Text', value: 'return fetch(id)' }\n * ```\n */\nexport function createText(value: string): TextNode {\n return { kind: nodeKinds.text, value }\n}\n\n/**\n * Creates a {@link BreakNode} representing a line break in the source output.\n *\n * @example\n * ```ts\n * createBreak()\n * // { kind: 'Break' }\n * ```\n */\nexport function createBreak(): BreakNode {\n return { kind: nodeKinds.break }\n}\n\n/**\n * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.\n *\n * @example\n * ```ts\n * createJsx('<>\\n <a href={href}>Open</a>\\n</>')\n * // { kind: 'Jsx', value: '<>\\n <a href={href}>Open</a>\\n</>' }\n * ```\n */\nexport function createJsx(value: string): JsxNode {\n return { kind: nodeKinds.jsx, value }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\nimport type { ParameterStyle } from './parameter.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * How one body property is serialized, from the `encoding` entry of its media type.\n */\nexport type EncodingNode = {\n /**\n * Content type of the part, for example `'application/json'` for a multipart property.\n */\n contentType?: string\n /**\n * Serialization style of the property.\n */\n style?: ParameterStyle\n /**\n * Whether array and object values expand into separate values.\n */\n explode?: boolean\n /**\n * Whether reserved characters are sent as-is instead of percent-encoded.\n */\n allowReserved?: boolean\n encoding?: Record<string, EncodingNode>\n prefixEncoding?: Array<EncodingNode>\n itemEncoding?: EncodingNode\n}\n\nexport type ExampleNode = {\n name?: string\n summary?: string\n description?: string\n value?: unknown\n serializedValue?: string\n}\n\n/**\n * AST node representing one content-type entry of a request body or response.\n *\n * There is one entry per content type declared in the spec (e.g. `application/json`,\n * `multipart/form-data`), and each entry holds its own body schema.\n *\n * @example\n * ```ts\n * const content: ContentNode = {\n * kind: 'Content',\n * contentType: 'application/json',\n * schema: createSchema({ type: 'string' }),\n * }\n * ```\n */\nexport type ContentNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Content'\n /**\n * The content type for this entry (e.g. `'application/json'`), or `''` for a response without a body.\n */\n contentType: string\n /**\n * Body schema for this content type. For a stream it is the same node as `stream.schema`.\n */\n schema?: SchemaNode\n /**\n * Set when the content is a stream of items (an event stream, JSON Lines, a channel of messages) instead of one body.\n */\n stream?: {\n /**\n * Schema of one item, such as one event of `text/event-stream` or one line of JSON Lines.\n */\n schema?: SchemaNode\n /**\n * What `schema` describes for an event stream.\n * - `'event'` the parsed event with its `event`, `data`, `id` and `retry` fields\n * - `'data'` only the `data` payload, which the client wraps in its own event type\n */\n shape?: 'event' | 'data'\n }\n /**\n * Property keys to exclude from the generated type via `Omit<Type, Keys>`.\n * Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.\n */\n keysToOmit?: Array<string> | null\n /**\n * Serialization settings per body property that sets at least one field in the spec's `encoding`.\n */\n encoding?: Record<string, EncodingNode>\n examples?: Array<ExampleNode>\n /**\n * Serialization of the first parts by position, for a body sent as an array of parts such as `multipart/mixed`.\n */\n prefixEncoding?: Array<EncodingNode>\n /**\n * Serialization of every part after `prefixEncoding`, for a body sent as an array of parts such as `multipart/mixed`.\n */\n itemEncoding?: EncodingNode\n /** Vendor extensions (`x-*` keys) from the source media type, copied as-is. */\n extensions?: Record<string, unknown>\n}\n\n/**\n * Creates a `ContentNode` for a single request-body or response content type.\n */\nexport const createContent = nodeFactory<ContentNode>(nodeKinds.content)\n","import { nodeKinds } from '../constants.ts'\nimport type { BaseNode } from './base.ts'\nimport type { OperationNode } from './operation.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * A variable declared by a server URL template.\n */\nexport type InputServerVariable = {\n default?: string\n enum?: Array<string>\n description?: string\n}\n\n/**\n * A server from the source document, with `{variable}` placeholders filled from their defaults.\n */\nexport type InputServer = {\n url: string\n name?: string\n description?: string\n /**\n * Variables of the source URL template, copied as-is. `url` already has their defaults filled in, so\n * this tells a templated server apart from a literal one. Absent when the server declares none.\n */\n variables?: Record<string, InputServerVariable>\n}\n\nexport type ExternalDocs = { url: string; description?: string }\n\nexport type InputTag = {\n name: string\n summary?: string\n description?: string\n /**\n * Name of the tag this tag nests under. `group: { type: 'tag' }` places its files in the parent's folder.\n */\n parent?: string\n kind?: string\n externalDocs?: ExternalDocs\n}\n\nexport type OAuthFlow = {\n authorizationUrl?: string\n deviceAuthorizationUrl?: string\n tokenUrl?: string\n refreshUrl?: string\n scopes?: Record<string, string>\n}\n\n/**\n * How a client sends a credential, in the same shape as the `Auth` object the generated clients pass to `auth`.\n */\nexport type AuthCredential =\n | { type: 'http'; scheme: 'bearer' | 'basic' | (string & {}); bearerFormat?: string }\n | { type: 'apiKey'; in: 'header' | 'query' | 'cookie'; name: string }\n | { type: 'oauth2'; flows: Record<string, OAuthFlow>; metadataUrl?: string }\n | { type: 'openIdConnect'; url?: string }\n | { type: 'mutualTLS' }\n\n/**\n * One way to authenticate, keyed by `name`, which operations refer to in `auth`.\n */\nexport type AuthScheme = {\n name: string\n description?: string\n deprecated?: boolean\n credential: AuthCredential\n}\n\n/**\n * One way to meet an operation's auth. Every scheme in it applies together. `scopes` are the OAuth2 or OpenID\n * Connect scopes the call needs. An empty list means the call may be sent without credentials.\n */\nexport type AuthRequirement = Array<{ scheme: string; scopes?: Array<string> }>\n\n/**\n * Metadata for an API document, populated by the adapter and available to every generator.\n * Every field is a plain JSON value.\n *\n * @example\n * ```ts\n * const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://api.example.com/v2' }\n * ```\n */\nexport type InputMeta = {\n /**\n * API title from `info.title` in the source document.\n */\n title?: string\n /**\n * API description from `info.description` in the source document.\n */\n description?: string\n /**\n * API version string from `info.version` in the source document.\n */\n version?: string\n summary?: string\n termsOfService?: string\n contact?: { name?: string; url?: string; email?: string }\n license?: { name: string; identifier?: string; url?: string }\n externalDocs?: ExternalDocs\n /**\n * Resolved base URL from the first matching server entry in the source document.\n */\n baseURL?: string | null\n /**\n * The server index the adapter was configured with. A plugin uses it to pick the server at the same position in an\n * operation's or a path's own `servers`. It counts the source document's entries, including any without a URL.\n * Absent when the adapter was given no index.\n */\n serverIndex?: number\n servers?: Array<InputServer>\n tags?: Array<InputTag>\n auth?: Array<AuthScheme>\n /**\n * Vendor extensions (`x-*` keys) from the document root, copied as-is. Absent when the root has none.\n */\n extensions?: Record<string, unknown>\n}\n\n/**\n * Input AST node that contains all schemas and operations for one API document.\n * Produced by the adapter and consumed by all Kubb plugins.\n *\n * @example\n * ```ts\n * const input: InputNode = {\n * kind: 'Input',\n * schemas: [],\n * operations: [],\n * meta: {},\n * }\n * ```\n */\nexport type InputNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Input'\n /**\n * All schema nodes in the document.\n */\n schemas: Array<SchemaNode>\n /**\n * All operation nodes in the document.\n */\n operations: Array<OperationNode>\n /**\n * Document metadata populated by the adapter.\n */\n meta: InputMeta\n}\n\n/**\n * Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to an empty\n * object. Every call allocates fresh defaults so no two inputs share them.\n *\n * @example\n * ```ts\n * const input = createInput()\n * // { kind: 'Input', schemas: [], operations: [] }\n * ```\n */\nexport function createInput(overrides: Partial<Omit<InputNode, 'kind'>> = {}): InputNode {\n return { schemas: [], operations: [], meta: {}, ...overrides, kind: nodeKinds.input }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\nimport type { ContentNode } from './content.ts'\n\n/**\n * AST node representing an operation request body.\n *\n * Body schemas live exclusively inside the `content` array (one entry per content type),\n * mirroring {@link ResponseNode}.\n *\n * @example\n * ```ts\n * const requestBody: RequestBodyNode = {\n * kind: 'RequestBody',\n * required: true,\n * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],\n * }\n * ```\n */\nexport type RequestBodyNode = BaseNode & {\n kind: 'RequestBody'\n /**\n * Request body description carried over from the spec.\n */\n description?: string\n /**\n * Whether the request body is required (`requestBody.required: true` in the spec).\n * When `false` or absent, the generated `data` parameter should be optional.\n */\n required?: boolean\n /**\n * Content type entries for this request body.\n *\n * When the adapter `contentType` option is set, this array contains exactly one entry for\n * that content type. Otherwise it contains one entry per content type declared in the spec,\n * so plugins can generate code for every variant (for example, separate hooks for\n * `application/json` and `multipart/form-data`).\n */\n content?: Array<ContentNode>\n /** Vendor extensions (`x-*` keys) from the source request body, copied as-is. */\n extensions?: Record<string, unknown>\n}\n\n/**\n * Creates a `RequestBodyNode`.\n */\nexport const createRequestBody = nodeFactory<RequestBodyNode>(nodeKinds.requestBody)\n","import { nodeKinds } from '../constants.ts'\nimport type { BaseNode } from './base.ts'\nimport type { AuthRequirement, ExternalDocs, InputServer } from './input.ts'\nimport type { ParameterNode } from './parameter.ts'\nimport { createRequestBody, type RequestBodyNode } from './requestBody.ts'\nimport type { ResponseNode } from './response.ts'\n\n/**\n * HTTP method an operation responds to. `QUERY` is the safe, idempotent method with a request body\n * from RFC 10008, declared with the `query` field of an OpenAPI 3.2 path item. Any other name is a\n * method the source declares outside this fixed set, in the capitalization it is sent with.\n */\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'QUERY' | (string & {})\n\n/**\n * Fields shared by every operation, regardless of transport.\n */\nexport type OperationNodeBase = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Operation'\n /**\n * Stable identifier for the operation.\n */\n operationId: string\n /**\n * Group labels for the operation.\n */\n tags: Array<string>\n /**\n * Short one-line operation summary.\n */\n summary?: string\n /**\n * Full operation description.\n */\n description?: string\n /**\n * Marks the operation as deprecated.\n */\n deprecated?: boolean\n externalDocs?: ExternalDocs\n /**\n * Query, path, header, and cookie parameters for the operation.\n */\n parameters: Array<ParameterNode>\n /**\n * Request body for the operation.\n */\n requestBody?: RequestBodyNode\n /**\n * Operation responses.\n */\n responses: Array<ResponseNode>\n /**\n * Vendor extensions (`x-*` keys) from the source operation, copied as-is. Absent when the source has none.\n */\n extensions?: Record<string, unknown>\n /** The operation's own `servers`, else its path item's, such as an upload host. Absent when neither declares any. */\n servers?: Array<InputServer>\n /**\n * Ways to authenticate, from the operation or else the document. Any one entry is enough. `[]` means no auth.\n */\n auth?: Array<AuthRequirement>\n}\n\n/**\n * Operation served over HTTP. `method` and `path` are guaranteed.\n *\n * @example\n * ```ts\n * const operation: HttpOperationNode = {\n * kind: 'Operation',\n * operationId: 'listPets',\n * protocol: 'http',\n * method: 'GET',\n * path: '/pets',\n * tags: [],\n * parameters: [],\n * responses: [],\n * }\n * ```\n */\nexport type HttpOperationNode = OperationNodeBase & {\n /**\n * Transport the operation belongs to.\n */\n protocol?: 'http'\n /**\n * HTTP method like `'GET'`.\n */\n method: HttpMethod\n /**\n * Path string, for example `/pets/{petId}`, with `{param}` notation preserved.\n */\n path: string\n}\n\n/**\n * Operation for a non-HTTP transport. HTTP-only fields are forbidden.\n */\nexport type GenericOperationNode = OperationNodeBase & {\n protocol?: never\n method?: never\n path?: never\n}\n\n/**\n * AST node representing one API operation.\n *\n * Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees\n * `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with\n * `ast.http.isOperation(node)` or `node.protocol === 'http'` before reading `method`/`path`.\n */\nexport type OperationNode = HttpOperationNode | GenericOperationNode\n\nexport type OperationInput = {\n operationId: string\n method?: HttpOperationNode['method']\n path?: HttpOperationNode['path']\n requestBody?: Omit<RequestBodyNode, 'kind'>\n [key: string]: unknown\n}\n\n/**\n * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.\n * HTTP operations (those carrying both `method` and `path`) are tagged with `protocol: 'http'`,\n * and the request body is normalized into a `RequestBodyNode`.\n *\n * @example\n * ```ts\n * const operation = createOperation({ operationId: 'getPetById', method: 'GET', path: '/pet/{petId}' })\n * // tags, parameters, and responses are []\n * ```\n */\nexport function createOperation(\n props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> &\n Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {\n requestBody?: Omit<RequestBodyNode, 'kind'>\n },\n): HttpOperationNode\nexport function createOperation(\n props: Pick<GenericOperationNode, 'operationId'> &\n Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {\n requestBody?: Omit<RequestBodyNode, 'kind'>\n },\n): GenericOperationNode\nexport function createOperation(props: OperationInput): OperationNode {\n const { requestBody, ...rest } = props\n const isHttp = rest.method !== undefined && rest.path !== undefined\n\n const node = {\n tags: [],\n parameters: [],\n responses: [],\n ...rest,\n kind: nodeKinds.operation,\n ...(isHttp ? { protocol: 'http' as const } : {}),\n requestBody: requestBody ? createRequestBody(requestBody) : undefined,\n }\n\n return node as OperationNode\n}\n\n/**\n * The operations a plugin keeps, as one node. A template with `kind: 'Operations'` gets it once, after every operation.\n */\nexport type OperationsNode = BaseNode & {\n kind: 'Operations'\n operations: Array<OperationNode>\n}\n\n/**\n * Creates an `OperationsNode` for a list of operations.\n *\n * @example\n * ```ts\n * const node = createOperations({ operations: [listPets, getPetById] })\n * // { kind: 'Operations', operations: [...] }\n * ```\n */\nexport function createOperations({ operations }: { operations: Array<OperationNode> }): OperationsNode {\n return { kind: nodeKinds.operations, operations }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { applyOptionality } from '../optionality.ts'\nimport type { BaseNode } from './base.ts'\nimport type { EncodingNode, ExampleNode } from './content.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * Where a parameter is sent. `querystring` carries the whole query string as one value, serialized per `contentType`.\n */\nexport type ParameterLocation = 'path' | 'query' | 'header' | 'cookie' | 'querystring'\n\n/**\n * Parameter serialization style, controlling how a parameter value is rendered into the request.\n */\nexport type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject' | 'cookie'\n\n/**\n * AST node representing one operation parameter.\n *\n * @example\n * ```ts\n * const param: ParameterNode = {\n * kind: 'Parameter',\n * name: 'petId',\n * in: 'path',\n * schema: createSchema({ type: 'string' }),\n * required: true,\n * }\n * ```\n */\nexport type ParameterNode = BaseNode & {\n kind: 'Parameter'\n /**\n * Parameter name.\n */\n name: string\n /**\n * Parameter location (`path`, `query`, `header`, `cookie`, or `querystring`).\n */\n in: ParameterLocation\n /**\n * Parameter schema.\n */\n schema: SchemaNode\n /**\n * Whether the parameter is required.\n */\n required: boolean\n /**\n * Serialization style. Absent when the source omits it, leaving consumers to apply the\n * per-location default.\n */\n style?: ParameterStyle\n /**\n * Whether array and object values expand into separate values. Absent when the source omits it,\n * leaving consumers to apply the default for the style.\n */\n explode?: boolean\n /**\n * Whether reserved characters (RFC 3986 `:/?#[]@!$&'()*+,;=`) are sent as-is instead of\n * percent-encoded. Absent when the source omits it.\n */\n allowReserved?: boolean\n /**\n * Media type of a parameter described with `content` instead of `schema`, for example\n * `application/json` when the value is sent as a JSON-encoded string. Absent for `schema` parameters.\n */\n contentType?: string\n /**\n * Serialization settings per property of a `content` parameter, from the `encoding` of its media type. An OpenAPI 3.2\n * `querystring` parameter sent as `application/x-www-form-urlencoded` uses it to set `style` and `explode` per field.\n */\n encoding?: Record<string, EncodingNode>\n examples?: Array<ExampleNode>\n deprecated?: boolean\n allowEmptyValue?: boolean\n /** Vendor extensions (`x-*` keys) from the source parameter, copied as-is. */\n extensions?: Record<string, unknown>\n}\n\nexport type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>\n\n/**\n * Creates a `ParameterNode`. `required` defaults to `false`, and the schema's\n * `optional`/`nullish` flags are derived from it.\n *\n * @example\n * ```ts\n * const param = createParameter({\n * name: 'petId',\n * in: 'path',\n * required: true,\n * schema: createSchema({ type: 'string' }),\n * })\n * ```\n */\nexport function createParameter(input: UserParameterNode): ParameterNode {\n const required = input.required ?? false\n\n return { ...input, required, schema: applyOptionality(input.schema, required), kind: nodeKinds.parameter }\n}\n","import { nodeKinds } from '../constants.ts'\nimport { applyOptionality } from '../optionality.ts'\nimport type { BaseNode } from './base.ts'\nimport type { SchemaNode } from './schema.ts'\n\n/**\n * AST node representing one named object property.\n *\n * @example\n * ```ts\n * const property: PropertyNode = {\n * kind: 'Property',\n * name: 'id',\n * schema: createSchema({ type: 'integer' }),\n * required: true,\n * }\n * ```\n */\nexport type PropertyNode = BaseNode & {\n kind: 'Property'\n /**\n * Property key.\n */\n name: string\n /**\n * Property schema.\n */\n schema: SchemaNode\n /**\n * Whether the property is required.\n */\n required: boolean\n}\n\n/**\n * Loosely-typed property accepted by `createProperty`, with `required` optional.\n */\nexport type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>\n\n/**\n * Creates a `PropertyNode`. `required` defaults to `false`, and the schema's\n * `optional`/`nullish` flags are derived from it.\n *\n * @example\n * ```ts\n * const property = createProperty({\n * name: 'status',\n * required: true,\n * schema: createSchema({ type: 'string', nullable: true }),\n * })\n * // required=true, no optional/nullish\n * ```\n */\nexport function createProperty(input: UserPropertyNode): PropertyNode {\n const required = input.required ?? false\n\n return { ...input, required, schema: applyOptionality(input.schema, required), kind: nodeKinds.property }\n}\n","import { nodeKinds } from '../constants.ts'\nimport type { BaseNode } from './base.ts'\nimport { type ContentNode, createContent } from './content.ts'\nimport type { InputServer } from './input.ts'\nimport type { ParameterNode } from './parameter.ts'\nimport type { SchemaNode } from './schema.ts'\n\nexport type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n\n/**\n * Response status code literal used by operations.\n *\n * Includes three-digit HTTP status code strings, ranges such as `\"2xx\"`, and `\"default\"` for catch-all responses.\n *\n * @example\n * ```ts\n * const status: StatusCode = '200'\n * const fallback: StatusCode = 'default'\n * ```\n */\nexport type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | `${1 | 2 | 3 | 4 | 5}xx` | 'default'\n\n/**\n * AST node representing one operation response variant.\n *\n * Mirrors {@link OperationNode.requestBody}: the response body schemas live exclusively inside\n * the `content` array (one entry per content type), so the same schema is never duplicated at the\n * node root and inside `content`.\n *\n * @example\n * ```ts\n * const response: ResponseNode = {\n * kind: 'Response',\n * statusCode: '200',\n * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],\n * }\n * ```\n */\nexport type ResponseNode = BaseNode & {\n /**\n * Node kind.\n */\n kind: 'Response'\n /**\n * HTTP status code or `'default'` for a fallback response.\n */\n statusCode: StatusCode\n summary?: string\n /**\n * Optional response description.\n */\n description?: string\n /**\n * All available content type entries for this response.\n *\n * For a response that declares content, the array holds exactly one entry for the adapter\n * `contentType` option when it is set. Otherwise it holds one entry per content type declared in\n * the spec, so that plugins can generate a union of response types (e.g. `application/json` and\n * `application/xml`). A body-less response always keeps a single entry whose `contentType` is `''`\n * and whose `schema` is the empty/`void` placeholder, even when the option is set.\n *\n * @example\n * ```ts\n * // spec response declares both application/json and application/xml\n * response.content[0].contentType // 'application/json'\n * response.content[1].contentType // 'application/xml'\n * ```\n */\n content?: Array<ContentNode>\n /**\n * Response headers, as `in: 'header'` parameters. `Content-Type` is left out.\n */\n headers?: Array<ParameterNode>\n links?: Record<string, ResponseLink>\n /** Vendor extensions (`x-*` keys) from the source response, copied as-is. */\n extensions?: Record<string, unknown>\n}\n\n/**\n * A link to another operation. `parameters` and `requestBody` hold runtime expressions such as `$response.body#/id`.\n */\nexport type ResponseLink = {\n operationId?: string\n operationRef?: string\n parameters?: Record<string, unknown>\n requestBody?: unknown\n description?: string\n server?: InputServer\n}\n\nexport type ResponseInput = Pick<ResponseNode, 'statusCode'> &\n Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {\n content?: Array<ContentNode>\n schema?: SchemaNode\n mediaType?: string | null\n keysToOmit?: Array<string> | null\n }\n\n/**\n * Creates a `ResponseNode`. A single legacy `schema` (with optional `mediaType`/`keysToOmit`)\n * is normalized into one `content` entry.\n *\n * @example\n * ```ts\n * const response = createResponse({\n * statusCode: '200',\n * content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })],\n * })\n * ```\n */\nexport function createResponse(props: ResponseInput): ResponseNode {\n const { schema, mediaType, keysToOmit, content, ...rest } = props\n const entries = content ?? (schema ? [createContent({ contentType: mediaType ?? 'application/json', schema, keysToOmit: keysToOmit ?? null })] : undefined)\n\n return { ...rest, content: entries, kind: nodeKinds.response }\n}\n","import type { ArrowFunctionNode, BreakNode, ConstNode, FunctionNode, JsxNode, TextNode, TypeNode } from './code.ts'\nimport type { ContentNode } from './content.ts'\nimport type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'\nimport type { InputNode } from './input.ts'\nimport type { OperationNode, OperationsNode } from './operation.ts'\nimport type { ParameterNode } from './parameter.ts'\nimport type { PropertyNode } from './property.ts'\nimport type { RequestBodyNode } from './requestBody.ts'\nimport type { ResponseNode } from './response.ts'\nimport type { SchemaNode } from './schema.ts'\n\nexport { createArrowFunction, createBreak, createConst, createFunction, createJsx, createText, createType } from './code.ts'\nexport { createContent } from './content.ts'\nexport { createExport, createFile, createImport, createSource } from './file.ts'\nexport type { ExportInput, ImportInput, ModuleName, Space, UserFileNode } from './file.ts'\nexport { createInput } from './input.ts'\nexport { createOperation, createOperations } from './operation.ts'\nexport { createParameter } from './parameter.ts'\nexport { createProperty } from './property.ts'\nexport { createRequestBody } from './requestBody.ts'\nexport { createResponse } from './response.ts'\nexport { createSchema } from './schema.ts'\n\n/**\n * Union of all AST node types.\n *\n * This lets TypeScript narrow types in `switch (node.kind)` blocks.\n *\n * @example\n * ```ts\n * function getKind(node: Node): string {\n * switch (node.kind) {\n * case nodeKinds.input:\n * return 'input'\n * default:\n * return 'other'\n * }\n * }\n * ```\n */\nexport type Node =\n | InputNode\n | OperationNode\n | OperationsNode\n | SchemaNode\n | PropertyNode\n | ParameterNode\n | ResponseNode\n | RequestBodyNode\n | ContentNode\n | FileNode\n | ImportNode\n | ExportNode\n | SourceNode\n | ConstNode\n | TypeNode\n | FunctionNode\n | ArrowFunctionNode\n | TextNode\n | BreakNode\n | JsxNode\n"],"mappings":";;;;;;;;;;;;;;;AAmQA,MAAa,cAAcA,2BAAAA,YAAuBC,kBAAAA,UAAU,KAAK;;;;;;;;;;AAWjE,MAAa,aAAaD,2BAAAA,YAAsBC,kBAAAA,UAAU,IAAI;;;;;;;;;;AAW9D,MAAa,iBAAiBD,2BAAAA,YAA0BC,kBAAAA,UAAU,QAAQ;;;;;;;;;;AAW1E,MAAa,sBAAsBD,2BAAAA,YAA+BC,kBAAAA,UAAU,aAAa;;;;;;;;;;AAWzF,SAAgB,WAAW,OAAyB;CAClD,OAAO;EAAE,MAAMA,kBAAAA,UAAU;EAAM;CAAM;AACvC;;;;;;;;;;AAWA,SAAgB,cAAyB;CACvC,OAAO,EAAE,MAAMA,kBAAAA,UAAU,MAAM;AACjC;;;;;;;;;;AAWA,SAAgB,UAAU,OAAwB;CAChD,OAAO;EAAE,MAAMA,kBAAAA,UAAU;EAAK;CAAM;AACtC;;;;;ACjOA,MAAa,gBAAgBC,2BAAAA,YAAyBC,kBAAAA,UAAU,OAAO;;;;;;;;;;;;AC2DvE,SAAgB,YAAY,YAA8C,CAAC,GAAc;CACvF,OAAO;EAAE,SAAS,CAAC;EAAG,YAAY,CAAC;EAAG,MAAM,CAAC;EAAG,GAAG;EAAW,MAAMC,kBAAAA,UAAU;CAAM;AACtF;;;;;ACzHA,MAAa,oBAAoBC,2BAAAA,YAA6BC,kBAAAA,UAAU,WAAW;;ACsGnF,SAAgB,gBAAgB,OAAsC;CACpE,MAAM,EAAE,aAAa,GAAG,SAAS;CACjC,MAAM,SAAS,KAAK,WAAW,KAAA,KAAa,KAAK,SAAS,KAAA;CAY1D,OAAO;EATL,MAAM,CAAC;EACP,YAAY,CAAC;EACb,WAAW,CAAC;EACZ,GAAG;EACH,MAAMC,kBAAAA,UAAU;EAChB,GAAI,SAAS,EAAE,UAAU,OAAgB,IAAI,CAAC;EAC9C,aAAa,cAAc,kBAAkB,WAAW,IAAI,KAAA;CAGpD;AACZ;;;;;;;;;;AAmBA,SAAgB,iBAAiB,EAAE,cAAoE;CACrG,OAAO;EAAE,MAAMA,kBAAAA,UAAU;EAAY;CAAW;AAClD;;;;;;;;;;;;;;;;ACxFA,SAAgB,gBAAgB,OAAyC;CACvE,MAAM,WAAW,MAAM,YAAY;CAEnC,OAAO;EAAE,GAAG;EAAO;EAAU,QAAQC,oBAAAA,iBAAiB,MAAM,QAAQ,QAAQ;EAAG,MAAMC,kBAAAA,UAAU;CAAU;AAC3G;;;;;;;;;;;;;;;;AC/CA,SAAgB,eAAe,OAAuC;CACpE,MAAM,WAAW,MAAM,YAAY;CAEnC,OAAO;EAAE,GAAG;EAAO;EAAU,QAAQC,oBAAAA,iBAAiB,MAAM,QAAQ,QAAQ;EAAG,MAAMC,kBAAAA,UAAU;CAAS;AAC1G;;;;;;;;;;;;;;ACqDA,SAAgB,eAAe,OAAoC;CACjE,MAAM,EAAE,QAAQ,WAAW,YAAY,SAAS,GAAG,SAAS;CAC5D,MAAM,UAAU,YAAY,SAAS,CAAC,cAAc;EAAE,aAAa,aAAa;EAAoB;EAAQ,YAAY,cAAc;CAAK,CAAC,CAAC,IAAI,KAAA;CAEjJ,OAAO;EAAE,GAAG;EAAM,SAAS;EAAS,MAAMC,kBAAAA,UAAU;CAAS;AAC/D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BYyVTPww.js";
|
|
2
2
|
import { t as nodeKinds } from "./constants-UorsTFsa.js";
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as createSource, i as createImport, n as createExport, o as nodeFactory, r as createFile } from "./combineFileMembers-DJHNAZBN.js";
|
|
4
4
|
import { t as applyOptionality } from "./optionality-FkRredTC.js";
|
|
5
5
|
import { t as createSchema } from "./schema-CC008xgK.js";
|
|
6
6
|
// src/nodes/code.ts
|
|
@@ -244,4 +244,4 @@ var nodes_exports = /* @__PURE__ */ __exportAll({
|
|
|
244
244
|
});
|
|
245
245
|
export { createOperation as a, createInput as c, createBreak as d, createConst as f, createType as g, createText as h, createParameter as i, createContent as l, createJsx as m, createResponse as n, createOperations as o, createFunction as p, createProperty as r, createRequestBody as s, nodes_exports as t, createArrowFunction as u };
|
|
246
246
|
|
|
247
|
-
//# sourceMappingURL=nodes-
|
|
247
|
+
//# sourceMappingURL=nodes-u9i-tqFp.js.map
|