@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
@@ -0,0 +1,62 @@
1
+ export interface StoredResponse {
2
+ body: Uint8Array;
3
+ headers: ReadonlyArray<readonly [string, string]>;
4
+ status: number;
5
+ }
6
+ export interface BeginMutationInput {
7
+ fingerprint: string;
8
+ key: string;
9
+ principal: string;
10
+ }
11
+ export type BeginMutationResult = {
12
+ kind: "execute";
13
+ mutationId: string;
14
+ } | {
15
+ kind: "replay";
16
+ response: StoredResponse;
17
+ } | {
18
+ kind: "conflict";
19
+ reason: "in-progress" | "payload-mismatch";
20
+ } | {
21
+ kind: "unavailable";
22
+ };
23
+ export interface CommitMutationInput {
24
+ mutationId: string;
25
+ response: StoredResponse;
26
+ }
27
+ export interface AbortMutationInput {
28
+ mutationId: string;
29
+ }
30
+ export interface SyncChange {
31
+ cursor: string;
32
+ invalidations: readonly string[];
33
+ }
34
+ export interface AppendChangesInput {
35
+ invalidations: readonly string[];
36
+ path: string;
37
+ }
38
+ export interface AppendChangesResult {
39
+ change: SyncChange;
40
+ }
41
+ export interface ReadChangesInput {
42
+ after: string | undefined;
43
+ limit: number;
44
+ path: string;
45
+ }
46
+ export interface ChangePage {
47
+ changes: readonly SyncChange[];
48
+ cursor: string;
49
+ hasMore: boolean;
50
+ reset: boolean;
51
+ }
52
+ export type SyncChangeListener = (change: SyncChange) => void;
53
+ type MaybePromise<T> = Promise<T> | T;
54
+ export interface SyncAdapter {
55
+ abortMutation(input: AbortMutationInput): MaybePromise<void>;
56
+ appendChanges(input: AppendChangesInput): MaybePromise<AppendChangesResult>;
57
+ beginMutation(input: BeginMutationInput): MaybePromise<BeginMutationResult>;
58
+ commitMutation(input: CommitMutationInput): MaybePromise<void>;
59
+ readChanges(input: ReadChangesInput): MaybePromise<ChangePage>;
60
+ subscribe(path: string, listener: SyncChangeListener): () => void;
61
+ }
62
+ export {};
@@ -0,0 +1,6 @@
1
+ interface FingerprintInput {
2
+ body: unknown;
3
+ request: Request;
4
+ }
5
+ export declare function createMutationFingerprint(input: FingerprintInput): Promise<string>;
6
+ export {};
@@ -1,4 +1,4 @@
1
1
  export type { FurinSyncOption } from "./config.ts";
2
2
  export { getSyncStreamPath, resolveSyncStreamPath, runWithSyncStreamPath, } from "./config.ts";
3
- export { furinSync, type SyncInput } from "./plugin.ts";
4
- export { __resetSyncState, createSyncStreamPlugin, publishSyncInvalidation, type SyncInvalidationEvent, } from "./stream.ts";
3
+ export { furinSync, type SyncInput, type SyncRouteOption } from "./plugin.ts";
4
+ export { __resetSyncState, createSyncStreamPlugin, publishSyncInvalidation, type SyncChange, type SyncChangePage, } from "./stream.ts";
@@ -0,0 +1,17 @@
1
+ import type { AbortMutationInput, AppendChangesInput, AppendChangesResult, BeginMutationInput, BeginMutationResult, ChangePage, CommitMutationInput, ReadChangesInput, SyncAdapter, SyncChangeListener } from "./adapter.ts";
2
+ export declare class MemorySyncAdapter implements SyncAdapter {
3
+ private readonly changes;
4
+ private readonly mutationKeys;
5
+ private readonly mutations;
6
+ beginMutation(input: BeginMutationInput): BeginMutationResult;
7
+ commitMutation(input: CommitMutationInput): void;
8
+ abortMutation(input: AbortMutationInput): void;
9
+ appendChanges(input: AppendChangesInput): AppendChangesResult;
10
+ readChanges(input: ReadChangesInput): ChangePage;
11
+ subscribe(path: string, listener: SyncChangeListener): () => void;
12
+ reset(): void;
13
+ private evictMutations;
14
+ private deleteMutation;
15
+ private getChangeState;
16
+ }
17
+ export declare const memorySyncAdapter: MemorySyncAdapter;
@@ -1,9 +1,10 @@
1
- import { type AfterHandler, Elysia } from "elysia";
1
+ import { Elysia } from "elysia";
2
2
  import type { InvalidationInput } from "../auto-invalidate/types.ts";
