@kubb/ast 5.25.0 → 5.26.0

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.
Files changed (79) hide show
  1. package/dist/{file-3gsgXreK.js → combineFileMembers-DJHNAZBN.js} +204 -161
  2. package/dist/combineFileMembers-DJHNAZBN.js.map +1 -0
  3. package/dist/{file-D73XubVb.cjs → combineFileMembers-DmmuOmY8.cjs} +216 -160
  4. package/dist/combineFileMembers-DmmuOmY8.cjs.map +1 -0
  5. package/dist/factory.cjs +6 -6
  6. package/dist/factory.d.cts +2 -2
  7. package/dist/factory.d.ts +2 -2
  8. package/dist/factory.js +2 -2
  9. package/dist/{file-CMHRNuMX.d.cts → file-DJqd2j3y.d.cts} +3 -1
  10. package/dist/{file-D67ITWja.d.ts → file-Dg70hXm3.d.ts} +3 -1
  11. package/dist/{file-1YtTOZeL.js → file-HwCmj--S.js} +5 -3
  12. package/dist/file-HwCmj--S.js.map +1 -0
  13. package/dist/{file-azmmZwDb.cjs → file-z3xToonr.cjs} +11 -9
  14. package/dist/file-z3xToonr.cjs.map +1 -0
  15. package/dist/file.cjs +7 -5
  16. package/dist/file.d.cts +2 -2
  17. package/dist/file.d.ts +2 -2
  18. package/dist/file.js +3 -3
  19. package/dist/{graph-DImDxlJE.js → graph-CePbhGIt.js} +17 -20
  20. package/dist/graph-CePbhGIt.js.map +1 -0
  21. package/dist/{graph-DDh1FFrm.cjs → graph-D-0CbFIv.cjs} +17 -20
  22. package/dist/graph-D-0CbFIv.cjs.map +1 -0
  23. package/dist/graph.cjs +1 -1
  24. package/dist/graph.d.cts +1 -1
  25. package/dist/graph.d.ts +1 -1
  26. package/dist/graph.js +1 -1
  27. package/dist/{index-DfTgdgaH.d.cts → index-BNf4pYPx.d.cts} +3 -2
  28. package/dist/{index-DerFkxlp.d.ts → index-BfNUrkK6.d.ts} +3 -2
  29. package/dist/{index-DNZgWmNq.d.cts → index-BjmAaymt.d.cts} +1 -1
  30. package/dist/{index-CIUD99Ft.d.ts → index-Br4bwEnS.d.ts} +2 -2
  31. package/dist/{index-CGmrJThc.d.ts → index-Bz33tfQo.d.ts} +1 -1
  32. package/dist/{index-Bcxj7FqZ.d.cts → index-C5SXJAtZ.d.cts} +2 -2
  33. package/dist/{index-bkTCYnZj.d.cts → index-CCUB1hoV.d.cts} +1 -1
  34. package/dist/{index-C-nsgwuD.d.ts → index-D3yqgtiN.d.ts} +2 -2
  35. package/dist/{index-84453BaS.d.cts → index-DBKL6vyC.d.cts} +16 -3
  36. package/dist/{index-BvdIGsVr.d.cts → index-DNDNDzyJ.d.cts} +2 -2
  37. package/dist/{index-C7U9EiIP.d.ts → index-DXdwkq7X.d.ts} +2 -2
  38. package/dist/{index-B3o1AkNE.d.ts → index-MzcNxet1.d.ts} +1 -1
  39. package/dist/{index-DR9ahJ-x.d.cts → index-OfWkiJ5O.d.cts} +2 -2
  40. package/dist/{index-BFwAhPp8.d.ts → index-VPq6RwTm.d.ts} +16 -3
  41. package/dist/index.cjs +3 -3
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.cts +9 -9
  44. package/dist/index.d.ts +9 -9
  45. package/dist/index.js +3 -3
  46. package/dist/index.js.map +1 -1
  47. package/dist/macro-3uGSg-ic.js.map +1 -1
  48. package/dist/macro-Ywn4-0s5.cjs.map +1 -1
  49. package/dist/macro.d.cts +1 -1
  50. package/dist/macro.d.ts +1 -1
  51. package/dist/mediaType-BbIfudh0.cjs.map +1 -1
  52. package/dist/mediaType-DXQCNYdM.js.map +1 -1
  53. package/dist/mediaType.d.cts +2 -2
  54. package/dist/mediaType.d.ts +2 -2
  55. package/dist/node.d.cts +2 -2
  56. package/dist/node.d.ts +2 -2
  57. package/dist/{nodes-BdZfapPI.cjs → nodes-TtDfZ9qf.cjs} +12 -12
  58. package/dist/{nodes-BdZfapPI.cjs.map → nodes-TtDfZ9qf.cjs.map} +1 -1
  59. package/dist/{nodes-D9nwroV5.js → nodes-u9i-tqFp.js} +2 -2
  60. package/dist/{nodes-D9nwroV5.js.map → nodes-u9i-tqFp.js.map} +1 -1
  61. package/dist/promise-B3YkZ4C8.js.map +1 -1
  62. package/dist/promise-DScaykew.cjs.map +1 -1
  63. package/dist/schema-0YJZqRXb.cjs.map +1 -1
  64. package/dist/schema-BvUrXIoX.js.map +1 -1
  65. package/dist/schema-CC008xgK.js.map +1 -1
  66. package/dist/schema-DfLGJ-oh.cjs.map +1 -1
  67. package/dist/schema.d.cts +2 -2
  68. package/dist/schema.d.ts +2 -2
  69. package/dist/{visitor-VYLe7Q4m.d.cts → visitor-BN5QJX7-.d.cts} +1 -1
  70. package/dist/{visitor-CqI8T9Qa.d.ts → visitor-BNGMMmpe.d.ts} +1 -1
  71. package/dist/visitor-DA5yfOJz.js.map +1 -1
  72. package/dist/visitor-DhuKS-7x.cjs.map +1 -1
  73. package/package.json +1 -1
  74. package/dist/file-1YtTOZeL.js.map +0 -1
  75. package/dist/file-3gsgXreK.js.map +0 -1
  76. package/dist/file-D73XubVb.cjs.map +0 -1
  77. package/dist/file-azmmZwDb.cjs.map +0 -1
  78. package/dist/graph-DDh1FFrm.cjs.map +0 -1
  79. package/dist/graph-DImDxlJE.js.map +0 -1
@@ -1,10 +1,12 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-BV8xUvPy.cjs");
2
- let node_crypto = require("node:crypto");
3
2
  let node_path = require("node:path");
4
- const require_constants = require("./constants-BCRkFAiy.cjs");
3
+ let node_process = require("node:process");
5
4
  const require_promise = require("./promise-DScaykew.cjs");
5
+ let node_crypto = require("node:crypto");
6
+ const require_constants = require("./constants-BCRkFAiy.cjs");
6
7
  const require_nodeText = require("./nodeText-DH4dLGUb.cjs");
7
8
  node_path = require_rolldown_runtime.__toESM(node_path, 1);
9
+ node_process = require_rolldown_runtime.__toESM(node_process, 1);
8
10
  // src/utils/moduleNames.ts
9
11
  /**
10
12
  * Returns the names an import or export brings across. A node built with the deprecated fields gets them from
@@ -14,6 +16,12 @@ function getNames(node) {
14
16
  if (node.names) return node.names;
15
17
  return node.kind === "Import" ? fromDeprecatedImport(node) : fromDeprecatedExport(node);
16
18
  }
19
+ /**
20
+ * Returns `true` when a source is an exported declaration. Reads the deprecated `isIndexable` and `isExportable`, in that order, when `export` is unset.
21
+ */
22
+ function isExported(source) {
23
+ return !!(source.export ?? source.isIndexable ?? source.isExportable);
24
+ }
17
25
  function getSpace(source) {
18
26
  if (source.space) return source.space;
19
27
  if (source.isTypeOnly != null) return source.isTypeOnly ? "type" : "value";
@@ -100,151 +108,6 @@ function toDeprecatedExport(names) {
100
108
  asAlias: false
101
109
  };
102
110
  }
