@teyik0/furin 0.6.0-alpha.1 → 0.7.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.
- package/dist/adapter/runtime-build.d.ts +1 -1
- package/dist/build/client.d.ts +4 -1
- package/dist/build/entry-template.d.ts +3 -0
- package/dist/build/entry-template.ts +7 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +1671 -276
- package/dist/build/preload-manifest.d.ts +17 -0
- package/dist/build/types.d.ts +6 -0
- package/dist/cli/index.js +1672 -286
- package/dist/client/client-module.d.ts +26 -0
- package/dist/client/define-route.d.ts +9 -0
- package/dist/client/document.d.ts +2 -0
- package/dist/client/internal/runtime-types.d.ts +2 -0
- package/dist/client/link.js +932 -118
- package/dist/client/mutation.d.ts +38 -0
- package/dist/client/query-store.d.ts +85 -0
- package/dist/client/query.d.ts +14 -0
- package/dist/client/route-api.d.ts +11 -0
- package/dist/client/router/context.d.ts +3 -2
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +8 -1
- package/dist/client/router/navigation.d.ts +2 -9
- package/dist/client/router/optimistic.d.ts +41 -0
- package/dist/client/router/search/index.d.ts +3 -3
- package/dist/client/router/search-store.d.ts +1 -0
- package/dist/client/router/sync-catch-up.d.ts +3 -0
- package/dist/client/router/types.d.ts +49 -7
- package/dist/client/sync.d.ts +39 -22
- package/dist/client.d.ts +11 -33
- package/dist/client.js +1219 -59
- package/dist/config.d.ts +7 -0
- package/dist/config.js +1 -0
- package/dist/define-route.d.ts +78 -32
- package/dist/env.d.ts +2 -2
- package/dist/furin.d.ts +1 -2
- package/dist/furin.js +2448 -710
- package/dist/plugin/hmr-dependencies.d.ts +2 -0
- package/dist/plugin/index.js +349 -18
- package/dist/plugin/transform-client-module.d.ts +16 -0
- package/dist/plugin/transform-client.d.ts +2 -0
- package/dist/plugin/transform-isomorphic.d.ts +1 -1
- package/dist/routes.d.ts +6 -0
- package/dist/rsc-client.js +87 -16
- package/dist/rsc.js +87 -16
- package/dist/server/auto-invalidate/registry.d.ts +1 -0
- package/dist/server/auto-invalidate/types.d.ts +2 -0
- package/dist/server/cache/isr.d.ts +2 -4
- package/dist/server/cache/route-cache.d.ts +5 -0
- package/dist/server/dev/graph.d.ts +1 -0
- package/dist/server/dev-page-plugin.d.ts +5 -19
- package/dist/server/internal.d.ts +3 -0
- package/dist/server/internal.js +55 -35
- package/dist/server/production-server.js +54 -34
- package/dist/server/render/loaders.d.ts +4 -2
- package/dist/server/render/react-stream.d.ts +3 -0
- package/dist/server/render/ssr.d.ts +2 -1
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +2 -0
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/sync/adapter.d.ts +25 -4
- package/dist/server/sync/atomic.d.ts +25 -0
- package/dist/server/sync/drizzle/index.d.ts +45 -0
- package/dist/server/sync/drizzle/index.js +540 -0
- package/dist/server/sync/execution-error.d.ts +2 -0
- package/dist/server/sync/index.d.ts +2 -1
- package/dist/server/sync/index.js +533 -105
- package/dist/server/sync/mutation-handler.d.ts +4 -0
- package/dist/server/sync/plugin.d.ts +34 -11
- package/dist/server/sync/postgres/execute.d.ts +3 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +34 -13
- package/dist/server/sync/postgres/sql.d.ts +8 -0
- package/dist/server/sync/prisma/index.d.ts +24 -0
- package/dist/server/sync/prisma/index.js +340 -0
- package/dist/server/sync/queries.d.ts +21 -0
- package/dist/server/sync/query-context.d.ts +5 -0
- package/dist/server/sync/redis/index.js +3 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/response.d.ts +1 -0
- package/dist/server/sync/sqlite/index.d.ts +3 -0
- package/dist/server/sync/sqlite/index.js +10 -4
- package/dist/server/sync/stream.d.ts +2 -5
- package/dist/server/sync/validation.d.ts +4 -0
- package/dist/shared/defer.d.ts +31 -0
- package/dist/shared/error.d.ts +2 -2
- package/dist/shared/page-key.d.ts +7 -0
- package/dist/shared/query-bindings.d.ts +12 -0
- package/dist/shared/route-frame.d.ts +1 -0
- package/dist/shared/sync-query.d.ts +40 -0
- package/package.json +29 -6
- package/src/adapter/package.ts +12 -2
- package/src/adapter/runtime-build.ts +63 -12
- package/src/adapter/static.ts +7 -2
- package/src/adapter/vercel.ts +15 -13
- package/src/build/client.ts +23 -5
- package/src/build/entry-template.ts +7 -0
- package/src/build/hydrate.ts +17 -3
- package/src/build/preload-manifest.ts +100 -0
- package/src/build/production-instrumentation.ts +6 -3
- package/src/build/types.ts +4 -0
- package/src/cli/index.ts +1 -0
- package/src/client/browser-events-runtime.ts +4 -0
- package/src/client/client-module.ts +57 -0
- package/src/client/define-route.ts +11 -1
- package/src/client/document.tsx +28 -18
- package/src/client/hmr.ts +2 -1
- package/src/client/internal/runtime-types.ts +2 -0
- package/src/client/link.tsx +8 -8
- package/src/client/mutation.ts +136 -0
- package/src/client/query-store.ts +418 -0
- package/src/client/query.tsx +67 -0
- package/src/client/route-api.tsx +75 -0
- package/src/client/router/boundary-tree.tsx +7 -2
- package/src/client/router/context.ts +57 -4
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +29 -1
- package/src/client/router/navigation.ts +3 -50
- package/src/client/router/optimistic.ts +233 -0
- package/src/client/router/provider.tsx +304 -44
- package/src/client/router/search/index.ts +37 -17
- package/src/client/router/search-store.ts +4 -0
- package/src/client/router/sync-catch-up.ts +7 -0
- package/src/client/router/types.ts +71 -9
- package/src/client/sync.ts +438 -65
- package/src/client.ts +20 -60
- package/src/config.ts +5 -0
- package/src/define-route.ts +113 -55
- package/src/env.d.ts +2 -2
- package/src/furin.ts +75 -13
- package/src/plugin/hmr-dependencies.ts +58 -0
- package/src/plugin/index.ts +38 -2
- package/src/plugin/routes.ts +3 -3
- package/src/plugin/transform-client-module.ts +123 -0
- package/src/plugin/transform-client.ts +293 -13
- package/src/plugin/transform-isomorphic.ts +11 -5
- package/src/routes.ts +8 -0
- package/src/rsc/shared.tsx +104 -18
- package/src/server/auto-invalidate/registry.ts +4 -0
- package/src/server/auto-invalidate/runtime.ts +17 -0
- package/src/server/auto-invalidate/types.ts +6 -0
- package/src/server/cache/isr.ts +6 -34
- package/src/server/cache/route-cache.ts +40 -4
- package/src/server/dev/graph.ts +16 -2
- package/src/server/dev-page-plugin.ts +93 -59
- package/src/server/internal.ts +3 -0
- package/src/server/render/document.tsx +10 -1
- package/src/server/render/element.tsx +7 -2
- package/src/server/render/isr.ts +61 -29
- package/src/server/render/loaders.ts +118 -47
- package/src/server/render/mixed-cache.ts +33 -4
- package/src/server/render/not-found.ts +4 -7
- package/src/server/render/ppr-document.ts +2 -1
- package/src/server/render/ppr-route.ts +30 -10
- package/src/server/render/react-stream.ts +17 -0
- package/src/server/render/route-frame-transport.ts +3 -0
- package/src/server/render/ssg.ts +51 -18
- package/src/server/render/ssr.ts +53 -8
- package/src/server/render/template.ts +23 -0
- package/src/server/router/defined-route.ts +3 -0
- package/src/server/router/hmr.ts +3 -2
- package/src/server/router/plugin.ts +27 -12
- package/src/server/sync/adapter.ts +41 -4
- package/src/server/sync/atomic.ts +303 -0
- package/src/server/sync/drizzle/index.ts +145 -0
- package/src/server/sync/execution-error.ts +1 -0
- package/src/server/sync/fingerprint.ts +2 -6
- package/src/server/sync/index.ts +6 -0
- package/src/server/sync/mutation-handler.ts +69 -0
- package/src/server/sync/plugin.ts +177 -60
- package/src/server/sync/postgres/execute.ts +20 -0
- package/src/server/sync/postgres/index.ts +52 -16
- package/src/server/sync/postgres/sql.ts +20 -0
- package/src/server/sync/prisma/index.ts +70 -0
- package/src/server/sync/queries.ts +75 -0
- package/src/server/sync/query-context.ts +85 -0
- package/src/server/sync/redis/index.ts +7 -3
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/response.ts +21 -0
- package/src/server/sync/sqlite/index.ts +19 -8
- package/src/server/sync/stream.ts +14 -22
- package/src/server/sync/validation.ts +34 -0
- package/src/shared/defer.ts +48 -0
- package/src/shared/error.ts +2 -2
- package/src/shared/page-key.ts +36 -0
- package/src/shared/query-bindings.ts +138 -0
- package/src/shared/route-frame.ts +13 -1
- package/src/shared/route-map.ts +12 -2
- package/src/shared/sync-query.ts +138 -0
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
buildSearchParams,
|
|
3
|
+
findSearchDefaultsForRouteTarget,
|
|
4
|
+
type SearchParamsInput,
|
|
5
|
+
type SearchRouteMetadata,
|
|
6
|
+
} from "../../shared/search-params.ts";
|
|
2
7
|
import type { CacheEntry } from "./types.ts";
|
|
3
8
|
|
|
4
9
|
const HASH_FRAGMENT_RE = /#.*$/;
|
|
@@ -94,6 +99,29 @@ export function applyLinkParams(
|
|
|
94
99
|
return url;
|
|
95
100
|
}
|
|
96
101
|
|
|
102
|
+
export interface RuntimeRouteTarget {
|
|
103
|
+
hash?: string;
|
|
104
|
+
params?: object;
|
|
105
|
+
search?: object;
|
|
106
|
+
to: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function resolveRouteTarget(
|
|
110
|
+
target: RuntimeRouteTarget,
|
|
111
|
+
routes: SearchRouteMetadata[]
|
|
112
|
+
): string {
|
|
113
|
+
const path = applyLinkParams(
|
|
114
|
+
target.to,
|
|
115
|
+
target.params as Record<string, string | number> | undefined
|
|
116
|
+
);
|
|
117
|
+
return buildHref(
|
|
118
|
+
path,
|
|
119
|
+
target.search as SearchParamsInput | undefined,
|
|
120
|
+
target.hash,
|
|
121
|
+
findSearchDefaultsForRouteTarget(path, routes)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
97
125
|
/**
|
|
98
126
|
* Builds a full href string from a pathname, optional search params, and optional hash.
|
|
99
127
|
* Null/undefined search values are omitted.
|
|
@@ -1,55 +1,8 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import {
|
|
3
|
-
findSearchDefaultsForRouteTarget,
|
|
4
|
-
type SearchParamsInput,
|
|
5
|
-
} from "../../shared/search-params.ts";
|
|
6
1
|
import { useRouter } from "./context.ts";
|
|
7
|
-
import {
|
|
8
|
-
import type { RouteSearch, RouteTo } from "./types.ts";
|
|
2
|
+
import type { Navigate } from "./types.ts";
|
|
9
3
|
|
|
10
|
-
export
|
|
11
|
-
hash?: string;
|
|
12
|
-
replace?: boolean;
|
|
13
|
-
resetScroll?: boolean;
|
|
14
|
-
search?: RouteSearch<To>;
|
|
15
|
-
to: To;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type Navigate = <To extends RouteTo>(next: NavigateInput<To>) => Promise<void>;
|
|
19
|
-
type NavigateOptions = Parameters<ReturnType<typeof useRouter>["navigate"]>[1];
|
|
4
|
+
export type { Navigate, NavigateInput } from "./types.ts";
|
|
20
5
|
|
|
21
6
|
export function useNavigate(): Navigate {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return useCallback<Navigate>(
|
|
25
|
-
(next) => {
|
|
26
|
-
const searchDefaults = findSearchDefaultsForRouteTarget(
|
|
27
|
-
next.to as string,
|
|
28
|
-
router.searchRoutes
|
|
29
|
-
);
|
|
30
|
-
const href = buildHref(
|
|
31
|
-
next.to as string,
|
|
32
|
-
next.search as SearchParamsInput | null | undefined,
|
|
33
|
-
next.hash,
|
|
34
|
-
searchDefaults
|
|
35
|
-
);
|
|
36
|
-
const policy = navigationHrefPolicy(
|
|
37
|
-
href,
|
|
38
|
-
typeof window === "undefined" ? undefined : window.location.origin
|
|
39
|
-
);
|
|
40
|
-
if (policy === "blocked") {
|
|
41
|
-
return Promise.reject(new Error("[furin] Unsafe navigation URL."));
|
|
42
|
-
}
|
|
43
|
-
if (policy === "external" && typeof window !== "undefined") {
|
|
44
|
-
window.location.assign(href);
|
|
45
|
-
return Promise.resolve();
|
|
46
|
-
}
|
|
47
|
-
const opts: NavigateOptions =
|
|
48
|
-
next.replace === undefined && next.resetScroll === undefined
|
|
49
|
-
? undefined
|
|
50
|
-
: { replace: next.replace, resetScroll: next.resetScroll };
|
|
51
|
-
return router.navigate(href, opts);
|
|
52
|
-
},
|
|
53
|
-
[router]
|
|
54
|
-
);
|
|
7
|
+
return useRouter().navigate;
|
|
55
8
|
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import type { SearchParamsInput } from "../../shared/search-params.ts";
|
|
2
|
+
import type { QueryStore } from "../query-store.ts";
|
|
3
|
+
import type { OptimisticCache } from "../sync.ts";
|
|
4
|
+
import { buildHref } from "./link-utils.ts";
|
|
5
|
+
|
|
6
|
+
interface Transformation {
|
|
7
|
+
href: string;
|
|
8
|
+
transform: (data: object) => object;
|
|
9
|
+
}
|
|
10
|
+
interface Operation {
|
|
11
|
+
onRemove?: () => void;
|
|
12
|
+
pending: boolean;
|
|
13
|
+
queryHref?: string;
|
|
14
|
+
transforms: Transformation[];
|
|
15
|
+
}
|
|
16
|
+
interface Snapshot {
|
|
17
|
+
href: string;
|
|
18
|
+
loaded: boolean;
|
|
19
|
+
pattern: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const SYNC_REQUEST = Symbol.for("furin.sync.request.v1");
|
|
23
|
+
|
|
24
|
+
export interface OptimisticRuntime {
|
|
25
|
+
basePath: string;
|
|
26
|
+
begin: (
|
|
27
|
+
optimistic: ((cache: OptimisticCache) => void) | undefined,
|
|
28
|
+
onRemove?: () => void,
|
|
29
|
+
hasQueries?: () => boolean
|
|
30
|
+
) => Operation;
|
|
31
|
+
commit: (href: string) => void;
|
|
32
|
+
finish: (
|
|
33
|
+
operation: Operation,
|
|
34
|
+
outcome: "success" | "error" | "ambiguous",
|
|
35
|
+
response: Response | undefined
|
|
36
|
+
) => void;
|
|
37
|
+
has: (href: string) => boolean;
|
|
38
|
+
project: <Data extends object>(data: Data, href: string) => Data;
|
|
39
|
+
publishable: (href: string, revision: number) => boolean;
|
|
40
|
+
queries?: QueryStore;
|
|
41
|
+
revision: (href?: string) => number;
|
|
42
|
+
subscribe: (listener: () => void) => () => void;
|
|
43
|
+
wait: (href: string, signal: AbortSignal | undefined) => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface RuntimeOptions {
|
|
47
|
+
basePath: string;
|
|
48
|
+
onResponse: (response: Response | undefined, optimistic: boolean) => void;
|
|
49
|
+
queries?: QueryStore;
|
|
50
|
+
snapshot: () => Snapshot;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function identity(href: string): string {
|
|
54
|
+
const url = new URL(href, "http://furin.local");
|
|
55
|
+
url.searchParams.sort();
|
|
56
|
+
return url.pathname + url.search;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const RUNTIMES = Symbol.for("furin.optimistic.runtimes.v1");
|
|
60
|
+
const runtimeGlobal = globalThis as typeof globalThis & { [RUNTIMES]?: Set<OptimisticRuntime> };
|
|
61
|
+
const runtimes = (runtimeGlobal[RUNTIMES] ??= new Set<OptimisticRuntime>());
|
|
62
|
+
|
|
63
|
+
export function registerOptimisticRuntime(runtime: OptimisticRuntime): () => void {
|
|
64
|
+
runtimes.add(runtime);
|
|
65
|
+
return () => {
|
|
66
|
+
runtimes.delete(runtime);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function findOptimisticRuntime(domain: string): OptimisticRuntime | undefined {
|
|
71
|
+
if (
|
|
72
|
+
typeof window === "undefined" ||
|
|
73
|
+
new URL(domain, window.location.origin).origin !== window.location.origin
|
|
74
|
+
) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const path = window.location.pathname;
|
|
78
|
+
const matches = [...runtimes]
|
|
79
|
+
.filter(
|
|
80
|
+
({ basePath }) => basePath === "" || path === basePath || path.startsWith(`${basePath}/`)
|
|
81
|
+
)
|
|
82
|
+
.sort((a, b) => b.basePath.length - a.basePath.length);
|
|
83
|
+
// Overlapping providers must not receive one another's projections.
|
|
84
|
+
return matches[0]?.basePath === matches[1]?.basePath ? undefined : matches[0];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function createOptimisticRuntime(options: RuntimeOptions): OptimisticRuntime {
|
|
88
|
+
const operations = new Set<Operation>();
|
|
89
|
+
const listeners = new Set<() => void>();
|
|
90
|
+
const revisions = new Map<string, number>();
|
|
91
|
+
let version = 0;
|
|
92
|
+
const notify = (operation: Operation) => {
|
|
93
|
+
version += 1;
|
|
94
|
+
for (const { href } of operation.transforms) {
|
|
95
|
+
revisions.set(href, (revisions.get(href) ?? 0) + 1);
|
|
96
|
+
}
|
|
97
|
+
if (operation.queryHref) {
|
|
98
|
+
revisions.set(operation.queryHref, (revisions.get(operation.queryHref) ?? 0) + 1);
|
|
99
|
+
}
|
|
100
|
+
for (const listener of listeners) {
|
|
101
|
+
listener();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const pending = (href: string) =>
|
|
105
|
+
[...operations].some(
|
|
106
|
+
(operation) =>
|
|
107
|
+
operation.pending &&
|
|
108
|
+
(operation.queryHref === identity(href) ||
|
|
109
|
+
operation.transforms.some((transform) => transform.href === identity(href)))
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
basePath: options.basePath,
|
|
114
|
+
queries: options.queries,
|
|
115
|
+
begin(optimistic, onRemove, hasQueries) {
|
|
116
|
+
const operation: Operation = { onRemove, pending: true, transforms: [] };
|
|
117
|
+
const cache = {
|
|
118
|
+
update(
|
|
119
|
+
target: string | { path: string; search?: SearchParamsInput },
|
|
120
|
+
transform: (data: object) => object
|
|
121
|
+
) {
|
|
122
|
+
const snapshot = options.snapshot();
|
|
123
|
+
const path =
|
|
124
|
+
typeof target === "string" ? target : buildHref(target.path, target.search, undefined);
|
|
125
|
+
const href = identity(
|
|
126
|
+
typeof target === "string" && target === snapshot.pattern ? snapshot.href : path
|
|
127
|
+
);
|
|
128
|
+
if (snapshot.loaded && href === identity(snapshot.href)) {
|
|
129
|
+
operation.transforms.push({ href, transform });
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
} as unknown as OptimisticCache;
|
|
133
|
+
optimistic?.(cache);
|
|
134
|
+
if (hasQueries?.() && options.snapshot().loaded) {
|
|
135
|
+
operation.queryHref = identity(options.snapshot().href);
|
|
136
|
+
}
|
|
137
|
+
if (operation.transforms.length > 0 || operation.queryHref !== undefined) {
|
|
138
|
+
operations.add(operation);
|
|
139
|
+
notify(operation);
|
|
140
|
+
}
|
|
141
|
+
return operation;
|
|
142
|
+
},
|
|
143
|
+
commit(href) {
|
|
144
|
+
for (const operation of operations) {
|
|
145
|
+
if (!operation.pending) {
|
|
146
|
+
if (operation.queryHref === identity(href)) {
|
|
147
|
+
operation.queryHref = undefined;
|
|
148
|
+
}
|
|
149
|
+
operation.transforms = operation.transforms.filter(
|
|
150
|
+
(transform) => transform.href !== identity(href)
|
|
151
|
+
);
|
|
152
|
+
if (operation.transforms.length === 0 && operation.queryHref === undefined) {
|
|
153
|
+
operations.delete(operation);
|
|
154
|
+
operation.onRemove?.();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Router publishes the new base and removal together; no intermediate notification.
|
|
159
|
+
},
|
|
160
|
+
finish(operation, outcome, response) {
|
|
161
|
+
operation.pending = false;
|
|
162
|
+
if (outcome === "error") {
|
|
163
|
+
operations.delete(operation);
|
|
164
|
+
}
|
|
165
|
+
if (
|
|
166
|
+
outcome === "error" ||
|
|
167
|
+
(operation.transforms.length === 0 && operation.queryHref === undefined)
|
|
168
|
+
) {
|
|
169
|
+
operation.onRemove?.();
|
|
170
|
+
}
|
|
171
|
+
if (operation.transforms.length > 0 || operation.queryHref !== undefined) {
|
|
172
|
+
notify(operation);
|
|
173
|
+
}
|
|
174
|
+
options.onResponse(
|
|
175
|
+
response,
|
|
176
|
+
outcome !== "error" &&
|
|
177
|
+
(operation.transforms.length > 0 || operation.queryHref !== undefined)
|
|
178
|
+
);
|
|
179
|
+
},
|
|
180
|
+
has: (href) =>
|
|
181
|
+
[...operations].some(
|
|
182
|
+
(operation) =>
|
|
183
|
+
operation.queryHref === identity(href) ||
|
|
184
|
+
operation.transforms.some((transform) => transform.href === identity(href))
|
|
185
|
+
),
|
|
186
|
+
project(data, href) {
|
|
187
|
+
let projected: object = data;
|
|
188
|
+
for (const operation of operations) {
|
|
189
|
+
for (const transformation of operation.transforms) {
|
|
190
|
+
if (transformation.href === identity(href)) {
|
|
191
|
+
projected = { ...projected, ...transformation.transform(projected) };
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return projected as typeof data;
|
|
196
|
+
},
|
|
197
|
+
publishable: (href, revision) =>
|
|
198
|
+
!pending(href) && (revisions.get(identity(href)) ?? 0) === revision,
|
|
199
|
+
revision: (href) => (href === undefined ? version : (revisions.get(identity(href)) ?? 0)),
|
|
200
|
+
subscribe(listener) {
|
|
201
|
+
listeners.add(listener);
|
|
202
|
+
return () => {
|
|
203
|
+
listeners.delete(listener);
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
wait(href, signal) {
|
|
207
|
+
if (signal?.aborted) {
|
|
208
|
+
return Promise.reject(signal.reason);
|
|
209
|
+
}
|
|
210
|
+
if (!pending(href)) {
|
|
211
|
+
return Promise.resolve();
|
|
212
|
+
}
|
|
213
|
+
return new Promise<void>((resolve, reject) => {
|
|
214
|
+
const cleanup = () => {
|
|
215
|
+
listeners.delete(check);
|
|
216
|
+
signal?.removeEventListener("abort", abort);
|
|
217
|
+
};
|
|
218
|
+
const abort = () => {
|
|
219
|
+
cleanup();
|
|
220
|
+
reject(signal?.reason);
|
|
221
|
+
};
|
|
222
|
+
const check = () => {
|
|
223
|
+
if (!pending(href)) {
|
|
224
|
+
cleanup();
|
|
225
|
+
resolve();
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
listeners.add(check);
|
|
229
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|