@kubb/ast 5.0.0-beta.103 → 5.0.0-beta.105

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as __name, t as __exportAll } from "./rolldown-runtime-CNktS9qV.js";
2
- import { $ as importDef, $t as DistributiveOmit, A as ResponseNode, At as ArrowFunctionNode, B as createParameter, Bt as breakDef, C as inputDef, Ct as schemaDef, D as OperationNode, Dt as propertyDef, E as HttpOperationNode, Et as createProperty, F as createRequestBody, Ft as JSDocNode, G as SourceNode, Gt as createFunction, H as ExportNode, Ht as createArrowFunction, I as requestBodyDef, It as JsxNode, J as createFile, Jt as createType, K as UserFileNode, Kt as createJsx, L as ParameterLocation, Lt as TextNode, M as createResponse, Mt as CodeNode, N as responseDef, Nt as ConstNode, O as createOperation, Ot as InferSchemaNode, P as RequestBodyNode, Pt as FunctionNode, Q as fileDef, Qt as typeDef, R as ParameterNode, Rt as TypeNode, S as createInput, St as createSchema, T as HttpMethod, Tt as UserPropertyNode, U as FileNode, Ut as createBreak, V as parameterDef, Vt as constDef, W as ImportNode, Wt as createConst, X as createSource, Xt as jsxDef, Y as createImport, Yt as functionDef, Z as exportDef, Zt as textDef, _ as OutputNode, _t as SchemaType, a as Enforce, at as DateSchemaNode, b as InputMeta, bt as UnionSchemaNode, c as composeMacros, ct as IntersectionSchemaNode, d as Visitor, dt as PrimitiveSchemaType, en as NodeDef, et as sourceDef, f as VisitorContext, ft as RefSchemaNode, g as Node, gt as SchemaNodeByType, h as transform, ht as SchemaNode, i as createPrinter, in as schemaTypes, it as ArraySchemaNode, j as StatusCode, jt as BreakNode, k as operationDef, kt as ParserOptions, l as defineMacro, lt as NumberSchemaNode, m as collectSync, mt as ScalarSchemaType, n as PrinterFactoryOptions, nn as BaseNode, nt as contentDef, o as Macro, ot as DatetimeSchemaNode, p as collect, pt as ScalarSchemaNode, q as createExport, qt as createText, r as PrinterPartial, rn as NodeKind, rt as createContent, s as applyMacros, st as EnumSchemaNode, t as Printer, tn as defineNode, tt as ContentNode, u as ParentOf, ut as ObjectSchemaNode, v as createOutput, vt as StringSchemaNode, w as GenericOperationNode, wt as PropertyNode, x as InputNode, xt as UrlSchemaNode, y as outputDef, yt as TimeSchemaNode, z as ParameterStyle, zt as arrowFunctionDef } from "./types-DK2c0yY4.js";
2
+ import { $ as importDef, $t as DistributiveOmit, A as ResponseNode, At as ArrowFunctionNode, B as createParameter, Bt as breakDef, C as inputDef, Ct as schemaDef, D as OperationNode, Dt as propertyDef, E as HttpOperationNode, Et as createProperty, F as createRequestBody, Ft as JSDocNode, G as SourceNode, Gt as createFunction, H as ExportNode, Ht as createArrowFunction, I as requestBodyDef, It as JsxNode, J as createFile, Jt as createType, K as UserFileNode, Kt as createJsx, L as ParameterLocation, Lt as TextNode, M as createResponse, Mt as CodeNode, N as responseDef, Nt as ConstNode, O as createOperation, Ot as InferSchemaNode, P as RequestBodyNode, Pt as FunctionNode, Q as fileDef, Qt as typeDef, R as ParameterNode, Rt as TypeNode, S as createInput, St as createSchema, T as HttpMethod, Tt as UserPropertyNode, U as FileNode, Ut as createBreak, V as parameterDef, Vt as constDef, W as ImportNode, Wt as createConst, X as createSource, Xt as jsxDef, Y as createImport, Yt as functionDef, Z as exportDef, Zt as textDef, _ as OutputNode, _t as SchemaType, a as Enforce, at as DateSchemaNode, b as InputMeta, bt as UnionSchemaNode, c as composeMacros, ct as IntersectionSchemaNode, d as Visitor, dt as PrimitiveSchemaType, en as NodeDef, et as sourceDef, f as VisitorContext, ft as RefSchemaNode, g as Node, gt as SchemaNodeByType, h as transform, ht as SchemaNode, i as createPrinter, in as schemaTypes, it as ArraySchemaNode, j as StatusCode, jt as BreakNode, k as operationDef, kt as ParserOptions, l as defineMacro, lt as NumberSchemaNode, m as collectSync, mt as ScalarSchemaType, n as PrinterFactoryOptions, nn as BaseNode, nt as contentDef, o as Macro, ot as DatetimeSchemaNode, p as collect, pt as ScalarSchemaNode, q as createExport, qt as createText, r as PrinterPartial, rn as NodeKind, rt as createContent, s as applyMacros, st as EnumSchemaNode, t as Printer, tn as defineNode, tt as ContentNode, u as ParentOf, ut as ObjectSchemaNode, v as createOutput, vt as StringSchemaNode, w as GenericOperationNode, wt as PropertyNode, x as InputNode, xt as UrlSchemaNode, y as outputDef, yt as TimeSchemaNode, z as ParameterStyle, zt as arrowFunctionDef } from "./types-BPqinVNh.js";
3
3
  //#region src/guards.d.ts
