@kubb/ast 5.0.0-alpha.2 → 5.0.0-alpha.21
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/index.cjs +1032 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +275 -9
- package/dist/index.js +1009 -129
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/visitor-COwfCgLK.d.ts +1983 -0
- package/package.json +3 -2
- package/src/constants.ts +97 -4
- package/src/factory.ts +276 -18
- package/src/guards.ts +63 -8
- package/src/index.ts +32 -6
- package/src/infer.ts +130 -0
- package/src/mocks.ts +12 -5
- package/src/nodes/base.ts +31 -4
- package/src/nodes/function.ts +131 -0
- package/src/nodes/http.ts +17 -5
- package/src/nodes/index.ts +18 -5
- package/src/nodes/operation.ts +61 -4
- package/src/nodes/parameter.ts +27 -1
- package/src/nodes/property.ts +23 -1
- package/src/nodes/response.ts +29 -3
- package/src/nodes/root.ts +41 -10
- package/src/nodes/schema.ts +328 -38
- package/src/printers/functionPrinter.ts +196 -0
- package/src/printers/index.ts +3 -0
- package/src/printers/printer.ts +217 -0
- package/src/refs.ts +36 -4
- package/src/resolvers.ts +45 -0
- package/src/transformers.ts +196 -0
- package/src/types.ts +9 -2
- package/src/utils.ts +77 -0
- package/src/visitor.ts +376 -81
- package/dist/visitor-CmsfJzro.d.ts +0 -649
- package/src/printer.ts +0 -129
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/constants.ts","../src/factory.ts","../src/guards.ts","../src/printer.ts","../src/refs.ts","../src/visitor.ts"],"sourcesContent":["import type { NodeKind } from './nodes/base.ts'\nimport type { MediaType } from './nodes/http.ts'\nimport type { HttpMethod } from './nodes/operation.ts'\nimport type { ParameterLocation } from './nodes/parameter.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\n/**\n * Depth for schema traversal in visitor functions.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\nexport const visitorDepths = {\n shallow: 'shallow',\n deep: 'deep',\n} as const satisfies Record<VisitorDepth, VisitorDepth>\n\nexport const nodeKinds = {\n root: 'Root',\n operation: 'Operation',\n schema: 'Schema',\n property: 'Property',\n parameter: 'Parameter',\n response: 'Response',\n} as const satisfies Record<Lowercase<NodeKind>, NodeKind>\n\nexport const schemaTypes = {\n string: 'string',\n /**\n * Floating-point number (`float`, `double`).\n */\n number: 'number',\n /**\n * Whole number (`int32`). Use `bigint` for `int64`.\n */\n integer: 'integer',\n /**\n * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.\n */\n bigint: 'bigint',\n boolean: 'boolean',\n null: 'null',\n any: 'any',\n unknown: 'unknown',\n void: 'void',\n object: 'object',\n array: 'array',\n tuple: 'tuple',\n union: 'union',\n intersection: 'intersection',\n enum: 'enum',\n ref: 'ref',\n date: 'date',\n datetime: 'datetime',\n time: 'time',\n uuid: 'uuid',\n email: 'email',\n url: 'url',\n blob: 'blob',\n} as const satisfies Record<SchemaType, SchemaType>\n\nexport const httpMethods = {\n get: 'GET',\n post: 'POST',\n put: 'PUT',\n patch: 'PATCH',\n delete: 'DELETE',\n head: 'HEAD',\n options: 'OPTIONS',\n trace: 'TRACE',\n} as const satisfies Record<Lowercase<HttpMethod>, HttpMethod>\n\nexport const parameterLocations = {\n path: 'path',\n query: 'query',\n header: 'header',\n cookie: 'cookie',\n} as const satisfies Record<ParameterLocation, ParameterLocation>\n\n/**\n * Default max concurrent visitor calls in `walk`.\n */\nexport const WALK_CONCURRENCY = 30\n\n/**\n * Fallback status code string for API spec responses.\n */\nexport const DEFAULT_STATUS_CODE = 'default' as const\n\nexport const mediaTypes = {\n applicationJson: 'application/json',\n applicationXml: 'application/xml',\n applicationFormUrlEncoded: 'application/x-www-form-urlencoded',\n applicationOctetStream: 'application/octet-stream',\n applicationPdf: 'application/pdf',\n applicationZip: 'application/zip',\n applicationGraphql: 'application/graphql',\n multipartFormData: 'multipart/form-data',\n textPlain: 'text/plain',\n textHtml: 'text/html',\n textCsv: 'text/csv',\n textXml: 'text/xml',\n imagePng: 'image/png',\n imageJpeg: 'image/jpeg',\n imageGif: 'image/gif',\n imageWebp: 'image/webp',\n imageSvgXml: 'image/svg+xml',\n audioMpeg: 'audio/mpeg',\n videoMp4: 'video/mp4',\n} as const satisfies Record<string, MediaType>\n","import type { ObjectSchemaNode, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode } from './nodes/index.ts'\n\n/**\n * Distributive variant of `Omit` that preserves union members.\n */\nexport type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\n/**\n * Creates a `RootNode`.\n */\nexport function createRoot(overrides: Partial<Omit<RootNode, 'kind'>> = {}): RootNode {\n return {\n schemas: [],\n operations: [],\n ...overrides,\n kind: 'Root',\n }\n}\n\n/**\n * Creates an `OperationNode`.\n */\nexport function createOperation(\n props: Pick<OperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<OperationNode, 'kind' | 'operationId' | 'method' | 'path'>>,\n): OperationNode {\n return {\n tags: [],\n parameters: [],\n responses: [],\n ...props,\n kind: 'Operation',\n }\n}\n\n/**\n * Creates a `SchemaNode`, narrowed to the variant of `props.type`.\n * For object schemas, `properties` defaults to `[]` when not provided.\n */\nexport function createSchema<T extends Omit<ObjectSchemaNode, 'kind' | 'properties'> & { properties?: Array<PropertyNode> }>(\n props: T,\n): Omit<T, 'properties'> & { properties: Array<PropertyNode>; kind: 'Schema' }\nexport function createSchema<T extends DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>>(props: T): T & { kind: 'Schema' }\nexport function createSchema(props: DistributiveOmit<SchemaNode, 'kind'>): SchemaNode\nexport function createSchema(props: Record<string, unknown>): Record<string, unknown> {\n if (props['type'] === 'object') {\n return { properties: [], ...props, kind: 'Schema' }\n }\n\n return { ...props, kind: 'Schema' }\n}\n\n/**\n * Creates a `PropertyNode`. `required` defaults to `false`.\n */\nexport function createProperty(props: Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>): PropertyNode {\n return {\n required: false,\n ...props,\n kind: 'Property',\n }\n}\n\n/**\n * Creates a `ParameterNode`. `required` defaults to `false`.\n */\nexport function createParameter(\n props: Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>,\n): ParameterNode {\n return {\n required: false,\n ...props,\n kind: 'Parameter',\n }\n}\n\n/**\n * Creates a `ResponseNode`.\n */\nexport function createResponse(props: Pick<ResponseNode, 'statusCode'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode'>>): ResponseNode {\n return {\n ...props,\n kind: 'Response',\n }\n}\n","import type { Node, NodeKind, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode, SchemaNodeByType } from './nodes/index.ts'\n\n/**\n * Narrows a `SchemaNode` to the specific variant matching `type`.\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | undefined {\n return node?.type === type ? (node as SchemaNodeByType[T]) : undefined\n}\n\nfunction isKind<T extends Node>(kind: NodeKind) {\n return (node: unknown): node is T => (node as Node).kind === kind\n}\n\n/**\n * Type guard for `RootNode`.\n */\nexport const isRootNode = isKind<RootNode>('Root')\n\n/**\n * Type guard for `OperationNode`.\n */\nexport const isOperationNode = isKind<OperationNode>('Operation')\n\n/**\n * Type guard for `SchemaNode`.\n */\nexport const isSchemaNode = isKind<SchemaNode>('Schema')\n\n/**\n * Type guard for `PropertyNode`.\n */\nexport const isPropertyNode = isKind<PropertyNode>('Property')\n\n/**\n * Type guard for `ParameterNode`.\n */\nexport const isParameterNode = isKind<ParameterNode>('Parameter')\n\n/**\n * Type guard for `ResponseNode`.\n */\nexport const isResponseNode = isKind<ResponseNode>('Response')\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Handler context for `definePrinter` — mirrors `PluginContext` from `@kubb/core`.\n * Available as `this` inside each node handler.\n */\nexport type PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively print a nested `SchemaNode`.\n */\n print: (node: SchemaNode) => TOutput | null | undefined\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for a specific `SchemaNode` variant identified by `SchemaType` key `T`.\n * Use a regular function (not an arrow function) so that `this` is available.\n */\nexport type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null | undefined\n\n/**\n * Shape of the type parameter passed to `definePrinter`.\n * Mirrors `AdapterFactoryOptions` / `PluginFactoryOptions` from `@kubb/core`.\n *\n * - `TName` — unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` — options passed to and stored on the printer\n * - `TOutput` — the type emitted by `print` (typically `string`)\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown> = {\n name: TName\n options: TOptions\n output: TOutput\n}\n\n/**\n * The object returned by calling a `definePrinter` instance.\n * Mirrors the shape of `Adapter` from `@kubb/core`.\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 * Emits `TOutput` from a `SchemaNode`. Returns `null | undefined` when no handler matches.\n */\n print: (node: SchemaNode) => T['output'] | null | undefined\n /**\n * Maps `print` over an array of `SchemaNode`s.\n */\n for: (nodes: Array<SchemaNode>) => Array<T['output'] | null | undefined>\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: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n}\n\n/**\n * Creates a named printer factory. Mirrors the `definePlugin` / `defineAdapter` pattern\n * from `@kubb/core` — wraps a builder to make options optional and separates raw options\n * from resolved options.\n *\n * @example\n * ```ts\n * type ZodPrinter = PrinterFactoryOptions<'zod', { strict?: boolean }, { strict: boolean }, string>\n *\n * export const zodPrinter = definePrinter<ZodPrinter>((options) => {\n * const { strict = true } = options\n * return {\n * name: 'zod',\n * options: { strict },\n * nodes: {\n * string(node) {\n * return `z.string()`\n * },\n * object(node) {\n * const props = node.properties\n * ?.map(p => `${p.name}: ${this.print(p)}`)\n * .join(', ') ?? ''\n * return `z.object({ ${props} })`\n * },\n * },\n * }\n * })\n *\n * const printer = zodPrinter({ strict: false })\n * printer.name // 'zod'\n * printer.options // { strict: false }\n * printer.print(node) // 'z.string()'\n * ```\n */\nexport function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return (options) => {\n const { name, options: resolvedOptions, nodes } = build(options ?? ({} as T['options']))\n\n const context: PrinterHandlerContext<T['output'], T['options']> = {\n options: resolvedOptions,\n print: (node: SchemaNode) => {\n const type = node.type as SchemaType\n const handler = nodes[type]\n return handler ? (handler as PrinterHandler<T['output'], T['options']>).call(context, node as SchemaNodeByType[SchemaType]) : undefined\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n print: context.print,\n for: (nodes) => nodes.map(context.print),\n }\n }\n}\n","import type { RootNode } from './nodes/root.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\n\n/**\n * Schema name to `SchemaNode` mapping.\n */\nexport type RefMap = Map<string, SchemaNode>\n\n/**\n * Indexes named schemas from `root.schemas` by name. Unnamed schemas are skipped.\n */\nexport function buildRefMap(root: RootNode): RefMap {\n const map: RefMap = new Map()\n\n for (const schema of root.schemas) {\n if (schema.name) {\n map.set(schema.name, schema)\n }\n }\n return map\n}\n\n/**\n * Looks up a schema by name. Prefer over `RefMap.get()` to keep the resolution strategy swappable.\n */\nexport function resolveRef(refMap: RefMap, ref: string): SchemaNode | undefined {\n return refMap.get(ref)\n}\n\n/**\n * Converts a `RefMap` to a plain object.\n */\nexport function refMapToObject(refMap: RefMap): Record<string, SchemaNode> {\n return Object.fromEntries(refMap)\n}\n","import type { VisitorDepth } from './constants.ts'\nimport { visitorDepths, WALK_CONCURRENCY } from './constants.ts'\nimport type { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode } from './nodes/index.ts'\n\nfunction createLimit(concurrency: number) {\n let active = 0\n const queue: Array<() => void> = []\n\n function next() {\n if (active < concurrency && queue.length > 0) {\n active++\n queue.shift()!()\n }\n }\n\n return function limit<T>(fn: () => Promise<T> | T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n queue.push(() => {\n Promise.resolve(fn())\n .then(resolve, reject)\n .finally(() => {\n active--\n next()\n })\n })\n next()\n })\n }\n}\n\ntype LimitFn = ReturnType<typeof createLimit>\n\n/**\n * Shared options for `walk`, `transform`, and `collect`.\n */\nexport type VisitorOptions = {\n depth?: VisitorDepth\n /**\n * Maximum number of sibling nodes visited concurrently inside `walk`.\n * @default 30\n */\n concurrency?: number\n}\n\n/**\n * Synchronous visitor for `transform` and `walk`.\n */\nexport type Visitor = {\n root?(node: RootNode): void | RootNode\n operation?(node: OperationNode): void | OperationNode\n schema?(node: SchemaNode): void | SchemaNode\n property?(node: PropertyNode): void | PropertyNode\n parameter?(node: ParameterNode): void | ParameterNode\n response?(node: ResponseNode): void | ResponseNode\n}\n\ntype MaybePromise<T> = T | Promise<T>\n\n/**\n * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.\n */\nexport type AsyncVisitor = {\n root?(node: RootNode): MaybePromise<void | RootNode>\n operation?(node: OperationNode): MaybePromise<void | OperationNode>\n schema?(node: SchemaNode): MaybePromise<void | SchemaNode>\n property?(node: PropertyNode): MaybePromise<void | PropertyNode>\n parameter?(node: ParameterNode): MaybePromise<void | ParameterNode>\n response?(node: ResponseNode): MaybePromise<void | ResponseNode>\n}\n\n/**\n * Visitor for `collect`.\n */\nexport type CollectVisitor<T> = {\n root?(node: RootNode): T | undefined\n operation?(node: OperationNode): T | undefined\n schema?(node: SchemaNode): T | undefined\n property?(node: PropertyNode): T | undefined\n parameter?(node: ParameterNode): T | undefined\n response?(node: ResponseNode): T | undefined\n}\n\n/**\n * Traversable children of `node`, respecting `recurse` for schema nodes.\n */\nfunction getChildren(node: Node, recurse: boolean): Array<Node> {\n switch (node.kind) {\n case 'Root':\n return [...node.schemas, ...node.operations]\n case 'Operation':\n return [...node.parameters, ...(node.requestBody ? [node.requestBody] : []), ...node.responses]\n case 'Schema': {\n const children: Array<Node> = []\n\n if (!recurse) return []\n\n if ('properties' in node && node.properties.length > 0) children.push(...node.properties)\n if ('items' in node && node.items) children.push(...node.items)\n if ('members' in node && node.members) children.push(...node.members)\n\n return children\n }\n case 'Property':\n return [node.schema]\n case 'Parameter':\n return [node.schema]\n case 'Response':\n return node.schema ? [node.schema] : []\n }\n}\n\n/**\n * Depth-first traversal for side effects. Visitor return values are ignored.\n * Sibling nodes at each level are visited concurrently up to `options.concurrency` (default: 30).\n */\nexport async function walk(node: Node, visitor: AsyncVisitor, options: VisitorOptions = {}): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n const limit = createLimit(options.concurrency ?? WALK_CONCURRENCY)\n return _walk(node, visitor, recurse, limit)\n}\n\nasync function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit: LimitFn): Promise<void> {\n switch (node.kind) {\n case 'Root':\n await limit(() => visitor.root?.(node))\n break\n case 'Operation':\n await limit(() => visitor.operation?.(node))\n break\n case 'Schema':\n await limit(() => visitor.schema?.(node))\n break\n case 'Property':\n await limit(() => visitor.property?.(node))\n break\n case 'Parameter':\n await limit(() => visitor.parameter?.(node))\n break\n case 'Response':\n await limit(() => visitor.response?.(node))\n break\n }\n\n const children = getChildren(node, recurse)\n await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit)))\n}\n\n/**\n * Depth-first immutable transformation. Visitor return values replace nodes; `undefined` keeps the original.\n */\nexport function transform(node: RootNode, visitor: Visitor, options?: VisitorOptions): RootNode\nexport function transform(node: OperationNode, visitor: Visitor, options?: VisitorOptions): OperationNode\nexport function transform(node: SchemaNode, visitor: Visitor, options?: VisitorOptions): SchemaNode\nexport function transform(node: PropertyNode, visitor: Visitor, options?: VisitorOptions): PropertyNode\nexport function transform(node: ParameterNode, visitor: Visitor, options?: VisitorOptions): ParameterNode\nexport function transform(node: ResponseNode, visitor: Visitor, options?: VisitorOptions): ResponseNode\nexport function transform(node: Node, visitor: Visitor, options?: VisitorOptions): Node\nexport function transform(node: Node, visitor: Visitor, options: VisitorOptions = {}): Node {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n\n switch (node.kind) {\n case 'Root': {\n let root = node\n const replaced = visitor.root?.(root)\n if (replaced) root = replaced\n\n return {\n ...root,\n schemas: root.schemas.map((s) => transform(s, visitor, options)),\n operations: root.operations.map((op) => transform(op, visitor, options)),\n }\n }\n case 'Operation': {\n let op = node\n const replaced = visitor.operation?.(op)\n if (replaced) op = replaced\n\n return {\n ...op,\n parameters: op.parameters.map((p) => transform(p, visitor, options)),\n requestBody: op.requestBody ? transform(op.requestBody, visitor, options) : undefined,\n responses: op.responses.map((r) => transform(r, visitor, options)),\n }\n }\n case 'Schema': {\n let schema = node\n const replaced = visitor.schema?.(schema)\n if (replaced) schema = replaced\n\n return {\n ...schema,\n ...('properties' in schema && recurse ? { properties: schema.properties.map((p) => transform(p, visitor, options)) } : {}),\n ...('items' in schema && recurse ? { items: schema.items?.map((i) => transform(i, visitor, options)) } : {}),\n ...('members' in schema && recurse ? { members: schema.members?.map((m) => transform(m, visitor, options)) } : {}),\n }\n }\n case 'Property': {\n let prop = node\n const replaced = visitor.property?.(prop)\n if (replaced) prop = replaced\n\n return {\n ...prop,\n schema: transform(prop.schema, visitor, options),\n }\n }\n case 'Parameter': {\n let param = node\n const replaced = visitor.parameter?.(param)\n if (replaced) param = replaced\n\n return {\n ...param,\n schema: transform(param.schema, visitor, options),\n }\n }\n case 'Response': {\n let response = node\n const replaced = visitor.response?.(response)\n if (replaced) response = replaced\n\n return {\n ...response,\n schema: response.schema ? transform(response.schema, visitor, options) : undefined,\n }\n }\n }\n}\n\n/**\n * Depth-first synchronous reduction. Collects non-`undefined` visitor return values into an array.\n */\nexport function collect<T>(node: Node, visitor: CollectVisitor<T>, options: VisitorOptions = {}): Array<T> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n const results: Array<T> = []\n\n let v: T | undefined\n switch (node.kind) {\n case 'Root':\n v = visitor.root?.(node)\n break\n case 'Operation':\n v = visitor.operation?.(node)\n break\n case 'Schema':\n v = visitor.schema?.(node)\n break\n case 'Property':\n v = visitor.property?.(node)\n break\n case 'Parameter':\n v = visitor.parameter?.(node)\n break\n case 'Response':\n v = visitor.response?.(node)\n break\n }\n if (v !== undefined) results.push(v)\n\n for (const child of getChildren(node, recurse)) {\n for (const item of collect(child, visitor, options)) {\n results.push(item)\n }\n }\n\n return results\n}\n"],"mappings":";;;;AAWA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;CACP;AAED,MAAa,YAAY;CACvB,MAAM;CACN,WAAW;CACX,QAAQ;CACR,UAAU;CACV,WAAW;CACX,UAAU;CACX;AAED,MAAa,cAAc;CACzB,QAAQ;CAIR,QAAQ;CAIR,SAAS;CAIT,QAAQ;CACR,SAAS;CACT,MAAM;CACN,KAAK;CACL,SAAS;CACT,MAAM;CACN,QAAQ;CACR,OAAO;CACP,OAAO;CACP,OAAO;CACP,cAAc;CACd,MAAM;CACN,KAAK;CACL,MAAM;CACN,UAAU;CACV,MAAM;CACN,MAAM;CACN,OAAO;CACP,KAAK;CACL,MAAM;CACP;AAED,MAAa,cAAc;CACzB,KAAK;CACL,MAAM;CACN,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,OAAO;CACR;AAmBD,MAAa,aAAa;CACxB,iBAAiB;CACjB,gBAAgB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ts","../../../internals/utils/src/reserved.ts","../src/guards.ts","../src/utils.ts","../src/factory.ts","../src/printers/printer.ts","../src/printers/functionPrinter.ts","../src/refs.ts","../src/visitor.ts","../src/resolvers.ts","../src/transformers.ts"],"sourcesContent":["import type { NodeKind } from './nodes/base.ts'\nimport type { MediaType } from './nodes/http.ts'\nimport type { HttpMethod } from './nodes/operation.ts'\nimport type { ParameterLocation } from './nodes/parameter.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\n/**\n * Traversal depth used by AST visitor utilities.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\nexport const visitorDepths = {\n shallow: 'shallow',\n deep: 'deep',\n} as const satisfies Record<VisitorDepth, VisitorDepth>\n\nexport const nodeKinds = {\n root: 'Root',\n operation: 'Operation',\n schema: 'Schema',\n property: 'Property',\n parameter: 'Parameter',\n response: 'Response',\n functionParameter: 'FunctionParameter',\n objectBindingParameter: 'ObjectBindingParameter',\n functionParameters: 'FunctionParameters',\n} as const satisfies Record<string, NodeKind>\n\n/**\n * Canonical schema type strings used by AST schema nodes.\n *\n * These values are used across the AST as stable discriminators\n * (for example `schema.type === schemaTypes.object`).\n *\n * The map is grouped by intent:\n * - primitives (`string`, `number`, `boolean`, ...)\n * - structural/composite (`object`, `array`, `union`, ...)\n * - special OpenAPI-oriented types (`ref`, `datetime`, `uuid`, ...)\n */\nexport const schemaTypes = {\n /**\n * Text value.\n */\n string: 'string',\n /**\n * Floating-point number (`float`, `double`).\n */\n number: 'number',\n /**\n * Whole number (`int32`). Use `bigint` for `int64`.\n */\n integer: 'integer',\n /**\n * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.\n */\n bigint: 'bigint',\n /**\n * Boolean value\n */\n boolean: 'boolean',\n /**\n * Explicit null value.\n */\n null: 'null',\n /**\n * Any value (no type restriction).\n */\n any: 'any',\n /**\n * Unknown value (must be narrowed before usage).\n */\n unknown: 'unknown',\n /**\n * No return value (`void`).\n */\n void: 'void',\n /**\n * Object with named properties.\n */\n object: 'object',\n /**\n * Sequential list of items.\n */\n array: 'array',\n /**\n * Fixed-length list with position-specific items.\n */\n tuple: 'tuple',\n /**\n * \"One of\" multiple schema members.\n */\n union: 'union',\n /**\n * \"All of\" multiple schema members.\n */\n intersection: 'intersection',\n /**\n * Enum schema.\n */\n enum: 'enum',\n /**\n * Reference to another schema.\n */\n ref: 'ref',\n /**\n * Calendar date (for example `2026-03-24`).\n */\n date: 'date',\n /**\n * Date-time value (for example `2026-03-24T09:00:00Z`).\n */\n datetime: 'datetime',\n /**\n * Time-only value (for example `09:00:00`).\n */\n time: 'time',\n /**\n * UUID value.\n */\n uuid: 'uuid',\n /**\n * Email address value.\n */\n email: 'email',\n /**\n * URL value.\n */\n url: 'url',\n /**\n * Binary/blob value.\n */\n blob: 'blob',\n /**\n * Impossible value (`never`).\n */\n never: 'never',\n} as const satisfies Record<SchemaType, SchemaType>\n\n/**\n * Primitive scalar schema types used when simplifying union members.\n */\nexport const SCALAR_PRIMITIVE_TYPES = new Set(['string', 'number', 'integer', 'bigint', 'boolean'] as const)\n\nexport const httpMethods = {\n get: 'GET',\n post: 'POST',\n put: 'PUT',\n patch: 'PATCH',\n delete: 'DELETE',\n head: 'HEAD',\n options: 'OPTIONS',\n trace: 'TRACE',\n} as const satisfies Record<Lowercase<HttpMethod>, HttpMethod>\n\nexport const parameterLocations = {\n path: 'path',\n query: 'query',\n header: 'header',\n cookie: 'cookie',\n} as const satisfies Record<ParameterLocation, ParameterLocation>\n\n/**\n * Default maximum number of concurrent callbacks used by `walk`.\n *\n * @example\n * ```ts\n * walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })\n * ```\n */\nexport const WALK_CONCURRENCY = 30\n\n/**\n * Fallback response status code used for catch-all responses.\n *\n * @example\n * ```ts\n * const status = DEFAULT_STATUS_CODE // 'default'\n * ```\n */\nexport const DEFAULT_STATUS_CODE = 'default' as const\n\nexport const mediaTypes = {\n applicationJson: 'application/json',\n applicationXml: 'application/xml',\n applicationFormUrlEncoded: 'application/x-www-form-urlencoded',\n applicationOctetStream: 'application/octet-stream',\n applicationPdf: 'application/pdf',\n applicationZip: 'application/zip',\n applicationGraphql: 'application/graphql',\n multipartFormData: 'multipart/form-data',\n textPlain: 'text/plain',\n textHtml: 'text/html',\n textCsv: 'text/csv',\n textXml: 'text/xml',\n imagePng: 'image/png',\n imageJpeg: 'image/jpeg',\n imageGif: 'image/gif',\n imageWebp: 'image/webp',\n imageSvgXml: 'image/svg+xml',\n audioMpeg: 'audio/mpeg',\n videoMp4: 'video/mp4',\n} as const satisfies Record<string, MediaType>\n","type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import type {\n FunctionParameterNode,\n FunctionParametersNode,\n Node,\n NodeKind,\n ObjectBindingParameterNode,\n OperationNode,\n ParameterNode,\n PropertyNode,\n ResponseNode,\n RootNode,\n SchemaNode,\n SchemaNodeByType,\n} from './nodes/index.ts'\n\n/**\n * Narrows a `SchemaNode` to the variant that matches `type`.\n *\n * @example\n * ```ts\n * const schema = createSchema({ type: 'string' })\n * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | undefined\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | undefined {\n return node?.type === type ? (node as SchemaNodeByType[T]) : undefined\n}\n\nfunction isKind<T extends Node>(kind: NodeKind) {\n return (node: unknown): node is T => (node as Node).kind === kind\n}\n\n/**\n * Returns `true` when the input is a `RootNode`.\n *\n * @example\n * ```ts\n * if (isRootNode(node)) {\n * console.log(node.schemas.length)\n * }\n * ```\n */\nexport const isRootNode = isKind<RootNode>('Root')\n\n/**\n * Returns `true` when the input is an `OperationNode`.\n *\n * @example\n * ```ts\n * if (isOperationNode(node)) {\n * console.log(node.operationId)\n * }\n * ```\n */\nexport const isOperationNode = isKind<OperationNode>('Operation')\n\n/**\n * Returns `true` when the input is a `SchemaNode`.\n *\n * @example\n * ```ts\n * if (isSchemaNode(node)) {\n * console.log(node.type)\n * }\n * ```\n */\nexport const isSchemaNode = isKind<SchemaNode>('Schema')\n\n/**\n * Returns `true` when the input is a `PropertyNode`.\n */\nexport const isPropertyNode = isKind<PropertyNode>('Property')\n\n/**\n * Returns `true` when the input is a `ParameterNode`.\n */\nexport const isParameterNode = isKind<ParameterNode>('Parameter')\n\n/**\n * Returns `true` when the input is a `ResponseNode`.\n */\nexport const isResponseNode = isKind<ResponseNode>('Response')\n\n/**\n * Returns `true` when the input is a `FunctionParameterNode`.\n */\nexport const isFunctionParameterNode = isKind<FunctionParameterNode>('FunctionParameter')\n\n/**\n * Returns `true` when the input is an `ObjectBindingParameterNode`.\n */\nexport const isObjectBindingParameterNode = isKind<ObjectBindingParameterNode>('ObjectBindingParameter')\n\n/**\n * Returns `true` when the input is a `FunctionParametersNode`.\n */\nexport const isFunctionParametersNode = isKind<FunctionParametersNode>('FunctionParameters')\n","import { camelCase, isValidVarName } from '@internals/utils'\n\nimport { narrowSchema } from './guards.ts'\nimport type { ParameterNode, SchemaNode } from './nodes/index.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns `true` when a schema is emitted as a plain TypeScript `string`.\n *\n * - `string`, `uuid`, `email`, `url`, `datetime` are always plain strings.\n * - `date` and `time` are plain strings when their `representation` is `'string'` rather than `'date'`.\n *\n * @example\n * ```ts\n * isStringType(createSchema({ type: 'uuid' })) // true\n * isStringType(createSchema({ type: 'date', representation: 'date' })) // false\n * ```\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n\n/**\n * Applies casing rules to parameter names and returns a new parameter array.\n *\n * The input array is not mutated.\n * If `casing` is not set, the original array is returned unchanged.\n *\n * Use this before passing parameters to schema builders so that property keys\n * in generated output match the desired casing while preserving\n * `OperationNode.parameters` for other consumers.\n *\n * @example\n * ```ts\n * const params = [createParameter({ name: 'pet_id', in: 'query', schema: createSchema({ type: 'string' }) })]\n * const cased = caseParams(params, 'camelcase')\n * // cased[0].name === 'petId'\n * ```\n */\nexport function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode> {\n if (!casing) {\n return params\n }\n\n return params.map((param) => {\n const transformed = casing === 'camelcase' || !isValidVarName(param.name) ? camelCase(param.name) : param.name\n\n return { ...param, name: transformed }\n })\n}\n\n/**\n * Syncs property/parameter schema optionality flags from `required` and `schema.nullable`.\n *\n * - `optional` is set for non-required, non-nullable schemas.\n * - `nullish` is set for non-required, nullable schemas.\n */\nexport function syncOptionality(required: boolean, schema: SchemaNode): SchemaNode {\n const nullable = schema.nullable ?? false\n\n return {\n ...schema,\n optional: !required && !nullable ? true : undefined,\n nullish: !required && nullable ? true : undefined,\n }\n}\n","import type { InferSchemaNode } from './infer.ts'\nimport type {\n FunctionParameterNode,\n FunctionParametersNode,\n ObjectBindingParameterNode,\n ObjectSchemaNode,\n OperationNode,\n ParameterNode,\n PropertyNode,\n ResponseNode,\n RootNode,\n SchemaNode,\n} from './nodes/index.ts'\nimport { syncOptionality } from './utils.ts'\n\n/**\n * Distributive `Omit` that preserves each member of a union.\n *\n * @example\n * ```ts\n * type A = { kind: 'a'; keep: string; drop: number }\n * type B = { kind: 'b'; keep: boolean; drop: number }\n * type Result = DistributiveOmit<A | B, 'drop'>\n * // -> { kind: 'a'; keep: string } | { kind: 'b'; keep: boolean }\n * ```\n */\nexport type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\ntype CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties'> & { properties?: Array<PropertyNode> }\ntype CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>\ntype CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & { kind: 'Schema' }\n\n/**\n * Creates a `RootNode` with stable defaults for `schemas` and `operations`.\n *\n * @example\n * ```ts\n * const root = createRoot()\n * // { kind: 'Root', schemas: [], operations: [] }\n * ```\n *\n * @example\n * ```ts\n * const root = createRoot({ schemas: [petSchema] })\n * // keeps default operations: []\n * ```\n */\nexport function createRoot(overrides: Partial<Omit<RootNode, 'kind'>> = {}): RootNode {\n return {\n schemas: [],\n operations: [],\n ...overrides,\n kind: 'Root',\n }\n}\n\n/**\n * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.\n *\n * @example\n * ```ts\n * const operation = createOperation({\n * operationId: 'getPetById',\n * method: 'GET',\n * path: '/pet/{petId}',\n * })\n * // tags, parameters, and responses are []\n * ```\n *\n * @example\n * ```ts\n * const operation = createOperation({\n * operationId: 'findPets',\n * method: 'GET',\n * path: '/pet/findByStatus',\n * tags: ['pet'],\n * })\n * ```\n */\nexport function createOperation(\n props: Pick<OperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<OperationNode, 'kind' | 'operationId' | 'method' | 'path'>>,\n): OperationNode {\n return {\n tags: [],\n parameters: [],\n responses: [],\n ...props,\n kind: 'Operation',\n }\n}\n\n/**\n * Creates a `SchemaNode`, narrowed to the variant of `props.type`.\n * For object schemas, `properties` defaults to an empty array.\n *\n * @example\n * ```ts\n * const scalar = createSchema({ type: 'string' })\n * // { kind: 'Schema', type: 'string' }\n * ```\n *\n * @example\n * ```ts\n * const object = createSchema({ type: 'object' })\n * // { kind: 'Schema', type: 'object', properties: [] }\n * ```\n *\n * @example\n * ```ts\n * const enumSchema = createSchema({\n * type: 'enum',\n * primitive: 'string',\n * enumValues: ['available', 'pending'],\n * })\n * ```\n */\nexport function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>\nexport function createSchema(props: CreateSchemaInput): SchemaNode\nexport function createSchema(props: CreateSchemaInput): SchemaNode {\n if (props['type'] === 'object') {\n return { properties: [], ...props, kind: 'Schema' } as CreateSchemaOutput<typeof props>\n }\n\n return { ...props, kind: 'Schema' } as CreateSchemaOutput<typeof props>\n}\n\n/**\n * Creates a `PropertyNode`.\n *\n * `required` defaults to `false`.\n * `schema.optional` and `schema.nullish` are derived from `required` and `schema.nullable`.\n *\n * @example\n * ```ts\n * const property = createProperty({\n * name: 'status',\n * schema: createSchema({ type: 'string' }),\n * })\n * // required=false, schema.optional=true\n * ```\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(props: Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>): PropertyNode {\n const required = props.required ?? false\n\n return {\n ...props,\n kind: 'Property',\n required,\n schema: syncOptionality(required, props.schema),\n }\n}\n\n/**\n * Creates a `ParameterNode`.\n *\n * `required` defaults to `false`.\n * Nested schema flags are set from `required` and `schema.nullable`.\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 *\n * @example\n * ```ts\n * const param = createParameter({\n * name: 'status',\n * in: 'query',\n * schema: createSchema({ type: 'string', nullable: true }),\n * })\n * // required=false, schema.nullish=true\n * ```\n */\nexport function createParameter(\n props: Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>,\n): ParameterNode {\n const required = props.required ?? false\n return {\n ...props,\n kind: 'Parameter',\n required,\n schema: syncOptionality(required, props.schema),\n }\n}\n\n/**\n * Creates a `ResponseNode`.\n *\n * @example\n * ```ts\n * const response = createResponse({\n * statusCode: '200',\n * description: 'Success',\n * schema: createSchema({ type: 'object', properties: [] }),\n * })\n * ```\n */\nexport function createResponse(\n props: Pick<ResponseNode, 'statusCode' | 'schema'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'schema'>>,\n): ResponseNode {\n return {\n ...props,\n kind: 'Response',\n }\n}\n\n/**\n * Creates a single-property object schema used as a discriminator literal.\n *\n * @example\n * ```ts\n * createDiscriminantNode({ propertyName: 'type', value: 'dog' })\n * // -> { type: 'object', properties: [{ name: 'type', required: true, schema: enum('dog') }] }\n * ```\n */\nexport function createDiscriminantNode({ propertyName, value }: { propertyName: string; value: string }): SchemaNode {\n return createSchema({\n type: 'object',\n primitive: 'object',\n properties: [\n createProperty({\n name: propertyName,\n schema: createSchema({\n type: 'enum',\n primitive: 'string',\n enumValues: [value],\n }),\n required: true,\n }),\n ],\n })\n}\n\n/**\n * Creates a `FunctionParameterNode`.\n *\n * `optional` defaults to `false`.\n *\n * @example Required typed param\n * ```ts\n * createFunctionParameter({ name: 'petId', type: 'string' })\n * // → petId: string\n * ```\n *\n * @example Optional param\n * ```ts\n * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })\n * // → params?: QueryParams\n * ```\n *\n * @example Param with default (implicitly optional; cannot combine with `optional: true`)\n * ```ts\n * createFunctionParameter({ name: 'config', type: 'RequestConfig', default: '{}' })\n * // → config: RequestConfig = {}\n * ```\n */\nexport function createFunctionParameter(\n props: { name: string; type?: string; rest?: boolean } & ({ optional: true; default?: never } | { optional?: false; default?: string }),\n): FunctionParameterNode {\n return {\n optional: false,\n ...props,\n kind: 'FunctionParameter',\n } as FunctionParameterNode\n}\n\n/**\n * Creates an `ObjectBindingParameterNode` for object-destructured parameter groups.\n *\n * @example Destructured object param\n * ```ts\n * createObjectBindingParameter({\n * properties: [\n * createFunctionParameter({ name: 'id', type: 'string', optional: false }),\n * createFunctionParameter({ name: 'name', type: 'string', optional: true }),\n * ],\n * default: '{}',\n * })\n * // declaration → { id, name? }: { id: string; name?: string } = {}\n * // call → { id, name }\n * ```\n *\n * @example Inline mode — children emitted as individual top-level parameters\n * ```ts\n * createObjectBindingParameter({\n * properties: [createFunctionParameter({ name: 'petId', type: 'string', optional: false })],\n * inline: true,\n * })\n * // declaration → petId: string\n * // call → petId\n * ```\n */\nexport function createObjectBindingParameter(\n props: Pick<ObjectBindingParameterNode, 'properties'> & Partial<Omit<ObjectBindingParameterNode, 'kind' | 'properties'>>,\n): ObjectBindingParameterNode {\n return {\n ...props,\n kind: 'ObjectBindingParameter',\n }\n}\n\n/**\n * Creates a `FunctionParametersNode` from an ordered list of parameters.\n *\n * @example\n * ```ts\n * createFunctionParameters({\n * params: [\n * createFunctionParameter({ name: 'petId', type: 'string', optional: false }),\n * createFunctionParameter({ name: 'config', type: 'RequestConfig', optional: false, default: '{}' }),\n * ],\n * })\n * ```\n *\n * @example\n * ```ts\n * const empty = createFunctionParameters()\n * // { kind: 'FunctionParameters', params: [] }\n * ```\n */\nexport function createFunctionParameters(props: Partial<Omit<FunctionParametersNode, 'kind'>> = {}): FunctionParametersNode {\n return {\n params: [],\n ...props,\n kind: 'FunctionParameters',\n }\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from '../nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\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 * }\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 */\n transform: (node: SchemaNode) => TOutput | null | undefined\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\nexport type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null | undefined\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 * Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null | undefined\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 | undefined\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: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\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.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Creates a schema printer factory.\n *\n * This function wraps a builder and makes options optional at call sites.\n *\n * The builder receives resolved options and returns:\n * - `name` — a unique identifier for the printer\n * - `options` — options stored on the returned printer instance\n * - `nodes` — a map of `SchemaType` → handler functions that convert a `SchemaNode` to `TOutput`\n * - `print` _(optional)_ — top-level override exposed as `printer.print`\n * - Inside this function, use `this.transform(node)` to dispatch to the `nodes` map\n * - This keeps recursion safe and avoids self-calls\n *\n * When no `print` override is provided, `printer.print` falls back to `printer.transform` (the node-level dispatcher).\n *\n * @example Basic usage — Zod schema printer\n * ```ts\n * type ZodPrinter = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = definePrinter<ZodPrinter>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties.map(p => `${p.name}: ${this.transform(p.schema)}`).join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return createPrinterFactory<SchemaNode, SchemaType, SchemaNodeByType>((node) => node.type)(build) as (options?: T['options']) => Printer<T>\n}\n\n/**\n * Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.\n **\n * @example\n * ```ts\n * export const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>(\n * (node) => kindToHandlerKey[node.kind],\n * )\n * ```\n */\nexport function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | undefined) {\n return function <T extends PrinterFactoryOptions>(\n build: (options: T['options']) => {\n name: T['name']\n options: T['options']\n nodes: Partial<{\n [K in TKey]: (\n this: { transform: (node: TNode) => T['output'] | null | undefined; options: T['options'] },\n node: TNodeByKey[K],\n ) => T['output'] | null | undefined\n }>\n print?: (this: { transform: (node: TNode) => T['output'] | null | undefined; options: T['options'] }, node: TNode) => T['printOutput'] | null | undefined\n },\n ): (options?: T['options']) => {\n name: T['name']\n options: T['options']\n transform: (node: TNode) => T['output'] | null | undefined\n print: (node: TNode) => T['printOutput'] | null | undefined\n } {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: TNode): T['output'] | null | undefined => {\n const key = getKey(node)\n if (key === undefined) return null\n\n const handler = nodes[key]\n\n if (!handler) return null\n\n return (handler as (this: typeof context, node: TNode) => T['output'] | null | undefined).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: TNode) => T['printOutput'] | null | undefined,\n }\n }\n }\n}\n","import type { FunctionNode, FunctionNodeType } from '../nodes/function.ts'\nimport type { FunctionParameterNode, FunctionParametersNode, ObjectBindingParameterNode } from '../nodes/index.ts'\nimport type { PrinterFactoryOptions } from './printer.ts'\nimport { createPrinterFactory } from './printer.ts'\n\n/**\n * Maps each function-printer handler key to its concrete node type.\n */\nexport type FunctionNodeByType = {\n functionParameter: FunctionParameterNode\n objectBindingParameter: ObjectBindingParameterNode\n functionParameters: FunctionParametersNode\n}\n\nconst kindToHandlerKey = {\n FunctionParameter: 'functionParameter',\n ObjectBindingParameter: 'objectBindingParameter',\n FunctionParameters: 'functionParameters',\n} satisfies Record<string, FunctionNodeType>\n\n/**\n * Creates a function-parameter printer factory.\n *\n * This wrapper uses `createPrinterFactory` and dispatches handlers by `node.kind`\n * (for function nodes) rather than by `node.type` (for schema nodes).\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { mode: 'declaration' | 'call' }, string>\n *\n * export const myPrinter = defineFunctionPrinter<MyPrinter>((options) => ({\n * name: 'my',\n * options,\n * nodes: {\n * functionParameter(node) {\n * return options.mode === 'declaration' && node.type ? `${node.name}: ${node.type}` : node.name\n * },\n * objectBindingParameter(node) {\n * const inner = node.properties.map(p => this.transform(p)).filter(Boolean).join(', ')\n * return `{ ${inner} }`\n * },\n * functionParameters(node) {\n * return node.params.map(p => this.transform(p)).filter(Boolean).join(', ')\n * },\n * },\n * }))\n * ```\n */\nexport const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>((node) => kindToHandlerKey[node.kind])\n\nexport type FunctionPrinterOptions = {\n /**\n * Rendering modes supported by `functionPrinter`.\n *\n * | Mode | Output example | Use case |\n * |---------------|---------------------------------------------|---------------------------------|\n * | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |\n * | `call` | `id, { method, url }` | Function call arguments |\n * | `keys` | `{ id, config }` | Key names only (destructuring) |\n * | `values` | `{ id: id, config: config }` | Key/value object entries |\n */\n mode: 'declaration' | 'call' | 'keys' | 'values'\n /**\n * Optional transformation applied to every parameter name before printing.\n */\n transformName?: (name: string) => string\n /**\n * Optional transformation applied to every type string before printing.\n */\n transformType?: (type: string) => string\n}\n\ntype DefaultPrinter = PrinterFactoryOptions<'functionParameters', FunctionPrinterOptions, string>\n\nfunction rank(param: FunctionParameterNode | ObjectBindingParameterNode): number {\n if (param.kind === 'ObjectBindingParameter') {\n if (param.default) return 2\n const isOptional = param.optional ?? param.properties.every((p) => p.optional || p.default !== undefined)\n return isOptional ? 1 : 0\n }\n if (param.rest) return 3\n if (param.default) return 2\n return param.optional ? 1 : 0\n}\n\nfunction sortParams(params: Array<FunctionParameterNode | ObjectBindingParameterNode>): Array<FunctionParameterNode | ObjectBindingParameterNode> {\n return [...params].sort((a, b) => rank(a) - rank(b))\n}\n\nfunction sortChildParams(params: Array<FunctionParameterNode>): Array<FunctionParameterNode> {\n return [...params].sort((a, b) => rank(a) - rank(b))\n}\n\n/**\n * Default function-signature printer.\n * Covers the four standard output modes used across Kubb plugins.\n *\n * @example\n * ```ts\n * const printer = functionPrinter({ mode: 'declaration' })\n *\n * const sig = createFunctionParameters({\n * params: [\n * createFunctionParameter({ name: 'petId', type: 'string', optional: false }),\n * createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),\n * ],\n * })\n *\n * printer.print(sig) // → \"petId: string, config: Config = {}\"\n * ```\n */\nexport const functionPrinter = defineFunctionPrinter<DefaultPrinter>((options) => ({\n name: 'functionParameters',\n options,\n nodes: {\n functionParameter(node) {\n const { mode, transformName, transformType } = this.options\n const name = transformName ? transformName(node.name) : node.name\n const type = node.type && transformType ? transformType(node.type) : node.type\n\n if (mode === 'keys' || mode === 'values') {\n return node.rest ? `...${name}` : name\n }\n\n if (mode === 'call') {\n return node.rest ? `...${name}` : name\n }\n\n if (node.rest) {\n return type ? `...${name}: ${type}` : `...${name}`\n }\n if (type) {\n if (node.optional) return `${name}?: ${type}`\n return node.default ? `${name}: ${type} = ${node.default}` : `${name}: ${type}`\n }\n return node.default ? `${name} = ${node.default}` : name\n },\n objectBindingParameter(node) {\n const { mode, transformName, transformType } = this.options\n const sorted = sortChildParams(node.properties)\n const isOptional = node.optional ?? sorted.every((p) => p.optional || p.default !== undefined)\n\n if (node.inline) {\n return sorted\n .map((p) => this.transform(p))\n .filter(Boolean)\n .join(', ')\n }\n\n if (mode === 'keys' || mode === 'values') {\n const keys = sorted.map((p) => p.name).join(', ')\n return `{ ${keys} }`\n }\n\n if (mode === 'call') {\n const keys = sorted.map((p) => p.name).join(', ')\n return `{ ${keys} }`\n }\n\n const names = sorted.map((p) => {\n const n = transformName ? transformName(p.name) : p.name\n\n return n\n })\n\n const nameStr = names.length ? `{ ${names.join(', ')} }` : undefined\n if (!nameStr) return null\n\n let typeAnnotation = node.type\n if (!typeAnnotation) {\n const typeParts = sorted\n .filter((p) => p.type)\n .map((p) => {\n const t = transformType && p.type ? transformType(p.type) : p.type!\n return p.optional || p.default !== undefined ? `${p.name}?: ${t}` : `${p.name}: ${t}`\n })\n typeAnnotation = typeParts.length ? `{ ${typeParts.join('; ')} }` : undefined\n }\n\n if (typeAnnotation) {\n if (isOptional) return `${nameStr}: ${typeAnnotation} = ${node.default ?? '{}'}`\n return node.default ? `${nameStr}: ${typeAnnotation} = ${node.default}` : `${nameStr}: ${typeAnnotation}`\n }\n\n return node.default ? `${nameStr} = ${node.default}` : nameStr\n },\n functionParameters(node) {\n const sorted = sortParams(node.params)\n\n return sorted\n .map((p) => this.transform(p))\n .filter(Boolean)\n .join(', ')\n },\n },\n}))\n","import type { RootNode } from './nodes/root.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\n\n/**\n * Lookup map from schema name to `SchemaNode`.\n */\nexport type RefMap = Map<string, SchemaNode>\n\n/**\n * Returns the last path segment of a reference string.\n *\n * Example: `#/components/schemas/Pet` becomes `Pet`.\n *\n * @example\n * ```ts\n * extractRefName('#/components/schemas/Pet') // 'Pet'\n * ```\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Builds a `RefMap` from `root.schemas` using each schema's `name`.\n *\n * Unnamed schemas are skipped.\n *\n * @example\n * ```ts\n * const refMap = buildRefMap(root)\n * const pet = refMap.get('Pet')\n * ```\n */\nexport function buildRefMap(root: RootNode): RefMap {\n const map: RefMap = new Map()\n\n for (const schema of root.schemas) {\n if (schema.name) {\n map.set(schema.name, schema)\n }\n }\n return map\n}\n\n/**\n * Resolves a schema by name from a `RefMap`.\n *\n * @example\n * ```ts\n * const petSchema = resolveRef(refMap, 'Pet')\n * ```\n */\nexport function resolveRef(refMap: RefMap, ref: string): SchemaNode | undefined {\n return refMap.get(ref)\n}\n\n/**\n * Converts a `RefMap` into a plain object.\n *\n * @example\n * ```ts\n * const refsObject = refMapToObject(refMap)\n * ```\n */\nexport function refMapToObject(refMap: RefMap): Record<string, SchemaNode> {\n return Object.fromEntries(refMap)\n}\n","import type { VisitorDepth } from './constants.ts'\nimport { visitorDepths, WALK_CONCURRENCY } from './constants.ts'\nimport { createParameter, createProperty } from './factory.ts'\nimport type { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode } from './nodes/index.ts'\n\n/**\n * Creates a small async concurrency limiter.\n *\n * At most `concurrency` tasks are in flight at once. Extra tasks are queued.\n *\n * @example\n * ```ts\n * const limit = createLimit(2)\n * await Promise.all([\n * limit(() => taskA()),\n * limit(() => taskB()),\n * limit(() => taskC()),\n * ])\n * // only 2 tasks run at the same time\n * ```\n */\nfunction createLimit(concurrency: number) {\n let active = 0\n const queue: Array<() => void> = []\n\n function next() {\n if (active < concurrency && queue.length > 0) {\n active++\n queue.shift()!()\n }\n }\n\n return function limit<T>(fn: () => Promise<T> | T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n queue.push(() => {\n Promise.resolve(fn())\n .then(resolve, reject)\n .finally(() => {\n active--\n next()\n })\n })\n next()\n })\n }\n}\n\ntype LimitFn = ReturnType<typeof createLimit>\n\n/**\n * Ordered mapping of `[NodeType, ParentType]` pairs.\n *\n * `ParentOf` uses this map to find parent types.\n */\ntype ParentNodeMap = [\n [RootNode, undefined],\n [OperationNode, RootNode],\n [SchemaNode, RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode],\n [PropertyNode, SchemaNode],\n [ParameterNode, OperationNode],\n [ResponseNode, OperationNode],\n]\n\n/**\n * Resolves the parent node type for a given AST node type.\n *\n * This is used by visitor context so `ctx.parent` is correctly typed\n * for each callback.\n *\n * @example\n * ```ts\n * type RootParent = ParentOf<RootNode>\n * // undefined\n * ```\n *\n * @example\n * ```ts\n * type PropertyParent = ParentOf<PropertyNode>\n * // SchemaNode\n * ```\n *\n * @example\n * ```ts\n * type SchemaParent = ParentOf<SchemaNode>\n * // RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode\n * ```\n */\nexport type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> = ParentNodeMap> = TEntries extends [\n infer TEntry extends [Node, unknown],\n ...infer TRest extends ReadonlyArray<[Node, unknown]>,\n]\n ? T extends TEntry[0]\n ? TEntry[1]\n : ParentOf<T, TRest>\n : Node\n\n/**\n * Traversal context passed as the second argument to every visitor callback.\n * `parent` is typed from the current node type.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * schema(node, { parent }) {\n * // parent type is narrowed by node kind\n * },\n * }\n * ```\n */\nexport type VisitorContext<T extends Node = Node> = {\n /**\n * Parent node of the currently visited node.\n * For `RootNode`, this is `undefined`.\n */\n parent?: ParentOf<T>\n}\n\n/**\n * Synchronous visitor used by `transform`.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `x_${node.operationId}` }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n root?(node: RootNode, context: VisitorContext<RootNode>): void | RootNode\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): void | OperationNode\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): void | SchemaNode\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): void | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): void | ParameterNode\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): void | ResponseNode\n}\n\n/**\n * Utility type for values that can be returned directly or asynchronously.\n */\ntype MaybePromise<T> = T | Promise<T>\n\n/**\n * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.\n *\n * @example\n * ```ts\n * const visitor: AsyncVisitor = {\n * async operation(node) {\n * await Promise.resolve(node.operationId)\n * },\n * }\n * ```\n */\nexport type AsyncVisitor = {\n root?(node: RootNode, context: VisitorContext<RootNode>): MaybePromise<void | RootNode>\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<void | OperationNode>\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<void | SchemaNode>\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<void | PropertyNode>\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<void | ParameterNode>\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<void | ResponseNode>\n}\n\n/**\n * Visitor used by `collect`.\n *\n * @example\n * ```ts\n * const visitor: CollectVisitor<string> = {\n * operation(node) {\n * return node.operationId\n * },\n * }\n * ```\n */\nexport type CollectVisitor<T> = {\n root?(node: RootNode, context: VisitorContext<RootNode>): T | undefined\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | undefined\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | undefined\n}\n\n/**\n * Options for `transform`.\n *\n * @example\n * ```ts\n * const options: TransformOptions = { depth: 'deep', schema: (node) => node }\n * ```\n *\n * @example\n * ```ts\n * // Only transform the current node, not nested children\n * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }\n * ```\n */\nexport type TransformOptions = Visitor & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\n/**\n * Options for `walk`.\n *\n * @example\n * ```ts\n * const options: WalkOptions = { depth: 'deep', concurrency: 10, root: () => {} }\n * ```\n */\nexport type WalkOptions = AsyncVisitor & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Maximum number of sibling nodes visited concurrently.\n * @default 30\n */\n concurrency?: number\n}\n\n/**\n * Options for `collect`.\n *\n * @example\n * ```ts\n * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }\n * ```\n */\nexport type CollectOptions<T> = CollectVisitor<T> & {\n /**\n * Traversal depth (`'deep'` by default).\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\n/**\n * Returns the immediate traversable children of `node`.\n *\n * For `Schema` nodes, children (`properties`, `items`, `members`, and non-boolean\n * `additionalProperties`) are only included\n * when `recurse` is `true`; shallow mode skips them.\n *\n * @example\n * ```ts\n * const children = getChildren(operationNode, true)\n * // returns parameters, requestBody schema (if present), and responses\n * ```\n */\nfunction getChildren(node: Node, recurse: boolean): Array<Node> {\n switch (node.kind) {\n case 'Root':\n return [...node.schemas, ...node.operations]\n case 'Operation':\n return [...node.parameters, ...(node.requestBody?.schema ? [node.requestBody.schema] : []), ...node.responses]\n case 'Schema': {\n const children: Array<Node> = []\n\n if (!recurse) return []\n\n if ('properties' in node && node.properties.length > 0) children.push(...node.properties)\n if ('items' in node && node.items) children.push(...node.items)\n if ('members' in node && node.members) children.push(...node.members)\n if ('additionalProperties' in node && node.additionalProperties && node.additionalProperties !== true) children.push(node.additionalProperties)\n\n return children\n }\n case 'Property':\n return [node.schema]\n case 'Parameter':\n return [node.schema]\n case 'Response':\n return node.schema ? [node.schema] : []\n case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n return []\n }\n}\n\n/**\n * Depth-first traversal for side effects. Visitor return values are ignored.\n * Sibling nodes at each level are visited concurrently up to `options.concurrency`\n * (default: `WALK_CONCURRENCY`).\n *\n * @example\n * ```ts\n * await walk(root, {\n * operation(node) {\n * console.log(node.operationId)\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Visit only the current node\n * await walk(root, { depth: 'shallow', root: () => {} })\n * ```\n */\nexport async function walk(node: Node, options: WalkOptions): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n const limit = createLimit(options.concurrency ?? WALK_CONCURRENCY)\n\n return _walk(node, options, recurse, limit, undefined)\n}\n\nasync function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit: LimitFn, parent: Node | undefined): Promise<void> {\n switch (node.kind) {\n case 'Root':\n await limit(() => visitor.root?.(node, { parent: parent as ParentOf<RootNode> }))\n break\n case 'Operation':\n await limit(() => visitor.operation?.(node, { parent: parent as ParentOf<OperationNode> }))\n break\n case 'Schema':\n await limit(() => visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> }))\n break\n case 'Property':\n await limit(() => visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> }))\n break\n case 'Parameter':\n await limit(() => visitor.parameter?.(node, { parent: parent as ParentOf<ParameterNode> }))\n break\n case 'Response':\n await limit(() => visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> }))\n break\n case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n break\n }\n\n const children = getChildren(node, recurse)\n await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)))\n}\n\n/**\n * Runs a depth-first immutable transform.\n *\n * If a visitor returns a node, it replaces the current node.\n * If it returns `undefined`, the current node stays the same.\n *\n * @example\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Shallow mode: only transform the input node\n * const next = transform(root, { depth: 'shallow', root: (node) => node })\n * ```\n */\nexport function transform(node: RootNode, options: TransformOptions): RootNode\nexport function transform(node: OperationNode, options: TransformOptions): OperationNode\nexport function transform(node: SchemaNode, options: TransformOptions): SchemaNode\nexport function transform(node: PropertyNode, options: TransformOptions): PropertyNode\nexport function transform(node: ParameterNode, options: TransformOptions): ParameterNode\nexport function transform(node: ResponseNode, options: TransformOptions): ResponseNode\nexport function transform(node: Node, options: TransformOptions): Node\nexport function transform(node: Node, options: TransformOptions): Node {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n\n switch (node.kind) {\n case 'Root': {\n let root = node\n const replaced = visitor.root?.(root, { parent: parent as ParentOf<RootNode> })\n if (replaced) root = replaced\n\n return {\n ...root,\n schemas: root.schemas.map((s) => transform(s, { ...options, parent: root })),\n operations: root.operations.map((op) => transform(op, { ...options, parent: root })),\n }\n }\n case 'Operation': {\n let op = node\n const replaced = visitor.operation?.(op, { parent: parent as ParentOf<OperationNode> })\n if (replaced) op = replaced\n\n return {\n ...op,\n parameters: op.parameters.map((p) => transform(p, { ...options, parent: op })),\n requestBody: op.requestBody\n ? { ...op.requestBody, schema: op.requestBody.schema ? transform(op.requestBody.schema, { ...options, parent: op }) : undefined }\n : undefined,\n responses: op.responses.map((r) => transform(r, { ...options, parent: op })),\n }\n }\n case 'Schema': {\n let schema = node\n const replaced = visitor.schema?.(schema, { parent: parent as ParentOf<SchemaNode> })\n if (replaced) schema = replaced\n\n const childOptions = { ...options, parent: schema }\n\n return {\n ...schema,\n ...('properties' in schema && recurse ? { properties: schema.properties.map((p) => transform(p, childOptions)) } : {}),\n ...('items' in schema && recurse ? { items: schema.items?.map((i) => transform(i, childOptions)) } : {}),\n ...('members' in schema && recurse ? { members: schema.members?.map((m) => transform(m, childOptions)) } : {}),\n ...('additionalProperties' in schema && recurse && schema.additionalProperties && schema.additionalProperties !== true\n ? { additionalProperties: transform(schema.additionalProperties, childOptions) }\n : {}),\n } as SchemaNode\n }\n case 'Property': {\n let prop = node\n const replaced = visitor.property?.(prop, { parent: parent as ParentOf<PropertyNode> })\n if (replaced) prop = replaced\n\n return createProperty({\n ...prop,\n schema: transform(prop.schema, { ...options, parent: prop }),\n })\n }\n case 'Parameter': {\n let param = node\n const replaced = visitor.parameter?.(param, { parent: parent as ParentOf<ParameterNode> })\n if (replaced) param = replaced\n\n return createParameter({\n ...param,\n schema: transform(param.schema, { ...options, parent: param }),\n })\n }\n case 'Response': {\n let response = node\n const replaced = visitor.response?.(response, { parent: parent as ParentOf<ResponseNode> })\n if (replaced) response = replaced\n\n return {\n ...response,\n schema: transform(response.schema, { ...options, parent: response }),\n }\n }\n case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n return node\n }\n}\n\n/**\n * Composes multiple visitors into one visitor, applied left to right.\n *\n * For each node kind, output from one visitor is input to the next.\n * If a visitor returns `undefined`, the previous node value is kept.\n *\n * @example\n * ```ts\n * const visitor = composeTransformers(\n * { operation: (node) => ({ ...node, operationId: `a_${node.operationId}` }) },\n * { operation: (node) => ({ ...node, operationId: `b_${node.operationId}` }) },\n * )\n * ```\n */\nexport function composeTransformers(...visitors: Array<Visitor>): Visitor {\n return {\n root(node, context) {\n return visitors.reduce<RootNode>((acc, v) => v.root?.(acc, context) ?? acc, node)\n },\n operation(node, context) {\n return visitors.reduce<OperationNode>((acc, v) => v.operation?.(acc, context) ?? acc, node)\n },\n schema(node, context) {\n return visitors.reduce<SchemaNode>((acc, v) => v.schema?.(acc, context) ?? acc, node)\n },\n property(node, context) {\n return visitors.reduce<PropertyNode>((acc, v) => v.property?.(acc, context) ?? acc, node)\n },\n parameter(node, context) {\n return visitors.reduce<ParameterNode>((acc, v) => v.parameter?.(acc, context) ?? acc, node)\n },\n response(node, context) {\n return visitors.reduce<ResponseNode>((acc, v) => v.response?.(acc, context) ?? acc, node)\n },\n }\n}\n\n/**\n * Runs a depth-first synchronous collection pass.\n *\n * Non-`undefined` values returned by visitor callbacks are appended to the result.\n *\n * @example\n * ```ts\n * const ids = collect(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n *\n * @example\n * ```ts\n * // Collect from only the current node\n * const values = collect(root, { depth: 'shallow', root: () => 'root' })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n const results: Array<T> = []\n\n let v: T | undefined\n switch (node.kind) {\n case 'Root':\n v = visitor.root?.(node, { parent: parent as ParentOf<RootNode> })\n break\n case 'Operation':\n v = visitor.operation?.(node, { parent: parent as ParentOf<OperationNode> })\n break\n case 'Schema':\n v = visitor.schema?.(node, { parent: parent as ParentOf<SchemaNode> })\n break\n case 'Property':\n v = visitor.property?.(node, { parent: parent as ParentOf<PropertyNode> })\n break\n case 'Parameter':\n v = visitor.parameter?.(node, { parent: parent as ParentOf<ParameterNode> })\n break\n case 'Response':\n v = visitor.response?.(node, { parent: parent as ParentOf<ResponseNode> })\n break\n case 'FunctionParameter':\n case 'ObjectBindingParameter':\n case 'FunctionParameters':\n break\n }\n if (v !== undefined) results.push(v)\n\n for (const child of getChildren(node, recurse)) {\n for (const item of collect(child, { ...options, parent: node })) {\n results.push(item)\n }\n }\n\n return results\n}\n","import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from './guards.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { extractRefName } from './refs.ts'\nimport { collect } from './visitor.ts'\n\nexport function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null {\n if (!mapping || !ref) return null\n return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null\n}\n\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Collects import entries for all `ref` schema nodes in `node`.\n */\nexport function collectImports<TImport>({\n node,\n nameMapping,\n resolve,\n}: {\n node: SchemaNode\n nameMapping: Map<string, string>\n resolve: (schemaName: string) => TImport | undefined\n}): Array<TImport> {\n return collect<TImport>(node, {\n schema(schemaNode): TImport | undefined {\n const schemaRef = narrowSchema(schemaNode, 'ref')\n if (!schemaRef?.ref) return\n\n const rawName = extractRefName(schemaRef.ref)\n const schemaName = nameMapping.get(rawName) ?? rawName\n const result = resolve(schemaName)\n if (!result) return\n\n return result\n },\n })\n}\n","import { SCALAR_PRIMITIVE_TYPES } from './constants.ts'\nimport { createProperty, createSchema } from './factory.ts'\nimport { narrowSchema } from './guards.ts'\nimport type { SchemaNode } from './nodes/schema.ts'\nimport { enumPropName } from './resolvers.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Replaces a discriminator property's schema with a string enum of allowed values.\n *\n * If `node` is not an object schema, or if the property does not exist, the input\n * node is returned as-is.\n *\n * @example\n * ```ts\n * const schema = createSchema({\n * type: 'object',\n * properties: [createProperty({ name: 'type', required: true, schema: createSchema({ type: 'string' }) })],\n * })\n * const result = setDiscriminatorEnum({ node: schema, propertyName: 'type', values: ['dog', 'cat'] })\n * ```\n */\nexport function setDiscriminatorEnum({\n node,\n propertyName,\n values,\n enumName,\n}: {\n node: SchemaNode\n propertyName: string\n values: Array<string>\n enumName?: string\n}): SchemaNode {\n const objectNode = narrowSchema(node, 'object')\n if (!objectNode?.properties?.length) {\n return node\n }\n\n const hasProperty = objectNode.properties.some((prop) => prop.name === propertyName)\n if (!hasProperty) {\n return node\n }\n\n return createSchema({\n ...objectNode,\n properties: objectNode.properties.map((prop) => {\n if (prop.name !== propertyName) {\n return prop\n }\n\n return createProperty({\n ...prop,\n schema: createSchema({\n type: 'enum',\n primitive: 'string',\n enumValues: values,\n name: enumName,\n readOnly: prop.schema.readOnly,\n writeOnly: prop.schema.writeOnly,\n }),\n })\n }),\n })\n}\n\n/**\n * Merges adjacent anonymous object members into a single anonymous object member.\n *\n * @example\n * ```ts\n * const merged = mergeAdjacentObjects([\n * createSchema({ type: 'object', properties: [createProperty({ name: 'a', schema: createSchema({ type: 'string' }) })] }),\n * createSchema({ type: 'object', properties: [createProperty({ name: 'b', schema: createSchema({ type: 'number' }) })] }),\n * ])\n * ```\n */\nexport function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode> {\n return members.reduce<Array<SchemaNode>>((acc, member) => {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name) {\n const previous = acc.at(-1)\n const previousObject = previous ? narrowSchema(previous, 'object') : undefined\n\n if (previousObject && !previousObject.name) {\n acc[acc.length - 1] = createSchema({\n ...previousObject,\n properties: [...(previousObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n return acc\n }\n }\n\n acc.push(member)\n return acc\n }, [])\n}\n\n/**\n * Removes enum members that are covered by broader scalar primitives in the same union.\n *\n * @example\n * ```ts\n * const simplified = simplifyUnion([\n * createSchema({ type: 'enum', primitive: 'string', enumValues: ['active'] }),\n * createSchema({ type: 'string' }),\n * ])\n * // keeps only string member\n * ```\n */\nexport function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode> {\n const scalarPrimitives = new Set(\n members.filter((member) => SCALAR_PRIMITIVE_TYPES.has(member.type as typeof SCALAR_PRIMITIVE_TYPES extends Set<infer T> ? T : never)).map((m) => m.type),\n )\n\n if (!scalarPrimitives.size) {\n return members\n }\n\n return members.filter((member) => {\n const enumNode = narrowSchema(member, 'enum')\n if (!enumNode) {\n return true\n }\n\n const primitive = enumNode.primitive\n if (!primitive) {\n return true\n }\n\n const enumValueCount = enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0\n if (enumValueCount <= 1) {\n return true\n }\n\n if (scalarPrimitives.has(primitive)) {\n return false\n }\n\n if ((primitive === 'integer' || primitive === 'number') && (scalarPrimitives.has('integer') || scalarPrimitives.has('number'))) {\n return false\n }\n\n return true\n })\n}\n\nexport function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode {\n const enumNode = narrowSchema(propNode, 'enum')\n\n if (enumNode?.primitive === 'boolean') {\n return { ...propNode, name: undefined }\n }\n\n if (enumNode) {\n return { ...propNode, name: enumPropName(parentName, propName, enumSuffix) }\n }\n\n return propNode\n}\n\n/**\n * Walks a schema tree and resolves `ref`/`enum` names through callbacks.\n */\nexport function resolveNames({\n node,\n nameMapping,\n resolveName,\n resolveEnumName,\n}: {\n node: SchemaNode\n nameMapping: Map<string, string>\n resolveName: (ref: string) => string | undefined\n resolveEnumName?: (name: string) => string | undefined\n}): SchemaNode {\n return transform(node, {\n schema(schemaNode) {\n const schemaRef = narrowSchema(schemaNode, 'ref')\n\n if (schemaRef && (schemaRef.ref || schemaRef.name)) {\n const rawRef = schemaRef.ref ?? schemaRef.name!\n const resolved = resolveName(nameMapping.get(rawRef) ?? rawRef)\n if (resolved) {\n return { ...schemaNode, name: resolved }\n }\n }\n\n const schemaEnum = narrowSchema(schemaNode, 'enum')\n if (schemaEnum?.name) {\n const resolved = (resolveEnumName ?? resolveName)(schemaEnum.name)\n if (resolved) {\n return { ...schemaNode, name: resolved }\n }\n }\n },\n }) as SchemaNode\n}\n"],"mappings":";;;AAWA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;CACP;AAED,MAAa,YAAY;CACvB,MAAM;CACN,WAAW;CACX,QAAQ;CACR,UAAU;CACV,WAAW;CACX,UAAU;CACV,mBA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AAO;EAAE,GAAG;EAAU,MAAM,aAAa,YAAY,UAAU,WAAW;EAAE;AAG9E,QAAO;;;;;AAMT,SAAgB,aAAa,EAC3B,MACA,aACA,aACA,mBAMa;AACb,QAAO,UAAU,MAAM,EACrB,OAAO,YAAY;EACjB,MAAM,YAAY,aAAa,YAAY,MAAM;AAEjD,MAAI,cAAc,UAAU,OAAO,UAAU,OAAO;GAClD,MAAM,SAAS,UAAU,OAAO,UAAU;GAC1C,MAAM,WAAW,YAAY,YAAY,IAAI,OAAO,IAAI,OAAO;AAC/D,OAAI,SACF,QAAO;IAAE,GAAG;IAAY,MAAM;IAAU;;EAI5C,MAAM,aAAa,aAAa,YAAY,OAAO;AACnD,MAAI,YAAY,MAAM;GACpB,MAAM,YAAY,mBAAmB,aAAa,WAAW,KAAK;AAClE,OAAI,SACF,QAAO;IAAE,GAAG;IAAY,MAAM;IAAU;;IAI/C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,301 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { D as
|
|
2
|
+
import { A as createRoot, B as ResponseNode, C as createFunctionParameter, Ct as httpMethods, D as createParameter, E as createOperation, Et as schemaTypes, G as ParameterNode, L as RootNode, M as InferSchema, N as InferSchemaNode, O as createProperty, P as ParserOptions, S as createDiscriminantNode, T as createObjectBindingParameter, Tt as nodeKinds, _ as resolveRef, _t as FunctionParametersNode, at as SchemaNode, b as definePrinter, d as transform, f as walk, g as refMapToObject, gt as FunctionParameterNode, h as extractRefName, j as createSchema, k as createResponse, l as collect, m as buildRefMap, mt as FunctionNode, ot as SchemaNodeByType, pt as PropertyNode, u as composeTransformers, vt as ObjectBindingParameterNode, w as createFunctionParameters, wt as mediaTypes, xt as SCALAR_PRIMITIVE_TYPES, y as PrinterFactoryOptions, z as OperationNode } from "./visitor-COwfCgLK.js";
|
|
3
3
|
|
|
4
4
|
//#region src/guards.d.ts
|
|
5
5
|
/**
|
|
6
|
-
* Narrows a `SchemaNode` to the
|
|
6
|
+
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const schema = createSchema({ type: 'string' })
|
|
11
|
+
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | undefined
|
|
12
|
+
* ```
|
|
7
13
|
*/
|
|
8
14
|
declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | undefined;
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
16
|
+
* Returns `true` when the input is a `RootNode`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* if (isRootNode(node)) {
|
|
21
|
+
* console.log(node.schemas.length)
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
11
24
|
*/
|
|
12
25
|
declare const isRootNode: (node: unknown) => node is RootNode;
|
|
13
26
|
/**
|
|
14
|
-
*
|
|
27
|
+
* Returns `true` when the input is an `OperationNode`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* if (isOperationNode(node)) {
|
|
32
|
+
* console.log(node.operationId)
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
15
35
|
*/
|
|
16
36
|
declare const isOperationNode: (node: unknown) => node is OperationNode;
|
|
17
37
|
/**
|
|
18
|
-
*
|
|
38
|
+
* Returns `true` when the input is a `SchemaNode`.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* if (isSchemaNode(node)) {
|
|
43
|
+
* console.log(node.type)
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
19
46
|
*/
|
|
20
47
|
declare const isSchemaNode: (node: unknown) => node is SchemaNode;
|
|
21
48
|
/**
|
|
22
|
-
*
|
|
49
|
+
* Returns `true` when the input is a `PropertyNode`.
|
|
23
50
|
*/
|
|
24
51
|
declare const isPropertyNode: (node: unknown) => node is PropertyNode;
|
|
25
52
|
/**
|
|
26
|
-
*
|
|
53
|
+
* Returns `true` when the input is a `ParameterNode`.
|
|
27
54
|
*/
|
|
28
55
|
declare const isParameterNode: (node: unknown) => node is ParameterNode;
|
|
29
56
|
/**
|
|
30
|
-
*
|
|
57
|
+
* Returns `true` when the input is a `ResponseNode`.
|
|
31
58
|
*/
|
|
32
59
|
declare const isResponseNode: (node: unknown) => node is ResponseNode;
|
|
60
|
+
/**
|
|
61
|
+
* Returns `true` when the input is a `FunctionParameterNode`.
|
|
62
|
+
*/
|
|
63
|
+
declare const isFunctionParameterNode: (node: unknown) => node is FunctionParameterNode;
|
|
64
|
+
/**
|
|
65
|
+
* Returns `true` when the input is an `ObjectBindingParameterNode`.
|
|
66
|
+
*/
|
|
67
|
+
declare const isObjectBindingParameterNode: (node: unknown) => node is ObjectBindingParameterNode;
|
|
68
|
+
/**
|
|
69
|
+
* Returns `true` when the input is a `FunctionParametersNode`.
|
|
70
|
+
*/
|
|
71
|
+
declare const isFunctionParametersNode: (node: unknown) => node is FunctionParametersNode;
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/printers/functionPrinter.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* Creates a function-parameter printer factory.
|
|
76
|
+
*
|
|
77
|
+
* This wrapper uses `createPrinterFactory` and dispatches handlers by `node.kind`
|
|
78
|
+
* (for function nodes) rather than by `node.type` (for schema nodes).
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* type MyPrinter = PrinterFactoryOptions<'my', { mode: 'declaration' | 'call' }, string>
|
|
83
|
+
*
|
|
84
|
+
* export const myPrinter = defineFunctionPrinter<MyPrinter>((options) => ({
|
|
85
|
+
* name: 'my',
|
|
86
|
+
* options,
|
|
87
|
+
* nodes: {
|
|
88
|
+
* functionParameter(node) {
|
|
89
|
+
* return options.mode === 'declaration' && node.type ? `${node.name}: ${node.type}` : node.name
|
|
90
|
+
* },
|
|
91
|
+
* objectBindingParameter(node) {
|
|
92
|
+
* const inner = node.properties.map(p => this.transform(p)).filter(Boolean).join(', ')
|
|
93
|
+
* return `{ ${inner} }`
|
|
94
|
+
* },
|
|
95
|
+
* functionParameters(node) {
|
|
96
|
+
* return node.params.map(p => this.transform(p)).filter(Boolean).join(', ')
|
|
97
|
+
* },
|
|
98
|
+
* },
|
|
99
|
+
* }))
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare const defineFunctionPrinter: <T extends PrinterFactoryOptions>(build: (options: T["options"]) => {
|
|
103
|
+
name: T["name"];
|
|
104
|
+
options: T["options"];
|
|
105
|
+
nodes: Partial<{
|
|
106
|
+
functionParameter: (this: {
|
|
107
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
108
|
+
options: T["options"];
|
|
109
|
+
}, node: FunctionParameterNode) => T["output"] | null | undefined;
|
|
110
|
+
objectBindingParameter: (this: {
|
|
111
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
112
|
+
options: T["options"];
|
|
113
|
+
}, node: ObjectBindingParameterNode) => T["output"] | null | undefined;
|
|
114
|
+
functionParameters: (this: {
|
|
115
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
116
|
+
options: T["options"];
|
|
117
|
+
}, node: FunctionParametersNode) => T["output"] | null | undefined;
|
|
118
|
+
}>;
|
|
119
|
+
print?: ((this: {
|
|
120
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
121
|
+
options: T["options"];
|
|
122
|
+
}, node: FunctionNode) => T["printOutput"] | null | undefined) | undefined;
|
|
123
|
+
}) => (options?: T["options"] | undefined) => {
|
|
124
|
+
name: T["name"];
|
|
125
|
+
options: T["options"];
|
|
126
|
+
transform: (node: FunctionNode) => T["output"] | null | undefined;
|
|
127
|
+
print: (node: FunctionNode) => T["printOutput"] | null | undefined;
|
|
128
|
+
};
|
|
129
|
+
type FunctionPrinterOptions = {
|
|
130
|
+
/**
|
|
131
|
+
* Rendering modes supported by `functionPrinter`.
|
|
132
|
+
*
|
|
133
|
+
* | Mode | Output example | Use case |
|
|
134
|
+
* |---------------|---------------------------------------------|---------------------------------|
|
|
135
|
+
* | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |
|
|
136
|
+
* | `call` | `id, { method, url }` | Function call arguments |
|
|
137
|
+
* | `keys` | `{ id, config }` | Key names only (destructuring) |
|
|
138
|
+
* | `values` | `{ id: id, config: config }` | Key/value object entries |
|
|
139
|
+
*/
|
|
140
|
+
mode: 'declaration' | 'call' | 'keys' | 'values';
|
|
141
|
+
/**
|
|
142
|
+
* Optional transformation applied to every parameter name before printing.
|
|
143
|
+
*/
|
|
144
|
+
transformName?: (name: string) => string;
|
|
145
|
+
/**
|
|
146
|
+
* Optional transformation applied to every type string before printing.
|
|
147
|
+
*/
|
|
148
|
+
transformType?: (type: string) => string;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Default function-signature printer.
|
|
152
|
+
* Covers the four standard output modes used across Kubb plugins.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const printer = functionPrinter({ mode: 'declaration' })
|
|
157
|
+
*
|
|
158
|
+
* const sig = createFunctionParameters({
|
|
159
|
+
* params: [
|
|
160
|
+
* createFunctionParameter({ name: 'petId', type: 'string', optional: false }),
|
|
161
|
+
* createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),
|
|
162
|
+
* ],
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* printer.print(sig) // → "petId: string, config: Config = {}"
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
|
|
169
|
+
name: "functionParameters";
|
|
170
|
+
options: FunctionPrinterOptions;
|
|
171
|
+
transform: (node: FunctionNode) => string | null | undefined;
|
|
172
|
+
print: (node: FunctionNode) => string | null | undefined;
|
|
173
|
+
};
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/resolvers.d.ts
|
|
176
|
+
declare function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null;
|
|
177
|
+
declare function childName(parentName: string | null | undefined, propName: string): string | null;
|
|
178
|
+
declare function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Collects import entries for all `ref` schema nodes in `node`.
|
|
181
|
+
*/
|
|
182
|
+
declare function collectImports<TImport>({
|
|
183
|
+
node,
|
|
184
|
+
nameMapping,
|
|
185
|
+
resolve
|
|
186
|
+
}: {
|
|
187
|
+
node: SchemaNode;
|
|
188
|
+
nameMapping: Map<string, string>;
|
|
189
|
+
resolve: (schemaName: string) => TImport | undefined;
|
|
190
|
+
}): Array<TImport>;
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/transformers.d.ts
|
|
193
|
+
/**
|
|
194
|
+
* Replaces a discriminator property's schema with a string enum of allowed values.
|
|
195
|
+
*
|
|
196
|
+
* If `node` is not an object schema, or if the property does not exist, the input
|
|
197
|
+
* node is returned as-is.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const schema = createSchema({
|
|
202
|
+
* type: 'object',
|
|
203
|
+
* properties: [createProperty({ name: 'type', required: true, schema: createSchema({ type: 'string' }) })],
|
|
204
|
+
* })
|
|
205
|
+
* const result = setDiscriminatorEnum({ node: schema, propertyName: 'type', values: ['dog', 'cat'] })
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
declare function setDiscriminatorEnum({
|
|
209
|
+
node,
|
|
210
|
+
propertyName,
|
|
211
|
+
values,
|
|
212
|
+
enumName
|
|
213
|
+
}: {
|
|
214
|
+
node: SchemaNode;
|
|
215
|
+
propertyName: string;
|
|
216
|
+
values: Array<string>;
|
|
217
|
+
enumName?: string;
|
|
218
|
+
}): SchemaNode;
|
|
219
|
+
/**
|
|
220
|
+
* Merges adjacent anonymous object members into a single anonymous object member.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const merged = mergeAdjacentObjects([
|
|
225
|
+
* createSchema({ type: 'object', properties: [createProperty({ name: 'a', schema: createSchema({ type: 'string' }) })] }),
|
|
226
|
+
* createSchema({ type: 'object', properties: [createProperty({ name: 'b', schema: createSchema({ type: 'number' }) })] }),
|
|
227
|
+
* ])
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
declare function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
231
|
+
/**
|
|
232
|
+
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* const simplified = simplifyUnion([
|
|
237
|
+
* createSchema({ type: 'enum', primitive: 'string', enumValues: ['active'] }),
|
|
238
|
+
* createSchema({ type: 'string' }),
|
|
239
|
+
* ])
|
|
240
|
+
* // keeps only string member
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
244
|
+
declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
|
|
245
|
+
/**
|
|
246
|
+
* Walks a schema tree and resolves `ref`/`enum` names through callbacks.
|
|
247
|
+
*/
|
|
248
|
+
declare function resolveNames({
|
|
249
|
+
node,
|
|
250
|
+
nameMapping,
|
|
251
|
+
resolveName,
|
|
252
|
+
resolveEnumName
|
|
253
|
+
}: {
|
|
254
|
+
node: SchemaNode;
|
|
255
|
+
nameMapping: Map<string, string>;
|
|
256
|
+
resolveName: (ref: string) => string | undefined;
|
|
257
|
+
resolveEnumName?: (name: string) => string | undefined;
|
|
258
|
+
}): SchemaNode;
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/utils.d.ts
|
|
261
|
+
/**
|
|
262
|
+
* Returns `true` when a schema is emitted as a plain TypeScript `string`.
|
|
263
|
+
*
|
|
264
|
+
* - `string`, `uuid`, `email`, `url`, `datetime` are always plain strings.
|
|
265
|
+
* - `date` and `time` are plain strings when their `representation` is `'string'` rather than `'date'`.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* isStringType(createSchema({ type: 'uuid' })) // true
|
|
270
|
+
* isStringType(createSchema({ type: 'date', representation: 'date' })) // false
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
declare function isStringType(node: SchemaNode): boolean;
|
|
274
|
+
/**
|
|
275
|
+
* Applies casing rules to parameter names and returns a new parameter array.
|
|
276
|
+
*
|
|
277
|
+
* The input array is not mutated.
|
|
278
|
+
* If `casing` is not set, the original array is returned unchanged.
|
|
279
|
+
*
|
|
280
|
+
* Use this before passing parameters to schema builders so that property keys
|
|
281
|
+
* in generated output match the desired casing while preserving
|
|
282
|
+
* `OperationNode.parameters` for other consumers.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* const params = [createParameter({ name: 'pet_id', in: 'query', schema: createSchema({ type: 'string' }) })]
|
|
287
|
+
* const cased = caseParams(params, 'camelcase')
|
|
288
|
+
* // cased[0].name === 'petId'
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
declare function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode>;
|
|
292
|
+
/**
|
|
293
|
+
* Syncs property/parameter schema optionality flags from `required` and `schema.nullable`.
|
|
294
|
+
*
|
|
295
|
+
* - `optional` is set for non-required, non-nullable schemas.
|
|
296
|
+
* - `nullish` is set for non-required, nullable schemas.
|
|
297
|
+
*/
|
|
298
|
+
declare function syncOptionality(required: boolean, schema: SchemaNode): SchemaNode;
|
|
33
299
|
//#endregion
|
|
34
|
-
export { buildRefMap, collect, createOperation, createParameter, createProperty, createResponse, createRoot, createSchema, definePrinter, httpMethods, isOperationNode, isParameterNode, isPropertyNode, isResponseNode, isRootNode, isSchemaNode, mediaTypes, narrowSchema, nodeKinds, refMapToObject, resolveRef, schemaTypes, transform, walk };
|
|
300
|
+
export { type InferSchema, type InferSchemaNode, type ParserOptions, SCALAR_PRIMITIVE_TYPES, buildRefMap, caseParams, childName, collect, collectImports, composeTransformers, createDiscriminantNode, createFunctionParameter, createFunctionParameters, createObjectBindingParameter, createOperation, createParameter, createProperty, createResponse, createRoot, createSchema, defineFunctionPrinter, definePrinter, enumPropName, extractRefName, findDiscriminator, functionPrinter, httpMethods, isFunctionParameterNode, isFunctionParametersNode, isObjectBindingParameterNode, isOperationNode, isParameterNode, isPropertyNode, isResponseNode, isRootNode, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, nodeKinds, refMapToObject, resolveNames, resolveRef, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, transform, walk };
|
|
35
301
|
//# sourceMappingURL=index.d.ts.map
|