103
- // src/utils/combineFileMembers.ts
104
- /**
105
- * File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and
106
- * export entries of one file, while `combineSources` deduplicates source entries in original order.
107
- * `combineImports` also drops imports nothing references. This works on a file's members, not on
108
- * schema content.
109
- */
110
- const IDENTIFIER_RUN = /[\w$]+/g;
111
- /**
112
- * How many imports a file needs before indexing the source beats scanning it once per name.
113
- */
114
- const INDEX_ABOVE_IMPORTS = 128;
115
- const importForm = (item) => item.alias && (item.name === "*" || item.name === "default") ? item.name : "named";
116
- const exportForm = (item) => item.name === "*" ? "*" : "named";
117
- const label = (item) => item.alias ? `${item.name} as ${item.alias}` : item.name;
118
- function statementKey({ path, form, space, names }) {
119
- return form === "named" ? `${path}\0named\0${space}` : `${path}\0${form}\0${names[0]?.alias ?? ""}\0${space}`;
120
- }
121
- function toStatements(nodes, formOf) {
122
- return nodes.flatMap((node) => {
123
- const statements = /* @__PURE__ */ new Map();
124
- for (const item of getNames(node)) {
125
- const statement = {
126
- path: node.path,
127
- root: node.kind === "Import" ? node.root : void 0,
128
- form: formOf(item),
129
- space: item.space ?? "value",
130
- names: []
131
- };
132
- const key = statementKey({
133
- ...statement,
134
- names: [item]
135
- });
136
- const existing = statements.get(key) ?? statement;
137
- statements.set(key, existing);
138
- existing.names.push(item);
139
- }
140
- return [...statements.values()];
141
- });
142
- }
143
- /**
144
- * Relative specifiers by `root`, then `path`. `createFile` sorts a file's imports again on every
145
- * merge, and the path math dominated that sort on large specs. Two levels keep the existing strings
146
- * as keys, so lookups reuse their hashes instead of hashing a new joined key each time.
147
- */
148
- const specifierCache = require_promise.memo.create({ max: 1e4 });
149
- /**
150
- * Returns the specifier a member is written with: POSIX and relative to the importing file when it
151
- * has a `root`, like `getRelativePath` in parser-ts. Sorting on it keeps the order the same on every OS.
152
- */
153
- function specifier(node) {
154
- const { root, path: target } = node;
155
- if (!root) return target;
156
- const byPath = require_promise.memo(specifierCache, root, () => /* @__PURE__ */ new Map());
157
- return require_promise.memo(byPath, target, () => {
158
- const relative = node_path.default.relative(node_path.default.dirname(root), target).replaceAll("\\", "/");
159
- return relative.startsWith("../") ? relative : `./${relative}`;
160
- });
161
- }
162
- function sortKey(statement) {
163
- return `${statement.form === "named" ? "1" : "0"}:${statement.space === "type" ? "0" : "1"}:${specifier(statement)}:${statement.names.map(label).toSorted().join("\0")}`;
164
- }
165
- function mergeStatements(statements, keep = () => true) {
166
- const merged = /* @__PURE__ */ new Map();
167
- const sorted = statements.map((statement) => ({
168
- statement,
169
- key: sortKey(statement)
170
- })).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
171
- for (const { statement } of sorted) {
172
- const key = statementKey(statement);
173
- const entry = merged.get(key) ?? {
174
- statement: {
175
- ...statement,
176
- names: []
177
- },
178
- seen: /* @__PURE__ */ new Set()
179
- };
180
- merged.set(key, entry);
181
- for (const item of statement.names) {
182
- const id = item.alias ?? item.name;
183
- if (entry.seen.has(id) || !keep(item, statement)) continue;
184
- entry.seen.add(id);
185
- entry.statement.names.push(item);
186
- }
187
- }
188
- const result = [...merged.values()].map(({ statement }) => statement);
189
- const bound = ({ path, item }) => `${path}\0${item.alias ?? item.name}`;
190
- const values = new Set(result.filter(({ space }) => space === "value").flatMap(({ path, names }) => names.map((item) => bound({
191
- path,
192
- item
193
- }))));
194
- return result.map((statement) => statement.space === "type" ? {
195
- ...statement,
196
- names: statement.names.filter((item) => !values.has(bound({
197
- path: statement.path,
198
- item
199
- })))
200
- } : statement).filter((statement) => statement.names.length > 0);
201
- }
202
- /**
203
- * Deduplicates `SourceNode` objects by `name + export + space`, keeping the first of each
204
- * key. An unnamed source only drops when the same node appears twice, so markdown can repeat a
205
- * paragraph or a table. Returns the deduplicated array in original order.
206
- */
207
- function combineSources(sources) {
208
- const seen = /* @__PURE__ */ new Set();
209
- return sources.filter((source) => {
210
- const key = source.name != null ? `${source.name}:${source.export ?? source.isExportable ?? false}:${getSpace(source)}` : source;
211
- if (seen.has(key)) return false;
212
- seen.add(key);
213
- return true;
214
- });
215
- }
216
- /**
217
- * Deduplicates and merges `ExportNode` objects: one export per path, form and space. Returns a sorted array.
218
- */
219
- function combineExports(exports) {
220
- return mergeStatements(toStatements(exports, exportForm)).map(({ path, names }) => ({
221
- kind: "Export",
222
- path,
223
- ...toDeprecatedExport(names),
224
- names
225
- }));
226
- }
227
- /**
228
- * Deduplicates and merges `ImportNode` objects, filtering out unused imports.
229
- *
230
- * Retains imports that are referenced in `source` or re-exported. One import per path, form and space. Returns
231
- * a sorted, deduplicated, filtered array.
232
- */
233
- function combineImports(imports, exports, source) {
234
- const exportedNames = new Set(exports.flatMap((node) => getNames(node).map((item) => item.alias ?? item.name)));
235
- const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? new Set(source.match(IDENTIFIER_RUN)) : null;
236
- const isUsed = (importName) => !source || identifiers?.has(importName) || source.includes(importName) || exportedNames.has(importName);
237
- const statements = toStatements(imports.filter((node) => node.path !== node.root), importForm);
238
- const pathsWithUsedNamedImport = new Set(statements.filter(({ form, names }) => form === "named" && names.some((item) => isUsed(item.alias ?? item.name))).map(({ path }) => path));
239
- const keep = (item, { form, path }) => isUsed(item.alias ?? item.name) || form !== "named" && pathsWithUsedNamedImport.has(path);
240
- return mergeStatements(statements, keep).map(({ path, root, names }) => ({
241
- kind: "Import",
242
- path,
243
- ...root != null ? { root } : {},
244
- ...toDeprecatedImport(names),
245
- names
246
- }));
247
- }
248
111
  // src/nodes/base.ts
249
112
  /** Builds a `createX` factory for a node whose only computed field is `kind`. */
250
113
  function nodeFactory(kind) {
@@ -265,9 +128,27 @@ function overrideSpace(names, { value, derived }) {
265
128
  }));
266
129
  }
267
130
  const isOverride = ({ value, derived }) => value !== void 0 && JSON.stringify(value) !== JSON.stringify(derived);
131
+ const DERIVED = Symbol.for("kubb.ast.derived");
132
+ /** The deprecated fields the caller set: a value equal to the one the spread node derived is dropped, so `names` decides it. */
133
+ function ownFields(input) {
134
+ const snapshot = input[DERIVED];
135
+ if (!snapshot) return {
136
+ name: input.name,
137
+ isTypeOnly: input.isTypeOnly
138
+ };
139
+ return {
140
+ name: JSON.stringify(input.name) === snapshot.name ? void 0 : input.name,
141
+ isTypeOnly: input.isTypeOnly === snapshot.isTypeOnly ? void 0 : input.isTypeOnly
142
+ };
143
+ }
144
+ function withoutDerived(input) {
145
+ const { [DERIVED]: _, ...rest } = input;
146
+ return rest;
147
+ }
268
148
  /**
269
149
  * Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
270
150
  * `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.
151
+ * Fields a spread copies over unchanged are not overrides, so `{ ...imp, names }` uses the new `names`.
271
152
  *
272
153
  * @example Named import
273
154
  * ```ts
@@ -277,34 +158,41 @@ const isOverride = ({ value, derived }) => value !== void 0 && JSON.stringify(va
277
158
  */
