@kubb/ast 4.33.3 → 4.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/constants.ts","../src/factory.ts","../src/guards.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 * 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 { 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 */\nexport function createSchema<T extends DistributiveOmit<SchemaNode, 'kind'>>(props: T): T & { kind: 'Schema' } {\n return { ...props, kind: 'Schema' } as T & { 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: Node): node is T => 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 { 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 } from './constants.ts'\nimport type { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode } from './nodes/index.ts'\n\n/**\n * Shared options for `walk`, `transform`, and `collect`.\n */\nexport type VisitorOptions = {\n depth?: VisitorDepth\n}\n\n/**\n * Synchronous visitor for `transform` and `walk`.\n */\nexport interface 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 interface 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 interface 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) 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 */\nexport async function walk(node: Node, visitor: AsyncVisitor, options: VisitorOptions = {}): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n\n switch (node.kind) {\n case 'Root':\n await visitor.root?.(node)\n break\n case 'Operation':\n await visitor.operation?.(node)\n break\n case 'Schema':\n await visitor.schema?.(node)\n break\n case 'Property':\n await visitor.property?.(node)\n break\n case 'Parameter':\n await visitor.parameter?.(node)\n break\n case 'Response':\n await visitor.response?.(node)\n break\n }\n\n for (const child of getChildren(node, recurse)) {\n await walk(child, visitor, options)\n }\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;AAcD,MAAa,aAAa;CACxB,iBAAiB;CACjB,gBAAgB;CAChB,2BAA2B;CAC3B,wBAAwB;CACxB,gBAAgB;CAChB,gBAAgB;CAChB,oBAAoB;CACpB,mBAAmB;CACnB,WAAW;CACX,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;CACX,aAAa;CACb,WAAW;CACX,UAAU;CACX;;;;;;AC7FD,SAAgB,WAAW,YAA6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L,GAAG;IACH,QAAQ,UAAU,KAAK,QAAQ,SAAS,QAAQ;IACjD;;EAEH,KAAK,aAAa;GAChB,IAAI,QAAQ;GACZ,MAAM,WAAW,QAAQ,YAAY,MAAM;AAC3C,OAAI,SAAU,SAAQ;AAEtB,UAAO;IACL,GAAG;IACH,QAAQ,UAAU,MAAM,QAAQ,SAAS,QAAQ;IAClD;;EAEH,KAAK,YAAY;GACf,IAAI,WAAW;GACf,MAAM,WAAW,QAAQ,WAAW,SAAS;AAC7C,OAAI,SAAU,YAAW;AAEzB,UAAO;IACL,GAAG;IACH,QAAQ,SAAS,SAAS,UAAU,SAAS,QAAQ,SAAS,QAAQ,GAAG,KAAA;IAC1E;;;;;;;AAQP,SAAgB,QAAW,MAAY,SAA4B,UAA0B,EAAE,EAAY;CACzG,MAAM,WAAW,QAAQ,SAAS,cAAc,UAAU,cAAc;CACxE,MAAM,UAAoB,EAAE;CAE5B,IAAI;AACJ,SAAQ,KAAK,MAAb;EACE,KAAK;AACH,OAAI,QAAQ,OAAO,KAAK;AACxB;EACF,KAAK;AACH,OAAI,QAAQ,YAAY,KAAK;AAC7B;EACF,KAAK;AACH,OAAI,QAAQ,SAAS,KAAK;AAC1B;EACF,KAAK;AACH,OAAI,QAAQ,WAAW,KAAK;AAC5B;EACF,KAAK;AACH,OAAI,QAAQ,YAAY,KAAK;AAC7B;EACF,KAAK;AACH,OAAI,QAAQ,WAAW,KAAK;AAC5B;;AAEJ,KAAI,MAAM,KAAA,EAAW,SAAQ,KAAK,EAAE;AAEpC,MAAK,MAAM,SAAS,YAAY,MAAM,QAAQ,CAC5C,MAAK,MAAM,QAAQ,QAAQ,OAAO,SAAS,QAAQ,CACjD,SAAQ,KAAK,KAAK;AAItB,QAAO"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/constants.ts","../src/factory.ts","../src/guards.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 * 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 { 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 */\nexport function createSchema<T extends DistributiveOmit<SchemaNode, 'kind'>>(props: T): T & { kind: 'Schema' } {\n return { ...props, kind: 'Schema' } as T & { 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: Node): node is T => 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 { 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 } from './constants.ts'\nimport type { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode } from './nodes/index.ts'\n\n/**\n * Shared options for `walk`, `transform`, and `collect`.\n */\nexport type VisitorOptions = {\n depth?: VisitorDepth\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) 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 */\nexport async function walk(node: Node, visitor: AsyncVisitor, options: VisitorOptions = {}): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n\n switch (node.kind) {\n case 'Root':\n await visitor.root?.(node)\n break\n case 'Operation':\n await visitor.operation?.(node)\n break\n case 'Schema':\n await visitor.schema?.(node)\n break\n case 'Property':\n await visitor.property?.(node)\n break\n case 'Parameter':\n await visitor.parameter?.(node)\n break\n case 'Response':\n await visitor.response?.(node)\n break\n }\n\n for (const child of getChildren(node, recurse)) {\n await walk(child, visitor, options)\n }\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;AAcD,MAAa,aAAa;CACxB,iBAAiB;CACjB,gBAAgB;CAChB,2BAA2B;CAC3B,wBAAwB;CACxB,gBAAgB;CAChB,gBAAgB;CAChB,oBAAoB;CACpB,mBAAmB;CACnB,WAAW;CACX,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;CACX,aAAa;CACb,WAAW;CACX,UAAU;CACX;;;;;;AC7FD,SAAgB,WAAW,YAA6C,EAAE,EAAY;AACpF,QAAO;EACL,SAAS,EAAE;EACX,YAAY,EAAE;EACd,GAAG;EACH,MAAM;EACP;;;;;AAMH,SAAgB,gBACd,OACe;AACf,QAAO;EACL,MAAM,EAAE;EACR,YAAY,EAAE;EACd,WAAW,EAAE;EACb,GAAG;EACH,MAAM;EACP;;;;;AAMH,SAAgB,aAA6D,OAAkC;AAC7G,QAAO;EAAE,GAAG;EAAO,MAAM;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ACf,MAAM,WAAW,QAAQ,WAAW,SAAS;AAC7C,OAAI,SAAU,YAAW;AAEzB,UAAO;IACL,GAAG;IACH,QAAQ,SAAS,SAAS,UAAU,SAAS,QAAQ,SAAS,QAAQ,GAAG,KAAA;IAC1E;;;;;;;AAQP,SAAgB,QAAW,MAAY,SAA4B,UAA0B,EAAE,EAAY;CACzG,MAAM,WAAW,QAAQ,SAAS,cAAc,UAAU,cAAc;CACxE,MAAM,UAAoB,EAAE;CAE5B,IAAI;AACJ,SAAQ,KAAK,MAAb;EACE,KAAK;AACH,OAAI,QAAQ,OAAO,KAAK;AACxB;EACF,KAAK;AACH,OAAI,QAAQ,YAAY,KAAK;AAC7B;EACF,KAAK;AACH,OAAI,QAAQ,SAAS,KAAK;AAC1B;EACF,KAAK;AACH,OAAI,QAAQ,WAAW,KAAK;AAC5B;EACF,KAAK;AACH,OAAI,QAAQ,YAAY,KAAK;AAC7B;EACF,KAAK;AACH,OAAI,QAAQ,WAAW,KAAK;AAC5B;;AAEJ,KAAI,MAAM,KAAA,EAAW,SAAQ,KAAK,EAAE;AAEpC,MAAK,MAAM,SAAS,YAAY,MAAM,QAAQ,CAC5C,MAAK,MAAM,QAAQ,QAAQ,OAAO,SAAS,QAAQ,CACjD,SAAQ,KAAK,KAAK;AAItB,QAAO"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { $ as httpMethods, C as ResponseNode, H as SchemaNode, O as ParameterNode, S as OperationNode, U as SchemaNodeByType, Y as PropertyNode, _ as createRoot, a as collect, b as RootNode, d as resolveRef, et as mediaTypes, g as createResponse, h as createProperty, l as buildRefMap, m as createParameter, nt as schemaTypes, o as transform, p as createOperation, s as walk, tt as nodeKinds, u as refMapToObject, v as createSchema, y as Node } from "./visitor-dtVfQZwX.js";
2
+ import { C as OperationNode, U as SchemaNode, W as SchemaNodeByType, X as PropertyNode, _ as createRoot, a as collect, d as resolveRef, et as httpMethods, g as createResponse, h as createProperty, k as ParameterNode, l as buildRefMap, m as createParameter, nt as nodeKinds, o as transform, p as createOperation, rt as schemaTypes, s as walk, tt as mediaTypes, u as refMapToObject, v as createSchema, w as ResponseNode, x as RootNode, y as Node } from "./visitor-DRohZSfu.js";
3
3
 
4
4
  //#region src/guards.d.ts
5
5
  /**
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/constants.ts","../src/factory.ts","../src/guards.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 * 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 { 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 */\nexport function createSchema<T extends DistributiveOmit<SchemaNode, 'kind'>>(props: T): T & { kind: 'Schema' } {\n return { ...props, kind: 'Schema' } as T & { 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: Node): node is T => 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 { 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 } from './constants.ts'\nimport type { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode } from './nodes/index.ts'\n\n/**\n * Shared options for `walk`, `transform`, and `collect`.\n */\nexport type VisitorOptions = {\n depth?: VisitorDepth\n}\n\n/**\n * Synchronous visitor for `transform` and `walk`.\n */\nexport interface 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 interface 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 interface 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) 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 */\nexport async function walk(node: Node, visitor: AsyncVisitor, options: VisitorOptions = {}): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n\n switch (node.kind) {\n case 'Root':\n await visitor.root?.(node)\n break\n case 'Operation':\n await visitor.operation?.(node)\n break\n case 'Schema':\n await visitor.schema?.(node)\n break\n case 'Property':\n await visitor.property?.(node)\n break\n case 'Parameter':\n await visitor.parameter?.(node)\n break\n case 'Response':\n await visitor.response?.(node)\n break\n }\n\n for (const child of getChildren(node, recurse)) {\n await walk(child, visitor, options)\n }\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;AAcD,MAAa,aAAa;CACxB,iBAAiB;CACjB,gBAAgB;CAChB,2BAA2B;CAC3B,wBAAwB;CACxB,gBAAgB;CAChB,gBAAgB;CAChB,oBAAoB;CACpB,mBAAmB;CACnB,WAAW;CACX,UAAU;CACV,SAAS;CACT,SAAS;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.ts","../src/factory.ts","../src/guards.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 * 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 { 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 */\nexport function createSchema<T extends DistributiveOmit<SchemaNode, 'kind'>>(props: T): T & { kind: 'Schema' } {\n return { ...props, kind: 'Schema' } as T & { 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: Node): node is T => 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 { 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 } from './constants.ts'\nimport type { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode } from './nodes/index.ts'\n\n/**\n * Shared options for `walk`, `transform`, and `collect`.\n */\nexport type VisitorOptions = {\n depth?: VisitorDepth\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) 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 */\nexport async function walk(node: Node, visitor: AsyncVisitor, options: VisitorOptions = {}): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n\n switch (node.kind) {\n case 'Root':\n await visitor.root?.(node)\n break\n case 'Operation':\n await visitor.operation?.(node)\n break\n case 'Schema':\n await visitor.schema?.(node)\n break\n case 'Property':\n await visitor.property?.(node)\n break\n case 'Parameter':\n await visitor.parameter?.(node)\n break\n case 'Response':\n await visitor.response?.(node)\n break\n }\n\n for (const child of getChildren(node, recurse)) {\n await walk(child, visitor, options)\n }\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;AAcD,MAAa,aAAa;CACxB,iBAAiB;CACjB,gBAAgB;CAChB,2BAA2B;CAC3B,wBAAwB;CACxB,gBAAgB;CAChB,gBAAgB;CAChB,oBAAoB;CACpB,mBAAmB;CACnB,WAAW;CACX,UAAU;CACV,SAAS;CACT,SAAS;CACT,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;CACX,aAAa;CACb,WAAW;CACX,UAAU;CACX;;;;;;AC7FD,SAAgB,WAAW,YAA6C,EAAE,EAAY;AACpF,QAAO;EACL,SAAS,EAAE;EACX,YAAY,EAAE;EACd,GAAG;EACH,MAAM;EACP;;;;;AAMH,SAAgB,gBACd,OACe;AACf,QAAO;EACL,MAAM,EAAE;EACR,YAAY,EAAE;EACd,W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B,UAAO;IACL,GAAG;IACH,QAAQ,UAAU,MAAM,QAAQ,SAAS,QAAQ;IAClD;;EAEH,KAAK,YAAY;GACf,IAAI,WAAW;GACf,MAAM,WAAW,QAAQ,WAAW,SAAS;AAC7C,OAAI,SAAU,YAAW;AAEzB,UAAO;IACL,GAAG;IACH,QAAQ,SAAS,SAAS,UAAU,SAAS,QAAQ,SAAS,QAAQ,GAAG,KAAA;IAC1E;;;;;;;AAQP,SAAgB,QAAW,MAAY,SAA4B,UAA0B,EAAE,EAAY;CACzG,MAAM,WAAW,QAAQ,SAAS,cAAc,UAAU,cAAc;CACxE,MAAM,UAAoB,EAAE;CAE5B,IAAI;AACJ,SAAQ,KAAK,MAAb;EACE,KAAK;AACH,OAAI,QAAQ,OAAO,KAAK;AACxB;EACF,KAAK;AACH,OAAI,QAAQ,YAAY,KAAK;AAC7B;EACF,KAAK;AACH,OAAI,QAAQ,SAAS,KAAK;AAC1B;EACF,KAAK;AACH,OAAI,QAAQ,WAAW,KAAK;AAC5B;EACF,KAAK;AACH,OAAI,QAAQ,YAAY,KAAK;AAC7B;EACF,KAAK;AACH,OAAI,QAAQ,WAAW,KAAK;AAC5B;;AAEJ,KAAI,MAAM,KAAA,EAAW,SAAQ,KAAK,EAAE;AAEpC,MAAK,MAAM,SAAS,YAAY,MAAM,QAAQ,CAC5C,MAAK,MAAM,QAAQ,QAAQ,OAAO,SAAS,QAAQ,CACjD,SAAQ,KAAK,KAAK;AAItB,QAAO"}
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as ComplexSchemaType, B as ScalarSchemaNode, C as ResponseNode, D as ParameterLocation, E as StatusCode, F as IntersectionSchemaNode, G as SpecialSchemaType, H as SchemaNode, I as NumberSchemaNode, J as UnionSchemaNode, K as StringSchemaNode, L as ObjectSchemaNode, M as DatetimeSchemaNode, N as EnumSchemaNode, O as ParameterNode, P as EnumValueNode, Q as VisitorDepth, R as PrimitiveSchemaType, S as OperationNode, T as MediaType, U as SchemaNodeByType, V as ScalarSchemaType, W as SchemaType, X as BaseNode, Y as PropertyNode, Z as NodeKind, b as RootNode, c as RefMap, f as DistributiveOmit, i as VisitorOptions, j as DateSchemaNode, k as ArraySchemaNode, n as CollectVisitor, q as TimeSchemaNode, r as Visitor, t as AsyncVisitor, w as HttpStatusCode, x as HttpMethod, y as Node, z as RefSchemaNode } from "./visitor-dtVfQZwX.js";
2
- export { type ArraySchemaNode, type AsyncVisitor, type BaseNode, type CollectVisitor, type ComplexSchemaType, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type HttpMethod, type HttpStatusCode, type IntersectionSchemaNode, type MediaType, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type PrimitiveSchemaType, type PropertyNode, type RefMap, type RefSchemaNode, type ResponseNode, type RootNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TimeSchemaNode, type UnionSchemaNode, type Visitor, type VisitorDepth, type VisitorOptions };
1
+ import { $ as VisitorDepth, A as ArraySchemaNode, B as RefSchemaNode, C as OperationNode, D as StatusCode, E as MediaType, F as EnumValueNode, G as SchemaType, H as ScalarSchemaType, I as IntersectionSchemaNode, J as TimeSchemaNode, K as SpecialSchemaType, L as NumberSchemaNode, M as DateSchemaNode, N as DatetimeSchemaNode, O as ParameterLocation, P as EnumSchemaNode, Q as NodeKind, R as ObjectSchemaNode, S as HttpMethod, T as HttpStatusCode, U as SchemaNode, V as ScalarSchemaNode, W as SchemaNodeByType, X as PropertyNode, Y as UnionSchemaNode, Z as BaseNode, b as RootMeta, c as RefMap, f as DistributiveOmit, i as VisitorOptions, j as ComplexSchemaType, k as ParameterNode, n as CollectVisitor, q as StringSchemaNode, r as Visitor, t as AsyncVisitor, w as ResponseNode, x as RootNode, y as Node, z as PrimitiveSchemaType } from "./visitor-DRohZSfu.js";
2
+ export { type ArraySchemaNode, type AsyncVisitor, type BaseNode, type CollectVisitor, type ComplexSchemaType, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type HttpMethod, type HttpStatusCode, type IntersectionSchemaNode, type MediaType, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type PrimitiveSchemaType, type PropertyNode, type RefMap, type RefSchemaNode, type ResponseNode, type RootMeta, type RootNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TimeSchemaNode, type UnionSchemaNode, type Visitor, type VisitorDepth, type VisitorOptions };
@@ -87,20 +87,20 @@ type NodeKind = 'Root' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Re
87
87
  /**
88
88
  * Common base for all AST nodes.
89
89
  */
90
- interface BaseNode {
90
+ type BaseNode = {
91
91
  kind: NodeKind;
92
- }
92
+ };
93
93
  //#endregion
94
94
  //#region src/nodes/property.d.ts
95
95
  /**
96
96
  * A named property within an object schema.
97
97
  */
98
- interface PropertyNode extends BaseNode {
98
+ type PropertyNode = BaseNode & {
99
99
  kind: 'Property';
100
100
  name: string;
101
101
  schema: SchemaNode;
102
102
  required: boolean;
103
- }
103
+ };
104
104
  //#endregion
105
105
  //#region src/nodes/schema.d.ts
106
106
  type PrimitiveSchemaType = 'string' | 'number' | 'integer' | 'bigint' | 'boolean' | 'null' | 'any' | 'unknown' | 'void' | 'object' | 'array' | 'date';
@@ -114,7 +114,7 @@ type ScalarSchemaType = Exclude<SchemaType, 'object' | 'array' | 'tuple' | 'unio
114
114
  /**
115
115
  * Base fields shared by every schema variant. Does not include spec-specific fields.
116
116
  */
117
- interface SchemaNodeBase extends BaseNode {
117
+ type SchemaNodeBase = BaseNode & {
118
118
  kind: 'Schema';
119
119
  /**
120
120
  * Named schema identifier (e.g. `"Pet"` from `#/components/schemas/Pet`). `undefined` for inline schemas.
@@ -123,6 +123,7 @@ interface SchemaNodeBase extends BaseNode {
123
123
  title?: string;
124
124
  description?: string;
125
125
  nullable?: boolean;
126
+ optional?: boolean;
126
127
  /**
127
128
  * Both optional and nullable (`optional` + `nullable`).
128
129
  */
@@ -136,11 +137,11 @@ interface SchemaNodeBase extends BaseNode {
136
137
  * Underlying primitive before format/semantic promotion (e.g. `'string'` for a `uuid` node).
137
138
  */
138
139
  primitive?: PrimitiveSchemaType;
139
- }
140
+ };
140
141
  /**
141
142
  * Object schema with ordered property definitions.
142
143
  */
143
- interface ObjectSchemaNode extends SchemaNodeBase {
144
+ type ObjectSchemaNode = SchemaNodeBase & {
144
145
  type: 'object';
145
146
  properties?: Array<PropertyNode>;
146
147
  /**
@@ -148,11 +149,11 @@ interface ObjectSchemaNode extends SchemaNodeBase {
148
149
  */
149
150
  additionalProperties?: SchemaNode | true;
150
151
  patternProperties?: Record<string, SchemaNode>;
151
- }
152
+ };
152
153
  /**
153
154
  * Array or tuple schema.
154
155
  */
155
- interface ArraySchemaNode extends SchemaNodeBase {
156
+ type ArraySchemaNode = SchemaNodeBase & {
156
157
  type: 'array' | 'tuple';
157
158
  items?: Array<SchemaNode>;
158
159
  /**
@@ -162,41 +163,41 @@ interface ArraySchemaNode extends SchemaNodeBase {
162
163
  min?: number;
163
164
  max?: number;
164
165
  unique?: boolean;
165
- }
166
+ };
166
167
  /**
167
168
  * Shared base for union and intersection schemas.
168
169
  */
169
- interface CompositeSchemaNodeBase extends SchemaNodeBase {
170
+ type CompositeSchemaNodeBase = SchemaNodeBase & {
170
171
  members?: Array<SchemaNode>;
171
- }
172
+ };
172
173
  /**
173
174
  * Union schema (`oneOf` / `anyOf`).
174
175
  */
175
- interface UnionSchemaNode extends CompositeSchemaNodeBase {
176
+ type UnionSchemaNode = CompositeSchemaNodeBase & {
176
177
  type: 'union';
177
178
  /**
178
179
  * Discriminator property from OAS `discriminator.propertyName`.
179
180
  */
180
181
  discriminatorPropertyName?: string;
181
- }
182
+ };
182
183
  /**
183
184
  * Intersection schema (`allOf`).
184
185
  */
185
- interface IntersectionSchemaNode extends CompositeSchemaNodeBase {
186
+ type IntersectionSchemaNode = CompositeSchemaNodeBase & {
186
187
  type: 'intersection';
187
- }
188
+ };
188
189
  /**
189
190
  * A named enum variant.
190
191
  */
191
- interface EnumValueNode {
192
+ type EnumValueNode = {
192
193
  name: string;
193
194
  value: string | number | boolean;
194
195
  format: 'string' | 'number' | 'boolean';
195
- }
196
+ };
196
197
  /**
197
198
  * Enum schema.
198
199
  */
199
- interface EnumSchemaNode extends SchemaNodeBase {
200
+ type EnumSchemaNode = SchemaNodeBase & {
200
201
  type: 'enum';
201
202
  /**
202
203
  * Enum member type. Generators should use const assertions for `'number'` / `'boolean'`.
@@ -210,11 +211,11 @@ interface EnumSchemaNode extends SchemaNodeBase {
210
211
  * Named variants (rich form). Takes priority over `enumValues` when present.
211
212
  */
212
213
  namedEnumValues?: Array<EnumValueNode>;
213
- }
214
+ };
214
215
  /**
215
216
  * Ref schema — pointer to another schema definition.
216
217
  */
217
- interface RefSchemaNode extends SchemaNodeBase {
218
+ type RefSchemaNode = SchemaNodeBase & {
218
219
  type: 'ref';
219
220
  name?: string;
220
221
  /**
@@ -225,11 +226,11 @@ interface RefSchemaNode extends SchemaNodeBase {
225
226
  * Pattern constraint propagated from a sibling `pattern` field next to the `$ref`.
226
227
  */
227
228
  pattern?: string;
228
- }
229
+ };
229
230
  /**
230
231
  * Datetime schema.
231
232
  */
232
- interface DatetimeSchemaNode extends SchemaNodeBase {
233
+ type DatetimeSchemaNode = SchemaNodeBase & {
233
234
  type: 'datetime';
234
235
  /**
235
236
  * Includes timezone offset (`dateType: 'stringOffset'`).
@@ -239,17 +240,17 @@ interface DatetimeSchemaNode extends SchemaNodeBase {
239
240
  * Local datetime without timezone (`dateType: 'stringLocal'`).
240
241
  */
241
242
  local?: boolean;
242
- }
243
+ };
243
244
  /**
244
245
  * Base for `date` and `time` schemas.
245
246
  */
246
- interface TemporalSchemaNodeBase<T extends 'date' | 'time'> extends SchemaNodeBase {
247
+ type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
247
248
  type: T;
248
249
  /**
249
250
  * Representation in generated code: native `Date` or plain string.
250
251
  */
251
252
  representation: 'date' | 'string';
252
- }
253
+ };
253
254
  /**
254
255
  * Date schema.
255
256
  */
@@ -261,28 +262,28 @@ type TimeSchemaNode = TemporalSchemaNodeBase<'time'>;
261
262
  /**
262
263
  * String schema.
263
264
  */
264
- interface StringSchemaNode extends SchemaNodeBase {
265
+ type StringSchemaNode = SchemaNodeBase & {
265
266
  type: 'string';
266
267
  min?: number;
267
268
  max?: number;
268
269
  pattern?: string;
269
- }
270
+ };
270
271
  /**
271
272
  * Number, integer, or bigint schema.
272
273
  */
273
- interface NumberSchemaNode extends SchemaNodeBase {
274
+ type NumberSchemaNode = SchemaNodeBase & {
274
275
  type: 'number' | 'integer' | 'bigint';
275
276
  min?: number;
276
277
  max?: number;
277
278
  exclusiveMinimum?: number;
278
279
  exclusiveMaximum?: number;
279
- }
280
+ };
280
281
  /**
281
282
  * Schema for scalar types with no additional constraints.
282
283
  */
283
- interface ScalarSchemaNode extends SchemaNodeBase {
284
+ type ScalarSchemaNode = SchemaNodeBase & {
284
285
  type: ScalarSchemaType;
285
- }
286
+ };
286
287
  /**
287
288
  * Maps each schema type string to its `SchemaNode` variant. Used by `narrowSchema`.
288
289
  */
@@ -321,13 +322,13 @@ type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
321
322
  /**
322
323
  * A single input parameter for an operation.
323
324
  */
324
- interface ParameterNode extends BaseNode {
325
+ type ParameterNode = BaseNode & {
325
326
  kind: 'Parameter';
326
327
  name: string;
327
328
  in: ParameterLocation;
328
329
  schema: SchemaNode;
329
330
  required: boolean;
330
- }
331
+ };
331
332
  //#endregion
332
333
  //#region src/nodes/http.d.ts
333
334
  /**
@@ -349,7 +350,7 @@ type MediaType = 'application/json' | 'application/xml' | 'application/x-www-for
349
350
  /**
350
351
  * A single response variant for an operation.
351
352
  */
352
- interface ResponseNode extends BaseNode {
353
+ type ResponseNode = BaseNode & {
353
354
  kind: 'Response';
354
355
  /**
355
356
  * HTTP status code or `'default'` for a fallback response.
@@ -358,14 +359,14 @@ interface ResponseNode extends BaseNode {
358
359
  description?: string;
359
360
  schema?: SchemaNode;
360
361
  mediaType?: MediaType;
361
- }
362
+ };
362
363
  //#endregion
363
364
  //#region src/nodes/operation.d.ts
364
365
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
365
366
  /**
366
367
  * A spec-agnostic representation of a single API operation.
367
368
  */
368
- interface OperationNode extends BaseNode {
369
+ type OperationNode = BaseNode & {
369
370
  kind: 'Operation';
370
371
  /**
371
372
  * Unique operation identifier (maps to `operationId` in OAS).
@@ -383,17 +384,33 @@ interface OperationNode extends BaseNode {
383
384
  */
384
385
  requestBody?: SchemaNode;
385
386
  responses: Array<ResponseNode>;
386
- }
387
+ };
387
388
  //#endregion
388
389
  //#region src/nodes/root.d.ts
390
+ /**
391
+ * Format-agnostic metadata about the API document.
392
+ * Adapters populate whichever fields are available in their source format.
393
+ */
394
+ type RootMeta = {
395
+ /** API title (from `info.title` in OAS/AsyncAPI). */title?: string; /** API version string (from `info.version` in OAS/AsyncAPI). */
396
+ version?: string;
397
+ /**
398
+ * Resolved base URL for the API.
399
+ * OAS: derived from `servers[serverIndex].url` with variable substitution.
400
+ * AsyncAPI: derived from `servers[serverIndex].url`.
401
+ * Drizzle / schema-only formats: not set.
402
+ */
403
+ baseURL?: string;
404
+ };
389
405
  /**
390
406
  * Top-level container for all schemas and operations in a single API document.
391
407
  */
392
- interface RootNode extends BaseNode {
408
+ type RootNode = BaseNode & {
393
409
  kind: 'Root';
394
410
  schemas: Array<SchemaNode>;
395
- operations: Array<OperationNode>;
396
- }
411
+ operations: Array<OperationNode>; /** Format-agnostic document metadata populated by the adapter. */
412
+ meta?: RootMeta;
413
+ };
397
414
  //#endregion
398
415
  //#region src/nodes/index.d.ts
399
416
  /**
@@ -465,37 +482,37 @@ type VisitorOptions = {
465
482
  /**
466
483
  * Synchronous visitor for `transform` and `walk`.
467
484
  */
468
- interface Visitor {
485
+ type Visitor = {
469
486
  root?(node: RootNode): void | RootNode;
470
487
  operation?(node: OperationNode): void | OperationNode;
471
488
  schema?(node: SchemaNode): void | SchemaNode;
472
489
  property?(node: PropertyNode): void | PropertyNode;
473
490
  parameter?(node: ParameterNode): void | ParameterNode;
474
491
  response?(node: ResponseNode): void | ResponseNode;
475
- }
492
+ };
476
493
  type MaybePromise<T> = T | Promise<T>;
477
494
  /**
478
495
  * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
479
496
  */
480
- interface AsyncVisitor {
497
+ type AsyncVisitor = {
481
498
  root?(node: RootNode): MaybePromise<void | RootNode>;
482
499
  operation?(node: OperationNode): MaybePromise<void | OperationNode>;
483
500
  schema?(node: SchemaNode): MaybePromise<void | SchemaNode>;
484
501
  property?(node: PropertyNode): MaybePromise<void | PropertyNode>;
485
502
  parameter?(node: ParameterNode): MaybePromise<void | ParameterNode>;
486
503
  response?(node: ResponseNode): MaybePromise<void | ResponseNode>;
487
- }
504
+ };
488
505
  /**
489
506
  * Visitor for `collect`.
490
507
  */
491
- interface CollectVisitor<T> {
508
+ type CollectVisitor<T> = {
492
509
  root?(node: RootNode): T | undefined;
493
510
  operation?(node: OperationNode): T | undefined;
494
511
  schema?(node: SchemaNode): T | undefined;
495
512
  property?(node: PropertyNode): T | undefined;
496
513
  parameter?(node: ParameterNode): T | undefined;
497
514
  response?(node: ResponseNode): T | undefined;
498
- }
515
+ };
499
516
  /**
500
517
  * Depth-first traversal for side effects. Visitor return values are ignored.
501
518
  */
@@ -515,5 +532,5 @@ declare function transform(node: Node, visitor: Visitor, options?: VisitorOption
515
532
  */
516
533
  declare function collect<T>(node: Node, visitor: CollectVisitor<T>, options?: VisitorOptions): Array<T>;
517
534
  //#endregion
518
- export { httpMethods as $, ComplexSchemaType as A, ScalarSchemaNode as B, ResponseNode as C, ParameterLocation as D, StatusCode as E, IntersectionSchemaNode as F, SpecialSchemaType as G, SchemaNode as H, NumberSchemaNode as I, UnionSchemaNode as J, StringSchemaNode as K, ObjectSchemaNode as L, DatetimeSchemaNode as M, EnumSchemaNode as N, ParameterNode as O, EnumValueNode as P, VisitorDepth as Q, PrimitiveSchemaType as R, OperationNode as S, MediaType as T, SchemaNodeByType as U, ScalarSchemaType as V, SchemaType as W, BaseNode as X, PropertyNode as Y, NodeKind as Z, createRoot as _, collect as a, RootNode as b, RefMap as c, resolveRef as d, mediaTypes as et, DistributiveOmit as f, createResponse as g, createProperty as h, VisitorOptions as i, DateSchemaNode as j, ArraySchemaNode as k, buildRefMap as l, createParameter as m, CollectVisitor as n, schemaTypes as nt, transform as o, createOperation as p, TimeSchemaNode as q, Visitor as r, walk as s, AsyncVisitor as t, nodeKinds as tt, refMapToObject as u, createSchema as v, HttpStatusCode as w, HttpMethod as x, Node as y, RefSchemaNode as z };
519
- //# sourceMappingURL=visitor-dtVfQZwX.d.ts.map
535
+ export { VisitorDepth as $, ArraySchemaNode as A, RefSchemaNode as B, OperationNode as C, StatusCode as D, MediaType as E, EnumValueNode as F, SchemaType as G, ScalarSchemaType as H, IntersectionSchemaNode as I, TimeSchemaNode as J, SpecialSchemaType as K, NumberSchemaNode as L, DateSchemaNode as M, DatetimeSchemaNode as N, ParameterLocation as O, EnumSchemaNode as P, NodeKind as Q, ObjectSchemaNode as R, HttpMethod as S, HttpStatusCode as T, SchemaNode as U, ScalarSchemaNode as V, SchemaNodeByType as W, PropertyNode as X, UnionSchemaNode as Y, BaseNode as Z, createRoot as _, collect as a, RootMeta as b, RefMap as c, resolveRef as d, httpMethods as et, DistributiveOmit as f, createResponse as g, createProperty as h, VisitorOptions as i, ComplexSchemaType as j, ParameterNode as k, buildRefMap as l, createParameter as m, CollectVisitor as n, nodeKinds as nt, transform as o, createOperation as p, StringSchemaNode as q, Visitor as r, schemaTypes as rt, walk as s, AsyncVisitor as t, mediaTypes as tt, refMapToObject as u, createSchema as v, ResponseNode as w, RootNode as x, Node as y, PrimitiveSchemaType as z };
536
+ //# sourceMappingURL=visitor-DRohZSfu.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/ast",
3
- "version": "4.33.3",
3
+ "version": "4.34.0",
4
4
  "description": "Spec-agnostic AST layer for Kubb. Defines nodes, visitor pattern, and factory functions used across codegen plugins.",
5
5
  "keywords": [
6
6
  "kubb",
package/src/nodes/base.ts CHANGED
@@ -6,7 +6,7 @@ export type NodeKind = 'Root' | 'Operation' | 'Schema' | 'Property' | 'Parameter
6
6
  /**
7
7
  * Common base for all AST nodes.
8
8
  */
9
- export interface BaseNode {
9
+ export type BaseNode = {
10
10
  kind: NodeKind
11
11
  }
12
12
 
@@ -11,7 +11,7 @@ export type { HttpMethod, OperationNode } from './operation.ts'
11
11
  export type { ParameterLocation, ParameterNode } from './parameter.ts'
12
12
  export type { PropertyNode } from './property.ts'
13
13
  export type { ResponseNode } from './response.ts'
14
- export type { RootNode } from './root.ts'
14
+ export type { RootMeta, RootNode } from './root.ts'
15
15
  export type {
16
16
  ArraySchemaNode,
17
17
  ComplexSchemaType,
@@ -8,7 +8,7 @@ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' |
8
8
  /**
9
9
  * A spec-agnostic representation of a single API operation.
10
10
  */
11
- export interface OperationNode extends BaseNode {
11
+ export type OperationNode = BaseNode & {
12
12
  kind: 'Operation'
13
13
  /**
14
14
  * Unique operation identifier (maps to `operationId` in OAS).
@@ -6,7 +6,7 @@ export type ParameterLocation = 'path' | 'query' | 'header' | 'cookie'
6
6
  /**
7
7
  * A single input parameter for an operation.
8
8
  */
9
- export interface ParameterNode extends BaseNode {
9
+ export type ParameterNode = BaseNode & {
10
10
  kind: 'Parameter'
11
11
  name: string
12
12
  in: ParameterLocation
@@ -4,7 +4,7 @@ import type { SchemaNode } from './schema.ts'
4
4
  /**
5
5
  * A named property within an object schema.
6
6
  */
7
- export interface PropertyNode extends BaseNode {
7
+ export type PropertyNode = BaseNode & {
8
8
  kind: 'Property'
9
9
  name: string
10
10
  schema: SchemaNode
@@ -5,7 +5,7 @@ import type { SchemaNode } from './schema.ts'
5
5
  /**
6
6
  * A single response variant for an operation.
7
7
  */
8
- export interface ResponseNode extends BaseNode {
8
+ export type ResponseNode = BaseNode & {
9
9
  kind: 'Response'
10
10
  /**
11
11
  * HTTP status code or `'default'` for a fallback response.
package/src/nodes/root.ts CHANGED
@@ -2,11 +2,31 @@ import type { BaseNode } from './base.ts'
2
2
  import type { OperationNode } from './operation.ts'
3
3
  import type { SchemaNode } from './schema.ts'
4
4
 
5
+ /**
6
+ * Format-agnostic metadata about the API document.
7
+ * Adapters populate whichever fields are available in their source format.
8
+ */
9
+ export type RootMeta = {
10
+ /** API title (from `info.title` in OAS/AsyncAPI). */
11
+ title?: string
12
+ /** API version string (from `info.version` in OAS/AsyncAPI). */
13
+ version?: string
14
+ /**
15
+ * Resolved base URL for the API.
16
+ * OAS: derived from `servers[serverIndex].url` with variable substitution.
17
+ * AsyncAPI: derived from `servers[serverIndex].url`.
18
+ * Drizzle / schema-only formats: not set.
19
+ */
20
+ baseURL?: string
21
+ }
22
+
5
23
  /**
6
24
  * Top-level container for all schemas and operations in a single API document.
7
25
  */
8
- export interface RootNode extends BaseNode {
26
+ export type RootNode = BaseNode & {
9
27
  kind: 'Root'
10
28
  schemas: Array<SchemaNode>
11
29
  operations: Array<OperationNode>
30
+ /** Format-agnostic document metadata populated by the adapter. */
31
+ meta?: RootMeta
12
32
  }
@@ -20,7 +20,7 @@ export type ScalarSchemaType = Exclude<
20
20
  /**
21
21
  * Base fields shared by every schema variant. Does not include spec-specific fields.
22
22
  */
23
- interface SchemaNodeBase extends BaseNode {
23
+ type SchemaNodeBase = BaseNode & {
24
24
  kind: 'Schema'
25
25
  /**
26
26
  * Named schema identifier (e.g. `"Pet"` from `#/components/schemas/Pet`). `undefined` for inline schemas.
@@ -29,6 +29,7 @@ interface SchemaNodeBase extends BaseNode {
29
29
  title?: string
30
30
  description?: string
31
31
  nullable?: boolean
32
+ optional?: boolean
32
33
  /**
33
34
  * Both optional and nullable (`optional` + `nullable`).
34
35
  */
@@ -47,7 +48,7 @@ interface SchemaNodeBase extends BaseNode {
47
48
  /**
48
49
  * Object schema with ordered property definitions.
49
50
  */
50
- export interface ObjectSchemaNode extends SchemaNodeBase {
51
+ export type ObjectSchemaNode = SchemaNodeBase & {
51
52
  type: 'object'
52
53
  properties?: Array<PropertyNode>
53
54
  /**
@@ -60,7 +61,7 @@ export interface ObjectSchemaNode extends SchemaNodeBase {
60
61
  /**
61
62
  * Array or tuple schema.
62
63
  */
63
- export interface ArraySchemaNode extends SchemaNodeBase {
64
+ export type ArraySchemaNode = SchemaNodeBase & {
64
65
  type: 'array' | 'tuple'
65
66
  items?: Array<SchemaNode>
66
67
  /**
@@ -75,14 +76,14 @@ export interface ArraySchemaNode extends SchemaNodeBase {
75
76
  /**
76
77
  * Shared base for union and intersection schemas.
77
78
  */
78
- interface CompositeSchemaNodeBase extends SchemaNodeBase {
79
+ type CompositeSchemaNodeBase = SchemaNodeBase & {
79
80
  members?: Array<SchemaNode>
80
81
  }
81
82
 
82
83
  /**
83
84
  * Union schema (`oneOf` / `anyOf`).
84
85
  */
85
- export interface UnionSchemaNode extends CompositeSchemaNodeBase {
86
+ export type UnionSchemaNode = CompositeSchemaNodeBase & {
86
87
  type: 'union'
87
88
  /**
88
89
  * Discriminator property from OAS `discriminator.propertyName`.
@@ -93,14 +94,14 @@ export interface UnionSchemaNode extends CompositeSchemaNodeBase {
93
94
  /**
94
95
  * Intersection schema (`allOf`).
95
96
  */
96
- export interface IntersectionSchemaNode extends CompositeSchemaNodeBase {
97
+ export type IntersectionSchemaNode = CompositeSchemaNodeBase & {
97
98
  type: 'intersection'
98
99
  }
99
100
 
100
101
  /**
101
102
  * A named enum variant.
102
103
  */
103
- export interface EnumValueNode {
104
+ export type EnumValueNode = {
104
105
  name: string
105
106
  value: string | number | boolean
106
107
  format: 'string' | 'number' | 'boolean'
@@ -109,7 +110,7 @@ export interface EnumValueNode {
109
110
  /**
110
111
  * Enum schema.
111
112
  */
112
- export interface EnumSchemaNode extends SchemaNodeBase {
113
+ export type EnumSchemaNode = SchemaNodeBase & {
113
114
  type: 'enum'
114
115
  /**
115
116
  * Enum member type. Generators should use const assertions for `'number'` / `'boolean'`.
@@ -128,7 +129,7 @@ export interface EnumSchemaNode extends SchemaNodeBase {
128
129
  /**
129
130
  * Ref schema — pointer to another schema definition.
130
131
  */
131
- export interface RefSchemaNode extends SchemaNodeBase {
132
+ export type RefSchemaNode = SchemaNodeBase & {
132
133
  type: 'ref'
133
134
  name?: string
134
135
  /**
@@ -144,7 +145,7 @@ export interface RefSchemaNode extends SchemaNodeBase {
144
145
  /**
145
146
  * Datetime schema.
146
147
  */
147
- export interface DatetimeSchemaNode extends SchemaNodeBase {
148
+ export type DatetimeSchemaNode = SchemaNodeBase & {
148
149
  type: 'datetime'
149
150
  /**
150
151
  * Includes timezone offset (`dateType: 'stringOffset'`).
@@ -159,7 +160,7 @@ export interface DatetimeSchemaNode extends SchemaNodeBase {
159
160
  /**
160
161
  * Base for `date` and `time` schemas.
161
162
  */
162
- interface TemporalSchemaNodeBase<T extends 'date' | 'time'> extends SchemaNodeBase {
163
+ type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
163
164
  type: T
164
165
  /**
165
166
  * Representation in generated code: native `Date` or plain string.
@@ -180,7 +181,7 @@ export type TimeSchemaNode = TemporalSchemaNodeBase<'time'>
180
181
  /**
181
182
  * String schema.
182
183
  */
183
- export interface StringSchemaNode extends SchemaNodeBase {
184
+ export type StringSchemaNode = SchemaNodeBase & {
184
185
  type: 'string'
185
186
  min?: number
186
187
  max?: number
@@ -190,7 +191,7 @@ export interface StringSchemaNode extends SchemaNodeBase {
190
191
  /**
191
192
  * Number, integer, or bigint schema.
192
193
  */
193
- export interface NumberSchemaNode extends SchemaNodeBase {
194
+ export type NumberSchemaNode = SchemaNodeBase & {
194
195
  type: 'number' | 'integer' | 'bigint'
195
196
  min?: number
196
197
  max?: number
@@ -201,7 +202,7 @@ export interface NumberSchemaNode extends SchemaNodeBase {
201
202
  /**
202
203
  * Schema for scalar types with no additional constraints.
203
204
  */
204
- export interface ScalarSchemaNode extends SchemaNodeBase {
205
+ export type ScalarSchemaNode = SchemaNodeBase & {
205
206
  type: ScalarSchemaType
206
207
  }
207
208
 
package/src/types.ts CHANGED
@@ -23,6 +23,7 @@ export type {
23
23
  PropertyNode,
24
24
  RefSchemaNode,
25
25
  ResponseNode,
26
+ RootMeta,
26
27
  RootNode,
27
28
  ScalarSchemaNode,
28
29
  ScalarSchemaType,
package/src/visitor.ts CHANGED
@@ -12,7 +12,7 @@ export type VisitorOptions = {
12
12
  /**
13
13
  * Synchronous visitor for `transform` and `walk`.
14
14
  */
15
- export interface Visitor {
15
+ export type Visitor = {
16
16
  root?(node: RootNode): void | RootNode
17
17
  operation?(node: OperationNode): void | OperationNode
18
18
  schema?(node: SchemaNode): void | SchemaNode
@@ -26,7 +26,7 @@ type MaybePromise<T> = T | Promise<T>
26
26
  /**
27
27
  * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
28
28
  */
29
- export interface AsyncVisitor {
29
+ export type AsyncVisitor = {
30
30
  root?(node: RootNode): MaybePromise<void | RootNode>
31
31
  operation?(node: OperationNode): MaybePromise<void | OperationNode>
32
32
  schema?(node: SchemaNode): MaybePromise<void | SchemaNode>
@@ -38,7 +38,7 @@ export interface AsyncVisitor {
38
38
  /**
39
39
  * Visitor for `collect`.
40
40
  */
41
- export interface CollectVisitor<T> {
41
+ export type CollectVisitor<T> = {
42
42
  root?(node: RootNode): T | undefined
43
43
  operation?(node: OperationNode): T | undefined
44
44
  schema?(node: SchemaNode): T | undefined