@teyik0/furin 0.5.0-alpha.1 → 0.5.0-alpha.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.
Files changed (61) hide show
  1. package/dist/build/entry-template.ts +3 -1
  2. package/dist/build/index.js +360 -219
  3. package/dist/build/private-server-sourcemaps.d.ts +2 -0
  4. package/dist/build/types.d.ts +2 -0
  5. package/dist/cli/index.js +363 -221
  6. package/dist/client/document.d.ts +2 -0
  7. package/dist/client/link.js +11 -0
  8. package/dist/client.js +11 -0
  9. package/dist/config.d.ts +7 -2
  10. package/dist/config.js +24 -1
  11. package/dist/furin.js +217 -82
  12. package/dist/rsc-client.js +9 -1
  13. package/dist/rsc.js +19 -7
  14. package/dist/server/browser-events/shutdown.d.ts +3 -0
  15. package/dist/server/cache/redis/index.d.ts +2 -0
  16. package/dist/server/cache/redis/index.js +67 -12
  17. package/dist/server/cache/redis/scripts.d.ts +5 -5
  18. package/dist/server/dev/plugin.d.ts +1 -0
  19. package/dist/server/evlog.d.ts +1 -1
  20. package/dist/server/internal.js +3 -1
  21. package/dist/server/production-server.d.ts +13 -0
  22. package/dist/server/production-server.js +2906 -0
  23. package/dist/server/router/hmr.d.ts +6 -0
  24. package/dist/server/router/hmr.production.d.ts +5 -0
  25. package/dist/server/router/plugin.d.ts +5 -1
  26. package/dist/server/sync/index.js +5 -2
  27. package/dist/server/sync/stream.d.ts +4 -0
  28. package/dist/shared/production-build.d.ts +2 -0
  29. package/package.json +8 -3
  30. package/src/adapter/bun.ts +74 -15
  31. package/src/adapter/vercel.ts +15 -1
  32. package/src/build/elysia-aot.ts +1 -1
  33. package/src/build/entry-template.ts +3 -1
  34. package/src/build/hydrate.ts +5 -1
  35. package/src/build/index.ts +5 -0
  36. package/src/build/private-server-sourcemaps.ts +20 -0
  37. package/src/build/server-app-entry.ts +3 -2
  38. package/src/build/types.ts +2 -0
  39. package/src/cli/index.ts +1 -0
  40. package/src/client/document.tsx +19 -0
  41. package/src/config.ts +30 -2
  42. package/src/furin.ts +37 -12
  43. package/src/rsc/codec.ts +11 -6
  44. package/src/rsc/render-error.ts +3 -1
  45. package/src/server/browser-events/plugin.ts +7 -0
  46. package/src/server/browser-events/shutdown.ts +32 -0
  47. package/src/server/cache/redis/index.ts +19 -2
  48. package/src/server/cache/redis/scripts.ts +47 -7
  49. package/src/server/dev/plugin.ts +10 -1
  50. package/src/server/evlog.ts +11 -4
  51. package/src/server/production-server.ts +135 -0
  52. package/src/server/render/document.tsx +7 -1
  53. package/src/server/render/ssr.ts +2 -1
  54. package/src/server/render/template.ts +5 -1
  55. package/src/server/router/discovery.ts +3 -1
  56. package/src/server/router/hmr.production.ts +11 -0
  57. package/src/server/router/hmr.ts +84 -77
  58. package/src/server/router/plugin.ts +76 -17
  59. package/src/server/router/schema-merge.ts +9 -2
  60. package/src/server/sync/stream.ts +43 -2
  61. package/src/shared/production-build.ts +20 -0
package/dist/rsc.js CHANGED
@@ -8,6 +8,12 @@ import { tmpdir } from "os";
8
8
  import { dirname, isAbsolute, join, resolve } from "path";
9
9
  import { pathToFileURL } from "url";
10
10
 
11
+ // src/shared/production-build.ts
12
+ var productionBuildScope;
13
+ function isProductionBuild() {
14
+ return productionBuildScope?.getStore() === true || typeof process !== "undefined" && false;
15
+ }
16
+
11
17
  // src/rsc/render-error.ts
