@kubb/ast 5.0.0-beta.53 → 5.0.0-beta.55

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 DedupeCanonical, $t as schemaTypes, A as createFunctionParameter, At as NumberSchemaNode, B as createProperty, Bt as UnionSchemaNode, C as UserFileNode, Ct as ImportNode, D as createExport, Dt as DatetimeSchemaNode, E as createConst, Et as DateSchemaNode, F as createOperation, Ft as SchemaNode, G as createText, Gt as ConstNode, H as createSchema, Ht as PropertyNode, I as createOutput, It as SchemaNodeByType, J as update, Jt as JsxNode, K as createType, Kt as FunctionNode, L as createParameter, Lt as SchemaType, M as createImport, Mt as PrimitiveSchemaType, N as createInput, Nt as RefSchemaNode, O as createFile, Ot as EnumSchemaNode, P as createJsx, Pt as ScalarSchemaType, Q as defineSchemaDialect, Qt as httpMethods, R as createParameterGroup, Rt as StringSchemaNode, S as DistributiveOmit, St as FileNode, T as createBreak, Tt as ArraySchemaNode, U as createSource, Ut as ArrowFunctionNode, V as createResponse, Vt as UrlSchemaNode, W as createStreamInput, Wt as CodeNode, X as ParserOptions, Xt as TypeNode, Y as InferSchemaNode, Yt as TextNode, Z as SchemaDialect, Zt as NodeKind, _ as Printer, _t as FunctionParameterNode, a as createDiscriminantNode, at as OutputNode, b as createPrinterFactory, bt as ParamsTypeNode, c as findCircularSchemas, ct as HttpMethod, d as ParentOf, dt as ResponseNode, et as DedupeLookups, f as Visitor, ft as StatusCode, g as walk, gt as FunctionParamNode, h as transform, ht as FunctionNodeType, i as containsCircularRef, it as Node, j as createFunctionParameters, jt as ObjectSchemaNode, k as createFunction, kt as IntersectionSchemaNode, l as isStringType, lt as HttpOperationNode, m as collect, mt as ParameterNode, n as caseParams, nt as applyDedupe, o as createOperationParams, ot as InputMeta, p as VisitorContext, pt as ParameterLocation, q as syncOptionality, qt as JSDocNode, r as collectUsedSchemaNames, rt as buildDedupePlan, s as extractStringsFromNodes, st as InputNode, t as OperationParamsResolver, tt as DedupePlan, u as syncSchemaRef, ut as OperationNode, v as PrinterFactoryOptions, vt as FunctionParametersNode, w as createArrowFunction, wt as SourceNode, x as definePrinter, xt as ExportNode, y as PrinterPartial, yt as ParameterGroupNode, z as createParamsType, zt as TimeSchemaNode } from "./types-BL7RpQAE.js";
3
3
 
4
4
  //#region src/guards.d.ts
5
5
  /**
@@ -68,37 +68,21 @@ declare function isHttpOperationNode(node: OperationNode): node is HttpOperation
68
68
  */
69
69
  declare const isSchemaNode: (node: unknown) => node is SchemaNode;
70
70
  //#endregion
71
- //#region src/resolvers.d.ts
72
- /**
73
- * Collects import entries for all `ref` schema nodes in `node`.
74
- */
75
- declare function collectImports<TImport>({
76
- node,
77
- nameMapping,
78
- resolve
79
- }: {
80
- node: SchemaNode;
81
- nameMapping: Map<string, string>;
82
- resolve: (schemaName: string) => TImport | null;
83
- }): Array<TImport>;
84
- //#endregion
85
71
  //#region src/signature.d.ts
86
72
  /**
87
- * Computes a deterministic, shape-only signature (a fixed-length content hash) for a schema node.
88
- *
89
- * Two schemas share a signature when they are structurally identical, ignoring
90
- * documentation (`name`, `title`, `description`, `example`, `default`, `deprecated`)
91
- * and usage-slot flags (`optional`, `nullish`, `readOnly`, `writeOnly`). `nullable`
92
- * is kept because it changes the produced type. `ref` nodes compare by target name,
93
- * which also keeps the algorithm terminating on circular shapes.
73
+ * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas
74
+ * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,
75
+ * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,
76
+ * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`
77
+ * nodes compare by target name, which also terminates on circular shapes.
94
78
  *
95
79
  * @example Two enums with different descriptions share a signature
96
80
  * ```ts
97
- * schemaSignature(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
98
- * schemaSignature(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
81
+ * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
82
+ * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
99
83
  * ```
100
84
  */
