@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
|
@@ -3565,6 +3565,42 @@ declare function createOperationParams(node: OperationNode, options: CreateOpera
|
|
|
3565
3565
|
* and nested node content. Used internally to build the full source string for import filtering.
|
|
3566
3566
|
*/
|
|
3567
3567
|
declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
|
|
3568
|
+
/**
|
|
3569
|
+
* Renders an object key, quoting it only when it is not a valid variable name.
|
|
3570
|
+
*
|
|
3571
|
+
* @example
|
|
3572
|
+
* ```ts
|
|
3573
|
+
* objectKey('id') // 'id'
|
|
3574
|
+
* objectKey('x-total') // '"x-total"'
|
|
3575
|
+
* ```
|
|
3576
|
+
*/
|
|
3577
|
+
declare function objectKey(name: string): string;
|
|
3578
|
+
/**
|
|
3579
|
+
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
3580
|
+
* level and closing the brace at column zero. Nested objects built the same way indent cumulatively,
|
|
3581
|
+
* so callers never re-parse the generated code. A trailing comma is added per entry to match the
|
|
3582
|
+
* formatter's multi-line style.
|
|
3583
|
+
*
|
|
3584
|
+
* @example
|
|
3585
|
+
* ```ts
|
|
3586
|
+
* buildObject(['id: z.number()', 'name: z.string()'])
|
|
3587
|
+
* // '{\n id: z.number(),\n name: z.string(),\n}'
|
|
3588
|
+
* ```
|
|
3589
|
+
*/
|
|
3590
|
+
declare function buildObject(entries: Array<string>): string;
|
|
3591
|
+
/**
|
|
3592
|
+
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
3593
|
+
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
3594
|
+
* one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,
|
|
3595
|
+
* `z.array([…])`, and similar member lists so objects inside them nest correctly.
|
|
3596
|
+
*
|
|
3597
|
+
* @example
|
|
3598
|
+
* ```ts
|
|
3599
|
+
* buildList(['z.string()', 'z.number()'])
|
|
3600
|
+
* // '[z.string(), z.number()]'
|
|
3601
|
+
* ```
|
|
3602
|
+
*/
|
|
3603
|
+
declare function buildList(items: Array<string>, brackets?: [open: string, close: string]): string;
|
|
3568
3604
|
declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
3569
3605
|
/**
|
|
3570
3606
|
* Identifies all schemas that participate in circular dependency chains, including direct self-loops.
|
|
@@ -3592,5 +3628,5 @@ declare function containsCircularRef(node: SchemaNode | undefined, {
|
|
|
3592
3628
|
excludeName?: string;
|
|
3593
3629
|
}): boolean;
|
|
3594
3630
|
//#endregion
|
|
3595
|
-
export {
|
|
3596
|
-
//# sourceMappingURL=types-
|
|
3631
|
+
export { createText as $, PrimitiveSchemaType as $t, DistributiveOmit as A, ParameterNode as At, createImport as B, SourceNode as Bt, transform as C, NodeKind as Cn, OperationNodeBase as Ct, PrinterPartial as D, schemaTypes as Dn, MediaType as Dt, PrinterFactoryOptions as E, httpMethods as En, HttpStatusCode as Et, createExport as F, ParameterGroupNode as Ft, createParameter as G, EnumSchemaNode as Gt, createJsx as H, ComplexSchemaType as Ht, createFile as I, ParamsTypeNode as It, createProperty as J, IntersectionSchemaNode as Jt, createParameterGroup as K, EnumValueNode as Kt, createFunction as L, ExportNode as Lt, createArrowFunction as M, FunctionParamNode as Mt, createBreak as N, FunctionParameterNode as Nt, createPrinterFactory as O, StatusCode as Ot, createConst as P, FunctionParametersNode as Pt, createStreamInput as Q, ObjectSchemaNode as Qt, createFunctionParameter as R, FileNode as Rt, collect as S, BaseNode as Sn, OperationNode as St, Printer as T, VisitorDepth as Tn, ResponseNode as Tt, createOperation as U, DateSchemaNode as Ut, createInput as V, ArraySchemaNode as Vt, createOutput as W, DatetimeSchemaNode as Wt, createSchema as X, Ipv6SchemaNode as Xt, createResponse as Y, Ipv4SchemaNode as Yt, createSource as Z, NumberSchemaNode as Zt, ParentOf as _, JSDocNode as _n, InputStreamNode as _t, collectUsedSchemaNames as a, SchemaType as an, DispatchRule as at, VisitorContext as b, TypeDeclarationNode as bn, HttpMethod as bt, createOperationParams as c, TimeSchemaNode as cn, defineSchemaDialect as ct, isStringType as d, PropertyNode as dn, DedupePlan as dt, RefSchemaNode as en, createType as et, objectKey as f, ArrowFunctionNode as fn, applyDedupe as ft, CollectVisitor as g, FunctionNode as gn, InputNode as gt, CollectOptions as h, ConstNode as hn, InputMeta as ht, caseParams as i, SchemaNodeByType as in, ParserOptions as it, UserFileNode as j, FunctionNodeType as jt, definePrinter as k, ParameterLocation as kt, extractStringsFromNodes as l, UnionSchemaNode as ln, BuildDedupePlanOptions as lt, AsyncVisitor as m, CodeNode as mn, Node as mt, buildList as n, ScalarSchemaType as nn, update as nt, containsCircularRef as o, SpecialSchemaType as on, dispatch as ot, syncSchemaRef as p, BreakNode as pn, buildDedupePlan as pt, createParamsType as q, FormatStringSchemaNode as qt, buildObject as r, SchemaNode as rn, InferSchemaNode as rt, createDiscriminantNode as s, StringSchemaNode as sn, SchemaDialect as st, OperationParamsResolver as t, ScalarSchemaNode as tn, syncOptionality as tt, findCircularSchemas as u, UrlSchemaNode as un, DedupeCanonical as ut, TransformOptions as v, JsxNode as vn, OutputNode as vt, walk as w, ScalarPrimitive as wn, OperationProtocol as wt, WalkOptions as x, TypeNode as xn, HttpOperationNode as xt, Visitor as y, TextNode as yn, GenericOperationNode as yt, createFunctionParameters as z, ImportNode as zt };
|
|
3632
|
+
//# sourceMappingURL=types-CC46hQUP.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as
|
|
1
|
+
import { $t as PrimitiveSchemaType, A as DistributiveOmit, At as ParameterNode, Bt as SourceNode, Cn as NodeKind, Ct as OperationNodeBase, D as PrinterPartial, Dt as MediaType, E as PrinterFactoryOptions, Et as HttpStatusCode, Ft as ParameterGroupNode, Gt as EnumSchemaNode, Ht as ComplexSchemaType, It as ParamsTypeNode, Jt as IntersectionSchemaNode, Kt as EnumValueNode, Lt as ExportNode, Mt as FunctionParamNode, Nt as FunctionParameterNode, Ot as StatusCode, Pt as FunctionParametersNode, Qt as ObjectSchemaNode, Rt as FileNode, Sn as BaseNode, St as OperationNode, T as Printer, Tn as VisitorDepth, Tt as ResponseNode, Ut as DateSchemaNode, Vt as ArraySchemaNode, Wt as DatetimeSchemaNode, Xt as Ipv6SchemaNode, Yt as Ipv4SchemaNode, Zt as NumberSchemaNode, _ as ParentOf, _n as JSDocNode, _t as InputStreamNode, an as SchemaType, at as DispatchRule, b as VisitorContext, bn as TypeDeclarationNode, bt as HttpMethod, cn as TimeSchemaNode, dn as PropertyNode, dt as DedupePlan, en as RefSchemaNode, fn as ArrowFunctionNode, g as CollectVisitor, gn as FunctionNode, gt as InputNode, h as CollectOptions, hn as ConstNode, ht as InputMeta, in as SchemaNodeByType, it as ParserOptions, j as UserFileNode, jt as FunctionNodeType, kt as ParameterLocation, ln as UnionSchemaNode, lt as BuildDedupePlanOptions, m as AsyncVisitor, mn as CodeNode, mt as Node, nn as ScalarSchemaType, on as SpecialSchemaType, pn as BreakNode, qt as FormatStringSchemaNode, rn as SchemaNode, rt as InferSchemaNode, sn as StringSchemaNode, st as SchemaDialect, t as OperationParamsResolver, tn as ScalarSchemaNode, un as UrlSchemaNode, ut as DedupeCanonical, v as TransformOptions, vn as JsxNode, vt as OutputNode, wn as ScalarPrimitive, wt as OperationProtocol, x as WalkOptions, xn as TypeNode, xt as HttpOperationNode, y as Visitor, yn as TextNode, yt as GenericOperationNode, zt as ImportNode } from "./types-CC46hQUP.js";
|
|
2
2
|
export type { ArraySchemaNode, ArrowFunctionNode, AsyncVisitor, BaseNode, BreakNode, BuildDedupePlanOptions, CodeNode, CollectOptions, CollectVisitor, ComplexSchemaType, ConstNode, DateSchemaNode, DatetimeSchemaNode, DedupeCanonical, DedupePlan, DispatchRule, DistributiveOmit, EnumSchemaNode, EnumValueNode, ExportNode, FileNode, FormatStringSchemaNode, FunctionNode, FunctionNodeType, FunctionParamNode, FunctionParameterNode, FunctionParametersNode, GenericOperationNode, HttpMethod, HttpOperationNode, HttpStatusCode, ImportNode, InferSchemaNode, InputMeta, InputNode, InputStreamNode, IntersectionSchemaNode, Ipv4SchemaNode, Ipv6SchemaNode, JSDocNode, JsxNode, MediaType, Node, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OperationNodeBase, OperationParamsResolver, OperationProtocol, OutputNode, ParameterGroupNode, ParameterLocation, ParameterNode, ParamsTypeNode, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, ResponseNode, ScalarPrimitive, ScalarSchemaNode, ScalarSchemaType, SchemaDialect, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, SpecialSchemaType, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TransformOptions, TypeDeclarationNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, VisitorDepth, WalkOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/ast",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.43",
|
|
4
4
|
"description": "Spec-agnostic AST layer for Kubb. Defines the node tree, visitor pattern, factory functions, and type guards used across all code generation plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"registry": "https://registry.npmjs.org/"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^22.19.
|
|
46
|
+
"@types/node": "^22.19.20",
|
|
47
47
|
"@internals/utils": "0.0.0"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsdown",
|
|
54
|
-
"clean": "
|
|
54
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
55
55
|
"lint": "oxlint .",
|
|
56
56
|
"lint:fix": "oxlint --fix .",
|
|
57
57
|
"release": "pnpm publish --no-git-check",
|
package/src/constants.ts
CHANGED
|
@@ -176,3 +176,14 @@ export const httpMethods = {
|
|
|
176
176
|
* ```
|
|
177
177
|
*/
|
|
178
178
|
export const WALK_CONCURRENCY = 30
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Number of spaces in one indentation level when assembling multi-line code as strings.
|
|
182
|
+
* Set to 2, 3, … to change the indent width used by `buildObject`/`buildList`.
|
|
183
|
+
*/
|
|
184
|
+
export const INDENT_SIZE = 2
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* One indentation level, derived from {@link INDENT_SIZE}.
|
|
188
|
+
*/
|
|
189
|
+
export const INDENT = Array.from({ length: INDENT_SIZE }, () => ' ').join('')
|
package/src/index.ts
CHANGED
|
@@ -37,6 +37,8 @@ export { schemaSignature } from './signature.ts'
|
|
|
37
37
|
export { mergeAdjacentObjectsLazy, setDiscriminatorEnum, setEnumName, simplifyUnion } from './transformers.ts'
|
|
38
38
|
export type * from './types.ts'
|
|
39
39
|
export {
|
|
40
|
+
buildList,
|
|
41
|
+
buildObject,
|
|
40
42
|
caseParams,
|
|
41
43
|
collectUsedSchemaNames,
|
|
42
44
|
containsCircularRef,
|
|
@@ -45,6 +47,7 @@ export {
|
|
|
45
47
|
extractStringsFromNodes,
|
|
46
48
|
findCircularSchemas,
|
|
47
49
|
isStringType,
|
|
50
|
+
objectKey,
|
|
48
51
|
syncSchemaRef,
|
|
49
52
|
} from './utils.ts'
|
|
50
53
|
export { collect, transform, walk } from './visitor.ts'
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { camelCase, isValidVarName, memoize } from '@internals/utils'
|
|
2
2
|
|
|
3
|
+
import { INDENT } from './constants.ts'
|
|
3
4
|
import { createFunctionParameter, createFunctionParameters, createParameterGroup, createParamsType, createProperty, createSchema } from './factory.ts'
|
|
4
5
|
import { narrowSchema } from './guards.ts'
|
|
5
6
|
import type {
|
|
@@ -761,6 +762,68 @@ export function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): str
|
|
|
761
762
|
.join('\n')
|
|
762
763
|
}
|
|
763
764
|
|
|
765
|
+
/**
|
|
766
|
+
* Indents every non-empty line of `text` by one indent level, leaving blank lines empty.
|
|
767
|
+
*/
|
|
768
|
+
function indentLines(text: string): string {
|
|
769
|
+
if (!text) return ''
|
|
770
|
+
return text
|
|
771
|
+
.split('\n')
|
|
772
|
+
.map((line) => (line.trim() ? `${INDENT}${line}` : ''))
|
|
773
|
+
.join('\n')
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Renders an object key, quoting it only when it is not a valid variable name.
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* ```ts
|
|
781
|
+
* objectKey('id') // 'id'
|
|
782
|
+
* objectKey('x-total') // '"x-total"'
|
|
783
|
+
* ```
|
|
784
|
+
*/
|
|
785
|
+
export function objectKey(name: string): string {
|
|
786
|
+
return isValidVarName(name) ? name : JSON.stringify(name)
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
791
|
+
* level and closing the brace at column zero. Nested objects built the same way indent cumulatively,
|
|
792
|
+
* so callers never re-parse the generated code. A trailing comma is added per entry to match the
|
|
793
|
+
* formatter's multi-line style.
|
|
794
|
+
*
|
|
795
|
+
* @example
|
|
796
|
+
* ```ts
|
|
797
|
+
* buildObject(['id: z.number()', 'name: z.string()'])
|
|
798
|
+
* // '{\n id: z.number(),\n name: z.string(),\n}'
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
export function buildObject(entries: Array<string>): string {
|
|
802
|
+
if (entries.length === 0) return '{}'
|
|
803
|
+
const body = entries.map((entry) => `${indentLines(entry)},`).join('\n')
|
|
804
|
+
return `{\n${body}\n}`
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
809
|
+
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
810
|
+
* one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,
|
|
811
|
+
* `z.array([…])`, and similar member lists so objects inside them nest correctly.
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* ```ts
|
|
815
|
+
* buildList(['z.string()', 'z.number()'])
|
|
816
|
+
* // '[z.string(), z.number()]'
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
export function buildList(items: Array<string>, brackets: [open: string, close: string] = ['[', ']']): string {
|
|
820
|
+
const [open, close] = brackets
|
|
821
|
+
if (items.length === 0) return `${open}${close}`
|
|
822
|
+
if (!items.some((item) => item.includes('\n'))) return `${open}${items.join(', ')}${close}`
|
|
823
|
+
const body = items.map((item) => `${indentLines(item)},`).join('\n')
|
|
824
|
+
return `${open}\n${body}\n${close}`
|
|
825
|
+
}
|
|
826
|
+
|
|
764
827
|
/**
|
|
765
828
|
* Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
|
|
766
829
|
*
|