@tinycloud/replica 0.3.5-beta.0 → 0.4.0-beta.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/kv-storage-testing.js +41 -0
- package/dist/kv-storage-testing.js.map +1 -1
- package/dist/kv-storage.js +42 -1
- package/dist/kv-storage.js.map +1 -1
- package/dist/{kv-storage.worker.c799a956679091b22f27bac87ad810d6fbd1f21d06fc997ab845eee01b731256.js → kv-storage.worker.f2ee4476484924b91a94e0f97d77023eca43ed50cb532a0488bafbe68ae591bd.js} +1 -1
- package/dist/kv-storage.worker.js +1 -1
- package/dist/kv-storage.worker.js.map +1 -1
- package/dist/replica.worker.js +1 -1
- package/dist/replica.worker.js.map +1 -1
- package/package.json +2 -2
|
@@ -1033,6 +1033,46 @@ function createIndexedDbLifecycle(options = {}) {
|
|
|
1033
1033
|
function erasePending(o) {
|
|
1034
1034
|
return exclusive(GATE_LOCK, () => erasePendingLocked(o));
|
|
1035
1035
|
}
|
|
1036
|
+
async function eraseLocalCopyLocked({ signal }) {
|
|
1037
|
+
const marker = logoutMarkerSet();
|
|
1038
|
+
const tombstone = readTombstone();
|
|
1039
|
+
if (marker && tombstone === null) {
|
|
1040
|
+
return { status: "refused", code: "gate_unavailable" };
|
|
1041
|
+
}
|
|
1042
|
+
if (!marker) {
|
|
1043
|
+
const gate = await readGate();
|
|
1044
|
+
const denied = gate === void 0 || gate.principalHash === null || tombstone !== null && gate.lifecycleEpoch < tombstone.epoch;
|
|
1045
|
+
if (!denied) return { status: "refused", code: "principal_active" };
|
|
1046
|
+
if (gate !== void 0 && gate.principalHash === null) {
|
|
1047
|
+
try {
|
|
1048
|
+
await erasePendingLocked({ signal });
|
|
1049
|
+
} catch {
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
if (signal.aborted) return { status: "failed", code: "ABORTED", marker: logoutMarkerSet() };
|
|
1054
|
+
const deleted = await deleteKvDatabase();
|
|
1055
|
+
if (deleted.status !== "deleted") {
|
|
1056
|
+
return { status: "failed", code: deleted.code, marker: marker || tombstone !== null && setLogoutMarker() };
|
|
1057
|
+
}
|
|
1058
|
+
if (marker) {
|
|
1059
|
+
try {
|
|
1060
|
+
localStorage.removeItem(REPLICA_LOGOUT_MARKER);
|
|
1061
|
+
if (localStorage.getItem(REPLICA_LOGOUT_MARKER) !== null) throw new Error("The logout marker was not cleared.");
|
|
1062
|
+
} catch {
|
|
1063
|
+
return { status: "failed", code: "STORAGE_ERROR", marker: true };
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
return { status: "erased" };
|
|
1067
|
+
}
|
|
1068
|
+
async function eraseLocalCopy(o) {
|
|
1069
|
+
try {
|
|
1070
|
+
return await exclusive(GATE_LOCK, () => eraseLocalCopyLocked(o), o.signal);
|
|
1071
|
+
} catch (error) {
|
|
1072
|
+
const code = codeOf(error);
|
|
1073
|
+
return error !== null && typeof error === "object" && "code" in error && error.code === "REPLICA_GATED" ? { status: "refused", code } : { status: "failed", code, marker: logoutMarkerSet() };
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1036
1076
|
async function recover({ signal }) {
|
|
1037
1077
|
try {
|
|
1038
1078
|
return await exclusive(GATE_LOCK, async () => {
|
|
@@ -1099,6 +1139,7 @@ function createIndexedDbLifecycle(options = {}) {
|
|
|
1099
1139
|
deliverable,
|
|
1100
1140
|
deny,
|
|
1101
1141
|
erasePending,
|
|
1142
|
+
eraseLocalCopy,
|
|
1102
1143
|
pendingPurge: readIntents
|
|
1103
1144
|
};
|
|
1104
1145
|
}
|