@optimystic/db-p2p-storage-ns 1.15.0 → 1.16.0

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.
@@ -1,3 +1,5 @@
1
+ import { StoreFailedError } from '@optimystic/db-p2p';
2
+ import { syncSqliteDb } from './sqlite-sync.js';
1
3
  /**
2
4
  * SQLite-backed `IKVStore` adapter for NativeScript peers.
3
5
  *
@@ -9,11 +11,23 @@
9
11
  *
10
12
  * Only the `s_val` column is read or written here; the `b_val` column is
11
13
  * reserved for binary identity material.
14
+ *
15
+ * Writes are autocommit statements: each is visible, and survives a crash of this process, once it
16
+ * resolves, and the write-ahead log keeps them in order. `flush()` makes them survive a power cut:
17
+ * when anything was written since the last flush it runs `syncSqliteDb`, one synced commit that
18
+ * syncs the shared log and with it every earlier write on the connection; otherwise it resolves at
19
+ * once. A failed sync latches the store, after which every write and flush throws
20
+ * `StoreFailedError` (rule 5 of the flush contract on `RawStoreDriver.flush`); reads keep working.
12
21
  */
13
22
  export class SqliteKVStore {
23
+ db;
14
24
  stmts;
15
25
  prefix;
26
+ /** Set once a write has resolved, cleared by the flush that syncs it. */
27
+ dirty = false;
28
+ fault;
16
29
  constructor(db, prefix = 'optimystic:txn:') {
30
+ this.db = db;
17
31
  this.prefix = prefix;
18
32
  this.stmts = {
19
33
  get: db.prepare('SELECT s_val FROM kv WHERE key = ?'),
@@ -30,10 +44,14 @@ export class SqliteKVStore {
30
44
  return typeof value === 'string' ? value : undefined;
31
45
  }
32
46
  async set(key, value) {
47
+ this.throwIfFailed();
33
48
  await this.stmts.set.run(this.prefix + key, value);
49
+ this.dirty = true;
34
50
  }
35
51
  async delete(key) {
52
+ this.throwIfFailed();
36
53
  await this.stmts.delete.run(this.prefix + key);
54
+ this.dirty = true;
37
55
  }
38
56
  async list(prefix) {
39
57
  const fullPrefix = this.prefix + prefix;
@@ -46,5 +64,25 @@ export class SqliteKVStore {
46
64
  const rows = await this.stmts.list.all(fullPrefix, upper);
47
65
  return rows.map(row => row.key.slice(this.prefix.length));
48
66
  }
67
+ /** `IKVStore.flush`: one synced commit when this store wrote since its last flush, otherwise nothing. */
68
+ async flush() {
69
+ this.throwIfFailed();
70
+ if (!this.dirty)
71
+ return;
72
+ // Cleared before the sync, so a write resolving while the sync runs is covered by the next
73
+ // flush whether or not this sync's commit happened to come after it.
74
+ this.dirty = false;
75
+ try {
76
+ await syncSqliteDb(this.db);
77
+ }
78
+ catch (err) {
79
+ this.fault ??= { cause: err };
80
+ throw new StoreFailedError(this.fault.cause);
81
+ }
82
+ }
83
+ throwIfFailed() {
84
+ if (this.fault)
85
+ throw new StoreFailedError(this.fault.cause);
86
+ }
49
87
  }
50
88
  //# sourceMappingURL=sqlite-kv-store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite-kv-store.js","sourceRoot":"","sources":["../../src/sqlite-kv-store.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAa;IACR,KAAK,CAKpB;IACe,MAAM,CAAS;IAEhC,YAAY,EAAY,EAAE,SAAiB,iBAAiB;QAC3D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG;YACZ,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,oCAAoC,CAAC;YACrD,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,8GAA8G,CAAC;YAC/H,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,8BAA8B,CAAC;YAClD,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,gEAAgE,CAAC;SAClF,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACpB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,GAAG;YAAE,OAAO,SAAS,CAAC;QAC3B,MAAM,KA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KvRawStorage, type RawStoreDriver, type StoreIdentity } from '@optimystic/db-p2p';
2
+ import { KvRawStorage, type BatchBackend, type BatchEntry, type CommittedBatch, type SetTimer, type SinkCommitOptions, type StoreDurability, type StoreIdentity, type StoreKey, type WriteGroupOptions } from '@optimystic/db-p2p';
3
3
  import type { SqliteDb } from './db.js';
4
+ /** What a {@link SqliteBatchBackend} is built with: the test-only `setTimer` that arms its deadline timer. */
5
+ export interface SqliteBatchBackendOptions {
6
+ readonly setTimer?: SetTimer;
7
+ }
4
8
  /**
5
- * SQLite {@link RawStoreDriver}: the six logical block-storage stores mapped to
6
- * the six relational tables (`metadata`, `revisions`, `pending`, `transactions`,
7
- * `proofs`, `materialized`) with their original columns and keys.
9
+ * SQLite {@link BatchBackend}: the six logical block-storage stores mapped to the six relational
10
+ * tables (`metadata`, `revisions`, `pending`, `transactions`, `proofs`, `materialized`) with their
11
+ * original columns and keys, every batch applied as ONE SQLite transaction. The reads are the
12
+ * former per-write driver's statements unchanged, so the on-disk format did not change with the
13
+ * move to batches.
14
+ *
15
+ * `KvRawStorage` owns all JSON serialization, so this backend only ever reads/writes `Uint8Array`
16
+ * values: the value columns are BLOB and SQLite binds a `Uint8Array` as a BLOB and returns it as a
17
+ * `Uint8Array`, so no codec lives here (a TEXT column would risk UTF-8 coercion corrupting non-ASCII
18
+ * JSON bytes).
19
+ *
20
+ * ### Why a committed batch survives a power cut, and in order
21
+ *
22
+ * `applySchema` (`db.ts`) opens every database in write-ahead-log (WAL) mode under
23
+ * `synchronous = NORMAL`. A commit appends the batch's frames to the one WAL file, each frame
24
+ * checksummed over the frames before it, and recovery stops at the first bad frame; before every
25
+ * checkpoint SQLite syncs the WAL, so the database file never holds later content ahead of earlier
26
+ * content. What a power cut leaves is therefore a prefix of the committed transactions, in commit
27
+ * order — rule 3 of the flush contract on `RawStoreDriver.flush` — and a batch is one transaction,
28
+ * so it survives whole or not at all. A commit under `synchronous = FULL`
29
+ * (`SqliteTransactionOptions.synced`) syncs the WAL at that commit, and the WAL being one
30
+ * append-only file, that sync covers every earlier commit on the database, the key-value store's
31
+ * and the identity helper's included, since all three share one connection. So the sync of a batch
32
+ * is one `FULL` commit — this batch's own when it must be synced at once, a later batch's, or the
33
+ * `durability_mark` bump the deadline timer commits — which is what `durability: 'power-loss'`
34
+ * states.
8
35
  *
9
- * `KvRawStorage` now owns all JSON serialization, so this driver only ever
10
- * reads/writes `Uint8Array` values: the value columns are BLOB and SQLite binds
11
- * a `Uint8Array` as a BLOB and returns it as a `Uint8Array`, so no codec lives
12
- * here (a TEXT column would risk UTF-8 coercion corrupting non-ASCII JSON bytes).
13
- * Everything SQLite-specific stays: each CRUD op goes through a prepared
14
- * statement bound once in the constructor; range/list queries drain their rows
15
- * (`.all(...)`) before yielding so no cursor straddles a consumer's `await`; and
16
- * `promote` runs as a single `db.transaction(fn)` — `BEGIN IMMEDIATE; INSERT…;
17
- * DELETE…; COMMIT;` — whose three statements are re-prepared against the OPEN
18
- * transaction so they run on the held mutex slot without re-locking (which would
19
- * deadlock — see `st-nativescript-sqlite-transaction-mutex`).
36
+ * ### How a commit decides
37
+ *
38
+ * The deadlines, the timer and the backpressure test are the rules of `SyncDeadlines` from
39
+ * `@optimystic/db-p2p`, shared with the file backend. `commit` takes the batch's deadline as it is
40
+ * called and decides whether the transaction is synced BEFORE taking the connection mutex, since
41
+ * the pragma is set as the transaction starts; the bookkeeping — `defer` of a deferred batch,
42
+ * `take` of the cover a synced one settles — runs INSIDE the transaction body, under the mutex, so
43
+ * it is ordered against every other commit and sync: a cover taken there is exactly the batches
44
+ * whose transactions committed earlier, every one of which this `FULL` commit syncs. A deadline
45
+ * that passes between the decision and the mutex only delays that commit's backpressure to the
46
+ * timer, which is due anyway.
47
+ *
48
+ * A read sees a batch as soon as its transaction commits, before it is synced, which `BatchBackend`
49
+ * allows; the overlay above serves the batch until it is durable. The handle is shared with
50
+ * `SqliteKVStore` and `loadOrCreateNSPeerKey`, so `close()` never closes it. Every write of a batch
51
+ * goes through `tx.prepare`, never a class-level statement, which would re-take the mutex the
52
+ * transaction holds and deadlock (see `SqliteDb.transaction`).
20
53
  */
21
- export declare class SqliteStoreDriver implements RawStoreDriver {
54
+ export declare class SqliteBatchBackend implements BatchBackend {
22
55
  private readonly db;
23
- private readonly stmts;
56
+ readonly durability: StoreDurability;
24
57
  private readonly identity;
25
- constructor(db: SqliteDb);
58
+ /** One point read per store. Reads run off the mutex, so a class-level statement is right here. */
59
+ private readonly reads;
60
+ private readonly stmts;
61
+ /**
62
+ * Batches committed and not yet synced, in order, each with the `durable` the next sync settles;
63
+ * the earliest deadline among them, with a timer armed for it; and the `window-overrun` episode.
64
+ * A batch's payload is nothing: its transaction has already applied it.
65
+ */
66
+ private readonly deadlines;
67
+ private fault;
68
+ constructor(db: SqliteDb, options?: SqliteBatchBackendOptions);
69
+ /** True once a transaction or a sync failed; every later `commit` and `sync` then throws {@link StoreFailedError}. */
70
+ get failed(): boolean;
26
71
  storeIdentity(): StoreIdentity;
27
- getMetadata(blockId: BlockId): Promise<Uint8Array | undefined>;
28
- putMetadata(blockId: BlockId, value: Uint8Array): Promise<void>;
29
- getRevision(blockId: BlockId, rev: number): Promise<Uint8Array | undefined>;
30
- putRevision(blockId: BlockId, rev: number, value: Uint8Array): Promise<void>;
31
- rangeRevisions(blockId: BlockId, lo: number, hi: number, reverse: boolean): AsyncIterable<[number, Uint8Array]>;
32
- getPending(blockId: BlockId, actionId: ActionId): Promise<Uint8Array | undefined>;
33
- putPending(blockId: BlockId, actionId: ActionId, value: Uint8Array): Promise<void>;
34
- deletePending(blockId: BlockId, actionId: ActionId): Promise<void>;
35
- listPendingActionIds(blockId: BlockId): AsyncIterable<ActionId>;
36
- getTransaction(blockId: BlockId, actionId: ActionId): Promise<Uint8Array | undefined>;
37
- putTransaction(blockId: BlockId, actionId: ActionId, value: Uint8Array): Promise<void>;
38
- getProof(blockId: BlockId, rev: number): Promise<Uint8Array | undefined>;
39
- putProof(blockId: BlockId, rev: number, value: Uint8Array): Promise<void>;
40
- getMaterialized(blockId: BlockId, actionId: ActionId): Promise<Uint8Array | undefined>;
41
- putMaterialized(blockId: BlockId, actionId: ActionId, value: Uint8Array): Promise<void>;
42
- deleteMaterialized(blockId: BlockId, actionId: ActionId): Promise<void>;
43
- promote(blockId: BlockId, actionId: ActionId): Promise<void>;
72
+ get(key: StoreKey): Promise<Uint8Array | undefined>;
73
+ rangeRevisions(blockId: BlockId, lo: number, hi: number): Promise<[number, Uint8Array][]>;
74
+ listPendingActionIds(blockId: BlockId): Promise<ActionId[]>;
44
75
  listBlockIds(): AsyncIterable<BlockId>;
45
76
  approximateBytesUsed(): Promise<number>;
77
+ /**
78
+ * Apply the batch as one transaction and resolve with its `durable`. `WriteGroupSink.commit`'s
79
+ * contract: with `syncWithinMs` 0, or a deadline already passed (`SyncDeadlines.mustSyncNow`),
80
+ * the transaction commits under `synchronous = FULL`, which syncs this batch and every one held,
81
+ * and `durable` is already settled; otherwise it commits under `NORMAL` and `durable` settles at
82
+ * the next sync, which the timer makes by the earliest deadline held. A rejection has latched the
83
+ * backend.
84
+ */
85
+ commit(entries: readonly BatchEntry[], { syncWithinMs }: SinkCommitOptions): Promise<CommittedBatch>;
86
+ /** Hasten: one synced commit covering every batch held when it runs; with nothing held, nothing is synced. `WriteGroupSink.sync`'s contract. */
87
+ sync(): Promise<void>;
88
+ /**
89
+ * The handle is shared, so it is not closed here: only the deadline timer must not outlive the
90
+ * backend. `WriteGroupDriver.close` flushes strictly first, which took and settled everything
91
+ * held and so disarmed the timer; a caller that did not flush gets the same here. After a latch
92
+ * nothing is held, since the latch took and rejected it.
93
+ */
94
+ close(): Promise<void>;
95
+ private commitDeferred;
96
+ private commitSynced;
97
+ /**
98
+ * The sync step: one synced transaction whose body runs `write`, if given, then takes the cover
99
+ * of every batch held — under the mutex, so the cover is exactly the batches whose transactions
100
+ * committed before this one — and, when there is a cover to settle and nothing of its own was
101
+ * written, bumps `durability_mark` so the commit has a frame to sync. The cover settles once the
102
+ * commit has resolved. A failure anywhere latches the backend and rejects every covered
103
+ * `durable`, so no flush waits for a sync the store will not make.
104
+ *
105
+ * `owedSince` is the moment the timer fired, when the timer's task runs this: `SyncDeadlines.take`
106
+ * counts the sync's lateness from it rather than from a deadline the timer's own slop missed.
107
+ */
108
+ private syncHeld;
109
+ /** The timer fired: run the sync step. Its failure has latched the backend, so it is only logged here. */
110
+ private syncInBackground;
111
+ /**
112
+ * Every entry in order — a put as `INSERT OR REPLACE`, a delete as `DELETE` — each statement
113
+ * prepared once per batch against the open transaction. Returns how many were applied.
114
+ */
115
+ private applyEntries;
116
+ private throwIfFailed;
117
+ /**
118
+ * Latch the backend failed on its first fault and reject every batch waiting for a sync that will
119
+ * now never be made, so no caller waits on a `durable` for ever. Returns the error to throw.
120
+ */
121
+ private latch;
46
122
  }
123
+ /** The write group's options (`WriteGroupOptions`); the test-only `setTimer` arms both the group's idle flush and the backend's deadline timer. */
124
+ export type SqliteRawStorageOptions = WriteGroupOptions;
47
125
  /**
48
- * SQLite-backed {@link IRawStorage} for NativeScript peers, now a thin shell over
49
- * the shared {@link KvRawStorage} kernel driven by a {@link SqliteStoreDriver}.
50
- * The public name/constructor (`new SqliteRawStorage(db)`) is unchanged so
51
- * existing imports keep resolving; the kernel supplies the `IRawStorage` surface
52
- * and the driver supplies SQLite behavior.
126
+ * SQLite-backed {@link IRawStorage} for NativeScript peers: the shared {@link KvRawStorage} kernel
127
+ * over a {@link WriteGroupDriver} over a {@link SqliteBatchBackend}. Every write resolves into the
128
+ * driver's in-memory overlay; `flush()` hands the group to the backend as one batch, which applies
129
+ * it as one SQLite transaction, synced before the flush resolves or within the window the flush
130
+ * allows. The public name/constructor (`new SqliteRawStorage(db)`) is unchanged so existing imports
131
+ * keep resolving.
53
132
  *
54
- * `listBlockIds`/`getApproximateBytesUsed` are re-declared here as always-present
55
- * (the SQLite driver always implements them, so the kernel constructor always
56
- * wires them) — the base declares them optional, but every NS consumer relies on
57
- * them.
133
+ * `listBlockIds`/`getApproximateBytesUsed`/`getStoreIdentity`/`close` are re-declared here as
134
+ * always-present (the backend always implements the first three, so the driver and kernel always
135
+ * wire them, and the driver always has a `close`) — the base declares them optional, but every NS
136
+ * consumer relies on them. `close()` flushes what is still held, syncs it, and disarms the timers;
137
+ * it does not close the shared handle, which the host closes afterwards.
58
138
  */
59
139
  export declare class SqliteRawStorage extends KvRawStorage {
60
140
  listBlockIds: () => AsyncIterable<BlockId>;
61
141
  getApproximateBytesUsed: () => Promise<number>;
62
142
  getStoreIdentity: () => StoreIdentity;
63
- constructor(db: SqliteDb);
143
+ close: () => Promise<void>;
144
+ constructor(db: SqliteDb, options?: SqliteRawStorageOptions);
64
145
  }
65
146
  //# sourceMappingURL=sqlite-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite-storage.d.ts","sourceRoot":"","sources":["../../src/sqlite-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAqB,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,SAAS,CAAC;AAKzD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IA8B3C,OAAO,CAAC,QAAQ,CAAC,EAAE;IA7B/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAqBpB;IAMF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;gBAEZ,EAAE,EAAE,QAAQ;IA8BzC,aAAa,IAAI,aAAa;IAMxB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAK9D,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAM/D,WAAW,CAAC,OAAO,EAAE,OAA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