@teyik0/furin 0.2.0-alpha.3 → 0.2.0-alpha.5
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.
- package/LICENSE +21 -21
- package/README.md +37 -33
- package/dist/adapter/bun.d.ts +17 -1
- package/dist/adapter/package.d.ts +26 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +3 -3
- package/dist/build/compile-entry.ts +114 -109
- package/dist/build/entry-template.d.ts +35 -9
- package/dist/build/entry-template.ts +206 -156
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +643 -247
- package/dist/build/scan-server.d.ts +10 -4
- package/dist/build/server-routes-entry.d.ts +3 -3
- package/dist/build/server-routes-entry.ts +30 -36
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +36 -1
- package/dist/cli/config.d.ts +6 -1
- package/dist/cli/index.js +662 -260
- package/dist/client/link.js +163 -16
- package/dist/client/router/abort.d.ts +1 -0
- package/dist/client/router/sync-catch-up.d.ts +29 -0
- package/dist/config.d.ts +11 -2
- package/dist/config.js +5 -1
- package/dist/furin.d.ts +37 -19
- package/dist/furin.js +982 -378
- package/dist/server/auto-invalidate/registry.d.ts +8 -1
- package/dist/server/cache/dev-loader.d.ts +3 -2
- package/dist/server/cache/invalidation.d.ts +19 -0
- package/dist/server/cache/isr.d.ts +6 -2
- package/dist/server/cache/registry.d.ts +3 -3
- package/dist/server/cache/ssg.d.ts +6 -2
- package/dist/server/cache/store-view.d.ts +11 -0
- package/dist/server/instance.d.ts +86 -0
- package/dist/server/internal.d.ts +16 -1
- package/dist/server/internal.js +72 -5
- package/dist/server/render/template.d.ts +3 -2
- package/dist/server/sync/adapter.d.ts +62 -0
- package/dist/server/sync/config.d.ts +11 -0
- package/dist/server/sync/fingerprint.d.ts +6 -0
- package/dist/server/sync/index.d.ts +2 -2
- package/dist/server/sync/memory-adapter.d.ts +17 -0
- package/dist/server/sync/plugin.d.ts +12 -195
- package/dist/server/sync/response.d.ts +4 -0
- package/dist/server/sync/stream.d.ts +24 -5
- package/dist/shared/prefix.d.ts +15 -0
- package/package.json +6 -1
- package/src/adapter/README.md +13 -13
- package/src/adapter/bun.ts +113 -50
- package/src/adapter/package.ts +206 -0
- package/src/build/client.ts +158 -152
- package/src/build/compile-entry.ts +114 -109
- package/src/build/entry-template.ts +206 -156
- package/src/build/hydrate.ts +342 -340
- package/src/build/index.ts +223 -152
- package/src/build/route-types.ts +145 -145
- package/src/build/scan-server.ts +111 -95
- package/src/build/server-routes-entry.ts +30 -36
- package/src/build/shared.ts +80 -80
- package/src/build/ssg-cache.ts +36 -32
- package/src/build/types.ts +125 -89
- package/src/cli/config.ts +9 -3
- package/src/cli/index.ts +21 -3
- package/src/client/router/abort.ts +5 -0
- package/src/client/router/link-utils.ts +184 -184
- package/src/client/router/provider.tsx +883 -804
- package/src/client/router/sync-catch-up.ts +113 -0
- package/src/client/router/types.ts +276 -276
- package/src/client/sync.ts +98 -98
- package/src/client.ts +369 -369
- package/src/config.ts +14 -1
- package/src/furin.ts +619 -465
- package/src/server/auto-invalidate/registry.ts +23 -1
- package/src/server/auto-invalidate/runtime.ts +159 -134
- package/src/server/cache/dev-loader.ts +77 -38
- package/src/server/cache/invalidation.ts +71 -30
- package/src/server/cache/isr.ts +20 -5
- package/src/server/cache/registry.ts +17 -20
- package/src/server/cache/ssg.ts +19 -4
- package/src/server/cache/store-view.ts +30 -0
- package/src/server/dev-page-plugin.ts +454 -454
- package/src/server/instance.ts +252 -0
- package/src/server/internal.ts +100 -5
- package/src/server/render/assemble.ts +160 -160
- package/src/server/render/isr.ts +323 -323
- package/src/server/render/not-found.ts +9 -3
- package/src/server/render/ssr.ts +603 -585
- package/src/server/render/template.ts +57 -24
- package/src/server/router/plugin.ts +384 -384
- package/src/server/sync/adapter.ts +65 -0
- package/src/server/sync/config.ts +60 -29
- package/src/server/sync/fingerprint.ts +44 -0
- package/src/server/sync/index.ts +15 -14
- package/src/server/sync/memory-adapter.ts +196 -0
- package/src/server/sync/plugin.ts +199 -108
- package/src/server/sync/response.ts +77 -0
- package/src/server/sync/stream.ts +162 -144
- package/src/shared/deferred-ndjson.ts +7 -0
- package/src/shared/prefix.ts +38 -0
package/src/client/sync.ts
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
|
|
3
|
-
export interface SyncMutationHeaders {
|
|
4
|
-
"Idempotency-Key": string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface SyncMutationOptions {
|
|
8
|
-
headers: SyncMutationHeaders;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface SyncMutationContext<TInput> {
|
|
12
|
-
idempotencyKey: string;
|
|
13
|
-
input: TInput;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface SyncMutationSuccessContext<TInput, TResult> extends SyncMutationContext<TInput> {
|
|
17
|
-
result: TResult;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface SyncMutationErrorContext<TInput, TResult> extends SyncMutationContext<TInput> {
|
|
21
|
-
error: unknown;
|
|
22
|
-
result?: TResult;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface UseSyncOptions<TInput, TResult> {
|
|
26
|
-
onError?: (ctx: SyncMutationErrorContext<TInput, TResult>) => Promise<void> | void;
|
|
27
|
-
onSuccess?: (ctx: SyncMutationSuccessContext<TInput, TResult>) => Promise<void> | void;
|
|
28
|
-
optimistic?: (ctx: SyncMutationContext<TInput>) => (() => void) | undefined;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type SyncMutation<TInput, TResult> = (
|
|
32
|
-
input: TInput,
|
|
33
|
-
options: SyncMutationOptions
|
|
34
|
-
) => Promise<TResult>;
|
|
35
|
-
|
|
36
|
-
export type SyncMutationRunner<TInput, TResult> = undefined extends TInput
|
|
37
|
-
? (input?: TInput) => Promise<TResult>
|
|
38
|
-
: (input: TInput) => Promise<TResult>;
|
|
39
|
-
|
|
40
|
-
interface EdenErrorResult {
|
|
41
|
-
error?: unknown;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function createIdempotencyKey(): string {
|
|
45
|
-
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
46
|
-
return globalThis.crypto.randomUUID();
|
|
47
|
-
}
|
|
48
|
-
return `${Date.now()}-${Math.random()}`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getResolvedError(result: unknown): unknown | undefined {
|
|
52
|
-
if (!(typeof result === "object" && result !== null && "error" in result)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const error = (result as EdenErrorResult).error;
|
|
57
|
-
return error == null ? undefined : error;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function useSync<TInput, TResult>(
|
|
61
|
-
mutation: SyncMutation<TInput, TResult>,
|
|
62
|
-
options?: UseSyncOptions<TInput, TResult>
|
|
63
|
-
): SyncMutationRunner<TInput, TResult> {
|
|
64
|
-
const optimistic = options?.optimistic;
|
|
65
|
-
const onError = options?.onError;
|
|
66
|
-
const onSuccess = options?.onSuccess;
|
|
67
|
-
|
|
68
|
-
const run = useCallback(
|
|
69
|
-
async (input: TInput) => {
|
|
70
|
-
const idempotencyKey = createIdempotencyKey();
|
|
71
|
-
const rollback = optimistic?.({ idempotencyKey, input });
|
|
72
|
-
|
|
73
|
-
let result: TResult;
|
|
74
|
-
try {
|
|
75
|
-
result = await mutation(input, {
|
|
76
|
-
headers: { "Idempotency-Key": idempotencyKey },
|
|
77
|
-
});
|
|
78
|
-
} catch (error) {
|
|
79
|
-
rollback?.();
|
|
80
|
-
await onError?.({ error, idempotencyKey, input });
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const resolvedError = getResolvedError(result);
|
|
85
|
-
if (resolvedError !== undefined) {
|
|
86
|
-
rollback?.();
|
|
87
|
-
await onError?.({ error: resolvedError, idempotencyKey, input, result });
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
await onSuccess?.({ idempotencyKey, input, result });
|
|
92
|
-
return result;
|
|
93
|
-
},
|
|
94
|
-
[mutation, optimistic, onError, onSuccess]
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return run as SyncMutationRunner<TInput, TResult>;
|
|
98
|
-
}
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
|
|
3
|
+
export interface SyncMutationHeaders {
|
|
4
|
+
"Idempotency-Key": string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SyncMutationOptions {
|
|
8
|
+
headers: SyncMutationHeaders;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SyncMutationContext<TInput> {
|
|
12
|
+
idempotencyKey: string;
|
|
13
|
+
input: TInput;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SyncMutationSuccessContext<TInput, TResult> extends SyncMutationContext<TInput> {
|
|
17
|
+
result: TResult;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SyncMutationErrorContext<TInput, TResult> extends SyncMutationContext<TInput> {
|
|
21
|
+
error: unknown;
|
|
22
|
+
result?: TResult;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface UseSyncOptions<TInput, TResult> {
|
|
26
|
+
onError?: (ctx: SyncMutationErrorContext<TInput, TResult>) => Promise<void> | void;
|
|
27
|
+
onSuccess?: (ctx: SyncMutationSuccessContext<TInput, TResult>) => Promise<void> | void;
|
|
28
|
+
optimistic?: (ctx: SyncMutationContext<TInput>) => (() => void) | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type SyncMutation<TInput, TResult> = (
|
|
32
|
+
input: TInput,
|
|
33
|
+
options: SyncMutationOptions
|
|
34
|
+
) => Promise<TResult>;
|
|
35
|
+
|
|
36
|
+
export type SyncMutationRunner<TInput, TResult> = undefined extends TInput
|
|
37
|
+
? (input?: TInput) => Promise<TResult>
|
|
38
|
+
: (input: TInput) => Promise<TResult>;
|
|
39
|
+
|
|
40
|
+
interface EdenErrorResult {
|
|
41
|
+
error?: unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function createIdempotencyKey(): string {
|
|
45
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
46
|
+
return globalThis.crypto.randomUUID();
|
|
47
|
+
}
|
|
48
|
+
return `${Date.now()}-${Math.random()}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getResolvedError(result: unknown): unknown | undefined {
|
|
52
|
+
if (!(typeof result === "object" && result !== null && "error" in result)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const error = (result as EdenErrorResult).error;
|
|
57
|
+
return error == null ? undefined : error;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function useSync<TInput, TResult>(
|
|
61
|
+
mutation: SyncMutation<TInput, TResult>,
|
|
62
|
+
options?: UseSyncOptions<TInput, TResult>
|
|
63
|
+
): SyncMutationRunner<TInput, TResult> {
|
|
64
|
+
const optimistic = options?.optimistic;
|
|
65
|
+
const onError = options?.onError;
|
|
66
|
+
const onSuccess = options?.onSuccess;
|
|
67
|
+
|
|
68
|
+
const run = useCallback(
|
|
69
|
+
async (input: TInput) => {
|
|
70
|
+
const idempotencyKey = createIdempotencyKey();
|
|
71
|
+
const rollback = optimistic?.({ idempotencyKey, input });
|
|
72
|
+
|
|
73
|
+
let result: TResult;
|
|
74
|
+
try {
|
|
75
|
+
result = await mutation(input, {
|
|
76
|
+
headers: { "Idempotency-Key": idempotencyKey },
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
rollback?.();
|
|
80
|
+
await onError?.({ error, idempotencyKey, input });
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const resolvedError = getResolvedError(result);
|
|
85
|
+
if (resolvedError !== undefined) {
|
|
86
|
+
rollback?.();
|
|
87
|
+
await onError?.({ error: resolvedError, idempotencyKey, input, result });
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
await onSuccess?.({ idempotencyKey, input, result });
|
|
92
|
+
return result;
|
|
93
|
+
},
|
|
94
|
+
[mutation, optimistic, onError, onSuccess]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return run as SyncMutationRunner<TInput, TResult>;
|
|
98
|
+
}
|