@kubb/ast 5.0.0-beta.42 → 5.0.0-beta.43
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 +60 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +58 -1
- package/dist/index.js.map +1 -1
- package/dist/{types-CEIHPTfs.d.ts → types-CC46hQUP.d.ts} +38 -2
- package/dist/types.d.ts +1 -1
- package/package.json +3 -3
- package/src/constants.ts +11 -0
- package/src/index.ts +3 -0
- package/src/utils.ts +63 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as createText, $t as PrimitiveSchemaType, A as DistributiveOmit, At as ParameterNode, B as createImport, Bt as SourceNode, C as transform, Cn as NodeKind, Ct as OperationNodeBase, D as PrinterPartial, Dn as schemaTypes, Dt as MediaType, E as PrinterFactoryOptions, En as httpMethods, Et as HttpStatusCode, F as createExport, Ft as ParameterGroupNode, G as createParameter, Gt as EnumSchemaNode, H as createJsx, Ht as ComplexSchemaType, I as createFile, It as ParamsTypeNode, J as createProperty, Jt as IntersectionSchemaNode, K as createParameterGroup, Kt as EnumValueNode, L as createFunction, Lt as ExportNode, M as createArrowFunction, Mt as FunctionParamNode, N as createBreak, Nt as FunctionParameterNode, O as createPrinterFactory, Ot as StatusCode, P as createConst, Pt as FunctionParametersNode, Q as createStreamInput, Qt as ObjectSchemaNode, R as createFunctionParameter, Rt as FileNode, S as collect, Sn as BaseNode, St as OperationNode, T as Printer, Tn as VisitorDepth, Tt as ResponseNode, U as createOperation, Ut as DateSchemaNode, V as createInput, Vt as ArraySchemaNode, W as createOutput, Wt as DatetimeSchemaNode, X as createSchema, Xt as Ipv6SchemaNode, Y as createResponse, Yt as Ipv4SchemaNode, Z as createSource, Zt as NumberSchemaNode, _ as ParentOf, _n as JSDocNode, _t as InputStreamNode, a as collectUsedSchemaNames, an as SchemaType, at as DispatchRule, b as VisitorContext, bn as TypeDeclarationNode, bt as HttpMethod, c as createOperationParams, cn as TimeSchemaNode, ct as defineSchemaDialect, d as isStringType, dn as PropertyNode, dt as DedupePlan, en as RefSchemaNode, et as createType, f as objectKey, fn as ArrowFunctionNode, ft as applyDedupe, g as CollectVisitor, gn as FunctionNode, gt as InputNode, h as CollectOptions, hn as ConstNode, ht as InputMeta, i as caseParams, in as SchemaNodeByType, it as ParserOptions, j as UserFileNode, jt as FunctionNodeType, k as definePrinter, kt as ParameterLocation, l as extractStringsFromNodes, ln as UnionSchemaNode, lt as BuildDedupePlanOptions, m as AsyncVisitor, mn as CodeNode, mt as Node, n as buildList, nn as ScalarSchemaType, nt as update, o as containsCircularRef, on as SpecialSchemaType, ot as dispatch, p as syncSchemaRef, pn as BreakNode, pt as buildDedupePlan, q as createParamsType, qt as FormatStringSchemaNode, r as buildObject, rn as SchemaNode, rt as InferSchemaNode, s as createDiscriminantNode, sn as StringSchemaNode, st as SchemaDialect, t as OperationParamsResolver, tn as ScalarSchemaNode, tt as syncOptionality, u as findCircularSchemas, un as UrlSchemaNode, ut as DedupeCanonical, v as TransformOptions, vn as JsxNode, vt as OutputNode, w as walk, wn as ScalarPrimitive, wt as OperationProtocol, x as WalkOptions, xn as TypeNode, xt as HttpOperationNode, y as Visitor, yn as TextNode, yt as GenericOperationNode, z as createFunctionParameters, zt as ImportNode } from "./types-CC46hQUP.js";
|
|
3
3
|
|
|
4
4
|
//#region src/guards.d.ts
|
|
5
5
|
/**
|
|
@@ -170,5 +170,5 @@ declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Genera
|
|
|
170
170
|
declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
171
171
|
declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
|
|
172
172
|
//#endregion
|
|
173
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, type AsyncVisitor, type BaseNode, type BreakNode, type BuildDedupePlanOptions, type CodeNode, type CollectOptions, type CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupeCanonical, type DedupePlan, type DispatchRule, type DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type HttpStatusCode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type InputStreamNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OperationNodeBase, type OperationParamsResolver, type OperationProtocol, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type ResponseNode, type ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaDialect, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, type VisitorDepth, type WalkOptions, applyDedupe, buildDedupePlan, caseParams, childName, collect, collectImports, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createStreamInput, createText, createType, definePrinter, defineSchemaDialect, dispatch, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaSignature, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
|
|
173
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type AsyncVisitor, type BaseNode, type BreakNode, type BuildDedupePlanOptions, type CodeNode, type CollectOptions, type CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupeCanonical, type DedupePlan, type DispatchRule, type DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type HttpStatusCode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type InputStreamNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OperationNodeBase, type OperationParamsResolver, type OperationProtocol, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type ResponseNode, type ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaDialect, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, type VisitorDepth, type WalkOptions, applyDedupe, buildDedupePlan, buildList, buildObject, caseParams, childName, collect, collectImports, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createStreamInput, createText, createType, definePrinter, defineSchemaDialect, dispatch, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, objectKey, schemaSignature, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
|
|
174
174
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -154,6 +154,10 @@ const httpMethods = {
|
|
|
154
154
|
options: "OPTIONS",
|
|
155
155
|
trace: "TRACE"
|
|
156
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* One indentation level, derived from {@link INDENT_SIZE}.
|
|
159
|
+
*/
|
|
160
|
+
const INDENT = Array.from({ length: 2 }, () => " ").join("");
|
|
157
161
|
//#endregion
|
|
158
162
|
//#region ../../internals/utils/src/casing.ts
|
|
159
163
|
/**
|
|
@@ -1180,6 +1184,59 @@ function extractStringsFromNodes(nodes) {
|
|
|
1180
1184
|
}).filter(Boolean).join("\n");
|
|
1181
1185
|
}
|
|
1182
1186
|
/**
|
|
1187
|
+
* Indents every non-empty line of `text` by one indent level, leaving blank lines empty.
|
|
1188
|
+
*/
|
|
1189
|
+
function indentLines(text) {
|
|
1190
|
+
if (!text) return "";
|
|
1191
|
+
return text.split("\n").map((line) => line.trim() ? `${INDENT}${line}` : "").join("\n");
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Renders an object key, quoting it only when it is not a valid variable name.
|
|
1195
|
+
*
|
|
1196
|
+
* @example
|
|
1197
|
+
* ```ts
|
|
1198
|
+
* objectKey('id') // 'id'
|
|
1199
|
+
* objectKey('x-total') // '"x-total"'
|
|
1200
|
+
* ```
|
|
1201
|
+
*/
|
|
1202
|
+
function objectKey(name) {
|
|
1203
|
+
return isValidVarName(name) ? name : JSON.stringify(name);
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
1207
|
+
* level and closing the brace at column zero. Nested objects built the same way indent cumulatively,
|
|
1208
|
+
* so callers never re-parse the generated code. A trailing comma is added per entry to match the
|
|
1209
|
+
* formatter's multi-line style.
|
|
1210
|
+
*
|
|
1211
|
+
* @example
|
|
1212
|
+
* ```ts
|
|
1213
|
+
* buildObject(['id: z.number()', 'name: z.string()'])
|
|
1214
|
+
* // '{\n id: z.number(),\n name: z.string(),\n}'
|
|
1215
|
+
* ```
|
|
1216
|
+
*/
|
|
1217
|
+
function buildObject(entries) {
|
|
1218
|
+
if (entries.length === 0) return "{}";
|
|
1219
|
+
return `{\n${entries.map((entry) => `${indentLines(entry)},`).join("\n")}\n}`;
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
1223
|
+
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
1224
|
+
* one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,
|
|
1225
|
+
* `z.array([…])`, and similar member lists so objects inside them nest correctly.
|
|
1226
|
+
*
|
|
1227
|
+
* @example
|
|
1228
|
+
* ```ts
|
|
1229
|
+
* buildList(['z.string()', 'z.number()'])
|
|
1230
|
+
* // '[z.string(), z.number()]'
|
|
1231
|
+
* ```
|
|
1232
|
+
*/
|
|
1233
|
+
function buildList(items, brackets = ["[", "]"]) {
|
|
1234
|
+
const [open, close] = brackets;
|
|
1235
|
+
if (items.length === 0) return `${open}${close}`;
|
|
1236
|
+
if (!items.some((item) => item.includes("\n"))) return `${open}${items.join(", ")}${close}`;
|
|
1237
|
+
return `${open}\n${items.map((item) => `${indentLines(item)},`).join("\n")}\n${close}`;
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1183
1240
|
* Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
|
|
1184
1241
|
*
|
|
1185
1242
|
* Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's
|
|
@@ -2666,6 +2723,6 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
|
|
|
2666
2723
|
return propNode;
|
|
2667
2724
|
}
|
|
2668
2725
|
//#endregion
|
|
2669
|
-
export { applyDedupe, buildDedupePlan, caseParams, childName, collect, collectImports, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createStreamInput, createText, createType, definePrinter, defineSchemaDialect, dispatch, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaSignature, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
|
|
2726
|
+
export { applyDedupe, buildDedupePlan, buildList, buildObject, caseParams, childName, collect, collectImports, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createStreamInput, createText, createType, definePrinter, defineSchemaDialect, dispatch, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, objectKey, schemaSignature, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
|
|
2670
2727
|
|
|
2671
2728
|
//# sourceMappingURL=index.js.map
|