ahmed-rivet-convex 2.2.7 → 2.2.9

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.
@@ -4542,6 +4542,16 @@ var PersistBaseMovedError = class extends Error {
4542
4542
  }
4543
4543
  name = "PersistBaseMovedError";
4544
4544
  };
4545
+ async function zeroDataOrBaseMoved(getZeroData, hash) {
4546
+ try {
4547
+ return await getZeroData(hash);
4548
+ } catch (e) {
4549
+ if (e instanceof ChunkNotFoundError) {
4550
+ throw new PersistBaseMovedError(hash, e.hash);
4551
+ }
4552
+ throw e;
4553
+ }
4554
+ }
4545
4555
  async function persistDD31(lc, clientID, memdag, perdag, mutators, closed, formatVersion, getZeroData, onGatherMemOnlyChunksForTest = () => Promise.resolve()) {
4546
4556
  if (closed()) {
4547
4557
  return;
@@ -4611,8 +4621,8 @@ async function persistDD31(lc, clientID, memdag, perdag, mutators, closed, forma
4611
4621
  return;
4612
4622
  }
4613
4623
  let memdagBaseSnapshotPersisted = false;
4614
- const zeroDataForMemdagBaseSnapshot = getZeroData && await getZeroData(memdagBaseSnapshot.chunk.hash);
4615
- const zeroDataForPerdagHeadAtRead = getZeroData && await getZeroData(perdagHeadHashAtRead);
4624
+ const zeroDataForMemdagBaseSnapshot = getZeroData && await zeroDataOrBaseMoved(getZeroData, memdagBaseSnapshot.chunk.hash);
4625
+ const zeroDataForPerdagHeadAtRead = getZeroData && await zeroDataOrBaseMoved(getZeroData, perdagHeadHashAtRead);
4616
4626
  if (closed()) {
4617
4627
  return;
4618
4628
  }
@@ -4669,6 +4679,32 @@ async function persistDD31(lc, clientID, memdag, perdag, mutators, closed, forma
4669
4679
  );
4670
4680
  }
4671
4681
  }
4682
+ if (!memdagBaseSnapshotPersisted) {
4683
+ const latestBase = await baseSnapshotFromCommit(
4684
+ latestPerdagMainClientGroupHeadCommit,
4685
+ perdagWrite
4686
+ );
4687
+ assertSnapshotCommitDD31(latestBase);
4688
+ if (compareCookiesForSnapshots(memdagBaseSnapshot, latestBase) <= 0 && (memdagBaseSnapshot.meta.lastMutationIDs[clientID] ?? 0) > await latestPerdagMainClientGroupHeadCommit.getMutationID(
4689
+ clientID,
4690
+ perdagWrite
4691
+ )) {
4692
+ lc.debug?.(
4693
+ "persist deferred: perdag head trails this client's confirmed LMID",
4694
+ {
4695
+ clientID,
4696
+ memdagLMID: memdagBaseSnapshot.meta.lastMutationIDs[clientID],
4697
+ perdagHeadLMID: await latestPerdagMainClientGroupHeadCommit.getMutationID(
4698
+ clientID,
4699
+ perdagWrite
4700
+ ),
4701
+ memdagCookie: memdagBaseSnapshot.meta.cookieJSON,
4702
+ perdagCookie: latestBase.meta.cookieJSON
4703
+ }
4704
+ );
4705
+ return;
4706
+ }
4707
+ }
4672
4708
  let zeroDataForPerdagHeadCommit;