101
- declare function schemaSignature(node: SchemaNode): string;
85
+ declare function signatureOf(node: SchemaNode): string;
102
86
  //#endregion
103
87
  //#region src/transformers.d.ts
104
88
  /**
@@ -154,5 +138,5 @@ declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Genera
154
138
  declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
155
139
  declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
156
140
  //#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 };
141
+ export { type ArraySchemaNode, type ArrowFunctionNode, type CodeNode, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DedupeCanonical, type DedupeLookups, type DedupePlan, 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 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, 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, extractStringsFromNodes, findCircularSchemas, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, signatureOf, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
158
142
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,7 +1,24 @@
1
1
  import "./chunk-C0LytTxp.js";
2
- import { S as visitorDepths, _ as isValidVarName, a as enumPropName, b as isScalarPrimitive, h as trimExtName, o as extractRefName, v as camelCase, x as schemaTypes, y as httpMethods } from "./utils-BIcKgbbc.js";
2
+ import { _ as httpMethods, a as enumPropName, b as visitorDepths, g as camelCase, h as isValidVarName, o as extractRefName, v as isScalarPrimitive, y as schemaTypes } from "./utils-0p8ZO287.js";
3
3
  import { hash } from "node:crypto";
4
4
  import path from "node:path";
5
+ //#region ../../internals/utils/src/fs.ts
6
+ /**
7
+ * Strips the file extension from a path or file name.
8
+ * Only removes the last `.ext` segment when the dot is not part of a directory name.
9
+ *
10
+ * @example
11
+ * trimExtName('petStore.ts') // 'petStore'
12
+ * trimExtName('/src/models/pet.ts') // '/src/models/pet'
13
+ * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
14
+ * trimExtName('noExtension') // 'noExtension'
15
+ */
16
+ function trimExtName(text) {
17
+ const dotIndex = text.lastIndexOf(".");
18
+ if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
19
+ return text;
20
+ }
21
+ //#endregion
5
22
  //#region ../../internals/utils/src/promise.ts
6
23
  /**
7
24
  * Wraps `factory` with a keyed cache backed by the provided store.
@@ -1054,7 +1071,7 @@ function createInput(overrides = {}) {
1054
1071
  };
1055
1072
  }
1056
1073
  /**
1057
- * Creates an `InputStreamNode` from pre-built `AsyncIterable` sources.
1074
+ * Creates a streaming `InputNode<true>` from pre-built `AsyncIterable` sources.
1058
1075
  *
1059
1076
  * @example
1060
1077
  * ```ts
@@ -1677,9 +1694,7 @@ function createJsx(value) {
1677
1694
  //#endregion
1678
1695
  //#region src/signature.ts
1679
1696
  /**
1680
- * The shape-affecting flags shared by every node kind: base primitive, format, and `nullable`.
1681
- * Documentation and usage-slot flags (`optional`/`nullish`/`readOnly`/`writeOnly`) are
1682
- * intentionally excluded, they describe the property slot, not the type.
1697
+ * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.
1683
1698
  */
