@kubb/ast 5.0.0-beta.35 → 5.0.0-beta.37
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 +25 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/{types-CE8VJ5_y.d.ts → types-CEIHPTfs.d.ts} +66 -75
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants.ts +2 -2
- package/src/dedupe.ts +3 -3
- package/src/dialect.ts +13 -19
- package/src/dispatch.ts +2 -2
- package/src/factory.ts +7 -7
- package/src/infer.ts +1 -1
- package/src/nodes/code.ts +1 -1
- package/src/nodes/function.ts +11 -11
- package/src/nodes/root.ts +5 -5
- package/src/nodes/schema.ts +5 -8
- package/src/printer.ts +12 -12
- package/src/signature.ts +4 -4
- package/src/utils.ts +10 -10
- package/src/visitor.ts +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
-
import { $ as update, $t as ScalarSchemaType, A as createBreak, At as FunctionParameterNode, B as createOperation, Bt as DateSchemaNode, C as PrinterFactoryOptions, Cn as httpMethods, Ct as HttpStatusCode, D as DistributiveOmit, Dt as ParameterNode, E as definePrinter, Et as ParameterLocation, F as createFunctionParameter, Ft as FileNode, G as createProperty, Gt as IntersectionSchemaNode, H as createParameter, Ht as EnumSchemaNode, I as createFunctionParameters, It as ImportNode, J as createSource, Jt as NumberSchemaNode, K as createResponse, Kt as Ipv4SchemaNode, L as createImport, Lt as SourceNode, M as createExport, Mt as ParameterGroupNode, N as createFile, Nt as ParamsTypeNode, O as UserFileNode, Ot as FunctionNodeType, P as createFunction, Pt as ExportNode, Q as syncOptionality, Qt as ScalarSchemaNode, R as createInput, Rt as ArraySchemaNode, S as Printer, Sn as VisitorDepth, St as ResponseNode, T as createPrinterFactory, Tt as StatusCode, U as createParameterGroup, Ut as EnumValueNode, V as createOutput, Vt as DatetimeSchemaNode, W as createParamsType, Wt as FormatStringSchemaNode, X as createText, Xt as PrimitiveSchemaType, Y as createStreamInput, Yt as ObjectSchemaNode, Z as createType, Zt as RefSchemaNode, _ as VisitorContext, _n as TypeDeclarationNode, _t as HttpMethod, a as createDiscriminantNode, an as TimeSchemaNode, at as defineSchemaDialect, b as transform, bn as NodeKind, bt as OperationNodeBase, c as findCircularSchemas, cn as PropertyNode, ct as DedupePlan, d as AsyncVisitor, dn as CodeNode, dt as Node, en as SchemaNode, et as InferSchemaNode, f as CollectOptions, fn as ConstNode, ft as InputMeta, g as Visitor, gn as TextNode, gt as GenericOperationNode, h as TransformOptions, hn as JsxNode, ht as OutputNode, i as containsCircularRef, in as StringSchemaNode, it as SchemaDialect, j as createConst, jt as FunctionParametersNode, k as createArrowFunction, kt as FunctionParamNode, l as isStringType, ln as ArrowFunctionNode, lt as applyDedupe, m as ParentOf, mn as JSDocNode, mt as InputStreamNode, n as caseParams, nn as SchemaType, nt as DispatchRule, o as createOperationParams, on as UnionSchemaNode, ot as BuildDedupePlanOptions, p as CollectVisitor, pn as FunctionNode, pt as InputNode, q as createSchema, qt as Ipv6SchemaNode, r as collectUsedSchemaNames, rn as SpecialSchemaType, rt as dispatch, s as extractStringsFromNodes, sn as UrlSchemaNode, st as DedupeCanonical, t as OperationParamsResolver, tn as SchemaNodeByType, tt as ParserOptions, u as syncSchemaRef, un as BreakNode, ut as buildDedupePlan, v as WalkOptions, vn as TypeNode, vt as HttpOperationNode, w as PrinterPartial, wn as schemaTypes, wt as MediaType, x as walk, xn as ScalarPrimitive, xt as OperationProtocol, y as collect, yn as BaseNode, yt as OperationNode, z as createJsx, zt as ComplexSchemaType } from "./types-
|
|
2
|
+
import { $ as update, $t as ScalarSchemaType, A as createBreak, At as FunctionParameterNode, B as createOperation, Bt as DateSchemaNode, C as PrinterFactoryOptions, Cn as httpMethods, Ct as HttpStatusCode, D as DistributiveOmit, Dt as ParameterNode, E as definePrinter, Et as ParameterLocation, F as createFunctionParameter, Ft as FileNode, G as createProperty, Gt as IntersectionSchemaNode, H as createParameter, Ht as EnumSchemaNode, I as createFunctionParameters, It as ImportNode, J as createSource, Jt as NumberSchemaNode, K as createResponse, Kt as Ipv4SchemaNode, L as createImport, Lt as SourceNode, M as createExport, Mt as ParameterGroupNode, N as createFile, Nt as ParamsTypeNode, O as UserFileNode, Ot as FunctionNodeType, P as createFunction, Pt as ExportNode, Q as syncOptionality, Qt as ScalarSchemaNode, R as createInput, Rt as ArraySchemaNode, S as Printer, Sn as VisitorDepth, St as ResponseNode, T as createPrinterFactory, Tt as StatusCode, U as createParameterGroup, Ut as EnumValueNode, V as createOutput, Vt as DatetimeSchemaNode, W as createParamsType, Wt as FormatStringSchemaNode, X as createText, Xt as PrimitiveSchemaType, Y as createStreamInput, Yt as ObjectSchemaNode, Z as createType, Zt as RefSchemaNode, _ as VisitorContext, _n as TypeDeclarationNode, _t as HttpMethod, a as createDiscriminantNode, an as TimeSchemaNode, at as defineSchemaDialect, b as transform, bn as NodeKind, bt as OperationNodeBase, c as findCircularSchemas, cn as PropertyNode, ct as DedupePlan, d as AsyncVisitor, dn as CodeNode, dt as Node, en as SchemaNode, et as InferSchemaNode, f as CollectOptions, fn as ConstNode, ft as InputMeta, g as Visitor, gn as TextNode, gt as GenericOperationNode, h as TransformOptions, hn as JsxNode, ht as OutputNode, i as containsCircularRef, in as StringSchemaNode, it as SchemaDialect, j as createConst, jt as FunctionParametersNode, k as createArrowFunction, kt as FunctionParamNode, l as isStringType, ln as ArrowFunctionNode, lt as applyDedupe, m as ParentOf, mn as JSDocNode, mt as InputStreamNode, n as caseParams, nn as SchemaType, nt as DispatchRule, o as createOperationParams, on as UnionSchemaNode, ot as BuildDedupePlanOptions, p as CollectVisitor, pn as FunctionNode, pt as InputNode, q as createSchema, qt as Ipv6SchemaNode, r as collectUsedSchemaNames, rn as SpecialSchemaType, rt as dispatch, s as extractStringsFromNodes, sn as UrlSchemaNode, st as DedupeCanonical, t as OperationParamsResolver, tn as SchemaNodeByType, tt as ParserOptions, u as syncSchemaRef, un as BreakNode, ut as buildDedupePlan, v as WalkOptions, vn as TypeNode, vt as HttpOperationNode, w as PrinterPartial, wn as schemaTypes, wt as MediaType, x as walk, xn as ScalarPrimitive, xt as OperationProtocol, y as collect, yn as BaseNode, yt as OperationNode, z as createJsx, zt as ComplexSchemaType } from "./types-CEIHPTfs.js";
|
|
3
3
|
|
|
4
4
|
//#region src/guards.d.ts
|
|
5
5
|
/**
|
package/dist/index.js
CHANGED
|
@@ -532,7 +532,7 @@ function isNode(value) {
|
|
|
532
532
|
/**
|
|
533
533
|
* Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.
|
|
534
534
|
*
|
|
535
|
-
* `Schema` children are only included when `recurse` is `true
|
|
535
|
+
* `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.
|
|
536
536
|
*
|
|
537
537
|
* @example
|
|
538
538
|
* ```ts
|
|
@@ -554,7 +554,7 @@ function* getChildren(node, recurse) {
|
|
|
554
554
|
}
|
|
555
555
|
/**
|
|
556
556
|
* Maps a node `kind` to the matching visitor callback name. Only the seven
|
|
557
|
-
* traversable node kinds have an entry
|
|
557
|
+
* traversable node kinds have an entry. Every other kind resolves to
|
|
558
558
|
* `undefined` and is skipped.
|
|
559
559
|
*/
|
|
560
560
|
const VISITOR_KEY_BY_KIND = {
|
|
@@ -587,7 +587,7 @@ function applyVisitor(node, visitor, parent) {
|
|
|
587
587
|
*
|
|
588
588
|
* Sibling nodes at each depth run concurrently up to `options.concurrency`
|
|
589
589
|
* (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
|
|
590
|
-
* work
|
|
590
|
+
* work. Lower values reduce memory pressure.
|
|
591
591
|
*
|
|
592
592
|
* @example Log every operation
|
|
593
593
|
* ```ts
|
|
@@ -1024,7 +1024,7 @@ function importKey(path, name, isTypeOnly) {
|
|
|
1024
1024
|
}
|
|
1025
1025
|
/**
|
|
1026
1026
|
* Computes a multi-level sort key for exports and imports:
|
|
1027
|
-
* non-array names first (wildcards/namespace aliases)
|
|
1027
|
+
* non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named.
|
|
1028
1028
|
*/
|
|
1029
1029
|
function sortKey(node) {
|
|
1030
1030
|
const isArray = Array.isArray(node.name) ? "1" : "0";
|
|
@@ -1199,7 +1199,7 @@ function resolveRefName(node) {
|
|
|
1199
1199
|
/**
|
|
1200
1200
|
* Collects every named schema referenced (transitively) from a node via ref edges.
|
|
1201
1201
|
*
|
|
1202
|
-
* Refs are followed by name only
|
|
1202
|
+
* Refs are followed by name only, the resolved `node.schema` is not traversed inline.
|
|
1203
1203
|
* Use this to determine schema dependencies, build reference graphs, or detect what schemas need to be emitted.
|
|
1204
1204
|
*
|
|
1205
1205
|
* @example Collect refs from a single schema
|
|
@@ -1235,7 +1235,7 @@ function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
|
|
|
1235
1235
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
1236
1236
|
*
|
|
1237
1237
|
* An operation uses a schema when any of its parameters, request body content, or responses
|
|
1238
|
-
* reference it
|
|
1238
|
+
* reference it, directly or indirectly through other named schemas.
|
|
1239
1239
|
* The walk is iterative and safe against reference cycles.
|
|
1240
1240
|
*
|
|
1241
1241
|
* Use this together with `include` filters to determine which schemas from `components/schemas`
|
|
@@ -1325,7 +1325,7 @@ function findCircularSchemas(schemas) {
|
|
|
1325
1325
|
* Use `excludeName` to ignore refs to specific schemas (useful when self-references are handled separately).
|
|
1326
1326
|
* Commonly used with `findCircularSchemas()` to detect where lazy wrappers are needed in code generation.
|
|
1327
1327
|
*
|
|
1328
|
-
* @note Returns `true` for the first matching circular ref found
|
|
1328
|
+
* @note Returns `true` for the first matching circular ref found. Use for fast dependency checks.
|
|
1329
1329
|
*/
|
|
1330
1330
|
function containsCircularRef(node, { circularSchemas, excludeName }) {
|
|
1331
1331
|
if (!node || circularSchemas.size === 0) return false;
|
|
@@ -1360,7 +1360,7 @@ function syncOptionality(schema, required) {
|
|
|
1360
1360
|
* `changes` already equals (by reference) the current value, otherwise a new node
|
|
1361
1361
|
* with the changes applied.
|
|
1362
1362
|
*
|
|
1363
|
-
* Mirrors the TypeScript compiler's `factory.updateX` contract
|
|
1363
|
+
* Mirrors the TypeScript compiler's `factory.updateX` contract, pair it with the
|
|
1364
1364
|
* structural sharing in {@link transform} so a no-op rewrite doesn't allocate and
|
|
1365
1365
|
* downstream passes can detect "nothing changed" by identity. Comparison is
|
|
1366
1366
|
* shallow: a structurally-equal but newly-allocated array/object counts as a change.
|
|
@@ -1476,7 +1476,7 @@ function createOperation(props) {
|
|
|
1476
1476
|
}
|
|
1477
1477
|
/**
|
|
1478
1478
|
* Maps schema `type` to its underlying `primitive`.
|
|
1479
|
-
* Primitive types map to themselves
|
|
1479
|
+
* Primitive types map to themselves. Special string formats map to `'string'`.
|
|
1480
1480
|
* Complex types (`ref`, `enum`, `union`, `intersection`, `tuple`, `blob`) are left unset.
|
|
1481
1481
|
*/
|
|
1482
1482
|
const TYPE_TO_PRIMITIVE = {
|
|
@@ -1627,7 +1627,7 @@ function createResponse(props) {
|
|
|
1627
1627
|
* // → params?: QueryParams
|
|
1628
1628
|
* ```
|
|
1629
1629
|
*
|
|
1630
|
-
* @example Param with default (implicitly optional
|
|
1630
|
+
* @example Param with default (implicitly optional. Cannot combine with `optional: true`)
|
|
1631
1631
|
* ```ts
|
|
1632
1632
|
* createFunctionParameter({ name: 'config', type: createParamsType({ variant: 'reference', name: 'RequestConfig' }), default: '{}' })
|
|
1633
1633
|
* // → config: RequestConfig = {}
|
|
@@ -1684,7 +1684,7 @@ function createParamsType(props) {
|
|
|
1684
1684
|
* // call → { id, name }
|
|
1685
1685
|
* ```
|
|
1686
1686
|
*
|
|
1687
|
-
* @example Inline (spread)
|
|
1687
|
+
* @example Inline (spread), children emitted as individual top-level parameters
|
|
1688
1688
|
* ```ts
|
|
1689
1689
|
* createParameterGroup({
|
|
1690
1690
|
* properties: [createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false })],
|
|
@@ -1786,9 +1786,9 @@ function createSource(props) {
|
|
|
1786
1786
|
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
1787
1787
|
*
|
|
1788
1788
|
* Computes:
|
|
1789
|
-
* - `id`
|
|
1790
|
-
* - `name`
|
|
1791
|
-
* - `extname`
|
|
1789
|
+
* - `id` SHA256 hash of the file path
|
|
1790
|
+
* - `name` `baseName` without extension
|
|
1791
|
+
* - `extname` extension extracted from `baseName`
|
|
1792
1792
|
*
|
|
1793
1793
|
* Deduplicates:
|
|
1794
1794
|
* - `sources` via `combineSources`
|
|
@@ -2020,7 +2020,7 @@ function createJsx(value) {
|
|
|
2020
2020
|
/**
|
|
2021
2021
|
* The shape-affecting flags shared by every node kind: base primitive, format, and `nullable`.
|
|
2022
2022
|
* Documentation and usage-slot flags (`optional`/`nullish`/`readOnly`/`writeOnly`) are
|
|
2023
|
-
* intentionally excluded
|
|
2023
|
+
* intentionally excluded, they describe the property slot, not the type.
|
|
2024
2024
|
*/
|
|
2025
2025
|
function flagsDescriptor(node) {
|
|
2026
2026
|
return `${node.primitive ?? ""};${node.format ?? ""};${node.nullable ? 1 : 0}`;
|
|
@@ -2233,7 +2233,7 @@ function serializeShapeField(field, node, record) {
|
|
|
2233
2233
|
}
|
|
2234
2234
|
/**
|
|
2235
2235
|
* Builds the local, shape-only descriptor for a node: its kind, flags, constraints, and its
|
|
2236
|
-
* children's signatures. {@link signatureOf} hashes this string
|
|
2236
|
+
* children's signatures. {@link signatureOf} hashes this string. Children contribute their
|
|
2237
2237
|
* fixed-length signature rather than their own full descriptor, which keeps the result bounded.
|
|
2238
2238
|
*/
|
|
2239
2239
|
function describeShape(node) {
|
|
@@ -2252,14 +2252,14 @@ function describeShape(node) {
|
|
|
2252
2252
|
* during dedupe planning is not re-hashed when the same tree is rewritten during streaming
|
|
2253
2253
|
* (where `schemaSignature` and `applyDedupe` would otherwise each walk it from scratch). Reuse
|
|
2254
2254
|
* across calls is sound because a signature depends only on a node's content, and schema nodes
|
|
2255
|
-
* are immutable once created
|
|
2255
|
+
* are immutable once created, transforms allocate new objects rather than mutating in place.
|
|
2256
2256
|
*/
|
|
2257
2257
|
const signatureCache = /* @__PURE__ */ new WeakMap();
|
|
2258
2258
|
/**
|
|
2259
2259
|
* Hash-consing: each node's signature is a fixed-length digest of its local shape plus its
|
|
2260
2260
|
* children's digests (a Merkle hash). Children contribute their 64-char hash instead of their
|
|
2261
2261
|
* full nested descriptor, so a signature stays bounded regardless of subtree depth, and the
|
|
2262
|
-
* digest is identical across calls because it depends only on content
|
|
2262
|
+
* digest is identical across calls because it depends only on content, never on traversal
|
|
2263
2263
|
* order. This keeps the keys built during planning consistent with the ones recomputed later
|
|
2264
2264
|
* during streaming. {@link signatureCache} memoizes node → digest across every computation.
|
|
2265
2265
|
*/
|
|
@@ -2337,7 +2337,7 @@ function cleanDefinition(node, name) {
|
|
|
2337
2337
|
*
|
|
2338
2338
|
* A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence
|
|
2339
2339
|
* is a named top-level schema, that name becomes the canonical (so other top-level duplicates
|
|
2340
|
-
* and inline copies turn into references to it)
|
|
2340
|
+
* and inline copies turn into references to it). Otherwise a new definition is hoisted using
|
|
2341
2341
|
* `nameFor`. The plan is then applied per node with {@link applyDedupe}.
|
|
2342
2342
|
*
|
|
2343
2343
|
* @example
|
|
@@ -2402,7 +2402,7 @@ function buildDedupePlan(roots, options) {
|
|
|
2402
2402
|
//#region src/dialect.ts
|
|
2403
2403
|
/**
|
|
2404
2404
|
* Identity helper that types a {@link SchemaDialect} for an adapter. Like
|
|
2405
|
-
* `defineParser`, it adds no runtime behavior
|
|
2405
|
+
* `defineParser`, it adds no runtime behavior, it pins the dialect's type for
|
|
2406
2406
|
* inference and gives adapter authors a discoverable anchor.
|
|
2407
2407
|
*
|
|
2408
2408
|
* @example
|
|
@@ -2432,7 +2432,7 @@ function defineSchemaDialect(dialect) {
|
|
|
2432
2432
|
*
|
|
2433
2433
|
* An adapter derives a context from a source spec node, then declares an ordered table of
|
|
2434
2434
|
* rules mapping spec shapes onto Kubb AST nodes. To add support for a new spec, write a new
|
|
2435
|
-
* context type and a new rules table
|
|
2435
|
+
* context type and a new rules table, the traversal here is reused unchanged.
|
|
2436
2436
|
*
|
|
2437
2437
|
* Order is significant: earlier rules win, so list higher-precedence or more specific shapes
|
|
2438
2438
|
* first (e.g. composition keywords before plain `type`). A rule whose `match` returns `true`
|
|
@@ -2462,11 +2462,11 @@ function dispatch(rules, context) {
|
|
|
2462
2462
|
*
|
|
2463
2463
|
* The builder receives resolved options and returns:
|
|
2464
2464
|
*
|
|
2465
|
-
* - `name`
|
|
2466
|
-
* - `options`
|
|
2467
|
-
* - `nodes`
|
|
2465
|
+
* - `name` unique identifier for the printer.
|
|
2466
|
+
* - `options` stored on the returned printer instance.
|
|
2467
|
+
* - `nodes` map of `SchemaType` → handler. Handlers return the rendered
|
|
2468
2468
|
* output (a string, a TypeScript AST node, ...) for that schema type.
|
|
2469
|
-
* - `print` (optional)
|
|
2469
|
+
* - `print` (optional), top-level override exposed as `printer.print`.
|
|
2470
2470
|
* Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
|
|
2471
2471
|
*
|
|
2472
2472
|
* Without a `print` override, `printer.print` falls back to `printer.transform`
|