ahmed-rivet-convex 2.2.6 → 2.2.7
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/{chunk-BKP7XQAL.js → chunk-5AEROL6U.js} +460 -85
- package/dist/react.js +1 -1
- package/dist/replicache/src/bg-interval.d.ts +7 -1
- package/dist/replicache/src/kv/idb-store.d.ts +8 -0
- package/dist/replicache/src/new-client-channel.d.ts +9 -1
- package/dist/replicache/src/persist/heartbeat.d.ts +7 -1
- package/dist/replicache/src/replicache-impl.d.ts +50 -2
- package/dist/replicache/src/replicache-options.d.ts +3 -0
- package/dist/zero-client/src/client/options.d.ts +5 -1
- package/dist/zero-client/src/client/zero-rep.d.ts +6 -0
- package/dist/zero.js +1 -1
- package/package.json +1 -1
|
@@ -940,6 +940,9 @@ var RefCountUpdates = class {
|
|
|
940
940
|
this.#refsCounted = this.#isLazyDelegate ? /* @__PURE__ */ new Set() : null;
|
|
941
941
|
}
|
|
942
942
|
async compute() {
|
|
943
|
+
if (!this.#isLazyDelegate) {
|
|
944
|
+
return this.#computeNet();
|
|
945
|
+
}
|
|
943
946
|
for (const n of this.#newHeads) {
|
|
944
947
|
await this.#changeRefCount(n, 1);
|
|
945
948
|
}
|
|
@@ -977,6 +980,153 @@ var RefCountUpdates = class {
|
|
|
977
980
|
}
|
|
978
981
|
return this.#refCountUpdates;
|
|
979
982
|
}
|
|
983
|
+
/**
|
|
984
|
+
* For stores that count every ref eagerly (the IndexedDB perdag). A
|
|
985
|
+
* persist replaces one path of a tree: the new root counts each of its
|
|
986
|
+
* children +1 and the old root -1, so nearly every child ends where it
|
|
987
|
+
* started. Counting them one by one loaded and rewrote each child's ref
|
|
988
|
+
* count — an IndexedDB get and put per child, ~300 of each per persist
|
|
989
|
+
* at 50k rows, the long-lived tab's write storm. Here deltas are summed
|
|
990
|
+
* first: a count is loaded only when it can matter, and only counts that
|
|
991
|
+
* changed (plus every put chunk, as documented) are returned. A chunk
|
|
992
|
+
* passes a change on to its refs when its count crosses zero — the same
|
|
993
|
+
* result as counting one by one.
|
|
994
|
+
*
|
|
995
|
+
* Order matters for cost, not for the result. Increments are passed on
|
|
996
|
+
* first and decrements held back until no increment is left: a persist
|
|
997
|
+
* of N writes puts a chain of N new commits whose first sits on the old
|
|
998
|
+
* head, so the chain's +1 reaches the old head N levels after the old
|
|
999
|
+
* head's own -1. Passing the -1 on at once dropped the whole old tree to
|
|
1000
|
+
* zero, then back.
|
|
1001
|
+
*
|
|
1002
|
+
* A +1 to a stored chunk this write did not put cannot make it newly
|
|
1003
|
+
* reachable: the store deletes a chunk whose count reaches 0, so every
|
|
1004
|
+
* chunk it holds has a count of at least 1. Such a count is not loaded
|
|
1005
|
+
* until the end (it is needed then only if it changed), and if it turns
|
|
1006
|
+
* out to be 0 after all, the change is passed on then.
|
|
1007
|
+
*
|
|
1008
|
+
* INVARIANT the assumed >= 1 shortcut depends on: the eager store deletes
|
|
1009
|
+
* any chunk whose count reaches 0. `StoreImpl.#applyRefCountUpdates`
|
|
1010
|
+
* does that for every returned entry with a count of 0
|
|
1011
|
+
* (`#removeAllRelatedKeys`), and it is safe that only changed counts and
|
|
1012
|
+
* put chunks are returned, because an unreturned count is by definition
|
|
1013
|
+
* unchanged and so already stored correctly. The quiescence check below
|
|
1014
|
+
* verifies the invariant instead of trusting it: every assumed chunk
|
|
1015
|
+
* whose net is not 0 is loaded, and a stored 0 is passed on as a real
|
|
1016
|
+
* 0 -> positive change. An assumed chunk whose net returns to 0 is never
|
|
1017
|
+
* loaded and never returned.
|
|
1018
|
+
*/
|
|
1019
|
+
async #computeNet() {
|
|
1020
|
+
const delegate = this.#delegate;
|
|
1021
|
+
const putChunks = this.#putChunks;
|
|
1022
|
+
const net = /* @__PURE__ */ new Map();
|
|
1023
|
+
const loaded = /* @__PURE__ */ new Map();
|
|
1024
|
+
const propagated = /* @__PURE__ */ new Map();
|
|
1025
|
+
const assumed = /* @__PURE__ */ new Set();
|
|
1026
|
+
const held = /* @__PURE__ */ new Set();
|
|
1027
|
+
let dirty = /* @__PURE__ */ new Set();
|
|
1028
|
+
const add = (hash, delta) => {
|
|
1029
|
+
net.set(hash, (net.get(hash) ?? 0) + delta);
|
|
1030
|
+
dirty.add(hash);
|
|
1031
|
+
};
|
|
1032
|
+
const load = (hashes) => Promise.all(
|
|
1033
|
+
Array.from(hashes, async (hash) => {
|
|
1034
|
+
if (!loaded.has(hash)) {
|
|
1035
|
+
loaded.set(hash, await delegate.getRefCount(hash) || 0);
|
|
1036
|
+
}
|
|
1037
|
+
})
|
|
1038
|
+
);
|
|
1039
|
+
const want = (hash) => {
|
|
1040
|
+
const old = loaded.get(hash);
|
|
1041
|
+
if (old === void 0 || hash === emptyHash) {
|
|
1042
|
+
return 0;
|
|
1043
|
+
}
|
|
1044
|
+
const now = old + (net.get(hash) ?? 0);
|
|
1045
|
+
return old === 0 && now > 0 ? 1 : old > 0 && now === 0 ? -1 : 0;
|
|
1046
|
+
};
|
|
1047
|
+
const passOn = async (hashes) => {
|
|
1048
|
+
const changes = [];
|
|
1049
|
+
for (const hash of hashes) {
|
|
1050
|
+
const w = want(hash);
|
|
1051
|
+
const d = w - (propagated.get(hash) ?? 0);
|
|
1052
|
+
if (d !== 0) {
|
|
1053
|
+
propagated.set(hash, w);
|
|
1054
|
+
changes.push([hash, d]);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
const refs = await Promise.all(
|
|
1058
|
+
changes.map(([hash]) => delegate.getRefs(hash))
|
|
1059
|
+
);
|
|
1060
|
+
for (let i = 0; i < changes.length; i++) {
|
|
1061
|
+
if (!isProd) {
|
|
1062
|
+
assert(refs[i], "refs must be defined");
|
|
1063
|
+
}
|
|
1064
|
+
for (const ref of refs[i] ?? []) add(ref, changes[i][1]);
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
for (const n of this.#newHeads) add(n, 1);
|
|
1068
|
+
for (const o of this.#oldHeads) add(o, -1);
|
|
1069
|
+
for (; ; ) {
|
|
1070
|
+
if (dirty.size > 0) {
|
|
1071
|
+
const current = dirty;
|
|
1072
|
+
dirty = /* @__PURE__ */ new Set();
|
|
1073
|
+
const toLoad = [];
|
|
1074
|
+
for (const hash of current) {
|
|
1075
|
+
const n = net.get(hash) ?? 0;
|
|
1076
|
+
if (loaded.has(hash) || n === 0) {
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
if (n < 0 || putChunks.has(hash)) {
|
|
1080
|
+
toLoad.push(hash);
|
|
1081
|
+
} else {
|
|
1082
|
+
assumed.add(hash);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
await load(toLoad);
|
|
1086
|
+
const up = [];
|
|
1087
|
+
for (const hash of current) {
|
|
1088
|
+
const d = want(hash) - (propagated.get(hash) ?? 0);
|
|
1089
|
+
if (d > 0) {
|
|
1090
|
+
up.push(hash);
|
|
1091
|
+
} else if (d < 0) {
|
|
1092
|
+
held.add(hash);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
await passOn(up);
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
if (held.size > 0) {
|
|
1099
|
+
const down = [...held];
|
|
1100
|
+
held.clear();
|
|
1101
|
+
await passOn(down);
|
|
1102
|
+
continue;
|
|
1103
|
+
}
|
|
1104
|
+
const unverified = [...assumed].filter(
|
|
1105
|
+
(hash) => !loaded.has(hash) && (net.get(hash) ?? 0) !== 0
|
|
1106
|
+
);
|
|
1107
|
+
assumed.clear();
|
|
1108
|
+
if (unverified.length === 0) {
|
|
1109
|
+
break;
|
|
1110
|
+
}
|
|
1111
|
+
await load(unverified);
|
|
1112
|
+
for (const hash of unverified) dirty.add(hash);
|
|
1113
|
+
}
|
|
1114
|
+
await load(putChunks);
|
|
1115
|
+
const updates = this.#refCountUpdates;
|
|
1116
|
+
for (const [hash, old] of loaded) {
|
|
1117
|
+
const now = old + (net.get(hash) ?? 0);
|
|
1118
|
+
if (now !== old || putChunks.has(hash)) {
|
|
1119
|
+
if (!isProd) {
|
|
1120
|
+
assert(
|
|
1121
|
+
now >= 0,
|
|
1122
|
+
`ref count update must be non-negative. ${hash}:${now}`
|
|
1123
|
+
);
|
|
1124
|
+
}
|
|
1125
|
+
updates.set(hash, now);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
return updates;
|
|
1129
|
+
}
|
|
980
1130
|
async #changeRefCount(hash, delta) {
|
|
981
1131
|
await this.#ensureRefCountLoaded(hash);
|
|
982
1132
|
if (this.#updateRefCount(hash, delta)) {
|
|
@@ -2903,24 +3053,36 @@ var liveTransactions = /* @__PURE__ */ new Set();
|
|
|
2903
3053
|
function txFailure(tx) {
|
|
2904
3054
|
return tx.error ?? new DOMException("IndexedDB transaction aborted", "AbortError");
|
|
2905
3055
|
}
|
|
2906
|
-
var
|
|
2907
|
-
function
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
3056
|
+
var frozen;
|
|
3057
|
+
function whenPageResumed() {
|
|
3058
|
+
return frozen ? frozen.promise : promiseVoid;
|
|
3059
|
+
}
|
|
3060
|
+
function installFreezeListeners() {
|
|
3061
|
+
globalThis.document?.addEventListener(
|
|
3062
|
+
"freeze",
|
|
3063
|
+
() => {
|
|
3064
|
+
frozen ??= resolver4();
|
|
3065
|
+
for (const open of liveTransactions) {
|
|
3066
|
+
try {
|
|
3067
|
+
open.abort();
|
|
3068
|
+
} catch {
|
|
2918
3069
|
}
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
3070
|
+
}
|
|
3071
|
+
liveTransactions.clear();
|
|
3072
|
+
},
|
|
3073
|
+
{ capture: true }
|
|
3074
|
+
);
|
|
3075
|
+
globalThis.document?.addEventListener(
|
|
3076
|
+
"resume",
|
|
3077
|
+
() => {
|
|
3078
|
+
frozen?.resolve();
|
|
3079
|
+
frozen = void 0;
|
|
3080
|
+
},
|
|
3081
|
+
{ capture: true }
|
|
3082
|
+
);
|
|
3083
|
+
}
|
|
3084
|
+
installFreezeListeners();
|
|
3085
|
+
function track(tx) {
|
|
2924
3086
|
liveTransactions.add(tx);
|
|
2925
3087
|
const done = () => liveTransactions.delete(tx);
|
|
2926
3088
|
tx.addEventListener("complete", done);
|
|
@@ -3020,6 +3182,9 @@ function openDatabaseOnce(name) {
|
|
|
3020
3182
|
var IDBNotFoundError = class extends Error {
|
|
3021
3183
|
name = "IDBNotFoundError";
|
|
3022
3184
|
};
|
|
3185
|
+
function isIDBNotFoundError(e) {
|
|
3186
|
+
return e instanceof IDBNotFoundError;
|
|
3187
|
+
}
|
|
3023
3188
|
|
|
3024
3189
|
// ../replicache/src/kv/mem-store.ts
|
|
3025
3190
|
import { RWLock as RWLock2 } from "@rocicorp/lock";
|
|
@@ -3257,8 +3422,8 @@ async function apply(lc, dbWrite, patch) {
|
|
|
3257
3422
|
for (const p of patch) {
|
|
3258
3423
|
switch (p.op) {
|
|
3259
3424
|
case "put": {
|
|
3260
|
-
const
|
|
3261
|
-
await dbWrite.put(lc, p.key,
|
|
3425
|
+
const frozen2 = deepFreeze(p.value);
|
|
3426
|
+
await dbWrite.put(lc, p.key, frozen2);
|
|
3262
3427
|
break;
|
|
3263
3428
|
}
|
|
3264
3429
|
case "update": {
|
|
@@ -3278,8 +3443,8 @@ async function apply(lc, dbWrite, patch) {
|
|
|
3278
3443
|
if (p.merge) {
|
|
3279
3444
|
addToEntries(p.merge);
|
|
3280
3445
|
}
|
|
3281
|
-
const
|
|
3282
|
-
await dbWrite.put(lc, p.key,
|
|
3446
|
+
const frozen2 = deepFreeze(Object.fromEntries(entries));
|
|
3447
|
+
await dbWrite.put(lc, p.key, frozen2);
|
|
3283
3448
|
break;
|
|
3284
3449
|
}
|
|
3285
3450
|
case "del": {
|
|
@@ -3745,7 +3910,7 @@ function makeChannelNameV1(replicacheName) {
|
|
|
3745
3910
|
function isNewClientChannelMessageV1(message) {
|
|
3746
3911
|
return typeof message === "object" && typeof message.clientGroupID === "string" && typeof message.idbName === "string";
|
|
3747
3912
|
}
|
|
3748
|
-
function initNewClientChannel(replicacheName, idbName, signal, clientGroupID, isNewClientGroup, onUpdateNeeded, perdag) {
|
|
3913
|
+
function initNewClientChannel(replicacheName, idbName, signal, clientGroupID, isNewClientGroup, onUpdateNeeded, perdag, onError) {
|
|
3749
3914
|
if (signal.aborted) {
|
|
3750
3915
|
return;
|
|
3751
3916
|
}
|
|
@@ -3756,7 +3921,7 @@ function initNewClientChannel(replicacheName, idbName, signal, clientGroupID, is
|
|
|
3756
3921
|
channelV0.postMessage([clientGroupID]);
|
|
3757
3922
|
channelV0.close();
|
|
3758
3923
|
}
|
|
3759
|
-
|
|
3924
|
+
const handleMessage = async (e) => {
|
|
3760
3925
|
const { data } = e;
|
|
3761
3926
|
if (isNewClientChannelMessageV1(data)) {
|
|
3762
3927
|
const { clientGroupID: newClientGroupID, idbName: newClientIDBName } = data;
|
|
@@ -3776,6 +3941,16 @@ function initNewClientChannel(replicacheName, idbName, signal, clientGroupID, is
|
|
|
3776
3941
|
}
|
|
3777
3942
|
}
|
|
3778
3943
|
};
|
|
3944
|
+
channelV1.onmessage = async (e) => {
|
|
3945
|
+
try {
|
|
3946
|
+
await handleMessage(e);
|
|
3947
|
+
} catch (err2) {
|
|
3948
|
+
if (!onError) {
|
|
3949
|
+
throw err2;
|
|
3950
|
+
}
|
|
3951
|
+
onError(err2);
|
|
3952
|
+
}
|
|
3953
|
+
};
|
|
3779
3954
|
signal.addEventListener("abort", () => channelV1.close(), { once: true });
|
|
3780
3955
|
}
|
|
3781
3956
|
|
|
@@ -3824,10 +3999,10 @@ async function pendingMutationsForAPI(dagRead) {
|
|
|
3824
3999
|
}
|
|
3825
4000
|
|
|
3826
4001
|
// ../replicache/src/bg-interval.ts
|
|
3827
|
-
function initBgIntervalProcess(processName, process2, delayMs, lc, signal) {
|
|
3828
|
-
void runBgIntervalProcess(processName, process2, delayMs, lc, signal);
|
|
4002
|
+
function initBgIntervalProcess(processName, process2, delayMs, lc, signal, stopOn) {
|
|
4003
|
+
void runBgIntervalProcess(processName, process2, delayMs, lc, signal, stopOn);
|
|
3829
4004
|
}
|
|
3830
|
-
async function runBgIntervalProcess(processName, process2, delayMs, lc, signal) {
|
|
4005
|
+
async function runBgIntervalProcess(processName, process2, delayMs, lc, signal, stopOn) {
|
|
3831
4006
|
if (signal.aborted) {
|
|
3832
4007
|
return;
|
|
3833
4008
|
}
|
|
@@ -3848,6 +4023,9 @@ async function runBgIntervalProcess(processName, process2, delayMs, lc, signal)
|
|
|
3848
4023
|
} catch (e) {
|
|
3849
4024
|
if (signal.aborted) {
|
|
3850
4025
|
lc.debug?.("Error running most likely due to close.", e);
|
|
4026
|
+
} else if (stopOn?.(e)) {
|
|
4027
|
+
lc.debug?.("Stopping: every later run would fail the same way.", e);
|
|
4028
|
+
break;
|
|
3851
4029
|
} else {
|
|
3852
4030
|
lc.error?.("Error running.", e);
|
|
3853
4031
|
}
|
|
@@ -3875,7 +4053,9 @@ function initClientGC(clientID, dagStore, clientMaxInactiveTime, gcInterval, onC
|
|
|
3875
4053
|
},
|
|
3876
4054
|
() => gcInterval,
|
|
3877
4055
|
lc,
|
|
3878
|
-
signal
|
|
4056
|
+
signal,
|
|
4057
|
+
// Works on this instance's own database: once it is gone, stop.
|
|
4058
|
+
isIDBNotFoundError
|
|
3879
4059
|
);
|
|
3880
4060
|
}
|
|
3881
4061
|
function gcClients(clientID, dagStore, clientMaxInactiveTime, onClientsDeleted) {
|
|
@@ -3919,7 +4099,9 @@ function initClientGroupGC(dagStore, enableMutationRecovery, lc, signal) {
|
|
|
3919
4099
|
},
|
|
3920
4100
|
() => GC_INTERVAL_MS,
|
|
3921
4101
|
lc,
|
|
3922
|
-
signal
|
|
4102
|
+
signal,
|
|
4103
|
+
// Works on this instance's own database: once it is gone, stop.
|
|
4104
|
+
isIDBNotFoundError
|
|
3923
4105
|
);
|
|
3924
4106
|
}
|
|
3925
4107
|
function gcClientGroups(dagStore, enableMutationRecovery) {
|
|
@@ -4161,16 +4343,22 @@ async function collectIDBDatabases(idbDatabasesStore, now, maxAge, kvDropStore,
|
|
|
4161
4343
|
if (deletedClientsToRemove.length > 0) {
|
|
4162
4344
|
let allDeletedClients = deletedClientsToRemove;
|
|
4163
4345
|
for (const name of dbNamesToKeep) {
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
allDeletedClients
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4346
|
+
try {
|
|
4347
|
+
await withWrite(newDagStore(name), async (dagWrite) => {
|
|
4348
|
+
const newDeletedClients = await addDeletedClients(
|
|
4349
|
+
dagWrite,
|
|
4350
|
+
deletedClientsToRemove
|
|
4351
|
+
);
|
|
4352
|
+
allDeletedClients = mergeDeletedClients(
|
|
4353
|
+
allDeletedClients,
|
|
4354
|
+
newDeletedClients
|
|
4355
|
+
);
|
|
4356
|
+
});
|
|
4357
|
+
} catch (e) {
|
|
4358
|
+
if (!isIDBNotFoundError(e)) {
|
|
4359
|
+
throw e;
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4174
4362
|
}
|
|
4175
4363
|
const normalizedDeletedClients = normalizeDeletedClients(allDeletedClients);
|
|
4176
4364
|
await onClientsDeleted(normalizedDeletedClients);
|
|
@@ -4216,7 +4404,12 @@ function gatherDatabaseInfoForCollect(db, now, maxAge, enableMutationRecovery, n
|
|
|
4216
4404
|
return canDatabaseBeCollectedAndGetDeletedClientIDs(
|
|
4217
4405
|
enableMutationRecovery,
|
|
4218
4406
|
newDagStore(db.name)
|
|
4219
|
-
)
|
|
4407
|
+
).catch((e) => {
|
|
4408
|
+
if (isIDBNotFoundError(e)) {
|
|
4409
|
+
return [true, []];
|
|
4410
|
+
}
|
|
4411
|
+
throw e;
|
|
4412
|
+
});
|
|
4220
4413
|
}
|
|
4221
4414
|
async function dropDatabase(dbName, opts) {
|
|
4222
4415
|
const logContext = createLogContext(opts?.logLevel, opts?.logSinks, {
|
|
@@ -4267,12 +4460,17 @@ function startHeartbeats(clientID, dagStore, onClientStateNotFound, heartbeatInt
|
|
|
4267
4460
|
onClientStateNotFound();
|
|
4268
4461
|
return;
|
|
4269
4462
|
}
|
|
4463
|
+
if (e instanceof IDBNotFoundError && !signal.aborted) {
|
|
4464
|
+
onClientStateNotFound(e);
|
|
4465
|
+
}
|
|
4270
4466
|
throw e;
|
|
4271
4467
|
}
|
|
4272
4468
|
},
|
|
4273
4469
|
() => heartbeatIntervalMs,
|
|
4274
4470
|
lc,
|
|
4275
|
-
signal
|
|
4471
|
+
signal,
|
|
4472
|
+
// Works on this instance's own database: once it is gone, stop.
|
|
4473
|
+
isIDBNotFoundError
|
|
4276
4474
|
);
|
|
4277
4475
|
}
|
|
4278
4476
|
function writeHeartbeat(clientID, dagStore) {
|
|
@@ -5073,18 +5271,26 @@ var SubscriptionsManagerImpl = class {
|
|
|
5073
5271
|
if (subs.length === 0) {
|
|
5074
5272
|
return;
|
|
5075
5273
|
}
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5274
|
+
let results;
|
|
5275
|
+
try {
|
|
5276
|
+
results = await this.#queryInternal(
|
|
5277
|
+
(tx) => Promise.allSettled(
|
|
5278
|
+
subs.map(async (s) => {
|
|
5279
|
+
const stx = new SubscriptionTransactionWrapper(tx);
|
|
5280
|
+
try {
|
|
5281
|
+
return await s.invoke(stx, kind, diffs);
|
|
5282
|
+
} finally {
|
|
5283
|
+
s.updateDeps(stx.keys, stx.scans);
|
|
5284
|
+
}
|
|
5285
|
+
})
|
|
5286
|
+
)
|
|
5287
|
+
);
|
|
5288
|
+
} catch (e) {
|
|
5289
|
+
if (this.#signal.aborted) {
|
|
5290
|
+
return;
|
|
5291
|
+
}
|
|
5292
|
+
throw e;
|
|
5293
|
+
}
|
|
5088
5294
|
this.callCallbacks(subs, results);
|
|
5089
5295
|
}
|
|
5090
5296
|
// Public method so that ZQL can wrap it in a transaction.
|
|
@@ -5111,11 +5317,15 @@ var SubscriptionsManagerImpl = class {
|
|
|
5111
5317
|
this.hasPendingSubscriptionRuns = false;
|
|
5112
5318
|
const subscriptions = [...this.#pendingSubscriptions];
|
|
5113
5319
|
this.#pendingSubscriptions.clear();
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5320
|
+
try {
|
|
5321
|
+
await this.#fireSubscriptions(
|
|
5322
|
+
subscriptions,
|
|
5323
|
+
InitialRun,
|
|
5324
|
+
void 0
|
|
5325
|
+
);
|
|
5326
|
+
} catch (e) {
|
|
5327
|
+
this.#lc.error?.("Error in initial subscription run:", e);
|
|
5328
|
+
}
|
|
5119
5329
|
}
|
|
5120
5330
|
}
|
|
5121
5331
|
shouldComputeDiffs() {
|
|
@@ -5301,6 +5511,7 @@ var ReplicacheImpl = class {
|
|
|
5301
5511
|
};
|
|
5302
5512
|
}
|
|
5303
5513
|
#closed = false;
|
|
5514
|
+
#idbNotFoundReported = false;
|
|
5304
5515
|
#online = true;
|
|
5305
5516
|
#clientID = makeClientID();
|
|
5306
5517
|
#ready;
|
|
@@ -5392,9 +5603,22 @@ var ReplicacheImpl = class {
|
|
|
5392
5603
|
*
|
|
5393
5604
|
* The default behavior is to reload the page (using `location.reload()`). Set
|
|
5394
5605
|
* this to `null` or provide your own function to prevent the page from
|
|
5395
|
-
* reloading automatically.
|
|
5606
|
+
* reloading automatically. The default reloads at most once per 10 seconds
|
|
5607
|
+
* for a given database (tracked in `sessionStorage`): a reload that lands
|
|
5608
|
+
* straight back here warns once and the page keeps running in memory
|
|
5609
|
+
* instead of looping.
|
|
5610
|
+
*
|
|
5611
|
+
* `reason` is `'idb-deleted'` when this instance's IndexedDB database was
|
|
5612
|
+
* deleted under it (another tab's collector dropped it, or site data was
|
|
5613
|
+
* cleared); it is `undefined` for the other causes.
|
|
5396
5614
|
*/
|
|
5397
|
-
onClientStateNotFound =
|
|
5615
|
+
onClientStateNotFound = () => {
|
|
5616
|
+
if (allowClientStateNotFoundReload(this.idbName)) {
|
|
5617
|
+
reload();
|
|
5618
|
+
} else {
|
|
5619
|
+
this.#warnReloadSuppressed();
|
|
5620
|
+
}
|
|
5621
|
+
};
|
|
5398
5622
|
/**
|
|
5399
5623
|
* `onUpdateNeeded` is called when a code update is needed.
|
|
5400
5624
|
*
|
|
@@ -5561,12 +5785,18 @@ var ReplicacheImpl = class {
|
|
|
5561
5785
|
/**
|
|
5562
5786
|
* Runs one IndexedDB step of open, retrying when IndexedDB aborted its
|
|
5563
5787
|
* transaction. The browser aborts transactions on events this code never
|
|
5564
|
-
* causes
|
|
5788
|
+
* causes: a tab being frozen (this store's own `freeze` release aborts
|
|
5565
5789
|
* every live transaction), storage filling up, a sibling deleting the
|
|
5566
|
-
* database
|
|
5567
|
-
*
|
|
5568
|
-
*
|
|
5569
|
-
*
|
|
5790
|
+
* database. Every step retried here is atomic (a registry read or put,
|
|
5791
|
+
* `initClientV6`'s single perdag write, Zero's `init` read — see
|
|
5792
|
+
* {@link ZeroOption.init}), so a retry starts from a clean transaction.
|
|
5793
|
+
*
|
|
5794
|
+
* Each retry consumes one of the {@link OPEN_IDB_RETRY_DELAYS_MS} attempts
|
|
5795
|
+
* of its step (attempts are per step, not per open). Before retrying, the
|
|
5796
|
+
* step waits for the page to resume — at most
|
|
5797
|
+
* {@link FREEZE_RESUME_WAIT_CAP_MS}, so a `resume` that is never delivered
|
|
5798
|
+
* cannot hang open — then backs off 0 / 100 / 500 / 2000 ms. Bounded, and
|
|
5799
|
+
* never after close.
|
|
5570
5800
|
*/
|
|
5571
5801
|
async #retryTransientIdbAbort(step, fn) {
|
|
5572
5802
|
for (let attempt = 0; ; attempt++) {
|
|
@@ -5580,6 +5810,20 @@ var ReplicacheImpl = class {
|
|
|
5580
5810
|
`IndexedDB aborted the ${step} transaction; retry ${attempt + 1}`,
|
|
5581
5811
|
e
|
|
5582
5812
|
);
|
|
5813
|
+
const { signal } = this.#closeAbortController;
|
|
5814
|
+
await new Promise((resolve) => {
|
|
5815
|
+
const capTimer = setTimeout(resolve, FREEZE_RESUME_WAIT_CAP_MS);
|
|
5816
|
+
const done = () => {
|
|
5817
|
+
clearTimeout(capTimer);
|
|
5818
|
+
signal.removeEventListener("abort", done);
|
|
5819
|
+
resolve();
|
|
5820
|
+
};
|
|
5821
|
+
void whenPageResumed().then(done);
|
|
5822
|
+
signal.addEventListener("abort", done, { once: true });
|
|
5823
|
+
});
|
|
5824
|
+
if (this.#closed) {
|
|
5825
|
+
throw e;
|
|
5826
|
+
}
|
|
5583
5827
|
const delay = OPEN_IDB_RETRY_DELAYS_MS[attempt];
|
|
5584
5828
|
if (delay > 0) {
|
|
5585
5829
|
await sleep(delay, this.#closeAbortController.signal);
|
|
@@ -5617,7 +5861,13 @@ var ReplicacheImpl = class {
|
|
|
5617
5861
|
this.memdag,
|
|
5618
5862
|
(write) => write.setHead(DEFAULT_HEAD_NAME, headHash)
|
|
5619
5863
|
);
|
|
5620
|
-
|
|
5864
|
+
const zero2 = this.#zero;
|
|
5865
|
+
if (zero2) {
|
|
5866
|
+
await this.#retryTransientIdbAbort(
|
|
5867
|
+
"Zero init",
|
|
5868
|
+
() => zero2.init(headHash, this.memdag)
|
|
5869
|
+
);
|
|
5870
|
+
}
|
|
5621
5871
|
resolveReady();
|
|
5622
5872
|
if (this.#enablePullAndPushInOpen) {
|
|
5623
5873
|
this.pull().catch(noop2);
|
|
@@ -5627,8 +5877,12 @@ var ReplicacheImpl = class {
|
|
|
5627
5877
|
startHeartbeats(
|
|
5628
5878
|
clientID,
|
|
5629
5879
|
this.perdag,
|
|
5630
|
-
() => {
|
|
5631
|
-
|
|
5880
|
+
(cause) => {
|
|
5881
|
+
if (cause) {
|
|
5882
|
+
this.#idbNotFound(cause);
|
|
5883
|
+
} else {
|
|
5884
|
+
this.#clientStateNotFoundOnClient(clientID);
|
|
5885
|
+
}
|
|
5632
5886
|
},
|
|
5633
5887
|
HEARTBEAT_INTERVAL,
|
|
5634
5888
|
this.#lc,
|
|
@@ -5664,7 +5918,14 @@ var ReplicacheImpl = class {
|
|
|
5664
5918
|
() => {
|
|
5665
5919
|
this.#fireOnUpdateNeeded(updateNeededReasonNewClientGroup);
|
|
5666
5920
|
},
|
|
5667
|
-
this.perdag
|
|
5921
|
+
this.perdag,
|
|
5922
|
+
(e) => {
|
|
5923
|
+
if (isIDBNotFoundError(e)) {
|
|
5924
|
+
this.#idbNotFound(e);
|
|
5925
|
+
} else {
|
|
5926
|
+
this.#lc.error?.("Error handling a new-client message", e);
|
|
5927
|
+
}
|
|
5928
|
+
}
|
|
5668
5929
|
);
|
|
5669
5930
|
setIntervalWithSignal(
|
|
5670
5931
|
() => this.recoverMutations(),
|
|
@@ -5684,7 +5945,15 @@ var ReplicacheImpl = class {
|
|
|
5684
5945
|
if (getBrowserGlobal("document")?.visibilityState !== "visible") {
|
|
5685
5946
|
return;
|
|
5686
5947
|
}
|
|
5687
|
-
|
|
5948
|
+
try {
|
|
5949
|
+
await this.#checkForClientStateNotFoundAndCallHandler();
|
|
5950
|
+
} catch (e) {
|
|
5951
|
+
if (e instanceof IDBNotFoundError) {
|
|
5952
|
+
this.#idbNotFound(e);
|
|
5953
|
+
} else {
|
|
5954
|
+
this.#lc.error?.("Error checking client state on visibility change", e);
|
|
5955
|
+
}
|
|
5956
|
+
}
|
|
5688
5957
|
};
|
|
5689
5958
|
async #checkForClientStateNotFoundAndCallHandler() {
|
|
5690
5959
|
const { clientID } = this;
|
|
@@ -5697,6 +5966,14 @@ var ReplicacheImpl = class {
|
|
|
5697
5966
|
}
|
|
5698
5967
|
return !hasClientState2;
|
|
5699
5968
|
}
|
|
5969
|
+
/**
|
|
5970
|
+
* `#ready` itself: resolves when open has completed (after Zero's `init`,
|
|
5971
|
+
* when there is one); never, if open failed. For tests that measure boot,
|
|
5972
|
+
* which must not read anything themselves to find out.
|
|
5973
|
+
*/
|
|
5974
|
+
get readyForTesting() {
|
|
5975
|
+
return this.#ready;
|
|
5976
|
+
}
|
|
5700
5977
|
/**
|
|
5701
5978
|
* The browser profile ID for this browser profile. Every instance of Replicache
|
|
5702
5979
|
* browser-profile-wide shares the same profile ID.
|
|
@@ -6106,6 +6383,16 @@ var ReplicacheImpl = class {
|
|
|
6106
6383
|
const { syncHead, httpRequestInfo } = beginPullResponse;
|
|
6107
6384
|
return { requestID, syncHead, ok: httpRequestInfo.httpStatusCode === 200 };
|
|
6108
6385
|
}
|
|
6386
|
+
/**
|
|
6387
|
+
* Writes the in-memory state to IndexedDB.
|
|
6388
|
+
*
|
|
6389
|
+
* Behaviour change: if this instance's IndexedDB database was deleted under
|
|
6390
|
+
* it (another tab's collector, or cleared site data), this no longer rejects
|
|
6391
|
+
* with `IDBNotFoundError`. It reports the loss once through
|
|
6392
|
+
* `onClientStateNotFound('idb-deleted')` and resolves; nothing was persisted.
|
|
6393
|
+
* `refresh()` behaves the same way. Callers that need to know the write did
|
|
6394
|
+
* not land must use `onClientStateNotFound`.
|
|
6395
|
+
*/
|
|
6109
6396
|
persist() {
|
|
6110
6397
|
return this.#persistLock.withLock(async () => {
|
|
6111
6398
|
const { clientID } = this;
|
|
@@ -6127,6 +6414,9 @@ var ReplicacheImpl = class {
|
|
|
6127
6414
|
} catch (e) {
|
|
6128
6415
|
if (e instanceof ClientStateNotFoundError) {
|
|
6129
6416
|
this.#clientStateNotFoundOnClient(clientID);
|
|
6417
|
+
} else if (e instanceof IDBNotFoundError) {
|
|
6418
|
+
this.#idbNotFound(e);
|
|
6419
|
+
return;
|
|
6130
6420
|
} else if (e instanceof PersistBaseMovedError) {
|
|
6131
6421
|
this.#lc.debug?.("Persist base moved; rescheduling", e.message);
|
|
6132
6422
|
void this.#schedulePersist();
|
|
@@ -6141,6 +6431,11 @@ var ReplicacheImpl = class {
|
|
|
6141
6431
|
this.#onPersist({ clientID, clientGroupID });
|
|
6142
6432
|
});
|
|
6143
6433
|
}
|
|
6434
|
+
/**
|
|
6435
|
+
* Pulls the latest persisted state from IndexedDB. Like `persist()`, a
|
|
6436
|
+
* deleted database reports `onClientStateNotFound('idb-deleted')` and
|
|
6437
|
+
* resolves instead of rejecting.
|
|
6438
|
+
*/
|
|
6144
6439
|
async refresh() {
|
|
6145
6440
|
await this.#ready;
|
|
6146
6441
|
const { clientID } = this;
|
|
@@ -6163,6 +6458,8 @@ var ReplicacheImpl = class {
|
|
|
6163
6458
|
} catch (e) {
|
|
6164
6459
|
if (e instanceof ClientStateNotFoundError) {
|
|
6165
6460
|
this.#clientStateNotFoundOnClient(clientID);
|
|
6461
|
+
} else if (e instanceof IDBNotFoundError) {
|
|
6462
|
+
this.#idbNotFound(e);
|
|
6166
6463
|
} else if (this.#closed) {
|
|
6167
6464
|
this.#lc.debug?.("Exception refreshing during close", e);
|
|
6168
6465
|
} else {
|
|
@@ -6173,8 +6470,48 @@ var ReplicacheImpl = class {
|
|
|
6173
6470
|
await this.#subscriptions.fire(refreshResult.diffs);
|
|
6174
6471
|
}
|
|
6175
6472
|
}
|
|
6176
|
-
#
|
|
6177
|
-
|
|
6473
|
+
#reloadSuppressedWarned = false;
|
|
6474
|
+
#warnReloadSuppressed() {
|
|
6475
|
+
if (this.#reloadSuppressedWarned) {
|
|
6476
|
+
return;
|
|
6477
|
+
}
|
|
6478
|
+
this.#reloadSuppressedWarned = true;
|
|
6479
|
+
this.#lc.warn?.(
|
|
6480
|
+
`Client state not found again within ${RELOAD_LOOP_WINDOW_MS / 1e3}s of the last reload; not reloading again. This page keeps running in memory until it is reloaded.`
|
|
6481
|
+
);
|
|
6482
|
+
}
|
|
6483
|
+
#fireOnClientStateNotFound(reason) {
|
|
6484
|
+
try {
|
|
6485
|
+
if (reason === void 0) {
|
|
6486
|
+
this.onClientStateNotFound?.();
|
|
6487
|
+
} else {
|
|
6488
|
+
this.onClientStateNotFound?.(reason);
|
|
6489
|
+
}
|
|
6490
|
+
} catch (e) {
|
|
6491
|
+
this.#lc.error?.("onClientStateNotFound threw", e);
|
|
6492
|
+
}
|
|
6493
|
+
}
|
|
6494
|
+
/**
|
|
6495
|
+
* This instance's IndexedDB database is gone under it: another tab's
|
|
6496
|
+
* collector deleted it (it looked abandoned), or site data was cleared.
|
|
6497
|
+
* The client's state went with it, so this is the client-state-not-found
|
|
6498
|
+
* path, taken once: one warning, one `onClientStateNotFound`. The
|
|
6499
|
+
* background processes stop on their own (see `initBgIntervalProcess`).
|
|
6500
|
+
*/
|
|
6501
|
+
#idbNotFound(e) {
|
|
6502
|
+
if (this.#closed) {
|
|
6503
|
+
this.#lc.debug?.("IndexedDB gone after close; ignoring.", e.message);
|
|
6504
|
+
return;
|
|
6505
|
+
}
|
|
6506
|
+
if (this.#idbNotFoundReported) {
|
|
6507
|
+
return;
|
|
6508
|
+
}
|
|
6509
|
+
this.#idbNotFoundReported = true;
|
|
6510
|
+
this.#lc.warn?.(
|
|
6511
|
+
`IndexedDB database ${this.idbName} was deleted while this client was running (another tab collected it, or site data was cleared). Its state is gone: calling onClientStateNotFound('${CLIENT_STATE_NOT_FOUND_REASON_IDB_DELETED}'), which reloads the page by default.`
|
|
6512
|
+
);
|
|
6513
|
+
this.#lc.debug?.(e);
|
|
6514
|
+
this.#fireOnClientStateNotFound(CLIENT_STATE_NOT_FOUND_REASON_IDB_DELETED);
|
|
6178
6515
|
}
|
|
6179
6516
|
#clientStateNotFoundOnClient(clientID) {
|
|
6180
6517
|
this.#lc.error?.(`Client state not found on client, clientID: ${clientID}`);
|
|
@@ -6533,7 +6870,9 @@ var ReplicacheImpl = class {
|
|
|
6533
6870
|
return withRead(this.memdag, pendingMutationsForAPI);
|
|
6534
6871
|
}
|
|
6535
6872
|
};
|
|
6873
|
+
var CLIENT_STATE_NOT_FOUND_REASON_IDB_DELETED = "idb-deleted";
|
|
6536
6874
|
var OPEN_IDB_RETRY_DELAYS_MS = [0, 100, 500, 2e3];
|
|
6875
|
+
var FREEZE_RESUME_WAIT_CAP_MS = 1e4;
|
|
6537
6876
|
function isTransientIdbAbort(e) {
|
|
6538
6877
|
return typeof DOMException !== "undefined" && e instanceof DOMException && (e.name === "AbortError" || e.name === "InvalidStateError" || e.name === "TransactionInactiveError");
|
|
6539
6878
|
}
|
|
@@ -6544,6 +6883,19 @@ async function throwIfError(p) {
|
|
|
6544
6883
|
throw res.error;
|
|
6545
6884
|
}
|
|
6546
6885
|
}
|
|
6886
|
+
var RELOAD_LOOP_WINDOW_MS = 1e4;
|
|
6887
|
+
function allowClientStateNotFoundReload(idbName, now = Date.now()) {
|
|
6888
|
+
try {
|
|
6889
|
+
const key = `replicache-client-state-not-found-reload:${idbName}`;
|
|
6890
|
+
const last = Number(sessionStorage.getItem(key));
|
|
6891
|
+
if (last > 0 && now - last >= 0 && now - last < RELOAD_LOOP_WINDOW_MS) {
|
|
6892
|
+
return false;
|
|
6893
|
+
}
|
|
6894
|
+
sessionStorage.setItem(key, String(now));
|
|
6895
|
+
} catch {
|
|
6896
|
+
}
|
|
6897
|
+
return true;
|
|
6898
|
+
}
|
|
6547
6899
|
function reload() {
|
|
6548
6900
|
if (typeof location !== "undefined") {
|
|
6549
6901
|
location.reload();
|
|
@@ -15243,7 +15595,7 @@ function makeMessage(message, context, logLevel) {
|
|
|
15243
15595
|
}
|
|
15244
15596
|
|
|
15245
15597
|
// ../zero-client/src/client/version.ts
|
|
15246
|
-
var version2 = "2.2.
|
|
15598
|
+
var version2 = "2.2.7";
|
|
15247
15599
|
|
|
15248
15600
|
// ../zero-client/src/client/log-options.ts
|
|
15249
15601
|
var LevelFilterLogSink = class {
|
|
@@ -16621,6 +16973,7 @@ var ZeroRep = class {
|
|
|
16621
16973
|
#onLocalHydrationComplete;
|
|
16622
16974
|
#store;
|
|
16623
16975
|
#auth;
|
|
16976
|
+
#initialized = false;
|
|
16624
16977
|
constructor(context, ivmMain, customMutatorsEnabled, mutationTracker, onLocalHydrationComplete) {
|
|
16625
16978
|
this.#context = context;
|
|
16626
16979
|
this.#ivmMain = ivmMain;
|
|
@@ -16635,7 +16988,16 @@ var ZeroRep = class {
|
|
|
16635
16988
|
this.#auth = auth;
|
|
16636
16989
|
}
|
|
16637
16990
|
}
|
|
16991
|
+
/**
|
|
16992
|
+
* Safe to call again: Replicache retries it when IndexedDB aborts its read
|
|
16993
|
+
* (a tab frozen while it boots). A call that fails applies nothing (the
|
|
16994
|
+
* rows are applied only after the whole read); once one has applied its
|
|
16995
|
+
* result, later calls do nothing.
|
|
16996
|
+
*/
|
|
16638
16997
|
async init(hash, store) {
|
|
16998
|
+
if (this.#initialized) {
|
|
16999
|
+
return;
|
|
17000
|
+
}
|
|
16639
17001
|
const t0 = nowMs();
|
|
16640
17002
|
const ts = () => Math.round(nowMs() - t0);
|
|
16641
17003
|
const diffs = [];
|
|
@@ -16692,21 +17054,34 @@ var ZeroRep = class {
|
|
|
16692
17054
|
console.log(`[ZERO-INIT] scan: ${diffs.length} entities at +${ts()}ms`);
|
|
16693
17055
|
}
|
|
16694
17056
|
});
|
|
16695
|
-
this.#
|
|
16696
|
-
|
|
16697
|
-
this.#context.processChanges(void 0, hash, diffs);
|
|
16698
|
-
if (shouldLogColdIdb()) {
|
|
16699
|
-
logColdIdbStage("init-processChanges", {
|
|
16700
|
-
entities: diffs.length,
|
|
16701
|
-
ms: Math.round(nowMs() - ivmT0),
|
|
16702
|
-
atMs: ts()
|
|
16703
|
-
});
|
|
16704
|
-
logColdIdbStage("init-done", { ms: ts(), entities: diffs.length });
|
|
17057
|
+
if (this.#initialized) {
|
|
17058
|
+
return;
|
|
16705
17059
|
}
|
|
16706
|
-
|
|
16707
|
-
|
|
17060
|
+
this.#store = store;
|
|
17061
|
+
try {
|
|
17062
|
+
const ivmT0 = nowMs();
|
|
17063
|
+
this.#context.processChanges(void 0, hash, diffs);
|
|
17064
|
+
if (shouldLogColdIdb()) {
|
|
17065
|
+
logColdIdbStage("init-processChanges", {
|
|
17066
|
+
entities: diffs.length,
|
|
17067
|
+
ms: Math.round(nowMs() - ivmT0),
|
|
17068
|
+
atMs: ts()
|
|
17069
|
+
});
|
|
17070
|
+
logColdIdbStage("init-done", { ms: ts(), entities: diffs.length });
|
|
17071
|
+
}
|
|
17072
|
+
if (shouldLogColdIdb()) {
|
|
17073
|
+
console.log(`[ZERO-INIT] done at +${ts()}ms`);
|
|
17074
|
+
}
|
|
17075
|
+
this.#onLocalHydrationComplete();
|
|
17076
|
+
this.#initialized = true;
|
|
17077
|
+
} catch (e) {
|
|
17078
|
+
if (typeof DOMException !== "undefined" && e instanceof DOMException) {
|
|
17079
|
+
throw new Error(`Zero init failed applying persisted rows: ${e.name}`, {
|
|
17080
|
+
cause: e
|
|
17081
|
+
});
|
|
17082
|
+
}
|
|
17083
|
+
throw e;
|
|
16708
17084
|
}
|
|
16709
|
-
this.#onLocalHydrationComplete();
|
|
16710
17085
|
}
|
|
16711
17086
|
getTxData = (desiredHead, readOptions) => {
|
|
16712
17087
|
if (!this.#customMutatorsEnabled) {
|
package/dist/react.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { LogContext } from '@rocicorp/logger';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Runs `process` every `delayMs()` until `signal` aborts. A failed run is
|
|
4
|
+
* logged as an error and the next one runs as usual — unless `stopOn(e)`
|
|
5
|
+
* says the failure is permanent for this process (e.g. its database is
|
|
6
|
+
* gone), in which case the process stops quietly (debug log).
|
|
7
|
+
*/
|
|
8
|
+
export declare function initBgIntervalProcess(processName: string, process: () => Promise<unknown>, delayMs: () => number, lc: LogContext, signal: AbortSignal, stopOn?: (e: unknown) => boolean): void;
|
|
3
9
|
//# sourceMappingURL=bg-interval.d.ts.map
|
|
@@ -7,6 +7,13 @@ export declare class IDBStore implements Store {
|
|
|
7
7
|
close(): Promise<void>;
|
|
8
8
|
get closed(): boolean;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolves at once unless the page is frozen (a `freeze` event this store
|
|
12
|
+
* saw, with no `resume` since); then when it resumes. Work IndexedDB
|
|
13
|
+
* aborted because of a freeze waits on this before trying again, so it
|
|
14
|
+
* does not run inside the frozen window.
|
|
15
|
+
*/
|
|
16
|
+
export declare function whenPageResumed(): Promise<void>;
|
|
10
17
|
/**
|
|
11
18
|
* This error is thrown when we detect that the IndexedDB has been removed. This
|
|
12
19
|
* does not normally happen but can happen during development if the user has
|
|
@@ -15,4 +22,5 @@ export declare class IDBStore implements Store {
|
|
|
15
22
|
export declare class IDBNotFoundError extends Error {
|
|
16
23
|
name: string;
|
|
17
24
|
}
|
|
25
|
+
export declare function isIDBNotFoundError(e: unknown): e is IDBNotFoundError;
|
|
18
26
|
//# sourceMappingURL=idb-store.d.ts.map
|
|
@@ -2,5 +2,13 @@ import type { Store } from './dag/store.ts';
|
|
|
2
2
|
declare function makeChannelNameV0(replicacheName: string): string;
|
|
3
3
|
declare function makeChannelNameV1(replicacheName: string): string;
|
|
4
4
|
export { makeChannelNameV0 as makeChannelNameV0ForTesting, makeChannelNameV1 as makeChannelNameV1ForTesting, };
|
|
5
|
-
export declare function initNewClientChannel(replicacheName: string, idbName: string, signal: AbortSignal, clientGroupID: string, isNewClientGroup: boolean, onUpdateNeeded: () => void, perdag: Store
|
|
5
|
+
export declare function initNewClientChannel(replicacheName: string, idbName: string, signal: AbortSignal, clientGroupID: string, isNewClientGroup: boolean, onUpdateNeeded: () => void, perdag: Store,
|
|
6
|
+
/**
|
|
7
|
+
* Called with anything a message handler throws (reading the perdag can
|
|
8
|
+
* fail, e.g. with IDBNotFoundError once the database is gone). The
|
|
9
|
+
* handler is an event listener: without this, the failure would be an
|
|
10
|
+
* unhandled rejection. Without an `onError` the failure is rethrown, as
|
|
11
|
+
* before.
|
|
12
|
+
*/
|
|
13
|
+
onError?: (e: unknown) => void): void;
|
|
6
14
|
//# sourceMappingURL=new-client-channel.d.ts.map
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { LogContext } from '@rocicorp/logger';
|
|
2
2
|
import type { Store } from '../dag/store.ts';
|
|
3
|
+
import { IDBNotFoundError } from '../kv/idb-store.ts';
|
|
3
4
|
import type { ClientID } from '../sync/ids.ts';
|
|
4
5
|
import { type ClientMap } from './clients.ts';
|
|
5
6
|
export declare const HEARTBEAT_INTERVAL: number;
|
|
6
7
|
export declare let latestHeartbeatUpdate: Promise<ClientMap> | undefined;
|
|
7
|
-
export declare function startHeartbeats(clientID: ClientID, dagStore: Store,
|
|
8
|
+
export declare function startHeartbeats(clientID: ClientID, dagStore: Store,
|
|
9
|
+
/**
|
|
10
|
+
* Called with no argument when this client's entry is gone, and with the
|
|
11
|
+
* error when the whole database is gone (this client's state with it).
|
|
12
|
+
*/
|
|
13
|
+
onClientStateNotFound: (cause?: IDBNotFoundError) => void, heartbeatIntervalMs: number, lc: LogContext, signal: AbortSignal): void;
|
|
8
14
|
export declare function writeHeartbeat(clientID: ClientID, dagStore: Store): Promise<ClientMap>;
|
|
9
15
|
//# sourceMappingURL=heartbeat.d.ts.map
|
|
@@ -132,9 +132,16 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
132
132
|
*
|
|
133
133
|
* The default behavior is to reload the page (using `location.reload()`). Set
|
|
134
134
|
* this to `null` or provide your own function to prevent the page from
|
|
135
|
-
* reloading automatically.
|
|
135
|
+
* reloading automatically. The default reloads at most once per 10 seconds
|
|
136
|
+
* for a given database (tracked in `sessionStorage`): a reload that lands
|
|
137
|
+
* straight back here warns once and the page keeps running in memory
|
|
138
|
+
* instead of looping.
|
|
139
|
+
*
|
|
140
|
+
* `reason` is `'idb-deleted'` when this instance's IndexedDB database was
|
|
141
|
+
* deleted under it (another tab's collector dropped it, or site data was
|
|
142
|
+
* cleared); it is `undefined` for the other causes.
|
|
136
143
|
*/
|
|
137
|
-
onClientStateNotFound: (() => void) | null;
|
|
144
|
+
onClientStateNotFound: ((reason?: string) => void) | null;
|
|
138
145
|
/**
|
|
139
146
|
* `onUpdateNeeded` is called when a code update is needed.
|
|
140
147
|
*
|
|
@@ -165,6 +172,12 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
165
172
|
onBeginPull: () => undefined;
|
|
166
173
|
onRecoverMutations: (r: Promise<boolean>) => Promise<boolean>;
|
|
167
174
|
constructor(options: ReplicacheOptions<MD>, implOptions?: ReplicacheImplOptions);
|
|
175
|
+
/**
|
|
176
|
+
* `#ready` itself: resolves when open has completed (after Zero's `init`,
|
|
177
|
+
* when there is one); never, if open failed. For tests that measure boot,
|
|
178
|
+
* which must not read anything themselves to find out.
|
|
179
|
+
*/
|
|
180
|
+
get readyForTesting(): Promise<void>;
|
|
168
181
|
/**
|
|
169
182
|
* The browser profile ID for this browser profile. Every instance of Replicache
|
|
170
183
|
* browser-profile-wide shares the same profile ID.
|
|
@@ -256,7 +269,22 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
256
269
|
*/
|
|
257
270
|
poke(poke: PokeInternal): Promise<void>;
|
|
258
271
|
beginPull(): Promise<BeginPullResult>;
|
|
272
|
+
/**
|
|
273
|
+
* Writes the in-memory state to IndexedDB.
|
|
274
|
+
*
|
|
275
|
+
* Behaviour change: if this instance's IndexedDB database was deleted under
|
|
276
|
+
* it (another tab's collector, or cleared site data), this no longer rejects
|
|
277
|
+
* with `IDBNotFoundError`. It reports the loss once through
|
|
278
|
+
* `onClientStateNotFound('idb-deleted')` and resolves; nothing was persisted.
|
|
279
|
+
* `refresh()` behaves the same way. Callers that need to know the write did
|
|
280
|
+
* not land must use `onClientStateNotFound`.
|
|
281
|
+
*/
|
|
259
282
|
persist(): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Pulls the latest persisted state from IndexedDB. Like `persist()`, a
|
|
285
|
+
* deleted database reports `onClientStateNotFound('idb-deleted')` and
|
|
286
|
+
* resolves instead of rejecting.
|
|
287
|
+
*/
|
|
260
288
|
refresh(): Promise<void>;
|
|
261
289
|
disableClientGroup(): Promise<void>;
|
|
262
290
|
/**
|
|
@@ -370,6 +398,18 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
370
398
|
*/
|
|
371
399
|
experimentalPendingMutations(): Promise<readonly PendingMutation[]>;
|
|
372
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* The `reason` `onClientStateNotFound` is called with when this instance's
|
|
403
|
+
* IndexedDB database was deleted under it.
|
|
404
|
+
*/
|
|
405
|
+
export declare const CLIENT_STATE_NOT_FOUND_REASON_IDB_DELETED = "idb-deleted";
|
|
406
|
+
/**
|
|
407
|
+
* The longest a retry waits for a `resume` after a freeze. `frozen` is
|
|
408
|
+
* module-global and set by any `freeze` event, so a `resume` that is missed
|
|
409
|
+
* (or a synthetic `freeze` from another tool) would otherwise park open
|
|
410
|
+
* forever. Past the cap the retry proceeds with its ordinary backoff.
|
|
411
|
+
*/
|
|
412
|
+
export declare const FREEZE_RESUME_WAIT_CAP_MS = 10000;
|
|
373
413
|
/**
|
|
374
414
|
* The DOMExceptions an IndexedDB call raises when the browser ended its
|
|
375
415
|
* transaction underneath it — a request in an aborted transaction
|
|
@@ -378,4 +418,12 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
378
418
|
* a missing store, bad data, quota on a fresh transaction — is not retried.
|
|
379
419
|
*/
|
|
380
420
|
export declare function isTransientIdbAbort(e: unknown): boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Reload loop guard for the default `onClientStateNotFound`. Records the
|
|
423
|
+
* reload's timestamp under a per-database `sessionStorage` key (the value
|
|
424
|
+
* survives the reload, which is the point) and refuses a second reload inside
|
|
425
|
+
* RELOAD_LOOP_WINDOW_MS. `sessionStorage` unavailable or throwing (privacy
|
|
426
|
+
* modes, sandboxed frames) means no guard: allow the reload, as before.
|
|
427
|
+
*/
|
|
428
|
+
export declare function allowClientStateNotFoundReload(idbName: string, now?: number): boolean;
|
|
381
429
|
//# sourceMappingURL=replicache-impl.d.ts.map
|
|
@@ -256,6 +256,9 @@ export interface ZeroOption {
|
|
|
256
256
|
auth: string;
|
|
257
257
|
/**
|
|
258
258
|
* Allow Zero to initialize its IVM state from the given hash and dag.
|
|
259
|
+
*
|
|
260
|
+
* Called again if IndexedDB aborts the read underneath it (a tab frozen
|
|
261
|
+
* while it boots): apply side effects only once the read has succeeded.
|
|
259
262
|
*/
|
|
260
263
|
init(hash: Hash, store: Store): Promise<void>;
|
|
261
264
|
/**
|
|
@@ -143,10 +143,14 @@ export interface ZeroOptions<S extends Schema, MD extends CustomMutatorDefs | un
|
|
|
143
143
|
* - the zero-cache fails to find the server side synchronization state for
|
|
144
144
|
* this client.
|
|
145
145
|
*
|
|
146
|
+
* - the local IndexedDB database was deleted while this client was running
|
|
147
|
+
* (another tab's collector dropped it, or site data was cleared); then
|
|
148
|
+
* `reason` is `'idb-deleted'`.
|
|
149
|
+
*
|
|
146
150
|
* The default behavior is to reload the page (using `location.reload()`).
|
|
147
151
|
* Provide your own function to prevent the page from reloading automatically.
|
|
148
152
|
*/
|
|
149
|
-
onClientStateNotFound?: (() => void) | undefined;
|
|
153
|
+
onClientStateNotFound?: ((reason?: string) => void) | undefined;
|
|
150
154
|
/**
|
|
151
155
|
* The number of milliseconds to wait before disconnecting a Zero
|
|
152
156
|
* instance whose tab has become hidden.
|
|
@@ -13,6 +13,12 @@ export declare class ZeroRep implements ZeroOption {
|
|
|
13
13
|
#private;
|
|
14
14
|
constructor(context: ZeroContext, ivmMain: IVMSourceBranch, customMutatorsEnabled: boolean, mutationTracker: MutationTracker, onLocalHydrationComplete: () => void);
|
|
15
15
|
set auth(auth: string);
|
|
16
|
+
/**
|
|
17
|
+
* Safe to call again: Replicache retries it when IndexedDB aborts its read
|
|
18
|
+
* (a tab frozen while it boots). A call that fails applies nothing (the
|
|
19
|
+
* rows are applied only after the whole read); once one has applied its
|
|
20
|
+
* result, later calls do nothing.
|
|
21
|
+
*/
|
|
16
22
|
init(hash: Hash, store: LazyStore): Promise<void>;
|
|
17
23
|
getTxData: (desiredHead: Hash, readOptions?: ZeroReadOptions | undefined) => Promise<TxData> | undefined;
|
|
18
24
|
advance: (expectedHash: Hash, newHash: Hash, diffs: InternalDiff) => void;
|
package/dist/zero.js
CHANGED
package/package.json
CHANGED