@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.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { a as AgentPermission, c as MAX_SNAPSHOT_BYTES, d as extensionKinds, i as AgentMessage, l as generationEventTypes, n as AGENT_SOCKET_PATH, r as AgentCloseCode, t as AGENT_INSTANCE_HEADER, u as ConfigEditOperation } from "./protocol-B6oWLc7W.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { createHash, hash, randomUUID } from "node:crypto";
4
- import { existsSync } from "node:fs";
5
- import { mkdir, mkdir as mkdir$1, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
4
+ import { existsSync, readFile, writeFile } from "node:fs";
5
+ import { mkdir, mkdir as mkdir$1, mkdtemp, rm, writeFile as writeFile$1 } from "node:fs/promises";
6
6
  import { tmpdir } from "node:os";
7
7
  import path, { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
8
8
  import process$1 from "node:process";
@@ -22,6 +22,63 @@ import net from "node:net";
22
22
  import { Readable, Transform } from "node:stream";
23
23
  import { ofetch } from "ofetch";
24
24
  import { gzipSync } from "node:zlib";
25
+ // ../../internals/utils/src/promise.ts
26
+ /**
27
+ * Returns the value cached under `key` in `store`, computing and storing it on the first call.
28
+ * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
29
+ * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
30
+ *
31
+ * @example
32
+ * `const refs = memo(refCache, node, () => collectRefs(node))`
33
+ */
34
+ function memo(store, key, compute) {
35
+ const cached = store.get(key);
36
+ if (cached !== void 0 || store.has(key)) return cached;
37
+ const value = compute();
38
+ store.set(key, value);
39
+ return value;
40
+ }
41
+ function createStore({ weak, max } = {}) {
42
+ if (weak) return /* @__PURE__ */ new WeakMap();
43
+ const entry = /* @__PURE__ */ new Map();
44
+ if (max === void 0) return entry;
45
+ const set = (key, value) => {
46
+ if (entry.size >= max) entry.clear();
47
+ entry.set(key, value);
48
+ };
49
+ if (max !== 1) return {
50
+ has: (key) => entry.has(key),
51
+ get: (key) => entry.get(key),
52
+ set
53
+ };
54
+ const touch = (key) => {
55
+ if (!entry.has(key)) return false;
56
+ set(key, entry.get(key));
57
+ return true;
58
+ };
59
+ return {
60
+ has: touch,
61
+ get: (key) => touch(key) ? entry.get(key) : void 0,
62
+ set
63
+ };
64
+ }
65
+ memo.create = createStore;
66
+ /**
67
+ * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
68
+ * takes the next item the moment it frees up instead of waiting for a batch to drain.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
73
+ * ```
74
+ */
75
+ async function inParallel({ items, limit, run }) {
76
+ const queue = items.entries();
77
+ const worker = async () => {
78
+ for (const [index, item] of queue) await run(item, index);
79
+ };
80
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
81
+ }
25
82
  // ../../internals/utils/src/casing.ts
26
83
  /**
27
84
  * Shared implementation for camelCase and PascalCase conversion.
@@ -36,16 +93,10 @@ function convert(text, pascal) {
36
93
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
37
94
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
38
95
  }
39
- const cache = /* @__PURE__ */ new Map();
40
- const cacheLimit = 1e5;
96
+ const cache = memo.create({ max: 1e5 });
41
97
  function toCamelOrPascal(text, pascal) {
42
98
  const key = `${pascal ? "P" : "c"}${text}`;
43
- const cached = cache.get(key);
44
- if (cached !== void 0) return cached;
45
- const result = convert(text, pascal);
46
- if (cache.size >= cacheLimit) cache.clear();
47
- cache.set(key, result);
48
- return result;
99
+ return memo(cache, key, () => convert(text, pascal));
49
100
  }
50
101
  /**
51
102
  * Converts `text` to camelCase.
@@ -127,7 +178,7 @@ function detect() {
127
178
  */
128
179
  async function read(path) {
129
180
  if (runtime.isBun) return Bun.file(path).text();
130
- return readFile(path, { encoding: "utf8" });
181
+ return new Promise((resolvePromise, reject) => readFile(path, { encoding: "utf8" }, (error, data) => error ? reject(error) : resolvePromise(data)));
131
182
  }
132
183
  /**
133
184
  * Writes UTF-8 content verbatim, including empty files and surrounding whitespace.
@@ -143,11 +194,11 @@ async function writeRaw(path, content) {
143
194
  return;
144
195
  }
145
196
  try {
146
- await writeFile(resolved, content, { encoding: "utf-8" });
197
+ await new Promise((resolvePromise, reject) => writeFile(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
147
198
  } catch (error) {
148
199
  if (error.code !== "ENOENT") throw error;
149
200
  await mkdir$1(dirname(resolved), { recursive: true });
150
- await writeFile(resolved, content, { encoding: "utf-8" });
201
+ await new Promise((resolvePromise, reject) => writeFile(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
151
202
  }
152
203
  }
153
204
  /**
@@ -171,25 +222,8 @@ function isPathInside(path, parent) {
171
222
  const rel = relative(resolvedParent, resolvedPath);
172
223
  return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
173
224
  }
174
- // ../../internals/utils/src/promise.ts
175
- /**
176
- * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
177
- * takes the next item the moment it frees up instead of waiting for a batch to drain.
178
- *
179
- * @example
180
- * ```ts
181
- * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
182
- * ```
183
- */
184
- async function inParallel({ items, limit, run }) {
185
- const queue = items.entries();
186
- const worker = async () => {
187
- for (const [index, item] of queue) await run(item, index);
188
- };
189
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
190
- }
191
225
  // package.json
192
- var version = "5.18.7";
226
+ var version = "5.19.0";
193
227
  // ../../internals/shared/src/constants.ts
194
228
  /**
195
229
  * Extensions `kubb` ships at its own version, so they count as installed without being a direct
@@ -929,14 +963,14 @@ function addPlugin({ source, parsed, config, edit, quote, extensions }) {
929
963
  if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` };
930
964
  const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : [];
931
965
  const imports = getImports(parsed.program);
932
- const missing = /* @__PURE__ */ new Map();
966
+ const missing = memo.create();
933
967
  for (const item of [...defaults, {
934
968
  importName,
935
969
  packageName: edit.plugin
936
970
  }]) {
937
971
  const from = imports.get(item.importName)?.from;
938
972
  if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` };
939
- if (!from) missing.set(item.packageName, [...missing.get(item.packageName) ?? [], item.importName]);
973
+ if (!from) memo(missing, item.packageName, () => []).push(item.importName);
940
974
  }
941
975
  const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ""})`;
942
976
  const next = array?.type === nodeTypes.arrayExpression ? appendItem(source, array, call) : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(", ")}]`);
@@ -2627,7 +2661,7 @@ var Agent = class extends RpcTarget {
2627
2661
  let wroteDocument = false;
2628
2662
  for (const [index, edit] of kept.entries()) {
2629
2663
  if (!("document" in edit) || !edit.document || !outcomes[index].applied) continue;
2630
- await writeFile(path.join(this.#options.root, edit.document.fileName), edit.document.text, "utf-8");
2664
+ await writeFile$1(path.join(this.#options.root, edit.document.fileName), edit.document.text, "utf-8");
2631
2665
  wroteDocument = true;
2632
2666
  }
2633
2667
  const changed = written.changed || wroteDocument;