@kubb/core 5.18.8 → 5.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -45,7 +45,65 @@ let node_readline = require("node:readline");
45
45
  let node_url = require("node:url");
46
46
  let node_module = require("node:module");
47
47
  // package.json
48
- var version = "5.18.8";
48
+ var version = "5.19.1";
49
+ // ../../internals/utils/src/promise.ts
50
+ /**
51
+ * Returns the value cached under `key` in `store`, computing and storing it on the first call.
52
+ * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
53
+ * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
54
+ *
55
+ * @example
56
+ * `const refs = memo(refCache, node, () => collectRefs(node))`
57
+ */
58
+ function memo$1(store, key, compute) {
59
+ const cached = store.get(key);
60
+ if (cached !== void 0 || store.has(key)) return cached;
61
+ const value = compute();
62
+ store.set(key, value);
63
+ return value;
64
+ }
65
+ __name(memo$1, "memo");
66
+ function createStore({ weak, max } = {}) {
67
+ if (weak) return /* @__PURE__ */ new WeakMap();
68
+ const entry = /* @__PURE__ */ new Map();
69
+ if (max === void 0) return entry;
70
+ const set = (key, value) => {
71
+ if (entry.size >= max) entry.clear();
72
+ entry.set(key, value);
73
+ };
74
+ if (max !== 1) return {
75
+ has: (key) => entry.has(key),
76
+ get: (key) => entry.get(key),
77
+ set
78
+ };
79
+ const touch = (key) => {
80
+ if (!entry.has(key)) return false;
81
+ set(key, entry.get(key));
82
+ return true;
83
+ };
84
+ return {
85
+ has: touch,
86
+ get: (key) => touch(key) ? entry.get(key) : void 0,
87
+ set
88
+ };
89
+ }
90
+ memo$1.create = createStore;
91
+ /**
92
+ * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
93
+ * takes the next item the moment it frees up instead of waiting for a batch to drain.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
98
+ * ```
99
+ */
100
+ async function inParallel({ items, limit, run }) {
101
+ const queue = items.entries();
102
+ const worker = async () => {
103
+ for (const [index, item] of queue) await run(item, index);
104
+ };
105
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
106
+ }
49
107
  // ../../internals/utils/src/casing.ts
50
108
  /**
51
109
  * Shared implementation for camelCase and PascalCase conversion.
@@ -60,16 +118,10 @@ function convert(text, pascal) {
60
118
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
61
119
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
62
120
  }
63
- const cache = /* @__PURE__ */ new Map();
64
- const cacheLimit = 1e5;
121
+ const cache = memo$1.create({ max: 1e5 });
65
122
  function toCamelOrPascal(text, pascal) {
66
123
  const key = `${pascal ? "P" : "c"}${text}`;
67
- const cached = cache.get(key);
68
- if (cached !== void 0) return cached;
69
- const result = convert(text, pascal);
70
- if (cache.size >= cacheLimit) cache.clear();
71
- cache.set(key, result);
72
- return result;
124
+ return memo$1(cache, key, () => convert(text, pascal));
73
125
  }
74
126
  /**
75
127
  * Converts `text` to camelCase.
@@ -366,59 +418,6 @@ function isPathInside(path, parent) {
366
418
  const rel = (0, node_path.relative)(resolvedParent, resolvedPath);
367
419
  return rel !== "" && !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel);
368
420
  }
369
- // ../../internals/utils/src/promise.ts
370
- /**
371
- * Returns the value cached under `key` in `store`, computing and storing it on the first call.
372
- * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
373
- * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
374
- *
375
- * @example
376
- * `const refs = memo(refCache, node, () => collectRefs(node))`
377
- */
378
- function memo$1(store, key, compute) {
379
- const cached = store.get(key);
380
- if (cached !== void 0 || store.has(key)) return cached;
381
- const value = compute();
382
- store.set(key, value);
383
- return value;
384
- }
385
- __name(memo$1, "memo");
386
- function createStore({ type }) {
387
- if (type === "weak") return /* @__PURE__ */ new WeakMap();
388
- const entry = /* @__PURE__ */ new Map();
389
- if (type === "map") return entry;
390
- const set = (key, value) => {
391
- entry.clear();
392
- entry.set(key, value);
393
- };
394
- const touch = (key) => {
395
- if (!entry.has(key)) return false;
396
- set(key, entry.get(key));
397
- return true;
398
- };
399
- return {
400
- has: touch,
401
- get: (key) => touch(key) ? entry.get(key) : void 0,
402
- set
403
- };
404
- }
405
- memo$1.create = createStore;
406
- /**
407
- * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
408
- * takes the next item the moment it frees up instead of waiting for a batch to drain.
409
- *
410
- * @example
411
- * ```ts
412
- * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
413
- * ```
414
- */
415
- async function inParallel({ items, limit, run }) {
416
- const queue = items.entries();
417
- const worker = async () => {
418
- for (const [index, item] of queue) await run(item, index);
419
- };
420
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
421
- }
422
421
  // ../../internals/utils/src/tools.ts
