@optimystic/db-p2p-storage-web 1.27.0 → 1.28.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.
- package/README.md +4 -3
- package/dist/src/db.d.ts +9 -3
- package/dist/src/db.d.ts.map +1 -1
- package/dist/src/db.js +9 -5
- package/dist/src/db.js.map +1 -1
- package/dist/src/indexeddb-storage.d.ts +5 -5
- package/dist/src/indexeddb-storage.d.ts.map +1 -1
- package/dist/src/indexeddb-storage.js +15 -13
- package/dist/src/indexeddb-storage.js.map +1 -1
- package/package.json +3 -3
- package/src/db.ts +17 -7
- package/src/indexeddb-storage.ts +17 -14
package/README.md
CHANGED
|
@@ -73,10 +73,10 @@ a closed handle.
|
|
|
73
73
|
## Persistence semantics
|
|
74
74
|
|
|
75
75
|
The package opens a single IndexedDB database (`optimystic` by default) with
|
|
76
|
-
|
|
76
|
+
nine object stores. `IndexedDBRawStorage` is the shared `KvRawStorage` kernel
|
|
77
77
|
over a `WriteGroupDriver` over a `JournalBatchBackend` over an
|
|
78
78
|
`IndexedDBJournalStore`: the kernel owns all JSON/UTF-8 serialization, so the
|
|
79
|
-
|
|
79
|
+
seven block-storage stores hold opaque kernel-encoded `Uint8Array` bytes rather
|
|
80
80
|
than live objects. The keys and the logical types the kernel decodes them back
|
|
81
81
|
into are unchanged from earlier builds, so data written by one reads unchanged:
|
|
82
82
|
|
|
@@ -86,7 +86,8 @@ into are unchanged from earlier builds, so data written by one reads unchanged:
|
|
|
86
86
|
| `revisions` | `[blockId, rev]` | `Uint8Array` | `ActionId` |
|
|
87
87
|
| `pending` | `[blockId, actionId]`| `Uint8Array` | `Transform` |
|
|
88
88
|
| `transactions` | `[blockId, actionId]`| `Uint8Array` | `Transform` |
|
|
89
|
-
| `proofs` | `[blockId, rev]` | `Uint8Array` | `BlockCommitProof`
|
|
89
|
+
| `proofs` | `[blockId, rev]` | `Uint8Array` | `StoredProofEntry`: a reference to a `commitProofs` entry (a whole `BlockCommitProof` when an earlier build wrote it) |
|
|
90
|
+
| `commitProofs` | `messageHash` | `Uint8Array` | `BlockCommitProof` |
|
|
90
91
|
| `materialized` | `[blockId, actionId]`| `Uint8Array` | `IBlock` |
|
|
91
92
|
| `journal` | `seq` (a number), or `'applied-through'` | a `JournalRecord` by structured clone, or the number of the last record applied | — (owned by `IndexedDBJournalStore`) |
|
|
92
93
|
| `kv` | `key` | `string` or `Uint8Array` | — (not kernel-backed) |
|
package/dist/src/db.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare const JOURNAL_MARK_KEY = "applied-through";
|
|
|
10
10
|
/**
|
|
11
11
|
* IndexedDB schema for the Optimystic browser storage backend.
|
|
12
12
|
*
|
|
13
|
-
* The
|
|
13
|
+
* The seven block-storage stores keep their original object stores and compound
|
|
14
14
|
* array keys, but their values are opaque `Uint8Array` blobs: the shared
|
|
15
15
|
* `KvRawStorage` kernel owns JSON (de)serialization, so `IndexedDBJournalStore`
|
|
16
16
|
* only ever hands IndexedDB kernel-encoded bytes. IndexedDB stores a
|
|
@@ -26,9 +26,11 @@ export declare const JOURNAL_MARK_KEY = "applied-through";
|
|
|
26
26
|
* - `proofs`: `BlockCommitProof` bytes keyed by `[blockId, rev]` — the same key shape
|
|
27
27
|
* as `revisions`, deliberately NOT the action keyspace (an action id is caller-chosen,
|
|
28
28
|
* so no reserved id could be relied on).
|
|
29
|
+
* - `commitProofs`: `BlockCommitProof` bytes keyed by the proof's `messageHash` string, one
|
|
30
|
+
* per consensus message however many blocks it covers.
|
|
29
31
|
* - `materialized`: materialized block bytes keyed by `[blockId, actionId]`. Deleting
|
|
30
32
|
* the row is an entry of a write group with no value, not a stored `undefined`.
|
|
31
|
-
* - `journal`: the write groups appended and not yet applied to the
|
|
33
|
+
* - `journal`: the write groups appended and not yet applied to the seven stores above, each a
|
|
32
34
|
* `JournalRecord` stored by structured clone under its `seq` (no codec: the record's keys are
|
|
33
35
|
* plain objects and its values `Uint8Array`s), and under {@link JOURNAL_MARK_KEY} the number of
|
|
34
36
|
* the last record applied. `IndexedDBJournalStore` owns both; nothing else touches the store.
|
|
@@ -58,6 +60,10 @@ export interface OptimysticWebDB extends DBSchema {
|
|
|
58
60
|
key: [BlockId, number];
|
|
59
61
|
value: Uint8Array;
|
|
60
62
|
};
|
|
63
|
+
commitProofs: {
|
|
64
|
+
key: string;
|
|
65
|
+
value: Uint8Array;
|
|
66
|
+
};
|
|
61
67
|
materialized: {
|
|
62
68
|
key: [BlockId, ActionId];
|
|
63
69
|
value: Uint8Array;
|
|
@@ -72,7 +78,7 @@ export interface OptimysticWebDB extends DBSchema {
|
|
|
72
78
|
};
|
|
73
79
|
}
|
|
74
80
|
export declare const DEFAULT_DB_NAME = "optimystic";
|
|
75
|
-
export declare const DEFAULT_DB_VERSION =
|
|
81
|
+
export declare const DEFAULT_DB_VERSION = 4;
|
|
76
82
|
export type OptimysticWebDBHandle = IDBPDatabase<OptimysticWebDB>;
|
|
77
83
|
/**
|
|
78
84
|
* Opens (and creates if necessary) the Optimystic IndexedDB database used by
|
package/dist/src/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,KAAK,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,oBAAoB,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,KAAK,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MA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O,MAAM,kBAAkB,IAAI,CAAC;AAEpC,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACxC,IAAI,GAAE,MAAwB,EAC9B,OAAO,GAAE,MAA2B,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAgChC"}
|
package/dist/src/db.js
CHANGED
|
@@ -6,11 +6,12 @@ import { openDB } from 'idb';
|
|
|
6
6
|
*/
|
|
7
7
|
export const JOURNAL_MARK_KEY = 'applied-through';
|
|
8
8
|
export const DEFAULT_DB_NAME = 'optimystic';
|
|
9
|
-
// Bumped to 2 when the `proofs` object store was added
|
|
10
|
-
// is guarded by `objectStoreNames.contains`, so an existing
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
9
|
+
// Bumped to 2 when the `proofs` object store was added, to 3 for `journal`, and to 4 for
|
|
10
|
+
// `commitProofs`. The `upgrade` hook is guarded by `objectStoreNames.contains`, so an existing
|
|
11
|
+
// database gains only the stores it lacks (backlog
|
|
12
|
+
// `debt-indexeddb-version-upgrade-is-untested-and-unhandled` owns testing that, and the open that
|
|
13
|
+
// another tab's older connection blocks).
|
|
14
|
+
export const DEFAULT_DB_VERSION = 4;
|
|
14
15
|
/**
|
|
15
16
|
* Opens (and creates if necessary) the Optimystic IndexedDB database used by
|
|
16
17
|
* `IndexedDBRawStorage`, `IndexedDBKVStore`, and `loadOrCreateBrowserPeerKey`.
|
|
@@ -36,6 +37,9 @@ export async function openOptimysticWebDb(name = DEFAULT_DB_NAME, version = DEFA
|
|
|
36
37
|
if (!db.objectStoreNames.contains('proofs')) {
|
|
37
38
|
db.createObjectStore('proofs');
|
|
38
39
|
}
|
|
40
|
+
if (!db.objectStoreNames.contains('commitProofs')) {
|
|
41
|
+
db.createObjectStore('commitProofs');
|
|
42
|
+
}
|
|
39
43
|
if (!db.objectStoreNames.contains('materialized')) {
|
|
40
44
|
db.createObjectStore('materialized');
|
|
41
45
|
}
|
package/dist/src/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoC,MAAM,KAAK,CAAC;AAI/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoC,MAAM,KAAK,CAAC;AAI/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAyElD,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAC5C,yFAAyF;AACzF,+FAA+F;AAC/F,mDAAmD;AACnD,kGAAkG;AAClG,0CAA0C;AAC1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAIpC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,OAAe,eAAe,EAC9B,UAAkB,kBAAkB;IAEpC,OAAO,MAAM,CAAkB,IAAI,EAAE,OAAO,EAAE;QAC7C,OAAO,CAAC,EAAE;YACT,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/C,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;YAClC,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gBAChD,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;YACnC,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9C,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YACjC,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;gBACnD,EAAE,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;YACtC,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7C,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YAChC,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;gBACnD,EAAE,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;YACtC,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;gBACnD,EAAE,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;YACtC,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9C,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YACjC,CAAC;YACD,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzC,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,9 +4,9 @@ import { type OptimysticWebDBHandle } from './db.js';
|
|
|
4
4
|
import { type IndexedDBDurabilityOptions } from './durability.js';
|
|
5
5
|
export type IndexedDBJournalStoreOptions = IndexedDBDurabilityOptions;
|
|
6
6
|
/**
|
|
7
|
-
* IndexedDB {@link JournalStore}: the
|
|
8
|
-
* object stores (`metadata`, `revisions`, `pending`, `transactions`, `proofs`,
|
|
9
|
-
* with their
|
|
7
|
+
* IndexedDB {@link JournalStore}: the seven logical block-storage stores mapped to the seven
|
|
8
|
+
* IndexedDB object stores (`metadata`, `revisions`, `pending`, `transactions`, `proofs`,
|
|
9
|
+
* `commitProofs`, `materialized`) with their keys, read exactly as the per-write driver before it read them, so
|
|
10
10
|
* data an earlier build wrote reads unchanged; and the journal in the `journal` object store,
|
|
11
11
|
* which `JournalBatchBackend` drives.
|
|
12
12
|
*
|
|
@@ -22,7 +22,7 @@ export type IndexedDBJournalStoreOptions = IndexedDBDurabilityOptions;
|
|
|
22
22
|
* transaction completes only once the browser has put it on the disk) but promises nothing about
|
|
23
23
|
* the order relaxed transactions reach the disk, which is why the backend journals (see
|
|
24
24
|
* `JournalBatchBackend`). Here an append is one relaxed transaction on `journal` alone, and an
|
|
25
|
-
* apply is one strict transaction over the
|
|
25
|
+
* apply is one strict transaction over the seven stores and `journal`: every record's entries in
|
|
26
26
|
* order, the applied-through mark, and the delete of each record applied or discarded. The apply
|
|
27
27
|
* carries every byte it applies, so its durability depends on no earlier transaction, and the
|
|
28
28
|
* backend syncs each apply before the next starts — so what a power cut leaves is a prefix of the
|
|
@@ -48,7 +48,7 @@ export declare class IndexedDBJournalStore implements JournalStore {
|
|
|
48
48
|
/** One relaxed transaction on `journal`: the record under its `seq`. `JournalStore.appendJournal`'s contract. */
|
|
49
49
|
appendJournal(record: JournalRecord): Promise<void>;
|
|
50
50
|
/**
|
|
51
|
-
* One transaction over the
|
|
51
|
+
* One transaction over the seven stores and `journal`, strict where the browser supports it: each
|
|
52
52
|
* record's entries in order, then the mark, then the delete of every numbered record. A number
|
|
53
53
|
* with no record present (a strict group's, never appended) deletes nothing.
|
|
54
54
|
* `JournalStore.applyJournal`'s contract.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexeddb-storage.d.ts","sourceRoot":"","sources":["../../src/indexeddb-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAEN,YAAY,EAIZ,KAAK,0BAA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,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC;IAiBzF,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAmB1D,YAAY,IAAI,aAAa,CAAC,OAAO,CAAC;IAWvC,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;IAY7C,iHAAiH;IAC3G,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzD;;;;;OAKG;IACG,YAAY,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBtH,2GAA2G;IACrG,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC;CAqB7C;AAED,+KAA+K;AAC/K,MAAM,MAAM,0BAA0B,GAAG,iBAAiB,GAAG,0BAA0B,GAAG,0BAA0B,CAAC;AAErH;;;;;;;;;;;;;;GAcG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IAC5C,YAAY,EAAE,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IAC3C,uBAAuB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,gBAAgB,EAAE,MAAM,aAAa,CAAC;IACtC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;gBAEvB,EAAE,EAAE,qBAAqB,EAAE,OAAO,GAAE,0BAA+B;CAG/E"}
|
|
@@ -3,10 +3,12 @@ import { JOURNAL_MARK_KEY } from './db.js';
|
|
|
3
3
|
import { resolveStrictDurability, transactionDurability } from './durability.js';
|
|
4
4
|
import { createLogger } from './logger.js';
|
|
5
5
|
const log = createLogger('storage:indexeddb');
|
|
6
|
-
/** The object stores an apply writes: the
|
|
7
|
-
const APPLY_STORES = ['metadata', 'revisions', 'pending', 'transactions', 'proofs', 'materialized', 'journal'];
|
|
6
|
+
/** The object stores an apply writes: the seven block-storage stores and the journal itself. */
|
|
7
|
+
const APPLY_STORES = ['metadata', 'revisions', 'pending', 'transactions', 'proofs', 'commitProofs', 'materialized', 'journal'];
|
|
8
8
|
function idbKeyOf(key) {
|
|
9
9
|
switch (key.store) {
|
|
10
|
+
case 'commitProofs':
|
|
11
|
+
return key.messageHash;
|
|
10
12
|
case 'metadata':
|
|
11
13
|
return key.blockId;
|
|
12
14
|
case 'revisions':
|
|
@@ -40,27 +42,27 @@ function isBatchEntry(entry) {
|
|
|
40
42
|
function isStoreKey(key) {
|
|
41
43
|
if (typeof key !== 'object' || key === null)
|
|
42
44
|
return false;
|
|
43
|
-
const { store, blockId, rev, actionId } = key;
|
|
44
|
-
if (typeof blockId !== 'string')
|
|
45
|
-
return false;
|
|
45
|
+
const { store, blockId, rev, actionId, messageHash } = key;
|
|
46
46
|
switch (store) {
|
|
47
|
+
case 'commitProofs':
|
|
48
|
+
return typeof messageHash === 'string';
|
|
47
49
|
case 'metadata':
|
|
48
|
-
return
|
|
50
|
+
return typeof blockId === 'string';
|
|
49
51
|
case 'revisions':
|
|
50
52
|
case 'proofs':
|
|
51
|
-
return Number.isInteger(rev);
|
|
53
|
+
return typeof blockId === 'string' && Number.isInteger(rev);
|
|
52
54
|
case 'pending':
|
|
53
55
|
case 'transactions':
|
|
54
56
|
case 'materialized':
|
|
55
|
-
return typeof actionId === 'string';
|
|
57
|
+
return typeof blockId === 'string' && typeof actionId === 'string';
|
|
56
58
|
default:
|
|
57
59
|
return false;
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
/**
|
|
61
|
-
* IndexedDB {@link JournalStore}: the
|
|
62
|
-
* object stores (`metadata`, `revisions`, `pending`, `transactions`, `proofs`,
|
|
63
|
-
* with their
|
|
63
|
+
* IndexedDB {@link JournalStore}: the seven logical block-storage stores mapped to the seven
|
|
64
|
+
* IndexedDB object stores (`metadata`, `revisions`, `pending`, `transactions`, `proofs`,
|
|
65
|
+
* `commitProofs`, `materialized`) with their keys, read exactly as the per-write driver before it read them, so
|
|
64
66
|
* data an earlier build wrote reads unchanged; and the journal in the `journal` object store,
|
|
65
67
|
* which `JournalBatchBackend` drives.
|
|
66
68
|
*
|
|
@@ -76,7 +78,7 @@ function isStoreKey(key) {
|
|
|
76
78
|
* transaction completes only once the browser has put it on the disk) but promises nothing about
|
|
77
79
|
* the order relaxed transactions reach the disk, which is why the backend journals (see
|
|
78
80
|
* `JournalBatchBackend`). Here an append is one relaxed transaction on `journal` alone, and an
|
|
79
|
-
* apply is one strict transaction over the
|
|
81
|
+
* apply is one strict transaction over the seven stores and `journal`: every record's entries in
|
|
80
82
|
* order, the applied-through mark, and the delete of each record applied or discarded. The apply
|
|
81
83
|
* carries every byte it applies, so its durability depends on no earlier transaction, and the
|
|
82
84
|
* backend syncs each apply before the next starts — so what a power cut leaves is a prefix of the
|
|
@@ -179,7 +181,7 @@ export class IndexedDBJournalStore {
|
|
|
179
181
|
await Promise.all([tx.store.put(record, record.seq), tx.done]);
|
|
180
182
|
}
|
|
181
183
|
/**
|
|
182
|
-
* One transaction over the
|
|
184
|
+
* One transaction over the seven stores and `journal`, strict where the browser supports it: each
|
|
183
185
|
* record's entries in order, then the mark, then the delete of every numbered record. A number
|
|
184
186
|
* with no record present (a strict group's, never appended) deletes nothing.
|
|
185
187
|
* `JournalStore.applyJournal`'s contract.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexeddb-storage.js","sourceRoot":"","sources":["../../src/indexeddb-storage.ts"],"names":[],"mappings":"AACA,OAAO,EACN,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,GAUjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAA8B,MAAM,SAAS,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAmC,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CAAC,CAAC;IAChH,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optimystic/db-p2p-storage-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Browser IndexedDB storage backend for @optimystic/db-p2p",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"typescript": "^5.9.3"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@optimystic/db-core": "^1.
|
|
58
|
-
"@optimystic/db-p2p": "^1.
|
|
57
|
+
"@optimystic/db-core": "^1.28.0",
|
|
58
|
+
"@optimystic/db-p2p": "^1.28.0",
|
|
59
59
|
"debug": "^4.4.3",
|
|
60
60
|
"idb": "^8.0.3"
|
|
61
61
|
},
|
package/src/db.ts
CHANGED
|
@@ -12,7 +12,7 @@ export const JOURNAL_MARK_KEY = 'applied-through';
|
|
|
12
12
|
/**
|
|
13
13
|
* IndexedDB schema for the Optimystic browser storage backend.
|
|
14
14
|
*
|
|
15
|
-
* The
|
|
15
|
+
* The seven block-storage stores keep their original object stores and compound
|
|
16
16
|
* array keys, but their values are opaque `Uint8Array` blobs: the shared
|
|
17
17
|
* `KvRawStorage` kernel owns JSON (de)serialization, so `IndexedDBJournalStore`
|
|
18
18
|
* only ever hands IndexedDB kernel-encoded bytes. IndexedDB stores a
|
|
@@ -28,9 +28,11 @@ export const JOURNAL_MARK_KEY = 'applied-through';
|
|
|
28
28
|
* - `proofs`: `BlockCommitProof` bytes keyed by `[blockId, rev]` — the same key shape
|
|
29
29
|
* as `revisions`, deliberately NOT the action keyspace (an action id is caller-chosen,
|
|
30
30
|
* so no reserved id could be relied on).
|
|
31
|
+
* - `commitProofs`: `BlockCommitProof` bytes keyed by the proof's `messageHash` string, one
|
|
32
|
+
* per consensus message however many blocks it covers.
|
|
31
33
|
* - `materialized`: materialized block bytes keyed by `[blockId, actionId]`. Deleting
|
|
32
34
|
* the row is an entry of a write group with no value, not a stored `undefined`.
|
|
33
|
-
* - `journal`: the write groups appended and not yet applied to the
|
|
35
|
+
* - `journal`: the write groups appended and not yet applied to the seven stores above, each a
|
|
34
36
|
* `JournalRecord` stored by structured clone under its `seq` (no codec: the record's keys are
|
|
35
37
|
* plain objects and its values `Uint8Array`s), and under {@link JOURNAL_MARK_KEY} the number of
|
|
36
38
|
* the last record applied. `IndexedDBJournalStore` owns both; nothing else touches the store.
|
|
@@ -60,6 +62,10 @@ export interface OptimysticWebDB extends DBSchema {
|
|
|
60
62
|
key: [BlockId, number];
|
|
61
63
|
value: Uint8Array;
|
|
62
64
|
};
|
|
65
|
+
commitProofs: {
|
|
66
|
+
key: string;
|
|
67
|
+
value: Uint8Array;
|
|
68
|
+
};
|
|
63
69
|
materialized: {
|
|
64
70
|
key: [BlockId, ActionId];
|
|
65
71
|
value: Uint8Array;
|
|
@@ -75,11 +81,12 @@ export interface OptimysticWebDB extends DBSchema {
|
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
export const DEFAULT_DB_NAME = 'optimystic';
|
|
78
|
-
// Bumped to 2 when the `proofs` object store was added
|
|
79
|
-
// is guarded by `objectStoreNames.contains`, so an existing
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
84
|
+
// Bumped to 2 when the `proofs` object store was added, to 3 for `journal`, and to 4 for
|
|
85
|
+
// `commitProofs`. The `upgrade` hook is guarded by `objectStoreNames.contains`, so an existing
|
|
86
|
+
// database gains only the stores it lacks (backlog
|
|
87
|
+
// `debt-indexeddb-version-upgrade-is-untested-and-unhandled` owns testing that, and the open that
|
|
88
|
+
// another tab's older connection blocks).
|
|
89
|
+
export const DEFAULT_DB_VERSION = 4;
|
|
83
90
|
|
|
84
91
|
export type OptimysticWebDBHandle = IDBPDatabase<OptimysticWebDB>;
|
|
85
92
|
|
|
@@ -111,6 +118,9 @@ export async function openOptimysticWebDb(
|
|
|
111
118
|
if (!db.objectStoreNames.contains('proofs')) {
|
|
112
119
|
db.createObjectStore('proofs');
|
|
113
120
|
}
|
|
121
|
+
if (!db.objectStoreNames.contains('commitProofs')) {
|
|
122
|
+
db.createObjectStore('commitProofs');
|
|
123
|
+
}
|
|
114
124
|
if (!db.objectStoreNames.contains('materialized')) {
|
|
115
125
|
db.createObjectStore('materialized');
|
|
116
126
|
}
|
package/src/indexeddb-storage.ts
CHANGED
|
@@ -20,14 +20,16 @@ import { createLogger } from './logger.js';
|
|
|
20
20
|
|
|
21
21
|
const log = createLogger('storage:indexeddb');
|
|
22
22
|
|
|
23
|
-
/** The object stores an apply writes: the
|
|
24
|
-
const APPLY_STORES = ['metadata', 'revisions', 'pending', 'transactions', 'proofs', 'materialized', 'journal'] as const;
|
|
23
|
+
/** The object stores an apply writes: the seven block-storage stores and the journal itself. */
|
|
24
|
+
const APPLY_STORES = ['metadata', 'revisions', 'pending', 'transactions', 'proofs', 'commitProofs', 'materialized', 'journal'] as const;
|
|
25
25
|
|
|
26
|
-
/** The IndexedDB key a `StoreKey` addresses in its object store: the
|
|
27
|
-
type IdbKey =
|
|
26
|
+
/** The IndexedDB key a `StoreKey` addresses in its object store: the keys the schema declares. */
|
|
27
|
+
type IdbKey = string | [BlockId, number] | [BlockId, ActionId];
|
|
28
28
|
|
|
29
29
|
function idbKeyOf(key: StoreKey): IdbKey {
|
|
30
30
|
switch (key.store) {
|
|
31
|
+
case 'commitProofs':
|
|
32
|
+
return key.messageHash;
|
|
31
33
|
case 'metadata':
|
|
32
34
|
return key.blockId;
|
|
33
35
|
case 'revisions':
|
|
@@ -60,18 +62,19 @@ function isBatchEntry(entry: unknown): entry is BatchEntry {
|
|
|
60
62
|
|
|
61
63
|
function isStoreKey(key: unknown): key is StoreKey {
|
|
62
64
|
if (typeof key !== 'object' || key === null) return false;
|
|
63
|
-
const { store, blockId, rev, actionId } = key as { store?: unknown; blockId?: unknown; rev?: unknown; actionId?: unknown };
|
|
64
|
-
if (typeof blockId !== 'string') return false;
|
|
65
|
+
const { store, blockId, rev, actionId, messageHash } = key as { store?: unknown; blockId?: unknown; rev?: unknown; actionId?: unknown; messageHash?: unknown };
|
|
65
66
|
switch (store) {
|
|
67
|
+
case 'commitProofs':
|
|
68
|
+
return typeof messageHash === 'string';
|
|
66
69
|
case 'metadata':
|
|
67
|
-
return
|
|
70
|
+
return typeof blockId === 'string';
|
|
68
71
|
case 'revisions':
|
|
69
72
|
case 'proofs':
|
|
70
|
-
return Number.isInteger(rev);
|
|
73
|
+
return typeof blockId === 'string' && Number.isInteger(rev);
|
|
71
74
|
case 'pending':
|
|
72
75
|
case 'transactions':
|
|
73
76
|
case 'materialized':
|
|
74
|
-
return typeof actionId === 'string';
|
|
77
|
+
return typeof blockId === 'string' && typeof actionId === 'string';
|
|
75
78
|
default:
|
|
76
79
|
return false;
|
|
77
80
|
}
|
|
@@ -80,9 +83,9 @@ function isStoreKey(key: unknown): key is StoreKey {
|
|
|
80
83
|
export type IndexedDBJournalStoreOptions = IndexedDBDurabilityOptions;
|
|
81
84
|
|
|
82
85
|
/**
|
|
83
|
-
* IndexedDB {@link JournalStore}: the
|
|
84
|
-
* object stores (`metadata`, `revisions`, `pending`, `transactions`, `proofs`,
|
|
85
|
-
* with their
|
|
86
|
+
* IndexedDB {@link JournalStore}: the seven logical block-storage stores mapped to the seven
|
|
87
|
+
* IndexedDB object stores (`metadata`, `revisions`, `pending`, `transactions`, `proofs`,
|
|
88
|
+
* `commitProofs`, `materialized`) with their keys, read exactly as the per-write driver before it read them, so
|
|
86
89
|
* data an earlier build wrote reads unchanged; and the journal in the `journal` object store,
|
|
87
90
|
* which `JournalBatchBackend` drives.
|
|
88
91
|
*
|
|
@@ -98,7 +101,7 @@ export type IndexedDBJournalStoreOptions = IndexedDBDurabilityOptions;
|
|
|
98
101
|
* transaction completes only once the browser has put it on the disk) but promises nothing about
|
|
99
102
|
* the order relaxed transactions reach the disk, which is why the backend journals (see
|
|
100
103
|
* `JournalBatchBackend`). Here an append is one relaxed transaction on `journal` alone, and an
|
|
101
|
-
* apply is one strict transaction over the
|
|
104
|
+
* apply is one strict transaction over the seven stores and `journal`: every record's entries in
|
|
102
105
|
* order, the applied-through mark, and the delete of each record applied or discarded. The apply
|
|
103
106
|
* carries every byte it applies, so its durability depends on no earlier transaction, and the
|
|
104
107
|
* backend syncs each apply before the next starts — so what a power cut leaves is a prefix of the
|
|
@@ -210,7 +213,7 @@ export class IndexedDBJournalStore implements JournalStore {
|
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
/**
|
|
213
|
-
* One transaction over the
|
|
216
|
+
* One transaction over the seven stores and `journal`, strict where the browser supports it: each
|
|
214
217
|
* record's entries in order, then the mark, then the delete of every numbered record. A number
|
|
215
218
|
* with no record present (a strict group's, never appended) deletes nothing.
|
|
216
219
|
* `JournalStore.applyJournal`'s contract.
|