@kubb/studio 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
@@ -50,6 +50,63 @@ node_net = __toESM(node_net, 1);
50
50
  let node_stream = require("node:stream");
51
51
  let ofetch = require("ofetch");
52
52
  let node_zlib = require("node:zlib");
53
+ // ../../internals/utils/src/promise.ts
54
+ /**
55
+ * Returns the value cached under `key` in `store`, computing and storing it on the first call.
56
+ * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
57
+ * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
58
+ *
59
+ * @example
60
+ * `const refs = memo(refCache, node, () => collectRefs(node))`
61
+ */
62
+ function memo(store, key, compute) {
63
+ const cached = store.get(key);
64
+ if (cached !== void 0 || store.has(key)) return cached;
65
+ const value = compute();
66
+ store.set(key, value);
67
+ return value;
68
+ }
69
+ function createStore({ weak, max } = {}) {
70
+ if (weak) return /* @__PURE__ */ new WeakMap();
71
+ const entry = /* @__PURE__ */ new Map();
72
+ if (max === void 0) return entry;
73
+ const set = (key, value) => {
74
+ if (entry.size >= max) entry.clear();
75
+ entry.set(key, value);
76
+ };
77
+ if (max !== 1) return {
78
+ has: (key) => entry.has(key),
79
+ get: (key) => entry.get(key),
80
+ set
81
+ };
82
+ const touch = (key) => {
83
+ if (!entry.has(key)) return false;
84
+ set(key, entry.get(key));
85
+ return true;
86
+ };
87
+ return {
88
+ has: touch,
89
+ get: (key) => touch(key) ? entry.get(key) : void 0,
90
+ set
91
+ };
92
+ }
93
+ memo.create = createStore;
94
+ /**
95
+ * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
96
+ * takes the next item the moment it frees up instead of waiting for a batch to drain.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
101
+ * ```
102
+ */
103
+ async function inParallel({ items, limit, run }) {
104
+ const queue = items.entries();
105
+ const worker = async () => {
106
+ for (const [index, item] of queue) await run(item, index);
107
+ };
108
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
109
+ }
53
110
  // ../../internals/utils/src/casing.ts
54
111
  /**
55
112
  * Shared implementation for camelCase and PascalCase conversion.
@@ -64,16 +121,10 @@ function convert(text, pascal) {
64
121
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
65
122
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
66
123
  }
67
- const cache = /* @__PURE__ */ new Map();
68
- const cacheLimit = 1e5;
124
+ const cache = memo.create({ max: 1e5 });
69
125
  function toCamelOrPascal(text, pascal) {
70
126
  const key = `${pascal ? "P" : "c"}${text}`;
71
- const cached = cache.get(key);
72
- if (cached !== void 0) return cached;
73
- const result = convert(text, pascal);
74
- if (cache.size >= cacheLimit) cache.clear();
75
- cache.set(key, result);
76
- return result;
127
+ return memo(cache, key, () => convert(text, pascal));
77
128
  }
78
129
  /**
79
130
  * Converts `text` to camelCase.
@@ -199,60 +250,8 @@ function isPathInside(path, parent) {
199
250
  const rel = (0, node_path.relative)(resolvedParent, resolvedPath);
200
251
  return rel !== "" && !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel);
201
252
  }
202
- // ../../internals/utils/src/promise.ts
203
- /**
204
- * Returns the value cached under `key` in `store`, computing and storing it on the first call.
205
- * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
206
- * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
207
- *
208
- * @example
209
- * `const refs = memo(refCache, node, () => collectRefs(node))`
210
- */
211
- function memo(store, key, compute) {
212
- const cached = store.get(key);
213
- if (cached !== void 0 || store.has(key)) return cached;
214
- const value = compute();
215
- store.set(key, value);
216
- return value;
217
- }
218
- function createStore({ type }) {
219
- if (type === "weak") return /* @__PURE__ */ new WeakMap();
220
- const entry = /* @__PURE__ */ new Map();
221
- if (type === "map") return entry;
222
- const set = (key, value) => {
223
- entry.clear();
224
- entry.set(key, value);
225
- };
226
- const touch = (key) => {
227
- if (!entry.has(key)) return false;
228
- set(key, entry.get(key));
229
- return true;
230
- };
231
- return {
232
- has: touch,
233
- get: (key) => touch(key) ? entry.get(key) : void 0,
234
- set
235
- };
236
- }
237
- memo.create = createStore;
238
- /**
239
- * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
240
- * takes the next item the moment it frees up instead of waiting for a batch to drain.
241
- *
242
- * @example
243
- * ```ts
244
- * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
245
- * ```
246
- */
247
- async function inParallel({ items, limit, run }) {
248
- const queue = items.entries();
249
- const worker = async () => {
250
- for (const [index, item] of queue) await run(item, index);
251
- };
252
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
253
- }
254
253
  // package.json
255
- var version = "5.18.8";
254
+ var version = "5.19.0";
256
255
  // ../../internals/shared/src/constants.ts
257
256
  /**
258
257
  * Extensions `kubb` ships at its own version, so they count as installed without being a direct
@@ -992,14 +991,14 @@ function addPlugin({ source, parsed, config, edit, quote, extensions }) {
992
991
  if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` };
993
992
  const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : [];
994
993
  const imports = getImports(parsed.program);
995
- const missing = /* @__PURE__ */ new Map();
994
+ const missing = memo.create();
996
995
  for (const item of [...defaults, {
997
996
  importName,
998
997
  packageName: edit.plugin
999
998
  }]) {
1000
999
  const from = imports.get(item.importName)?.from;
1001
1000
  if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` };
1002
- if (!from) missing.set(item.packageName, [...missing.get(item.packageName) ?? [], item.importName]);
1001
+ if (!from) memo(missing, item.packageName, () => []).push(item.importName);
1003
1002
  }
1004
1003
  const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ""})`;
1005
1004
  const next = array?.type === nodeTypes.arrayExpression ? appendItem(source, array, call) : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(", ")}]`);