@kubb/ast 5.0.0-beta.71 → 5.0.0-beta.73
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/{defineMacro-VfsvblGi.js → defineMacro-B5Plh1uq.js} +2 -2
- package/dist/{defineMacro-VfsvblGi.js.map → defineMacro-B5Plh1uq.js.map} +1 -1
- package/dist/{defineMacro-BXpTwp0y.d.ts → defineMacro-Bm07PZIF.d.ts} +2 -2
- package/dist/{defineMacro-5Dvct8k_.cjs → defineMacro-CI0a-SWY.cjs} +2 -2
- package/dist/{defineMacro-5Dvct8k_.cjs.map → defineMacro-CI0a-SWY.cjs.map} +1 -1
- package/dist/{index-DJEyS5y6.d.ts → index-aTdOZp_L.d.ts} +4 -263
- package/dist/index.cjs +2 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -24
- package/dist/index.js +3 -13
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +3 -3
- package/dist/macros.d.ts +1 -1
- package/dist/macros.js +3 -3
- package/dist/{refs-D18OeCgb.js → refs-1t3qfkLE.js} +3 -19
- package/dist/refs-1t3qfkLE.js.map +1 -0
- package/dist/{refs-DuP3_Leg.cjs → refs-Dga4lfv7.cjs} +2 -24
- package/dist/refs-Dga4lfv7.cjs.map +1 -0
- package/dist/{types-BsP1SK9j.d.ts → types-DqFHKeAc.d.ts} +2 -2
- package/dist/types.d.ts +4 -5
- package/dist/utils.cjs +2 -192
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +2 -3
- package/dist/utils.js +3 -191
- package/dist/utils.js.map +1 -1
- package/dist/{visitor-dcVC5TOW.js → visitor-CeO-upp5.js} +2 -128
- package/dist/visitor-CeO-upp5.js.map +1 -0
- package/dist/{visitor-CQdSiClY.cjs → visitor-ChiWLwlh.cjs} +1 -193
- package/dist/visitor-ChiWLwlh.cjs.map +1 -0
- package/package.json +2 -2
- package/dist/operationParams-BaY12i2I.d.ts +0 -148
- package/dist/refs-D18OeCgb.js.map +0 -1
- package/dist/refs-DuP3_Leg.cjs.map +0 -1
- package/dist/visitor-CQdSiClY.cjs.map +0 -1
- package/dist/visitor-dcVC5TOW.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import { a as defineMacro, c as VisitorContext, d as walk, f as schemaTypes, i as composeMacros, l as collect, n as Macro, o as ParentOf, r as applyMacros, s as Visitor, t as Enforce, u as transform } from "./defineMacro-
|
|
3
|
-
import { a as Dialect, i as createPrinter, n as PrinterFactoryOptions, o as SchemaDialect, r as PrinterPartial, s as defineDialect, t as Printer } from "./types-
|
|
4
|
-
import { $ as
|
|
5
|
-
import { t as OperationParamsResolver } from "./operationParams-BaY12i2I.js";
|
|
2
|
+
import { a as defineMacro, c as VisitorContext, d as walk, f as schemaTypes, i as composeMacros, l as collect, n as Macro, o as ParentOf, r as applyMacros, s as Visitor, t as Enforce, u as transform } from "./defineMacro-Bm07PZIF.js";
|
|
3
|
+
import { a as Dialect, i as createPrinter, n as PrinterFactoryOptions, o as SchemaDialect, r as PrinterPartial, s as defineDialect, t as Printer } from "./types-DqFHKeAc.js";
|
|
4
|
+
import { $ as SchemaNode, A as UserFileNode, At as createJsx, B as contentDef, Bt as BaseNode, C as ParameterNode, Ct as arrowFunctionDef, D as FileNode, Dt as createBreak, E as ExportNode, Et as createArrowFunction, F as exportDef, Ft as textDef, G as EnumSchemaNode, H as ArraySchemaNode, I as fileDef, It as typeDef, J as ObjectSchemaNode, K as IntersectionSchemaNode, L as importDef, Lt as DistributiveOmit, M as createFile, Mt as createType, N as createImport, Nt as functionDef, O as ImportNode, Ot as createConst, P as createSource, Pt as jsxDef, Q as ScalarSchemaType, R as sourceDef, Rt as NodeDef, S as ParameterLocation, St as TypeNode, T as parameterDef, Tt as constDef, U as DateSchemaNode, V as createContent, Vt as NodeKind, W as DatetimeSchemaNode, X as RefSchemaNode, Y as PrimitiveSchemaType, Z as ScalarSchemaNode, _ as createResponse, _t as ConstNode, a as InputMeta, at as UrlSchemaNode, b as createRequestBody, bt as JsxNode, c as inputDef, ct as PropertyNode, d as HttpOperationNode, dt as propertyDef, et as SchemaNodeByType, f as OperationNode, ft as InferSchemaNode, g as StatusCode, gt as CodeNode, h as ResponseNode, ht as BreakNode, i as outputDef, it as UnionSchemaNode, j as createExport, jt as createText, k as SourceNode, kt as createFunction, l as GenericOperationNode, lt as UserPropertyNode, m as operationDef, mt as ArrowFunctionNode, n as OutputNode, nt as StringSchemaNode, o as InputNode, ot as createSchema, p as createOperation, pt as ParserOptions, q as NumberSchemaNode, r as createOutput, rt as TimeSchemaNode, s as createInput, st as schemaDef, t as Node, tt as SchemaType, u as HttpMethod, ut as createProperty, v as responseDef, vt as FunctionNode, w as createParameter, wt as breakDef, x as requestBodyDef, xt as TextNode, y as RequestBodyNode, yt as JSDocNode, z as ContentNode, zt as defineNode } from "./index-aTdOZp_L.js";
|
|
6
5
|
|
|
7
6
|
//#region src/guards.d.ts
|
|
8
7
|
/**
|
|
@@ -34,7 +33,7 @@ declare function isHttpOperationNode(node: OperationNode): node is HttpOperation
|
|
|
34
33
|
*/
|
|
35
34
|
declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
|
|
36
35
|
declare namespace factory_d_exports {
|
|
37
|
-
export { UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction,
|
|
36
|
+
export { UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOutput, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType, update };
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
40
39
|
* Identity-preserving node update: returns `node` unchanged when every field in
|
|
@@ -59,7 +58,7 @@ declare function update<T extends Node>(node: T, changes: Partial<T>): T;
|
|
|
59
58
|
* Every node definition. Adding a node means adding its `defineNode` to one
|
|
60
59
|
* `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
|
|
61
60
|
*/
|
|
62
|
-
declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "kind" | "primitive" | "properties"> & {
|
|
61
|
+
declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<SchemaNode, (Omit<ObjectSchemaNode, "kind" | "primitive" | "properties"> & {
|
|
63
62
|
properties?: Array<PropertyNode>;
|
|
64
63
|
primitive?: "object";
|
|
65
64
|
}) | DistributiveOmit<ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | (BaseNode & {
|
|
@@ -115,7 +114,7 @@ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<Schem
|
|
|
115
114
|
format?: string;
|
|
116
115
|
} & {
|
|
117
116
|
type: "ipv6";
|
|
118
|
-
}) | ScalarSchemaNode, "kind">> | NodeDef<
|
|
117
|
+
}) | ScalarSchemaNode, "kind">> | NodeDef<InputNode<false>, Partial<Omit<InputNode<false>, "kind">>> | NodeDef<OutputNode, Partial<Omit<OutputNode, "kind">>> | NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">> | NodeDef<OperationNode, {
|
|
119
118
|
[key: string]: unknown;
|
|
120
119
|
operationId: string;
|
|
121
120
|
method?: HttpOperationNode["method"];
|
|
@@ -126,24 +125,10 @@ declare const nodeDefs: (NodeDef<PropertyNode, UserPropertyNode> | NodeDef<Schem
|
|
|
126
125
|
schema?: SchemaNode;
|
|
127
126
|
mediaType?: string | null;
|
|
128
127
|
keysToOmit?: Array<string> | null;
|
|
129
|
-
}> | NodeDef<ParameterNode, Pick<ParameterNode, "name" | "schema" | "in"> & Partial<Omit<ParameterNode, "kind" | "name" | "schema" | "in">>> | NodeDef<
|
|
130
|
-
name: string | ObjectBindingPatternNode;
|
|
131
|
-
type?: TypeExpression;
|
|
132
|
-
optional?: boolean;
|
|
133
|
-
default?: string;
|
|
134
|
-
rest?: boolean;
|
|
135
|
-
} | {
|
|
136
|
-
properties: Array<{
|
|
137
|
-
name: string;
|
|
138
|
-
type: TypeExpression;
|
|
139
|
-
optional?: boolean;
|
|
140
|
-
}>;
|
|
141
|
-
optional?: boolean;
|
|
142
|
-
default?: string;
|
|
143
|
-
}> | NodeDef<FunctionParametersNode, Partial<Omit<FunctionParametersNode, "kind">>> | NodeDef<IndexedAccessTypeNode, Omit<IndexedAccessTypeNode, "kind">> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
|
|
128
|
+
}> | NodeDef<ParameterNode, Pick<ParameterNode, "name" | "schema" | "in"> & Partial<Omit<ParameterNode, "kind" | "name" | "schema" | "in">>> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
|
|
144
129
|
declare namespace exports_d_exports {
|
|
145
|
-
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dialect, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode,
|
|
130
|
+
export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dialect, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, composeMacros, constDef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, exportDef, factory_d_exports as factory, fileDef, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef, walk };
|
|
146
131
|
}
|
|
147
132
|
//#endregion
|
|
148
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type Dialect, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type
|
|
133
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type Dialect, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterLocation, type ParameterNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaDialect, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, collect, composeMacros, constDef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, exportDef, factory_d_exports as factory, fileDef, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef, walk };
|
|
149
134
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import {
|
|
3
|
-
import { n as composeMacros, r as defineMacro, t as applyMacros } from "./defineMacro-
|
|
2
|
+
import { A as sourceDef, B as createConst, C as createExport, D as exportDef, E as createSource, F as arrowFunctionDef, G as functionDef, H as createJsx, I as breakDef, J as typeDef, K as jsxDef, L as constDef, N as contentDef, O as fileDef, P as createContent, Q as narrowSchema, R as createArrowFunction, S as inputDef, T as createImport, U as createText, V as createFunction, W as createType, Y as defineNode, Z as isHttpOperationNode, _ as createOperation, a as nodeDefs, b as requestBodyDef, c as createResponse, d as propertyDef, et as schemaTypes, f as createParameter, g as outputDef, h as createOutput, i as walk, k as importDef, l as responseDef, m as optionality, o as createSchema, p as parameterDef, q as textDef, r as transform, s as schemaDef, t as collect, u as createProperty, v as operationDef, w as createFile, x as createInput, y as createRequestBody, z as createBreak } from "./visitor-CeO-upp5.js";
|
|
3
|
+
import { n as composeMacros, r as defineMacro, t as applyMacros } from "./defineMacro-B5Plh1uq.js";
|
|
4
4
|
//#region src/defineDialect.ts
|
|
5
5
|
/**
|
|
6
6
|
* Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
|
|
@@ -93,13 +93,9 @@ var factory_exports = /* @__PURE__ */ __exportAll({
|
|
|
93
93
|
createExport: () => createExport,
|
|
94
94
|
createFile: () => createFile,
|
|
95
95
|
createFunction: () => createFunction,
|
|
96
|
-
createFunctionParameter: () => createFunctionParameter,
|
|
97
|
-
createFunctionParameters: () => createFunctionParameters,
|
|
98
96
|
createImport: () => createImport,
|
|
99
|
-
createIndexedAccessType: () => createIndexedAccessType,
|
|
100
97
|
createInput: () => createInput,
|
|
101
98
|
createJsx: () => createJsx,
|
|
102
|
-
createObjectBindingPattern: () => createObjectBindingPattern,
|
|
103
99
|
createOperation: () => createOperation,
|
|
104
100
|
createOutput: () => createOutput,
|
|
105
101
|
createParameter: () => createParameter,
|
|
@@ -110,7 +106,6 @@ var factory_exports = /* @__PURE__ */ __exportAll({
|
|
|
110
106
|
createSource: () => createSource,
|
|
111
107
|
createText: () => createText,
|
|
112
108
|
createType: () => createType,
|
|
113
|
-
createTypeLiteral: () => createTypeLiteral,
|
|
114
109
|
update: () => update
|
|
115
110
|
});
|
|
116
111
|
/**
|
|
@@ -154,16 +149,12 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
154
149
|
factory: () => factory_exports,
|
|
155
150
|
fileDef: () => fileDef,
|
|
156
151
|
functionDef: () => functionDef,
|
|
157
|
-
functionParameterDef: () => functionParameterDef,
|
|
158
|
-
functionParametersDef: () => functionParametersDef,
|
|
159
152
|
importDef: () => importDef,
|
|
160
|
-
indexedAccessTypeDef: () => indexedAccessTypeDef,
|
|
161
153
|
inputDef: () => inputDef,
|
|
162
154
|
isHttpOperationNode: () => isHttpOperationNode,
|
|
163
155
|
jsxDef: () => jsxDef,
|
|
164
156
|
narrowSchema: () => narrowSchema,
|
|
165
157
|
nodeDefs: () => nodeDefs,
|
|
166
|
-
objectBindingPatternDef: () => objectBindingPatternDef,
|
|
167
158
|
operationDef: () => operationDef,
|
|
168
159
|
optionality: () => optionality,
|
|
169
160
|
outputDef: () => outputDef,
|
|
@@ -177,10 +168,9 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
177
168
|
textDef: () => textDef,
|
|
178
169
|
transform: () => transform,
|
|
179
170
|
typeDef: () => typeDef,
|
|
180
|
-
typeLiteralDef: () => typeLiteralDef,
|
|
181
171
|
walk: () => walk
|
|
182
172
|
});
|
|
183
173
|
//#endregion
|
|
184
|
-
export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, composeMacros, constDef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, exportDef, factory_exports as factory, fileDef, functionDef,
|
|
174
|
+
export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, composeMacros, constDef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, exportDef, factory_exports as factory, fileDef, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef, walk };
|
|
185
175
|
|
|
186
176
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/defineDialect.ts","../src/createPrinter.ts","../src/factory.ts","../src/exports.ts"],"sourcesContent":["/**\n * The spec-specific questions a schema parser answers while turning a source document into Kubb\n * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where\n * OpenAPI, AsyncAPI, and plain JSON Schema differ.\n */\nexport type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Whether the schema is nullable.\n */\n isNullable(schema?: TSchema): boolean\n /**\n * Whether the value is a `$ref` pointer.\n */\n isReference(value?: unknown): value is TRef\n /**\n * Whether the schema carries a discriminator for polymorphism.\n */\n isDiscriminator(value?: unknown): value is TDiscriminated\n /**\n * Whether the schema is binary data, converted to a `blob` node.\n */\n isBinary(schema: TSchema): boolean\n /**\n * Resolves a local `$ref` against the document, or nullish when it cannot.\n */\n resolveRef<TResolved>(document: TDocument, ref: string): TResolved | null | undefined\n}\n\n/**\n * A spec adapter's dialect. `name` identifies it in logs and diagnostics, and `schema` holds the\n * spec-specific schema questions the parser answers.\n */\nexport type Dialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Identifies the dialect in logs and diagnostics.\n */\n name: string\n /**\n * The spec-specific schema behavior. See {@link SchemaDialect}.\n */\n schema: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>\n}\n\n/**\n * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the\n * dialect's type for inference.\n *\n * @example\n * ```ts\n * export const oasDialect = defineDialect({\n * name: 'oas',\n * schema: {\n * isNullable,\n * isReference,\n * isDiscriminator,\n * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',\n * resolveRef,\n * },\n * })\n * ```\n */\nexport function defineDialect<TSchema, TRef, TDiscriminated, TDocument>(\n dialect: Dialect<TSchema, TRef, TDiscriminated, TDocument>,\n): Dialect<TSchema, TRef, TDiscriminated, TDocument> {\n return dialect\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * }\n * ```\n */\ntype PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n */\n transform: (node: SchemaNode) => TOutput | null\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\ntype PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\ntype PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n/**\n * Creates a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { createPrinter, type PrinterFactoryOptions } from '@kubb/ast'\n *\n * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = createPrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: SchemaNode): T['output'] | null => {\n const handler = nodes[node.type]\n if (!handler) return null\n\n return (handler as (this: typeof context, node: SchemaNode) => T['output'] | null).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: SchemaNode) => T['printOutput'] | null,\n }\n }\n}\n","import type { Node } from './nodes/index.ts'\n\n// Node constructors, grouped under the `factory` namespace the way the TypeScript compiler exposes\n// `ts.factory.createX`. Aggregating them here lets `export * as factory from './factory.ts'` in the\n// barrel surface every `createX` alongside the `createFile`/`update` helpers from a single module.\nexport { createArrowFunction, createBreak, createConst, createFunction, createJsx, createText, createType } from './nodes/code.ts'\nexport { createContent } from './nodes/content.ts'\nexport { createExport, createFile, createImport, createSource } from './nodes/file.ts'\nexport type { UserFileNode } from './nodes/file.ts'\nexport { createFunctionParameter, createFunctionParameters, createIndexedAccessType, createObjectBindingPattern, createTypeLiteral } from './nodes/function.ts'\nexport { createInput } from './nodes/input.ts'\nexport { createOperation } from './nodes/operation.ts'\nexport { createOutput } from './nodes/output.ts'\nexport { createParameter } from './nodes/parameter.ts'\nexport { createProperty } from './nodes/property.ts'\nexport { createRequestBody } from './nodes/requestBody.ts'\nexport { createResponse } from './nodes/response.ts'\nexport { createSchema } from './nodes/schema.ts'\n\n/**\n * Identity-preserving node update: returns `node` unchanged when every field in\n * `changes` already equals (by reference) the current value, otherwise a new node\n * with the changes applied.\n *\n * Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the\n * structural sharing in {@link transform} so a no-op rewrite does not allocate and\n * downstream passes can detect \"nothing changed\" by identity. Comparison is shallow,\n * so a structurally equal but newly allocated array or object counts as a change.\n *\n * @example\n * ```ts\n * update(node, { name: node.name }) // -> same `node` reference\n * update(node, { name: 'renamed' }) // -> new node, `name` replaced\n * ```\n */\nexport function update<T extends Node>(node: T, changes: Partial<T>): T {\n for (const key in changes) {\n if (changes[key] !== node[key as keyof T]) {\n return { ...node, ...changes }\n }\n }\n\n return node\n}\n","export { schemaTypes } from './constants.ts'\nexport { defineDialect } from './defineDialect.ts'\nexport { isHttpOperationNode, narrowSchema } from './guards.ts'\nexport { applyMacros, composeMacros, defineMacro } from './defineMacro.ts'\nexport { defineNode } from './defineNode.ts'\nexport { optionality } from './optionality.ts'\nexport { createPrinter } from './createPrinter.ts'\nexport { collect, transform, walk } from './visitor.ts'\n\nexport * as factory from './factory.ts'\nexport * from './registry.ts'\nexport type * from './types.ts'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,cACd,SACmD;CACnD,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC2HA,SAAgB,cAAuE,OAAkE;CACvJ,QAAQ,YAAY;EAClB,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,OAAO,kBAAkB,MAAM,WAAY,CAAC,CAAkB;EAE7G,MAAM,UAAU;GACd,SAAS;GACT,YAAY,SAAyC;IACnD,MAAM,UAAU,MAAM,KAAK;IAC3B,IAAI,CAAC,SAAS,OAAO;IAErB,OAAQ,QAA2E,KAAK,SAAS,IAAI;GACvG;EACF;EAEA,OAAO;GACL;GACA,SAAS;GACT,WAAW,QAAQ;GACnB,OAAQ,gBAAgB,cAAc,KAAK,OAAO,IAAI,QAAQ;EAChE;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC9KA,SAAgB,OAAuB,MAAS,SAAwB;CACtE,KAAK,MAAM,OAAO,SAChB,IAAI,QAAQ,SAAS,KAAK,MACxB,OAAO;EAAE,GAAG;EAAM,GAAG;CAAQ;CAIjC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/defineDialect.ts","../src/createPrinter.ts","../src/factory.ts","../src/exports.ts"],"sourcesContent":["/**\n * The spec-specific questions a schema parser answers while turning a source document into Kubb\n * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where\n * OpenAPI, AsyncAPI, and plain JSON Schema differ.\n */\nexport type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Whether the schema is nullable.\n */\n isNullable(schema?: TSchema): boolean\n /**\n * Whether the value is a `$ref` pointer.\n */\n isReference(value?: unknown): value is TRef\n /**\n * Whether the schema carries a discriminator for polymorphism.\n */\n isDiscriminator(value?: unknown): value is TDiscriminated\n /**\n * Whether the schema is binary data, converted to a `blob` node.\n */\n isBinary(schema: TSchema): boolean\n /**\n * Resolves a local `$ref` against the document, or nullish when it cannot.\n */\n resolveRef<TResolved>(document: TDocument, ref: string): TResolved | null | undefined\n}\n\n/**\n * A spec adapter's dialect. `name` identifies it in logs and diagnostics, and `schema` holds the\n * spec-specific schema questions the parser answers.\n */\nexport type Dialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {\n /**\n * Identifies the dialect in logs and diagnostics.\n */\n name: string\n /**\n * The spec-specific schema behavior. See {@link SchemaDialect}.\n */\n schema: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>\n}\n\n/**\n * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the\n * dialect's type for inference.\n *\n * @example\n * ```ts\n * export const oasDialect = defineDialect({\n * name: 'oas',\n * schema: {\n * isNullable,\n * isReference,\n * isDiscriminator,\n * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',\n * resolveRef,\n * },\n * })\n * ```\n */\nexport function defineDialect<TSchema, TRef, TDiscriminated, TDocument>(\n dialect: Dialect<TSchema, TRef, TDiscriminated, TDocument>,\n): Dialect<TSchema, TRef, TDiscriminated, TDocument> {\n return dialect\n}\n","import type { SchemaNode, SchemaNodeByType, SchemaType } from './nodes/index.ts'\n\n/**\n * Runtime context passed as `this` to printer handlers.\n *\n * `this.transform` dispatches to node-level handlers from `nodes`.\n *\n * @example\n * ```ts\n * const context: PrinterHandlerContext<string, {}> = {\n * options: {},\n * transform: () => 'value',\n * }\n * ```\n */\ntype PrinterHandlerContext<TOutput, TOptions extends object> = {\n /**\n * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.\n * Use `this.transform` inside `nodes` handlers and inside the `print` override.\n */\n transform: (node: SchemaNode) => TOutput | null\n /**\n * Options for this printer instance.\n */\n options: TOptions\n}\n\n/**\n * Handler for one schema node type.\n *\n * Use a regular function (not an arrow function) if you need `this`.\n *\n * @example\n * ```ts\n * const handler: PrinterHandler<string, {}, 'string'> = function () {\n * return 'string'\n * }\n * ```\n */\ntype PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (\n this: PrinterHandlerContext<TOutput, TOptions>,\n node: SchemaNodeByType[T],\n) => TOutput | null\n\n/**\n * Partial map of per-node-type handler overrides for a printer.\n *\n * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).\n * Supply only the handlers you want to replace. The printer's built-in\n * defaults fill in the rest.\n *\n * @example\n * ```ts\n * pluginZod({\n * printer: {\n * nodes: {\n * date(): string {\n * return 'z.string().date()'\n * },\n * } satisfies PrinterPartial<string, PrinterZodOptions>,\n * },\n * })\n * ```\n */\nexport type PrinterPartial<TOutput, TOptions extends object> = Partial<{\n [K in SchemaType]: PrinterHandler<TOutput, TOptions, K>\n}>\n\n/**\n * Generic shape used by `definePrinter`.\n *\n * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)\n * - `TOptions` options passed to and stored on the printer instance\n * - `TOutput` the type emitted by node handlers\n * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)\n *\n * @example\n * ```ts\n * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>\n * ```\n */\nexport type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {\n name: TName\n options: TOptions\n output: TOutput\n printOutput: TPrintOutput\n}\n\n/**\n * Printer instance returned by a printer factory.\n *\n * @example\n * ```ts\n * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})\n * ```\n */\nexport type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {\n /**\n * Unique identifier supplied at creation time.\n */\n name: T['name']\n /**\n * Options for this printer instance.\n */\n options: T['options']\n /**\n * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.\n * Always dispatches through the `nodes` map. Never calls the `print` override.\n * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.\n */\n transform: (node: SchemaNode) => T['output'] | null\n /**\n * Public printer. If the builder provides a root-level `print`, this calls that\n * higher-level function (which may produce full declarations).\n * Otherwise, falls back to the node-level dispatcher.\n */\n print: (node: SchemaNode) => T['printOutput'] | null\n}\n\n/**\n * Builder function passed to `definePrinter`.\n *\n * It receives resolved options and returns:\n * - `name`\n * - `options`\n * - `nodes` handlers\n * - optional top-level `print` override\n *\n * @example\n * ```ts\n * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })\n * ```\n */\ntype PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {\n name: T['name']\n /**\n * Options to store on the printer.\n */\n options: T['options']\n nodes: Partial<{\n [K in SchemaType]: PrinterHandler<T['output'], T['options'], K>\n }>\n /**\n * Optional root-level print override. When provided, becomes the public `printer.print`.\n * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),\n * not the override itself, so recursion is safe.\n */\n print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null\n}\n/**\n * Creates a schema printer: a function that takes a `SchemaNode` and emits\n * code in your target language. Each plugin that produces code from schemas\n * (TypeScript types, Zod schemas, Faker factories) ships a printer built\n * with this helper.\n *\n * The builder receives resolved options and returns:\n *\n * - `name` unique identifier for the printer.\n * - `options` stored on the returned printer instance.\n * - `nodes` map of `SchemaType` → handler. Handlers return the rendered\n * output (a string, a TypeScript AST node, ...) for that schema type.\n * - `print` (optional), top-level override exposed as `printer.print`.\n * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.\n *\n * Without a `print` override, `printer.print` falls back to `printer.transform`\n * (the node-level dispatcher).\n *\n * @example Tiny Zod printer\n * ```ts\n * import { createPrinter, type PrinterFactoryOptions } from '@kubb/ast'\n *\n * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>\n *\n * export const zodPrinter = createPrinter<PrinterZod>((options) => ({\n * name: 'zod',\n * options: { strict: options.strict ?? true },\n * nodes: {\n * string: () => 'z.string()',\n * object(node) {\n * const props = node.properties\n * .map((p) => `${p.name}: ${this.transform(p.schema)}`)\n * .join(', ')\n * return `z.object({ ${props} })`\n * },\n * },\n * }))\n * ```\n */\nexport function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T> {\n return (options) => {\n const { name, options: resolvedOptions, nodes, print: printOverride } = build(options ?? ({} as T['options']))\n\n const context = {\n options: resolvedOptions,\n transform: (node: SchemaNode): T['output'] | null => {\n const handler = nodes[node.type]\n if (!handler) return null\n\n return (handler as (this: typeof context, node: SchemaNode) => T['output'] | null).call(context, node)\n },\n }\n\n return {\n name,\n options: resolvedOptions,\n transform: context.transform,\n print: (printOverride ? printOverride.bind(context) : context.transform) as (node: SchemaNode) => T['printOutput'] | null,\n }\n }\n}\n","import type { Node } from './nodes/index.ts'\n\n// Node constructors, grouped under the `factory` namespace the way the TypeScript compiler exposes\n// `ts.factory.createX`. Aggregating them here lets `export * as factory from './factory.ts'` in the\n// barrel surface every `createX` alongside the `createFile`/`update` helpers from a single module.\nexport { createArrowFunction, createBreak, createConst, createFunction, createJsx, createText, createType } from './nodes/code.ts'\nexport { createContent } from './nodes/content.ts'\nexport { createExport, createFile, createImport, createSource } from './nodes/file.ts'\nexport type { UserFileNode } from './nodes/file.ts'\nexport { createInput } from './nodes/input.ts'\nexport { createOperation } from './nodes/operation.ts'\nexport { createOutput } from './nodes/output.ts'\nexport { createParameter } from './nodes/parameter.ts'\nexport { createProperty } from './nodes/property.ts'\nexport { createRequestBody } from './nodes/requestBody.ts'\nexport { createResponse } from './nodes/response.ts'\nexport { createSchema } from './nodes/schema.ts'\n\n/**\n * Identity-preserving node update: returns `node` unchanged when every field in\n * `changes` already equals (by reference) the current value, otherwise a new node\n * with the changes applied.\n *\n * Mirrors the TypeScript compiler's `factory.updateX` contract. Pair it with the\n * structural sharing in {@link transform} so a no-op rewrite does not allocate and\n * downstream passes can detect \"nothing changed\" by identity. Comparison is shallow,\n * so a structurally equal but newly allocated array or object counts as a change.\n *\n * @example\n * ```ts\n * update(node, { name: node.name }) // -> same `node` reference\n * update(node, { name: 'renamed' }) // -> new node, `name` replaced\n * ```\n */\nexport function update<T extends Node>(node: T, changes: Partial<T>): T {\n for (const key in changes) {\n if (changes[key] !== node[key as keyof T]) {\n return { ...node, ...changes }\n }\n }\n\n return node\n}\n","export { schemaTypes } from './constants.ts'\nexport { defineDialect } from './defineDialect.ts'\nexport { isHttpOperationNode, narrowSchema } from './guards.ts'\nexport { applyMacros, composeMacros, defineMacro } from './defineMacro.ts'\nexport { defineNode } from './defineNode.ts'\nexport { optionality } from './optionality.ts'\nexport { createPrinter } from './createPrinter.ts'\nexport { collect, transform, walk } from './visitor.ts'\n\nexport * as factory from './factory.ts'\nexport * from './registry.ts'\nexport type * from './types.ts'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,cACd,SACmD;CACnD,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC2HA,SAAgB,cAAuE,OAAkE;CACvJ,QAAQ,YAAY;EAClB,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,OAAO,kBAAkB,MAAM,WAAY,CAAC,CAAkB;EAE7G,MAAM,UAAU;GACd,SAAS;GACT,YAAY,SAAyC;IACnD,MAAM,UAAU,MAAM,KAAK;IAC3B,IAAI,CAAC,SAAS,OAAO;IAErB,OAAQ,QAA2E,KAAK,SAAS,IAAI;GACvG;EACF;EAEA,OAAO;GACL;GACA,SAAS;GACT,WAAW,QAAQ;GACnB,OAAQ,gBAAgB,cAAc,KAAK,OAAO,IAAI,QAAQ;EAChE;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC/KA,SAAgB,OAAuB,MAAS,SAAwB;CACtE,KAAK,MAAM,OAAO,SAChB,IAAI,QAAQ,SAAS,KAAK,MACxB,OAAO;EAAE,GAAG;EAAM,GAAG;CAAQ;CAIjC,OAAO;AACT"}
|
package/dist/macros.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_visitor = require("./visitor-
|
|
3
|
-
const require_defineMacro = require("./defineMacro-
|
|
4
|
-
const require_refs = require("./refs-
|
|
2
|
+
const require_visitor = require("./visitor-ChiWLwlh.cjs");
|
|
3
|
+
const require_defineMacro = require("./defineMacro-CI0a-SWY.cjs");
|
|
4
|
+
const require_refs = require("./refs-Dga4lfv7.cjs");
|
|
5
5
|
//#region src/macros/macroDiscriminatorEnum.ts
|
|
6
6
|
/**
|
|
7
7
|
* Builds a macro that replaces a discriminator property's schema with a string enum of the given
|
package/dist/macros.d.ts
CHANGED
package/dist/macros.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import {
|
|
3
|
-
import { r as defineMacro } from "./defineMacro-
|
|
4
|
-
import { n as enumPropName } from "./refs-
|
|
2
|
+
import { Q as narrowSchema, o as createSchema, u as createProperty } from "./visitor-CeO-upp5.js";
|
|
3
|
+
import { r as defineMacro } from "./defineMacro-B5Plh1uq.js";
|
|
4
|
+
import { n as enumPropName } from "./refs-1t3qfkLE.js";
|
|
5
5
|
//#region src/macros/macroDiscriminatorEnum.ts
|
|
6
6
|
/**
|
|
7
7
|
* Builds a macro that replaces a discriminator property's schema with a string enum of the given
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import {
|
|
2
|
+
import { M as pascalCase, Q as narrowSchema, o as createSchema } from "./visitor-CeO-upp5.js";
|
|
3
3
|
//#region src/utils/refs.ts
|
|
4
4
|
const plainStringTypes = new Set([
|
|
5
5
|
"string",
|
|
@@ -95,23 +95,7 @@ function isStringType(node) {
|
|
|
95
95
|
if (temporal) return temporal.representation !== "date";
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Derives a {@link ParamGroupType} for a query or header group from the resolver.
|
|
100
|
-
*
|
|
101
|
-
* Returns `null` when there is no resolver, no params, or the group name equals the
|
|
102
|
-
* individual param name (so there is no real group to emit).
|
|
103
|
-
*/
|
|
104
|
-
function resolveGroupType({ node, params, group, resolver }) {
|
|
105
|
-
if (!resolver || !params.length) return null;
|
|
106
|
-
const firstParam = params[0];
|
|
107
|
-
const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
|
|
108
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
109
|
-
return {
|
|
110
|
-
type: groupName,
|
|
111
|
-
optional: params.every((p) => !p.required)
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
98
|
//#endregion
|
|
115
|
-
export {
|
|
99
|
+
export { resolveRefName as a, isStringType as i, enumPropName as n, syncSchemaRef as o, extractRefName as r, childName as t };
|
|
116
100
|
|
|
117
|
-
//# sourceMappingURL=refs-
|
|
101
|
+
//# sourceMappingURL=refs-1t3qfkLE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs-1t3qfkLE.js","names":[],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n"],"mappings":";;;AAKA,MAAM,mBAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;AAQpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;AAWA,SAAgB,eAAe,MAA6C;CAC1E,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO;CACzC,IAAI,KAAK,KAAK,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;CAEnF,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC3C;;;;;;;;;;;AAYA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAa,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI;AACrE;;;;;;;;AASA,SAAgB,aAAa,YAAuC,UAAkB,YAA4B;CAChH,OAAO,WAAW;EAAC;EAAY;EAAU;CAAU,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC;AAChF;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,MAA8B;CAC1D,MAAM,MAAM,aAAa,MAAM,KAAK;CAEpC,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,CAAC,IAAI,QAAQ,OAAO;CAExB,MAAM,EAAE,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,KAAK,MAAM,QAAQ,SAAS,GAAG,cAAc;CAG5F,MAAM,mBAAmB,OAAO,YAAY,OAAO,QAAQ,SAAS,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CAExG,OAAO,aAAa;EAAE,GAAG,IAAI;EAAQ,GAAG;CAAiB,CAAC;AAC5D;;;;;;;AAQA,SAAgB,aAAa,MAA2B;CACtD,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAChC,OAAO;CAGT,MAAM,WAAW,aAAa,MAAM,MAAM,KAAK,aAAa,MAAM,MAAM;CACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_visitor = require("./visitor-
|
|
1
|
+
const require_visitor = require("./visitor-ChiWLwlh.cjs");
|
|
2
2
|
//#region src/utils/refs.ts
|
|
3
3
|
const plainStringTypes = new Set([
|
|
4
4
|
"string",
|
|
@@ -94,22 +94,6 @@ function isStringType(node) {
|
|
|
94
94
|
if (temporal) return temporal.representation !== "date";
|
|
95
95
|
return false;
|
|
96
96
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Derives a {@link ParamGroupType} for a query or header group from the resolver.
|
|
99
|
-
*
|
|
100
|
-
* Returns `null` when there is no resolver, no params, or the group name equals the
|
|
101
|
-
* individual param name (so there is no real group to emit).
|
|
102
|
-
*/
|
|
103
|
-
function resolveGroupType({ node, params, group, resolver }) {
|
|
104
|
-
if (!resolver || !params.length) return null;
|
|
105
|
-
const firstParam = params[0];
|
|
106
|
-
const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
|
|
107
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
108
|
-
return {
|
|
109
|
-
type: groupName,
|
|
110
|
-
optional: params.every((p) => !p.required)
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
97
|
//#endregion
|
|
114
98
|
Object.defineProperty(exports, "childName", {
|
|
115
99
|
enumerable: true,
|
|
@@ -135,12 +119,6 @@ Object.defineProperty(exports, "isStringType", {
|
|
|
135
119
|
return isStringType;
|
|
136
120
|
}
|
|
137
121
|
});
|
|
138
|
-
Object.defineProperty(exports, "resolveGroupType", {
|
|
139
|
-
enumerable: true,
|
|
140
|
-
get: function() {
|
|
141
|
-
return resolveGroupType;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
122
|
Object.defineProperty(exports, "resolveRefName", {
|
|
145
123
|
enumerable: true,
|
|
146
124
|
get: function() {
|
|
@@ -154,4 +132,4 @@ Object.defineProperty(exports, "syncSchemaRef", {
|
|
|
154
132
|
}
|
|
155
133
|
});
|
|
156
134
|
|
|
157
|
-
//# sourceMappingURL=refs-
|
|
135
|
+
//# sourceMappingURL=refs-Dga4lfv7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs-Dga4lfv7.cjs","names":["pascalCase","narrowSchema","createSchema"],"sources":["../src/utils/refs.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n"],"mappings":";;AAKA,MAAM,mBAAmB,IAAI,IAAgB;CAAC;CAAU;CAAQ;CAAS;CAAO;AAAU,CAAU;;;;;;;AAQpG,SAAgB,eAAe,KAAqB;CAClD,OAAO,IAAI,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;AAClC;;;;;;;;;;AAWA,SAAgB,eAAe,MAA6C;CAC1E,IAAI,CAAC,QAAQ,KAAK,SAAS,OAAO,OAAO;CACzC,IAAI,KAAK,KAAK,OAAO,eAAe,KAAK,GAAG,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;CAEnF,OAAO,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC3C;;;;;;;;;;;AAYA,SAAgB,UAAU,YAAuC,UAAiC;CAChG,OAAO,aAAaA,gBAAAA,WAAW,CAAC,YAAY,QAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI;AACrE;;;;;;;;AASA,SAAgB,aAAa,YAAuC,UAAkB,YAA4B;CAChH,OAAOA,gBAAAA,WAAW;EAAC;EAAY;EAAU;CAAU,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC;AAChF;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,MAA8B;CAC1D,MAAM,MAAMC,gBAAAA,aAAa,MAAM,KAAK;CAEpC,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,CAAC,IAAI,QAAQ,OAAO;CAExB,MAAM,EAAE,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,KAAK,MAAM,QAAQ,SAAS,GAAG,cAAc;CAG5F,MAAM,mBAAmB,OAAO,YAAY,OAAO,QAAQ,SAAS,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CAExG,OAAOC,gBAAAA,aAAa;EAAE,GAAG,IAAI;EAAQ,GAAG;CAAiB,CAAC;AAC5D;;;;;;;AAQA,SAAgB,aAAa,MAA2B;CACtD,IAAI,iBAAiB,IAAI,KAAK,IAAI,GAChC,OAAO;CAGT,MAAM,WAAWD,gBAAAA,aAAa,MAAM,MAAM,KAAKA,gBAAAA,aAAa,MAAM,MAAM;CACxE,IAAI,UACF,OAAO,SAAS,mBAAmB;CAGrC,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as SchemaNode, et as SchemaNodeByType, tt as SchemaType } from "./index-aTdOZp_L.js";
|
|
3
3
|
|
|
4
4
|
//#region src/defineDialect.d.ts
|
|
5
5
|
/**
|
|
@@ -241,4 +241,4 @@ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) =
|
|
|
241
241
|
declare function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
|
|
242
242
|
//#endregion
|
|
243
243
|
export { Dialect as a, createPrinter as i, PrinterFactoryOptions as n, SchemaDialect as o, PrinterPartial as r, defineDialect as s, Printer as t };
|
|
244
|
-
//# sourceMappingURL=types-
|
|
244
|
+
//# sourceMappingURL=types-DqFHKeAc.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { c as VisitorContext, n as Macro, o as ParentOf, s as Visitor, t as Enforce } from "./defineMacro-
|
|
2
|
-
import { a as Dialect, n as PrinterFactoryOptions, o as SchemaDialect, r as PrinterPartial, t as Printer } from "./types-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export type { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dialect, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, FunctionParamKind, FunctionParamNode, FunctionParameterNode, FunctionParametersNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, IndexedAccessTypeNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectBindingPatternNode, ObjectSchemaNode, OperationNode, OperationParamsResolver, OutputNode, ParameterLocation, ParameterNode, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeExpression, TypeLiteralNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext };
|
|
1
|
+
import { c as VisitorContext, n as Macro, o as ParentOf, s as Visitor, t as Enforce } from "./defineMacro-Bm07PZIF.js";
|
|
2
|
+
import { a as Dialect, n as PrinterFactoryOptions, o as SchemaDialect, r as PrinterPartial, t as Printer } from "./types-DqFHKeAc.js";
|
|
3
|
+
import { $ as SchemaNode, A as UserFileNode, C as ParameterNode, D as FileNode, E as ExportNode, G as EnumSchemaNode, H as ArraySchemaNode, J as ObjectSchemaNode, K as IntersectionSchemaNode, Lt as DistributiveOmit, O as ImportNode, Q as ScalarSchemaType, Rt as NodeDef, S as ParameterLocation, St as TypeNode, U as DateSchemaNode, Vt as NodeKind, W as DatetimeSchemaNode, X as RefSchemaNode, Y as PrimitiveSchemaType, Z as ScalarSchemaNode, _t as ConstNode, a as InputMeta, at as UrlSchemaNode, bt as JsxNode, ct as PropertyNode, d as HttpOperationNode, et as SchemaNodeByType, f as OperationNode, ft as InferSchemaNode, g as StatusCode, gt as CodeNode, h as ResponseNode, ht as BreakNode, it as UnionSchemaNode, k as SourceNode, l as GenericOperationNode, mt as ArrowFunctionNode, n as OutputNode, nt as StringSchemaNode, o as InputNode, pt as ParserOptions, q as NumberSchemaNode, rt as TimeSchemaNode, t as Node, tt as SchemaType, u as HttpMethod, vt as FunctionNode, xt as TextNode, y as RequestBodyNode, yt as JSDocNode, z as ContentNode } from "./index-aTdOZp_L.js";
|
|
4
|
+
export type { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, Dialect, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext };
|
package/dist/utils.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_visitor = require("./visitor-
|
|
3
|
-
const require_refs = require("./refs-
|
|
2
|
+
const require_visitor = require("./visitor-ChiWLwlh.cjs");
|
|
3
|
+
const require_refs = require("./refs-Dga4lfv7.cjs");
|
|
4
4
|
//#region ../../internals/utils/src/promise.ts
|
|
5
5
|
/**
|
|
6
6
|
* Wraps `factory` with a keyed cache backed by the provided store.
|
|
@@ -584,202 +584,12 @@ function lazyGetter({ name, body }) {
|
|
|
584
584
|
return `get ${objectKey(name)}() { return ${body} }`;
|
|
585
585
|
}
|
|
586
586
|
//#endregion
|
|
587
|
-
//#region src/utils/operationParams.ts
|
|
588
|
-
const caseParamsMemo = memoize(/* @__PURE__ */ new WeakMap(), (params) => memoize(/* @__PURE__ */ new Map(), (casing) => params.map((param) => {
|
|
589
|
-
const transformed = casing === "camelcase" || !isValidVarName(param.name) ? require_visitor.camelCase(param.name) : param.name;
|
|
590
|
-
return {
|
|
591
|
-
...param,
|
|
592
|
-
name: transformed
|
|
593
|
-
};
|
|
594
|
-
})));
|
|
595
|
-
/**
|
|
596
|
-
* Applies casing rules to parameter names and returns a new array without mutating the input.
|
|
597
|
-
*
|
|
598
|
-
* Run it before handing parameters to schema builders so output property keys get the right casing
|
|
599
|
-
* while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
|
|
600
|
-
* original array is returned unchanged.
|
|
601
|
-
*/
|
|
602
|
-
function caseParams(params, casing) {
|
|
603
|
-
if (!casing) return params;
|
|
604
|
-
return caseParamsMemo(params)(casing);
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Resolves the {@link TypeExpression} for an individual parameter.
|
|
608
|
-
*
|
|
609
|
-
* Without a resolver, it falls back to the schema primitive (a plain type-name string). When the
|
|
610
|
-
* parameter belongs to a named group, it emits an {@link IndexedAccessTypeNode} like
|
|
611
|
-
* `GroupParams['petId']`, otherwise the resolved individual name.
|
|
612
|
-
*/
|
|
613
|
-
function resolveParamType({ node, param, resolver }) {
|
|
614
|
-
if (!resolver) return param.schema.primitive ?? "unknown";
|
|
615
|
-
const individualName = resolver.resolveParamName(node, param);
|
|
616
|
-
const groupLocation = param.in === "path" || param.in === "query" || param.in === "header" ? param.in : void 0;
|
|
617
|
-
const groupResolvers = {
|
|
618
|
-
path: resolver.resolvePathParamsName,
|
|
619
|
-
query: resolver.resolveQueryParamsName,
|
|
620
|
-
header: resolver.resolveHeaderParamsName
|
|
621
|
-
};
|
|
622
|
-
const groupName = groupLocation ? groupResolvers[groupLocation].call(resolver, node, param) : void 0;
|
|
623
|
-
if (groupName && groupName !== individualName) return require_visitor.createIndexedAccessType({
|
|
624
|
-
target: groupName,
|
|
625
|
-
key: param.name
|
|
626
|
-
});
|
|
627
|
-
return individualName;
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* Converts an `OperationNode` into function parameters for code generation.
|
|
631
|
-
*
|
|
632
|
-
* Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one
|
|
633
|
-
* destructured object parameter (`object`) and separate top-level parameters (`inline`), while
|
|
634
|
-
* `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type
|
|
635
|
-
* name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.
|
|
636
|
-
*/
|
|
637
|
-
function createOperationParams(node, options) {
|
|
638
|
-
const { paramsType, pathParamsType, paramsCasing, resolver, pathParamsDefault, extraParams = [], paramNames, typeWrapper } = options;
|
|
639
|
-
const dataName = paramNames?.data ?? "data";
|
|
640
|
-
const paramsName = paramNames?.params ?? "params";
|
|
641
|
-
const headersName = paramNames?.headers ?? "headers";
|
|
642
|
-
const pathName = paramNames?.path ?? "pathParams";
|
|
643
|
-
const wrapType = (type) => typeWrapper ? typeWrapper(type) : type;
|
|
644
|
-
const wrapTypeExpression = (type) => typeof type === "string" ? wrapType(type) : type;
|
|
645
|
-
const casedParams = caseParams(node.parameters, paramsCasing);
|
|
646
|
-
const pathParams = casedParams.filter((p) => p.in === "path");
|
|
647
|
-
const queryParams = casedParams.filter((p) => p.in === "query");
|
|
648
|
-
const headerParams = casedParams.filter((p) => p.in === "header");
|
|
649
|
-
const toProperty = (param) => ({
|
|
650
|
-
name: param.name,
|
|
651
|
-
type: wrapTypeExpression(resolveParamType({
|
|
652
|
-
node,
|
|
653
|
-
param,
|
|
654
|
-
resolver
|
|
655
|
-
})),
|
|
656
|
-
optional: !param.required
|
|
657
|
-
});
|
|
658
|
-
const emptyObjectDefault = (props) => props.every((p) => p.optional) ? "{}" : void 0;
|
|
659
|
-
const bodyType = node.requestBody?.content?.[0]?.schema ? wrapType(resolver?.resolveDataName(node) ?? "unknown") : void 0;
|
|
660
|
-
const bodyProperty = bodyType ? [{
|
|
661
|
-
name: dataName,
|
|
662
|
-
type: bodyType,
|
|
663
|
-
optional: !(node.requestBody?.required ?? false)
|
|
664
|
-
}] : [];
|
|
665
|
-
const trailingGroups = [{
|
|
666
|
-
name: paramsName,
|
|
667
|
-
node,
|
|
668
|
-
params: queryParams,
|
|
669
|
-
groupType: require_refs.resolveGroupType({
|
|
670
|
-
node,
|
|
671
|
-
params: queryParams,
|
|
672
|
-
group: "query",
|
|
673
|
-
resolver
|
|
674
|
-
}),
|
|
675
|
-
resolver,
|
|
676
|
-
wrapType
|
|
677
|
-
}, {
|
|
678
|
-
name: headersName,
|
|
679
|
-
node,
|
|
680
|
-
params: headerParams,
|
|
681
|
-
groupType: require_refs.resolveGroupType({
|
|
682
|
-
node,
|
|
683
|
-
params: headerParams,
|
|
684
|
-
group: "header",
|
|
685
|
-
resolver
|
|
686
|
-
}),
|
|
687
|
-
resolver,
|
|
688
|
-
wrapType
|
|
689
|
-
}];
|
|
690
|
-
const params = [];
|
|
691
|
-
if (paramsType === "object") {
|
|
692
|
-
const children = [
|
|
693
|
-
...pathParams.map(toProperty),
|
|
694
|
-
...bodyProperty,
|
|
695
|
-
...trailingGroups.flatMap(buildGroupProperty)
|
|
696
|
-
];
|
|
697
|
-
if (children.length) params.push(require_visitor.createFunctionParameter({
|
|
698
|
-
properties: children,
|
|
699
|
-
default: emptyObjectDefault(children)
|
|
700
|
-
}));
|
|
701
|
-
} else {
|
|
702
|
-
if (pathParamsType === "inlineSpread" && pathParams.length) {
|
|
703
|
-
const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]);
|
|
704
|
-
params.push(require_visitor.createFunctionParameter({
|
|
705
|
-
name: pathName,
|
|
706
|
-
type: spreadType ? wrapType(spreadType) : void 0,
|
|
707
|
-
rest: true
|
|
708
|
-
}));
|
|
709
|
-
} else if (pathParamsType === "inline") params.push(...pathParams.map((p) => require_visitor.createFunctionParameter(toProperty(p))));
|
|
710
|
-
else if (pathParams.length) {
|
|
711
|
-
const pathChildren = pathParams.map(toProperty);
|
|
712
|
-
params.push(require_visitor.createFunctionParameter({
|
|
713
|
-
properties: pathChildren,
|
|
714
|
-
default: pathParamsDefault ?? emptyObjectDefault(pathChildren)
|
|
715
|
-
}));
|
|
716
|
-
}
|
|
717
|
-
params.push(...bodyProperty.map((p) => require_visitor.createFunctionParameter(p)));
|
|
718
|
-
params.push(...trailingGroups.flatMap(buildGroupParam));
|
|
719
|
-
}
|
|
720
|
-
params.push(...extraParams);
|
|
721
|
-
return require_visitor.createFunctionParameters({ params });
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Builds the property descriptor for a query or header group.
|
|
725
|
-
* Returns an empty array when there are no params to emit.
|
|
726
|
-
*
|
|
727
|
-
* A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline
|
|
728
|
-
* {@link TypeLiteralNode} from the individual params.
|
|
729
|
-
*/
|
|
730
|
-
function buildGroupProperty({ name, node, params, groupType, resolver, wrapType }) {
|
|
731
|
-
if (groupType) return [{
|
|
732
|
-
name,
|
|
733
|
-
type: typeof groupType.type === "string" ? wrapType(groupType.type) : groupType.type,
|
|
734
|
-
optional: groupType.optional
|
|
735
|
-
}];
|
|
736
|
-
if (params.length) return [{
|
|
737
|
-
name,
|
|
738
|
-
type: buildTypeLiteral({
|
|
739
|
-
node,
|
|
740
|
-
params,
|
|
741
|
-
resolver
|
|
742
|
-
}),
|
|
743
|
-
optional: params.every((p) => !p.required)
|
|
744
|
-
}];
|
|
745
|
-
return [];
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Builds a single {@link FunctionParameterNode} for a query or header group.
|
|
749
|
-
* Returns an empty array when there are no params to emit.
|
|
750
|
-
*
|
|
751
|
-
* A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline
|
|
752
|
-
* {@link TypeLiteralNode} from the individual params.
|
|
753
|
-
*/
|
|
754
|
-
function buildGroupParam(args) {
|
|
755
|
-
return buildGroupProperty(args).map((p) => require_visitor.createFunctionParameter(p));
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* Builds a {@link TypeLiteralNode} for an inline anonymous type grouping named fields.
|
|
759
|
-
*
|
|
760
|
-
* Used when query or header parameters have no dedicated group type name.
|
|
761
|
-
* Each language printer renders this appropriately (TypeScript: `{ petId: string; name?: string }`).
|
|
762
|
-
*/
|
|
763
|
-
function buildTypeLiteral({ node, params, resolver }) {
|
|
764
|
-
return require_visitor.createTypeLiteral({ members: params.map((p) => ({
|
|
765
|
-
name: p.name,
|
|
766
|
-
type: resolveParamType({
|
|
767
|
-
node,
|
|
768
|
-
param: p,
|
|
769
|
-
resolver
|
|
770
|
-
}),
|
|
771
|
-
optional: !p.required
|
|
772
|
-
})) });
|
|
773
|
-
}
|
|
774
|
-
//#endregion
|
|
775
587
|
exports.buildJSDoc = buildJSDoc;
|
|
776
588
|
exports.buildList = buildList;
|
|
777
589
|
exports.buildObject = buildObject;
|
|
778
|
-
exports.caseParams = caseParams;
|
|
779
590
|
exports.childName = require_refs.childName;
|
|
780
591
|
exports.collectUsedSchemaNames = collectUsedSchemaNames;
|
|
781
592
|
exports.containsCircularRef = containsCircularRef;
|
|
782
|
-
exports.createOperationParams = createOperationParams;
|
|
783
593
|
exports.enumPropName = require_refs.enumPropName;
|
|
784
594
|
exports.extractRefName = require_refs.extractRefName;
|
|
785
595
|
exports.extractStringsFromNodes = require_visitor.extractStringsFromNodes;
|