278
159
  function createImport(input) {
279
160
  if (!input.names) return {
280
- ...input,
161
+ ...withoutDerived(input),
281
162
  name: input.name ?? [],
282
163
  kind: require_constants.nodeKinds.import
283
164
  };
165
+ const own = ownFields(input);
284
166
  const derived = toDeprecatedImport(input.names);
285
167
  if (isOverride({
286
- value: input.name,
168
+ value: own.name,
287
169
  derived: derived.name
288
170
  })) return {
289
- ...input,
171
+ ...withoutDerived(input),
290
172
  names: null,
291
- name: input.name ?? [],
173
+ name: own.name ?? [],
292
174
  kind: require_constants.nodeKinds.import
293
175
  };
294
176
  const names = overrideSpace(input.names, {
295
- value: input.isTypeOnly,
177
+ value: own.isTypeOnly,
296
178
  derived: derived.isTypeOnly
297
179
  });
180
+ const fields = toDeprecatedImport(names);
298
181
  return {
299
182
  ...input,
300
- ...toDeprecatedImport(names),
183
+ ...fields,
301
184
  names,
185
+ [DERIVED]: {
186
+ name: JSON.stringify(fields.name),
187
+ isTypeOnly: fields.isTypeOnly
188
+ },
302
189
  kind: require_constants.nodeKinds.import
303
190
  };
304
191
  }
305
192
  /**
306
193
  * Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
307
- * `isTypeOnly` that differs from the one `names` gives overrides it.
194
+ * `isTypeOnly` that differs from the one `names` gives overrides it. Fields a spread copies over unchanged are not
195
+ * overrides, so `{ ...exp, names }` uses the new `names`.
308
196
  *
309
197
  * @example Named export
310
198
  * ```ts
@@ -314,26 +202,34 @@ function createImport(input) {
314
202
  */
315
203
  function createExport(input) {
316
204
  if (!input.names) return {
317
- ...input,
205
+ ...withoutDerived(input),
318
206
  kind: require_constants.nodeKinds.export
319
207
  };
208
+ const own = ownFields(input);
320
209
  const derived = toDeprecatedExport(input.names);
321
210
  if (isOverride({
322
- value: input.name,
211
+ value: own.name,
323
212
  derived: derived.name
324
213
  })) return {
325
- ...input,
214
+ ...withoutDerived(input),
215
+ name: own.name,
326
216
  names: null,
327
217
  kind: require_constants.nodeKinds.export
328
218
  };
329
219
  const names = overrideSpace(input.names, {
330
- value: input.isTypeOnly,
220
+ value: own.isTypeOnly,
331
221
  derived: derived.isTypeOnly
332
222
  });
223
+ const fields = toDeprecatedExport(names);
333
224
  return {
334
225
  ...input,
335
- ...toDeprecatedExport(names),
226
+ ...fields,
227
+ name: fields.name,
336
228
  names,
229
+ [DERIVED]: {
230
+ name: JSON.stringify(fields.name),
231
+ isTypeOnly: fields.isTypeOnly
232
+ },
337
233
  kind: require_constants.nodeKinds.export
338
234
  };
339
235
  }
@@ -423,6 +319,154 @@ function createFile(input) {
423
319
  meta: input.meta ?? {}
424
320
  };
425
321
  }
