@kubb/studio 5.14.6 → 5.15.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
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -20,8 +20,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- //#endregion
24
- const require_protocol = require("./protocol-n7fVO3_7.cjs");
23
+ const require_protocol = require("./protocol-B4wWGPon.cjs");
25
24
  let node_crypto = require("node:crypto");
26
25
  let node_fs = require("node:fs");
27
26
  let node_fs_promises = require("node:fs/promises");
@@ -51,7 +50,7 @@ node_net = __toESM(node_net, 1);
51
50
  let node_stream = require("node:stream");
52
51
  let ofetch = require("ofetch");
53
52
  let node_zlib = require("node:zlib");
54
- //#region ../../internals/utils/src/casing.ts
53
+ // ../../internals/utils/src/casing.ts
55
54
  /**
56
55
  * Shared implementation for camelCase and PascalCase conversion.
57
56
  * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
@@ -66,7 +65,7 @@ function convert(text, pascal) {
66
65
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
67
66
  }
68
67
  const cache = /* @__PURE__ */ new Map();
69
- const cacheLimit = 1e4;
68
+ const cacheLimit = 1e5;
70
69
  function toCamelOrPascal(text, pascal) {
71
70
  const key = `${pascal ? "P" : "c"}${text}`;
72
71
  const cached = cache.get(key);
@@ -88,8 +87,7 @@ function toCamelOrPascal(text, pascal) {
88
87
  function camelCase(text, { prefix = "", suffix = "" } = {}) {
89
88
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
90
89
  }
91
- //#endregion
92
- //#region ../../internals/utils/src/errors.ts
90
+ // ../../internals/utils/src/errors.ts
93
91
  /**
94
92
  * Coerces an unknown thrown value to an `Error` instance.
95
93
  * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
@@ -116,8 +114,7 @@ function toError(value) {
116
114
  function getErrorMessage(value) {
117
115
  return value instanceof Error ? value.message : String(value);
118
116
  }
119
- //#endregion
120
- //#region ../../internals/utils/src/runtime.ts
117
+ // ../../internals/utils/src/runtime.ts
121
118
  const isBun = typeof Bun !== "undefined";
122
119
  const isDeno = "Deno" in globalThis;
123
120
  /**
@@ -146,8 +143,7 @@ function detect() {
146
143
  version: process.versions?.node ?? ""
147
144
  };
148
145
  }
149
- //#endregion
150
- //#region ../../internals/utils/src/fs.ts
146
+ // ../../internals/utils/src/fs.ts
151
147
  /**
152
148
  * Reads the file at `path` as a UTF-8 string.
153
149
  * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
@@ -203,8 +199,7 @@ function isPathInside(path, parent) {
203
199
  const rel = (0, node_path.relative)(resolvedParent, resolvedPath);
204
200
  return rel !== "" && !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel);
205
201
  }
206
- //#endregion
207
- //#region ../../internals/utils/src/promise.ts
202
+ // ../../internals/utils/src/promise.ts
208
203
  /**
209
204
  * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
210
205
  * takes the next item the moment it frees up instead of waiting for a batch to drain.
@@ -221,8 +216,7 @@ async function inParallel({ items, limit, run }) {
221
216
  };
222
217
  await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
223
218
  }
224
- //#endregion
225
- //#region ../../internals/utils/src/time.ts
219
+ // ../../internals/utils/src/time.ts
226
220
  /**
227
221
  * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
228
222
  * Rounds to 2 decimal places for sub-millisecond precision without noise.
@@ -239,11 +233,9 @@ function getElapsedMs(hrStart) {
239
233
  const ms = seconds * 1e3 + nanoseconds / 1e6;
240
234
  return Math.round(ms * 100) / 100;
241
235
  }
242
- //#endregion
243
- //#region package.json
244
- var version = "5.14.6";
245
- //#endregion
246
- //#region ../../internals/shared/src/constants.ts
236
+ // package.json
237
+ var version = "5.15.1";
238
+ // ../../internals/shared/src/constants.ts
247
239
  /**
248
240
  * Extensions `kubb` ships at its own version, so they count as installed without being a direct
249
241
  * dependency. `constants.test.ts` checks it against the `kubb` package's dependencies.
@@ -254,8 +246,7 @@ const BUNDLED_PACKAGES = [
254
246
  "@kubb/parser-md",
255
247
  "@kubb/plugin-barrel"
256
248
  ];
257
- //#endregion
258
- //#region ../../internals/shared/src/configFile/ast.ts
249
+ // ../../internals/shared/src/configFile/ast.ts
259
250
  /** Node types the config editor reads from the yuku AST. */
260
251
  const nodeTypes = {
261
252
  arrayExpression: "ArrayExpression",
@@ -316,8 +307,7 @@ function parseExpression(source) {
316
307
  const [statement] = parsed.program.body;
317
308
  return parsed.program.body.length === 1 && statement?.type === nodeTypes.expressionStatement ? statement.expression : void 0;
318
309
  }
319
- //#endregion
320
- //#region ../../internals/shared/src/configFile/rules.ts
310
+ // ../../internals/shared/src/configFile/rules.ts
321
311
  /** `@kubb/plugin-ts` becomes `plugin-ts`, the `name` Kubb plugin factories use. */
322
312
  function toPluginName(packageName) {
323
313
  return packageName.split("/").pop() ?? packageName;
@@ -381,8 +371,7 @@ function isOutputValue({ key, value }) {
381
371
  function pickOutput(output) {
382
372
  return Object.fromEntries(Object.entries(output).filter(([key]) => isOutputKey(key)));
383
373
  }
384
- //#endregion
385
- //#region ../../internals/shared/src/configFile/text.ts
374
+ // ../../internals/shared/src/configFile/text.ts
386
375
  /**
387
376
  * A valid JavaScript identifier, so an import name can only ever print as `import { name } from`,
388
377
  * never as source that breaks out of the import statement.
@@ -454,8 +443,7 @@ function removeItem(source, node, index) {
454
443
  const next = items[index + 1];
455
444
  return next ? replaceText(source, start, next.start) : replaceText(source, items[index - 1].end, end);
456
445
  }
457
- //#endregion
458
- //#region ../../internals/shared/src/configFile/configFile.ts
446
+ // ../../internals/shared/src/configFile/configFile.ts
459
447
  /** The marker `disable-plugin` writes, with the block's line count so `enable-plugin` restores exactly those lines. */
460
448
  const DISABLED_MARKER_PATTERN = /^kubb:disabled (.+)\s+(\d+)$/;
461
449
  const OPERATIONS = new Set(Object.values(require_protocol.ConfigEditOperation));
@@ -1189,8 +1177,7 @@ async function editConfigFile({ filePath, edits, extensions }) {
1189
1177
  if (result.changed) await writeRaw(filePath, result.source);
1190
1178
  return result;
1191
1179
  }
1192
- //#endregion
1193
- //#region src/diff.ts
1180
+ // src/diff.ts
1194
1181
  const CONTEXT_LINES = 3;
1195
1182
  const DIFF_TIMEOUT_MS = 1e3;
1196
1183
  const splitLines = (text) => text === "" ? [] : text.split(/(?<=\n)/);
@@ -1342,8 +1329,7 @@ function pageHunks({ hunks, cursor, limit }) {
1342
1329
  nextCursor: cursor + used < total ? cursor + used : null
1343
1330
  };
1344
1331
  }
1345
- //#endregion
1346
- //#region src/generations.ts
1332
+ // src/generations.ts
1347
1333
  const READ_CONCURRENCY = 50;
1348
1334
  const MB = 1048576;
1349
1335
  const INDEX_KEY = "studio/generations.json";
@@ -1438,6 +1424,19 @@ async function listDisk({ root, outputPath, maxFiles }) {
1438
1424
  };
1439
1425
  }
1440
1426
  /**
1427
+ * The input as Studio stores and receives it. `JSON.stringify` writes a `Set` as `{}`, so the `meta` name sets become arrays.
1428
+ */
1429
+ function toInputJson(input) {
1430
+ return {
1431
+ ...input,
1432
+ meta: {
1433
+ ...input.meta,
1434
+ circularNames: [...input.meta.circularNames],
1435
+ enumNames: [...input.meta.enumNames]
1436
+ }
1437
+ };
1438
+ }
1439
+ /**
1441
1440
  * Keeps recent generations by job id in `storage`, with an index next to them so a store on disk
1442
1441
  * survives a restart. A generation is only ever looked up by its job id, so on a pooled sandbox one
1443
1442
  * tenant never reaches another's output. Initial disk output and generated jobs each get their
@@ -1544,10 +1543,10 @@ function createGenerationStore({ storage, maxCount, maxMb, ttlMs, now = Date.now
1544
1543
  if (!input) return 0;
1545
1544
  let json;
1546
1545
  try {
1547
- json = JSON.stringify(_kubb_ast.ast.transform(input, { schema: (node) => node.type === "ref" && node.schema ? {
1546
+ json = JSON.stringify(toInputJson(_kubb_ast.ast.transform(input, { schema: (node) => node.type === "ref" && node.schema ? {
1548
1547
  ...node,
1549
1548
  schema: void 0
1550
- } : void 0 }));
1549
+ } : void 0 })));
1551
1550
  } catch {
1552
1551
  return 0;
1553
1552
  }
@@ -1598,8 +1597,7 @@ function createGenerationStore({ storage, maxCount, maxMb, ttlMs, now = Date.now
1598
1597
  }
1599
1598
  };
1600
1599
  }
1601
- //#endregion
1602
- //#region src/generationEvents.ts
1600
+ // src/generationEvents.ts
1603
1601
  const MAX_QUEUED_EVENTS = 1024;
1604
1602
  const RESERVED_EVENTS = 64;
1605
1603
  const isDiscardable = (type) => type === "kubb:files:processing:update" || type === "kubb:info" || type === "kubb:success";
@@ -1781,8 +1779,7 @@ function createGenerationStream(hooks, jobId) {
1781
1779
  fail
1782
1780
  };
1783
1781
  }
1784
- //#endregion
1785
- //#region src/publicFetch.ts
1782
+ // src/publicFetch.ts
1786
1783
  const MAX_REDIRECTS = 5;
1787
1784
  const MAX_BYTES = 52428800;
1788
1785
  const REDIRECTS = /* @__PURE__ */ new Set([
@@ -1881,8 +1878,7 @@ async function withPublicFetch(run) {
1881
1878
  globalThis.fetch = original;
1882
1879
  }
1883
1880
  }
1884
- //#endregion
1885
- //#region src/resolveConfig.ts
1881
+ // src/resolveConfig.ts
1886
1882
  /**
1887
1883
  * Turns the JSON config Studio sends back into live Kubb objects.
1888
1884
  *
@@ -2206,8 +2202,7 @@ async function mergeParsers({ diskParsers, studioParsers, extensions = /* @__PUR
2206
2202
  extensions
2207
2203
  })));
2208
2204
  }
2209
- //#endregion
2210
- //#region src/url.ts
2205
+ // src/url.ts
2211
2206
  /**
2212
2207
  * Hosted Kubb Studio URL, used when a host passes none.
2213
2208
  */
@@ -2234,8 +2229,7 @@ function secureUrl({ studioUrl, path, socket = false }) {
2234
2229
  if (socket) url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
2235
2230
  return url;
2236
2231
  }
2237
- //#endregion
2238
- //#region src/connect.ts
2232
+ // src/connect.ts
2239
2233
  const HEARTBEAT_INTERVAL_MS = 3e4;
2240
2234
  const MAX_HEARTBEAT_INTERVAL_MS = 6e4;
2241
2235
  const PING_TIMEOUT_MS = 1e4;
@@ -3215,8 +3209,7 @@ function connectAgent(options) {
3215
3209
  openRpc: openWebSocketRpc
3216
3210
  });
3217
3211
  }
3218
- //#endregion
3219
- //#region src/pair.ts
3212
+ // src/pair.ts
3220
3213
  /** Labels, not secrets: a person approving the code in the browser is what authorizes a pairing. */
3221
3214
  const CLIENT_IDS = {
3222
3215
  cli: "kubb-cli",
@@ -3365,8 +3358,7 @@ async function pairAgent({ onCode, onRetry, maxAttempts = 1, ...options }) {
3365
3358
  }
3366
3359
  }
3367
3360
  }
3368
- //#endregion
3369
- //#region src/snapshot.ts
3361
+ // src/snapshot.ts
3370
3362
  const UPLOAD_TIMEOUT_MS = 12e4;
3371
3363
  const BUNDLED_DEPENDENCIES = ["@kubb/plugin-barrel"];
3372
3364
  /**
@@ -3614,7 +3606,6 @@ async function createSnapshot({ studioUrl = defaultStudioUrl, apiKey, config, ho
3614
3606
  });
3615
3607
  return _data.snapshot;
3616
3608
  }
3617
- //#endregion
3618
3609
  exports.IncompatibleAgentError = IncompatibleAgentError;
3619
3610
  exports.InvalidAgentTokenError = InvalidAgentTokenError;
3620
3611
  exports.PairingCanceledError = PairingCanceledError;