@vitemcp/server 1.6.3 → 1.6.5

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/ViteMCP.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  requireAuth,
13
13
  requireRole,
14
14
  requireScopes
15
- } from "./chunk-INI5RROX.js";
15
+ } from "./chunk-J2FAZRSL.js";
16
16
 
17
17
  // src/ViteMCP.ts
18
18
  import {
@@ -222,9 +222,11 @@ var DiscoveryDocumentCache = class {
222
222
  return this.#cache.size;
223
223
  }
224
224
  #cache = /* @__PURE__ */ new Map();
225
+ #generation = 0;
225
226
  #inFlight = /* @__PURE__ */ new Map();
226
227
  #timeoutMs;
227
228
  #ttl;
229
+ #urlGenerations = /* @__PURE__ */ new Map();
228
230
  /**
229
231
  * @param options - configuration options
230
232
  * @param options.timeoutMs - timeout in miliseconds for the upstream fetch
@@ -240,8 +242,13 @@ var DiscoveryDocumentCache = class {
240
242
  clear(url) {
241
243
  if (url) {
242
244
  this.#cache.delete(url);
245
+ this.#inFlight.delete(url);
246
+ this.#urlGenerations.set(url, (this.#urlGenerations.get(url) ?? 0) + 1);
243
247
  } else {
244
248
  this.#cache.clear();
249
+ this.#inFlight.clear();
250
+ this.#urlGenerations.clear();
251
+ this.#generation++;
245
252
  }
246
253
  }
247
254
  /**
@@ -263,13 +270,19 @@ var DiscoveryDocumentCache = class {
263
270
  if (inFlight) {
264
271
  return inFlight;
265
272
  }
266
- const fetchPromise = this.#fetchAndCache(url);
273
+ const fetchPromise = this.#fetchAndCache(
274
+ url,
275
+ this.#generation,
276
+ this.#urlGenerations.get(url) ?? 0
277
+ );
267
278
  this.#inFlight.set(url, fetchPromise);
268
279
  try {
269
280
  const data = await fetchPromise;
270
281
  return data;
271
282
  } finally {
272
- this.#inFlight.delete(url);
283
+ if (this.#inFlight.get(url) === fetchPromise) {
284
+ this.#inFlight.delete(url);
285
+ }
273
286
  }
274
287
  }
275
288
  /**
@@ -288,7 +301,7 @@ var DiscoveryDocumentCache = class {
288
301
  }
289
302
  return true;
290
303
  }
291
- async #fetchAndCache(url) {
304
+ async #fetchAndCache(url, generation, urlGeneration) {
292
305
  let res;
293
306
  try {
294
307
  res = await fetch(url, {
@@ -310,10 +323,12 @@ var DiscoveryDocumentCache = class {
310
323
  }
311
324
  const data = await res.json();
312
325
  const expiresAt = Date.now() + this.#ttl;
313
- this.#cache.set(url, {
314
- data,
315
- expiresAt
316
- });
326
+ if (this.#generation === generation && (this.#urlGenerations.get(url) ?? 0) === urlGeneration) {
327
+ this.#cache.set(url, {
328
+ data,
329
+ expiresAt
330
+ });
331
+ }
317
332
  return data;
318
333
  }
319
334
  };
@@ -370,7 +385,7 @@ async function compileSchema(schema) {
370
385
  function toIssue(error) {
371
386
  const path = error.instancePath.split("/").filter(Boolean).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")).map((segment) => {
372
387
  const index = Number(segment);
373
- return Number.isInteger(index) && segment !== "" ? index : segment;
388
+ return /^(?:0|[1-9]\d*)$/.test(segment) && Number.isSafeInteger(index) ? index : segment;
374
389
  });
375
390
  const missingProperty = error.params?.missingProperty;
376
391
  if (error.keyword === "required" && typeof missingProperty === "string") {