4
4
  /**
5
5
  * Narrows a `SchemaNode` to the variant that matches `type`.
@@ -78,6 +78,24 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
78
78
  declare function resolveRefName(node: SchemaNode | null | undefined): string | null;
79
79
  //#endregion
80
80
  //#region src/utils/schemaGraph.d.ts
81
+ /**
82
+ * Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
83
+ * first-occurrence order. The walk is memoized by node identity, so the subtree is scanned once and
84
+ * `resolver.imports` reads the same result across the ts, zod, and faker plugins instead of
85
+ * re-scanning the same schema per plugin.
86
+ *
87
+ * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
88
+ * same file (a union member created by name) is left out. That leaves exactly the set
89
+ * `resolver.imports` emits. This is the ordered, import-facing counterpart to
90
+ * {@link collectReferencedSchemaNames}, which returns an unordered set for graph analysis.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * collectImportedRefNames(petSchema)
95
+ * // ['Category', 'Tag']
96
+ * ```
97
+ */
98
+ declare const collectImportedRefNames: (key: SchemaNode) => readonly string[];
81
99
  /**
82
100
  * Collects the names of all top-level schemas transitively used by a set of operations.
83
101
  *
@@ -99,6 +117,24 @@ declare function resolveRefName(node: SchemaNode | null | undefined): string | n
99
117
  * ```
100
118
  */
101
119
  declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