3
- export type SyncInput = InvalidationInput | {
3
+ export type SyncRouteOption = false | InvalidationInput | {
4
4
  invalidate: InvalidationInput;
5
5
  };
6
- type AnyHandlerContext = Parameters<AfterHandler>[0];
6
+ /** @deprecated Use SyncRouteOption. */
7
+ export type SyncInput = Exclude<SyncRouteOption, false>;
7
8
  export declare function furinSync(): Elysia<"", {
8
9
  decorator: {};
9
10
  store: {};
@@ -16,11 +17,11 @@ export declare function furinSync(): Elysia<"", {
16
17
  schema: {};
17
18
  standaloneSchema: {};
18
19
  macro: Partial<{
19
- readonly sync: SyncInput;
20
+ readonly sync: SyncRouteOption;
20
21
  }>;
21
22
  macroFn: {
22
- readonly sync: (input: SyncInput) => {
23
- readonly beforeHandle: (ctx: {
23
+ readonly sync: (input: SyncRouteOption) => {
24
+ readonly transform: ({ request }: {
24
25
  body: unknown;
25
26
  query: Record<string, string>;
26
27
  params: {};
@@ -38,7 +39,7 @@ export declare function furinSync(): Elysia<"", {
38
39
  route: string;
39
40
  request: Request;
40
41
  store: {};
41
- status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 301 | 302 | 303 | 307 | 308 | 200 | 300 | 404 | 500 | 304 | 400 | 422 | 100 | 428 | 409 | 101 | 102 | 103 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 401 | 402 | 403 | 405 | 406 | 407 | 408 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 423 | 424 | 425 | 426 | 429 | 431 | 451 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
42
+ status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 301 | 302 | 303 | 307 | 308 | 200 | 300 | 404 | 500 | 304 | 400 | 422 | 100 | 101 | 102 | 103 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 401 | 402 | 403 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
42
43
  readonly 100: "Continue";
43
44
  readonly 101: "Switching Protocols";
44
45
  readonly 102: "Processing";
@@ -163,196 +164,13 @@ export declare function furinSync(): Elysia<"", {
163
164
  readonly "Not Extended": 510;
164
165
  readonly "Network Authentication Required": 511;
165
166
  }[Code] : Code>;
166
- }) => Response | undefined;
167
- readonly afterHandle: (ctx: AnyHandlerContext) => void;
168
- readonly error: ({ request }: {
169
- body: unknown;
170
- query: Record<string, string | undefined>;
171
- params: {};
172
- headers: Record<string, string | undefined>;
173
- cookie: Record<string, import("elysia").Cookie<string | undefined>>;
174
- server: import("elysia/universal/server").Server | null;
175
- redirect: import("elysia").redirect;
176
- set: {
177
- headers: import("elysia").HTTPHeaders;
178
- status?: number | keyof import("elysia").StatusMap;
179
- redirect?: string;
180
- cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
181
- };
182
- status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 301 | 302 | 303 | 307 | 308 | 200 | 300 | 404 | 500 | 304 | 400 | 422 | 100 | 428 | 409 | 101 | 102 | 103 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 401 | 402 | 403 | 405 | 406 | 407 | 408 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 423 | 424 | 425 | 426 | 429 | 431 | 451 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
183
- readonly 100: "Continue";
184
- readonly 101: "Switching Protocols";
185
- readonly 102: "Processing";
186
- readonly 103: "Early Hints";
187
- readonly 200: "OK";
188
- readonly 201: "Created";
189
- readonly 202: "Accepted";
190
- readonly 203: "Non-Authoritative Information";
191
- readonly 204: "No Content";
192
- readonly 205: "Reset Content";
193
- readonly 206: "Partial Content";
194
- readonly 207: "Multi-Status";
195
- readonly 208: "Already Reported";
196
- readonly 300: "Multiple Choices";
197
- readonly 301: "Moved Permanently";
198
- readonly 302: "Found";
199
- readonly 303: "See Other";
200
- readonly 304: "Not Modified";
201
- readonly 307: "Temporary Redirect";
202
- readonly 308: "Permanent Redirect";
203
- readonly 400: "Bad Request";
204
- readonly 401: "Unauthorized";
205
- readonly 402: "Payment Required";
206
- readonly 403: "Forbidden";
207
- readonly 404: "Not Found";
208
- readonly 405: "Method Not Allowed";
209
- readonly 406: "Not Acceptable";
210
- readonly 407: "Proxy Authentication Required";
211
- readonly 408: "Request Timeout";
212
- readonly 409: "Conflict";
213
- readonly 410: "Gone";
214
- readonly 411: "Length Required";
215
- readonly 412: "Precondition Failed";
216
- readonly 413: "Payload Too Large";
217
- readonly 414: "URI Too Long";
218
- readonly 415: "Unsupported Media Type";
219
- readonly 416: "Range Not Satisfiable";
220
- readonly 417: "Expectation Failed";
221
- readonly 418: "I'm a teapot";
222
- readonly 420: "Enhance Your Calm";
223
- readonly 421: "Misdirected Request";
224
- readonly 422: "Unprocessable Content";
225
- readonly 423: "Locked";
226
- readonly 424: "Failed Dependency";
227
- readonly 425: "Too Early";
228
- readonly 426: "Upgrade Required";
229
- readonly 428: "Precondition Required";
230
- readonly 429: "Too Many Requests";
231
- readonly 431: "Request Header Fields Too Large";
232
- readonly 451: "Unavailable For Legal Reasons";
233
- readonly 500: "Internal Server Error";
234
- readonly 501: "Not Implemented";
235
- readonly 502: "Bad Gateway";
236
- readonly 503: "Service Unavailable";
237
- readonly 504: "Gateway Timeout";
238
- readonly 505: "HTTP Version Not Supported";
239
- readonly 506: "Variant Also Negotiates";
240
- readonly 507: "Insufficient Storage";
241
- readonly 508: "Loop Detected";
242
- readonly 510: "Not Extended";
243
- readonly 511: "Network Authentication Required";
244
- }[Code] : Code>(code: Code, response?: T) => import("elysia").ElysiaCustomStatusResponse<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
245
- readonly Continue: 100;
246
- readonly "Switching Protocols": 101;
247
- readonly Processing: 102;
248
- readonly "Early Hints": 103;
249
- readonly OK: 200;
250
- readonly Created: 201;
251
- readonly Accepted: 202;
252
- readonly "Non-Authoritative Information": 203;
253
- readonly "No Content": 204;
254
- readonly "Reset Content": 205;
255
- readonly "Partial Content": 206;
256
- readonly "Multi-Status": 207;
257
- readonly "Already Reported": 208;
258
- readonly "Multiple Choices": 300;
259
- readonly "Moved Permanently": 301;
260
- readonly Found: 302;
261
- readonly "See Other": 303;
262
- readonly "Not Modified": 304;
263
- readonly "Temporary Redirect": 307;
264
- readonly "Permanent Redirect": 308;
265
- readonly "Bad Request": 400;
266
- readonly Unauthorized: 401;
267
- readonly "Payment Required": 402;
268
- readonly Forbidden: 403;
269
- readonly "Not Found": 404;
270
- readonly "Method Not Allowed": 405;
271
- readonly "Not Acceptable": 406;
272
- readonly "Proxy Authentication Required": 407;
273
- readonly "Request Timeout": 408;
274
- readonly Conflict: 409;
275
- readonly Gone: 410;
276
- readonly "Length Required": 411;
277
- readonly "Precondition Failed": 412;
278
- readonly "Payload Too Large": 413;
279
- readonly "URI Too Long": 414;
280
- readonly "Unsupported Media Type": 415;
281
- readonly "Range Not Satisfiable": 416;
282
- readonly "Expectation Failed": 417;
283
- readonly "I'm a teapot": 418;
284
- readonly "Enhance Your Calm": 420;
285
- readonly "Misdirected Request": 421;
286
- readonly "Unprocessable Content": 422;
287
- readonly Locked: 423;
288
- readonly "Failed Dependency": 424;
289
- readonly "Too Early": 425;
290
- readonly "Upgrade Required": 426;
291
- readonly "Precondition Required": 428;
292
- readonly "Too Many Requests": 429;
293
- readonly "Request Header Fields Too Large": 431;
294
- readonly "Unavailable For Legal Reasons": 451;
295
- readonly "Internal Server Error": 500;
296
- readonly "Not Implemented": 501;
297
- readonly "Bad Gateway": 502;
298
- readonly "Service Unavailable": 503;
299
- readonly "Gateway Timeout": 504;
300
- readonly "HTTP Version Not Supported": 505;
301
- readonly "Variant Also Negotiates": 506;
302
- readonly "Insufficient Storage": 507;
303
- readonly "Loop Detected": 508;
304
- readonly "Not Extended": 510;
305
- readonly "Network Authentication Required": 511;
306
- }[Code] : Code>;
307
- path: string;
308
- route: string;
309
- request: Request;
310
- store: {};
311
- } & ({
312
- request: Request;
313
- code: "UNKNOWN";
314
- error: Readonly<Error>;
315
- set: import("elysia").Context["set"];
316
- } | {
317
- request: Request;
318
- code: "VALIDATION";
319
- error: Readonly<import("elysia").ValidationError>;
320
- set: import("elysia").Context["set"];
321
- } | {
322
- request: Request;
323
- code: "NOT_FOUND";
324
- error: Readonly<import("elysia").NotFoundError>;
325
- set: import("elysia").Context["set"];
326
- } | {
327
- request: Request;
328
- code: "PARSE";
329
- error: Readonly<import("elysia").ParseError>;
330
- set: import("elysia").Context["set"];
331
- } | {
332
- request: Request;
333
- code: "INTERNAL_SERVER_ERROR";
334
- error: Readonly<import("elysia").InternalServerError>;
335
- set: import("elysia").Context["set"];
336
- } | {
337
- request: Request;
338
- code: "INVALID_COOKIE_SIGNATURE";
339
- error: Readonly<import("elysia").InvalidCookieSignature>;
340
- set: import("elysia").Context["set"];
341
- } | {
342
- request: Request;
343
- code: "INVALID_FILE_TYPE";
344
- error: Readonly<import("elysia").InvalidFileType>;
345
- set: import("elysia").Context["set"];
346
- } | {
347
- request: Request;
348
- code: number;
349
- error: Readonly<import("elysia").ElysiaCustomStatusResponse<number>>;
350
- set: import("elysia").Context["set"];
351
- })) => void;
167
+ }) => void;
352
168
  };
353
169
  };
354
170
  parser: {};
355
- response: {};
171
+ response: {
172
+ 200: Response;
173
+ };
356
174
  }, {}, {
357
175
  derive: {};
358
176
  resolve: {};
@@ -366,4 +184,3 @@ export declare function furinSync(): Elysia<"", {
366
184
  standaloneSchema: {};
367
185
  response: {};
368
186
  }>;
369
- export {};
@@ -0,0 +1,4 @@
1
+ import { type Context } from "elysia";
2
+ import type { StoredResponse } from "./adapter.ts";
3
+ export declare function storeResponse(responseValue: unknown, set: Context["set"]): Promise<StoredResponse>;
4
+ export declare function replayResponse(stored: StoredResponse): Response;
@@ -1,7 +1,5 @@
1
1
  import { Elysia } from "elysia";
2
- export interface SyncInvalidationEvent {
3
- invalidations: readonly string[];
4
- }
2
+ export type { ChangePage as SyncChangePage, SyncChange } from "./adapter.ts";
5
3
  export declare function publishSyncInvalidation(invalidations: readonly string[]): void;
6
4
  export declare function createSyncStreamPlugin(path?: string): Elysia<"", {
7
5
  decorator: {};
@@ -19,6 +17,20 @@ export declare function createSyncStreamPlugin(path?: string): Elysia<"", {
19
17
  parser: {};
20
18
  response: {};
21
19
  }, {
20
+ [x: string]: {
21
+ changes: {
22
+ get: {
23
+ body: unknown;
24
+ params: {};
25
+ query: unknown;
26
+ headers: unknown;
27
+ response: {
28
+ 200: Response | import("./adapter.ts").ChangePage;
29
+ };
30
+ };
31
+ };
32
+ };
33
+ } & {
22
34
  [x: string]: {
23
35
  get: {
24
36
  body: unknown;
@@ -43,5 +55,5 @@ export declare function createSyncStreamPlugin(path?: string): Elysia<"", {
43
55
  standaloneSchema: {};
44
56
  response: {};
45
57
  }>;
46
- /** @internal — resets process-local stream subscribers between tests. */
58
+ /** @internal — resets process-local sync state between tests. */
47
59
  export declare function __resetSyncState(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teyik0/furin",
3
- "version": "0.2.0-alpha.3",
3
+ "version": "0.2.0-alpha.4",
4
4
  "description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
5
5
  "license": "MIT",
6
6
  "author": "teyik0",
@@ -1,13 +1,13 @@
1
- ## Bun adapter
2
-
3
- Goal is having 3 modes:
4
-
5
- - generate server.js + client/
6
- - generate server (compiled to binary) + client/
7
- - generate server (compiled to binary with client/ [embeded](https://bun.com/docs/bundler/executables.md))
8
-
9
- All should be portable.
10
-
11
- ## Cloudflare adapter
12
-
13
- ## Vercel adapter
1
+ ## Bun adapter
2
+
3
+ Goal is having 3 modes:
4
+
5
+ - generate server.js + client/
6
+ - generate server (compiled to binary) + client/
7
+ - generate server (compiled to binary with client/ [embeded](https://bun.com/docs/bundler/executables.md))
8
+
9
+ All should be portable.
10
+
11
+ ## Cloudflare adapter
12
+
13
+ ## Vercel adapter