loro-repo 0.23.1 → 0.23.3

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 CHANGED
@@ -501,6 +501,12 @@ nothing across restarts can use `persistence: { mode: "ephemeral" }`.
501
501
  | `database` | — | Pass a pre-constructed `better-sqlite3` `Database` to share a connection; the caller owns its lifetime. |
502
502
  | `tablePrefix` | `""` | Optional prefix for all table names, useful when multiple repos share one database. |
503
503
  | `wal` | `true` | Enables `journal_mode=WAL` + `synchronous=NORMAL` for fast, durable writes. |
504
+ | `busyTimeoutMs` | `0` (`5000` for a supplied `database`) | Longest one SQLite call may block the thread for another connection's lock after opening. Opening itself may wait 5000 ms. |
505
+ | `busyRetryMs` | `5000` | How long after its first attempt an operation that hits `SQLITE_BUSY` keeps retrying, with an asynchronous backoff, before it rejects with the driver's error. Operations queued behind it start their own budget when they reach the head. |
506
+
507
+ While another connection or process holds the write lock, storage operations
508
+ wait without blocking the event loop and still reach SQLite in the order they
509
+ were requested. Closing the store rejects operations that are still waiting.
504
510
 
505
511
  The schema (created on first use) is:
506
512
 
package/dist/effect.cjs CHANGED
@@ -1521,24 +1521,29 @@ const make = effect.Effect.fnUntraced(function* (options = {}) {
1521
1521
  const reportFailure = (error) => effect.Effect.sync(() => {
1522
1522
  for (const queue of failures) effect.Queue.offerUnsafe(queue, error);
1523
1523
  });
1524
+ const runCompaction = (entry, compact) => effect.Effect.suspend(() => entry.compaction ? effect.Deferred.await(entry.compaction.done) : start(compactReplica(entry, compact), (job) => {
1525
+ entry.compaction = job;
1526
+ entry.work.add(job);
1527
+ return () => {
1528
+ entry.work.delete(job);
1529
+ if (entry.compaction === job) entry.compaction = void 0;
1530
+ };
1531
+ }).pipe(effect.Effect.flatMap(awaitJob)));
1524
1532
  const armCompaction = (entry) => effect.Effect.suspend(() => {
1525
1533
  const compact = compactor(entry);
1526
1534
  if (!compact || !compactionBytes || entry.compactionArmed || closing || entry.retiring) return effect.Effect.void;
1527
1535
  entry.compactionArmed = true;
1528
- return effect.Effect.forkIn(effect.Effect.sleep(COMPACTION_DELAY_MS).pipe(effect.Effect.andThen(effect.Effect.suspend(() => entry.released || entry.retiring || closing || !entry.updateBytes ? effect.Effect.void : start(compactReplica(entry, compact), (job) => {
1529
- entry.work.add(job);
1530
- return () => {
1531
- entry.work.delete(job);
1532
- };
1533
- }).pipe(effect.Effect.flatMap(awaitJob)))), effect.Effect.catch(reportFailure), effect.Effect.ensuring(effect.Effect.sync(() => {
1536
+ return effect.Effect.forkIn(effect.Effect.sleep(COMPACTION_DELAY_MS).pipe(effect.Effect.andThen(effect.Effect.suspend(() => {
1534
1537
  entry.compactionArmed = false;
1535
- }))), backgroundScope).pipe(effect.Effect.asVoid);
1538
+ return entry.released || entry.retiring || closing || !entry.updateBytes ? effect.Effect.void : runCompaction(entry, compact).pipe(effect.Effect.andThen(effect.Effect.suspend(() => entry.updateBytes && !entry.compactionFailed ? armCompaction(entry) : effect.Effect.void)));
1539
+ })), effect.Effect.catch(reportFailure)), backgroundScope).pipe(effect.Effect.asVoid);
1536
1540
  });
1537
1541
  const maintainJournal = (entry) => effect.Effect.suspend(() => {
1538
1542
  if (entry.kind === "doc" || !entry.updateBytes) return effect.Effect.void;
1539
1543
  const compact = compactor(entry);
1540
- if (compact && compactionBytes && entry.updateBytes >= compactionBytes && !entry.compactionFailed) return compactReplica(entry, compact).pipe(effect.Effect.catch((error) => reportFailure(error).pipe(effect.Effect.andThen(armCompaction(entry)))));
1541
- return armCompaction(entry);
1544
+ if (!compact || !compactionBytes || entry.updateBytes < compactionBytes || entry.compactionFailed) return armCompaction(entry);
1545
+ if (entry.compaction) return effect.Deferred.await(entry.compaction.done).pipe(effect.Effect.andThen(effect.Effect.suspend(() => entry.retiring || entry.released ? effect.Effect.void : maintainJournal(entry))));
1546
+ return runCompaction(entry, compact).pipe(effect.Effect.catch((error) => reportFailure(error).pipe(effect.Effect.andThen(armCompaction(entry)))));
1542
1547
  });
1543
1548
  const markExistence = (entry) => {
1544
1549
  if (!meta.value || entry.kind === "meta") return;