@teyik0/furin 0.4.0-alpha.2 → 0.5.0-alpha.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.
Files changed (100) hide show
  1. package/dist/build/compile-entry.d.ts +2 -1
  2. package/dist/build/compile-entry.ts +17 -13
  3. package/dist/build/elysia-aot.d.ts +9 -0
  4. package/dist/build/entry-template.d.ts +5 -1
  5. package/dist/build/entry-template.ts +24 -5
  6. package/dist/build/index.js +753 -453
  7. package/dist/build/server-app-entry.d.ts +12 -0
  8. package/dist/cache.d.ts +1 -0
  9. package/dist/cache.js +185 -0
  10. package/dist/cli/index.js +766 -466
  11. package/dist/client/internal/runtime-types.d.ts +8 -1
  12. package/dist/client/link.js +221 -11
  13. package/dist/client/sync.d.ts +1 -0
  14. package/dist/config.d.ts +22 -21
  15. package/dist/config.js +1 -1
  16. package/dist/define-route.d.ts +273 -1009
  17. package/dist/furin.d.ts +20 -5
  18. package/dist/furin.js +6222 -5383
  19. package/dist/plugin/routes.d.ts +6 -0
  20. package/dist/server/assets/production.d.ts +3 -0
  21. package/dist/server/auto-invalidate/plugin.d.ts +8 -24
  22. package/dist/server/auto-invalidate/runtime.d.ts +2 -2
  23. package/dist/server/cache/invalidation.d.ts +1 -1
  24. package/dist/server/cache/page-cache-state.d.ts +5 -0
  25. package/dist/server/cache/page-cache.d.ts +53 -0
  26. package/dist/server/cache/redis/index.d.ts +39 -0
  27. package/dist/server/cache/redis/index.js +396 -0
  28. package/dist/server/cache/redis/scripts.d.ts +6 -0
  29. package/dist/server/context-logger.d.ts +2 -2
  30. package/dist/server/dev/runtime.production.d.ts +1 -0
  31. package/dist/server/dev-page-plugin.d.ts +7 -0
  32. package/dist/server/evlog.d.ts +14 -0
  33. package/dist/server/internal.d.ts +6 -0
  34. package/dist/server/internal.js +2537 -0
  35. package/dist/server/render/not-found.d.ts +1 -1
  36. package/dist/server/render/ssg.d.ts +5 -0
  37. package/dist/server/render/static-params.d.ts +4 -0
  38. package/dist/server/router/defined-route.d.ts +1 -1
  39. package/dist/server/router/schemas.d.ts +1 -0
  40. package/dist/server/sync/index.js +794 -116
  41. package/dist/server/sync/plugin.d.ts +31 -158
  42. package/dist/server/sync/stream.d.ts +34 -49
  43. package/dist/shared/elysia-contract.d.ts +8 -14
  44. package/package.json +13 -7
  45. package/src/adapter/README.md +9 -2
  46. package/src/adapter/bun.ts +73 -27
  47. package/src/adapter/package.ts +6 -2
  48. package/src/adapter/runtime-build.ts +11 -4
  49. package/src/adapter/static.ts +8 -6
  50. package/src/adapter/vercel.ts +49 -30
  51. package/src/build/client.ts +18 -1
  52. package/src/build/compile-entry.ts +17 -13
  53. package/src/build/elysia-aot.ts +102 -0
  54. package/src/build/entry-template.ts +24 -5
  55. package/src/build/index.ts +0 -5
  56. package/src/build/production-instrumentation.ts +2 -2
  57. package/src/build/server-app-entry.ts +60 -0
  58. package/src/build/shared.ts +3 -1
  59. package/src/build/ssg-cache.ts +5 -10
  60. package/src/build/virtual-entry.ts +5 -4
  61. package/src/cache.ts +12 -0
  62. package/src/cli/config.ts +3 -3
  63. package/src/cli/index.ts +5 -2
  64. package/src/client/internal/runtime-types.ts +10 -1
  65. package/src/client/sync.ts +1 -0
  66. package/src/config.ts +3 -2
  67. package/src/define-route.ts +266 -128
  68. package/src/furin.ts +138 -149
  69. package/src/plugin/route-config-autofix.ts +11 -2
  70. package/src/plugin/routes.ts +85 -29
  71. package/src/server/assets/production.ts +99 -0
  72. package/src/server/auto-invalidate/plugin.ts +4 -4
  73. package/src/server/auto-invalidate/runtime.ts +74 -42
  74. package/src/server/browser-events/plugin.ts +6 -1
  75. package/src/server/cache/invalidation.ts +61 -20
  76. package/src/server/cache/page-cache-state.ts +22 -0
  77. package/src/server/cache/page-cache.ts +300 -0
  78. package/src/server/cache/redis/index.ts +350 -0
  79. package/src/server/cache/redis/scripts.ts +160 -0
  80. package/src/server/context-logger.ts +5 -5
  81. package/src/server/dev/runtime.production.ts +4 -0
  82. package/src/server/dev-page-plugin.ts +54 -10
  83. package/src/server/evlog.ts +99 -0
  84. package/src/server/internal.ts +7 -0
  85. package/src/server/render/isr.ts +480 -132
  86. package/src/server/render/loaders.ts +18 -12
  87. package/src/server/render/not-found.ts +4 -4
  88. package/src/server/render/ppr-document.ts +2 -2
  89. package/src/server/render/ppr-route.ts +193 -7
  90. package/src/server/render/ssg.ts +148 -4
  91. package/src/server/render/ssr.ts +4 -6
  92. package/src/server/render/static-params.ts +174 -0
  93. package/src/server/router/defined-route.ts +2 -1
  94. package/src/server/router/hmr.ts +2 -0
  95. package/src/server/router/plugin.ts +44 -35
  96. package/src/server/router/schema-merge.ts +1 -1
  97. package/src/server/router/schemas.ts +174 -61
  98. package/src/server/sync/plugin.ts +14 -10
  99. package/src/server/sync/response.ts +3 -3
  100. package/src/shared/elysia-contract.ts +23 -25