12
18
  var INTERNAL_STACK_FRAMES = new Set([
13
19
  "<anonymous>",
@@ -45,7 +51,9 @@ function detectComponent(error, hook) {
45
51
  }
46
52
  }
47
53
  function renderErrorMessage(options) {
48
- if (typeof process !== "undefined" && false) {}
54
+ if (isProductionBuild()) {
55
+ return `[furin/rsc] Server Component rendering failed inside ${options.operation}().`;
56
+ }
49
57
  if (options.hook !== undefined && options.component !== undefined) {
50
58
  const diagnostic = `[furin/rsc] A component rendered inside ${options.operation}()
51
59
  used a client-only React hook.
@@ -149,7 +157,7 @@ async function drainFlight(session, operation) {
149
157
  }
150
158
 
151
159
  // src/rsc/codec.ts
152
- var serverCodecPromise;
160
+ var serverCodecPromises = new Map;
153
161
  function resolveConfiguredCodecPath(configuredPath) {
154
162
  if (configuredPath === undefined || configuredPath.trim() === "") {
155
163
  return;
@@ -165,10 +173,12 @@ function resolveBuiltCodecPath(moduleDir, executablePath) {
165
173
  return candidates.find((candidate) => existsSync(candidate));
166
174
  }
167
175
  function loadServerCodec() {
168
- if (serverCodecPromise !== undefined) {
169
- return serverCodecPromise;
176
+ const mode = isProductionBuild() ? "production" : "development";
177
+ const existing = serverCodecPromises.get(mode);
178
+ if (existing !== undefined) {
179
+ return existing;
170
180
  }
171
- serverCodecPromise = (async () => {
181
+ const codecPromise = (async () => {
172
182
  const configuredCodecPath = resolveConfiguredCodecPath(process.env.FURIN_RSC_CODEC_PATH);
173
183
  if (configuredCodecPath !== undefined) {
174
184
  return import(pathToFileURL(configuredCodecPath).href);
@@ -177,7 +187,7 @@ function loadServerCodec() {
177
187
  if (builtCodecPath !== undefined) {
178
188
  return import(pathToFileURL(builtCodecPath).href);
179
189
  }
180
- const outdir = join(tmpdir(), `furin-rsc-${process.pid}-${Bun.hash(import.meta.url)}`);
190
+ const outdir = join(tmpdir(), `furin-rsc-${process.pid}-${Bun.hash(import.meta.url)}-${mode}`);
181
191
  mkdirSync(outdir, { recursive: true });
182
192
  const sourcePath = join(import.meta.dir, "server-codec.ts");
183
193
  if (!existsSync(sourcePath)) {
@@ -185,6 +195,7 @@ function loadServerCodec() {
185
195
  }
186
196
  const result = await Bun.build({
187
197
  conditions: ["react-server"],
198
+ define: { "process.env.NODE_ENV": JSON.stringify(mode) },
188
199
  entrypoints: [sourcePath],
189
200
  format: "esm",
190
201
  minify: false,
@@ -204,7 +215,8 @@ ${details}`);
204
215
  }
205
216
  return import(pathToFileURL(output.path).href);
206
217
  })();
207
- return serverCodecPromise;
218
+ serverCodecPromises.set(mode, codecPromise);
219
+ return codecPromise;
208
220
  }
209
221
  async function encodeFlight(model, signal, operation) {
210
222
  const codec = await loadServerCodec();
@@ -0,0 +1,3 @@
1
+ export declare function registerBrowserEventConnection(server: Bun.Server<unknown>, close: () => void): void;
2
+ export declare function unregisterBrowserEventConnection(server: Bun.Server<unknown>, close: () => void): void;
3
+ export declare function closeBrowserEventConnections(server: Bun.Server<unknown>): void;
@@ -33,7 +33,9 @@ export declare class RedisPageCache implements PageCacheAdapter {
33
33
  private fenceKey;
34
34
  private leaseKey;
35
35
  private pathsKey;
36
+ private leasesKey;
36
37
  private tagPathsKey;
38
+ private tagLeasesKey;
37
39
  private versionsKey;
38
40
  }
39
41
  export declare function redisPageCache(options: RedisPageCacheOptions): PageCacheAdapter;
@@ -7,6 +7,10 @@ local now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) /
7
7
  if raw then
8
8
  local active = cjson.decode(raw)
9
9
  if active.expiresAt > now then return nil end
10
+ if active.indexMember then redis.call('ZREM', KEYS[4], active.indexMember) end
11
+ for _, key in ipairs(active.tagLeaseKeys or {}) do
12
+ redis.call('ZREM', key, active.indexMember)
13
+ end
10
14
  end
11
15
  local fence = redis.call('INCR', KEYS[2])
12
16
  redis.call('PEXPIRE', KEYS[2], ARGV[4])
@@ -16,14 +20,26 @@ for index, field in ipairs(fields) do
16
20
  values[index] = tonumber(redis.call('HGET', KEYS[3], field) or '0')
17
21
  end
18
22
  redis.call('PEXPIRE', KEYS[3], ARGV[4])
