@kubb/ast 5.0.0-beta.52 → 5.0.0-beta.54

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 { t as __name } from "./chunk-C0LytTxp.js";
2
- import { $ as SchemaDialect, $t as httpMethods, A as createFunctionParameter, At as IntersectionSchemaNode, B as createProperty, Bt as TimeSchemaNode, C as UserFileNode, Ct as FileNode, D as createExport, Dt as DateSchemaNode, E as createConst, Et as ArraySchemaNode, F as createOperation, Ft as ScalarSchemaType, G as createText, Gt as CodeNode, H as createSchema, Ht as UrlSchemaNode, I as createOutput, It as SchemaNode, J as update, Jt as JSDocNode, K as createType, Kt as ConstNode, L as createParameter, Lt as SchemaNodeByType, M as createImport, Mt as ObjectSchemaNode, N as createInput, Nt as PrimitiveSchemaType, O as createFile, Ot as DatetimeSchemaNode, P as createJsx, Pt as RefSchemaNode, Q as dispatch, Qt as NodeKind, R as createParameterGroup, Rt as SchemaType, S as DistributiveOmit, St as ExportNode, T as createBreak, Tt as SourceNode, U as createSource, Ut as PropertyNode, V as createResponse, Vt as UnionSchemaNode, W as createStreamInput, Wt as ArrowFunctionNode, X as ParserOptions, Xt as TextNode, Y as InferSchemaNode, Yt as JsxNode, Z as DispatchRule, Zt as TypeNode, _ as Printer, _t as FunctionParamNode, a as createDiscriminantNode, at as InputMeta, b as createPrinterFactory, bt as ParameterGroupNode, c as findCircularSchemas, ct as OutputNode, d as ParentOf, dt as OperationNode, en as schemaTypes, et as defineSchemaDialect, f as Visitor, ft as ResponseNode, g as walk, gt as FunctionNodeType, h as transform, ht as ParameterNode, i as containsCircularRef, it as Node, j as createFunctionParameters, jt as NumberSchemaNode, k as createFunction, kt as EnumSchemaNode, l as isStringType, lt as HttpMethod, m as collect, mt as ParameterLocation, n as caseParams, nt as applyDedupe, o as createOperationParams, ot as InputNode, p as VisitorContext, pt as StatusCode, q as syncOptionality, qt as FunctionNode, r as collectUsedSchemaNames, rt as buildDedupePlan, s as extractStringsFromNodes, st as InputStreamNode, t as OperationParamsResolver, tt as DedupePlan, u as syncSchemaRef, ut as HttpOperationNode, v as PrinterFactoryOptions, vt as FunctionParameterNode, w as createArrowFunction, wt as ImportNode, x as definePrinter, xt as ParamsTypeNode, y as PrinterPartial, yt as FunctionParametersNode, z as createParamsType, zt as StringSchemaNode } from "./types-IHUK_alM.js";
2
+ import { $ as SchemaDialect, $t as TypeNode, A as createFunctionParameter, At as DatetimeSchemaNode, B as createProperty, Bt as SchemaType, C as UserFileNode, Ct as ParamsTypeNode, D as createExport, Dt as SourceNode, E as createConst, Et as ImportNode, F as createOperation, Ft as PrimitiveSchemaType, G as createText, Gt as PropertyNode, H as createSchema, Ht as TimeSchemaNode, I as createOutput, It as RefSchemaNode, J as update, Jt as ConstNode, K as createType, Kt as ArrowFunctionNode, L as createParameter, Lt as ScalarSchemaType, M as createImport, Mt as IntersectionSchemaNode, N as createInput, Nt as NumberSchemaNode, O as createFile, Ot as ArraySchemaNode, P as createJsx, Pt as ObjectSchemaNode, Q as dispatch, Qt as TextNode, R as createParameterGroup, Rt as SchemaNode, S as DistributiveOmit, St as ParameterGroupNode, T as createBreak, Tt as FileNode, U as createSource, Ut as UnionSchemaNode, V as createResponse, Vt as StringSchemaNode, W as createStreamInput, Wt as UrlSchemaNode, X as ParserOptions, Xt as JSDocNode, Y as InferSchemaNode, Yt as FunctionNode, Z as DispatchRule, Zt as JsxNode, _ as Printer, _t as ParameterNode, a as createDiscriminantNode, at as buildDedupePlan, b as createPrinterFactory, bt as FunctionParameterNode, c as findCircularSchemas, ct as InputNode, d as ParentOf, dt as HttpMethod, en as NodeKind, et as defineSchemaDialect, f as Visitor, ft as HttpOperationNode, g as walk, gt as ParameterLocation, h as transform, ht as StatusCode, i as containsCircularRef, it as applyDedupe, j as createFunctionParameters, jt as EnumSchemaNode, k as createFunction, kt as DateSchemaNode, l as isStringType, lt as InputStreamNode, m as collect, mt as ResponseNode, n as caseParams, nn as schemaTypes, nt as DedupeLookups, o as createOperationParams, ot as Node, p as VisitorContext, pt as OperationNode, q as syncOptionality, qt as CodeNode, r as collectUsedSchemaNames, rt as DedupePlan, s as extractStringsFromNodes, st as InputMeta, t as OperationParamsResolver, tn as httpMethods, tt as DedupeCanonical, u as syncSchemaRef, ut as OutputNode, v as PrinterFactoryOptions, vt as FunctionNodeType, w as createArrowFunction, wt as ExportNode, x as definePrinter, xt as FunctionParametersNode, y as PrinterPartial, yt as FunctionParamNode, z as createParamsType, zt as SchemaNodeByType } from "./types-BYujEIxF.js";
3
3
 