@@ -17,8 +17,14 @@ export interface DevRouteTopologyWatcherOptions {
17
17
  onTopologyChange: (sourcePaths: readonly string[]) => Promise<void> | void;
18
18
  }
19
19
  export declare function routeModuleSpecifier(instance: RouteInstanceSpec): string;
20
+ export declare function composableRouteModuleSpecifier(instance: RouteInstanceSpec): string;
20
21
  export declare function routeSourcePaths(instance: RouteInstanceSpec): string[];
21
22
  export declare function registerDevRouteTopologyWatcher(options: DevRouteTopologyWatcherOptions): DevRouteTopologyWatcher;
23
+ /**
24
+ * Emits a real server route module for build-time consumers such as Elysia's
25
+ * AOT plugin, which imports the application outside Bun's virtual module graph.
26
+ */
27
+ export declare function materializedRouteModuleSource(instance: RouteInstanceSpec): Promise<string>;
22
28
  export declare function validateRouteParams(path: string, schemas: {
23
29
  params?: {
24
30
  properties?: object;
@@ -0,0 +1,3 @@
1
+ import { type AnyElysia } from "elysia";
2
+ import type { CompileContext, EmbeddedAppData } from "../internal.ts";
3
+ export declare function createProductionAssetsPlugin(ctx: CompileContext, embedded: EmbeddedAppData | undefined, clientDir: string): Promise<AnyElysia>;
@@ -1,38 +1,22 @@
1
- import { type AfterHandler, Elysia } from "elysia";
1
+ import { Elysia } from "elysia";
2
+ import { isSuccessfulMutationResponse } from "./runtime.ts";
2
3
  import type { InvalidationInput } from "./types.ts";
3
- type AnyAfterHandleContext = Parameters<AfterHandler>[0];
4
- export declare function furinInvalidate(): Elysia<"", {
5
- decorator: {};
6
- store: {};
7
- derive: {};
8
- resolve: {};
9
- }, {
4
+ type AnyAfterHandleContext = Parameters<typeof isSuccessfulMutationResponse>[0];
5
+ export declare function furinInvalidate(): Elysia<"", "local", import("elysia").DefaultSingleton, {
10
6
  typebox: {};
11
- error: {};
7
+ error: [];
12
8
  }, {
13
9
  schema: {};
14
- standaloneSchema: {};
10
+ schemas: {};
15
11
  macro: Partial<{
16
12
  readonly invalidate: InvalidationInput;
17
13
  }>;
18
14
  macroFn: {
19
15
  readonly invalidate: (rules: InvalidationInput) => {
20
- readonly afterHandle: (ctx: AnyAfterHandleContext) => void;
16
+ afterHandle(ctx: AnyAfterHandleContext): Promise<void>;
21
17
  };
22
18
  };
23
19
  parser: {};
24
20
  response: {};
25
- }, {}, {
26
- derive: {};
27
- resolve: {};
28
- schema: {};
29
- standaloneSchema: {};
30
- response: {};
31
- }, {
32
- derive: {};
33
- resolve: {};
34
- schema: {};
35
- standaloneSchema: {};
36
- response: {};
37
- }>;
21
+ }, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral>;
38
22
  export {};
@@ -5,5 +5,5 @@ export declare function isSuccessfulMutationResponse(ctx: Pick<Context, "set"> &
5
5
  response?: unknown;
6
6
  }): boolean;
7
7
  export declare function appendPendingInvalidationHeader(set: Context["set"]): string[];
8
- export declare function revalidateTag(tags: string | readonly string[]): boolean;
9
- export declare function runInvalidationRules(input: InvalidationInput): boolean;
8
+ export declare function revalidateTag(tags: string | readonly string[]): Promise<boolean>;
9
+ export declare function runInvalidationRules(input: InvalidationInput): Promise<boolean>;
@@ -13,7 +13,7 @@ export declare function callCachePurger(paths: string[]): void;
13
13
  * instance's invalidation runs inside its own scope so cache `onDelete` hooks
14
14
  * (auto-invalidate unregistration) hit the owning instance's registry.
15
15
  */
16
- export declare function revalidatePath(path: string, type: RevalidateType): boolean;
16
+ export declare function revalidatePath(path: string, type: RevalidateType): Promise<boolean>;
17
17
  /**
18
18
  * Invalidates `path` against a SINGLE instance's caches. `revalidateTag` uses
19
19
  * this because it knows which instance registered each path — the cross-app
@@ -0,0 +1,5 @@
1
+ import { type FurinInstance } from "../instance.ts";
2
+ import type { PageCacheAdapter } from "./page-cache.ts";
3
+ export declare function getPageCacheAdapter(instance?: FurinInstance): PageCacheAdapter | undefined;
4
+ export declare function setPageCacheAdapter(instance: FurinInstance, adapter: PageCacheAdapter): void;
5
+ export declare function resetPageCacheAdapter(instance: FurinInstance): void;
@@ -0,0 +1,53 @@
1
+ export type PageCacheMode = "isr" | "ppr" | "ssg";
2
+ export interface PageCacheIdentity {
3
+ buildId: string;
4
+ key: string;
5
+ mode: PageCacheMode;
6
+ path: string;
7
+ scope: string;
8
+ tags: readonly string[];
9
+ }
10
+ export interface PageCacheEntry {
11
+ cachedAt: number;
12
+ payload: string;
13
+ revalidate: number | null;
14
+ }
15
+ export interface PageCacheLease {
16
+ expiresAt: number;
17
+ fence: number;
18
+ id: string;
19
+ revision: string;
20
+ }
21
+ export type PageCacheInvalidation = {
22
+ kind: "path";
23
+ path: string;
24
+ scope: string;
25
+ type: "layout" | "page";
26
+ } | {
27
+ kind: "tags";
28
+ scope: string;
29
+ tags: readonly string[];
30
+ };
31
+ export interface PageCacheInvalidationResult {
32
+ invalidated: boolean;
33
+ paths: readonly string[];
34
+ }
35
+ export interface PageCacheAdapter {
36
+ acquire: (input: {
37
+ identity: PageCacheIdentity;
38
+ leaseMs: number;
39
+ }) => Promise<PageCacheLease | null>;
40
+ commit: (input: {
41
+ entry: PageCacheEntry;
42
+ identity: PageCacheIdentity;
43
+ lease: PageCacheLease;
44
+ }) => Promise<"stored" | "superseded">;
45
+ invalidate: (input: PageCacheInvalidation) => Promise<PageCacheInvalidationResult>;
46
+ read: (identity: PageCacheIdentity) => Promise<PageCacheEntry | null>;
47
+ release: (input: {
48
+ identity: PageCacheIdentity;
49
+ lease: PageCacheLease;
50
+ }) => Promise<void>;
51
+ }
52
+ export declare function waitForPageCacheEntry(adapter: PageCacheAdapter, identity: PageCacheIdentity, timeoutMs: number): Promise<PageCacheEntry | null>;
53
+ export declare function createMemoryPageCache(): PageCacheAdapter;
@@ -0,0 +1,39 @@
1
+ import type { RedisClient } from "bun";
2
+ import type { PageCacheAdapter, PageCacheEntry, PageCacheIdentity, PageCacheLease } from "../page-cache.ts";
3
+ export interface RedisPageCacheOptions {
4
+ client: RedisClient;
5
+ namespace: string;
6
+ retentionMs?: number;
7
+ }
8
+ export declare class RedisPageCache implements PageCacheAdapter {
9
+ private readonly client;
10
+ private readonly metadataRetentionMs;
11
+ private readonly prefix;
12
+ private readonly retentionMs;
13
+ constructor(options: RedisPageCacheOptions);
14
+ acquire({ identity, leaseMs, }: {
15
+ identity: PageCacheIdentity;
16
+ leaseMs: number;
17
+ }): Promise<PageCacheLease | null>;
18
+ commit({ entry, identity, lease, }: {
19
+ entry: PageCacheEntry;
20
+ identity: PageCacheIdentity;
21
+ lease: PageCacheLease;
22
+ }): Promise<"stored" | "superseded">;
23
+ invalidate(input: Parameters<PageCacheAdapter["invalidate"]>[0]): Promise<{
24
+ invalidated: boolean;
25
+ paths: string[];
26
+ }>;
27
+ read(identity: PageCacheIdentity): Promise<PageCacheEntry | null>;
28
+ release({ identity, lease, }: {
29
+ identity: PageCacheIdentity;
30
+ lease: PageCacheLease;
31
+ }): Promise<void>;
32
+ private entryKey;
33
+ private fenceKey;
34
+ private leaseKey;
35
+ private pathsKey;
36
+ private tagPathsKey;
37
+ private versionsKey;
38
+ }
39
+ export declare function redisPageCache(options: RedisPageCacheOptions): PageCacheAdapter;
@@ -0,0 +1,396 @@
1
+ // @bun
2
+ // src/server/cache/redis/scripts.ts
3
+ var ACQUIRE_PAGE_CACHE_LEASE_SCRIPT = `
4
+ local raw = redis.call('GET', KEYS[1])
5
+ local now_parts = redis.call('TIME')
6
+ local now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)
7
+ if raw then
8
+ local active = cjson.decode(raw)
9
+ if active.expiresAt > now then return nil end
10
+ end
11
+ local fence = redis.call('INCR', KEYS[2])
12
+ redis.call('PEXPIRE', KEYS[2], ARGV[4])
13
+ local fields = cjson.decode(ARGV[3])
14
+ local values = {}
15
+ for index, field in ipairs(fields) do
16
+ values[index] = tonumber(redis.call('HGET', KEYS[3], field) or '0')
17
+ end
18
+ redis.call('PEXPIRE', KEYS[3], ARGV[4])
19
+ local lease = {
20
+ expiresAt = now + tonumber(ARGV[2]),
21
+ fence = fence,
22
+ fields = fields,
23
+ id = ARGV[1],
24
+ values = values
25
+ }
26
+ redis.call('SET', KEYS[1], cjson.encode(lease), 'PX', ARGV[2])
27
+ return cjson.encode(lease)
28
+ `;
29
+ var COMMIT_PAGE_CACHE_ENTRY_SCRIPT = `
30
+ local raw = redis.call('GET', KEYS[1])
31
+ if not raw then return 'superseded' end
32
+ local lease = cjson.decode(raw)
33
+ local now_parts = redis.call('TIME')
34
+ local now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)
35
+ if lease.id ~= ARGV[1] or lease.fence ~= tonumber(ARGV[2]) or lease.expiresAt <= now then
36
+ return 'superseded'
37
+ end
38
+ for index, field in ipairs(lease.fields) do
39
+ local current = tonumber(redis.call('HGET', KEYS[3], field) or '0')
40
+ if current ~= lease.values[index] then
41
+ redis.call('DEL', KEYS[1])
42
+ return 'superseded'
43
+ end
44
+ end
45
+ local previous_raw = redis.call('GET', KEYS[2])
46
+ if previous_raw then
47
+ local previous = cjson.decode(previous_raw)
48
+ if previous.indexMember then
49
+ redis.call('ZREM', previous.pathsKey, previous.indexMember)
50
+ for _, tag_key in ipairs(previous.tagKeys) do
51
+ redis.call('ZREM', tag_key, previous.indexMember)
52
+ end
53
+ end
54
+ end
55
+ local expires_at = now + tonumber(ARGV[5])
56
+ redis.call('SET', KEYS[2], ARGV[3], 'PX', ARGV[5])
57
+ redis.call('ZREMRANGEBYSCORE', KEYS[4], '-inf', now)
58
+ redis.call('ZADD', KEYS[4], expires_at, ARGV[4])
59
+ redis.call('PEXPIRE', KEYS[4], ARGV[6])
60
+ for index = 5, #KEYS do
61
+ redis.call('ZREMRANGEBYSCORE', KEYS[index], '-inf', now)
62
+ redis.call('ZADD', KEYS[index], expires_at, ARGV[4])
63
+ redis.call('PEXPIRE', KEYS[index], ARGV[6])
64
+ end
65
+ redis.call('PEXPIRE', KEYS[3], ARGV[6])
66
+ redis.call('DEL', KEYS[1])
67
+ return 'stored'
68
+ `;
69
+ var READ_PAGE_CACHE_ENTRY_SCRIPT = `
70
+ local raw = redis.call('GET', KEYS[1])
71
+ if not raw then return nil end
72
+ local value = cjson.decode(raw)
73
+ for index, field in ipairs(value.fields) do
74
+ local current = tonumber(redis.call('HGET', KEYS[2], field) or '0')
75
+ if current ~= value.values[index] then
76
+ redis.call('DEL', KEYS[1])
77
+ if value.indexMember then
78
+ redis.call('ZREM', value.pathsKey, value.indexMember)
79
+ for _, tag_key in ipairs(value.tagKeys) do
80
+ redis.call('ZREM', tag_key, value.indexMember)
81
+ end
82
+ end
83
+ return nil
84
+ end
85
+ end
86
+ return raw
87
+ `;
88
+ var RELEASE_PAGE_CACHE_LEASE_SCRIPT = `
89
+ local raw = redis.call('GET', KEYS[1])
90
+ if not raw then return 0 end
91
+ local lease = cjson.decode(raw)
92
+ if lease.id == ARGV[1] and lease.fence == tonumber(ARGV[2]) then
93
+ return redis.call('DEL', KEYS[1])
94
+ end
95
+ return 0
96
+ `;
97
+ var INVALIDATE_PAGE_CACHE_PATH_SCRIPT = `
98
+ redis.call('HINCRBY', KEYS[1], ARGV[1], 1)
99
+ redis.call('PEXPIRE', KEYS[1], ARGV[4])
100
+ local now_parts = redis.call('TIME')
101
+ local now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)
102
+ redis.call('ZREMRANGEBYSCORE', KEYS[2], '-inf', now)
103
+ local members = redis.call('ZRANGE', KEYS[2], 0, -1)
104
+ local seen = {}
105
+ local affected = {}
106
+ for _, member in ipairs(members) do
107
+ 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
113
+ redis.call('DEL', index.entryKey)
114
+ redis.call('ZREM', index.pathsKey, member)
115
+ for _, tag_key in ipairs(index.tagKeys) do
116
+ redis.call('ZREM', tag_key, member)
117
+ end
118
+ if not seen[index.path] then
119
+ seen[index.path] = true
120
+ table.insert(affected, index.path)
121
+ end
122
+ end
123
+ end
124
+ return affected
125
+ `;
126
+ var INVALIDATE_PAGE_CACHE_TAGS_SCRIPT = `
127
+ local tags = cjson.decode(ARGV[1])
128
+ for _, tag in ipairs(tags) do
129
+ redis.call('HINCRBY', KEYS[1], 'tag:' .. tag, 1)
130
+ end
131
+ redis.call('PEXPIRE', KEYS[1], ARGV[2])
132
+ local now_parts = redis.call('TIME')
133
+ local now = tonumber(now_parts[1]) * 1000 + math.floor(tonumber(now_parts[2]) / 1000)
134
+ local seen_members = {}
135
+ local seen_paths = {}
136
+ local affected = {}
137
+ for key_index = 3, #KEYS do
138
+ redis.call('ZREMRANGEBYSCORE', KEYS[key_index], '-inf', now)
139
+ local members = redis.call('ZRANGE', KEYS[key_index], 0, -1)
140
+ for _, member in ipairs(members) do
141
+ if not seen_members[member] then
142
+ seen_members[member] = true
143
+ local index = cjson.decode(member)
144
+ redis.call('DEL', index.entryKey)
145
+ redis.call('ZREM', index.pathsKey, member)
146
+ for _, tag_key in ipairs(index.tagKeys) do
147
+ redis.call('ZREM', tag_key, member)
148
+ end
149
+ if not seen_paths[index.path] then
150
+ seen_paths[index.path] = true
151
+ table.insert(affected, index.path)
152
+ end
153
+ end
154
+ end
155
+ end
156
+ return affected
157
+ `;
158
+
159
+ // src/server/cache/redis/index.ts
160
+ var TRAILING_SLASHES = /\/+$/;
161
+ var DEFAULT_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
162
+ var METADATA_GRACE_MS = 24 * 60 * 60 * 1000;
163
+ function assertNamespace(namespace) {
164
+ if (namespace.length === 0) {
165
+ throw new Error("[furin-page-cache-redis] namespace must not be empty.");
166
+ }
167
+ if (!namespace.isWellFormed()) {
168
+ throw new Error("[furin-page-cache-redis] namespace must contain valid Unicode.");
169
+ }
170
+ }
171
+ function digest(value) {
172
+ return new Bun.CryptoHasher("sha256").update(value).digest("hex");
173
+ }
174
+ function identityDigest(identity) {
175
+ return digest(JSON.stringify([identity.scope, identity.buildId, identity.mode, identity.key]));
176
+ }
177
+ function layoutPaths(path) {
178
+ if (path === "/") {
179
+ return ["/"];
180
+ }
181
+ const paths = ["/"];
182
+ let current = "";
183
+ for (const segment of path.split("/").filter(Boolean)) {
184
+ current += `/${segment}`;
185
+ paths.push(current);
186
+ }
187
+ return paths;
188
+ }
189
+ function normalizeInvalidationPath(path) {
190
+ return path.length > 1 ? path.replace(TRAILING_SLASHES, "") : path;
191
+ }
192
+ function selectorFields(identity) {
193
+ return [
194
+ `page:${identity.path}`,
195
+ ...layoutPaths(identity.path).map((path) => `layout:${path}`),
196
+ ...identity.tags.map((tag) => `tag:${tag}`)
197
+ ];
198
+ }
199
+ function stringResult(value, operation) {
200
+ if (typeof value !== "string") {
201
+ throw new Error(`[furin-page-cache-redis] Invalid ${operation} response.`);
202
+ }
203
+ return value;
204
+ }
205
+ function stringArrayResult(value, operation) {
206
+ if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string")) {
207
+ throw new Error(`[furin-page-cache-redis] Invalid ${operation} response.`);
208
+ }
209
+ return value;
210
+ }
211
+ function parseLease(raw) {
212
+ const value = JSON.parse(raw);
213
+ if (typeof value !== "object" || value === null || !("expiresAt" in value) || typeof value.expiresAt !== "number" || !("fence" in value) || typeof value.fence !== "number" || !("fields" in value) || !Array.isArray(value.fields) || value.fields.some((field) => typeof field !== "string") || !("id" in value) || typeof value.id !== "string" || !("values" in value) || !Array.isArray(value.values) || value.values.some((revision) => typeof revision !== "number")) {
214
+ throw new Error("[furin-page-cache-redis] Invalid lease document.");
215
+ }
216
+ return value;
217
+ }
218
+ function parseEntry(raw) {
219
+ const value = JSON.parse(raw);
220
+ if (typeof value !== "object" || value === null || !("entry" in value) || typeof value.entry !== "object" || value.entry === null || !("cachedAt" in value.entry) || typeof value.entry.cachedAt !== "number" || !("payload" in value.entry) || typeof value.entry.payload !== "string" || !("revalidate" in value.entry) || typeof value.entry.revalidate !== "number" && value.entry.revalidate !== null) {
221
+ throw new Error("[furin-page-cache-redis] Invalid cache entry document.");
222
+ }
223
+ return value.entry;
224
+ }
225
+
226
+ class RedisPageCache {
227
+ client;
228
+ metadataRetentionMs;
229
+ prefix;
230
+ retentionMs;
231
+ constructor(options) {
232
+ assertNamespace(options.namespace);
233
+ const retentionMs = options.retentionMs ?? DEFAULT_RETENTION_MS;
234
+ if (!Number.isSafeInteger(retentionMs) || retentionMs <= 0 || retentionMs > Number.MAX_SAFE_INTEGER - METADATA_GRACE_MS) {
235
+ throw new Error("[furin-page-cache-redis] retentionMs must be a positive safe integer.");
236
+ }
237
+ this.client = options.client;
238
+ this.prefix = `furin:page:{${encodeURIComponent(options.namespace)}}`;
239
+ this.retentionMs = retentionMs;
240
+ this.metadataRetentionMs = retentionMs + METADATA_GRACE_MS;
241
+ }
242
+ async acquire({
243
+ identity,
244
+ leaseMs
245
+ }) {
246
+ const id = crypto.randomUUID();
247
+ const keys = [
248
+ this.leaseKey(identity),
249
+ this.fenceKey(identity),
250
+ this.versionsKey(identity.scope)
251
+ ];
252
+ const raw = await this.client.send("EVAL", [
253
+ ACQUIRE_PAGE_CACHE_LEASE_SCRIPT,
254
+ String(keys.length),
255
+ ...keys,
256
+ id,
257
+ String(leaseMs),
258
+ JSON.stringify(selectorFields(identity)),
259
+ String(this.metadataRetentionMs)
260
+ ]);
261
+ if (raw === null) {
262
+ return null;
263
+ }
264
+ const lease = parseLease(stringResult(raw, "lease acquisition"));
265
+ return {
266
+ expiresAt: lease.expiresAt,
267
+ fence: lease.fence,
268
+ id: lease.id,
269
+ revision: JSON.stringify(lease.values)
270
+ };
271
+ }
272
+ async commit({
273
+ entry,
274
+ identity,
275
+ lease
276
+ }) {
277
+ const tagKeys = [...new Set(identity.tags)].map((tag) => this.tagPathsKey(identity.scope, tag));
278
+ const entryKey = this.entryKey(identity);
279
+ const pathsKey = this.pathsKey(identity.scope);
280
+ const indexMember = JSON.stringify({
281
+ entryKey,
282
+ path: identity.path,
283
+ pathsKey,
284
+ tagKeys
285
+ });
286
+ const document = {
287
+ entry,
288
+ fields: selectorFields(identity),
289
+ indexMember,
290
+ pathsKey,
291
+ tagKeys,
292
+ values: JSON.parse(lease.revision)
293
+ };
294
+ const keys = [
295
+ this.leaseKey(identity),
296
+ entryKey,
297
+ this.versionsKey(identity.scope),
298
+ pathsKey,
299
+ ...tagKeys
300
+ ];
301
+ const result = await this.client.send("EVAL", [
302
+ COMMIT_PAGE_CACHE_ENTRY_SCRIPT,
303
+ String(keys.length),
304
+ ...keys,
305
+ lease.id,
306
+ String(lease.fence),
307
+ JSON.stringify(document),
308
+ indexMember,
309
+ String(this.retentionMs),
310
+ String(this.metadataRetentionMs)
311
+ ]);
312
+ if (result === "stored" || result === "superseded") {
313
+ return result;
314
+ }
315
+ throw new Error("[furin-page-cache-redis] Invalid cache commit response.");
316
+ }
317
+ async invalidate(input) {
318
+ if (input.kind === "path") {
319
+ const path = normalizeInvalidationPath(input.path);
320
+ const result = stringArrayResult(await this.client.send("EVAL", [
321
+ INVALIDATE_PAGE_CACHE_PATH_SCRIPT,
322
+ "2",
323
+ this.versionsKey(input.scope),
324
+ this.pathsKey(input.scope),
325
+ `${input.type}:${path}`,
326
+ path,
327
+ input.type,
328
+ String(this.metadataRetentionMs)
329
+ ]), "path invalidation");
330
+ return { invalidated: result.length > 0, paths: result };
331
+ }
332
+ const tags = [...new Set(input.tags)];
333
+ const keys = [
334
+ this.versionsKey(input.scope),
335
+ this.pathsKey(input.scope),
336
+ ...tags.map((tag) => this.tagPathsKey(input.scope, tag))
337
+ ];
338
+ const result = stringArrayResult(await this.client.send("EVAL", [
339
+ INVALIDATE_PAGE_CACHE_TAGS_SCRIPT,
340
+ String(keys.length),
341
+ ...keys,
342
+ JSON.stringify(tags),
343
+ String(this.metadataRetentionMs)
344
+ ]), "tag invalidation");
345
+ return { invalidated: result.length > 0, paths: result };
346
+ }
347
+ async read(identity) {
348
+ const raw = await this.client.send("EVAL", [
349
+ READ_PAGE_CACHE_ENTRY_SCRIPT,
350
+ "2",
351
+ this.entryKey(identity),
352
+ this.versionsKey(identity.scope)
353
+ ]);
354
+ if (raw === null) {
355
+ return null;
356
+ }
357
+ return parseEntry(stringResult(raw, "cache read"));
358
+ }
359
+ async release({
360
+ identity,
361
+ lease
362
+ }) {
363
+ await this.client.send("EVAL", [
364
+ RELEASE_PAGE_CACHE_LEASE_SCRIPT,
365
+ "1",
366
+ this.leaseKey(identity),
367
+ lease.id,
368
+ String(lease.fence)
369
+ ]);
370
+ }
371
+ entryKey(identity) {
372
+ return `${this.prefix}:entry:${identityDigest(identity)}`;
373
+ }
374
+ fenceKey(identity) {
375
+ return `${this.prefix}:fence:${identityDigest(identity)}`;
376
+ }
377
+ leaseKey(identity) {
378
+ return `${this.prefix}:lease:${identityDigest(identity)}`;
379
+ }
380
+ pathsKey(scope) {
381
+ return `${this.prefix}:paths:${digest(scope)}`;
382
+ }
383
+ tagPathsKey(scope, tag) {
384
+ return `${this.prefix}:tag-paths:${digest(scope)}:${digest(tag)}`;
385
+ }
386
+ versionsKey(scope) {
387
+ return `${this.prefix}:versions:${digest(scope)}`;
388
+ }
389
+ }
390
+ function redisPageCache(options) {
391
+ return new RedisPageCache(options);
392
+ }
393
+ export {
394
+ RedisPageCache,
395
+ redisPageCache
396
+ };
@@ -0,0 +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";
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";
@@ -13,12 +13,12 @@ export { createLogger };
13
13
  * Import from `@teyik0/furin` instead of `evlog/elysia` so this fallback chain
14
14
  * applies in all rendering contexts.
15
15
  */
16
- export declare function useLogger(): RequestLogger;
16
+ export declare function getLogger(): RequestLogger;
17
17
  /**
18
18
  * Runs `fn` inside a synthetic render scope.
19
19
  *
20
20
  * Creates a detached `createLogger()` instance for the duration of `fn`.
21
- * `useLogger()` calls inside `fn` (including user loaders) return this logger
21
+ * `getLogger()` calls inside `fn` (including user loaders) return this logger
22
22
  * instead of throwing. On completion, the accumulated wide event is emitted to
23
23
  * the global drain with the provided initial context (e.g. route pattern).
24
24
  *
@@ -2,4 +2,5 @@ import { type AnyElysia } from "elysia";
2
2
  export declare function createDevDiagnosticPlugin(_store: undefined, _instance: unknown, _reconcileRoutes: unknown): AnyElysia;
3
3
  export declare function createDevelopmentBrowserEventSources(_instance: unknown, _diagnostics: undefined): readonly never[];
4
4
  export declare function devDiagnosticStore(): undefined;
5
+ export declare function devGraph(): never;
5
6
  export declare function injectDevDiagnosticClient(html: string, _basePath: string): string;
@@ -53,6 +53,10 @@
53
53
  * rewritten while string literals in non-import positions are left untouched.
54
54
  */
55
55
  export declare const WORKSPACE_SOURCE_FILTER: RegExp;
56
+ interface CachedDevPageContents {
57
+ contents: string;
58
+ moduleIdentity: string;
59
+ }
56
60
  /** Converts a native absolute path to Bun's cross-platform import format. */
57
61
  export declare function toImportSpecifier(filePath: string): string;
58
62
  /**
@@ -115,4 +119,7 @@ export declare function transformDevSource(raw: string, filePath: string, option
115
119
  rewriteBareImports: boolean;
116
120
  rewriteRelativeImports: boolean;
117
121
  }): string;
122
+ /** @internal exported for testing */
123
+ export declare function loadDevPageContents(filePath: string, moduleIdentity: string, transformedSourceCache: Map<string, CachedDevPageContents>): Promise<string>;
118
124
  export declare function registerDevPagePlugin(): void;
125
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { RequestLogger } from "evlog";
2
+ import { type BaseEvlogOptions } from "evlog/toolkit";
3
+ export type FurinEvlogOptions = BaseEvlogOptions;
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;
6
+ /** Elysia 2-native evlog integration built on evlog's public adapter toolkit. */
7
+ export declare function createFurinEvlog(options: FurinEvlogOptions): import("elysia/types").GlobalHookReturn<"", "local", import("elysia").DefaultSingleton, {
8
+ typebox: {};
9
+ error: [];
10
+ }, import("elysia").DefaultMetadata, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral, import("elysia/types").ExtractErrorFromHandle<{
11
+ readonly log: RequestLogger<Record<string, unknown>>;
12
+ }>, {
13
+ readonly log: RequestLogger<Record<string, unknown>>;
14
+ }>;