1684
1699
  function flagsDescriptor(node) {
1685
1700
  return `${node.primitive ?? ""};${node.format ?? ""};${node.nullable ? 1 : 0}`;
@@ -1752,9 +1767,8 @@ const rangeFields = [{
1752
1767
  prefix: "mx"
1753
1768
  }];
1754
1769
  /**
1755
- * Maps each schema node `type` to the ordered list of shape-contributing fields.
1756
- * Node types absent from this map (scalar types like boolean, null, any, etc.) fall
1757
- * back to `${type}|${flags}` with no additional fields.
1770
+ * Maps each node `type` to its ordered shape-contributing fields. Types absent from the map
1771
+ * (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.
1758
1772
  */
1759
1773
  const SHAPE_KEYS = {
1760
1774
  object: [
@@ -1891,9 +1905,8 @@ function serializeShapeField(field, node, record) {
1891
1905
  }
1892
1906
  }
1893
1907
  /**
1894
- * Builds the local, shape-only descriptor for a node: its kind, flags, constraints, and its
1895
- * children's signatures. {@link signatureOf} hashes this string. Children contribute their
1896
- * fixed-length signature rather than their own full descriptor, which keeps the result bounded.
1908
+ * Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,
1909
+ * constraints, and its children's signatures.
1897
1910
  */
1898
1911
  function describeShape(node) {
1899
1912
  const flags = flagsDescriptor(node);
@@ -1905,22 +1918,23 @@ function describeShape(node) {
1905
1918
  return parts.join("|");
1906
1919
  }
1907
1920
  /**
1908
- * Persistent hash-consing cache: `SchemaNode` signature digest, keyed by node identity.
1909
- *
1910
- * A `WeakMap` so entries are released once the node is garbage-collected, and so a node hashed
1911
- * during dedupe planning is not re-hashed when the same tree is rewritten during streaming
1912
- * (where `schemaSignature` and `applyDedupe` would otherwise each walk it from scratch). Reuse
1913
- * across calls is sound because a signature depends only on a node's content, and schema nodes
1914
- * are immutable once created, transforms allocate new objects rather than mutating in place.
1921
+ * Node digest cache, keyed by identity. A `WeakMap` so entries die with the node, and so a tree
1922
+ * hashed during dedupe planning is not walked again when it is rewritten during streaming. Reuse
1923
+ * is safe because a signature depends only on content, and nodes are immutable once created.
1915
1924
  */
1916
1925
  const signatureCache = /* @__PURE__ */ new WeakMap();
1917
1926
  /**
1918
- * Hash-consing: each node's signature is a fixed-length digest of its local shape plus its
1919
- * children's digests (a Merkle hash). Children contribute their 64-char hash instead of their
1920
- * full nested descriptor, so a signature stays bounded regardless of subtree depth, and the
1921
- * digest is identical across calls because it depends only on content, never on traversal
1922
- * order. This keeps the keys built during planning consistent with the ones recomputed later
1923
- * during streaming. {@link signatureCache} memoizes node → digest across every computation.
1927
+ * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas
1928
+ * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,
1929
+ * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,
1930
+ * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`
1931
+ * nodes compare by target name, which also terminates on circular shapes.
1932
+ *
1933
+ * @example Two enums with different descriptions share a signature
1934
+ * ```ts
1935
+ * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
1936
+ * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
1937
+ * ```
1924
1938
  */
1925
1939
  function signatureOf(node) {
1926
1940
  const cached = signatureCache.get(node);
@@ -1929,24 +1943,6 @@ function signatureOf(node) {
1929
1943
  signatureCache.set(node, signature);
1930
1944
  return signature;
1931
1945
  }
1932
- /**
1933
- * Computes a deterministic, shape-only signature (a fixed-length content hash) for a schema node.
1934
- *
1935
- * Two schemas share a signature when they are structurally identical, ignoring
1936
- * documentation (`name`, `title`, `description`, `example`, `default`, `deprecated`)
1937
- * and usage-slot flags (`optional`, `nullish`, `readOnly`, `writeOnly`). `nullable`
1938
- * is kept because it changes the produced type. `ref` nodes compare by target name,
1939
- * which also keeps the algorithm terminating on circular shapes.
1940
- *
1941
- * @example Two enums with different descriptions share a signature
1942
- * ```ts
1943
- * schemaSignature(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
1944
- * schemaSignature(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
1945
- * ```
1946
- */
1947
- function schemaSignature(node) {
1948
- return signatureOf(node);
1949
- }
1950
1946
  //#endregion
1951
1947
  //#region src/dedupe.ts
1952
1948
  /**
@@ -1968,10 +1964,20 @@ function createRefNode(node, canonical) {
1968
1964
  example: node.example
1969
1965
  });
1970
1966
  }
1971
- function applyDedupe(node, canonicalBySignature, skipRootMatch = false) {
1972
- if (canonicalBySignature.size === 0) return node;
1967
+ function applyDedupe(node, plan, skipRootMatch = false) {
1968
+ const { canonicalBySignature, aliasNames } = plan;
1969
+ if (canonicalBySignature.size === 0 && aliasNames.size === 0) return node;
1973
1970
  const root = node;
1974
1971
  return transform(node, { schema(schemaNode) {
1972
+ if (schemaNode.type === "ref") {
1973
+ const target = schemaNode.ref ? extractRefName(schemaNode.ref) : schemaNode.name;
1974
+ const canonical = target ? aliasNames.get(target) : void 0;
1975
+ return canonical ? {
1976
+ ...schemaNode,
1977
+ name: canonical.name,
1978
+ ref: canonical.ref
1979
+ } : void 0;
1980
+ }
1975
1981
  const signature = signatureOf(schemaNode);
1976
1982
  if (skipRootMatch && schemaNode === root) return void 0;
1977
1983
  const canonical = canonicalBySignature.get(signature);
@@ -1995,9 +2001,11 @@ function cleanDefinition(node, name) {
1995
2001
  * Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.
1996
2002
  *
1997
2003
  * 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}.
2004
+ * is a named top-level schema, the first one becomes the canonical (so other top-level
2005
+ * duplicates and inline copies turn into references to it). Every other top-level name with
2006
+ * the same content is recorded in `aliasNames`, so refs to it can be repointed at the
2007
+ * canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied
2008
+ * per node with {@link applyDedupe}.
2001
2009
  *
2002
2010
  * @example
2003
2011
  * ```ts
@@ -2019,11 +2027,11 @@ function buildDedupePlan(roots, options) {
2019
2027
  const group = groups.get(signature);
2020
2028
  if (group) {
2021
2029
  group.count++;
2022
- if (isTopLevel && !group.topLevelName) group.topLevelName = schemaNode.name;
2030
+ if (isTopLevel) group.topLevelNames.push(schemaNode.name);
2023
2031
  } else groups.set(signature, {
2024
2032
  count: 1,
2025
2033
  representative: schemaNode,
2026
- topLevelName: isTopLevel ? schemaNode.name : void 0
2034
+ topLevelNames: isTopLevel ? [schemaNode.name] : []
2027
2035
  });
2028
2036
  }
2029
2037
  for (const root of roots) {
@@ -2031,14 +2039,18 @@ function buildDedupePlan(roots, options) {
2031
2039
  for (const schemaNode of collectLazy(root, { schema: (node) => node })) record(schemaNode);
2032
2040
  }
2033
2041
  const canonicalBySignature = /* @__PURE__ */ new Map();
2042
+ const aliasNames = /* @__PURE__ */ new Map();
2034
2043
  const pendingHoists = [];
2035
2044
  for (const [signature, group] of groups) {
2036
2045
  if (group.count < minOccurrences) continue;
2037
- if (group.topLevelName) {
2038
- canonicalBySignature.set(signature, {
2039
- name: group.topLevelName,
2040
- ref: refFor(group.topLevelName)
2041
- });
2046
+ const [firstName, ...duplicateNames] = group.topLevelNames;
2047
+ if (firstName) {
2048
+ const canonical = {
2049
+ name: firstName,
2050
+ ref: refFor(firstName)
2051
+ };
2052
+ canonicalBySignature.set(signature, canonical);
2053
+ for (const duplicate of duplicateNames) aliasNames.set(duplicate, canonical);
2042
2054
  continue;
2043
2055
  }
2044
2056
  const name = nameFor(group.representative, signature);
@@ -2054,15 +2066,18 @@ function buildDedupePlan(roots, options) {
2054
2066
  }
2055
2067
  return {
2056
2068
  canonicalBySignature,
2057
- hoisted: pendingHoists.map(({ name, representative }) => cleanDefinition(applyDedupe(representative, canonicalBySignature, true), name))
2069
+ aliasNames,
2070
+ hoisted: pendingHoists.map(({ name, representative }) => cleanDefinition(applyDedupe(representative, {
2071
+ canonicalBySignature,
2072
+ aliasNames
2073
+ }, true), name))
2058
2074
  };
2059
2075
  }
2060
2076
  //#endregion
2061
2077
  //#region src/dialect.ts
2062
2078
  /**
2063
- * Identity helper that types a {@link SchemaDialect} for an adapter. Like
2064
- * `defineParser`, it adds no runtime behavior, it pins the dialect's type for
2065
- * inference and gives adapter authors a discoverable anchor.
2079
+ * Types a {@link SchemaDialect} for an adapter. Adds no runtime behavior and only pins the
2080
+ * dialect's type for inference.
2066
2081
  *
2067
2082
  * @example
2068
2083
  * ```ts
@@ -2080,38 +2095,6 @@ function defineSchemaDialect(dialect) {
2080
2095
  return dialect;
2081
2096
  }
2082
2097
  //#endregion
2083
- //#region src/dispatch.ts
2084
- /**
2085
- * Walks an ordered list of {@link DispatchRule}s and returns the first node produced.
2086
- *
2087
- * This is the shared backbone for spec adapters (OpenAPI today, AsyncAPI and others later).
2088
- * The contract an adapter follows is intentionally minimal:
2089
- *
2090
- * context → [rule.match → rule.convert] → node
2091
- *
2092
- * An adapter derives a context from a source spec node, then declares an ordered table of
2093
- * rules mapping spec shapes onto Kubb AST nodes. To add support for a new spec, write a new
2094
- * context type and a new rules table, the traversal here is reused unchanged.
2095
- *
2096
- * Order is significant: earlier rules win, so list higher-precedence or more specific shapes
2097
- * first (e.g. composition keywords before plain `type`). A rule whose `match` returns `true`
2098
- * may still `convert` to `null` to defer to later rules. When no rule produces a node this
2099
- * returns `null`, leaving the caller to apply its own fallback.
2100
- *
2101
- * @example
2102
- * ```ts
2103
- * const node = dispatch(schemaRules, schemaContext) ?? createSchema({ type: fallbackType })
2104
- * ```
2105
- */
2106
- function dispatch(rules, context) {
2107
- for (const rule of rules) {
2108
- if (!rule.match(context)) continue;
2109
- const node = rule.convert(context);
2110
- if (node !== null && node !== void 0) return node;
2111
- }
2112
- return null;
2113
- }
2114
- //#endregion
2115
2098
  //#region src/printer.ts
2116
2099
  /**
2117
2100
  * Defines a schema printer: a function that takes a `SchemaNode` and emits
@@ -2189,21 +2172,6 @@ function createPrinterFactory(getKey) {
2189
2172
  };
2190
2173
  }
2191
2174
  //#endregion
2192
- //#region src/resolvers.ts
2193
- /**
2194
- * Collects import entries for all `ref` schema nodes in `node`.
2195
- */
2196
- function collectImports({ node, nameMapping, resolve }) {
2197
- return collect(node, { schema(schemaNode) {
2198
- const schemaRef = narrowSchema(schemaNode, "ref");
2199
- if (!schemaRef?.ref) return null;
2200
- const rawName = extractRefName(schemaRef.ref);
2201
- const result = resolve(nameMapping.get(rawName) ?? rawName);
2202
- if (!result) return null;
2203
- return result;
2204
- } });
2205
- }
2206
- //#endregion
2207
2175
  //#region src/transformers.ts
2208
2176
  /**
2209
2177
  * Replaces a discriminator property's schema with a string enum of allowed values.
@@ -2311,6 +2279,6 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
2311
2279
  return propNode;
2312
2280
  }
2313
2281
  //#endregion
2314
- export { 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 };
2282
+ export { applyDedupe, buildDedupePlan, caseParams, collect, 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, extractStringsFromNodes, findCircularSchemas, httpMethods, isHttpOperationNode, isInputNode, isOperationNode, isOutputNode, isSchemaNode, isStringType, mergeAdjacentObjectsLazy, narrowSchema, schemaTypes, setDiscriminatorEnum, setEnumName, signatureOf, simplifyUnion, syncOptionality, syncSchemaRef, transform, update, walk };
2315
2283
 
2316
2284
  //# sourceMappingURL=index.js.map