@kubb/ast 5.0.0-beta.53 → 5.0.0-beta.55
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 +75 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -26
- package/dist/index.js +74 -106
- package/dist/index.js.map +1 -1
- package/dist/{types-IHUK_alM.d.ts → types-BL7RpQAE.d.ts} +141 -172
- package/dist/types.d.ts +2 -2
- package/dist/{utils-BIcKgbbc.js → utils-0p8ZO287.js} +15 -71
- package/dist/utils-0p8ZO287.js.map +1 -0
- package/dist/{utils-CMRZrT-w.cjs → utils-cdQ6Pzyi.cjs} +14 -82
- package/dist/utils-cdQ6Pzyi.cjs.map +1 -0
- package/dist/utils.cjs +1 -2
- package/dist/utils.d.ts +1 -14
- package/dist/utils.js +2 -2
- package/package.json +1 -1
- package/src/dedupe.ts +47 -16
- package/src/dialect.ts +23 -28
- package/src/factory.ts +2 -3
- package/src/index.ts +1 -3
- package/src/mocks.ts +1 -1
- package/src/nodes/index.ts +6 -4
- package/src/nodes/{root.ts → input.ts} +16 -39
- package/src/nodes/operation.ts +1 -41
- package/src/nodes/requestBody.ts +42 -0
- package/src/signature.ts +23 -48
- package/src/types.ts +1 -3
- package/src/utils/index.ts +3 -1
- package/dist/utils-BIcKgbbc.js.map +0 -1
- package/dist/utils-CMRZrT-w.cjs.map +0 -1
- package/src/dispatch.ts +0 -53
- package/src/resolvers.ts +0 -31
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 DedupeCanonical, $t as schemaTypes, A as createFunctionParameter, At as NumberSchemaNode, B as createProperty, Bt as UnionSchemaNode, C as UserFileNode, Ct as ImportNode, D as createExport, Dt as DatetimeSchemaNode, E as createConst, Et as DateSchemaNode, F as createOperation, Ft as SchemaNode, G as createText, Gt as ConstNode, H as createSchema, Ht as PropertyNode, I as createOutput, It as SchemaNodeByType, J as update, Jt as JsxNode, K as createType, Kt as FunctionNode, L as createParameter, Lt as SchemaType, M as createImport, Mt as PrimitiveSchemaType, N as createInput, Nt as RefSchemaNode, O as createFile, Ot as EnumSchemaNode, P as createJsx, Pt as ScalarSchemaType, Q as defineSchemaDialect, Qt as httpMethods, R as createParameterGroup, Rt as StringSchemaNode, S as DistributiveOmit, St as FileNode, T as createBreak, Tt as ArraySchemaNode, U as createSource, Ut as ArrowFunctionNode, V as createResponse, Vt as UrlSchemaNode, W as createStreamInput, Wt as CodeNode, X as ParserOptions, Xt as TypeNode, Y as InferSchemaNode, Yt as TextNode, Z as SchemaDialect, Zt as NodeKind, _ as Printer, _t as FunctionParameterNode, a as createDiscriminantNode, at as OutputNode, b as createPrinterFactory, bt as ParamsTypeNode, c as findCircularSchemas, ct as HttpMethod, d as ParentOf, dt as ResponseNode, et as DedupeLookups, f as Visitor, ft as StatusCode, g as walk, gt as FunctionParamNode, h as transform, ht as FunctionNodeType, i as containsCircularRef, it as Node, j as createFunctionParameters, jt as ObjectSchemaNode, k as createFunction, kt as IntersectionSchemaNode, l as isStringType, lt as HttpOperationNode, m as collect, mt as ParameterNode, n as caseParams, nt as applyDedupe, o as createOperationParams, ot as InputMeta, p as VisitorContext, pt as ParameterLocation, q as syncOptionality, qt as JSDocNode, r as collectUsedSchemaNames, rt as buildDedupePlan, s as extractStringsFromNodes, st as InputNode, t as OperationParamsResolver, tt as DedupePlan, u as syncSchemaRef, ut as OperationNode, v as PrinterFactoryOptions, vt as FunctionParametersNode, w as createArrowFunction, wt as SourceNode, x as definePrinter, xt as ExportNode, y as PrinterPartial, yt as ParameterGroupNode, z as createParamsType, zt as TimeSchemaNode } from "./types-BL7RpQAE.js";
|
|
3
3
|
|
|
4
4
|
//#region src/guards.d.ts
|
|
5
5
|
/**
|
|
@@ -68,37 +68,21 @@ declare function isHttpOperationNode(node: OperationNode): node is HttpOperation
|
|
|
68
68
|
*/
|
|
69
69
|
declare const isSchemaNode: (node: unknown) => node is SchemaNode;
|
|
70
70
|
//#endregion
|
|
71
|
-
//#region src/resolvers.d.ts
|
|
72
|
-
/**
|
|
73
|
-
* Collects import entries for all `ref` schema nodes in `node`.
|
|
74
|
-
*/
|
|
75
|
-
declare function collectImports<TImport>({
|
|
76
|
-
node,
|
|
77
|
-
nameMapping,
|
|
78
|
-
resolve
|
|
79
|
-
}: {
|
|
80
|
-
node: SchemaNode;
|
|
81
|
-
nameMapping: Map<string, string>;
|
|
82
|
-
resolve: (schemaName: string) => TImport | null;
|
|
83
|
-
}): Array<TImport>;
|
|
84
|
-
//#endregion
|
|
85
71
|
//#region src/signature.d.ts
|
|
86
72
|
/**
|
|
87
|
-
* Computes a deterministic, shape-only signature (a
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* is kept because it changes the produced type. `ref` nodes compare by target name,
|
|
93
|
-
* which also keeps the algorithm terminating on circular shapes.
|
|
73
|
+
* Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas
|
|
74
|
+
* share a signature when they are structurally identical, ignoring documentation (`name`, `title`,
|
|
75
|
+
* `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,
|
|
76
|
+
* `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`
|
|
77
|
+
* nodes compare by target name, which also terminates on circular shapes.
|
|
94
78
|
*
|
|
95
79
|
* @example Two enums with different descriptions share a signature
|
|
96
80
|
* ```ts
|
|
97
|
-
*
|
|
98
|
-
*
|
|
81
|
+
* signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
|
|
82
|
+
* signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
|
|
99
83
|
* ```
|
|
100
84
|
*/
|
|
101
|
-
declare function
|
|
85
|
+
declare function signatureOf(node: SchemaNode): string;
|
|
102
86
|
//#endregion
|
|
103
87
|
//#region src/transformers.d.ts
|
|
104
88
|
/**
|
|
@@ -154,5 +138,5 @@ declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Genera
|
|
|
154
138
|
declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
155
139
|
declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
|
|
156
140
|
//#endregion
|
|
157
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, type CodeNode, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type
|
|
141
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, type CodeNode, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupeCanonical, type DedupeLookups, type DedupePlan, type DistributiveOmit, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OperationParamsResolver, 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 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, applyDedupe, buildDedupePlan, caseParams, collect, 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, extractStringsFromNodes, findCircularSchemas, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, signatureOf, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
|
|
158
142
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import "./chunk-C0LytTxp.js";
|
|
2
|
-
import {
|
|
2
|
+
import { _ as httpMethods, a as enumPropName, b as visitorDepths, g as camelCase, h as isValidVarName, o as extractRefName, v as isScalarPrimitive, y as schemaTypes } from "./utils-0p8ZO287.js";
|
|
3
3
|
import { hash } from "node:crypto";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
//#region ../../internals/utils/src/fs.ts
|
|
6
|
+
/**
|
|
7
|
+
* Strips the file extension from a path or file name.
|
|
8
|
+
* Only removes the last `.ext` segment when the dot is not part of a directory name.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* trimExtName('petStore.ts') // 'petStore'
|
|
12
|
+
* trimExtName('/src/models/pet.ts') // '/src/models/pet'
|
|
13
|
+
* trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
|
|
14
|
+
* trimExtName('noExtension') // 'noExtension'
|
|
15
|
+
*/
|
|
16
|
+
function trimExtName(text) {
|
|
17
|
+
const dotIndex = text.lastIndexOf(".");
|
|
18
|
+
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
5
22
|
//#region ../../internals/utils/src/promise.ts
|
|
6
23
|
/**
|
|
7
24
|
* Wraps `factory` with a keyed cache backed by the provided store.
|
|
@@ -1054,7 +1071,7 @@ function createInput(overrides = {}) {
|
|
|
1054
1071
|
};
|
|
1055
1072
|
}
|
|
1056
1073
|
/**
|
|
1057
|
-
* Creates
|
|
1074
|
+
* Creates a streaming `InputNode<true>` from pre-built `AsyncIterable` sources.
|
|
1058
1075
|
*
|
|
1059
1076
|
* @example
|
|
1060
1077
|
* ```ts
|
|
@@ -1677,9 +1694,7 @@ function createJsx(value) {
|
|
|
1677
1694
|
//#endregion
|
|
1678
1695
|
//#region src/signature.ts
|
|
1679
1696
|
/**
|
|
1680
|
-
* The
|
|
1681
|
-
* Documentation and usage-slot flags (`optional`/`nullish`/`readOnly`/`writeOnly`) are
|
|
1682
|
-
* intentionally excluded, they describe the property slot, not the type.
|
|
1697
|
+
* The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.
|
|
1683
1698
|
*/
|
|
1684
1699
|
function flagsDescriptor(node) {
|
|
1685
1700
|
return `${node.primitive ?? ""};${node.format ?? ""};${node.nullable ? 1 : 0}`;
|
|
@@ -1752,9 +1767,8 @@ const rangeFields = [{
|
|
|
1752
1767
|
prefix: "mx"
|
|
1753
1768
|
}];
|
|
1754
1769
|
/**
|
|
1755
|
-
* Maps each
|
|
1756
|
-
*
|
|
1757
|
-
* back to `${type}|${flags}` with no additional fields.
|
|
1770
|
+
* Maps each node `type` to its ordered shape-contributing fields. Types absent from the map
|
|
1771
|
+
* (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.
|
|
1758
1772
|
*/
|
|
1759
1773
|
const SHAPE_KEYS = {
|
|
1760
1774
|
object: [
|
|
@@ -1891,9 +1905,8 @@ function serializeShapeField(field, node, record) {
|
|
|
1891
1905
|
}
|
|
1892
1906
|
}
|
|
1893
1907
|
/**
|
|
1894
|
-
* Builds the local
|
|
1895
|
-
* children's signatures.
|
|
1896
|
-
* fixed-length signature rather than their own full descriptor, which keeps the result bounded.
|
|
1908
|
+
* Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,
|
|
1909
|
+
* constraints, and its children's signatures.
|
|
1897
1910
|
*/
|
|
1898
1911
|
function describeShape(node) {
|
|
1899
1912
|
const flags = flagsDescriptor(node);
|
|
@@ -1905,22 +1918,23 @@ function describeShape(node) {
|
|
|
1905
1918
|
return parts.join("|");
|
|
1906
1919
|
}
|
|
1907
1920
|
/**
|
|
1908
|
-
*
|
|
1909
|
-
*
|
|
1910
|
-
*
|
|
1911
|
-
* during dedupe planning is not re-hashed when the same tree is rewritten during streaming
|
|
1912
|
-
* (where `schemaSignature` and `applyDedupe` would otherwise each walk it from scratch). Reuse
|
|
1913
|
-
* across calls is sound because a signature depends only on a node's content, and schema nodes
|
|
1914
|
-
* are immutable once created, transforms allocate new objects rather than mutating in place.
|
|
1921
|
+
* Node → digest cache, keyed by identity. A `WeakMap` so entries die with the node, and so a tree
|
|
1922
|
+
* hashed during dedupe planning is not walked again when it is rewritten during streaming. Reuse
|
|
1923
|
+
* is safe because a signature depends only on content, and nodes are immutable once created.
|
|
1915
1924
|
*/
|
|
1916
1925
|
const signatureCache = /* @__PURE__ */ new WeakMap();
|
|
1917
1926
|
/**
|
|
1918
|
-
*
|
|
1919
|
-
*
|
|
1920
|
-
*
|
|
1921
|
-
*
|
|
1922
|
-
*
|
|
1923
|
-
*
|
|
1927
|
+
* Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas
|
|
1928
|
+
* share a signature when they are structurally identical, ignoring documentation (`name`, `title`,
|
|
1929
|
+
* `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,
|
|
1930
|
+
* `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`
|
|
1931
|
+
* nodes compare by target name, which also terminates on circular shapes.
|
|
1932
|
+
*
|
|
1933
|
+
* @example Two enums with different descriptions share a signature
|
|
1934
|
+
* ```ts
|
|
1935
|
+
* signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
|
|
1936
|
+
* signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
|
|
1937
|
+
* ```
|
|
1924
1938
|
*/
|
|
1925
1939
|
function signatureOf(node) {
|
|
1926
1940
|
const cached = signatureCache.get(node);
|
|
@@ -1929,24 +1943,6 @@ function signatureOf(node) {
|
|
|
1929
1943
|
signatureCache.set(node, signature);
|
|
1930
1944
|
return signature;
|
|
1931
1945
|
}
|
|
1932
|
-
/**
|
|
1933
|
-
* Computes a deterministic, shape-only signature (a fixed-length content hash) for a schema node.
|
|
1934
|
-
*
|
|
1935
|
-
* Two schemas share a signature when they are structurally identical, ignoring
|
|
1936
|
-
* documentation (`name`, `title`, `description`, `example`, `default`, `deprecated`)
|
|
1937
|
-
* and usage-slot flags (`optional`, `nullish`, `readOnly`, `writeOnly`). `nullable`
|
|
1938
|
-
* is kept because it changes the produced type. `ref` nodes compare by target name,
|
|
1939
|
-
* which also keeps the algorithm terminating on circular shapes.
|
|
1940
|
-
*
|
|
1941
|
-
* @example Two enums with different descriptions share a signature
|
|
1942
|
-
* ```ts
|
|
1943
|
-
* schemaSignature(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
|
|
1944
|
-
* schemaSignature(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
|
|
1945
|
-
* ```
|
|
1946
|
-
*/
|
|
1947
|
-
function schemaSignature(node) {
|
|
1948
|
-
return signatureOf(node);
|
|
1949
|
-
}
|
|
1950
1946
|
//#endregion
|
|
1951
1947
|
//#region src/dedupe.ts
|
|
1952
1948
|
/**
|
|
@@ -1968,10 +1964,20 @@ function createRefNode(node, canonical) {
|
|
|
1968
1964
|
example: node.example
|
|
1969
1965
|
});
|
|
1970
1966
|
}
|
|
1971
|
-
function applyDedupe(node,
|
|
1972
|
-
|
|
1967
|
+
function applyDedupe(node, plan, skipRootMatch = false) {
|
|
1968
|
+
const { canonicalBySignature, aliasNames } = plan;
|
|
1969
|
+
if (canonicalBySignature.size === 0 && aliasNames.size === 0) return node;
|
|
1973
1970
|
const root = node;
|
|
1974
1971
|
return transform(node, { schema(schemaNode) {
|
|
1972
|
+
if (schemaNode.type === "ref") {
|
|
1973
|
+
const target = schemaNode.ref ? extractRefName(schemaNode.ref) : schemaNode.name;
|
|
1974
|
+
const canonical = target ? aliasNames.get(target) : void 0;
|
|
1975
|
+
return canonical ? {
|
|
1976
|
+
...schemaNode,
|
|
1977
|
+
name: canonical.name,
|
|
1978
|
+
ref: canonical.ref
|
|
1979
|
+
} : void 0;
|
|
1980
|
+
}
|
|
1975
1981
|
const signature = signatureOf(schemaNode);
|
|
1976
1982
|
if (skipRootMatch && schemaNode === root) return void 0;
|
|
1977
1983
|
const canonical = canonicalBySignature.get(signature);
|
|
@@ -1995,9 +2001,11 @@ function cleanDefinition(node, name) {
|
|
|
1995
2001
|
* Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.
|
|
1996
2002
|
*
|
|
1997
2003
|
* A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence
|
|
1998
|
-
* is a named top-level schema,
|
|
1999
|
-
* and inline copies turn into references to it).
|
|
2000
|
-
*
|
|
2004
|
+
* is a named top-level schema, the first one becomes the canonical (so other top-level
|
|
2005
|
+
* duplicates and inline copies turn into references to it). Every other top-level name with
|
|
2006
|
+
* the same content is recorded in `aliasNames`, so refs to it can be repointed at the
|
|
2007
|
+
* canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied
|
|
2008
|
+
* per node with {@link applyDedupe}.
|
|
2001
2009
|
*
|
|
2002
2010
|
* @example
|
|
2003
2011
|
* ```ts
|
|
@@ -2019,11 +2027,11 @@ function buildDedupePlan(roots, options) {
|
|
|
2019
2027
|
const group = groups.get(signature);
|
|
2020
2028
|
if (group) {
|
|
2021
2029
|
group.count++;
|
|
2022
|
-
if (isTopLevel
|
|
2030
|
+
if (isTopLevel) group.topLevelNames.push(schemaNode.name);
|
|
2023
2031
|
} else groups.set(signature, {
|
|
2024
2032
|
count: 1,
|
|
2025
2033
|
representative: schemaNode,
|
|
2026
|
-
|
|
2034
|
+
topLevelNames: isTopLevel ? [schemaNode.name] : []
|
|
2027
2035
|
});
|
|
2028
2036
|
}
|
|
2029
2037
|
for (const root of roots) {
|
|
@@ -2031,14 +2039,18 @@ function buildDedupePlan(roots, options) {
|
|
|
2031
2039
|
for (const schemaNode of collectLazy(root, { schema: (node) => node })) record(schemaNode);
|
|
2032
2040
|
}
|
|
2033
2041
|
const canonicalBySignature = /* @__PURE__ */ new Map();
|
|
2042
|
+
const aliasNames = /* @__PURE__ */ new Map();
|
|
2034
2043
|
const pendingHoists = [];
|
|
2035
2044
|
for (const [signature, group] of groups) {
|
|
2036
2045
|
if (group.count < minOccurrences) continue;
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2046
|
+
const [firstName, ...duplicateNames] = group.topLevelNames;
|
|
2047
|
+
if (firstName) {
|
|
2048
|
+
const canonical = {
|
|
2049
|
+
name: firstName,
|
|
2050
|
+
ref: refFor(firstName)
|
|
2051
|
+
};
|
|
2052
|
+
canonicalBySignature.set(signature, canonical);
|
|
2053
|
+
for (const duplicate of duplicateNames) aliasNames.set(duplicate, canonical);
|
|
2042
2054
|
continue;
|
|
2043
2055
|
}
|
|
2044
2056
|
const name = nameFor(group.representative, signature);
|
|
@@ -2054,15 +2066,18 @@ function buildDedupePlan(roots, options) {
|
|
|
2054
2066
|
}
|
|
2055
2067
|
return {
|
|
2056
2068
|
canonicalBySignature,
|
|
2057
|
-
|
|
2069
|
+
aliasNames,
|
|
2070
|
+
hoisted: pendingHoists.map(({ name, representative }) => cleanDefinition(applyDedupe(representative, {
|
|
2071
|
+
canonicalBySignature,
|
|
2072
|
+
aliasNames
|
|
2073
|
+
}, true), name))
|
|
2058
2074
|
};
|
|
2059
2075
|
}
|
|
2060
2076
|
//#endregion
|
|
2061
2077
|
//#region src/dialect.ts
|
|
2062
2078
|
/**
|
|
2063
|
-
*
|
|
2064
|
-
*
|
|
2065
|
-
* inference and gives adapter authors a discoverable anchor.
|
|
2079
|
+
* Types a {@link SchemaDialect} for an adapter. Adds no runtime behavior and only pins the
|
|
2080
|
+
* dialect's type for inference.
|
|
2066
2081
|
*
|
|
2067
2082
|
* @example
|
|
2068
2083
|
* ```ts
|
|
@@ -2080,38 +2095,6 @@ function defineSchemaDialect(dialect) {
|
|
|
2080
2095
|
return dialect;
|
|
2081
2096
|
}
|
|
2082
2097
|
//#endregion
|
|
2083
|
-
//#region src/dispatch.ts
|
|
2084
|
-
/**
|
|
2085
|
-
* Walks an ordered list of {@link DispatchRule}s and returns the first node produced.
|
|
2086
|
-
*
|
|
2087
|
-
* This is the shared backbone for spec adapters (OpenAPI today, AsyncAPI and others later).
|
|
2088
|
-
* The contract an adapter follows is intentionally minimal:
|
|
2089
|
-
*
|
|
2090
|
-
* context → [rule.match → rule.convert] → node
|
|
2091
|
-
*
|
|
2092
|
-
* An adapter derives a context from a source spec node, then declares an ordered table of
|
|
2093
|
-
* rules mapping spec shapes onto Kubb AST nodes. To add support for a new spec, write a new
|
|
2094
|
-
* context type and a new rules table, the traversal here is reused unchanged.
|
|
2095
|
-
*
|
|
2096
|
-
* Order is significant: earlier rules win, so list higher-precedence or more specific shapes
|
|
2097
|
-
* first (e.g. composition keywords before plain `type`). A rule whose `match` returns `true`
|
|
2098
|
-
* may still `convert` to `null` to defer to later rules. When no rule produces a node this
|
|
2099
|
-
* returns `null`, leaving the caller to apply its own fallback.
|
|
2100
|
-
*
|
|
2101
|
-
* @example
|
|
2102
|
-
* ```ts
|
|
2103
|
-
* const node = dispatch(schemaRules, schemaContext) ?? createSchema({ type: fallbackType })
|
|
2104
|
-
* ```
|
|
2105
|
-
*/
|
|
2106
|
-
function dispatch(rules, context) {
|
|
2107
|
-
for (const rule of rules) {
|
|
2108
|
-
if (!rule.match(context)) continue;
|
|
2109
|
-
const node = rule.convert(context);
|
|
2110
|
-
if (node !== null && node !== void 0) return node;
|
|
2111
|
-
}
|
|
2112
|
-
return null;
|
|
2113
|
-
}
|
|
2114
|
-
//#endregion
|
|
2115
2098
|
//#region src/printer.ts
|
|
2116
2099
|
/**
|
|
2117
2100
|
* Defines a schema printer: a function that takes a `SchemaNode` and emits
|
|
@@ -2189,21 +2172,6 @@ function createPrinterFactory(getKey) {
|
|
|
2189
2172
|
};
|
|
2190
2173
|
}
|
|
2191
2174
|
//#endregion
|
|
2192
|
-
//#region src/resolvers.ts
|
|
2193
|
-
/**
|
|
2194
|
-
* Collects import entries for all `ref` schema nodes in `node`.
|
|
2195
|
-
*/
|
|
2196
|
-
function collectImports({ node, nameMapping, resolve }) {
|
|
2197
|
-
return collect(node, { schema(schemaNode) {
|
|
2198
|
-
const schemaRef = narrowSchema(schemaNode, "ref");
|
|
2199
|
-
if (!schemaRef?.ref) return null;
|
|
2200
|
-
const rawName = extractRefName(schemaRef.ref);
|
|
2201
|
-
const result = resolve(nameMapping.get(rawName) ?? rawName);
|
|
2202
|
-
if (!result) return null;
|
|
2203
|
-
return result;
|
|
2204
|
-
} });
|
|
2205
|
-
}
|
|
2206
|
-
//#endregion
|
|
2207
2175
|
//#region src/transformers.ts
|
|
2208
2176
|
/**
|
|
2209
2177
|
* Replaces a discriminator property's schema with a string enum of allowed values.
|
|
@@ -2311,6 +2279,6 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
|
|
|
2311
2279
|
return propNode;
|
|
2312
2280
|
}
|
|
2313
2281
|
//#endregion
|
|
2314
|
-
export { applyDedupe, buildDedupePlan, caseParams, collect,
|
|
2282
|
+
export { applyDedupe, buildDedupePlan, caseParams, collect, 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, extractStringsFromNodes, findCircularSchemas, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, signatureOf, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
|
|
2315
2283
|
|
|
2316
2284
|
//# sourceMappingURL=index.js.map
|