@kubb/ast 5.0.0-beta.13 → 5.0.0-beta.14
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 +41 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +41 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/utils.ts +7 -6
- package/src/visitor.ts +31 -31
package/dist/index.d.ts
CHANGED
|
@@ -3170,6 +3170,7 @@ declare function transform(node: Node, options: TransformOptions): Node;
|
|
|
3170
3170
|
* const values = collect(root, { depth: 'shallow', root: () => 'root' })
|
|
3171
3171
|
* ```
|
|
3172
3172
|
*/
|
|
3173
|
+
declare function collectLazy<T>(node: Node, options: CollectOptions<T>): Generator<T, void, undefined>;
|
|
3173
3174
|
declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
|
|
3174
3175
|
//#endregion
|
|
3175
3176
|
//#region src/utils.d.ts
|
|
@@ -3447,5 +3448,5 @@ declare function containsCircularRef(node: SchemaNode | undefined, {
|
|
|
3447
3448
|
excludeName?: string;
|
|
3448
3449
|
}): boolean;
|
|
3449
3450
|
//#endregion
|
|
3450
|
-
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, 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 };
|
|
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 };
|
|
3451
3452
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -510,32 +510,36 @@ function createLimit(concurrency) {
|
|
|
510
510
|
* // returns parameters, requestBody schema (if present), and responses
|
|
511
511
|
* ```
|
|
512
512
|
*/
|
|
513
|
-
function getChildren(node, recurse) {
|
|
513
|
+
function* getChildren(node, recurse) {
|
|
514
514
|
switch (node.kind) {
|
|
515
|
-
case "Input":
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
if (
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
case "
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
case "
|
|
538
|
-
|
|
515
|
+
case "Input":
|
|
516
|
+
yield* node.schemas;
|
|
517
|
+
yield* node.operations;
|
|
518
|
+
break;
|
|
519
|
+
case "Output": break;
|
|
520
|
+
case "Operation":
|
|
521
|
+
yield* node.parameters;
|
|
522
|
+
if (node.requestBody?.content) {
|
|
523
|
+
for (const c of node.requestBody.content) if (c.schema) yield c.schema;
|
|
524
|
+
}
|
|
525
|
+
yield* node.responses;
|
|
526
|
+
break;
|
|
527
|
+
case "Schema":
|
|
528
|
+
if (!recurse) break;
|
|
529
|
+
if ("properties" in node && node.properties.length > 0) yield* node.properties;
|
|
530
|
+
if ("items" in node && node.items) yield* node.items;
|
|
531
|
+
if ("members" in node && node.members) yield* node.members;
|
|
532
|
+
if ("additionalProperties" in node && node.additionalProperties && node.additionalProperties !== true) yield node.additionalProperties;
|
|
533
|
+
break;
|
|
534
|
+
case "Property":
|
|
535
|
+
yield node.schema;
|
|
536
|
+
break;
|
|
537
|
+
case "Parameter":
|
|
538
|
+
yield node.schema;
|
|
539
|
+
break;
|
|
540
|
+
case "Response":
|
|
541
|
+
if (node.schema) yield node.schema;
|
|
542
|
+
break;
|
|
539
543
|
}
|
|
540
544
|
}
|
|
541
545
|
/**
|
|
@@ -722,10 +726,9 @@ function transform(node, options) {
|
|
|
722
726
|
* const values = collect(root, { depth: 'shallow', root: () => 'root' })
|
|
723
727
|
* ```
|
|
724
728
|
*/
|
|
725
|
-
function
|
|
729
|
+
function* collectLazy(node, options) {
|
|
726
730
|
const { depth, parent, ...visitor } = options;
|
|
727
731
|
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
728
|
-
const results = [];
|
|
729
732
|
let v;
|
|
730
733
|
switch (node.kind) {
|
|
731
734
|
case "Input":
|
|
@@ -753,12 +756,14 @@ function collect(node, options) {
|
|
|
753
756
|
case "ParameterGroup":
|
|
754
757
|
case "FunctionParameters": break;
|
|
755
758
|
}
|
|
756
|
-
if (v !== void 0)
|
|
757
|
-
for (const child of getChildren(node, recurse))
|
|
759
|
+
if (v !== void 0) yield v;
|
|
760
|
+
for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
|
|
758
761
|
...options,
|
|
759
762
|
parent: node
|
|
760
|
-
})
|
|
761
|
-
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
function collect(node, options) {
|
|
766
|
+
return Array.from(collectLazy(node, options));
|
|
762
767
|
}
|
|
763
768
|
//#endregion
|
|
764
769
|
//#region src/utils.ts
|
|
@@ -1308,7 +1313,7 @@ function collectUsedSchemaNames(operations, schemas) {
|
|
|
1308
1313
|
if (namedSchema) visitSchema(namedSchema);
|
|
1309
1314
|
}
|
|
1310
1315
|
}
|
|
1311
|
-
for (const op of operations) for (const schema of
|
|
1316
|
+
for (const op of operations) for (const schema of collectLazy(op, {
|
|
1312
1317
|
depth: "shallow",
|
|
1313
1318
|
schema: (node) => node
|
|
1314
1319
|
})) visitSchema(schema);
|
|
@@ -1357,11 +1362,12 @@ function findCircularSchemas(schemas) {
|
|
|
1357
1362
|
*/
|
|
1358
1363
|
function containsCircularRef(node, { circularSchemas, excludeName }) {
|
|
1359
1364
|
if (!node || circularSchemas.size === 0) return false;
|
|
1360
|
-
|
|
1365
|
+
for (const _ of collectLazy(node, { schema(child) {
|
|
1361
1366
|
if (child.type !== "ref") return void 0;
|
|
1362
1367
|
const name = resolveRefName(child);
|
|
1363
1368
|
return name && name !== excludeName && circularSchemas.has(name) ? true : void 0;
|
|
1364
|
-
} })
|
|
1369
|
+
} })) return true;
|
|
1370
|
+
return false;
|
|
1365
1371
|
}
|
|
1366
1372
|
//#endregion
|
|
1367
1373
|
//#region src/factory.ts
|
|
@@ -2192,6 +2198,6 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
|
|
|
2192
2198
|
return propNode;
|
|
2193
2199
|
}
|
|
2194
2200
|
//#endregion
|
|
2195
|
-
export { caseParams, childName, collect, collectImports, 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 };
|
|
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 };
|
|
2196
2202
|
|
|
2197
2203
|
//# sourceMappingURL=index.js.map
|