@teyik0/furin 0.2.0-alpha.3 → 0.2.0-alpha.4

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 (54) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +37 -33
  3. package/dist/build/compile-entry.ts +109 -109
  4. package/dist/build/entry-template.ts +156 -156
  5. package/dist/build/server-routes-entry.ts +36 -36
  6. package/dist/cli/index.js +0 -0
  7. package/dist/client/link.js +163 -16
  8. package/dist/client/router/abort.d.ts +1 -0
  9. package/dist/client/router/sync-catch-up.d.ts +29 -0
  10. package/dist/furin.d.ts +1 -1
  11. package/dist/furin.js +499 -215
  12. package/dist/server/sync/adapter.d.ts +62 -0
  13. package/dist/server/sync/fingerprint.d.ts +6 -0
  14. package/dist/server/sync/index.d.ts +2 -2
  15. package/dist/server/sync/memory-adapter.d.ts +17 -0
  16. package/dist/server/sync/plugin.d.ts +12 -195
  17. package/dist/server/sync/response.d.ts +4 -0
  18. package/dist/server/sync/stream.d.ts +16 -4
  19. package/package.json +1 -1
  20. package/src/adapter/README.md +13 -13
  21. package/src/build/client.ts +152 -152
  22. package/src/build/compile-entry.ts +109 -109
  23. package/src/build/entry-template.ts +156 -156
  24. package/src/build/hydrate.ts +340 -340
  25. package/src/build/index.ts +152 -152
  26. package/src/build/route-types.ts +145 -145
  27. package/src/build/scan-server.ts +95 -95
  28. package/src/build/server-routes-entry.ts +36 -36
  29. package/src/build/shared.ts +80 -80
  30. package/src/build/ssg-cache.ts +32 -32
  31. package/src/build/types.ts +89 -89
  32. package/src/client/router/abort.ts +5 -0
  33. package/src/client/router/link-utils.ts +184 -184
  34. package/src/client/router/provider.tsx +883 -804
  35. package/src/client/router/sync-catch-up.ts +113 -0
  36. package/src/client/router/types.ts +276 -276
  37. package/src/client/sync.ts +98 -98
  38. package/src/client.ts +369 -369
  39. package/src/furin.ts +465 -465
  40. package/src/server/auto-invalidate/runtime.ts +134 -134
  41. package/src/server/dev-page-plugin.ts +454 -454
  42. package/src/server/render/assemble.ts +160 -160
  43. package/src/server/render/isr.ts +323 -323
  44. package/src/server/render/ssr.ts +591 -585
  45. package/src/server/router/plugin.ts +384 -384
  46. package/src/server/sync/adapter.ts +65 -0
  47. package/src/server/sync/config.ts +29 -29
  48. package/src/server/sync/fingerprint.ts +44 -0
  49. package/src/server/sync/index.ts +15 -14
  50. package/src/server/sync/memory-adapter.ts +196 -0
  51. package/src/server/sync/plugin.ts +200 -108
  52. package/src/server/sync/response.ts +77 -0
  53. package/src/server/sync/stream.ts +152 -144
  54. package/src/shared/deferred-ndjson.ts +7 -0