23
+ local tag_lease_keys = {}
24
+ for index = 5, #KEYS do table.insert(tag_lease_keys, KEYS[index]) end
19
25
  local lease = {
26
+ tagLeaseKeys = tag_lease_keys,
20
27
  expiresAt = now + tonumber(ARGV[2]),
21
28
  fence = fence,
22
29
  fields = fields,
23
30
  id = ARGV[1],
31
+ indexMember = cjson.encode({id = ARGV[1], path = ARGV[5], tags = cjson.decode(ARGV[6])}),
24
32
  values = values
25
33
  }
26
34
  redis.call('SET', KEYS[1], cjson.encode(lease), 'PX', ARGV[2])
35
+ redis.call('ZREMRANGEBYSCORE', KEYS[4], '-inf', now)
36
+ redis.call('ZADD', KEYS[4], lease.expiresAt, lease.indexMember)
37
+ redis.call('PEXPIRE', KEYS[4], ARGV[4])
38
+ for _, key in ipairs(tag_lease_keys) do
39
+ redis.call('ZREMRANGEBYSCORE', key, '-inf', now)
40
+ redis.call('ZADD', key, lease.expiresAt, lease.indexMember)
41
+ redis.call('PEXPIRE', key, ARGV[4])
42
+ end
27
43
  return cjson.encode(lease)
28
44
  `;
29
45
  var COMMIT_PAGE_CACHE_ENTRY_SCRIPT = `
@@ -39,6 +55,8 @@ for index, field in ipairs(lease.fields) do
39
55
  local current = tonumber(redis.call('HGET', KEYS[3], field) or '0')
40
56
  if current ~= lease.values[index] then
41
57
  redis.call('DEL', KEYS[1])
58
+ if lease.indexMember then redis.call('ZREM', KEYS[5], lease.indexMember) end
59
+ for _, key in ipairs(lease.tagLeaseKeys or {}) do redis.call('ZREM', key, lease.indexMember) end
42
60
  return 'superseded'
43
61
  end
44
62
  end
@@ -57,13 +75,15 @@ redis.call('SET', KEYS[2], ARGV[3], 'PX', ARGV[5])
57
75
  redis.call('ZREMRANGEBYSCORE', KEYS[4], '-inf', now)
58
76
  redis.call('ZADD', KEYS[4], expires_at, ARGV[4])
59
77
  redis.call('PEXPIRE', KEYS[4], ARGV[6])
60
- for index = 5, #KEYS do
78
+ for index = 6, #KEYS do
61
79
  redis.call('ZREMRANGEBYSCORE', KEYS[index], '-inf', now)
62
80
  redis.call('ZADD', KEYS[index], expires_at, ARGV[4])
63
81
  redis.call('PEXPIRE', KEYS[index], ARGV[6])
64
82
  end
65
83
  redis.call('PEXPIRE', KEYS[3], ARGV[6])
66
84
  redis.call('DEL', KEYS[1])
85
+ if lease.indexMember then redis.call('ZREM', KEYS[5], lease.indexMember) end
86
+ for _, key in ipairs(lease.tagLeaseKeys or {}) do redis.call('ZREM', key, lease.indexMember) end
67
87
  return 'stored'
68
88
  `;
69
89
  var READ_PAGE_CACHE_ENTRY_SCRIPT = `
@@ -90,6 +110,8 @@ local raw = redis.call('GET', KEYS[1])
90
110
  if not raw then return 0 end
91
111
  local lease = cjson.decode(raw)
92
112
  if lease.id == ARGV[1] and lease.fence == tonumber(ARGV[2]) then
113
+ if lease.indexMember then redis.call('ZREM', KEYS[2], lease.indexMember) end
114
+ for _, key in ipairs(lease.tagLeaseKeys or {}) do redis.call('ZREM', key, lease.indexMember) end
93
115
  return redis.call('DEL', KEYS[1])
94
116
  end
95
117
  return 0
@@ -103,13 +125,13 @@ redis.call('ZREMRANGEBYSCORE', KEYS[2], '-inf', now)
103
125
  local members = redis.call('ZRANGE', KEYS[2], 0, -1)
104
126
  local seen = {}
105
127
  local affected = {}
128
+ local function matches_path(path)
129
+ if path == ARGV[2] then return true end
130
+ return ARGV[3] == 'layout' and (ARGV[2] == '/' or string.sub(path, 1, string.len(ARGV[2]) + 1) == ARGV[2] .. '/')
131
+ end
106
132
  for _, member in ipairs(members) do
107
133
  local index = cjson.decode(member)
108
- local matches = index.path == ARGV[2]
109
- if ARGV[3] == 'layout' and not matches then
110
- matches = ARGV[2] == '/' or string.sub(index.path, 1, string.len(ARGV[2]) + 1) == ARGV[2] .. '/'
111
- end
112
- if matches then
134
+ if matches_path(index.path) then
113
135
  redis.call('DEL', index.entryKey)
114
136
  redis.call('ZREM', index.pathsKey, member)
