@kubb/ast 4.33.5 → 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.
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/{visitor-D9_Eb8I1.d.ts → visitor-DRohZSfu.d.ts} +65 -49
- package/package.json +1 -1
- package/src/nodes/base.ts +1 -1
- package/src/nodes/index.ts +1 -1
- package/src/nodes/operation.ts +1 -1
- package/src/nodes/parameter.ts +1 -1
- package/src/nodes/property.ts +1 -1
- package/src/nodes/response.ts +1 -1
- package/src/nodes/root.ts +21 -1
- package/src/nodes/schema.ts +14 -14
- package/src/types.ts +1 -0
- package/src/visitor.ts +3 -3
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/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,K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H,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;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AO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
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,KAA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,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.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 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,UA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
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
@@ -137,11 +137,11 @@ interface SchemaNodeBase extends BaseNode {
|
|
|
137
137
|
* Underlying primitive before format/semantic promotion (e.g. `'string'` for a `uuid` node).
|
|
138
138
|
*/
|
|
139
139
|
primitive?: PrimitiveSchemaType;
|
|
140
|
-
}
|
|
140
|
+
};
|
|
141
141
|
/**
|
|
142
142
|
* Object schema with ordered property definitions.
|
|
143
143
|
*/
|
|
144
|
-
|
|
144
|
+
type ObjectSchemaNode = SchemaNodeBase & {
|
|
145
145
|
type: 'object';
|
|
146
146
|
properties?: Array<PropertyNode>;
|
|
147
147
|
/**
|
|
@@ -149,11 +149,11 @@ interface ObjectSchemaNode extends SchemaNodeBase {
|
|
|
149
149
|
*/
|
|
150
150
|
additionalProperties?: SchemaNode | true;
|
|
151
151
|
patternProperties?: Record<string, SchemaNode>;
|
|
152
|
-
}
|
|
152
|
+
};
|
|
153
153
|
/**
|
|
154
154
|
* Array or tuple schema.
|
|
155
155
|
*/
|
|
156
|
-
|
|
156
|
+
type ArraySchemaNode = SchemaNodeBase & {
|
|
157
157
|
type: 'array' | 'tuple';
|
|
158
158
|
items?: Array<SchemaNode>;
|
|
159
159
|
/**
|
|
@@ -163,41 +163,41 @@ interface ArraySchemaNode extends SchemaNodeBase {
|
|
|
163
163
|
min?: number;
|
|
164
164
|
max?: number;
|
|
165
165
|
unique?: boolean;
|
|
166
|
-
}
|
|
166
|
+
};
|
|
167
167
|
/**
|
|
168
168
|
* Shared base for union and intersection schemas.
|
|
169
169
|
*/
|
|
170
|
-
|
|
170
|
+
type CompositeSchemaNodeBase = SchemaNodeBase & {
|
|
171
171
|
members?: Array<SchemaNode>;
|
|
172
|
-
}
|
|
172
|
+
};
|
|
173
173
|
/**
|
|
174
174
|
* Union schema (`oneOf` / `anyOf`).
|
|
175
175
|
*/
|
|
176
|
-
|
|
176
|
+
type UnionSchemaNode = CompositeSchemaNodeBase & {
|
|
177
177
|
type: 'union';
|
|
178
178
|
/**
|
|
179
179
|
* Discriminator property from OAS `discriminator.propertyName`.
|
|
180
180
|
*/
|
|
181
181
|
discriminatorPropertyName?: string;
|
|
182
|
-
}
|
|
182
|
+
};
|
|
183
183
|
/**
|
|
184
184
|
* Intersection schema (`allOf`).
|
|
185
185
|
*/
|
|
186
|
-
|
|
186
|
+
type IntersectionSchemaNode = CompositeSchemaNodeBase & {
|
|
187
187
|
type: 'intersection';
|
|
188
|
-
}
|
|
188
|
+
};
|
|
189
189
|
/**
|
|
190
190
|
* A named enum variant.
|
|
191
191
|
*/
|
|
192
|
-
|
|
192
|
+
type EnumValueNode = {
|
|
193
193
|
name: string;
|
|
194
194
|
value: string | number | boolean;
|
|
195
195
|
format: 'string' | 'number' | 'boolean';
|
|
196
|
-
}
|
|
196
|
+
};
|
|
197
197
|
/**
|
|
198
198
|
* Enum schema.
|
|
199
199
|
*/
|
|
200
|
-
|
|
200
|
+
type EnumSchemaNode = SchemaNodeBase & {
|
|
201
201
|
type: 'enum';
|
|
202
202
|
/**
|
|
203
203
|
* Enum member type. Generators should use const assertions for `'number'` / `'boolean'`.
|
|
@@ -211,11 +211,11 @@ interface EnumSchemaNode extends SchemaNodeBase {
|
|
|
211
211
|
* Named variants (rich form). Takes priority over `enumValues` when present.
|
|
212
212
|
*/
|
|
213
213
|
namedEnumValues?: Array<EnumValueNode>;
|
|
214
|
-
}
|
|
214
|
+
};
|
|
215
215
|
/**
|
|
216
216
|
* Ref schema — pointer to another schema definition.
|
|
217
217
|
*/
|
|
218
|
-
|
|
218
|
+
type RefSchemaNode = SchemaNodeBase & {
|
|
219
219
|
type: 'ref';
|
|
220
220
|
name?: string;
|
|
221
221
|
/**
|
|
@@ -226,11 +226,11 @@ interface RefSchemaNode extends SchemaNodeBase {
|
|
|
226
226
|
* Pattern constraint propagated from a sibling `pattern` field next to the `$ref`.
|
|
227
227
|
*/
|
|
228
228
|
pattern?: string;
|
|
229
|
-
}
|
|
229
|
+
};
|
|
230
230
|
/**
|
|
231
231
|
* Datetime schema.
|
|
232
232
|
*/
|
|
233
|
-
|
|
233
|
+
type DatetimeSchemaNode = SchemaNodeBase & {
|
|
234
234
|
type: 'datetime';
|
|
235
235
|
/**
|
|
236
236
|
* Includes timezone offset (`dateType: 'stringOffset'`).
|
|
@@ -240,17 +240,17 @@ interface DatetimeSchemaNode extends SchemaNodeBase {
|
|
|
240
240
|
* Local datetime without timezone (`dateType: 'stringLocal'`).
|
|
241
241
|
*/
|
|
242
242
|
local?: boolean;
|
|
243
|
-
}
|
|
243
|
+
};
|
|
244
244
|
/**
|
|
245
245
|
* Base for `date` and `time` schemas.
|
|
246
246
|
*/
|
|
247
|
-
|
|
247
|
+
type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
|
|
248
248
|
type: T;
|
|
249
249
|
/**
|
|
250
250
|
* Representation in generated code: native `Date` or plain string.
|
|
251
251
|
*/
|
|
252
252
|
representation: 'date' | 'string';
|
|
253
|
-
}
|
|
253
|
+
};
|
|
254
254
|
/**
|
|
255
255
|
* Date schema.
|
|
256
256
|
*/
|
|
@@ -262,28 +262,28 @@ type TimeSchemaNode = TemporalSchemaNodeBase<'time'>;
|
|
|
262
262
|
/**
|
|
263
263
|
* String schema.
|
|
264
264
|
*/
|
|
265
|
-
|
|
265
|
+
type StringSchemaNode = SchemaNodeBase & {
|
|
266
266
|
type: 'string';
|
|
267
267
|
min?: number;
|
|
268
268
|
max?: number;
|
|
269
269
|
pattern?: string;
|
|
270
|
-
}
|
|
270
|
+
};
|
|
271
271
|
/**
|
|
272
272
|
* Number, integer, or bigint schema.
|
|
273
273
|
*/
|
|
274
|
-
|
|
274
|
+
type NumberSchemaNode = SchemaNodeBase & {
|
|
275
275
|
type: 'number' | 'integer' | 'bigint';
|
|
276
276
|
min?: number;
|
|
277
277
|
max?: number;
|
|
278
278
|
exclusiveMinimum?: number;
|
|
279
279
|
exclusiveMaximum?: number;
|
|
280
|
-
}
|
|
280
|
+
};
|
|
281
281
|
/**
|
|
282
282
|
* Schema for scalar types with no additional constraints.
|
|
283
283
|
*/
|
|
284
|
-
|
|
284
|
+
type ScalarSchemaNode = SchemaNodeBase & {
|
|
285
285
|
type: ScalarSchemaType;
|
|
286
|
-
}
|
|
286
|
+
};
|
|
287
287
|
/**
|
|
288
288
|
* Maps each schema type string to its `SchemaNode` variant. Used by `narrowSchema`.
|
|
289
289
|
*/
|
|
@@ -322,13 +322,13 @@ type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
|
|
|
322
322
|
/**
|
|
323
323
|
* A single input parameter for an operation.
|
|
324
324
|
*/
|
|
325
|
-
|
|
325
|
+
type ParameterNode = BaseNode & {
|
|
326
326
|
kind: 'Parameter';
|
|
327
327
|
name: string;
|
|
328
328
|
in: ParameterLocation;
|
|
329
329
|
schema: SchemaNode;
|
|
330
330
|
required: boolean;
|
|
331
|
-
}
|
|
331
|
+
};
|
|
332
332
|
//#endregion
|
|
333
333
|
//#region src/nodes/http.d.ts
|
|
334
334
|
/**
|
|
@@ -350,7 +350,7 @@ type MediaType = 'application/json' | 'application/xml' | 'application/x-www-for
|
|
|
350
350
|
/**
|
|
351
351
|
* A single response variant for an operation.
|
|
352
352
|
*/
|
|
353
|
-
|
|
353
|
+
type ResponseNode = BaseNode & {
|
|
354
354
|
kind: 'Response';
|
|
355
355
|
/**
|
|
356
356
|
* HTTP status code or `'default'` for a fallback response.
|
|
@@ -359,14 +359,14 @@ interface ResponseNode extends BaseNode {
|
|
|
359
359
|
description?: string;
|
|
360
360
|
schema?: SchemaNode;
|
|
361
361
|
mediaType?: MediaType;
|
|
362
|
-
}
|
|
362
|
+
};
|
|
363
363
|
//#endregion
|
|
364
364
|
//#region src/nodes/operation.d.ts
|
|
365
365
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
|
|
366
366
|
/**
|
|
367
367
|
* A spec-agnostic representation of a single API operation.
|
|
368
368
|
*/
|
|
369
|
-
|
|
369
|
+
type OperationNode = BaseNode & {
|
|
370
370
|
kind: 'Operation';
|
|
371
371
|
/**
|
|
372
372
|
* Unique operation identifier (maps to `operationId` in OAS).
|
|
@@ -384,17 +384,33 @@ interface OperationNode extends BaseNode {
|
|
|
384
384
|
*/
|
|
385
385
|
requestBody?: SchemaNode;
|
|
386
386
|
responses: Array<ResponseNode>;
|
|
387
|
-
}
|
|
387
|
+
};
|
|
388
388
|
//#endregion
|
|
389
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
|
+
};
|
|
390
405
|
/**
|
|
391
406
|
* Top-level container for all schemas and operations in a single API document.
|
|
392
407
|
*/
|
|
393
|
-
|
|
408
|
+
type RootNode = BaseNode & {
|
|
394
409
|
kind: 'Root';
|
|
395
410
|
schemas: Array<SchemaNode>;
|
|
396
|
-
operations: Array<OperationNode>;
|
|
397
|
-
|
|
411
|
+
operations: Array<OperationNode>; /** Format-agnostic document metadata populated by the adapter. */
|
|
412
|
+
meta?: RootMeta;
|
|
413
|
+
};
|
|
398
414
|
//#endregion
|
|
399
415
|
//#region src/nodes/index.d.ts
|
|
400
416
|
/**
|
|
@@ -466,37 +482,37 @@ type VisitorOptions = {
|
|
|
466
482
|
/**
|
|
467
483
|
* Synchronous visitor for `transform` and `walk`.
|
|
468
484
|
*/
|
|
469
|
-
|
|
485
|
+
type Visitor = {
|
|
470
486
|
root?(node: RootNode): void | RootNode;
|
|
471
487
|
operation?(node: OperationNode): void | OperationNode;
|
|
472
488
|
schema?(node: SchemaNode): void | SchemaNode;
|
|
473
489
|
property?(node: PropertyNode): void | PropertyNode;
|
|
474
490
|
parameter?(node: ParameterNode): void | ParameterNode;
|
|
475
491
|
response?(node: ResponseNode): void | ResponseNode;
|
|
476
|
-
}
|
|
492
|
+
};
|
|
477
493
|
type MaybePromise<T> = T | Promise<T>;
|
|
478
494
|
/**
|
|
479
495
|
* Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
|
|
480
496
|
*/
|
|
481
|
-
|
|
497
|
+
type AsyncVisitor = {
|
|
482
498
|
root?(node: RootNode): MaybePromise<void | RootNode>;
|
|
483
499
|
operation?(node: OperationNode): MaybePromise<void | OperationNode>;
|
|
484
500
|
schema?(node: SchemaNode): MaybePromise<void | SchemaNode>;
|
|
485
501
|
property?(node: PropertyNode): MaybePromise<void | PropertyNode>;
|
|
486
502
|
parameter?(node: ParameterNode): MaybePromise<void | ParameterNode>;
|
|
487
503
|
response?(node: ResponseNode): MaybePromise<void | ResponseNode>;
|
|
488
|
-
}
|
|
504
|
+
};
|
|
489
505
|
/**
|
|
490
506
|
* Visitor for `collect`.
|
|
491
507
|
*/
|
|
492
|
-
|
|
508
|
+
type CollectVisitor<T> = {
|
|
493
509
|
root?(node: RootNode): T | undefined;
|
|
494
510
|
operation?(node: OperationNode): T | undefined;
|
|
495
511
|
schema?(node: SchemaNode): T | undefined;
|
|
496
512
|
property?(node: PropertyNode): T | undefined;
|
|
497
513
|
parameter?(node: ParameterNode): T | undefined;
|
|
498
514
|
response?(node: ResponseNode): T | undefined;
|
|
499
|
-
}
|
|
515
|
+
};
|
|
500
516
|
/**
|
|
501
517
|
* Depth-first traversal for side effects. Visitor return values are ignored.
|
|
502
518
|
*/
|
|
@@ -516,5 +532,5 @@ declare function transform(node: Node, visitor: Visitor, options?: VisitorOption
|
|
|
516
532
|
*/
|
|
517
533
|
declare function collect<T>(node: Node, visitor: CollectVisitor<T>, options?: VisitorOptions): Array<T>;
|
|
518
534
|
//#endregion
|
|
519
|
-
export {
|
|
520
|
-
//# sourceMappingURL=visitor-
|
|
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
package/src/nodes/base.ts
CHANGED
package/src/nodes/index.ts
CHANGED
|
@@ -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,
|
package/src/nodes/operation.ts
CHANGED
|
@@ -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
|
|
11
|
+
export type OperationNode = BaseNode & {
|
|
12
12
|
kind: 'Operation'
|
|
13
13
|
/**
|
|
14
14
|
* Unique operation identifier (maps to `operationId` in OAS).
|
package/src/nodes/parameter.ts
CHANGED
|
@@ -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
|
|
9
|
+
export type ParameterNode = BaseNode & {
|
|
10
10
|
kind: 'Parameter'
|
|
11
11
|
name: string
|
|
12
12
|
in: ParameterLocation
|
package/src/nodes/property.ts
CHANGED
package/src/nodes/response.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
}
|
package/src/nodes/schema.ts
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
@@ -48,7 +48,7 @@ interface SchemaNodeBase extends BaseNode {
|
|
|
48
48
|
/**
|
|
49
49
|
* Object schema with ordered property definitions.
|
|
50
50
|
*/
|
|
51
|
-
export
|
|
51
|
+
export type ObjectSchemaNode = SchemaNodeBase & {
|
|
52
52
|
type: 'object'
|
|
53
53
|
properties?: Array<PropertyNode>
|
|
54
54
|
/**
|
|
@@ -61,7 +61,7 @@ export interface ObjectSchemaNode extends SchemaNodeBase {
|
|
|
61
61
|
/**
|
|
62
62
|
* Array or tuple schema.
|
|
63
63
|
*/
|
|
64
|
-
export
|
|
64
|
+
export type ArraySchemaNode = SchemaNodeBase & {
|
|
65
65
|
type: 'array' | 'tuple'
|
|
66
66
|
items?: Array<SchemaNode>
|
|
67
67
|
/**
|
|
@@ -76,14 +76,14 @@ export interface ArraySchemaNode extends SchemaNodeBase {
|
|
|
76
76
|
/**
|
|
77
77
|
* Shared base for union and intersection schemas.
|
|
78
78
|
*/
|
|
79
|
-
|
|
79
|
+
type CompositeSchemaNodeBase = SchemaNodeBase & {
|
|
80
80
|
members?: Array<SchemaNode>
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* Union schema (`oneOf` / `anyOf`).
|
|
85
85
|
*/
|
|
86
|
-
export
|
|
86
|
+
export type UnionSchemaNode = CompositeSchemaNodeBase & {
|
|
87
87
|
type: 'union'
|
|
88
88
|
/**
|
|
89
89
|
* Discriminator property from OAS `discriminator.propertyName`.
|
|
@@ -94,14 +94,14 @@ export interface UnionSchemaNode extends CompositeSchemaNodeBase {
|
|
|
94
94
|
/**
|
|
95
95
|
* Intersection schema (`allOf`).
|
|
96
96
|
*/
|
|
97
|
-
export
|
|
97
|
+
export type IntersectionSchemaNode = CompositeSchemaNodeBase & {
|
|
98
98
|
type: 'intersection'
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* A named enum variant.
|
|
103
103
|
*/
|
|
104
|
-
export
|
|
104
|
+
export type EnumValueNode = {
|
|
105
105
|
name: string
|
|
106
106
|
value: string | number | boolean
|
|
107
107
|
format: 'string' | 'number' | 'boolean'
|
|
@@ -110,7 +110,7 @@ export interface EnumValueNode {
|
|
|
110
110
|
/**
|
|
111
111
|
* Enum schema.
|
|
112
112
|
*/
|
|
113
|
-
export
|
|
113
|
+
export type EnumSchemaNode = SchemaNodeBase & {
|
|
114
114
|
type: 'enum'
|
|
115
115
|
/**
|
|
116
116
|
* Enum member type. Generators should use const assertions for `'number'` / `'boolean'`.
|
|
@@ -129,7 +129,7 @@ export interface EnumSchemaNode extends SchemaNodeBase {
|
|
|
129
129
|
/**
|
|
130
130
|
* Ref schema — pointer to another schema definition.
|
|
131
131
|
*/
|
|
132
|
-
export
|
|
132
|
+
export type RefSchemaNode = SchemaNodeBase & {
|
|
133
133
|
type: 'ref'
|
|
134
134
|
name?: string
|
|
135
135
|
/**
|
|
@@ -145,7 +145,7 @@ export interface RefSchemaNode extends SchemaNodeBase {
|
|
|
145
145
|
/**
|
|
146
146
|
* Datetime schema.
|
|
147
147
|
*/
|
|
148
|
-
export
|
|
148
|
+
export type DatetimeSchemaNode = SchemaNodeBase & {
|
|
149
149
|
type: 'datetime'
|
|
150
150
|
/**
|
|
151
151
|
* Includes timezone offset (`dateType: 'stringOffset'`).
|
|
@@ -160,7 +160,7 @@ export interface DatetimeSchemaNode extends SchemaNodeBase {
|
|
|
160
160
|
/**
|
|
161
161
|
* Base for `date` and `time` schemas.
|
|
162
162
|
*/
|
|
163
|
-
|
|
163
|
+
type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
|
|
164
164
|
type: T
|
|
165
165
|
/**
|
|
166
166
|
* Representation in generated code: native `Date` or plain string.
|
|
@@ -181,7 +181,7 @@ export type TimeSchemaNode = TemporalSchemaNodeBase<'time'>
|
|
|
181
181
|
/**
|
|
182
182
|
* String schema.
|
|
183
183
|
*/
|
|
184
|
-
export
|
|
184
|
+
export type StringSchemaNode = SchemaNodeBase & {
|
|
185
185
|
type: 'string'
|
|
186
186
|
min?: number
|
|
187
187
|
max?: number
|
|
@@ -191,7 +191,7 @@ export interface StringSchemaNode extends SchemaNodeBase {
|
|
|
191
191
|
/**
|
|
192
192
|
* Number, integer, or bigint schema.
|
|
193
193
|
*/
|
|
194
|
-
export
|
|
194
|
+
export type NumberSchemaNode = SchemaNodeBase & {
|
|
195
195
|
type: 'number' | 'integer' | 'bigint'
|
|
196
196
|
min?: number
|
|
197
197
|
max?: number
|
|
@@ -202,7 +202,7 @@ export interface NumberSchemaNode extends SchemaNodeBase {
|
|
|
202
202
|
/**
|
|
203
203
|
* Schema for scalar types with no additional constraints.
|
|
204
204
|
*/
|
|
205
|
-
export
|
|
205
|
+
export type ScalarSchemaNode = SchemaNodeBase & {
|
|
206
206
|
type: ScalarSchemaType
|
|
207
207
|
}
|
|
208
208
|
|
package/src/types.ts
CHANGED
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
|
|
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
|
|
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
|
|
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
|