@gonvex/client 0.1.31 → 0.3.0
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/README.md +119 -95
- package/dist/control.d.ts +416 -0
- package/dist/control.js +210 -0
- package/dist/control.js.map +1 -0
- package/dist/error-reporter.d.ts +20 -6
- package/dist/error-reporter.js +55 -27
- package/dist/error-reporter.js.map +1 -1
- package/dist/index.d.ts +170 -132
- package/dist/index.js +1123 -1138
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-replica.d.ts +20 -0
- package/dist/indexeddb-replica.js +193 -0
- package/dist/indexeddb-replica.js.map +1 -0
- package/dist/kv-stores.d.ts +15 -0
- package/dist/kv-stores.js +60 -0
- package/dist/kv-stores.js.map +1 -0
- package/dist/local-replica.d.ts +240 -0
- package/dist/local-replica.js +590 -0
- package/dist/local-replica.js.map +1 -0
- package/dist/optimistic.d.ts +34 -55
- package/dist/optimistic.js +70 -269
- package/dist/optimistic.js.map +1 -1
- package/dist/outbox.d.ts +74 -16
- package/dist/outbox.js +194 -14
- package/dist/outbox.js.map +1 -1
- package/dist/query-expression.d.ts +58 -0
- package/dist/query-expression.js +164 -0
- package/dist/query-expression.js.map +1 -0
- package/dist/replica-integrity.d.ts +5 -0
- package/dist/replica-integrity.js +58 -0
- package/dist/replica-integrity.js.map +1 -0
- package/package.json +4 -4
- package/dist/browser-cache-client.d.ts +0 -77
- package/dist/browser-cache-client.js +0 -156
- package/dist/browser-cache-client.js.map +0 -1
- package/dist/browser-cache-shared-worker.d.ts +0 -35
- package/dist/browser-cache-shared-worker.js +0 -118
- package/dist/browser-cache-shared-worker.js.map +0 -1
- package/dist/browser-cache.d.ts +0 -43
- package/dist/browser-cache.js +0 -67
- package/dist/browser-cache.js.map +0 -1
- package/dist/browser-capabilities.d.ts +0 -21
- package/dist/browser-capabilities.js +0 -31
- package/dist/browser-capabilities.js.map +0 -1
- package/dist/cache-coordinator.d.ts +0 -37
- package/dist/cache-coordinator.js +0 -109
- package/dist/cache-coordinator.js.map +0 -1
- package/dist/cache.d.ts +0 -74
- package/dist/cache.js +0 -120
- package/dist/cache.js.map +0 -1
- package/dist/persistent-cache.d.ts +0 -41
- package/dist/persistent-cache.js +0 -103
- package/dist/persistent-cache.js.map +0 -1
- package/dist/query-cache.d.ts +0 -88
- package/dist/query-cache.js +0 -346
- package/dist/query-cache.js.map +0 -1
- package/dist/sync-store.d.ts +0 -96
- package/dist/sync-store.js +0 -500
- package/dist/sync-store.js.map +0 -1
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
export class CacheCoordinatorModel {
|
|
2
|
-
tabs = new Map();
|
|
3
|
-
activeTabId;
|
|
4
|
-
status = "no_owner";
|
|
5
|
-
registerTab(tab) {
|
|
6
|
-
this.tabs.set(tab.id, normalizeTab(tab));
|
|
7
|
-
this.electIfNeeded();
|
|
8
|
-
}
|
|
9
|
-
updateTab(tabId, patch) {
|
|
10
|
-
const current = this.tabs.get(tabId);
|
|
11
|
-
if (!current) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
this.tabs.set(tabId, normalizeTab({ ...current, ...patch }));
|
|
15
|
-
if (tabId === this.activeTabId && !this.canOwn(this.tabs.get(tabId))) {
|
|
16
|
-
this.activeTabId = undefined;
|
|
17
|
-
this.status = "owner_lost";
|
|
18
|
-
}
|
|
19
|
-
this.electIfNeeded();
|
|
20
|
-
}
|
|
21
|
-
closeTab(tabId) {
|
|
22
|
-
this.tabs.delete(tabId);
|
|
23
|
-
if (this.activeTabId === tabId) {
|
|
24
|
-
this.activeTabId = undefined;
|
|
25
|
-
this.status = "owner_lost";
|
|
26
|
-
}
|
|
27
|
-
this.electIfNeeded();
|
|
28
|
-
}
|
|
29
|
-
disableUnsafeFallback() {
|
|
30
|
-
this.activeTabId = undefined;
|
|
31
|
-
this.status = "unsafe_fallback_disabled";
|
|
32
|
-
}
|
|
33
|
-
verifyActiveOwnerIntegrity() {
|
|
34
|
-
if (!this.activeTabId || this.status === "unsafe_fallback_disabled") {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
this.updateTab(this.activeTabId, { integrityVerified: true });
|
|
38
|
-
}
|
|
39
|
-
markActiveOwnerStorageReady() {
|
|
40
|
-
if (!this.activeTabId || this.status === "unsafe_fallback_disabled") {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this.updateTab(this.activeTabId, { storageReady: true });
|
|
44
|
-
}
|
|
45
|
-
markActiveOwnerReady() {
|
|
46
|
-
if (!this.activeTabId || this.status === "unsafe_fallback_disabled") {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
this.updateTab(this.activeTabId, {
|
|
50
|
-
dedicatedWorkerReady: true,
|
|
51
|
-
storageReady: true,
|
|
52
|
-
integrityVerified: true,
|
|
53
|
-
});
|
|
54
|
-
this.electIfNeeded();
|
|
55
|
-
}
|
|
56
|
-
routeRequest() {
|
|
57
|
-
if (this.status === "unsafe_fallback_disabled") {
|
|
58
|
-
return { route: "server", reason: "unsafe-fallback-disabled" };
|
|
59
|
-
}
|
|
60
|
-
if (!this.activeTabId) {
|
|
61
|
-
return { route: "server", reason: "no-active-owner" };
|
|
62
|
-
}
|
|
63
|
-
const active = this.tabs.get(this.activeTabId);
|
|
64
|
-
if (!this.canOwn(active) || !this.ownerReady(active) || this.status !== "active_owner_ready") {
|
|
65
|
-
return { route: "server", reason: "owner-not-ready" };
|
|
66
|
-
}
|
|
67
|
-
return { route: "active-worker", activeTabId: this.activeTabId };
|
|
68
|
-
}
|
|
69
|
-
snapshot() {
|
|
70
|
-
return {
|
|
71
|
-
status: this.status,
|
|
72
|
-
activeTabId: this.activeTabId,
|
|
73
|
-
tabs: [...this.tabs.values()].map((tab) => ({ ...tab })),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
electIfNeeded() {
|
|
77
|
-
if (this.status === "unsafe_fallback_disabled") {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (this.activeTabId && this.canOwn(this.tabs.get(this.activeTabId))) {
|
|
81
|
-
this.status = this.ownerReady(this.tabs.get(this.activeTabId)) ? "active_owner_ready" : "electing";
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const nextOwner = [...this.tabs.values()]
|
|
85
|
-
.filter((tab) => this.canOwn(tab))
|
|
86
|
-
.sort((left, right) => left.id.localeCompare(right.id))[0];
|
|
87
|
-
if (!nextOwner) {
|
|
88
|
-
this.activeTabId = undefined;
|
|
89
|
-
this.status = this.tabs.size > 0 ? "electing" : "no_owner";
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
this.activeTabId = nextOwner.id;
|
|
93
|
-
this.status = this.ownerReady(nextOwner) ? "active_owner_ready" : "electing";
|
|
94
|
-
}
|
|
95
|
-
canOwn(tab) {
|
|
96
|
-
return Boolean(tab?.hasLivenessLock);
|
|
97
|
-
}
|
|
98
|
-
ownerReady(tab) {
|
|
99
|
-
return Boolean(tab?.dedicatedWorkerReady && tab.storageReady && tab.integrityVerified);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function normalizeTab(tab) {
|
|
103
|
-
return {
|
|
104
|
-
...tab,
|
|
105
|
-
storageReady: tab.storageReady ?? false,
|
|
106
|
-
integrityVerified: tab.integrityVerified ?? false,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=cache-coordinator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-coordinator.js","sourceRoot":"","sources":["../src/cache-coordinator.ts"],"names":[],"mappings":"AAoBA,MAAM,OAAO,qBAAqB;IACxB,IAAI,GAAG,IAAI,GAAG,EAAoB,CAAC;IACnC,WAAW,CAAqB;IAChC,MAAM,GAAqB,UAAU,CAAC;IAE9C,WAAW,CAAC,GAAa;QACvB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,IAAI,C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G,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;YAC3D,OAAO;QACT,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,UAAU,CAAC;IAC/E,CAAC;IAEO,MAAM,CAAC,GAAyB;QACtC,OAAO,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACvC,CAAC;IAEO,UAAU,CAAC,GAAyB;QAC1C,OAAO,OAAO,CAAC,GAAG,EAAE,oBAAoB,IAAI,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACzF,CAAC;CACF;AAED,SAAS,YAAY,CAAC,GAAa;IACjC,OAAO;QACL,GAAG,GAAG;QACN,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,KAAK;QACvC,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,IAAI,KAAK;KAClD,CAAC;AACJ,CAAC"}
|
package/dist/cache.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
export type ShapeSyncStatus = "not_started" | "syncing" | "ready" | "stale" | "too_large" | "error";
|
|
2
|
-
export type CacheDBHealth = "healthy" | "initializing" | "unavailable" | "corrupt";
|
|
3
|
-
export type CacheRoutingSource = "local" | "server";
|
|
4
|
-
export type CacheRoutingReason = "local-ready" | "query-has-no-local-plan" | "query-has-no-shape" | "shape-missing" | "shape-does-not-cover-query" | "shape-not-ready" | "shape-too-large" | "query-row-limit-unsafe" | "shape-auth-scope-mismatch" | "shape-epoch-mismatch" | "db-not-healthy" | "db-owner-unsafe";
|
|
5
|
-
export type CacheShapeVisibilityScope = "project" | "tenant" | "user" | "auth";
|
|
6
|
-
export type CacheShapeDefinition = {
|
|
7
|
-
id: string;
|
|
8
|
-
tables: string[];
|
|
9
|
-
visibilityScope: CacheShapeVisibilityScope;
|
|
10
|
-
maxRows?: number;
|
|
11
|
-
maxBytes?: number;
|
|
12
|
-
schemaVersion: string;
|
|
13
|
-
permissionVersion: string;
|
|
14
|
-
};
|
|
15
|
-
export type CacheShapeState = {
|
|
16
|
-
id: string;
|
|
17
|
-
projectId: string;
|
|
18
|
-
tenantId: string;
|
|
19
|
-
userId: string;
|
|
20
|
-
authScope: string;
|
|
21
|
-
status: ShapeSyncStatus;
|
|
22
|
-
schemaVersion: string;
|
|
23
|
-
permissionVersion: string;
|
|
24
|
-
checkpoint?: string;
|
|
25
|
-
rowCount?: number;
|
|
26
|
-
maxRows?: number;
|
|
27
|
-
};
|
|
28
|
-
export type CacheQueryPlan = {
|
|
29
|
-
queryKey: string;
|
|
30
|
-
queryPath?: string;
|
|
31
|
-
projectId: string;
|
|
32
|
-
tenantId: string;
|
|
33
|
-
userId: string;
|
|
34
|
-
authScope: string;
|
|
35
|
-
requiredShapeId?: string;
|
|
36
|
-
hasLocalPlan: boolean;
|
|
37
|
-
schemaVersion: string;
|
|
38
|
-
permissionVersion: string;
|
|
39
|
-
coveredByShapeIds?: string[];
|
|
40
|
-
estimatedRows?: number;
|
|
41
|
-
limit?: number;
|
|
42
|
-
};
|
|
43
|
-
export type CacheEnvironment = {
|
|
44
|
-
dbHealth: CacheDBHealth;
|
|
45
|
-
singleWriter: boolean;
|
|
46
|
-
shapes: Record<string, CacheShapeState | undefined>;
|
|
47
|
-
definitions?: Record<string, CacheShapeDefinition | undefined>;
|
|
48
|
-
};
|
|
49
|
-
export type CacheRoutingDecision = {
|
|
50
|
-
source: CacheRoutingSource;
|
|
51
|
-
reason: CacheRoutingReason;
|
|
52
|
-
shape?: CacheShapeState;
|
|
53
|
-
};
|
|
54
|
-
export type CacheFailureAction = {
|
|
55
|
-
action: "reset-and-server-fallback";
|
|
56
|
-
reason: "cache-corruption-suspected";
|
|
57
|
-
} | {
|
|
58
|
-
action: "server-fallback";
|
|
59
|
-
reason: "ordinary-failure";
|
|
60
|
-
};
|
|
61
|
-
export declare function chooseQuerySource(query: CacheQueryPlan, environment: CacheEnvironment): CacheRoutingDecision;
|
|
62
|
-
export declare function defineVisibleShape(definition: CacheShapeDefinition): CacheShapeDefinition;
|
|
63
|
-
export declare function cacheKey(parts: {
|
|
64
|
-
projectId: string;
|
|
65
|
-
tenantId: string;
|
|
66
|
-
userId: string;
|
|
67
|
-
authScope: string;
|
|
68
|
-
queryPath: string;
|
|
69
|
-
argsHash: string;
|
|
70
|
-
schemaVersion: string;
|
|
71
|
-
permissionVersion: string;
|
|
72
|
-
}): string;
|
|
73
|
-
export declare function shouldResetLocalCache(error: unknown): boolean;
|
|
74
|
-
export declare function cacheFailureAction(error: unknown): CacheFailureAction;
|
package/dist/cache.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
export function chooseQuerySource(query, environment) {
|
|
2
|
-
if (!query.hasLocalPlan) {
|
|
3
|
-
return server("query-has-no-local-plan");
|
|
4
|
-
}
|
|
5
|
-
if (!query.requiredShapeId) {
|
|
6
|
-
return server("query-has-no-shape");
|
|
7
|
-
}
|
|
8
|
-
if (environment.dbHealth !== "healthy") {
|
|
9
|
-
return server("db-not-healthy");
|
|
10
|
-
}
|
|
11
|
-
if (!environment.singleWriter) {
|
|
12
|
-
return server("db-owner-unsafe");
|
|
13
|
-
}
|
|
14
|
-
const shape = environment.shapes[query.requiredShapeId];
|
|
15
|
-
if (!shape) {
|
|
16
|
-
return server("shape-missing");
|
|
17
|
-
}
|
|
18
|
-
const definition = environment.definitions?.[query.requiredShapeId];
|
|
19
|
-
if (!shapeCoversQuery(query, definition)) {
|
|
20
|
-
return server("shape-does-not-cover-query", shape);
|
|
21
|
-
}
|
|
22
|
-
if (shape.status === "too_large") {
|
|
23
|
-
return server("shape-too-large", shape);
|
|
24
|
-
}
|
|
25
|
-
if (shape.status !== "ready") {
|
|
26
|
-
return server("shape-not-ready", shape);
|
|
27
|
-
}
|
|
28
|
-
if (!sameScope(query, shape)) {
|
|
29
|
-
return server("shape-auth-scope-mismatch", shape);
|
|
30
|
-
}
|
|
31
|
-
if (shape.schemaVersion !== query.schemaVersion || shape.permissionVersion !== query.permissionVersion) {
|
|
32
|
-
return server("shape-epoch-mismatch", shape);
|
|
33
|
-
}
|
|
34
|
-
if (shape.maxRows !== undefined && shape.rowCount !== undefined && shape.rowCount > shape.maxRows) {
|
|
35
|
-
return server("shape-too-large", shape);
|
|
36
|
-
}
|
|
37
|
-
if (!queryLimitIsSafe(query, shape, definition)) {
|
|
38
|
-
return server("query-row-limit-unsafe", shape);
|
|
39
|
-
}
|
|
40
|
-
return { source: "local", reason: "local-ready", shape };
|
|
41
|
-
}
|
|
42
|
-
export function defineVisibleShape(definition) {
|
|
43
|
-
if (!definition.id.trim()) {
|
|
44
|
-
throw new Error("cache shape id is required");
|
|
45
|
-
}
|
|
46
|
-
if (definition.tables.length === 0 || definition.tables.some((table) => !table.trim())) {
|
|
47
|
-
throw new Error(`cache shape ${definition.id} must include at least one table`);
|
|
48
|
-
}
|
|
49
|
-
if (definition.maxRows !== undefined && definition.maxRows <= 0) {
|
|
50
|
-
throw new Error(`cache shape ${definition.id} maxRows must be positive`);
|
|
51
|
-
}
|
|
52
|
-
if (definition.maxBytes !== undefined && definition.maxBytes <= 0) {
|
|
53
|
-
throw new Error(`cache shape ${definition.id} maxBytes must be positive`);
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
...definition,
|
|
57
|
-
tables: [...definition.tables],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export function cacheKey(parts) {
|
|
61
|
-
return [
|
|
62
|
-
"gonvex",
|
|
63
|
-
parts.projectId,
|
|
64
|
-
parts.tenantId,
|
|
65
|
-
parts.userId,
|
|
66
|
-
parts.authScope,
|
|
67
|
-
parts.queryPath,
|
|
68
|
-
parts.argsHash,
|
|
69
|
-
parts.schemaVersion,
|
|
70
|
-
parts.permissionVersion,
|
|
71
|
-
].map(escapeKeyPart).join(":");
|
|
72
|
-
}
|
|
73
|
-
export function shouldResetLocalCache(error) {
|
|
74
|
-
if (!(error instanceof Error)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const message = error.message.toLowerCase();
|
|
78
|
-
return message.includes("corrupt")
|
|
79
|
-
|| message.includes("integrity")
|
|
80
|
-
|| message.includes("checkpoint")
|
|
81
|
-
|| message.includes("schema mismatch");
|
|
82
|
-
}
|
|
83
|
-
export function cacheFailureAction(error) {
|
|
84
|
-
if (shouldResetLocalCache(error)) {
|
|
85
|
-
return { action: "reset-and-server-fallback", reason: "cache-corruption-suspected" };
|
|
86
|
-
}
|
|
87
|
-
return { action: "server-fallback", reason: "ordinary-failure" };
|
|
88
|
-
}
|
|
89
|
-
function sameScope(query, shape) {
|
|
90
|
-
return shape.projectId === query.projectId
|
|
91
|
-
&& shape.tenantId === query.tenantId
|
|
92
|
-
&& shape.userId === query.userId
|
|
93
|
-
&& shape.authScope === query.authScope;
|
|
94
|
-
}
|
|
95
|
-
function shapeCoversQuery(query, definition) {
|
|
96
|
-
if (query.coveredByShapeIds) {
|
|
97
|
-
return query.coveredByShapeIds.includes(query.requiredShapeId ?? "");
|
|
98
|
-
}
|
|
99
|
-
return definition !== undefined;
|
|
100
|
-
}
|
|
101
|
-
function queryLimitIsSafe(query, shape, definition) {
|
|
102
|
-
const maxRows = shape.maxRows ?? definition?.maxRows;
|
|
103
|
-
if (maxRows === undefined) {
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
if (query.limit !== undefined) {
|
|
107
|
-
return query.limit <= maxRows;
|
|
108
|
-
}
|
|
109
|
-
if (query.estimatedRows !== undefined) {
|
|
110
|
-
return query.estimatedRows <= maxRows;
|
|
111
|
-
}
|
|
112
|
-
return shape.rowCount === undefined || shape.rowCount <= maxRows;
|
|
113
|
-
}
|
|
114
|
-
function server(reason, shape) {
|
|
115
|
-
return { source: "server", reason, shape };
|
|
116
|
-
}
|
|
117
|
-
function escapeKeyPart(part) {
|
|
118
|
-
return encodeURIComponent(part);
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=cache.js.map
|
package/dist/cache.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AA+EA,MAAM,UAAU,iBAAiB,CAAC,KAAqB,EAAE,WAA6B;IACpF,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,yBAAyB,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,WAAW,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACxD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,eAAe,CAAC,CAAC;IACjC,CAAC;IACD,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACpE,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;QACzC,OAAO,MAAM,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE,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IACD,OAAO,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,IAAI,OAAO,CAAC;AACnE,CAAC;AAED,SAAS,MAAM,CAAC,MAA0B,EAAE,KAAuB;IACjE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type CacheDBHealth, type CacheEnvironment, type CacheQueryPlan, type CacheRoutingDecision, type CacheShapeDefinition, type CacheShapeState } from "./cache.js";
|
|
2
|
-
import { CacheCoordinatorModel } from "./cache-coordinator.js";
|
|
3
|
-
import { type BrowserCacheCapabilities } from "./browser-capabilities.js";
|
|
4
|
-
export type ShapeHydrationResult = Omit<CacheShapeState, "status"> & {
|
|
5
|
-
status?: CacheShapeState["status"];
|
|
6
|
-
};
|
|
7
|
-
export type ShapeHydrator = (definition: CacheShapeDefinition) => Promise<ShapeHydrationResult>;
|
|
8
|
-
export declare class CacheMetadataStore {
|
|
9
|
-
private dbHealth;
|
|
10
|
-
private readonly definitions;
|
|
11
|
-
private readonly shapes;
|
|
12
|
-
setDBHealth(health: CacheDBHealth): void;
|
|
13
|
-
getDBHealth(): CacheDBHealth;
|
|
14
|
-
registerShape(definition: CacheShapeDefinition): void;
|
|
15
|
-
markShapeSyncing(definition: CacheShapeDefinition, scope: Pick<CacheShapeState, "projectId" | "tenantId" | "userId" | "authScope">): void;
|
|
16
|
-
updateShape(shape: CacheShapeState): void;
|
|
17
|
-
markAllShapesStale(): void;
|
|
18
|
-
environment(singleWriter: boolean): CacheEnvironment;
|
|
19
|
-
shapeStates(): {
|
|
20
|
-
id: string;
|
|
21
|
-
projectId: string;
|
|
22
|
-
tenantId: string;
|
|
23
|
-
userId: string;
|
|
24
|
-
authScope: string;
|
|
25
|
-
status: import("./cache.js").ShapeSyncStatus;
|
|
26
|
-
schemaVersion: string;
|
|
27
|
-
permissionVersion: string;
|
|
28
|
-
checkpoint?: string;
|
|
29
|
-
rowCount?: number;
|
|
30
|
-
maxRows?: number;
|
|
31
|
-
}[];
|
|
32
|
-
}
|
|
33
|
-
export declare class BrowserPersistentCache {
|
|
34
|
-
readonly metadata: CacheMetadataStore;
|
|
35
|
-
readonly coordinator: CacheCoordinatorModel;
|
|
36
|
-
constructor(metadata?: CacheMetadataStore, coordinator?: CacheCoordinatorModel);
|
|
37
|
-
decideQuerySource(query: CacheQueryPlan): CacheRoutingDecision;
|
|
38
|
-
disableIfUnsupported(capabilities?: BrowserCacheCapabilities): BrowserCacheCapabilities;
|
|
39
|
-
hydrateShapeInBackground(definition: CacheShapeDefinition, scope: Pick<CacheShapeState, "projectId" | "tenantId" | "userId" | "authScope">, hydrate: ShapeHydrator): void;
|
|
40
|
-
quarantineScope(nextScope: Pick<CacheShapeState, "projectId" | "tenantId" | "userId" | "authScope">): void;
|
|
41
|
-
}
|
package/dist/persistent-cache.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { chooseQuerySource, } from "./cache.js";
|
|
2
|
-
import { CacheCoordinatorModel } from "./cache-coordinator.js";
|
|
3
|
-
import { detectBrowserCacheCapabilities } from "./browser-capabilities.js";
|
|
4
|
-
export class CacheMetadataStore {
|
|
5
|
-
dbHealth = "initializing";
|
|
6
|
-
definitions = new Map();
|
|
7
|
-
shapes = new Map();
|
|
8
|
-
setDBHealth(health) {
|
|
9
|
-
this.dbHealth = health;
|
|
10
|
-
}
|
|
11
|
-
getDBHealth() {
|
|
12
|
-
return this.dbHealth;
|
|
13
|
-
}
|
|
14
|
-
registerShape(definition) {
|
|
15
|
-
this.definitions.set(definition.id, definition);
|
|
16
|
-
}
|
|
17
|
-
markShapeSyncing(definition, scope) {
|
|
18
|
-
this.registerShape(definition);
|
|
19
|
-
this.shapes.set(definition.id, {
|
|
20
|
-
id: definition.id,
|
|
21
|
-
...scope,
|
|
22
|
-
status: "syncing",
|
|
23
|
-
schemaVersion: definition.schemaVersion,
|
|
24
|
-
permissionVersion: definition.permissionVersion,
|
|
25
|
-
maxRows: definition.maxRows,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
updateShape(shape) {
|
|
29
|
-
this.shapes.set(shape.id, { ...shape });
|
|
30
|
-
}
|
|
31
|
-
markAllShapesStale() {
|
|
32
|
-
for (const [id, shape] of this.shapes) {
|
|
33
|
-
this.shapes.set(id, { ...shape, status: "stale" });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
environment(singleWriter) {
|
|
37
|
-
return {
|
|
38
|
-
dbHealth: this.dbHealth,
|
|
39
|
-
singleWriter,
|
|
40
|
-
shapes: Object.fromEntries(this.shapes),
|
|
41
|
-
definitions: Object.fromEntries(this.definitions),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
shapeStates() {
|
|
45
|
-
return [...this.shapes.values()].map((shape) => ({ ...shape }));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export class BrowserPersistentCache {
|
|
49
|
-
metadata;
|
|
50
|
-
coordinator;
|
|
51
|
-
constructor(metadata = new CacheMetadataStore(), coordinator = new CacheCoordinatorModel()) {
|
|
52
|
-
this.metadata = metadata;
|
|
53
|
-
this.coordinator = coordinator;
|
|
54
|
-
}
|
|
55
|
-
decideQuerySource(query) {
|
|
56
|
-
const route = this.coordinator.routeRequest();
|
|
57
|
-
return chooseQuerySource(query, this.metadata.environment(route.route === "active-worker"));
|
|
58
|
-
}
|
|
59
|
-
disableIfUnsupported(capabilities = detectBrowserCacheCapabilities()) {
|
|
60
|
-
if (!capabilities.supported) {
|
|
61
|
-
this.coordinator.disableUnsafeFallback();
|
|
62
|
-
}
|
|
63
|
-
return capabilities;
|
|
64
|
-
}
|
|
65
|
-
hydrateShapeInBackground(definition, scope, hydrate) {
|
|
66
|
-
this.metadata.markShapeSyncing(definition, scope);
|
|
67
|
-
void hydrate(definition).then((shape) => {
|
|
68
|
-
this.metadata.updateShape({
|
|
69
|
-
...shape,
|
|
70
|
-
id: definition.id,
|
|
71
|
-
projectId: shape.projectId,
|
|
72
|
-
tenantId: shape.tenantId,
|
|
73
|
-
userId: shape.userId,
|
|
74
|
-
authScope: shape.authScope,
|
|
75
|
-
status: shape.status ?? "ready",
|
|
76
|
-
schemaVersion: definition.schemaVersion,
|
|
77
|
-
permissionVersion: definition.permissionVersion,
|
|
78
|
-
maxRows: definition.maxRows,
|
|
79
|
-
});
|
|
80
|
-
}).catch(() => {
|
|
81
|
-
this.metadata.updateShape({
|
|
82
|
-
id: definition.id,
|
|
83
|
-
...scope,
|
|
84
|
-
status: "error",
|
|
85
|
-
schemaVersion: definition.schemaVersion,
|
|
86
|
-
permissionVersion: definition.permissionVersion,
|
|
87
|
-
maxRows: definition.maxRows,
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
quarantineScope(nextScope) {
|
|
92
|
-
for (const shape of this.metadata.shapeStates()) {
|
|
93
|
-
const scopeMatches = shape.projectId === nextScope.projectId
|
|
94
|
-
&& shape.tenantId === nextScope.tenantId
|
|
95
|
-
&& shape.userId === nextScope.userId
|
|
96
|
-
&& shape.authScope === nextScope.authScope;
|
|
97
|
-
if (!scopeMatches) {
|
|
98
|
-
this.metadata.updateShape({ ...shape, status: "stale" });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=persistent-cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"persistent-cache.js","sourceRoot":"","sources":["../src/persistent-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAOlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAiC,MAAM,2BAA2B,CAAC;AAQ1G,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}
|
package/dist/query-cache.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { JsonValue } from "@gonvex/protocol";
|
|
2
|
-
export declare const defaultQueryCacheMaxAgeMs: number;
|
|
3
|
-
export declare const defaultQueryCacheMaxEntryBytes: number;
|
|
4
|
-
export declare const defaultQueryCacheMaxEntriesPerScope = 100;
|
|
5
|
-
export declare const defaultQueryCacheMaxBytesPerScope: number;
|
|
6
|
-
export declare const defaultQueryCacheMaxBytes: number;
|
|
7
|
-
export declare const defaultQueryCacheReadTimeoutMs = 250;
|
|
8
|
-
export type QueryCacheLookup = {
|
|
9
|
-
result: JsonValue;
|
|
10
|
-
revision: string;
|
|
11
|
-
writtenAt: number;
|
|
12
|
-
ageMs: number;
|
|
13
|
-
};
|
|
14
|
-
export type QueryCacheWrite = {
|
|
15
|
-
scope: string;
|
|
16
|
-
path: string;
|
|
17
|
-
args: JsonValue;
|
|
18
|
-
result: JsonValue;
|
|
19
|
-
revision: string;
|
|
20
|
-
maxAgeMs: number;
|
|
21
|
-
};
|
|
22
|
-
export type QueryCacheWriteOutcome = "written" | "older" | "oversize" | "disabled" | "error";
|
|
23
|
-
export type QueryCacheStatus = {
|
|
24
|
-
enabled: boolean;
|
|
25
|
-
readsEnabled: boolean;
|
|
26
|
-
writesEnabled: boolean;
|
|
27
|
-
reason?: string;
|
|
28
|
-
};
|
|
29
|
-
export type QueryCacheStore = {
|
|
30
|
-
read(scope: string, path: string, args: JsonValue, maxAgeMs?: number): Promise<QueryCacheLookup | undefined>;
|
|
31
|
-
write(value: QueryCacheWrite): Promise<QueryCacheWriteOutcome>;
|
|
32
|
-
delete(scope: string, path: string, args: JsonValue): Promise<void>;
|
|
33
|
-
clear(scope?: string): Promise<void>;
|
|
34
|
-
status(): QueryCacheStatus;
|
|
35
|
-
close(): void;
|
|
36
|
-
};
|
|
37
|
-
export type QueryCacheOptions = {
|
|
38
|
-
enabled?: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Maximum time to wait for a persisted warm result before subscribing
|
|
41
|
-
* without its revision. Defaults to 250ms. This is intentionally longer
|
|
42
|
-
* than a typical IndexedDB read so startup contention does not turn a warm
|
|
43
|
-
* reload into a full server payload.
|
|
44
|
-
*/
|
|
45
|
-
readTimeoutMs?: number;
|
|
46
|
-
maxAgeMs?: number;
|
|
47
|
-
maxEntryBytes?: number;
|
|
48
|
-
maxEntriesPerScope?: number;
|
|
49
|
-
maxBytesPerScope?: number;
|
|
50
|
-
maxBytes?: number;
|
|
51
|
-
store?: QueryCacheStore;
|
|
52
|
-
databaseName?: string;
|
|
53
|
-
indexedDB?: IDBFactory;
|
|
54
|
-
IDBKeyRange?: typeof IDBKeyRange;
|
|
55
|
-
};
|
|
56
|
-
export declare class DexieQueryCacheStore implements QueryCacheStore {
|
|
57
|
-
private readonly databaseName;
|
|
58
|
-
private readonly maxAgeMs;
|
|
59
|
-
private readonly maxEntryBytes;
|
|
60
|
-
private readonly maxEntriesPerScope;
|
|
61
|
-
private readonly maxBytesPerScope;
|
|
62
|
-
private readonly maxBytes;
|
|
63
|
-
private readonly indexedDB?;
|
|
64
|
-
private readonly keyRange?;
|
|
65
|
-
private readonly memory;
|
|
66
|
-
private databasePromise;
|
|
67
|
-
private database;
|
|
68
|
-
private readsEnabled;
|
|
69
|
-
private writesEnabled;
|
|
70
|
-
private disabledReason;
|
|
71
|
-
private cleanupScheduled;
|
|
72
|
-
constructor(options?: QueryCacheOptions);
|
|
73
|
-
read(scope: string, path: string, args: JsonValue, maxAgeMs?: number): Promise<QueryCacheLookup | undefined>;
|
|
74
|
-
write(value: QueryCacheWrite): Promise<QueryCacheWriteOutcome>;
|
|
75
|
-
delete(scope: string, path: string, args: JsonValue): Promise<void>;
|
|
76
|
-
clear(scope?: string): Promise<void>;
|
|
77
|
-
status(): QueryCacheStatus;
|
|
78
|
-
close(): void;
|
|
79
|
-
private open;
|
|
80
|
-
private createDatabase;
|
|
81
|
-
private putRecord;
|
|
82
|
-
private deleteByHash;
|
|
83
|
-
private touchMemory;
|
|
84
|
-
private scheduleCleanup;
|
|
85
|
-
private cleanup;
|
|
86
|
-
private disable;
|
|
87
|
-
}
|
|
88
|
-
export declare function createQueryCacheStore(options: QueryCacheOptions | false | undefined): QueryCacheStore | undefined;
|