@kozojs/core 0.3.7 → 0.3.8

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/lib/index.js CHANGED
@@ -484,10 +484,15 @@ function uwsFastWriteError(err, uwsRes) {
484
484
  }
485
485
  }
486
486
  async function tryLoadUws() {
487
+ const { createRequire } = await import("module");
487
488
  try {
488
- const { createRequire } = await import("module");
489
489
  const req = createRequire(import.meta.url);
490
490
  return req("uWebSockets.js");
491
+ } catch {
492
+ }
493
+ try {
494
+ const req = createRequire(new URL(`file://${process.cwd()}/index.js`));
495
+ return req("uWebSockets.js");
491
496
  } catch {
492
497
  return null;
493
498
  }
@@ -2640,6 +2645,11 @@ function rateLimit(options) {
2640
2645
  const windowMs = window * 1e3;
2641
2646
  let record = store.get(key);
2642
2647
  if (!record || now > record.resetAt) {
2648
+ if (store.size > 1e4) {
2649
+ for (const [k, v] of store) {
2650
+ if (now > v.resetAt) store.delete(k);
2651
+ }
2652
+ }
2643
2653
  record = { count: 0, resetAt: now + windowMs };
2644
2654
  }
2645
2655
  record.count++;