120
+ /**
121
+ * Finds every schema that takes part in a circular dependency chain in a schema dependency graph
122
+ * that maps each schema name to the names it references directly.
123
+ *
124
+ * Use this when the graph was already collected during another pass (e.g. the adapter's convert
125
+ * walk), so the schema nodes are not swept a second time. `findCircularSchemas` builds the graph
126
+ * from schema nodes and delegates here.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const graph = new Map([
131
+ * ['Pet', new Set(['Category'])],
132
+ * ['Category', new Set(['Pet'])],
133
+ * ])
134
+ * findCircularSchemasFromGraph(graph) // Set { 'Pet', 'Category' }
135
+ * ```
136
+ */
137
+ declare function findCircularSchemasFromGraph(graph: ReadonlyMap<string, ReadonlySet<string>>): Set<string>;
102
138
  /**
103
139
  * Finds every schema that takes part in a circular dependency chain, including direct self-loops.
104
140
  *
@@ -204,8 +240,8 @@ declare const nodeDefs: (NodeDef<InputNode, Partial<Omit<InputNode, "kind">>> |
204
240
  type: "ipv6";
205
241
  }) | ScalarSchemaNode, "kind">> | NodeDef<PropertyNode, UserPropertyNode> | NodeDef<ParameterNode, Pick<ParameterNode, "schema" | "name" | "in"> & Partial<Omit<ParameterNode, "schema" | "kind" | "name" | "in">>> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
206
242
  declare namespace exports_d_exports {
207
- export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
243
+ export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, arrowFunctionDef, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
208
244
  }
209
245
  //#endregion
210
- export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, 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, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, collect, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
246
+ export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, 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, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
211
247
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1175,7 +1175,7 @@ function chain({ macros, key, node, context }) {
1175
1175
  for (const macro of macros) {
1176
1176
  const callback = macro[key];
1177
1177
  if (!callback) continue;
1178
- if (macro.when && !macro.when(current)) continue;
1178
+ if (macro.match && !macro.match(current)) continue;
1179
1179
  const next = callback(current, context);
1180
1180
  if (next != null) current = next;
1181
1181
  }
@@ -1362,6 +1362,36 @@ function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
1362
1362
  for (const name of collectSchemaRefs(node)) out.add(name);
1363
1363
  return out;
1364
1364
  }
1365
+ /**
1366
+ * Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
1367
+ * first-occurrence order. The walk is memoized by node identity, so the subtree is scanned once and
1368
+ * `resolver.imports` reads the same result across the ts, zod, and faker plugins instead of
1369
+ * re-scanning the same schema per plugin.
1370
+ *
1371
+ * Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
1372
+ * same file (a union member created by name) is left out. That leaves exactly the set
1373
+ * `resolver.imports` emits. This is the ordered, import-facing counterpart to
1374
+ * {@link collectReferencedSchemaNames}, which returns an unordered set for graph analysis.
1375
+ *
1376
+ * @example
1377
+ * ```ts
1378
+ * collectImportedRefNames(petSchema)
1379
+ * // ['Category', 'Tag']
1380
+ * ```
1381
+ */
1382
+ const collectImportedRefNames = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
1383
+ const seen = /* @__PURE__ */ new Set();
1384
+ const names = [];
1385
+ collectSync(node, { schema(child) {
1386
+ if (child.type !== "ref" || !child.ref) return;
1387
+ const name = resolveRefName(child);
1388
+ if (name && !seen.has(name)) {
1389
+ seen.add(name);
1390
+ names.push(name);
1391
+ }
1392
+ } });
1393
+ return names;
1394
+ });
1365
1395
  function computeUsedSchemaNames(operations, schemas) {
1366
1396
  const schemaMap = /* @__PURE__ */ new Map();
1367
1397
  for (const schema of schemas) if (schema.name) schemaMap.set(schema.name, schema);
@@ -1404,12 +1434,24 @@ function collectUsedSchemaNames(operations, schemas) {
1404
1434
  return computeUsedSchemaNames(operations, schemas);
1405
1435
  }
1406
1436
  const EMPTY_CIRCULAR_SET = /* @__PURE__ */ new Set();
1407
- const findCircularSchemasMemo = memoize(/* @__PURE__ */ new WeakMap(), (schemas) => {
1408
- const graph = /* @__PURE__ */ new Map();
1409
- for (const schema of schemas) {
1410
- if (!schema.name) continue;
1411
- graph.set(schema.name, collectReferencedSchemaNames(schema));
1412
- }
1437
+ /**
1438
+ * Finds every schema that takes part in a circular dependency chain in a schema dependency graph
1439
+ * that maps each schema name to the names it references directly.
1440
+ *
1441
+ * Use this when the graph was already collected during another pass (e.g. the adapter's convert
1442
+ * walk), so the schema nodes are not swept a second time. `findCircularSchemas` builds the graph
1443
+ * from schema nodes and delegates here.
1444
+ *
1445
+ * @example
1446
+ * ```ts
1447
+ * const graph = new Map([
1448
+ * ['Pet', new Set(['Category'])],
1449
+ * ['Category', new Set(['Pet'])],
1450
+ * ])
1451
+ * findCircularSchemasFromGraph(graph) // Set { 'Pet', 'Category' }
1452
+ * ```
1453
+ */
1454
+ function findCircularSchemasFromGraph(graph) {
1413
1455
  const circular = /* @__PURE__ */ new Set();
1414
1456
  for (const start of graph.keys()) {
1415
1457
  const visited = /* @__PURE__ */ new Set();
@@ -1427,6 +1469,14 @@ const findCircularSchemasMemo = memoize(/* @__PURE__ */ new WeakMap(), (schemas)
1427
1469
  }
1428
1470
  }
1429
1471
  return circular;
1472
+ }
1473
+ const findCircularSchemasMemo = memoize(/* @__PURE__ */ new WeakMap(), (schemas) => {
1474
+ const graph = /* @__PURE__ */ new Map();
1475
+ for (const schema of schemas) {
1476
+ if (!schema.name) continue;
1477
+ graph.set(schema.name, collectReferencedSchemaNames(schema));
1478
+ }
1479
+ return findCircularSchemasFromGraph(graph);
1430
1480
  });
1431
1481
  /**
1432
1482
  * Finds every schema that takes part in a circular dependency chain, including direct self-loops.
@@ -1496,6 +1546,7 @@ var exports_exports = /* @__PURE__ */ __exportAll({
1496
1546
  arrowFunctionDef: () => arrowFunctionDef,
1497
1547
  breakDef: () => breakDef,
1498
1548
  collect: () => collect,
1549
+ collectImportedRefNames: () => collectImportedRefNames,
1499
1550
  collectSync: () => collectSync,
1500
1551
  collectUsedSchemaNames: () => collectUsedSchemaNames,
1501
1552
  combineExports: () => combineExports,
@@ -1512,6 +1563,7 @@ var exports_exports = /* @__PURE__ */ __exportAll({
1512
1563
  factory: () => factory_exports,
1513
1564
  fileDef: () => fileDef,
1514
1565
  findCircularSchemas: () => findCircularSchemas,
1566
+ findCircularSchemasFromGraph: () => findCircularSchemasFromGraph,
1515
1567
  functionDef: () => functionDef,
1516
1568
  importDef: () => importDef,
1517
1569
  inputDef: () => inputDef,
@@ -1535,6 +1587,6 @@ var exports_exports = /* @__PURE__ */ __exportAll({
1535
1587
  typeDef: () => typeDef
1536
1588
  });
1537
1589
  //#endregion
1538
- export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
1590
+ export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
1539
1591
 
1540
1592
  //# sourceMappingURL=index.js.map