@kubb/core 5.18.8 → 5.19.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.
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.0";
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
  */
@@ -1780,9 +1791,9 @@ function inputToAdapterSource(config) {
1780
1791
  };
1781
1792
  }
1782
1793
  // src/resolveOptions.ts
1783
- const patterns = /* @__PURE__ */ new Map();
1784
- const methodPatterns = /* @__PURE__ */ new Map();
1785
- const nodeCaches = /* @__PURE__ */ new WeakMap();
1794
+ const patterns = memo$1.create();
1795
+ const methodPatterns = memo$1.create();
1796
+ const nodeCaches = memo$1.create({ weak: true });
1786
1797
  function testPattern(value, pattern) {
1787
1798
  if (typeof pattern === "string") return memo$1(patterns, pattern, () => new RegExp(pattern)).test(value);
1788
1799
  return value.match(pattern) !== null;
@@ -1913,12 +1924,12 @@ var Resolver = class Resolver {
1913
1924
  /** The built-in machinery, untouched by `name`/`file` overrides and built once since the driver reads it per node. */
1914
1925
  default;
1915
1926
  #options;
1916
- #memo = /* @__PURE__ */ new Map();
1927
+ #memo = memo$1.create();
1917
1928
  #usedNames = /* @__PURE__ */ new Set();
1918
- #stringNames = /* @__PURE__ */ new Map();
1929
+ #stringNames = memo$1.create();
1919
1930
  #arrayNames = createNameNode();
1920
- #outputDirs = /* @__PURE__ */ new WeakMap();
1921
- #importPaths = /* @__PURE__ */ new WeakMap();
1931
+ #outputDirs = memo$1.create({ weak: true });
1932
+ #importPaths = memo$1.create({ weak: true });
1922
1933
  #tagParents = /* @__PURE__ */ new Map();
1923
1934
  #baseName;
1924
1935
  #filePath;
@@ -2725,7 +2736,7 @@ var KubbDriver = class {
2725
2736
  */
2726
2737
  fileManager = new FileManager();
2727
2738
  plugins = /* @__PURE__ */ new Map();
2728
- #memo = /* @__PURE__ */ new Map();
2739
+ #memo = memo$1.create();
2729
2740
  /**
2730
2741
  * Removers for every listener the driver added (plugin, generator) so `dispose()` can detach
2731
2742
  * them in one pass. External `hooks.hook(...)` listeners are not tracked.
@@ -3567,7 +3578,7 @@ const cacheStorage = createStorage(({ root = process.cwd() }) => {
3567
3578
  * ```
3568
3579
  */
3569
3580
  var Hookable = class {
3570
- #listeners = /* @__PURE__ */ new Map();
3581
+ #listeners = memo$1.create();
3571
3582
  /**
3572
3583
  * Calls `hookName` and awaits all registered listeners sequentially.
3573
3584
  * Throws if any listener rejects, wrapping the cause in an error that names the hook.
@@ -3599,9 +3610,7 @@ var Hookable = class {
3599
3610
  * ```
3600
3611
  */
3601
3612
  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);
3613
+ memo$1(this.#listeners, hookName, () => /* @__PURE__ */ new Set()).add(handler);
3605
3614
  return () => this.removeHook(hookName, handler);
3606
3615
  }
3607
3616
  /**