115
137
  for _, tag_key in ipairs(index.tagKeys) do
@@ -121,6 +143,14 @@ for _, member in ipairs(members) do
121
143
  end
122
144
  end
123
145
  end
146
+ redis.call('ZREMRANGEBYSCORE', KEYS[3], '-inf', now)
147
+ for _, member in ipairs(redis.call('ZRANGE', KEYS[3], 0, -1)) do
148
+ local lease = cjson.decode(member)
149
+ if matches_path(lease.path) and not seen[lease.path] then
150
+ seen[lease.path] = true
151
+ table.insert(affected, lease.path)
152
+ end
153
+ end
124
154
  return affected
125
155
  `;
126
156
  var INVALIDATE_PAGE_CACHE_TAGS_SCRIPT = `
@@ -134,7 +164,7 @@ local now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) /
134
164
  local seen_members = {}
135
165
  local seen_paths = {}
136
166
  local affected = {}
137
- for key_index = 3, #KEYS do
167
+ for key_index = 4, 3 + #tags do
138
168
  redis.call('ZREMRANGEBYSCORE', KEYS[key_index], '-inf', now)
139
169
  local members = redis.call('ZRANGE', KEYS[key_index], 0, -1)
140
170
  for _, member in ipairs(members) do
@@ -153,6 +183,16 @@ for key_index = 3, #KEYS do
153
183
  end
154
184
  end
155
185
  end
186
+ for key_index = 4 + #tags, #KEYS do
187
+ redis.call('ZREMRANGEBYSCORE', KEYS[key_index], '-inf', now)
188
+ for _, member in ipairs(redis.call('ZRANGE', KEYS[key_index], 0, -1)) do
189
+ local lease = cjson.decode(member)
190
+ if not seen_paths[lease.path] then
191
+ seen_paths[lease.path] = true
192
+ table.insert(affected, lease.path)
193
+ end
194
+ end
195
+ end
156
196
  return affected