4673
4709
  if (!memdagBaseSnapshotPersisted && getZeroData) {
4674
4710
  if (newMainClientGroupHeadHash !== perdagHeadHashAtRead) {
@@ -4813,7 +4849,9 @@ async function refresh(lc, memdag, perdag, clientID, mutators, diffConfig, close
4813
4849
  if (shouldAbortRefresh(
4814
4850
  memdagBaseSnapshot,
4815
4851
  perdagClientGroupBaseSnapshot2,
4816
- perdagClientGroupHeadHash2
4852
+ perdagClientGroupHeadHash2,
4853
+ perdagLmid2,
4854
+ clientID
4817
4855
  )) {
4818
4856
  return void 0;
4819
4857
  }
@@ -4871,7 +4909,9 @@ async function refresh(lc, memdag, perdag, clientID, mutators, diffConfig, close
4871
4909
  if (shouldAbortRefresh(
4872
4910
  memdagBaseSnapshot2,
4873
4911
  perdagClientGroupBaseSnapshot,
4874
- perdagClientGroupHeadHash
4912
+ perdagClientGroupHeadHash,
4913
+ perdagLmid,
4914
+ clientID
4875
4915
  )) {
4876
4916
  return {
4877
4917
  type: "aborted",
@@ -4952,12 +4992,12 @@ async function refresh(lc, memdag, perdag, clientID, mutators, diffConfig, close
4952
4992
  diffs: result.diffs
4953
4993
  };
4954
4994
  }
4955
- function shouldAbortRefresh(memdagBaseSnapshot, perdagClientGroupBaseSnapshot, perdagClientGroupHeadHash) {
4995
+ function shouldAbortRefresh(memdagBaseSnapshot, perdagClientGroupBaseSnapshot, perdagClientGroupHeadHash, perdagLmid, clientID) {
4956
4996
  const baseSnapshotCookieCompareResult = compareCookiesForSnapshots(
4957
4997
  memdagBaseSnapshot,
4958
4998
  perdagClientGroupBaseSnapshot
4959
4999
  );
4960
- return baseSnapshotCookieCompareResult > 0 || baseSnapshotCookieCompareResult === 0 && perdagClientGroupHeadHash === perdagClientGroupBaseSnapshot.chunk.hash;
5000
+ return baseSnapshotCookieCompareResult > 0 || (memdagBaseSnapshot.meta.lastMutationIDs[clientID] ?? 0) > perdagLmid || baseSnapshotCookieCompareResult === 0 && perdagClientGroupHeadHash === perdagClientGroupBaseSnapshot.chunk.hash;
4961
5001
  }
4962
5002
 
4963
5003
  // ../replicache/src/process-scheduler.ts
@@ -6048,6 +6088,7 @@ var ReplicacheImpl = class {
6048
6088
  resolve();
6049
6089
  }
6050
6090
  async maybeEndPull(syncHead, requestID) {
6091
+ let chunkRetries = 0;
6051
6092
  for (; ; ) {
6052
6093
  if (this.#closed) {
6053
6094
  return;
@@ -6069,7 +6110,17 @@ var ReplicacheImpl = class {
6069
6110
  void this.#schedulePersist();
6070
6111
  return;
6071
6112
  }
6072
- const zeroData2 = await this.#zero?.getTxData?.(syncHead);
6113
+ let zeroData2;
6114
+ try {
6115
+ zeroData2 = await this.#zero?.getTxData?.(syncHead);
6116
+ } catch (e) {
6117
+ if (e instanceof ChunkNotFoundError && ++chunkRetries <= 3) {
6118
+ lc.debug?.("IVM base moved during replay; retrying", e.message);
6119
+ await Promise.resolve();
6120
+ continue;
6121
+ }
6122
+ throw e;
6123
+ }
6073
6124
  for (const mutation of replayMutations) {
6074
6125
  if (this.#subscriptions.hasPendingSubscriptionRuns) {
6075
6126
  await Promise.resolve();
@@ -6393,6 +6444,11 @@ var ReplicacheImpl = class {
6393
6444
  * `refresh()` behaves the same way. Callers that need to know the write did
6394
6445
  * not land must use `onClientStateNotFound`.
6395
6446
  */
6447
+ /** Consecutive `PersistBaseMovedError` reschedules. A moved base resolves
6448
+ * on the next attempt; one that keeps "moving" is not a race any more —
6449
+ * past the cap the error is rethrown so the host's persist-failure
6450
+ * recovery sees it instead of a silent reschedule loop. */
6451
+ #persistBaseMovedStreak = 0;
6396
6452
  persist() {
6397
6453
  return this.#persistLock.withLock(async () => {
6398
6454
  const { clientID } = this;
@@ -6411,13 +6467,14 @@ var ReplicacheImpl = class {
6411
6467
  Latest,
6412
6468
  this.#zero?.getTxData
6413
6469
  );
6470
+ this.#persistBaseMovedStreak = 0;
6414
6471
  } catch (e) {
6415
6472
  if (e instanceof ClientStateNotFoundError) {
6416
6473
  this.#clientStateNotFoundOnClient(clientID);
6417
6474
  } else if (e instanceof IDBNotFoundError) {
6418
6475
  this.#idbNotFound(e);
6419
6476
  return;
6420
- } else if (e instanceof PersistBaseMovedError) {
6477
+ } else if (e instanceof PersistBaseMovedError && ++this.#persistBaseMovedStreak <= 5) {
6421
6478
  this.#lc.debug?.("Persist base moved; rescheduling", e.message);
6422
6479
  void this.#schedulePersist();
6423
6480
  } else if (this.#closed) {
@@ -15595,7 +15652,7 @@ function makeMessage(message, context, logLevel) {
15595
15652
  }
15596
15653
 
15597
15654
  // ../zero-client/src/client/version.ts
15598
- var version2 = "2.2.7";
15655
+ var version2 = "2.2.9";
15599
15656
 
15600
15657
  // ../zero-client/src/client/log-options.ts
15601
15658
  var LevelFilterLogSink = class {
package/dist/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Zero
3
- } from "./chunk-5AEROL6U.js";
3
+ } from "./chunk-LTAG2LCD.js";
4
4
  import {
5
5
  DEFAULT_TTL_MS
6
6
  } from "./chunk-FVFX5V7B.js";
@@ -1,7 +1,7 @@
1
1
  import type { LogContext } from '@rocicorp/logger';
2
2
  import type { Enum } from '../../../shared/src/enum.ts';
3
3
  import type { LazyStore } from '../dag/lazy-store.ts';
4
- import type { Store } from '../dag/store.ts';
4
+ import { type Store } from '../dag/store.ts';
5
5
  import * as FormatVersion from '../format-version-enum.ts';
6
6
  import type { Hash } from '../hash.ts';
7
7
  import type { ClientID } from '../sync/ids.ts';
@@ -269,16 +269,6 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
269
269
  */
270
270
  poke(poke: PokeInternal): Promise<void>;
271
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
- */
282
272
  persist(): Promise<void>;
283
273
  /**
284
274
  * Pulls the latest persisted state from IndexedDB. Like `persist()`, a
package/dist/zero.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  number,
7
7
  string,
8
8
  table
9
- } from "./chunk-5AEROL6U.js";
9
+ } from "./chunk-LTAG2LCD.js";
10
10
  import "./chunk-FVFX5V7B.js";
11
11
 
12
12
  // src/adapters/convex.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ahmed-rivet-convex",
3
- "version": "2.2.7",
3
+ "version": "2.2.9",
4
4
  "description": "Client-only local-first data runtime for the browser: reactive queries over IndexedDB with optimistic writes.",
5
5
  "author": "Ahmed Banihani",
6
6
  "license": "Apache-2.0",