@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.
@@ -1895,6 +1895,46 @@ function createIndexedDbLifecycle(options = {}) {
1895
1895
  function erasePending(o) {
1896
1896
  return exclusive(GATE_LOCK, () => erasePendingLocked(o));
1897
1897
  }
1898
+ async function eraseLocalCopyLocked({ signal }) {
1899
+ const marker = logoutMarkerSet();
1900
+ const tombstone = readTombstone();
1901
+ if (marker && tombstone === null) {
1902
+ return { status: "refused", code: "gate_unavailable" };
1903
+ }
1904
+ if (!marker) {
1905
+ const gate = await readGate();
1906
+ const denied = gate === void 0 || gate.principalHash === null || tombstone !== null && gate.lifecycleEpoch < tombstone.epoch;
1907
+ if (!denied) return { status: "refused", code: "principal_active" };
1908
+ if (gate !== void 0 && gate.principalHash === null) {
1909
+ try {
1910
+ await erasePendingLocked({ signal });
1911
+ } catch {
1912
+ }
1913
+ }
1914
+ }
1915
+ if (signal.aborted) return { status: "failed", code: "ABORTED", marker: logoutMarkerSet() };
1916
+ const deleted = await deleteKvDatabase();
1917
+ if (deleted.status !== "deleted") {
1918
+ return { status: "failed", code: deleted.code, marker: marker || tombstone !== null && setLogoutMarker() };
1919
+ }
1920
+ if (marker) {
1921
+ try {
1922
+ localStorage.removeItem(REPLICA_LOGOUT_MARKER);
1923
+ if (localStorage.getItem(REPLICA_LOGOUT_MARKER) !== null) throw new Error("The logout marker was not cleared.");
1924
+ } catch {
1925
+ return { status: "failed", code: "STORAGE_ERROR", marker: true };
1926
+ }
1927
+ }
1928
+ return { status: "erased" };
1929
+ }
1930
+ async function eraseLocalCopy(o) {
1931
+ try {
1932
+ return await exclusive(GATE_LOCK, () => eraseLocalCopyLocked(o), o.signal);
1933
+ } catch (error) {
1934
+ const code = codeOf(error);
1935
+ return error !== null && typeof error === "object" && "code" in error && error.code === "REPLICA_GATED" ? { status: "refused", code } : { status: "failed", code, marker: logoutMarkerSet() };
1936
+ }
1937
+ }
1898
1938
  async function recover({ signal }) {
1899
1939
  try {
1900
1940
  return await exclusive(GATE_LOCK, async () => {
@@ -1961,6 +2001,7 @@ function createIndexedDbLifecycle(options = {}) {
1961
2001
  deliverable,
1962
2002
  deny,
1963
2003
  erasePending,
2004
+ eraseLocalCopy,
1964
2005
  pendingPurge: readIntents
1965
2006
  };
1966
2007
  }
@@ -2131,7 +2172,7 @@ function spawn(source) {
2131
2172
  if (source instanceof URL || typeof source === "string") return new Worker(source, { type: "module" });
2132
2173
  if (typeof source === "function") return source();
2133
2174
  }
2134
- return new Worker(new URL("./kv-storage.worker.c799a956679091b22f27bac87ad810d6fbd1f21d06fc997ab845eee01b731256.js", import.meta.url), { type: "module" });
2175
+ return new Worker(new URL("./kv-storage.worker.f2ee4476484924b91a94e0f97d77023eca43ed50cb532a0488bafbe68ae591bd.js", import.meta.url), { type: "module" });
2135
2176
  }
2136
2177
  var WorkerConnection = class {
2137
2178
  ready;