@kubb/ast 5.0.0-beta.14 → 5.0.0-beta.15
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 +30 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -21
- package/dist/index.js +30 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/transformers.ts +19 -14
- package/src/utils.ts +15 -5
package/dist/index.d.ts
CHANGED
|
@@ -2901,6 +2901,7 @@ declare function setDiscriminatorEnum({
|
|
|
2901
2901
|
* ])
|
|
2902
2902
|
* ```
|
|
2903
2903
|
*/
|
|
2904
|
+
declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined>;
|
|
2904
2905
|
declare function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
2905
2906
|
/**
|
|
2906
2907
|
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
@@ -3372,26 +3373,6 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
|
|
|
3372
3373
|
* ```
|
|
3373
3374
|
*/
|
|
3374
3375
|
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
3376
|
declare function collectReferencedSchemaNames(node: SchemaNode | undefined, out?: Set<string>): Set<string>;
|
|
3396
3377
|
/**
|
|
3397
3378
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
@@ -3448,5 +3429,5 @@ declare function containsCircularRef(node: SchemaNode | undefined, {
|
|
|
3448
3429
|
excludeName?: string;
|
|
3449
3430
|
}): boolean;
|
|
3450
3431
|
//#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 };
|
|
3432
|
+
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, mergeAdjacentObjectsLazy, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
3452
3433
|
//# 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
|
/**
|
|
@@ -2141,23 +2150,27 @@ function setDiscriminatorEnum({ node, propertyName, values, enumName }) {
|
|
|
2141
2150
|
* ])
|
|
2142
2151
|
* ```
|
|
2143
2152
|
*/
|
|
2144
|
-
function
|
|
2145
|
-
|
|
2153
|
+
function* mergeAdjacentObjectsLazy(members) {
|
|
2154
|
+
let acc;
|
|
2155
|
+
for (const member of members) {
|
|
2146
2156
|
const objectMember = narrowSchema(member, "object");
|
|
2147
|
-
if (objectMember && !objectMember.name) {
|
|
2148
|
-
const
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
...
|
|
2153
|
-
properties: [...previousObject.properties ?? [], ...objectMember.properties ?? []]
|
|
2157
|
+
if (objectMember && !objectMember.name && acc !== void 0) {
|
|
2158
|
+
const accObject = narrowSchema(acc, "object");
|
|
2159
|
+
if (accObject && !accObject.name) {
|
|
2160
|
+
acc = createSchema({
|
|
2161
|
+
...accObject,
|
|
2162
|
+
properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
|
|
2154
2163
|
});
|
|
2155
|
-
|
|
2164
|
+
continue;
|
|
2156
2165
|
}
|
|
2157
2166
|
}
|
|
2158
|
-
acc
|
|
2159
|
-
|
|
2160
|
-
}
|
|
2167
|
+
if (acc !== void 0) yield acc;
|
|
2168
|
+
acc = member;
|
|
2169
|
+
}
|
|
2170
|
+
if (acc !== void 0) yield acc;
|
|
2171
|
+
}
|
|
2172
|
+
function mergeAdjacentObjects(members) {
|
|
2173
|
+
return [...mergeAdjacentObjectsLazy(members)];
|
|
2161
2174
|
}
|
|
2162
2175
|
/**
|
|
2163
2176
|
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
@@ -2198,6 +2211,6 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
|
|
|
2198
2211
|
return propNode;
|
|
2199
2212
|
}
|
|
2200
2213
|
//#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 };
|
|
2214
|
+
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, mergeAdjacentObjectsLazy, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
2202
2215
|
|
|
2203
2216
|
//# sourceMappingURL=index.js.map
|