@thexjs/core 1.10.0 → 1.10.2

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/adapter.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  scanNotFound,
10
10
  scanPages,
11
11
  scanRoutes
12
- } from "./chunk-ME4ES2PD.js";
12
+ } from "./chunk-GVDJW4PD.js";
13
13
  import "./chunk-OXV2QTWV.js";
14
14
 
15
15
  // src/adapter/bundle.ts
@@ -593,7 +593,28 @@ function snapshotActionRoutes() {
593
593
  routePath: entry.routePath,
594
594
  paramNames: entry.paramNames,
595
595
  fns: new Map(entry.fns)
596
- }));
596
+ })).sort(compareActionRoutes);
597
+ }
598
+ function compareActionRoutes(a, b) {
599
+ const aCategory = routeCategory(a);
600
+ const bCategory = routeCategory(b);
601
+ if (aCategory !== bCategory) return aCategory - bCategory;
602
+ const aSpecificity = segmentSpecificity(a);
603
+ const bSpecificity = segmentSpecificity(b);
604
+ for (let i = 0; i < Math.max(aSpecificity.length, bSpecificity.length); i++) {
605
+ const as = aSpecificity[i] ?? -1;
606
+ const bs = bSpecificity[i] ?? -1;
607
+ if (as !== bs) return as - bs;
608
+ }
609
+ return a.routePath < b.routePath ? -1 : a.routePath > b.routePath ? 1 : 0;
610
+ }
611
+ function routeCategory(entry) {
612
+ if (entry.paramNames.length === 0) return 0;
613
+ if (entry.routePath.includes("*")) return 2;
614
+ return 1;
615
+ }
616
+ function segmentSpecificity(entry) {
617
+ return entry.routePath.split("/").filter((segment) => segment.length > 0).map((segment) => segment === "*" ? 2 : segment.startsWith(":") ? 1 : 0);
597
618
  }
598
619
  function getServerFunctionHandler(csrfOptions) {
599
620
  return async (req) => {
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ import {
39
39
  verifyOrigin,
40
40
  withCsrfCookie,
41
41
  writeManifest
42
- } from "./chunk-ME4ES2PD.js";
42
+ } from "./chunk-GVDJW4PD.js";
43
43
  import {
44
44
  OTEL_ERROR_STATUS_CODE,
45
45
  REDACTED,
@@ -1615,19 +1615,37 @@ async function rateLimitMiddleware(limiter, req, server) {
1615
1615
  }
1616
1616
  function createBunRedisClient(options) {
1617
1617
  return async () => {
1618
- const require2 = import.meta.require;
1619
- const mod = require2("bun:redis");
1620
- const instance = options.url ? new mod.RedisClient({ url: options.url }) : new mod.RedisClient();
1618
+ const BunRedis = globalThis.Bun.RedisClient;
1619
+ const instance = options.url ? new BunRedis(options.url) : new BunRedis();
1621
1620
  await instance.connect();
1622
- return instance;
1621
+ return {
1622
+ sendCommand: (command, ...args) => instance.send(command, args)
1623
+ };
1623
1624
  };
1624
1625
  }
1625
1626
  function createRedisRateLimitStore(options = {}) {
1626
1627
  return createRedisRateLimitStoreFromClient(createBunRedisClient(options));
1627
1628
  }
1629
+ var INCR_WITH_WINDOW_SCRIPT = `local c = redis.call('INCR', KEYS[1])
1630
+ if redis.call('PTTL', KEYS[1]) == -1 then redis.call('EXPIRE', KEYS[1], ARGV[1]) end
1631
+ return { c, redis.call('PTTL', KEYS[1]) }`;
1632
+ async function incrWithoutScript(c, redisKey, ttlSeconds) {
1633
+ const count = Number(await c.sendCommand("INCR", redisKey));
1634
+ let pttl = Number(await c.sendCommand("PTTL", redisKey));
1635
+ if (pttl === -1) {
1636
+ await c.sendCommand("EXPIRE", redisKey, String(ttlSeconds));
1637
+ pttl = Number(await c.sendCommand("PTTL", redisKey));
1638
+ }
1639
+ return [count, pttl];
1640
+ }
1641
+ function isScriptingDenied(err) {
1642
+ const message = err instanceof Error ? err.message : String(err);
1643
+ return /NOSCRIPT|unknown command|NOPERM|scripting is disabled|not allowed/i.test(message);
1644
+ }
1628
1645
  function createRedisRateLimitStoreFromClient(clientFactory) {
1629
1646
  let client = null;
1630
1647
  let connecting = null;
1648
+ let scriptingDenied = false;
1631
1649
  function getClient() {
1632
1650
  if (client) return Promise.resolve(client);
1633
1651
  if (!connecting) {
@@ -1649,12 +1667,26 @@ function createRedisRateLimitStoreFromClient(clientFactory) {
1649
1667
  const c = await getClient();
1650
1668
  const redisKey = `x:ratelimit:${key}`;
1651
1669
  const ttlSeconds = Math.max(1, Math.ceil(windowMs / 1e3));
1652
- const count = Number(await c.sendCommand("INCR", redisKey));
1653
- if (count === 1) {
1654
- await c.sendCommand("EXPIRE", redisKey, String(ttlSeconds));
1670
+ let reply;
1671
+ if (scriptingDenied) {
1672
+ reply = await incrWithoutScript(c, redisKey, ttlSeconds);
1673
+ } else {
1674
+ try {
1675
+ reply = await c.sendCommand(
1676
+ "EVAL",
1677
+ INCR_WITH_WINDOW_SCRIPT,
1678
+ "1",
1679
+ redisKey,
1680
+ String(ttlSeconds)
1681
+ );
1682
+ } catch (err) {
1683
+ if (!isScriptingDenied(err)) throw err;
1684
+ scriptingDenied = true;
1685
+ reply = await incrWithoutScript(c, redisKey, ttlSeconds);
1686
+ }
1655
1687
  }
1656
- const pttl = Number(await c.sendCommand("PTTL", redisKey));
1657
- const remainingMs = Math.max(pttl, 0);
1688
+ const count = Number(reply[0]);
1689
+ const remainingMs = Math.max(Number(reply[1]), 0);
1658
1690
  return { count, resetAt: Date.now() + remainingMs };
1659
1691
  }
1660
1692
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thexjs/core",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "description": "Full-stack React framework core (router, SSR/SSG renderer, islands, server functions) for the x framework, built on Bun.",
5
5
  "keywords": [
6
6
  "react",