@@ -1,134 +1,134 @@
1
- import type { Context } from "elysia";
2
- import { consumePendingInvalidations, revalidatePath } from "../cache/invalidation.ts";
3
- import { autoInvalidateRegistry } from "./registry.ts";
4
- import type { InvalidationInput, InvalidationRule } from "./types.ts";
5
-
6
- function toRules(input: InvalidationInput): readonly InvalidationRule[] {
7
- return Array.isArray(input) ? input : [input as InvalidationRule];
8
- }
9
-
10
- function statusFromResponseValue(responseValue: unknown): number | undefined {
11
- if (responseValue instanceof Response) {
12
- return responseValue.status;
13
- }
14
- if (responseValue && typeof responseValue === "object" && "status" in responseValue) {
15
- const status = (responseValue as { status?: unknown }).status;
16
- if (typeof status === "number") {
17
- return status;
18
- }
19
- }
20
- if (responseValue && typeof responseValue === "object" && "code" in responseValue) {
21
- const code = (responseValue as { code?: unknown }).code;
22
- if (typeof code === "number") {
23
- return code;
24
- }
25
- }
26
- return;
27
- }
28
-
29
- export function isSuccessfulMutationResponse(
30
- ctx: Pick<Context, "set"> & {
31
- responseValue?: unknown;
32
- response?: unknown;
33
- }
34
- ): boolean {
35
- const responseStatus =
36
- statusFromResponseValue(ctx.responseValue) ?? statusFromResponseValue(ctx.response);
37
- if (responseStatus !== undefined) {
38
- return responseStatus >= 200 && responseStatus < 400;
39
- }
40
-
41
- const setStatus = ctx.set.status;
42
- if (typeof setStatus === "number") {
43
- return setStatus >= 200 && setStatus < 400;
44
- }
45
- if (typeof setStatus === "string") {
46
- // Elysia allows string status codes (e.g. "Not Found"). We cannot map
47
- // every possible string to its numeric code without the StatusMap, so we
48
- // treat known client-error (4xx) and server-error (5xx) texts as failures
49
- // and everything else as success (1xx, 2xx, 3xx, and any unknown string).
50
- const errorStatusTexts = new Set([
51
- "Bad Request",
52
- "Unauthorized",
53
- "Payment Required",
54
- "Forbidden",
55
- "Not Found",
56
- "Method Not Allowed",
57
- "Not Acceptable",
58
- "Proxy Authentication Required",
59
- "Request Timeout",
60
- "Conflict",
61
- "Gone",
62
- "Length Required",
63
- "Precondition Failed",
64
- "Payload Too Large",
65
- "URI Too Long",
66
- "Unsupported Media Type",
67
- "Range Not Satisfiable",
68
- "Expectation Failed",
69
- "I'm a teapot",
70
- "Misdirected Request",
71
- "Unprocessable Content",
72
- "Locked",
73
- "Failed Dependency",
74
- "Too Early",
75
- "Upgrade Required",
76
- "Precondition Required",
77
- "Too Many Requests",
78
- "Enhance Your Calm",
79
- "Request Header Fields Too Large",
80
- "Unavailable For Legal Reasons",
81
- "Internal Server Error",
82
- "Not Implemented",
83
- "Bad Gateway",
84
- "Service Unavailable",
85
- "Gateway Timeout",
86
- "HTTP Version Not Supported",
87
- "Variant Also Negotiates",
88
- "Insufficient Storage",
89
- "Loop Detected",
90
- "Not Extended",
91
- "Network Authentication Required",
92
- ]);
93
- return !errorStatusTexts.has(setStatus);
94
- }
95
- // No explicit status was set — default to success (200).
96
- return true;
97
- }
98
-
99
- export function appendPendingInvalidationHeader(set: Context["set"]): string[] {
100
- const pending = consumePendingInvalidations();
101
- if (pending.length === 0) {
102
- return [];
103
- }
104
-
105
- const headerName = "x-furin-revalidate";
106
- const existing = set.headers[headerName];
107
- set.headers[headerName] =
108
- typeof existing === "string" && existing.length > 0
109
- ? `${existing},${pending.join(",")}`
110
- : pending.join(",");
111
- return pending;
112
- }
113
-
114
- export function revalidateTag(tags: string | readonly string[]): boolean {
115
- const tagList = typeof tags === "string" ? [tags] : [...tags];
116
- let deleted = false;
117
- for (const path of autoInvalidateRegistry.pathsForTags(tagList)) {
118
- deleted = revalidatePath(path, "page") || deleted;
119
- }
120
- return deleted;
121
- }
122
-
123
- export function runInvalidationRules(input: InvalidationInput): boolean {
124
- let deleted = false;
125
- for (const rule of toRules(input)) {
126
- if ("path" in rule && rule.path) {
127
- deleted = revalidatePath(rule.path, rule.type) || deleted;
128
- }
129
- if (rule.tags && rule.tags.length > 0) {
130
- deleted = revalidateTag(rule.tags) || deleted;
131
- }
132
- }
133
- return deleted;
134
- }
1
+ import type { Context } from "elysia";
2
+ import { consumePendingInvalidations, revalidatePath } from "../cache/invalidation.ts";
3
+ import { autoInvalidateRegistry } from "./registry.ts";
4
+ import type { InvalidationInput, InvalidationRule } from "./types.ts";
5
+
6
+ function toRules(input: InvalidationInput): readonly InvalidationRule[] {
7
+ return Array.isArray(input) ? input : [input as InvalidationRule];
8
+ }
9
+
10
+ function statusFromResponseValue(responseValue: unknown): number | undefined {
11
+ if (responseValue instanceof Response) {
12
+ return responseValue.status;
13
+ }
14
+ if (responseValue && typeof responseValue === "object" && "status" in responseValue) {
15
+ const status = (responseValue as { status?: unknown }).status;
16
+ if (typeof status === "number") {
17
+ return status;
18
+ }
19
+ }
20
+ if (responseValue && typeof responseValue === "object" && "code" in responseValue) {
21
+ const code = (responseValue as { code?: unknown }).code;
22
+ if (typeof code === "number") {
23
+ return code;
24
+ }
25
+ }
26
+ return;
27
+ }
28
+
29
+ export function isSuccessfulMutationResponse(
30
+ ctx: Pick<Context, "set"> & {
31
+ responseValue?: unknown;
32
+ response?: unknown;
33
+ }
34
+ ): boolean {
35
+ const responseStatus =
36
+ statusFromResponseValue(ctx.responseValue) ?? statusFromResponseValue(ctx.response);
37
+ if (responseStatus !== undefined) {
38
+ return responseStatus >= 200 && responseStatus < 400;
39
+ }
40
+
41
+ const setStatus = ctx.set.status;
42
+ if (typeof setStatus === "number") {
43
+ return setStatus >= 200 && setStatus < 400;
44
+ }
45
+ if (typeof setStatus === "string") {
46
+ // Elysia allows string status codes (e.g. "Not Found"). We cannot map
47
+ // every possible string to its numeric code without the StatusMap, so we
48
+ // treat known client-error (4xx) and server-error (5xx) texts as failures
49
+ // and everything else as success (1xx, 2xx, 3xx, and any unknown string).
50
+ const errorStatusTexts = new Set([
51
+ "Bad Request",
52
+ "Unauthorized",
53
+ "Payment Required",
54
+ "Forbidden",
55
+ "Not Found",
56
+ "Method Not Allowed",
57
+ "Not Acceptable",
58
+ "Proxy Authentication Required",
59
+ "Request Timeout",
60
+ "Conflict",
61
+ "Gone",
62
+ "Length Required",
63
+ "Precondition Failed",
64
+ "Payload Too Large",
65
+ "URI Too Long",
66
+ "Unsupported Media Type",
67
+ "Range Not Satisfiable",
68
+ "Expectation Failed",
69
+ "I'm a teapot",
70
+ "Misdirected Request",
71
+ "Unprocessable Content",
72
+ "Locked",
73
+ "Failed Dependency",
74
+ "Too Early",
75
+ "Upgrade Required",
76
+ "Precondition Required",
77
+ "Too Many Requests",
78
+ "Enhance Your Calm",
79
+ "Request Header Fields Too Large",
80
+ "Unavailable For Legal Reasons",
81
+ "Internal Server Error",
82
+ "Not Implemented",
83
+ "Bad Gateway",
84
+ "Service Unavailable",
85
+ "Gateway Timeout",
86
+ "HTTP Version Not Supported",
87
+ "Variant Also Negotiates",
88
+ "Insufficient Storage",
89
+ "Loop Detected",
90
+ "Not Extended",
91
+ "Network Authentication Required",
92
+ ]);
93
+ return !errorStatusTexts.has(setStatus);
94
+ }
95
+ // No explicit status was set — default to success (200).
96
+ return true;
97
+ }
98
+
99
+ export function appendPendingInvalidationHeader(set: Context["set"]): string[] {
100
+ const pending = consumePendingInvalidations();
101
+ if (pending.length === 0) {
102
+ return [];
103
+ }
104
+
105
+ const headerName = "x-furin-revalidate";
106
+ const existing = set.headers[headerName];
107
+ set.headers[headerName] =
108
+ typeof existing === "string" && existing.length > 0
109
+ ? `${existing},${pending.join(",")}`
110
+ : pending.join(",");
111
+ return pending;
112
+ }
113
+
114
+ export function revalidateTag(tags: string | readonly string[]): boolean {
115
+ const tagList = typeof tags === "string" ? [tags] : [...tags];
116
+ let deleted = false;
117
+ for (const path of autoInvalidateRegistry.pathsForTags(tagList)) {
118
+ deleted = revalidatePath(path, "page") || deleted;
119
+ }
120
+ return deleted;
121
+ }
122
+
123
+ export function runInvalidationRules(input: InvalidationInput): boolean {
124
+ let deleted = false;
125
+ for (const rule of toRules(input)) {
126
+ if ("path" in rule && rule.path) {
127
+ deleted = revalidatePath(rule.path, rule.type) || deleted;
128
+ }
129
+ if (rule.tags && rule.tags.length > 0) {
130
+ deleted = revalidateTag(rule.tags) || deleted;
131
+ }
132
+ }
133
+ return deleted;
134
+ }