157
197
  `;
158
198
 
@@ -247,7 +287,9 @@ class RedisPageCache {
247
287
  const keys = [
248
288
  this.leaseKey(identity),
249
289
  this.fenceKey(identity),
250
- this.versionsKey(identity.scope)
290
+ this.versionsKey(identity.scope),
291
+ this.leasesKey(identity.scope),
292
+ ...[...new Set(identity.tags)].map((tag) => this.tagLeasesKey(identity.scope, tag))
251
293
  ];
252
294
  const raw = await this.client.send("EVAL", [
253
295
  ACQUIRE_PAGE_CACHE_LEASE_SCRIPT,
@@ -256,7 +298,9 @@ class RedisPageCache {
256
298
  id,
257
299
  String(leaseMs),
258
300
  JSON.stringify(selectorFields(identity)),
259
- String(this.metadataRetentionMs)
301
+ String(this.metadataRetentionMs),
302
+ identity.path,
303
+ JSON.stringify(identity.tags)
260
304
  ]);
261
305
  if (raw === null) {
262
306
  return null;
@@ -296,6 +340,7 @@ class RedisPageCache {
296
340
  entryKey,
297
341
  this.versionsKey(identity.scope),
298
342
  pathsKey,
343
+ this.leasesKey(identity.scope),
299
344
  ...tagKeys
300
345
  ];
301
346
  const result = await this.client.send("EVAL", [
@@ -319,9 +364,10 @@ class RedisPageCache {
319
364
  const path = normalizeInvalidationPath(input.path);
320
365
  const result = stringArrayResult(await this.client.send("EVAL", [
321
366
  INVALIDATE_PAGE_CACHE_PATH_SCRIPT,
322
- "2",
367
+ "3",
323
368
  this.versionsKey(input.scope),
324
369
  this.pathsKey(input.scope),
370
+ this.leasesKey(input.scope),
325
371
  `${input.type}:${path}`,
326
372
  path,
327
373
  input.type,
@@ -333,7 +379,9 @@ class RedisPageCache {
333
379
  const keys = [
334
380
  this.versionsKey(input.scope),
335
381
  this.pathsKey(input.scope),
336
- ...tags.map((tag) => this.tagPathsKey(input.scope, tag))
382
+ this.leasesKey(input.scope),
383
+ ...tags.map((tag) => this.tagPathsKey(input.scope, tag)),
384
+ ...tags.map((tag) => this.tagLeasesKey(input.scope, tag))
337
385
  ];
338
386
  const result = stringArrayResult(await this.client.send("EVAL", [
339
387
  INVALIDATE_PAGE_CACHE_TAGS_SCRIPT,
@@ -362,8 +410,9 @@ class RedisPageCache {
362
410
  }) {
363
411
  await this.client.send("EVAL", [
364
412
  RELEASE_PAGE_CACHE_LEASE_SCRIPT,
365
- "1",
413
+ "2",
366
414
  this.leaseKey(identity),
415
+ this.leasesKey(identity.scope),
367
416
  lease.id,
368
417
  String(lease.fence)
369
418
  ]);
@@ -380,9 +429,15 @@ class RedisPageCache {
380
429
  pathsKey(scope) {
381
430
  return `${this.prefix}:paths:${digest(scope)}`;
382
431
  }
432
+ leasesKey(scope) {
433
+ return `${this.prefix}:leases:${digest(scope)}`;
434
+ }
383
435
  tagPathsKey(scope, tag) {
384
436
  return `${this.prefix}:tag-paths:${digest(scope)}:${digest(tag)}`;
385
437
  }
438
+ tagLeasesKey(scope, tag) {
439
+ return `${this.prefix}:tag-leases:${digest(scope)}:${digest(tag)}`;
440
+ }
386
441
  versionsKey(scope) {
387
442
  return `${this.prefix}:versions:${digest(scope)}`;
388
443
  }
@@ -1,6 +1,6 @@
1
- export declare const ACQUIRE_PAGE_CACHE_LEASE_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nif raw then\n local active = cjson.decode(raw)\n if active.expiresAt > now then return nil end\nend\nlocal fence = redis.call('INCR', KEYS[2])\nredis.call('PEXPIRE', KEYS[2], ARGV[4])\nlocal fields = cjson.decode(ARGV[3])\nlocal values = {}\nfor index, field in ipairs(fields) do\n values[index] = tonumber(redis.call('HGET', KEYS[3], field) or '0')\nend\nredis.call('PEXPIRE', KEYS[3], ARGV[4])\nlocal lease = {\n expiresAt = now + tonumber(ARGV[2]),\n fence = fence,\n fields = fields,\n id = ARGV[1],\n values = values\n}\nredis.call('SET', KEYS[1], cjson.encode(lease), 'PX', ARGV[2])\nreturn cjson.encode(lease)\n";
2
- export declare const COMMIT_PAGE_CACHE_ENTRY_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nif not raw then return 'superseded' end\nlocal lease = cjson.decode(raw)\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nif lease.id ~= ARGV[1] or lease.fence ~= tonumber(ARGV[2]) or lease.expiresAt <= now then\n return 'superseded'\nend\nfor index, field in ipairs(lease.fields) do\n local current = tonumber(redis.call('HGET', KEYS[3], field) or '0')\n if current ~= lease.values[index] then\n redis.call('DEL', KEYS[1])\n return 'superseded'\n end\nend\nlocal previous_raw = redis.call('GET', KEYS[2])\nif previous_raw then\n local previous = cjson.decode(previous_raw)\n if previous.indexMember then\n redis.call('ZREM', previous.pathsKey, previous.indexMember)\n for _, tag_key in ipairs(previous.tagKeys) do\n redis.call('ZREM', tag_key, previous.indexMember)\n end\n end\nend\nlocal expires_at = now + tonumber(ARGV[5])\nredis.call('SET', KEYS[2], ARGV[3], 'PX', ARGV[5])\nredis.call('ZREMRANGEBYSCORE', KEYS[4], '-inf', now)\nredis.call('ZADD', KEYS[4], expires_at, ARGV[4])\nredis.call('PEXPIRE', KEYS[4], ARGV[6])\nfor index = 5, #KEYS do\n redis.call('ZREMRANGEBYSCORE', KEYS[index], '-inf', now)\n redis.call('ZADD', KEYS[index], expires_at, ARGV[4])\n redis.call('PEXPIRE', KEYS[index], ARGV[6])\nend\nredis.call('PEXPIRE', KEYS[3], ARGV[6])\nredis.call('DEL', KEYS[1])\nreturn 'stored'\n";
1
+ export declare const ACQUIRE_PAGE_CACHE_LEASE_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nif raw then\n local active = cjson.decode(raw)\n if active.expiresAt > now then return nil end\n if active.indexMember then redis.call('ZREM', KEYS[4], active.indexMember) end\n for _, key in ipairs(active.tagLeaseKeys or {}) do\n redis.call('ZREM', key, active.indexMember)\n end\nend\nlocal fence = redis.call('INCR', KEYS[2])\nredis.call('PEXPIRE', KEYS[2], ARGV[4])\nlocal fields = cjson.decode(ARGV[3])\nlocal values = {}\nfor index, field in ipairs(fields) do\n values[index] = tonumber(redis.call('HGET', KEYS[3], field) or '0')\nend\nredis.call('PEXPIRE', KEYS[3], ARGV[4])\nlocal tag_lease_keys = {}\nfor index = 5, #KEYS do table.insert(tag_lease_keys, KEYS[index]) end\nlocal lease = {\n tagLeaseKeys = tag_lease_keys,\n expiresAt = now + tonumber(ARGV[2]),\n fence = fence,\n fields = fields,\n id = ARGV[1],\n indexMember = cjson.encode({id = ARGV[1], path = ARGV[5], tags = cjson.decode(ARGV[6])}),\n values = values\n}\nredis.call('SET', KEYS[1], cjson.encode(lease), 'PX', ARGV[2])\nredis.call('ZREMRANGEBYSCORE', KEYS[4], '-inf', now)\nredis.call('ZADD', KEYS[4], lease.expiresAt, lease.indexMember)\nredis.call('PEXPIRE', KEYS[4], ARGV[4])\nfor _, key in ipairs(tag_lease_keys) do\n redis.call('ZREMRANGEBYSCORE', key, '-inf', now)\n redis.call('ZADD', key, lease.expiresAt, lease.indexMember)\n redis.call('PEXPIRE', key, ARGV[4])\nend\nreturn cjson.encode(lease)\n";
2
+ export declare const COMMIT_PAGE_CACHE_ENTRY_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nif not raw then return 'superseded' end\nlocal lease = cjson.decode(raw)\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nif lease.id ~= ARGV[1] or lease.fence ~= tonumber(ARGV[2]) or lease.expiresAt <= now then\n return 'superseded'\nend\nfor index, field in ipairs(lease.fields) do\n local current = tonumber(redis.call('HGET', KEYS[3], field) or '0')\n if current ~= lease.values[index] then\n redis.call('DEL', KEYS[1])\n if lease.indexMember then redis.call('ZREM', KEYS[5], lease.indexMember) end\n for _, key in ipairs(lease.tagLeaseKeys or {}) do redis.call('ZREM', key, lease.indexMember) end\n return 'superseded'\n end\nend\nlocal previous_raw = redis.call('GET', KEYS[2])\nif previous_raw then\n local previous = cjson.decode(previous_raw)\n if previous.indexMember then\n redis.call('ZREM', previous.pathsKey, previous.indexMember)\n for _, tag_key in ipairs(previous.tagKeys) do\n redis.call('ZREM', tag_key, previous.indexMember)\n end\n end\nend\nlocal expires_at = now + tonumber(ARGV[5])\nredis.call('SET', KEYS[2], ARGV[3], 'PX', ARGV[5])\nredis.call('ZREMRANGEBYSCORE', KEYS[4], '-inf', now)\nredis.call('ZADD', KEYS[4], expires_at, ARGV[4])\nredis.call('PEXPIRE', KEYS[4], ARGV[6])\nfor index = 6, #KEYS do\n redis.call('ZREMRANGEBYSCORE', KEYS[index], '-inf', now)\n redis.call('ZADD', KEYS[index], expires_at, ARGV[4])\n redis.call('PEXPIRE', KEYS[index], ARGV[6])\nend\nredis.call('PEXPIRE', KEYS[3], ARGV[6])\nredis.call('DEL', KEYS[1])\nif lease.indexMember then redis.call('ZREM', KEYS[5], lease.indexMember) end\nfor _, key in ipairs(lease.tagLeaseKeys or {}) do redis.call('ZREM', key, lease.indexMember) end\nreturn 'stored'\n";
3
3
  export declare const READ_PAGE_CACHE_ENTRY_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nif not raw then return nil end\nlocal value = cjson.decode(raw)\nfor index, field in ipairs(value.fields) do\n local current = tonumber(redis.call('HGET', KEYS[2], field) or '0')\n if current ~= value.values[index] then\n redis.call('DEL', KEYS[1])\n if value.indexMember then\n redis.call('ZREM', value.pathsKey, value.indexMember)\n for _, tag_key in ipairs(value.tagKeys) do\n redis.call('ZREM', tag_key, value.indexMember)\n end\n end\n return nil\n end\nend\nreturn raw\n";
4
- export declare const RELEASE_PAGE_CACHE_LEASE_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nif not raw then return 0 end\nlocal lease = cjson.decode(raw)\nif lease.id == ARGV[1] and lease.fence == tonumber(ARGV[2]) then\n return redis.call('DEL', KEYS[1])\nend\nreturn 0\n";
5
- export declare const INVALIDATE_PAGE_CACHE_PATH_SCRIPT = "\nredis.call('HINCRBY', KEYS[1], ARGV[1], 1)\nredis.call('PEXPIRE', KEYS[1], ARGV[4])\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nredis.call('ZREMRANGEBYSCORE', KEYS[2], '-inf', now)\nlocal members = redis.call('ZRANGE', KEYS[2], 0, -1)\nlocal seen = {}\nlocal affected = {}\nfor _, member in ipairs(members) do\n local index = cjson.decode(member)\n local matches = index.path == ARGV[2]\n if ARGV[3] == 'layout' and not matches then\n matches = ARGV[2] == '/' or string.sub(index.path, 1, string.len(ARGV[2]) + 1) == ARGV[2] .. '/'\n end\n if matches then\n redis.call('DEL', index.entryKey)\n redis.call('ZREM', index.pathsKey, member)\n for _, tag_key in ipairs(index.tagKeys) do\n redis.call('ZREM', tag_key, member)\n end\n if not seen[index.path] then\n seen[index.path] = true\n table.insert(affected, index.path)\n end\n end\nend\nreturn affected\n";
6
- export declare const INVALIDATE_PAGE_CACHE_TAGS_SCRIPT = "\nlocal tags = cjson.decode(ARGV[1])\nfor _, tag in ipairs(tags) do\n redis.call('HINCRBY', KEYS[1], 'tag:' .. tag, 1)\nend\nredis.call('PEXPIRE', KEYS[1], ARGV[2])\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nlocal seen_members = {}\nlocal seen_paths = {}\nlocal affected = {}\nfor key_index = 3, #KEYS do\n redis.call('ZREMRANGEBYSCORE', KEYS[key_index], '-inf', now)\n local members = redis.call('ZRANGE', KEYS[key_index], 0, -1)\n for _, member in ipairs(members) do\n if not seen_members[member] then\n seen_members[member] = true\n local index = cjson.decode(member)\n redis.call('DEL', index.entryKey)\n redis.call('ZREM', index.pathsKey, member)\n for _, tag_key in ipairs(index.tagKeys) do\n redis.call('ZREM', tag_key, member)\n end\n if not seen_paths[index.path] then\n seen_paths[index.path] = true\n table.insert(affected, index.path)\n end\n end\n end\nend\nreturn affected\n";
4
+ export declare const RELEASE_PAGE_CACHE_LEASE_SCRIPT = "\nlocal raw = redis.call('GET', KEYS[1])\nif not raw then return 0 end\nlocal lease = cjson.decode(raw)\nif lease.id == ARGV[1] and lease.fence == tonumber(ARGV[2]) then\n if lease.indexMember then redis.call('ZREM', KEYS[2], lease.indexMember) end\n for _, key in ipairs(lease.tagLeaseKeys or {}) do redis.call('ZREM', key, lease.indexMember) end\n return redis.call('DEL', KEYS[1])\nend\nreturn 0\n";
5
+ export declare const INVALIDATE_PAGE_CACHE_PATH_SCRIPT = "\nredis.call('HINCRBY', KEYS[1], ARGV[1], 1)\nredis.call('PEXPIRE', KEYS[1], ARGV[4])\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nredis.call('ZREMRANGEBYSCORE', KEYS[2], '-inf', now)\nlocal members = redis.call('ZRANGE', KEYS[2], 0, -1)\nlocal seen = {}\nlocal affected = {}\nlocal function matches_path(path)\n if path == ARGV[2] then return true end\n return ARGV[3] == 'layout' and (ARGV[2] == '/' or string.sub(path, 1, string.len(ARGV[2]) + 1) == ARGV[2] .. '/')\nend\nfor _, member in ipairs(members) do\n local index = cjson.decode(member)\n if matches_path(index.path) then\n redis.call('DEL', index.entryKey)\n redis.call('ZREM', index.pathsKey, member)\n for _, tag_key in ipairs(index.tagKeys) do\n redis.call('ZREM', tag_key, member)\n end\n if not seen[index.path] then\n seen[index.path] = true\n table.insert(affected, index.path)\n end\n end\nend\nredis.call('ZREMRANGEBYSCORE', KEYS[3], '-inf', now)\nfor _, member in ipairs(redis.call('ZRANGE', KEYS[3], 0, -1)) do\n local lease = cjson.decode(member)\n if matches_path(lease.path) and not seen[lease.path] then\n seen[lease.path] = true\n table.insert(affected, lease.path)\n end\nend\nreturn affected\n";
6
+ export declare const INVALIDATE_PAGE_CACHE_TAGS_SCRIPT = "\nlocal tags = cjson.decode(ARGV[1])\nfor _, tag in ipairs(tags) do\n redis.call('HINCRBY', KEYS[1], 'tag:' .. tag, 1)\nend\nredis.call('PEXPIRE', KEYS[1], ARGV[2])\nlocal now_parts = redis.call('TIME')\nlocal now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)\nlocal seen_members = {}\nlocal seen_paths = {}\nlocal affected = {}\nfor key_index = 4, 3 + #tags do\n redis.call('ZREMRANGEBYSCORE', KEYS[key_index], '-inf', now)\n local members = redis.call('ZRANGE', KEYS[key_index], 0, -1)\n for _, member in ipairs(members) do\n if not seen_members[member] then\n seen_members[member] = true\n local index = cjson.decode(member)\n redis.call('DEL', index.entryKey)\n redis.call('ZREM', index.pathsKey, member)\n for _, tag_key in ipairs(index.tagKeys) do\n redis.call('ZREM', tag_key, member)\n end\n if not seen_paths[index.path] then\n seen_paths[index.path] = true\n table.insert(affected, index.path)\n end\n end\n end\nend\nfor key_index = 4 + #tags, #KEYS do\n redis.call('ZREMRANGEBYSCORE', KEYS[key_index], '-inf', now)\n for _, member in ipairs(redis.call('ZRANGE', KEYS[key_index], 0, -1)) do\n local lease = cjson.decode(member)\n if not seen_paths[lease.path] then\n seen_paths[lease.path] = true\n table.insert(affected, lease.path)\n end\n end\nend\nreturn affected\n";
@@ -2,6 +2,7 @@ import { type AnyElysia } from "elysia";
2
2
  import type { DevDiagnosticEvent } from "../../shared/dev-diagnostics.ts";
3
3
  import type { FurinInstance } from "../instance.ts";
4
4
  import { type DevDiagnosticStore } from "./diagnostics.ts";
5
+ export declare const extensionErrorFilterScript = "window.addEventListener(\"unhandledrejection\", (event) => {\n const stack = event.reason?.stack;\n if (typeof stack !== \"string\") return;\n const firstFrame = stack.match(/^(?:\\s*at [^\\n]*|[^\\n]*@[^\\n]*)/m)?.[0];\n if (firstFrame && /\\b(?:chrome|moz)-extension:\\/\\//.test(firstFrame)) {\n event.stopImmediatePropagation();\n }\n}, true);";
5
6
  export declare function createDevDiagnosticPlugin(store: DevDiagnosticStore, instance: FurinInstance | undefined, reconcileRoutes: (() => Promise<void>) | undefined): AnyElysia;
6
7
  export declare function injectDevDiagnosticClient(html: string, basePath: string): string;
7
8
  export declare function renderDevDiagnosticResponse(event: Extract<DevDiagnosticEvent, {
@@ -2,7 +2,7 @@ import type { RequestLogger } from "evlog";
2
2
  import { type BaseEvlogOptions } from "evlog/toolkit";
3
3
  export type FurinEvlogOptions = BaseEvlogOptions;
4
4
  export declare const getRequestLogger: <T extends object = Record<string, unknown>>() => import("evlog").AuditableLogger<T>;
5
- export declare function setRuntimeEvlogWaitUntil(waitUntil: NonNullable<FurinEvlogOptions["waitUntil"]>): void;
5
+ export declare function setRuntimeEvlogWaitUntil(waitUntil: NonNullable<FurinEvlogOptions["waitUntil"]>): () => void;
6
6
  /** Elysia 2-native evlog integration built on evlog's public adapter toolkit. */
7
7
  export declare function createFurinEvlog(options: FurinEvlogOptions): import("elysia/types").GlobalHookReturn<"", "local", import("elysia").DefaultSingleton, {
8
8
  typebox: {};
@@ -2506,7 +2506,8 @@ var init_toolkit = __esm(() => {
2506
2506
  // src/server/evlog.ts
2507
2507
  import { Elysia } from "elysia";
2508
2508
  function setRuntimeEvlogWaitUntil(waitUntil) {
2509
- runtimeWaitUntil = waitUntil;
2509
+ runtimeWaitUntil.add(waitUntil);
2510
+ return () => runtimeWaitUntil.delete(waitUntil);
2510
2511
  }
2511
2512
  var loggerStorage, integration, getRequestLogger, runtimeWaitUntil;
2512
2513
  var init_evlog = __esm(() => {
@@ -2529,6 +2530,7 @@ var init_evlog = __esm(() => {
2529
2530
  storage: loggerStorage.storage
2530
2531
  });
2531
2532
  getRequestLogger = loggerStorage.useLogger;
2533
+ runtimeWaitUntil = new Set;
2532
2534
  });
2533
2535
 
2534
2536
  // src/server/instance.ts
@@ -0,0 +1,13 @@
1
+ import type { AnyElysia } from "elysia";
2
+ export interface ProductionServerOptions {
3
+ app: AnyElysia;
4
+ idleTimeout?: number;
5
+ onShutdown?: () => Promise<void> | void;
6
+ port: number;
7
+ preStopDelayMs?: number;
8
+ shutdownTimeoutMs?: number;
9
+ }
10
+ export declare function startProductionServer(options: ProductionServerOptions): {
11
+ server: Bun.Server<unknown>;
12
+ shutdown: () => Promise<void>;
13
+ };