423
422
  /**
424
423
  * CLI command descriptors for each supported code formatter.
@@ -1418,8 +1417,20 @@ function injectFile(file) {
1418
1417
  }
1419
1418
  /**
1420
1419
  * Returns a value computed once per build and shared by every plugin, like `ctx.memo`.
1420
+ *
1421
+ * Pass a store first to cache in it instead, with no build needed: a `Map` or `WeakMap`, or one
1422
+ * from `memo.create`.
1423
+ *
1424
+ * @example Once per build
1425
+ * `const names = memo('myPlugin:names', () => collectNames(schemas))`
1426
+ *
1427
+ * @example In your own store
1428
+ * ```ts
1429
+ * const cache = memo.create<ast.SchemaNode, Array<string>>({ weak: true })
1430
+ * const refs = memo(cache, node, () => collectRefs(node))
1431
+ * ```
1421
1432
  */
1422
- const memo = (key, compute) => requireContext("memo").memo(key, compute);
1433
+ const memo = Object.assign((...args) => args.length === 3 ? memo$1(...args) : requireContext("memo").memo(...args), { create: memo$1.create });
1423
1434
  /**
1424
1435
  * Returns the options the user passed to the plugin being set up, like `ctx.options`.
1425
1436
  */
@@ -1623,7 +1634,7 @@ function gitAuthEnv(env, { repo, authorization }) {
1623
1634
  /**
1624
1635
  * Fetches one commit of a git repository into a temporary directory with a shallow `git fetch`,
1625
1636
  * so any host and the user's own git credentials work, and relative `$ref` files resolve.
1626
- * Resolves to the spec path on disk and a `dispose` that deletes the checkout.
1637
+ * Resolves to the spec path on disk, the checkout `dir`, and a `dispose` that deletes the checkout.
1627
1638
  *
1628
1639
  * With `publicOnly`, the repository must be an https URL on public addresses, the fetch connects to
1629
1640
  * the addresses checked, and it does not follow a redirect. `authorization` adds that header to this
@@ -1698,6 +1709,7 @@ async function checkoutGitInput(input, signal, { publicOnly = false, authorizati
1698
1709
  }
1699
1710
  return {
1700
1711
  path: specPath,
1712
+ dir,
1701
1713
  dispose
1702
1714
  };
1703
1715
  }
@@ -1780,9 +1792,9 @@ function inputToAdapterSource(config) {
1780
1792
  };
1781
1793
  }
1782
1794
  // src/resolveOptions.ts
1783
- const patterns = /* @__PURE__ */ new Map();
1784
- const methodPatterns = /* @__PURE__ */ new Map();
1785
- const nodeCaches = /* @__PURE__ */ new WeakMap();
1795
+ const patterns = memo$1.create();
1796
+ const methodPatterns = memo$1.create();
1797
+ const nodeCaches = memo$1.create({ weak: true });
1786
1798
  function testPattern(value, pattern) {
1787
1799
  if (typeof pattern === "string") return memo$1(patterns, pattern, () => new RegExp(pattern)).test(value);
1788
1800
  return value.match(pattern) !== null;
@@ -1913,12 +1925,12 @@ var Resolver = class Resolver {
1913
1925
  /** The built-in machinery, untouched by `name`/`file` overrides and built once since the driver reads it per node. */
1914
1926
  default;
1915
1927
  #options;
1916
- #memo = /* @__PURE__ */ new Map();
1928
+ #memo = memo$1.create();
1917
1929
  #usedNames = /* @__PURE__ */ new Set();
1918
- #stringNames = /* @__PURE__ */ new Map();
1930
+ #stringNames = memo$1.create();
1919
1931
  #arrayNames = createNameNode();
1920
- #outputDirs = /* @__PURE__ */ new WeakMap();
1921
- #importPaths = /* @__PURE__ */ new WeakMap();
1932
+ #outputDirs = memo$1.create({ weak: true });
1933
+ #importPaths = memo$1.create({ weak: true });
1922
1934
  #tagParents = /* @__PURE__ */ new Map();
1923
1935
  #baseName;
1924
1936
  #filePath;
@@ -2725,7 +2737,7 @@ var KubbDriver = class {
2725
2737
  */
2726
2738
  fileManager = new FileManager();
2727
2739
  plugins = /* @__PURE__ */ new Map();
2728
- #memo = /* @__PURE__ */ new Map();
2740
+ #memo = memo$1.create();
2729
2741
  /**
2730
2742
  * Removers for every listener the driver added (plugin, generator) so `dispose()` can detach
2731
2743
  * them in one pass. External `hooks.hook(...)` listeners are not tracked.
@@ -2829,7 +2841,10 @@ var KubbDriver = class {
2829
2841
  this.inputNode = await this.adapter.parse(checkout ? {
2830
2842
  type: "path",
2831
2843
  path: checkout.path
2832
- } : source, { signal: this.options.signal });
2844
+ } : source, {
2845
+ signal: this.options.signal,
2846
+ fileRefs: checkout && this.options.fileRefs ? [...this.options.fileRefs, checkout.dir] : this.options.fileRefs
2847
+ });
2833
2848
  } catch (caughtError) {
2834
2849
  throw new Diagnostics.Error(Diagnostics.fromExtension(caughtError, {
2835
2850
  kind: "adapter",
@@ -3567,7 +3582,7 @@ const cacheStorage = createStorage(({ root = process.cwd() }) => {
3567
3582
  * ```
3568
3583
  */
3569
3584
  var Hookable = class {
3570
- #listeners = /* @__PURE__ */ new Map();
3585
+ #listeners = memo$1.create();
3571
3586
  /**
3572
3587
  * Calls `hookName` and awaits all registered listeners sequentially.
3573
3588
  * Throws if any listener rejects, wrapping the cause in an error that names the hook.
@@ -3599,9 +3614,7 @@ var Hookable = class {
3599
3614
  * ```
3600
3615
  */
3601
3616
  hook(hookName, handler) {
3602
- let listeners = this.#listeners.get(hookName);
3603
- if (!listeners) this.#listeners.set(hookName, listeners = /* @__PURE__ */ new Set());
3604
- listeners.add(handler);
3617
+ memo$1(this.#listeners, hookName, () => /* @__PURE__ */ new Set()).add(handler);
3605
3618
  return () => this.removeHook(hookName, handler);
3606
3619
  }
3607
3620
  /**
@@ -3900,10 +3913,12 @@ var Kubb = class Kubb {
3900
3913
  #driver = null;
3901
3914
  #manifest = null;
3902
3915
  #signal;
3916
+ #fileRefs;
3903
3917
  constructor(userConfig, options = {}) {
3904
3918
  this.config = resolveConfig(userConfig);
3905
3919
  this.hooks = options.hooks ?? new Hookable();
3906
3920
  this.#signal = options.signal;
3921
+ this.#fileRefs = options.fileRefs;
3907
3922
  }
3908
3923
  /**
3909
3924
  * Generates every config of a `defineConfig([...])` array in order and yields each result as its config finishes, so
@@ -3967,7 +3982,8 @@ var Kubb = class Kubb {
3967
3982
  hooks: this.hooks,
3968
3983
  manifest,
3969
3984
  signal,
3970
- cleanPath
3985
+ cleanPath,
3986
+ fileRefs: this.#fileRefs
3971
3987
  });
3972
3988
  await driver.setup();
3973
3989
  this.#driver = driver;