@kubb/ast 5.0.0-beta.14 → 5.0.0-beta.16
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 +47 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -21
- package/dist/index.js +46 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/factory.ts +14 -0
- package/src/index.ts +2 -1
- package/src/nodes/index.ts +1 -1
- package/src/nodes/root.ts +24 -0
- package/src/transformers.ts +19 -14
- package/src/types.ts +1 -0
- package/src/utils.ts +15 -5
package/dist/index.d.ts
CHANGED
|
@@ -1884,6 +1884,26 @@ type InputNode = BaseNode & {
|
|
|
1884
1884
|
*/
|
|
1885
1885
|
meta?: InputMeta;
|
|
1886
1886
|
};
|
|
1887
|
+
/**
|
|
1888
|
+
* Streaming variant of `InputNode` for memory-efficient processing of large API specs.
|
|
1889
|
+
*
|
|
1890
|
+
* `schemas` and `operations` are `AsyncIterable` rather than arrays — each `for await`
|
|
1891
|
+
* loop creates a fresh parse pass from the cached in-memory document, so multiple
|
|
1892
|
+
* consumers (plugins) can iterate independently without keeping all nodes in memory.
|
|
1893
|
+
*
|
|
1894
|
+
* @example
|
|
1895
|
+
* ```ts
|
|
1896
|
+
* for await (const schema of inputStreamNode.schemas) {
|
|
1897
|
+
* // only this one SchemaNode is live here; previous ones are GC-eligible
|
|
1898
|
+
* }
|
|
1899
|
+
* ```
|
|
1900
|
+
*/
|
|
1901
|
+
type InputStreamNode = {
|
|
1902
|
+
kind: 'Input'; /** Lazily parsed schema nodes. Each `for await` creates a fresh parse pass. */
|
|
1903
|
+
schemas: AsyncIterable<SchemaNode>; /** Lazily parsed operation nodes. Each `for await` creates a fresh parse pass. */
|
|
1904
|
+
operations: AsyncIterable<OperationNode>; /** Document metadata — available immediately, before the first yield. */
|
|
1905
|
+
meta?: InputMeta;
|
|
1906
|
+
};
|
|
1887
1907
|
//#endregion
|
|
1888
1908
|
//#region src/nodes/index.d.ts
|
|
1889
1909
|
/**
|
|
@@ -2092,6 +2112,15 @@ type CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {
|
|
|
2092
2112
|
* ```
|
|
2093
2113
|
*/
|
|
2094
2114
|
declare function createInput(overrides?: Partial<Omit<InputNode, 'kind'>>): InputNode;
|
|
2115
|
+
/**
|
|
2116
|
+
* Creates an `InputStreamNode` from pre-built `AsyncIterable` sources.
|
|
2117
|
+
*
|
|
2118
|
+
* @example
|
|
2119
|
+
* ```ts
|
|
2120
|
+
* const node = createStreamInput(schemasIterable, operationsIterable, { title: 'My API' })
|
|
2121
|
+
* ```
|
|
2122
|
+
*/
|
|
2123
|
+
declare function createStreamInput(schemas: AsyncIterable<SchemaNode>, operations: AsyncIterable<OperationNode>, meta?: InputMeta): InputStreamNode;
|
|
2095
2124
|
/**
|
|
2096
2125
|
* Creates an `OutputNode` with a stable default for `files`.
|
|
2097
2126
|
*
|
|
@@ -2901,6 +2930,7 @@ declare function setDiscriminatorEnum({
|
|
|
2901
2930
|
* ])
|
|
2902
2931
|
* ```
|
|
2903
2932
|
*/
|
|
2933
|
+
declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined>;
|
|
2904
2934
|
declare function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
2905
2935
|
/**
|
|
2906
2936
|
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
@@ -3372,26 +3402,6 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
|
|
|
3372
3402
|
* ```
|
|
3373
3403
|
*/
|
|
3374
3404
|
declare function resolveRefName(node: SchemaNode | undefined): string | undefined;
|
|
3375
|
-
/**
|
|
3376
|
-
* Collects every named schema referenced (transitively) from a node via ref edges.
|
|
3377
|
-
*
|
|
3378
|
-
* Refs are followed by name only — the resolved `node.schema` is not traversed inline.
|
|
3379
|
-
* Use this to determine schema dependencies, build reference graphs, or detect what schemas need to be emitted.
|
|
3380
|
-
*
|
|
3381
|
-
* @example Collect refs from a single schema
|
|
3382
|
-
* ```ts
|
|
3383
|
-
* const names = collectReferencedSchemaNames(petSchema)
|
|
3384
|
-
* // → Set { 'Category', 'Tag' }
|
|
3385
|
-
* ```
|
|
3386
|
-
*
|
|
3387
|
-
* @example Accumulate refs from multiple schemas into one set
|
|
3388
|
-
* ```ts
|
|
3389
|
-
* const out = new Set<string>()
|
|
3390
|
-
* for (const schema of schemas) {
|
|
3391
|
-
* collectReferencedSchemaNames(schema, out)
|
|
3392
|
-
* }
|
|
3393
|
-
* ```
|
|
3394
|
-
*/
|
|
3395
3405
|
declare function collectReferencedSchemaNames(node: SchemaNode | undefined, out?: Set<string>): Set<string>;
|
|
3396
3406
|
/**
|
|
3397
3407
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
@@ -3448,5 +3458,5 @@ declare function containsCircularRef(node: SchemaNode | undefined, {
|
|
|
3448
3458
|
excludeName?: string;
|
|
3449
3459
|
}): boolean;
|
|
3450
3460
|
//#endregion
|
|
3451
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, AsyncVisitor, type BaseNode, type BreakNode, type CodeNode, CollectOptions, CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, InferSchema, InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, OperationParamsResolver, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, ParentOf, ParserOptions, type PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, type PropertyNode, RefMap, type RefSchemaNode, type ResponseNode, ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, UserFileNode, Visitor, VisitorContext, VisitorDepth, WalkOptions, caseParams, childName, collect, collectImports, collectLazy, collectReferencedSchemaNames, 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, createText, createType, definePrinter, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
3461
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, AsyncVisitor, type BaseNode, type BreakNode, type CodeNode, CollectOptions, CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, InferSchema, InferSchemaNode, type InputMeta, type InputNode, type InputStreamNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, OperationParamsResolver, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, ParentOf, ParserOptions, type PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, type PropertyNode, RefMap, type RefSchemaNode, type ResponseNode, ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, UserFileNode, Visitor, VisitorContext, VisitorDepth, WalkOptions, caseParams, childName, collect, collectImports, collectLazy, collectReferencedSchemaNames, 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, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, mergeAdjacentObjectsLazy, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
3452
3462
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1263,14 +1263,23 @@ function resolveRefName(node) {
|
|
|
1263
1263
|
* }
|
|
1264
1264
|
* ```
|
|
1265
1265
|
*/
|
|
1266
|
-
|
|
1267
|
-
|
|
1266
|
+
const schemaRefCache = /* @__PURE__ */ new WeakMap();
|
|
1267
|
+
function collectSchemaRefs(node) {
|
|
1268
|
+
const cached = schemaRefCache.get(node);
|
|
1269
|
+
if (cached) return cached;
|
|
1270
|
+
const refs = /* @__PURE__ */ new Set();
|
|
1268
1271
|
collect(node, { schema(child) {
|
|
1269
1272
|
if (child.type === "ref") {
|
|
1270
1273
|
const name = resolveRefName(child);
|
|
1271
|
-
if (name)
|
|
1274
|
+
if (name) refs.add(name);
|
|
1272
1275
|
}
|
|
1273
1276
|
} });
|
|
1277
|
+
schemaRefCache.set(node, refs);
|
|
1278
|
+
return refs;
|
|
1279
|
+
}
|
|
1280
|
+
function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
|
|
1281
|
+
if (!node) return out;
|
|
1282
|
+
for (const name of collectSchemaRefs(node)) out.add(name);
|
|
1274
1283
|
return out;
|
|
1275
1284
|
}
|
|
1276
1285
|
/**
|
|
@@ -1409,6 +1418,22 @@ function createInput(overrides = {}) {
|
|
|
1409
1418
|
};
|
|
1410
1419
|
}
|
|
1411
1420
|
/**
|
|
1421
|
+
* Creates an `InputStreamNode` from pre-built `AsyncIterable` sources.
|
|
1422
|
+
*
|
|
1423
|
+
* @example
|
|
1424
|
+
* ```ts
|
|
1425
|
+
* const node = createStreamInput(schemasIterable, operationsIterable, { title: 'My API' })
|
|
1426
|
+
* ```
|
|
1427
|
+
*/
|
|
1428
|
+
function createStreamInput(schemas, operations, meta) {
|
|
1429
|
+
return {
|
|
1430
|
+
kind: "Input",
|
|
1431
|
+
schemas,
|
|
1432
|
+
operations,
|
|
1433
|
+
meta
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1412
1437
|
* Creates an `OutputNode` with a stable default for `files`.
|
|
1413
1438
|
*
|
|
1414
1439
|
* @example
|
|
@@ -2141,23 +2166,27 @@ function setDiscriminatorEnum({ node, propertyName, values, enumName }) {
|
|
|
2141
2166
|
* ])
|
|
2142
2167
|
* ```
|
|
2143
2168
|
*/
|
|
2144
|
-
function
|
|
2145
|
-
|
|
2169
|
+
function* mergeAdjacentObjectsLazy(members) {
|
|
2170
|
+
let acc;
|
|
2171
|
+
for (const member of members) {
|
|
2146
2172
|
const objectMember = narrowSchema(member, "object");
|
|
2147
|
-
if (objectMember && !objectMember.name) {
|
|
2148
|
-
const
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
...
|
|
2153
|
-
properties: [...previousObject.properties ?? [], ...objectMember.properties ?? []]
|
|
2173
|
+
if (objectMember && !objectMember.name && acc !== void 0) {
|
|
2174
|
+
const accObject = narrowSchema(acc, "object");
|
|
2175
|
+
if (accObject && !accObject.name) {
|
|
2176
|
+
acc = createSchema({
|
|
2177
|
+
...accObject,
|
|
2178
|
+
properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
|
|
2154
2179
|
});
|
|
2155
|
-
|
|
2180
|
+
continue;
|
|
2156
2181
|
}
|
|
2157
2182
|
}
|
|
2158
|
-
acc
|
|
2159
|
-
|
|
2160
|
-
}
|
|
2183
|
+
if (acc !== void 0) yield acc;
|
|
2184
|
+
acc = member;
|
|
2185
|
+
}
|
|
2186
|
+
if (acc !== void 0) yield acc;
|
|
2187
|
+
}
|
|
2188
|
+
function mergeAdjacentObjects(members) {
|
|
2189
|
+
return [...mergeAdjacentObjectsLazy(members)];
|
|
2161
2190
|
}
|
|
2162
2191
|
/**
|
|
2163
2192
|
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
@@ -2198,6 +2227,6 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
|
|
|
2198
2227
|
return propNode;
|
|
2199
2228
|
}
|
|
2200
2229
|
//#endregion
|
|
2201
|
-
export { caseParams, childName, collect, collectImports, collectLazy, collectReferencedSchemaNames, 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, createText, createType, definePrinter, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
2230
|
+
export { caseParams, childName, collect, collectImports, collectLazy, collectReferencedSchemaNames, 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, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, mergeAdjacentObjectsLazy, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
2202
2231
|
|
|
2203
2232
|
//# sourceMappingURL=index.js.map
|