322
+ // src/utils/combineFileMembers.ts
323
+ /**
324
+ * File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and
325
+ * export entries of one file, while `combineSources` deduplicates source entries in original order.
326
+ * `combineImports` also drops imports nothing references. This works on a file's members, not on
327
+ * schema content.
328
+ */
329
+ const IDENTIFIER_RUN = /[\w$]+/g;
330
+ /**
331
+ * How many imports a file needs before indexing the source beats scanning it once per name.
332
+ */
333
+ const INDEX_ABOVE_IMPORTS = 128;
334
+ const importForm = (item) => item.alias && (item.name === "*" || item.name === "default") ? item.name : "named";
335
+ const exportForm = (item) => item.name === "*" ? "*" : "named";
336
+ const label = (item) => item.alias ? `${item.name} as ${item.alias}` : item.name;
337
+ function statementKey({ path, form, space, names }) {
338
+ return form === "named" ? `${path}\0named\0${space}` : `${path}\0${form}\0${names[0]?.alias ?? ""}\0${space}`;
339
+ }
340
+ function toStatements(nodes, formOf) {
341
+ return nodes.flatMap((node) => {
342
+ const statements = /* @__PURE__ */ new Map();
343
+ for (const item of getNames(node)) {
344
+ const statement = {
345
+ path: node.path,
346
+ root: node.kind === "Import" ? node.root : void 0,
347
+ form: formOf(item),
348
+ space: item.space ?? "value",
349
+ names: []
350
+ };
351
+ const key = statementKey({
352
+ ...statement,
353
+ names: [item]
354
+ });
355
+ const existing = statements.get(key) ?? statement;
356
+ statements.set(key, existing);
357
+ existing.names.push(item);
358
+ }
359
+ return [...statements.values()];
360
+ });
361
+ }
362
+ /**
363
+ * Relative specifiers by `root`, then `path`. `createFile` sorts a file's imports again on every
364
+ * merge, and the path math dominated that sort on large specs. Two levels keep the existing strings
365
+ * as keys, so lookups reuse their hashes instead of hashing a new joined key each time.
366
+ */
367
+ const specifierCache = require_promise.memo.create({ max: 1e4 });
368
+ /**
369
+ * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * getRelativePath('/root/src/models/pet.ts', '/root/lib/client.ts') // '../../lib/client.ts'
374
+ * ```
375
+ */
376
+ function getRelativePath(root, filePath) {
377
+ const rootKey = node_path.default.isAbsolute(root) && node_path.default.isAbsolute(filePath) ? root : `${node_process.default.cwd()}\u0000${root}`;
378
+ const byPath = require_promise.memo(specifierCache, rootKey, () => /* @__PURE__ */ new Map());
379
+ return require_promise.memo(byPath, filePath, () => {
380
+ const relative = node_path.default.relative(node_path.default.dirname(root), filePath).replaceAll("\\", "/");
381
+ return relative.startsWith("../") ? relative : `./${relative}`;
382
+ });
383
+ }
384
+ /** The specifier a member is written with, so sorting on it gives the same order on every OS. */
385
+ function specifier(node) {
386
+ return node.root ? getRelativePath(node.root, node.path) : node.path;
387
+ }
388
+ function sortKey(statement) {
389
+ return `${statement.form === "named" ? "1" : "0"}:${statement.space === "type" ? "0" : "1"}:${specifier(statement)}:${statement.names.map(label).toSorted().join("\0")}`;
390
+ }
391
+ function mergeStatements(statements, keep = () => true) {
392
+ const merged = /* @__PURE__ */ new Map();
393
+ const sorted = statements.map((statement) => ({
394
+ statement,
395
+ key: sortKey(statement)
396
+ })).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
397
+ for (const { statement } of sorted) {
398
+ const key = statementKey(statement);
399
+ const entry = merged.get(key) ?? {
400
+ statement: {
401
+ ...statement,
402
+ names: []
403
+ },
404
+ seen: /* @__PURE__ */ new Set()
405
+ };
406
+ merged.set(key, entry);
407
+ for (const item of statement.names) {
408
+ const id = item.alias ?? item.name;
409
+ if (entry.seen.has(id) || !keep(item, statement)) continue;
410
+ entry.seen.add(id);
411
+ entry.statement.names.push(item);
412
+ }
413
+ }
414
+ const result = [...merged.values()].map(({ statement }) => statement);
415
+ const bound = ({ path, item }) => `${path}\0${item.alias ?? item.name}`;
416
+ const values = new Set(result.filter(({ space }) => space === "value").flatMap(({ path, names }) => names.map((item) => bound({
417
+ path,
418
+ item
419
+ }))));
420
+ return result.map((statement) => statement.space === "type" ? {
421
+ ...statement,
422
+ names: statement.names.filter((item) => !values.has(bound({
423
+ path: statement.path,
424
+ item
425
+ })))
426
+ } : statement).filter((statement) => statement.names.length > 0);
427
+ }
428
+ /**
429
+ * Deduplicates `SourceNode` objects by `name + export + space`, keeping the first of each
430
+ * key. An unnamed source only drops when the same node appears twice, so markdown can repeat a
431
+ * paragraph or a table. Returns the deduplicated array in original order.
432
+ */
433
+ function combineSources(sources) {
434
+ const seen = /* @__PURE__ */ new Set();
435
+ return sources.filter((source) => {
436
+ const key = source.name != null ? `${source.name}:${isExported(source)}:${getSpace(source)}` : source;
437
+ if (seen.has(key)) return false;
438
+ seen.add(key);
439
+ return true;
440
+ });
441
+ }
442
+ /**
443
+ * Deduplicates and merges `ExportNode` objects: one export per path, form and space. Returns a sorted array.
444
+ */
445
+ function combineExports(exports) {
446
+ return mergeStatements(toStatements(exports, exportForm)).map(({ path, names }) => createExport({
447
+ path,
448
+ names
449
+ }));
450
+ }
451
+ /**
452
+ * Deduplicates and merges `ImportNode` objects, filtering out unused imports.
453
+ *
454
+ * Retains imports that are referenced in `source` or re-exported. One import per path, form and space. Returns
455
+ * a sorted, deduplicated, filtered array.
456
+ */
457
+ function combineImports(imports, exports, source) {
458
+ const exportedNames = new Set(exports.flatMap((node) => getNames(node).map((item) => item.alias ?? item.name)));
459
+ const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? new Set(source.match(IDENTIFIER_RUN)) : null;
460
+ const isUsed = (importName) => !source || identifiers?.has(importName) || source.includes(importName) || exportedNames.has(importName);
461
+ const statements = toStatements(imports.filter((node) => node.path !== node.root), importForm);
462
+ const pathsWithUsedNamedImport = new Set(statements.filter(({ form, names }) => form === "named" && names.some((item) => isUsed(item.alias ?? item.name))).map(({ path }) => path));
463
+ const keep = (item, { form, path }) => isUsed(item.alias ?? item.name) || form !== "named" && pathsWithUsedNamedImport.has(path);
464
+ return mergeStatements(statements, keep).map(({ path, root, names }) => createImport({
465
+ path,
466
+ ...root != null ? { root } : {},
467
+ names
468
+ }));
469
+ }
426
470
  Object.defineProperty(exports, "createExport", {
427
471
  enumerable: true,
428
472
  get: function() {
@@ -453,12 +497,24 @@ Object.defineProperty(exports, "getNames", {
453
497
  return getNames;
454
498
  }
455
499
  });
500
+ Object.defineProperty(exports, "getRelativePath", {
501
+ enumerable: true,
502
+ get: function() {
503
+ return getRelativePath;
504
+ }
505
+ });
456
506
  Object.defineProperty(exports, "getSpace", {
457
507
  enumerable: true,
458
508
  get: function() {
459
509
  return getSpace;
460
510
  }
461
511
  });
512
+ Object.defineProperty(exports, "isExported", {
513
+ enumerable: true,
514
+ get: function() {
515
+ return isExported;
516
+ }
517
+ });
462
518
  Object.defineProperty(exports, "nodeFactory", {
463
519
  enumerable: true,
464
520
  get: function() {
@@ -466,4 +522,4 @@ Object.defineProperty(exports, "nodeFactory", {
466
522
  }
467
523
  });
468
524
 
469
- //# sourceMappingURL=file-D73XubVb.cjs.map
525
+ //# sourceMappingURL=combineFileMembers-DmmuOmY8.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combineFileMembers-DmmuOmY8.cjs","names":["nodeKinds","path","getNodeText","hash","memo","path","process"],"sources":["../src/utils/moduleNames.ts","../src/nodes/base.ts","../src/nodes/file.ts","../src/utils/combineFileMembers.ts"],"sourcesContent":["import type { ExportNode, ImportNode, ModuleName, SourceNode, Space } from '../nodes/file.ts'\n\n/**\n * Returns the names an import or export brings across. A node built with the deprecated fields gets them from\n * those, each with an explicit `space`, so it prints exactly as before.\n */\nexport function getNames(node: ImportNode | ExportNode): Array<ModuleName> {\n if (node.names) return node.names\n return node.kind === 'Import' ? fromDeprecatedImport(node) : fromDeprecatedExport(node)\n}\n\n/**\n * Returns `true` when a source is an exported declaration. Reads the deprecated `isIndexable` and `isExportable`, in that order, when `export` is unset.\n */\nexport function isExported(source: Pick<SourceNode, 'export' | 'isIndexable' | 'isExportable'>): boolean {\n return !!(source.export ?? source.isIndexable ?? source.isExportable)\n}\n\nexport function getSpace(source: SourceNode): Space {\n if (source.space) return source.space\n if (source.isTypeOnly != null) return source.isTypeOnly ? 'type' : 'value'\n return source.nodes?.[0]?.kind === 'Type' ? 'type' : 'value'\n}\n\nexport type DeprecatedImport = Pick<ImportNode, 'name' | 'isTypeOnly' | 'isNameSpace'>\nexport type DeprecatedExport = Pick<ExportNode, 'name' | 'isTypeOnly' | 'asAlias'>\n\n/**\n * @deprecated Converts a node built with `name`, `isTypeOnly` and `isNameSpace` to `names`. Removed in Kubb v6.\n */\nfunction fromDeprecatedImport({ name, isTypeOnly, isNameSpace }: DeprecatedImport): Array<ModuleName> {\n const space: Space = isTypeOnly ? 'type' : 'value'\n if (!Array.isArray(name)) return [{ name: isNameSpace ? '*' : 'default', alias: name, space }]\n return name.map((item) => (typeof item === 'string' ? { name: item, space } : { name: item.propertyName, ...(item.name ? { alias: item.name } : {}), space }))\n}\n\n/**\n * @deprecated Converts a node built with `name`, `isTypeOnly` and `asAlias` to `names`. Removed in Kubb v6.\n */\nfunction fromDeprecatedExport({ name, isTypeOnly, asAlias }: DeprecatedExport): Array<ModuleName> {\n const space: Space = isTypeOnly ? 'type' : 'value'\n if (name == null) return [{ name: '*', space }]\n if (!Array.isArray(name)) return [asAlias ? { name: '*', alias: name, space } : { name, space }]\n return name.map((item) => ({ name: item, space }))\n}\n\n/**\n * @deprecated The old import fields for `names`, for code that still reads them. Removed in Kubb v6.\n */\nexport function toDeprecatedImport(names: ReadonlyArray<ModuleName>): DeprecatedImport {\n const isTypeOnly = names.length > 0 && names.every((item) => item.space === 'type')\n const [first] = names\n if (names.length === 1 && first?.alias && (first.name === '*' || first.name === 'default')) {\n return { name: first.alias, isTypeOnly, isNameSpace: first.name === '*' }\n }\n return { name: names.map((item) => (item.alias ? { propertyName: item.name, name: item.alias } : item.name)), isTypeOnly, isNameSpace: false }\n}\n\n/**\n * @deprecated The old export fields for `names`; an alias stands in for its name. Removed in Kubb v6.\n */\nexport function toDeprecatedExport(names: ReadonlyArray<ModuleName>): DeprecatedExport {\n const isTypeOnly = names.length > 0 && names.every((item) => item.space === 'type')\n const [first] = names\n if (names.length === 1 && first?.name === '*') {\n return first.alias ? { name: first.alias, isTypeOnly, asAlias: true } : { isTypeOnly, asAlias: false }\n }\n return { name: names.map((item) => item.alias ?? item.name), isTypeOnly, asAlias: false }\n}\n","import type { ValueOf } from '@internals/utils'\nimport type { nodeKinds } from '../constants.ts'\n\n/**\n * `kind` values used by AST nodes.\n *\n * @example\n * ```ts\n * const kind: NodeKind = 'Schema'\n * ```\n */\nexport type NodeKind = ValueOf<typeof nodeKinds>\n\n/**\n * Base shape shared by all AST nodes.\n *\n * @example\n * ```ts\n * const base: BaseNode = { kind: 'Input' }\n * ```\n */\nexport type BaseNode = {\n /**\n * Node discriminator.\n */\n kind: NodeKind\n /**\n * Where the node comes from in the input, in the form the adapter's `locate` reads. Document\n * adapters such as OpenAPI and AsyncAPI use an RFC 6901 JSON pointer, for example\n * `#/components/schemas/Pet`. Plugins can copy it to the code nodes they emit.\n */\n pointer?: string\n}\n\n/** `Omit` applied to each member of a union, so the union survives. */\nexport type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never\n\n/** Builds a `createX` factory for a node whose only computed field is `kind`. */\nexport function nodeFactory<T extends BaseNode>(kind: T['kind']): (input: Omit<T, 'kind'>) => T {\n return (input) => {\n const node = { ...input, kind }\n return node as T\n }\n}\n","import { hash } from 'node:crypto'\nimport path from 'node:path'\nimport { nodeKinds } from '../constants.ts'\nimport { combineExports, combineImports, combineSources } from '../utils/combineFileMembers.ts'\nimport { getNames, toDeprecatedExport, toDeprecatedImport } from '../utils/moduleNames.ts'\nimport { getNodeText } from '../utils/nodeText.ts'\nimport { type BaseNode, nodeFactory } from './base.ts'\nimport type { CodeNode } from './code.ts'\n\n/**\n * Supported file extensions.\n */\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type ImportName = string | Array<string | { propertyName: string; name?: string }>\n\n/**\n * Whether a declaration exists only at compile time (`'type'`) or also at runtime (`'value'`).\n */\nexport type Space = 'type' | 'value'\n\n/**\n * One name an import or export brings across, as in the ECMAScript `ImportEntry` record.\n */\nexport type ModuleName = {\n /**\n * Name in the other module: `'default'` for its default export, `'*'` for the whole module.\n */\n name: string\n /**\n * Local name for an import, or the exported name for an export.\n */\n alias?: string | null\n /**\n * Type or value.\n * @default 'value'\n */\n space?: Space | null\n}\n\n/**\n * Represents a language-agnostic import/dependency declaration.\n *\n * @example Named import (TypeScript: `import { useState } from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'useState' }], path: 'react' })\n * ```\n *\n * @example Default import (TypeScript: `import React from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'default', alias: 'React' }], path: 'react' })\n * ```\n *\n * @example Type-only import (TypeScript: `import type { FC } from 'react'`)\n * ```ts\n * createImport({ names: [{ name: 'FC', space: 'type' }], path: 'react' })\n * ```\n *\n * @example Namespace import (TypeScript: `import * as React from 'react'`)\n * ```ts\n * createImport({ names: [{ name: '*', alias: 'React' }], path: 'react' })\n * ```\n */\nexport type ImportNode = BaseNode & {\n kind: 'Import'\n /**\n * The names the import brings in. `ast.file.getNames` also reads the deprecated fields.\n */\n names?: Array<ModuleName> | null\n /**\n * Import name(s) to be used.\n *\n * @deprecated Use `names`. Removed in Kubb v6.\n */\n name: ImportName\n /**\n * Path for the import.\n *\n * @example\n * `'@kubb/core'`\n */\n path: string\n /**\n * Add a type-only import prefix.\n *\n * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Import the entire module as a namespace.\n *\n * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.\n */\n isNameSpace?: boolean | null\n /**\n * When set, the import path is resolved relative to this root.\n */\n root?: string | null\n}\n\n/**\n * Represents a language-agnostic export/public API declaration.\n *\n * @example Named export (TypeScript: `export { Pets } from './Pets'`)\n * ```ts\n * createExport({ names: [{ name: 'Pets' }], path: './Pets' })\n * ```\n *\n * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)\n * ```ts\n * createExport({ names: [{ name: 'Pet', space: 'type' }], path: './Pet' })\n * ```\n *\n * @example Wildcard export (TypeScript: `export * from './utils'`)\n * ```ts\n * createExport({ names: [{ name: '*' }], path: './utils' })\n * ```\n *\n * @example Namespace alias (TypeScript: `export * as utils from './utils'`)\n * ```ts\n * createExport({ names: [{ name: '*', alias: 'utils' }], path: './utils' })\n * ```\n */\nexport type ExportNode = BaseNode & {\n kind: 'Export'\n /**\n * The names the export passes on. `ast.file.getNames` also reads the deprecated fields.\n */\n names?: Array<ModuleName> | null\n /**\n * Export name(s) to be used. When omitted, generates a wildcard export.\n *\n * @deprecated Use `names`. Removed in Kubb v6.\n */\n name?: string | Array<string> | null\n /**\n * Path for the export.\n *\n * @example\n * `'@kubb/core'`\n */\n path: string\n /**\n * Add a type-only export prefix.\n *\n * @deprecated Set `space: 'type'` on each name. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Export as an aliased namespace.\n *\n * @deprecated Use `{ name: '*', alias }` in `names`. Removed in Kubb v6.\n */\n asAlias?: boolean | null\n}\n\n/**\n * Represents a fragment of source code within a file.\n *\n * @example Named exportable source\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })\n * ```\n *\n * @example Inline unnamed code block\n * ```ts\n * createSource({ nodes: [createText('const x = 1')] })\n * ```\n */\nexport type SourceNode = BaseNode & {\n kind: 'Source'\n /**\n * Optional name identifying this source (used for deduplication and barrel generation).\n */\n name?: string | null\n /**\n * Type or value. When unset, a source whose first node is a `Type` is a type.\n */\n space?: Space | null\n /**\n * Mark this source as a type-only export.\n *\n * @deprecated Use `space: 'type'`. Removed in Kubb v6.\n */\n isTypeOnly?: boolean | null\n /**\n * Mark this source as an exported declaration, which barrels list. The source text carries its own `export` keyword.\n */\n export?: boolean | null\n /**\n * Mark this exported source as the module's default export. Barrels skip it, since they can't re-export it by name.\n */\n default?: boolean | null\n /**\n * @deprecated Use `export`. Removed in Kubb v6.\n */\n isExportable?: boolean | null\n /**\n * @deprecated Use `export`. Removed in Kubb v6.\n */\n isIndexable?: boolean | null\n /**\n * Marks the source as a definition that importing files absorb instead of import. `expression` is\n * the declaration's right-hand side, such as `{ body: Pet }`.\n *\n * @deprecated Set `inline` on the file. Removed in Kubb v6.\n */\n inline?: { expression: string } | null\n /**\n * Child nodes that make up this source fragment, in DOM order.\n * Use a {@link TextNode} for raw string content.\n */\n nodes?: Array<CodeNode>\n}\n\n/**\n * Represents a fully resolved file in the AST.\n *\n * Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input\n * and deduplicates `imports`, `exports`, and `sources`.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of the path\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n */\nexport type FileNode<TMeta extends object = object> = BaseNode & {\n kind: 'File'\n /**\n * Unique identifier derived from a SHA256 hash of the file path. `createFile`\n * computes it, so callers do not need to provide it.\n */\n id: string\n /**\n * File name without extension, derived from `baseName`.\n *\n * @see https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n /**\n * File base name, including extension, shaped like `${name}${extname}`.\n *\n * @see https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: `${string}.${string}`\n /**\n * Full qualified path to the file.\n */\n path: string\n /**\n * File extension extracted from `baseName`.\n */\n extname: Extname\n /**\n * Deduplicated list of source code fragments.\n */\n sources: Array<SourceNode>\n /**\n * Deduplicated list of import declarations.\n */\n imports: Array<ImportNode>\n /**\n * Deduplicated list of export declarations.\n */\n exports: Array<ExportNode>\n /**\n * Optional metadata attached to this file, read by plugins during barrel generation.\n */\n meta?: TMeta\n /**\n * Optional banner prepended to the generated file content.\n * Accepts `null` so `resolver.default.banner()` results can be passed directly.\n */\n banner?: string | null\n /**\n * Optional footer appended to the generated file content.\n * Accepts `null` so `resolver.default.footer()` results can be passed directly.\n */\n footer?: string | null\n /**\n * Absolute on-disk path to copy into the output, through the parser's `copy` hook when it has one.\n *\n * Use to emit a real source file shipped inside a package (a template) into the generated\n * folder. When set, `copy` provides the file content and any `sources` nodes are ignored for\n * output; `sources` may still carry `name`/`export` so barrel generation\n * treats the file the same as a rendered one.\n */\n copy?: string | null\n /**\n * Marks a file that is never written. Each file that imports from it gets the body of each imported declaration, such as `{ body: Pet }`, in place of its name.\n */\n inline?: boolean | null\n}\n\nexport type ImportInput = Omit<ImportNode, 'kind' | 'name'> & { name?: ImportName }\n\nexport type ExportInput = Omit<ExportNode, 'kind'>\n\n// A spread node carries the deprecated fields derived from its `names`, so only a value that differs is an override.\ntype Override<TValue> = { value: TValue | null | undefined; derived: TValue | null | undefined }\n\nfunction overrideSpace(names: Array<ModuleName>, { value, derived }: Override<boolean>): Array<ModuleName> {\n if (value == null || value === derived) return names\n const space = value ? 'type' : 'value'\n return names.map((item) => ({ ...item, space }))\n}\n\nconst isOverride = ({ value, derived }: Override<unknown>): boolean => value !== undefined && JSON.stringify(value) !== JSON.stringify(derived)\n\n// Object spread copies symbol keys, so `{ ...imp, names }` carries the fields `imp` derived and they can be told apart from an override.\nconst DERIVED = Symbol.for('kubb.ast.derived')\n// `name` is stored as JSON, so changing the node's `name` array in place still counts as an override.\ntype Derived = { name: string | undefined; isTypeOnly?: boolean | null }\ntype WithDerived = { [DERIVED]?: Derived }\n\n/** The deprecated fields the caller set: a value equal to the one the spread node derived is dropped, so `names` decides it. */\nfunction ownFields<TName>(input: { name?: TName; isTypeOnly?: boolean | null } & WithDerived): { name?: TName; isTypeOnly?: boolean | null } {\n const snapshot = input[DERIVED]\n if (!snapshot) return { name: input.name, isTypeOnly: input.isTypeOnly }\n return {\n name: JSON.stringify(input.name) === snapshot.name ? undefined : input.name,\n isTypeOnly: input.isTypeOnly === snapshot.isTypeOnly ? undefined : input.isTypeOnly,\n }\n}\n\nfunction withoutDerived<T extends object>(input: T): T {\n const { [DERIVED]: _, ...rest } = input as T & WithDerived\n return rest as T\n}\n\n/**\n * Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or\n * `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.\n * Fields a spread copies over unchanged are not overrides, so `{ ...imp, names }` uses the new `names`.\n *\n * @example Named import\n * ```ts\n * createImport({ names: [{ name: 'useState' }], path: 'react' })\n * // import { useState } from 'react'\n * ```\n */\nexport function createImport(input: ImportInput): ImportNode {\n if (!input.names) return { ...withoutDerived(input), name: input.name ?? [], kind: nodeKinds.import }\n const own = ownFields(input)\n const derived = toDeprecatedImport(input.names)\n if (isOverride({ value: own.name, derived: derived.name })) return { ...withoutDerived(input), names: null, name: own.name ?? [], kind: nodeKinds.import }\n const names = overrideSpace(input.names, { value: own.isTypeOnly, derived: derived.isTypeOnly })\n const fields = toDeprecatedImport(names)\n const node: ImportNode & WithDerived = {\n ...input,\n ...fields,\n names,\n [DERIVED]: { name: JSON.stringify(fields.name), isTypeOnly: fields.isTypeOnly },\n kind: nodeKinds.import,\n }\n return node\n}\n\n/**\n * Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or\n * `isTypeOnly` that differs from the one `names` gives overrides it. Fields a spread copies over unchanged are not\n * overrides, so `{ ...exp, names }` uses the new `names`.\n *\n * @example Named export\n * ```ts\n * createExport({ names: [{ name: 'Pet' }], path: './Pet' })\n * // export { Pet } from './Pet'\n * ```\n */\nexport function createExport(input: ExportInput): ExportNode {\n if (!input.names) return { ...withoutDerived(input), kind: nodeKinds.export }\n const own = ownFields(input)\n const derived = toDeprecatedExport(input.names)\n if (isOverride({ value: own.name, derived: derived.name })) return { ...withoutDerived(input), name: own.name, names: null, kind: nodeKinds.export }\n const names = overrideSpace(input.names, { value: own.isTypeOnly, derived: derived.isTypeOnly })\n const fields = toDeprecatedExport(names)\n const node: ExportNode & WithDerived = {\n ...input,\n ...fields,\n name: fields.name,\n names,\n [DERIVED]: { name: JSON.stringify(fields.name), isTypeOnly: fields.isTypeOnly },\n kind: nodeKinds.export,\n }\n return node\n}\n\n/**\n * Creates a `SourceNode` representing a fragment of source code within a file.\n *\n * @example\n * ```ts\n * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], export: true })\n * ```\n */\nexport const createSource = nodeFactory<SourceNode>(nodeKinds.source)\n\n/**\n * Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed\n * and `imports`/`exports`/`sources` are deduplicated.\n */\nexport type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> &\n Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>\n\n/**\n * Creates a fully resolved `FileNode` from a file input descriptor.\n *\n * Computes:\n * - `id` SHA256 hash of the file path\n * - `name` `baseName` without extension\n * - `extname` extension extracted from `baseName`\n *\n * Deduplicates:\n * - `sources` via `combineSources`\n * - `exports` via `combineExports`\n * - `imports` via `combineImports` (also filters unused imports)\n *\n * @throws {Error} when `baseName` has no extension.\n *\n * @example\n * ```ts\n * const file = createFile({\n * baseName: 'petStore.ts',\n * path: 'src/models/petStore.ts',\n * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],\n * imports: [createImport({ name: ['z'], path: 'zod' })],\n * exports: [createExport({ name: ['Pet'], path: './petStore' })],\n * })\n * // file.id = SHA256 hash of 'src/models/petStore.ts'\n * // file.name = 'petStore'\n * // file.extname = '.ts'\n * ```\n *\n * @example Copy a real file into the output\n * ```ts\n * const file = createFile({\n * baseName: 'client.ts',\n * path: 'src/gen/client.ts',\n * copy: '/abs/path/to/templates/client.ts',\n * })\n * ```\n */\nexport function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta> {\n const extname = path.extname(input.baseName) as `.${string}`\n if (!extname) {\n throw new Error(`No extname found for ${input.baseName}`)\n }\n\n const resolvedExports = input.exports?.length ? combineExports(input.exports) : []\n const resolvedSources = input.sources?.length ? combineSources(input.sources) : []\n\n // Skip building the source text and local-name set when there are no imports to resolve against them.\n const resolvedImports: Array<ImportNode> = (() => {\n if (!input.imports?.length) return []\n\n const sourceParts: Array<string> = []\n const localNames = new Set<string>()\n // Only the sources the file keeps count: an import used just by a dropped duplicate is unused.\n for (const item of resolvedSources) {\n const extracted = item.nodes && getNodeText(item.nodes)\n if (extracted) sourceParts.push(extracted)\n if (item.name) localNames.add(item.name)\n }\n const source = sourceParts.join('\\n') || undefined\n const combinedImports = combineImports(input.imports, resolvedExports, source)\n // Consolidating output (`mode: 'file'`) can put a symbol's definition and an import of it in the\n // same file: by path when the import still targets this file, by name when consolidation moved it.\n return combinedImports.flatMap((imp) => {\n if (imp.path === input.path) return []\n const names = getNames(imp)\n const kept = names.filter((item) => !localNames.has(item.alias ?? item.name))\n if (!kept.length) return []\n return [kept.length === names.length ? imp : createImport({ path: imp.path, ...(imp.root != null ? { root: imp.root } : {}), names: kept })]\n })\n })()\n\n return {\n ...input,\n kind: nodeKinds.file,\n id: hash('sha256', input.path, 'hex'),\n name: path.basename(input.baseName, extname),\n extname,\n imports: resolvedImports,\n exports: resolvedExports,\n sources: resolvedSources,\n meta: (input.meta ?? {}) as TMeta,\n }\n}\n","/**\n * File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and\n * export entries of one file, while `combineSources` deduplicates source entries in original order.\n * `combineImports` also drops imports nothing references. This works on a file's members, not on\n * schema content.\n */\nimport path from 'node:path'\nimport process from 'node:process'\nimport { memo } from '@internals/utils'\nimport { createExport, createImport, type ExportNode, type ImportNode, type ModuleName, type SourceNode, type Space } from '../nodes/file.ts'\nimport { getNames, getSpace, isExported } from './moduleNames.ts'\n\nconst IDENTIFIER_RUN = /[\\w$]+/g\n\n/**\n * How many imports a file needs before indexing the source beats scanning it once per name.\n */\nconst INDEX_ABOVE_IMPORTS = 128\n\ntype Form = 'named' | 'default' | '*'\n\ntype Statement = { path: string; root?: string | null; form: Form; space: Space; names: Array<ModuleName> }\n\nconst importForm = (item: ModuleName): Form => (item.alias && (item.name === '*' || item.name === 'default') ? item.name : 'named')\nconst exportForm = (item: ModuleName): Form => (item.name === '*' ? '*' : 'named')\nconst label = (item: ModuleName): string => (item.alias ? `${item.name} as ${item.alias}` : item.name)\n\nfunction statementKey({ path, form, space, names }: Statement): string {\n return form === 'named' ? `${path}\\0named\\0${space}` : `${path}\\0${form}\\0${names[0]?.alias ?? ''}\\0${space}`\n}\n\nfunction toStatements(nodes: ReadonlyArray<ImportNode | ExportNode>, formOf: (item: ModuleName) => Form): Array<Statement> {\n return nodes.flatMap((node) => {\n const statements = new Map<string, Statement>()\n for (const item of getNames(node)) {\n const statement: Statement = {\n path: node.path,\n root: node.kind === 'Import' ? node.root : undefined,\n form: formOf(item),\n space: item.space ?? 'value',\n names: [],\n }\n const key = statementKey({ ...statement, names: [item] })\n const existing = statements.get(key) ?? statement\n statements.set(key, existing)\n existing.names.push(item)\n }\n return [...statements.values()]\n })\n}\n\n/**\n * Relative specifiers by `root`, then `path`. `createFile` sorts a file's imports again on every\n * merge, and the path math dominated that sort on large specs. Two levels keep the existing strings\n * as keys, so lookups reuse their hashes instead of hashing a new joined key each time.\n */\nconst specifierCache = memo.create<string, Map<string, string>>({ max: 10_000 })\n\n/**\n * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.\n *\n * @example\n * ```ts\n * getRelativePath('/root/src/models/pet.ts', '/root/lib/client.ts') // '../../lib/client.ts'\n * ```\n */\nexport function getRelativePath(root: string, filePath: string): string {\n // A relative input resolves against the working directory, so that directory is part of its key.\n const rootKey = path.isAbsolute(root) && path.isAbsolute(filePath) ? root : `${process.cwd()}\\u0000${root}`\n const byPath = memo(specifierCache, rootKey, () => new Map<string, string>())\n return memo(byPath, filePath, () => {\n const relative = path.relative(path.dirname(root), filePath).replaceAll('\\\\', '/')\n return relative.startsWith('../') ? relative : `./${relative}`\n })\n}\n\n/** The specifier a member is written with, so sorting on it gives the same order on every OS. */\nfunction specifier(node: { path: string; root?: string | null }): string {\n return node.root ? getRelativePath(node.root, node.path) : node.path\n}\n\nfunction sortKey(statement: Statement): string {\n const form = statement.form === 'named' ? '1' : '0'\n const space = statement.space === 'type' ? '0' : '1'\n return `${form}:${space}:${specifier(statement)}:${statement.names.map(label).toSorted().join('\\0')}`\n}\n\nfunction mergeStatements(statements: Array<Statement>, keep: (item: ModuleName, statement: Statement) => boolean = () => true): Array<Statement> {\n const merged = new Map<string, { statement: Statement; seen: Set<string> }>()\n const sorted = statements.map((statement) => ({ statement, key: sortKey(statement) })).sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))\n\n for (const { statement } of sorted) {\n const key = statementKey(statement)\n const entry = merged.get(key) ?? { statement: { ...statement, names: [] }, seen: new Set<string>() }\n merged.set(key, entry)\n for (const item of statement.names) {\n const id = item.alias ?? item.name\n if (entry.seen.has(id) || !keep(item, statement)) continue\n entry.seen.add(id)\n entry.statement.names.push(item)\n }\n }\n\n const result = [...merged.values()].map(({ statement }) => statement)\n // A name kept as a value also serves its type uses, so a type statement from the same path must not bind it again.\n const bound = ({ path, item }: { path: string; item: ModuleName }) => `${path}\\0${item.alias ?? item.name}`\n const values = new Set(result.filter(({ space }) => space === 'value').flatMap(({ path, names }) => names.map((item) => bound({ path, item }))))\n return result\n .map((statement) =>\n statement.space === 'type' ? { ...statement, names: statement.names.filter((item) => !values.has(bound({ path: statement.path, item }))) } : statement,\n )\n .filter((statement) => statement.names.length > 0)\n}\n\n/**\n * Deduplicates `SourceNode` objects by `name + export + space`, keeping the first of each\n * key. An unnamed source only drops when the same node appears twice, so markdown can repeat a\n * paragraph or a table. Returns the deduplicated array in original order.\n */\nexport function combineSources(sources: Array<SourceNode>): Array<SourceNode> {\n const seen = new Set<SourceNode | string>()\n return sources.filter((source) => {\n const key = source.name != null ? `${source.name}:${isExported(source)}:${getSpace(source)}` : source\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n}\n\n/**\n * Deduplicates and merges `ExportNode` objects: one export per path, form and space. Returns a sorted array.\n */\nexport function combineExports(exports: Array<ExportNode>): Array<ExportNode> {\n // Built through `createExport`, so a later `{ ...exp, names }` keeps the new names.\n return mergeStatements(toStatements(exports, exportForm)).map(({ path, names }) => createExport({ path, names }))\n}\n\n/**\n * Deduplicates and merges `ImportNode` objects, filtering out unused imports.\n *\n * Retains imports that are referenced in `source` or re-exported. One import per path, form and space. Returns\n * a sorted, deduplicated, filtered array.\n */\nexport function combineImports(imports: Array<ImportNode>, exports: Array<ExportNode>, source?: string): Array<ImportNode> {\n // Build a lookup of all exported names to retain imports that are re-exported\n const exportedNames = new Set(exports.flatMap((node) => getNames(node).map((item) => item.alias ?? item.name)))\n // `createFile` re-runs on every merge into a file, so scanning the source once per import name\n // costs a heavily merged file that scan again for every fragment it already holds. Indexing pays\n // for itself there, and costs more than it saves on the small files the default output produces.\n const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? new Set(source.match(IDENTIFIER_RUN)) : null\n\n // A name in the index is used. One that is not still might be, inside a longer identifier, so the\n // substring test stays behind it.\n const isUsed = (importName: string): boolean => !source || identifiers?.has(importName) || source.includes(importName) || exportedNames.has(importName)\n\n const statements = toStatements(\n imports.filter((node) => node.path !== node.root),\n importForm,\n )\n\n // Paths that keep at least one used named import. A default import from such a path is retained\n // even when its binding can't be found in `source` e.g. a generated `client` default import\n // alongside `import type { Client } from <same path>`, where merged grouped output omits the body.\n const pathsWithUsedNamedImport = new Set(\n statements.filter(({ form, names }) => form === 'named' && names.some((item) => isUsed(item.alias ?? item.name))).map(({ path }) => path),\n )\n const keep = (item: ModuleName, { form, path }: Statement) => isUsed(item.alias ?? item.name) || (form !== 'named' && pathsWithUsedNamedImport.has(path))\n\n return mergeStatements(statements, keep).map(({ path, root, names }) => createImport({ path, ...(root != null ? { root } : {}), names }))\n}\n"],"mappings":";;;;;;;;;;;;;;AAMA,SAAgB,SAAS,MAAkD;CACzE,IAAI,KAAK,OAAO,OAAO,KAAK;CAC5B,OAAO,KAAK,SAAS,WAAW,qBAAqB,IAAI,IAAI,qBAAqB,IAAI;AACxF;;;;AAKA,SAAgB,WAAW,QAA8E;CACvG,OAAO,CAAC,EAAE,OAAO,UAAU,OAAO,eAAe,OAAO;AAC1D;AAEA,SAAgB,SAAS,QAA2B;CAClD,IAAI,OAAO,OAAO,OAAO,OAAO;CAChC,IAAI,OAAO,cAAc,MAAM,OAAO,OAAO,aAAa,SAAS;CACnE,OAAO,OAAO,QAAQ,EAAE,EAAE,SAAS,SAAS,SAAS;AACvD;;;;AAQA,SAAS,qBAAqB,EAAE,MAAM,YAAY,eAAoD;CACpG,MAAM,QAAe,aAAa,SAAS;CAC3C,IAAI,CAAC,MAAM,QAAQ,IAAI,GAAG,OAAO,CAAC;EAAE,MAAM,cAAc,MAAM;EAAW,OAAO;EAAM;CAAM,CAAC;CAC7F,OAAO,KAAK,KAAK,SAAU,OAAO,SAAS,WAAW;EAAE,MAAM;EAAM;CAAM,IAAI;EAAE,MAAM,KAAK;EAAc,GAAI,KAAK,OAAO,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC;EAAI;CAAM,CAAE;AAC/J;;;;AAKA,SAAS,qBAAqB,EAAE,MAAM,YAAY,WAAgD;CAChG,MAAM,QAAe,aAAa,SAAS;CAC3C,IAAI,QAAQ,MAAM,OAAO,CAAC;EAAE,MAAM;EAAK;CAAM,CAAC;CAC9C,IAAI,CAAC,MAAM,QAAQ,IAAI,GAAG,OAAO,CAAC,UAAU;EAAE,MAAM;EAAK,OAAO;EAAM;CAAM,IAAI;EAAE;EAAM;CAAM,CAAC;CAC/F,OAAO,KAAK,KAAK,UAAU;EAAE,MAAM;EAAM;CA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B,EAAE,MAAM,WAAsB,OAAO,KAAK,SAAS,KAAK,IAAI,KAAM,SAAS,WAAW,yBAAyB,IAAI,IAAI;CAEvJ,OAAO,gBAAgB,YAAY,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,MAAM,YAAY,aAAa;EAAE;EAAM,GAAI,QAAQ,OAAO,EAAE,KAAK,IAAI,CAAC;EAAI;CAAM,CAAC,CAAC;AAC1I"}
package/dist/factory.cjs CHANGED
@@ -1,15 +1,15 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_schema = require("./schema-0YJZqRXb.cjs");
3
- const require_file = require("./file-D73XubVb.cjs");
4
- const require_nodes = require("./nodes-BdZfapPI.cjs");
3
+ const require_combineFileMembers = require("./combineFileMembers-DmmuOmY8.cjs");
4
+ const require_nodes = require("./nodes-TtDfZ9qf.cjs");
5
5
  exports.createArrowFunction = require_nodes.createArrowFunction;
6
6
  exports.createBreak = require_nodes.createBreak;
7
7
  exports.createConst = require_nodes.createConst;
8
8
  exports.createContent = require_nodes.createContent;
9
- exports.createExport = require_file.createExport;
10
- exports.createFile = require_file.createFile;
9
+ exports.createExport = require_combineFileMembers.createExport;
10
+ exports.createFile = require_combineFileMembers.createFile;
11
11
  exports.createFunction = require_nodes.createFunction;
12
- exports.createImport = require_file.createImport;
12
+ exports.createImport = require_combineFileMembers.createImport;
13
13
  exports.createInput = require_nodes.createInput;
14
14
  exports.createJsx = require_nodes.createJsx;
15
15
  exports.createOperation = require_nodes.createOperation;
@@ -19,6 +19,6 @@ exports.createProperty = require_nodes.createProperty;
19
19
  exports.createRequestBody = require_nodes.createRequestBody;
20
20
  exports.createResponse = require_nodes.createResponse;
21
21
  exports.createSchema = require_schema.createSchema;
22
- exports.createSource = require_file.createSource;
22
+ exports.createSource = require_combineFileMembers.createSource;
23
23
  exports.createText = require_nodes.createText;
24
24
  exports.createType = require_nodes.createType;
@@ -1,4 +1,4 @@
1
- import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as createFile, f as createImport, i as ImportInput, k as createType, l as UserFileNode, o as ModuleName, p as createSource, t as ExportInput, u as createExport, w as createBreak } from "./file-CMHRNuMX.cjs";
1
+ import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as createFile, f as createImport, i as ImportInput, k as createType, l as UserFileNode, o as ModuleName, p as createSource, t as ExportInput, u as createExport, w as createBreak } from "./file-DJqd2j3y.cjs";
2
2
  import { Q as createSchema, _ as createParameter, d as createResponse, et as createProperty, j as createInput, o as createOperation, p as createRequestBody, s as createOperations, x as createContent } from "./operation-De4lbIZS.cjs";
3
- import { t as Node } from "./index-DNZgWmNq.cjs";
3
+ import { t as Node } from "./index-BjmAaymt.cjs";
4
4
  export { type ExportInput, type ImportInput, type ModuleName, Node, type Space, type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOperations, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
package/dist/factory.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as createFile, f as createImport, i as ImportInput, k as createType, l as UserFileNode, o as ModuleName, p as createSource, t as ExportInput, u as createExport, w as createBreak } from "./file-D67ITWja.js";
1
+ import { C as createArrowFunction, D as createJsx, E as createFunction, O as createText, T as createConst, c as Space, d as createFile, f as createImport, i as ImportInput, k as createType, l as UserFileNode, o as ModuleName, p as createSource, t as ExportInput, u as createExport, w as createBreak } from "./file-Dg70hXm3.js";
2
2
  import { Q as createSchema, _ as createParameter, d as createResponse, et as createProperty, j as createInput, o as createOperation, p as createRequestBody, s as createOperations, x as createContent } from "./operation-Dd0-l2VB.js";
3
- import { t as Node } from "./index-CGmrJThc.js";
3
+ import { t as Node } from "./index-Bz33tfQo.js";
4
4
  export { type ExportInput, type ImportInput, type ModuleName, Node, type Space, type UserFileNode, createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOperations, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
package/dist/factory.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { t as createSchema } from "./schema-CC008xgK.js";
2
- import { i as createSource, n as createFile, r as createImport, t as createExport } from "./file-3gsgXreK.js";
3
- import { a as createOperation, c as createInput, d as createBreak, f as createConst, g as createType, h as createText, i as createParameter, l as createContent, m as createJsx, n as createResponse, o as createOperations, p as createFunction, r as createProperty, s as createRequestBody, u as createArrowFunction } from "./nodes-D9nwroV5.js";
2
+ import { a as createSource, i as createImport, n as createExport, r as createFile } from "./combineFileMembers-DJHNAZBN.js";
3
+ import { a as createOperation, c as createInput, d as createBreak, f as createConst, g as createType, h as createText, i as createParameter, l as createContent, m as createJsx, n as createResponse, o as createOperations, p as createFunction, r as createProperty, s as createRequestBody, u as createArrowFunction } from "./nodes-u9i-tqFp.js";
4
4
  export { createArrowFunction, createBreak, createConst, createContent, createExport, createFile, createFunction, createImport, createInput, createJsx, createOperation, createOperations, createParameter, createProperty, createRequestBody, createResponse, createSchema, createSource, createText, createType };
@@ -605,6 +605,7 @@ type ExportInput = Omit<ExportNode, 'kind'>;
605
605
  /**
606
606
  * Creates an `ImportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
607
607
  * `isTypeOnly` that differs from the one `names` gives overrides it, so `{ ...imp, isTypeOnly: true }` still works.
608
+ * Fields a spread copies over unchanged are not overrides, so `{ ...imp, names }` uses the new `names`.
608
609
  *
609
610
  * @example Named import
610
611
  * ```ts
@@ -615,7 +616,8 @@ type ExportInput = Omit<ExportNode, 'kind'>;
615
616
  declare function createImport(input: ImportInput): ImportNode;
616
617
  /**
617
618
  * Creates an `ExportNode`. A node built from `names` also gets the deprecated fields. A deprecated `name` or
618
- * `isTypeOnly` that differs from the one `names` gives overrides it.
619
+ * `isTypeOnly` that differs from the one `names` gives overrides it. Fields a spread copies over unchanged are not
620
+ * overrides, so `{ ...exp, names }` uses the new `names`.
619
621
  *
620
622
  * @example Named export
621
623
  * ```ts