@kubb/studio 5.18.7 → 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.
@@ -155,7 +206,7 @@ function detect() {
155
206
  */
156
207
  async function read(path) {
157
208
  if (runtime.isBun) return Bun.file(path).text();
158
- return (0, node_fs_promises.readFile)(path, { encoding: "utf8" });
209
+ return new Promise((resolvePromise, reject) => (0, node_fs.readFile)(path, { encoding: "utf8" }, (error, data) => error ? reject(error) : resolvePromise(data)));
159
210
  }
160
211
  /**
161
212
  * Writes UTF-8 content verbatim, including empty files and surrounding whitespace.
@@ -171,11 +222,11 @@ async function writeRaw(path, content) {
171
222
  return;
172
223
  }
173
224
  try {
174
- await (0, node_fs_promises.writeFile)(resolved, content, { encoding: "utf-8" });
225
+ await new Promise((resolvePromise, reject) => (0, node_fs.writeFile)(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
175
226
  } catch (error) {
176
227
  if (error.code !== "ENOENT") throw error;
177
228
  await (0, node_fs_promises.mkdir)((0, node_path.dirname)(resolved), { recursive: true });
178
- await (0, node_fs_promises.writeFile)(resolved, content, { encoding: "utf-8" });
229
+ await new Promise((resolvePromise, reject) => (0, node_fs.writeFile)(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
179
230
  }
180
231
  }
181
232
  /**
@@ -199,25 +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
- * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
205
- * takes the next item the moment it frees up instead of waiting for a batch to drain.
206
- *
207
- * @example
208
- * ```ts
209
- * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
210
- * ```
211
- */
212
- async function inParallel({ items, limit, run }) {
213
- const queue = items.entries();
214
- const worker = async () => {
215
- for (const [index, item] of queue) await run(item, index);
216
- };
217
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
218
- }
219
253
  // package.json
220
- var version = "5.18.7";
254
+ var version = "5.19.0";
221
255
  // ../../internals/shared/src/constants.ts
222
256
  /**
223
257
  * Extensions `kubb` ships at its own version, so they count as installed without being a direct
@@ -957,14 +991,14 @@ function addPlugin({ source, parsed, config, edit, quote, extensions }) {
957
991
  if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` };
958
992
  const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : [];
959
993
  const imports = getImports(parsed.program);
960
- const missing = /* @__PURE__ */ new Map();
994
+ const missing = memo.create();
961
995
  for (const item of [...defaults, {
962
996
  importName,
963
997
  packageName: edit.plugin
964
998
  }]) {
965
999
  const from = imports.get(item.importName)?.from;
966
1000
  if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` };
967
- if (!from) missing.set(item.packageName, [...missing.get(item.packageName) ?? [], item.importName]);
1001
+ if (!from) memo(missing, item.packageName, () => []).push(item.importName);
968
1002
  }
969
1003
  const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ""})`;
970
1004
  const next = array?.type === nodeTypes.arrayExpression ? appendItem(source, array, call) : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(", ")}]`);