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

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 (84) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +33 -33
  3. package/dist/adapter/static.d.ts +1 -1
  4. package/dist/build/compile-entry.ts +109 -109
  5. package/dist/build/entry-template.ts +156 -156
  6. package/dist/build/index.js +1724 -687
  7. package/dist/build/route-types.d.ts +3 -1
  8. package/dist/build/server-routes-entry.ts +36 -36
  9. package/dist/build/shared.d.ts +1 -0
  10. package/dist/build/ssg-cache.d.ts +1 -1
  11. package/dist/cli/index.js +1673 -658
  12. package/dist/client/link.js +883 -89
  13. package/dist/client/router/index.d.ts +4 -0
  14. package/dist/client/router/link-utils.d.ts +3 -1
  15. package/dist/client/router/navigation.d.ts +10 -0
  16. package/dist/client/router/provider.d.ts +1 -1
  17. package/dist/client/router/search/index.d.ts +18 -0
  18. package/dist/client/router/search-store.d.ts +21 -0
  19. package/dist/client/router/types.d.ts +14 -1
  20. package/dist/client/sync.d.ts +25 -0
  21. package/dist/client.d.ts +1 -0
  22. package/dist/client.js +44 -0
  23. package/dist/furin.d.ts +9 -1
  24. package/dist/furin.js +1578 -258
  25. package/dist/server/auto-invalidate/runtime.d.ts +1 -1
  26. package/dist/server/dev-page-plugin.d.ts +3 -0
  27. package/dist/server/render/assemble.d.ts +2 -0
  28. package/dist/server/render/isr.d.ts +2 -1
  29. package/dist/server/render/ssg.d.ts +3 -2
  30. package/dist/server/render/ssr.d.ts +5 -4
  31. package/dist/server/router/hmr.d.ts +4 -3
  32. package/dist/server/router/index.d.ts +1 -1
  33. package/dist/server/router/index.js +1 -2
  34. package/dist/server/router/index.ts +1 -2
  35. package/dist/server/router/plugin.d.ts +2 -1
  36. package/dist/server/router/schemas.d.ts +25 -17
  37. package/dist/server/sync/config.d.ts +6 -0
  38. package/dist/server/sync/index.d.ts +4 -0
  39. package/dist/server/sync/plugin.d.ts +369 -0
  40. package/dist/server/sync/stream.d.ts +47 -0
  41. package/dist/shared/search-params.d.ts +17 -0
  42. package/package.json +10 -5
  43. package/src/adapter/README.md +13 -13
  44. package/src/adapter/static.ts +23 -6
  45. package/src/build/client.ts +152 -149
  46. package/src/build/compile-entry.ts +109 -109
  47. package/src/build/entry-template.ts +156 -156
  48. package/src/build/hydrate.ts +340 -331
  49. package/src/build/index.ts +152 -152
  50. package/src/build/route-types.ts +145 -115
  51. package/src/build/scan-server.ts +95 -95
  52. package/src/build/server-routes-entry.ts +36 -36
  53. package/src/build/shared.ts +80 -78
  54. package/src/build/ssg-cache.ts +32 -31
  55. package/src/build/types.ts +89 -89
  56. package/src/client/link.tsx +13 -4
  57. package/src/client/router/context.ts +2 -0
  58. package/src/client/router/index.ts +9 -0
  59. package/src/client/router/link-utils.ts +184 -180
  60. package/src/client/router/navigation.ts +61 -0
  61. package/src/client/router/provider.tsx +804 -723
  62. package/src/client/router/search/index.ts +99 -0
  63. package/src/client/router/search-store.ts +86 -0
  64. package/src/client/router/types.ts +276 -263
  65. package/src/client/sync.ts +98 -0
  66. package/src/client.ts +369 -355
  67. package/src/furin.ts +465 -437
  68. package/src/server/auto-invalidate/runtime.ts +134 -133
  69. package/src/server/dev-page-plugin.ts +454 -449
  70. package/src/server/render/assemble.ts +160 -133
  71. package/src/server/render/isr.ts +323 -295
  72. package/src/server/render/not-found.ts +2 -0
  73. package/src/server/render/ssg.ts +15 -4
  74. package/src/server/render/ssr.ts +585 -545
  75. package/src/server/router/hmr.ts +14 -10
  76. package/src/server/router/index.ts +1 -2
  77. package/src/server/router/patterns.ts +5 -0
  78. package/src/server/router/plugin.ts +384 -401
  79. package/src/server/router/schemas.ts +172 -57
  80. package/src/server/sync/config.ts +29 -0
  81. package/src/server/sync/index.ts +14 -0
  82. package/src/server/sync/plugin.ts +108 -0
  83. package/src/server/sync/stream.ts +144 -0
  84. package/src/shared/search-params.ts +182 -0
@@ -1,133 +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"]): void {
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
- }
112
-
113
- export function revalidateTag(tags: string | readonly string[]): boolean {
114
- const tagList = typeof tags === "string" ? [tags] : [...tags];
115
- let deleted = false;
116
- for (const path of autoInvalidateRegistry.pathsForTags(tagList)) {
117
- deleted = revalidatePath(path, "page") || deleted;
118
- }
119
- return deleted;
120
- }
121
-
122
- export function runInvalidationRules(input: InvalidationInput): boolean {
123
- let deleted = false;
124
- for (const rule of toRules(input)) {
125
- if ("path" in rule && rule.path) {
126
- deleted = revalidatePath(rule.path, rule.type) || deleted;
127
- }
128
- if (rule.tags && rule.tags.length > 0) {
129
- deleted = revalidateTag(rule.tags) || deleted;
130
- }
131
- }
132
- return deleted;
133
- }
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
+ }