4
4
  //#region src/guards.d.ts
5
5
  /**
@@ -154,5 +154,5 @@ declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Genera
154
154
  declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
155
155
  declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
156
156
  //#endregion
157
- export { type ArraySchemaNode, type ArrowFunctionNode, type CodeNode, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupePlan, type DispatchRule, 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 InputStreamNode, 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, collectImports, 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, dispatch, extractStringsFromNodes, findCircularSchemas, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaSignature, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
157
+ export { type ArraySchemaNode, type ArrowFunctionNode, type CodeNode, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupeCanonical, type DedupeLookups, type DedupePlan, type DispatchRule, 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 InputStreamNode, 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, collectImports, 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, dispatch, extractStringsFromNodes, findCircularSchemas, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaSignature, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
158
158
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1968,10 +1968,20 @@ function createRefNode(node, canonical) {
1968
1968
  example: node.example
1969
1969
  });
1970
1970
  }
1971
- function applyDedupe(node, canonicalBySignature, skipRootMatch = false) {
1972
- if (canonicalBySignature.size === 0) return node;
1971
+ function applyDedupe(node, plan, skipRootMatch = false) {
1972
+ const { canonicalBySignature, aliasNames } = plan;
1973
+ if (canonicalBySignature.size === 0 && aliasNames.size === 0) return node;
1973
1974
  const root = node;
1974
1975
  return transform(node, { schema(schemaNode) {
1976
+ if (schemaNode.type === "ref") {
1977
+ const target = schemaNode.ref ? extractRefName(schemaNode.ref) : schemaNode.name;
1978
+ const canonical = target ? aliasNames.get(target) : void 0;
1979
+ return canonical ? {
1980
+ ...schemaNode,
1981
+ name: canonical.name,
1982
+ ref: canonical.ref
1983
+ } : void 0;
1984
+ }
1975
1985
  const signature = signatureOf(schemaNode);
1976
1986
  if (skipRootMatch && schemaNode === root) return void 0;
1977
1987
  const canonical = canonicalBySignature.get(signature);
@@ -1995,9 +2005,11 @@ function cleanDefinition(node, name) {
1995
2005
  * Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.
1996
2006
  *
1997
2007
  * A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence
1998
- * is a named top-level schema, that name becomes the canonical (so other top-level duplicates
1999
- * and inline copies turn into references to it). Otherwise a new definition is hoisted using
2000
- * `nameFor`. The plan is then applied per node with {@link applyDedupe}.
2008
+ * is a named top-level schema, the first one becomes the canonical (so other top-level
2009
+ * duplicates and inline copies turn into references to it). Every other top-level name with
2010
+ * the same content is recorded in `aliasNames`, so refs to it can be repointed at the
2011
+ * canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied
2012
+ * per node with {@link applyDedupe}.
2001
2013
  *
2002
2014
  * @example
2003
2015
  * ```ts
@@ -2019,11 +2031,11 @@ function buildDedupePlan(roots, options) {
2019
2031
  const group = groups.get(signature);
2020
2032
  if (group) {
2021
2033
  group.count++;
2022
- if (isTopLevel && !group.topLevelName) group.topLevelName = schemaNode.name;
2034
+ if (isTopLevel) group.topLevelNames.push(schemaNode.name);
2023
2035
  } else groups.set(signature, {
2024
2036
  count: 1,
2025
2037
  representative: schemaNode,
2026
- topLevelName: isTopLevel ? schemaNode.name : void 0
2038
+ topLevelNames: isTopLevel ? [schemaNode.name] : []
2027
2039
  });
2028
2040
  }
2029
2041
  for (const root of roots) {
@@ -2031,14 +2043,18 @@ function buildDedupePlan(roots, options) {
2031
2043
  for (const schemaNode of collectLazy(root, { schema: (node) => node })) record(schemaNode);
2032
2044
  }
2033
2045
  const canonicalBySignature = /* @__PURE__ */ new Map();
2046
+ const aliasNames = /* @__PURE__ */ new Map();
2034
2047
  const pendingHoists = [];
2035
2048
  for (const [signature, group] of groups) {
2036
2049
  if (group.count < minOccurrences) continue;
2037
- if (group.topLevelName) {
2038
- canonicalBySignature.set(signature, {
2039
- name: group.topLevelName,
2040
- ref: refFor(group.topLevelName)
2041
- });
2050
+ const [firstName, ...duplicateNames] = group.topLevelNames;
2051
+ if (firstName) {
2052
+ const canonical = {
2053
+ name: firstName,
2054
+ ref: refFor(firstName)
2055
+ };
2056
+ canonicalBySignature.set(signature, canonical);
2057
+ for (const duplicate of duplicateNames) aliasNames.set(duplicate, canonical);
2042
2058
  continue;
2043
2059
  }
2044
2060
  const name = nameFor(group.representative, signature);
@@ -2054,7 +2070,11 @@ function buildDedupePlan(roots, options) {
2054
2070
  }
2055
2071
  return {
2056
2072
  canonicalBySignature,
2057
- hoisted: pendingHoists.map(({ name, representative }) => cleanDefinition(applyDedupe(representative, canonicalBySignature, true), name))
2073
+ aliasNames,
2074
+ hoisted: pendingHoists.map(({ name, representative }) => cleanDefinition(applyDedupe(representative, {
2075
+ canonicalBySignature,
2076
+ aliasNames
2077
+ }, true), name))
2058
2078
  };
2059
2079
  }
2060
2080
  //#endregion