@optimystic/db-p2p-storage-rn 1.22.0 → 1.23.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 CHANGED
@@ -50,6 +50,8 @@ const libp2p = await createLibp2pNode({
50
50
  bootstrapNodes: [/* … */],
51
51
  networkName: 'my-network',
52
52
  privateKey,
53
+ storage: rawStorage,
54
+ kvStore,
53
55
  });
54
56
  ```
55
57
 
@@ -60,7 +62,7 @@ The same handle is shared by all three consumers. Close the storage and the
60
62
  key-value store before the handle, and the handle last:
61
63
 
62
64
  ```ts
63
- await rawStorage.close(); // applies what it still holds, disarms its timers
65
+ await rawStorage.close(); // releases its read cache, applies what it still holds, disarms its timers
64
66
  await kvStore.close(); // commits what it still holds, disarms its timer
65
67
  await db.close();
66
68
  ```
@@ -69,17 +71,29 @@ Neither `close()` closes the shared handle. A write a store still holds when the
69
71
  handle is closed under it is lost, and a timer it still has armed would fire on
70
72
  a closed handle.
71
73
 
74
+ Open **one** `LevelDBRawStorage` per handle. Its read cache claims the handle
75
+ in its cache pool, so constructing a second one over the same handle while the
76
+ first is open throws (`two caches over one backing store never converge`). That
77
+ refusal is new, but the shape was already wrong: two storages over one store
78
+ each hold writes the other cannot see, which is what
79
+ [storage.md §1. Every write to a store goes through `IRawStorage`](../db-p2p/docs/storage.md#1-every-write-to-a-store-goes-through-irawstorage)
80
+ rules out. Close the first before opening another, including when a node over
81
+ the handle stops and starts again in the same process: the node never closes a
82
+ storage it was handed.
83
+
72
84
  ## Persistence semantics
73
85
 
74
86
  Everything lives in one LevelDB database (`optimystic` by default), one
75
87
  ordered byte keyspace partitioned by a leading tag byte (`src/keys.ts`).
76
- `LevelDBRawStorage` is the shared `KvRawStorage` kernel over a
77
- `WriteGroupDriver` over a `JournalBatchBackend` over a `LevelDBJournalStore`:
78
- the kernel owns all JSON/UTF-8 serialization, so the six block-storage stores
79
- hold opaque kernel-encoded bytes. The keys and the logical types the kernel
80
- decodes them back into are unchanged from earlier builds, so data written by
81
- one reads unchanged, and a database an earlier build wrote has no journal, so
82
- the first open over it applies nothing.
88
+ `LevelDBRawStorage` is the shared `KvRawStorage` kernel over a read cache
89
+ (`CachedStoreDriver`) over a `WriteGroupDriver` over a `JournalBatchBackend`
90
+ over a `LevelDBJournalStore`: the kernel owns all JSON serialization, so the six
91
+ block-storage stores hold opaque kernel-encoded values, written as UTF-8 bytes
92
+ and read back as text (see *Reads decode text in native code* below). The keys,
93
+ the bytes, and the logical types the kernel decodes them back into are
94
+ unchanged from earlier builds, so data written by one reads unchanged, and a
95
+ database an earlier build wrote has no journal, so the first open over it
96
+ applies nothing.
83
97
 
84
98
  | Tag | Store | Key suffix | Decoded (logical) type |
85
99
  |-----|-------|------------|------------------------|
@@ -99,6 +113,51 @@ across a consumer's `await`. `promotePendingTransaction` records two entries of
99
113
  one write group — the committed row's put and the pending row's delete — applied
100
114
  in that group's batch, so the move is atomic across crashes.
101
115
 
116
+ ## Reads decode text in native code
117
+
118
+ Every stored value is JSON text or an action id, written as `TextEncoder`
119
+ output (native in Hermes). Every read — a block, a transform, metadata, a
120
+ proof, a revision's action id, a key-value record — asks `rn-leveldb` for the
121
+ value as a string (`getStr`, and `valueStr` on an iterator), which the binding
122
+ decodes from UTF-8 in native code. No read reaches a JavaScript `TextDecoder`,
123
+ which Hermes provides only as a polyfill and which a device profile of an
124
+ offline save on an older phone measured as the largest single cost of the save
125
+ (GitHub #51). Values are held as text all the way up: the read cache and the
126
+ write group's in-memory overlay hold the string, so a cache hit is the string
127
+ and one `JSON.parse`, and text becomes bytes only when a group is written to
128
+ LevelDB.
129
+
130
+ The read cache is part of the storage, not something to add: the node's own
131
+ cache (`withReadCache`) would front the storage through an adapter that carries
132
+ bytes, bringing back two JavaScript decodes per cold read. `LevelDBRawStorage`
133
+ reports itself read-cached, so the node and the Quereus plugin use it as it is.
134
+ Do not wrap it in a cache of your own: `CachedRawStorage` over it throws
135
+ (`redundant read cache`); a host that wraps every storage should pass one that
136
+ reports `readCached` through unchanged, as `withReadCache` does.
137
+ It shares a memory budget with every other cache in the process
138
+ (`defaultCachePool()`, 8 MB on React Native by default); pass `readCachePool`
139
+ to use a pool of your own, and `readCacheLabel` to name the storage in the
140
+ pool's statistics (`'leveldb'` by default):
141
+
142
+ ```ts
143
+ const rawStorage = new LevelDBRawStorage(db, { readCachePool: pool, readCacheLabel: 'blocks' });
144
+ ```
145
+
146
+ The binding's decoder and `TextDecoder` agree on every value this package
147
+ stores, since `TextEncoder` output is always valid UTF-8, with one difference:
148
+ `TextDecoder` drops a leading byte-order mark and the binding keeps it. JSON
149
+ never starts with one; an action id can, since whoever originates a write
150
+ chooses it, and it now reads back as written, as it already did from the cache
151
+ and the overlay. Existing databases need no migration.
152
+
153
+ **The `TextDecoder` polyfill is still required.** `multiformats` and `cborg`
154
+ construct one when they load, and this package still decodes keys with it:
155
+ block and action ids out of a key in a listing (`listPendingTransactions`,
156
+ `listBlockIds`, the key-value store's `list`), since a key is binary and the
157
+ binding's text reads are defined only for UTF-8. Once `rn-leveldb` can sync a
158
+ batch, journal recovery at open will decode each journal record's keys with it
159
+ too, at open only.
160
+
102
161
  ## Durability
103
162
 
104
163
  A write resolves into memory and is served from there; `flush()` hands every
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,eAAO,MAAM,YAAY,IAAO,CAAC;AACjC,eAAO,MAAM,aAAa,IAAO,CAAC;AAClC,eAAO,MAAM,WAAW,IAAO,CAAC;AAChC,eAAO,MAAM,gBAAgB,IAAO,CAAC;AACrC,eAAO,MAAM,gBAAgB,IAAO,CAAC;AACrC,eAAO,MAAM,UAAU,IAAO,CAAC;AAC/B,eAAO,MAAM,WAAW,IAAO,CAAC;AAChC,eAAO,MAAM,MAAM,KAAO,CAAC;AAC3B,eAAO,MAAM,YAAY,KAAO,CAAC;AA6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CAEpE;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAEvE;AAED,kGAAkG;AAClG,wBAAgB,YAAY,IAAI;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,CAElE;AAED,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAEzD;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAErE;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAE7C;AAED,wGAAwG;AACxG,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,CAcjF;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAErD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAEvD"}
package/dist/src/keys.js CHANGED
@@ -135,6 +135,10 @@ export function blockEnvelopeRange(tag, blockId) {
135
135
  return { gte, lt };
136
136
  }
137
137
  /** Decode the `actionId` suffix from a `pendingKey` / `transactionKey` / `materializedKey`. */
138
+ // NOTE: listings decode key suffixes with `TextDecoder`, a JavaScript polyfill on React Native, where
139
+ // stored values are decoded in native code; a key is binary (tag, length, id), so the engine's text
140
+ // reads cannot decode it. Ids are short and mostly base64url ASCII. If this shows in a device
141
+ // profile, decode an all-ASCII suffix with `String.fromCharCode` and fall back to `TextDecoder`.
138
142
  export function actionIdFromKey(key, blockId) {
139
143
  const blockIdLen = textEncoder.encode(blockId).length;
140
144
  const suffixOffset = 1 + 4 + blockIdLen;
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/keys.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ACf,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACvB,EAAE,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACpB,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,aAAa,CAAC,GAAe;IAC5C,OAAO,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAe;IAC1C,OAAO,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AACzE,CAAC"}
@@ -20,6 +20,11 @@ export type LevelDBKVStoreOptions = WriteGroupOptions;
20
20
  * treats every window, and each batch carries its own data. A failed batch latches the store, after
21
21
  * which every write and flush throws `StoreFailedError` (rule 5 of the flush contract on
22
22
  * `RawStoreDriver.flush`); reads keep serving the overlay.
23
+ *
24
+ * Values stay text until they reach LevelDB: the overlay holds the string, a batch encodes it with
25
+ * `TextEncoder` (native in Hermes), and a read from the store is decoded from UTF-8 by the engine
26
+ * (`LevelDBLike.getText`), so no read constructs a `TextDecoder`, which Hermes has only as a slow
27
+ * polyfill.
23
28
  */
24
29
  export declare class LevelDBKVStore implements IKVStore {
25
30
  private readonly db;
@@ -27,6 +32,7 @@ export declare class LevelDBKVStore implements IKVStore {
27
32
  private readonly group;
28
33
  constructor(db: LevelDBLike, prefix?: string, options?: LevelDBKVStoreOptions);
29
34
  get(key: string): Promise<string | undefined>;
35
+ /** Held as the text it reads back as once stored, so an overlay hit and a read from the store agree on an ill-formed string. */
30
36
  set(key: string, value: string): Promise<void>;
31
37
  delete(key: string): Promise<void>;
32
38
  /** Every key under `prefix`: the store's, plus those written and not yet flushed, less those deleted and not yet flushed. */
@@ -1 +1 @@
1
- {"version":3,"file":"leveldb-kv-store.d.ts","sourceRoot":"","sources":["../../src/leveldb-kv-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAwB,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACrJ,OAAO,EAAS,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG5D,+FAA+F;AAC/F,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AAQtD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,cAAe,YAAW,QAAQ;IAI7C,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;gBAGzB,EAAE,EAAE,WAAW,EACf,MAAM,GAAE,MAA0B,EACnD,OAAO,GAAE,qBAA0B;IAS9B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAQ7C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,6HAA6H;IACvH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAY7C,8KAA8K;IAC9K,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,uIAAuI;IACvI,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,iHAAiH;IACjH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAIR,MAAM;YAUN,UAAU;CAKxB"}
1
+ {"version":3,"file":"leveldb-kv-store.d.ts","sourceRoot":"","sources":["../../src/leveldb-kv-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,KAAK,iBAAiB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAS,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG5D,+FAA+F;AAC/F,MAAM,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AAItD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,cAAe,YAAW,QAAQ;IAI7C,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;gBAGjC,EAAE,EAAE,WAAW,EACf,MAAM,GAAE,MAA0B,EACnD,OAAO,GAAE,qBAA0B;IAS9B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMnD,gIAAgI;IAC1H,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,6HAA6H;IACvH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAY7C,8KAA8K;IAC9K,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,uIAAuI;IACvI,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,iHAAiH;IACjH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAIR,MAAM;YAUN,UAAU;CAKxB"}
@@ -1,11 +1,7 @@
1
- import { WriteGroup } from '@optimystic/db-p2p';
1
+ import { WriteGroup, asStoredText, textValueCodec, } from '@optimystic/db-p2p';
2
2
  import { drain } from './leveldb-like.js';
3
3
  import { kvKey, kvKeyToString, kvPrefixRange } from './keys.js';
4
4
  const textEncoder = new TextEncoder();
5
- // Built on first use, not at module load: Hermes (React Native) has no native `TextDecoder`, so a
6
- // module-scope construction fails the import itself whenever it runs ahead of the host's polyfill.
7
- let textDecoderInstance;
8
- const textDecoder = () => textDecoderInstance ??= new TextDecoder();
9
5
  /**
10
6
  * LevelDB-backed `IKVStore` adapter for React Native peers.
11
7
  *
@@ -24,6 +20,11 @@ const textDecoder = () => textDecoderInstance ??= new TextDecoder();
24
20
  * treats every window, and each batch carries its own data. A failed batch latches the store, after
25
21
  * which every write and flush throws `StoreFailedError` (rule 5 of the flush contract on
26
22
  * `RawStoreDriver.flush`); reads keep serving the overlay.
23
+ *
24
+ * Values stay text until they reach LevelDB: the overlay holds the string, a batch encodes it with
25
+ * `TextEncoder` (native in Hermes), and a read from the store is decoded from UTF-8 by the engine
26
+ * (`LevelDBLike.getText`), so no read constructs a `TextDecoder`, which Hermes has only as a slow
27
+ * polyfill.
27
28
  */
28
29
  export class LevelDBKVStore {
29
30
  db;
@@ -36,19 +37,17 @@ export class LevelDBKVStore {
36
37
  commit: entries => this.commit(entries),
37
38
  // Every commit is as durable as this store can make it when it resolves, so nothing is ever owed a sync.
38
39
  sync: () => Promise.resolve(),
39
- }, options);
40
+ }, { ...options, storedBytes: textValueCodec.storedBytes });
40
41
  }
41
42
  async get(key) {
42
43
  const held = this.group.lookup(key);
43
44
  if (held !== undefined)
44
- return held === null ? undefined : textDecoder().decode(held);
45
- const bytes = await this.db.get(kvKey(this.prefix + key));
46
- if (!bytes)
47
- return undefined;
48
- return textDecoder().decode(bytes);
45
+ return held ?? undefined;
46
+ return this.db.getText(kvKey(this.prefix + key));
49
47
  }
48
+ /** Held as the text it reads back as once stored, so an overlay hit and a read from the store agree on an ill-formed string. */
50
49
  async set(key, value) {
51
- this.group.put(key, textEncoder.encode(value));
50
+ this.group.put(key, asStoredText(value));
52
51
  }
53
52
  async delete(key) {
54
53
  this.group.delete(key);
@@ -86,7 +85,7 @@ export class LevelDBKVStore {
86
85
  if (value === undefined)
87
86
  batch.delete(encoded);
88
87
  else
89
- batch.put(encoded, value);
88
+ batch.put(encoded, textEncoder.encode(value));
90
89
  }
91
90
  await batch.write({ sync: this.db.canSync });
92
91
  return { durable: Promise.resolve() };
@@ -1 +1 @@
1
- {"version":3,"file":"leveldb-kv-store.js","sourceRoot":"","sources":["../../src/leveldb-kv-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuG,MAAM,oBAAoB,CAAC;AACrJ,OAAO,EAAE,KAAK,EAAoB,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAKhE,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,kGAAkG;AAClG,mGAAmG;AACnG,IAAI,mBAA4C,CAAC;AACjD,MAAM,WAAW,GAAG,GAAgB,EAAE,CAAC,mBAAmB,KAAK,IAAI,WAAW,EAAE,CAAC;AAEjF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,cAAc;IAIR;IACA;IAJD,KAAK,CAAqB;IAE3C,YACkB,EAAe,EACf,SAAiB,iBAAiB,EACnD,UAAiC,EAAE;QAFlB,OAAE,GAAF,EAAE,CAAa;QACf,WAAM,GAAN,MAAM,CAA4B;QAGnD,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,CAAS,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE;YAC/C,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YACvC,yGAAyG;YACzG,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE;SAC7B,EAAE,OAAO,CAAC,CAAC;IACb,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,IAAI,KA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C;IACnF,CAAC;CACD"}
@@ -34,10 +34,12 @@ export interface LevelDBIteratorOptions {
34
34
  /** Skip values (return zero-length Uint8Array for value). Used by `getApproximateBytesUsed`. */
35
35
  keys?: boolean;
36
36
  }
37
- /** Cursor over a `LevelDBLike` range scan. Caller must `close()` exactly once. */
38
- export interface LevelDBIteratorLike {
37
+ /** Range options for a `LevelDBLike.textIterator` scan: an iterator's, less `keys`, since a text scan exists to read values. */
38
+ export type LevelDBTextIteratorOptions = Omit<LevelDBIteratorOptions, 'keys'>;
39
+ /** Cursor over a `LevelDBLike` range scan, each value a `V` (bytes, or text from `textIterator`). Caller must `close()` exactly once. */
40
+ export interface LevelDBIteratorLike<V = Uint8Array> {
39
41
  /** Return the next entry, or `undefined` when the range is exhausted. */
40
- next(): Promise<[Uint8Array, Uint8Array] | undefined>;
42
+ next(): Promise<[Uint8Array, V] | undefined>;
41
43
  /** Release any native resources held by the iterator. */
42
44
  close(): Promise<void>;
43
45
  }
@@ -73,8 +75,19 @@ export interface LevelDBLike {
73
75
  */
74
76
  readonly canSync: boolean;
75
77
  get(key: Uint8Array): Promise<Uint8Array | undefined>;
78
+ /**
79
+ * The value at `key` as the text its UTF-8 bytes decode to, decoded by the engine rather than by a
80
+ * JavaScript `TextDecoder`, which Hermes provides only as a slow polyfill. Defined for a value that
81
+ * is valid UTF-8, and undefined for any other: every block-storage and key-value value this package
82
+ * stores is `TextEncoder` output, while a journal record, the journal's mark, the identity key and
83
+ * every key are binary, so those are read with `get` and `iterator` alone. Unlike `TextDecoder`,
84
+ * the engine keeps a leading byte-order mark.
85
+ */
86
+ getText(key: Uint8Array): Promise<string | undefined>;
76
87
  batch(): LevelDBWriteBatchLike;
77
88
  iterator(options?: LevelDBIteratorOptions): LevelDBIteratorLike;
89
+ /** `iterator`, each value read as `getText` reads one. */
90
+ textIterator(options?: LevelDBTextIteratorOptions): LevelDBIteratorLike<string>;
78
91
  /** Release the underlying database handle. */
79
92
  close(): Promise<void>;
80
93
  }
@@ -83,5 +96,5 @@ export interface LevelDBLike {
83
96
  * iterator never stays open across consumer awaits — same rationale as the
84
97
  * IndexedDB and SQLite backends.
85
98
  */
86
- export declare function drain(iter: LevelDBIteratorLike): Promise<Array<[Uint8Array, Uint8Array]>>;
99
+ export declare function drain<V>(iter: LevelDBIteratorLike<V>): Promise<Array<[Uint8Array, V]>>;
87
100
  //# sourceMappingURL=leveldb-like.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"leveldb-like.d.ts","sourceRoot":"","sources":["../../src/leveldb-like.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,uDAAuD;AACvD,MAAM,WAAW,sBAAsB;IACtC,6BAA6B;IAC7B,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,6BAA6B;IAC7B,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,6BAA6B;IAC7B,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,6BAA6B;IAC7B,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gGAAgG;IAChG,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,kFAAkF;AAClF,MAAM,WAAW,mBAAmB;IACnC,yEAAyE;IACzE,IAAI,IAAI,OAAO,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,SAAS,CAAC,CAAC;IACtD,yDAAyD;IACzD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED,8BAA8B;AAC9B,MAAM,WAAW,mBAAmB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,6EAA6E;AAC7E,MAAM,WAAW,qBAAqB;IACrC,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9C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AK,CAAC,CAAC,EAAE,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAY5F"}
@@ -1 +1 @@
1
- {"version":3,"file":"leveldb-like.js","sourceRoot":"","sources":["../../src/leveldb-like.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAoEH;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,IAAyB;IACpD,MAAM,GAAG,GAAoC,EAAE,CAAC;IAChD,IAAI,CAAC;QACJ,OAAO,IAAI,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK;gBAAE,MAAM;YAClB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;IACF,CAAC;YAAS,CAAC;QACV,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
1
+ {"version":3,"file":"leveldb-like.js","sourceRoot":"","sources":["../../src/leveldb-like.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAkFH;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAI,IAA4B;IAC1D,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,IAAI,CAAC;QACJ,OAAO,IAAI,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK;gBAAE,MAAM;YAClB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;IACF,CAAC;YAAS,CAAC;QACV,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { ActionId, BlockId } from '@optimystic/db-core';
2
- import { KvRawStorage, type JournalBatchBackendOptions, type JournalContents, type JournalRecord, type JournalStore, type StoreDurability, type StoreIdentity, type StoreKey, type WriteGroupOptions } from '@optimystic/db-p2p';
2
+ import { KvRawStorage, type JournalBatchBackendOptions, type JournalContents, type JournalRecord, type JournalStore, type SharedCachePool, type StoreDurability, type StoreIdentity, type StoreKey, type WriteGroupOptions } from '@optimystic/db-p2p';
3
3
  import { type LevelDBLike } from './leveldb-like.js';
4
4
  /**
5
5
  * LevelDB {@link JournalStore}: the six logical block-storage stores mapped into a single ordered
@@ -7,8 +7,12 @@ import { type LevelDBLike } from './leveldb-like.js';
7
7
  * driver before it read them, so data an earlier build wrote reads unchanged; and the journal under
8
8
  * its own tag byte, which `JournalBatchBackend` drives.
9
9
  *
10
- * `KvRawStorage` owns all JSON/UTF-8 serialization, so this store only ever reads/writes raw
11
- * `Uint8Array` values; a journal record is bytes too, through `encodeJournalRecord`. Everything
10
+ * `KvRawStorage` owns all JSON serialization, so this store only moves values: it writes the
11
+ * UTF-8 bytes the write group hands it, and reads each value back as the text those bytes decode
12
+ * to, decoded by LevelDB's binding in native code (`LevelDBLike.getText` and `textIterator`), so a
13
+ * read never reaches a JavaScript `TextDecoder` — on React Native a polyfill, measured as the
14
+ * largest single cost of an offline save on an older phone (GitHub #51). A journal record stays
15
+ * bytes, through `encodeJournalRecord`, and is read only by recovery at open. Everything
12
16
  * LevelDB-specific stays here: the tag-range scans (drained snapshot-first before yielding, so a
13
17
  * native iterator never straddles a consumer's `await`), and the one `WriteBatch` each journal
14
18
  * write is.
@@ -34,14 +38,14 @@ import { type LevelDBLike } from './leveldb-like.js';
34
38
  * The handle is shared with `LevelDBKVStore` and `loadOrCreateRNPeerKey`, so there is no `close`
35
39
  * here: the host closes the handle after `storage.close()` has resolved.
36
40
  */
37
- export declare class LevelDBJournalStore implements JournalStore {
41
+ export declare class LevelDBJournalStore implements JournalStore<string> {
38
42
  private readonly db;
39
43
  readonly durability: StoreDurability;
40
44
  private readonly identity;
41
45
  constructor(db: LevelDBLike);
42
46
  storeIdentity(): StoreIdentity;
43
- get(key: StoreKey): Promise<Uint8Array | undefined>;
44
- rangeRevisions(blockId: BlockId, lo: number, hi: number): Promise<[number, Uint8Array][]>;
47
+ get(key: StoreKey): Promise<string | undefined>;
48
+ rangeRevisions(blockId: BlockId, lo: number, hi: number): Promise<[number, string][]>;
45
49
  listPendingActionIds(blockId: BlockId): Promise<ActionId[]>;
46
50
  listBlockIds(): AsyncIterable<BlockId>;
47
51
  approximateBytesUsed(): Promise<number>;
@@ -64,28 +68,47 @@ export declare class LevelDBJournalStore implements JournalStore {
64
68
  private readMark;
65
69
  private readRecord;
66
70
  }
67
- /** The write group's and the journal backend's options (`idleFlushMs`, `maxUnsyncedBytes`, the test-only `setTimer` and `now`). */
68
- export type LevelDBRawStorageOptions = WriteGroupOptions & JournalBatchBackendOptions;
69
71
  /**
70
- * LevelDB-backed {@link IRawStorage} for React Native peers: the shared {@link KvRawStorage}
71
- * kernel over a {@link WriteGroupDriver} over a {@link JournalBatchBackend} over a
72
- * {@link LevelDBJournalStore}. Every write resolves into the driver's in-memory overlay; `flush()`
73
- * hands the group to the backend as one LevelDB batch — applied before the flush resolves, or,
74
- * for a flush with a window on a handle that can sync, appended as one journal record and applied
75
- * by the deadline. The public name/constructor (`new LevelDBRawStorage(db)`) is unchanged so
76
- * existing imports keep resolving.
72
+ * The write group's and the journal backend's options (`idleFlushMs`, `maxUnsyncedBytes`, the
73
+ * test-only `setTimer` and `now`), and the read cache's.
74
+ */
75
+ export interface LevelDBRawStorageOptions extends WriteGroupOptions, JournalBatchBackendOptions {
76
+ /** The pool the storage's read cache shares its memory budget with; `defaultCachePool()` by default. */
77
+ readCachePool?: SharedCachePool;
78
+ /** Names the storage in the pool's statistics; `'leveldb'` by default. */
79
+ readCacheLabel?: string;
80
+ }
81
+ /**
82
+ * LevelDB-backed {@link IRawStorage} for React Native peers, every layer holding text: the shared
83
+ * {@link KvRawStorage} kernel over a {@link CachedStoreDriver} (its read cache) over a
84
+ * {@link WriteGroupDriver} over a {@link JournalBatchBackend} over a {@link LevelDBJournalStore}.
85
+ * Every write resolves into the driver's in-memory overlay; `flush()` hands the group to the
86
+ * backend as one LevelDB batch — applied before the flush resolves, or, for a flush with a window on
87
+ * a handle that can sync, appended as one journal record and applied by the deadline. The public
88
+ * name/constructor (`new LevelDBRawStorage(db)`) is unchanged so existing imports keep resolving.
89
+ *
90
+ * The read cache is built in, and there is no option to leave it out: the node's own cache
91
+ * (`withReadCache`) fronts a storage through `RawStorageDriverAdapter`, which carries bytes, so a
92
+ * cold read through it would decode the stored value, re-encode it to bytes and decode it again,
93
+ * twice in JavaScript. Because this storage reports `readCached`, the node and the Quereus plugin
94
+ * pass it through unwrapped. A cache hit is the cached string and one `JSON.parse`. The cache claims
95
+ * the handle in its pool (`SharedCachePool.registerStore`), so a second storage over the same handle
96
+ * while the first is open is refused: two write groups over one store would already break Invariant 1
97
+ * (every write funnels through one `IRawStorage`) in `packages/db-p2p/docs/storage.md`.
77
98
  *
78
- * `listBlockIds`/`getApproximateBytesUsed`/`getStoreIdentity`/`close` are re-declared here as
79
- * always-present (the store always implements the first three, so the backend, driver and kernel
80
- * always wire them, and the driver always has a `close`) — the base declares them optional, but
81
- * every RN consumer relies on them. `close()` applies what is still held and disarms the timers;
82
- * it does not close the shared handle, which the host closes afterwards.
99
+ * `listBlockIds`/`getApproximateBytesUsed`/`getStoreIdentity`/`close`/`readCached` are re-declared
100
+ * here as always-present (the store always implements the first three, so every layer always wires
101
+ * them, the cache always has a `close` and always reports `readCached`) — the base declares them
102
+ * optional, but every RN consumer relies on them. `close()` drops the cache and releases its pool
103
+ * registration, then applies what the write group still holds and disarms the timers; it does not
104
+ * close the shared handle, which the host closes afterwards.
83
105
  */
84
- export declare class LevelDBRawStorage extends KvRawStorage {
106
+ export declare class LevelDBRawStorage extends KvRawStorage<string> {
85
107
  listBlockIds: () => AsyncIterable<BlockId>;
86
108
  getApproximateBytesUsed: () => Promise<number>;
87
109
  getStoreIdentity: () => StoreIdentity;
88
110
  close: () => Promise<void>;
111
+ readonly readCached: true;
89
112
  constructor(db: LevelDBLike, options?: LevelDBRawStorageOptions);
90
113
  }
91
114
  //# sourceMappingURL=leveldb-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"leveldb-storage.d.ts","sourceRoot":"","sources":["../../src/leveldb-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAGN,YAAY,EAKZ,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,iBAAiB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAS,KAAK,WAAW,EAA8B,MAAM,mBAAmB,CAAC;AA4CxF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IAa3C,OAAO,CAAC,QAAQ,CAAC,EAAE;IAR/B,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IAMrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;gBAEZ,EAAE,EAAE,WAAW;IAK5C,aAAa,IAAI,aAAa;IAMxB,GAAG,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAInD,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC;IAYzF,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAM1D,YAAY,IAAI,aAAa,CAAC,O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AAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,iBAAkB,SAAQ,YAAY,CAAC,MAAM,CAAC;IAClD,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;IAGnC,SAAiB,UAAU,EAAE,IAAI,CAAC;gBAEtB,EAAE,EAAE,WAAW,EAAE,OAAO,GAAE,wBAA6B;CAInE"}
@@ -1,4 +1,4 @@
1
- import { JournalBatchBackend, JournalRecordDecodeError, KvRawStorage, WriteGroupDriver, decodeJournalRecord, encodeJournalRecord, identityForHandle, } from '@optimystic/db-p2p';
1
+ import { CachedStoreDriver, JournalBatchBackend, JournalRecordDecodeError, KvRawStorage, WriteGroupDriver, decodeJournalRecord, encodeJournalRecord, identityForHandle, textValueCodec, } from '@optimystic/db-p2p';
2
2
  import { drain } from './leveldb-like.js';
3
3
  import { TAG_PENDING, actionIdFromKey, blockEnvelopeRange, blockIdFromMetadataKey, decodeJournalMark, encodeJournalMark, isJournalMarkKey, journalMarkKey, journalRange, journalRecordKey, materializedKey, metadataKey, metadataRange, pendingKey, proofKey, revisionFromKey, revisionKey, seqFromJournalKey, transactionKey, } from './keys.js';
4
4
  import { createLogger } from './logger.js';
@@ -26,8 +26,12 @@ function keyBytes(key) {
26
26
  * driver before it read them, so data an earlier build wrote reads unchanged; and the journal under
27
27
  * its own tag byte, which `JournalBatchBackend` drives.
28
28
  *
29
- * `KvRawStorage` owns all JSON/UTF-8 serialization, so this store only ever reads/writes raw
30
- * `Uint8Array` values; a journal record is bytes too, through `encodeJournalRecord`. Everything
29
+ * `KvRawStorage` owns all JSON serialization, so this store only moves values: it writes the
30
+ * UTF-8 bytes the write group hands it, and reads each value back as the text those bytes decode
31
+ * to, decoded by LevelDB's binding in native code (`LevelDBLike.getText` and `textIterator`), so a
32
+ * read never reaches a JavaScript `TextDecoder` — on React Native a polyfill, measured as the
33
+ * largest single cost of an offline save on an older phone (GitHub #51). A journal record stays
34
+ * bytes, through `encodeJournalRecord`, and is read only by recovery at open. Everything
31
35
  * LevelDB-specific stays here: the tag-range scans (drained snapshot-first before yielding, so a
32
36
  * native iterator never straddles a consumer's `await`), and the one `WriteBatch` each journal
33
37
  * write is.
@@ -75,7 +79,7 @@ export class LevelDBJournalStore {
75
79
  }
76
80
  // --- reads: the applied stores ---
77
81
  async get(key) {
78
- return this.db.get(keyBytes(key));
82
+ return this.db.getText(keyBytes(key));
79
83
  }
80
84
  async rangeRevisions(blockId, lo, hi) {
81
85
  // Revs are encoded 8-byte big-endian (`revisionKey`), so byte order == numeric
@@ -85,7 +89,7 @@ export class LevelDBJournalStore {
85
89
  const lt = revisionKey(blockId, hi + 1);
86
90
  // Drained before returning: a native LevelDB iterator must not stay open across the
87
91
  // consumer's awaits (the kernel's drain-before-yield contract).
88
- const entries = await drain(this.db.iterator({ gte, lt }));
92
+ const entries = await drain(this.db.textIterator({ gte, lt }));
89
93
  return entries.map(([key, value]) => [revisionFromKey(key), value]);
90
94
  }
91
95
  async listPendingActionIds(blockId) {
@@ -216,23 +220,34 @@ function putEntries(batch, record) {
216
220
  }
217
221
  }
218
222
  /**
219
- * LevelDB-backed {@link IRawStorage} for React Native peers: the shared {@link KvRawStorage}
220
- * kernel over a {@link WriteGroupDriver} over a {@link JournalBatchBackend} over a
221
- * {@link LevelDBJournalStore}. Every write resolves into the driver's in-memory overlay; `flush()`
222
- * hands the group to the backend as one LevelDB batch — applied before the flush resolves, or,
223
- * for a flush with a window on a handle that can sync, appended as one journal record and applied
224
- * by the deadline. The public name/constructor (`new LevelDBRawStorage(db)`) is unchanged so
225
- * existing imports keep resolving.
223
+ * LevelDB-backed {@link IRawStorage} for React Native peers, every layer holding text: the shared
224
+ * {@link KvRawStorage} kernel over a {@link CachedStoreDriver} (its read cache) over a
225
+ * {@link WriteGroupDriver} over a {@link JournalBatchBackend} over a {@link LevelDBJournalStore}.
226
+ * Every write resolves into the driver's in-memory overlay; `flush()` hands the group to the
227
+ * backend as one LevelDB batch — applied before the flush resolves, or, for a flush with a window on
228
+ * a handle that can sync, appended as one journal record and applied by the deadline. The public
229
+ * name/constructor (`new LevelDBRawStorage(db)`) is unchanged so existing imports keep resolving.
226
230
  *
227
- * `listBlockIds`/`getApproximateBytesUsed`/`getStoreIdentity`/`close` are re-declared here as
228
- * always-present (the store always implements the first three, so the backend, driver and kernel
229
- * always wire them, and the driver always has a `close`) — the base declares them optional, but
230
- * every RN consumer relies on them. `close()` applies what is still held and disarms the timers;
231
- * it does not close the shared handle, which the host closes afterwards.
231
+ * The read cache is built in, and there is no option to leave it out: the node's own cache
232
+ * (`withReadCache`) fronts a storage through `RawStorageDriverAdapter`, which carries bytes, so a
233
+ * cold read through it would decode the stored value, re-encode it to bytes and decode it again,
234
+ * twice in JavaScript. Because this storage reports `readCached`, the node and the Quereus plugin
235
+ * pass it through unwrapped. A cache hit is the cached string and one `JSON.parse`. The cache claims
236
+ * the handle in its pool (`SharedCachePool.registerStore`), so a second storage over the same handle
237
+ * while the first is open is refused: two write groups over one store would already break Invariant 1
238
+ * (every write funnels through one `IRawStorage`) in `packages/db-p2p/docs/storage.md`.
239
+ *
240
+ * `listBlockIds`/`getApproximateBytesUsed`/`getStoreIdentity`/`close`/`readCached` are re-declared
241
+ * here as always-present (the store always implements the first three, so every layer always wires
242
+ * them, the cache always has a `close` and always reports `readCached`) — the base declares them
243
+ * optional, but every RN consumer relies on them. `close()` drops the cache and releases its pool
244
+ * registration, then applies what the write group still holds and disarms the timers; it does not
245
+ * close the shared handle, which the host closes afterwards.
232
246
  */
233
247
  export class LevelDBRawStorage extends KvRawStorage {
234
248
  constructor(db, options = {}) {
235
- super(new WriteGroupDriver(new JournalBatchBackend(new LevelDBJournalStore(db), options), options));
249
+ const writeGroup = new WriteGroupDriver(new JournalBatchBackend(new LevelDBJournalStore(db), options), options, textValueCodec);
250
+ super(new CachedStoreDriver(writeGroup, options.readCachePool, options.readCacheLabel ?? 'leveldb', textValueCodec), textValueCodec);
236
251
  }
237
252
  }
238
253
  //# sourceMappingURL=leveldb-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"leveldb-storage.js","sourceRoot":"","sources":["../../src/leveldb-storage.ts"],"names":[],"mappings":"AACA,OAAO,EACN,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,GASjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAgD,MAAM,mBAAmB,CAAC;AACxF,OAAO,EACN,WAAW,EACX,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,cAAc,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,GAAG,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAC;AAE5C,wIAAwI;AACxI,SAAS,QAAQ,CAAC,GAAa;IAC9B,QAAQ,GAAG,CAAC,KAAK,EAAE,CAAC;QACnB,KAAK,UAAU;YACd,OAAO,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACjC,KAAK,WAAW;YACf,OAAO,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1C,KAAK,QAAQ;YACZ,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QACvC,KAAK,SAAS;YACb,OAAO,UAAU,CAAC,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AACvG,SAAS,UAAU,CAAC,KAA4B,EAAE,MAAqB;IACtE,KAAK,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QAC7C,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;;YAAM,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAChF,CAAC;AACF,CAAC;AAaD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,iBAAkB,SAAQ,YAAoB;IAS1D,YAAY,EAAe,EAAE,UAAoC,EAAE;QAClE,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAC,IAAI,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;QAChI,KAAK,CAAC,IAAI,iBAAiB,CAAC,UAAU,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,cAAc,IAAI,SAAS,EAAE,cAAc,CAAC,EAAE,cAAc,CAAC,CAAC;IACtI,CAAC;CACD"}
@@ -11,6 +11,8 @@ import type { LevelDBLike } from './leveldb-like.js';
11
11
  export interface RNLevelDBNative {
12
12
  put(key: ArrayBuffer | string, value: ArrayBuffer | string): void;
13
13
  getBuf(key: ArrayBuffer | string): ArrayBuffer | null;
14
+ /** The value decoded from UTF-8 in native code (JSI's `String::createFromUtf8`), or `null` when absent. */
15
+ getStr(key: ArrayBuffer | string): string | null;
14
16
  delete(key: ArrayBuffer | string): void;
15
17
  close(): void;
16
18
  newIterator(): RNLevelDBIteratorNative;
@@ -30,6 +32,8 @@ export interface RNLevelDBIteratorNative {
30
32
  prev(): void;
31
33
  keyBuf(): ArrayBuffer;
32
34
  valueBuf(): ArrayBuffer;
35
+ /** The current value decoded from UTF-8 in native code, as `getStr` decodes one. */
36
+ valueStr(): string;
33
37
  close(): void;
34
38
  }
35
39
  /** Constructor type for `rn-leveldb`'s `LevelDBWriteBatch`. */
@@ -1 +1 @@
1
- {"version":3,"file":"rn-opener.d.ts","sourceRoot":"","sources":["../../src/rn-opener.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGX,WAAW,EAGX,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC/B,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;IAClE,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IACtD,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;IACxC,KAAK,IAAI,IAAI,CAAC;IACd,WAAW,IAAI,uBAAuB,CAAC;IACvC,KAAK,CAAC,KAAK,EAAE,yBAAyB,GAAG,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,yBAAyB;IACzC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;IAClE,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;IACxC,KAAK,IAAI,IAAI,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACvC,KAAK,IAAI,OAAO,CAAC;IACjB,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,GAAG,uBAAuB,CAAC;IAC5D,WAAW,IAAI,uBAAuB,CAAC;IACvC,QAAQ,IAAI,uBAAuB,CAAC;IACpC,IAAI,IAAI,IAAI,CAAC;IACb,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,IAAI,WAAW,CAAC;IACtB,QAAQ,IAAI,WAAW,CAAC;IACxB,KAAK,IAAI,IAA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E;IACxE,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,WAAW,CAOlF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,uBAAuB,GAAG,WAAW,CAEvG"}
@@ -35,11 +35,17 @@ class RNLevelDBAdapter {
35
35
  const result = this.native.getBuf(toArrayBuffer(key));
36
36
  return result === null ? undefined : new Uint8Array(result);
37
37
  }
38
+ async getText(key) {
39
+ return this.native.getStr(toArrayBuffer(key)) ?? undefined;
40
+ }
38
41
  batch() {
39
42
  return new RNLevelDBWriteBatchAdapter(this.native, new this.WriteBatch());
40
43
  }
41
44
  iterator(options = {}) {
42
- return new RNLevelDBIteratorAdapter(this.native.newIterator(), options);
45
+ return new RNLevelDBIteratorAdapter(this.native.newIterator(), options, options.keys ? noValue : bytesValue);
46
+ }
47
+ textIterator(options = {}) {
48
+ return new RNLevelDBIteratorAdapter(this.native.newIterator(), options, textValue);
43
49
  }
44
50
  async close() {
45
51
  this.native.close();
@@ -73,15 +79,22 @@ class RNLevelDBWriteBatchAdapter {
73
79
  }
74
80
  }
75
81
  }
82
+ const bytesValue = iter => new Uint8Array(iter.valueBuf());
83
+ const textValue = iter => iter.valueStr();
84
+ /** A `keys: true` scan wants only keys, so the `valueBuf` native call is skipped. */
85
+ const noValue = () => new Uint8Array(0);
86
+ /** One positioning and bounds walk for both value kinds; only {@link ReadValue} differs. */
76
87
  class RNLevelDBIteratorAdapter {
77
88
  iter;
78
89
  opts;
90
+ readValue;
79
91
  positioned = false;
80
92
  yielded = 0;
81
93
  done = false;
82
- constructor(iter, opts) {
94
+ constructor(iter, opts, readValue) {
83
95
  this.iter = iter;
84
96
  this.opts = opts;
97
+ this.readValue = readValue;
85
98
  }
86
99
  async next() {
87
100
  if (this.done)
@@ -126,8 +139,7 @@ class RNLevelDBIteratorAdapter {
126
139
  return undefined;
127
140
  }
128
141
  }
129
- // `keys: true` means caller wants only keys; skip the `valueBuf` native call.
130
- const value = this.opts.keys ? new Uint8Array(0) : new Uint8Array(this.iter.valueBuf());
142
+ const value = this.readValue(this.iter);
131
143
  this.yielded++;
132
144
  return [key, value];
133
145
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rn-opener.js","sourceRoot":"","sources":["../../src/rn-opener.ts"],"names":[],"mappings":"AAuDA,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAe5C;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkC;IACpE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAC5B,OAAO,CAAC,IAAI,IAAI,eAAe,EAC/B,OAAO,CAAC,eAAe,IAAI,IAAI,EAC/B,OAAO,CAAC,aAAa,IAAI,KAAK,CAC9B,CAAC;IACF,OAAO,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAuB,EAAE,UAAmC;IACzF,OAAO,IAAI,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,gBAAgB;IAOH;IACA;IAPlB,8FAA8F;IAC9F,2FAA2F;IAC3F,+CAA+C;IACtC,OAAO,GAAG,KAAK,CAAC;IAEzB,YACkB,MAAuB,EACvB,UAAmC;QADnC,WAAM,GAAN,MAAM,CAAiB;QACvB,eAAU,GAAV,UAAU,CAAyB;IAClD,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,GAAe;QACxB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;QACtD,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC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C,UAAU,KAAK,CAAC;WACtB,KAAK,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU,EAAE,CAAC;QAC5C,OAAO,MAAM,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CAAC,CAAa,EAAE,CAAa;IACjD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;QACjB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;QACjB,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AAC5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimystic/db-p2p-storage-rn",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "type": "module",
5
5
  "description": "React Native LevelDB 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.22.0",
58
- "@optimystic/db-p2p": "^1.22.0",
57
+ "@optimystic/db-core": "^1.23.0",
58
+ "@optimystic/db-p2p": "^1.23.0",
59
59
  "debug": "^4.4.3"
60
60
  },
61
61
  "peerDependencies": {
package/src/keys.ts CHANGED
@@ -149,6 +149,10 @@ export function blockEnvelopeRange(tag: number, blockId: string): { gte: Uint8Ar
149
149
  }
150
150
 
151
151
  /** Decode the `actionId` suffix from a `pendingKey` / `transactionKey` / `materializedKey`. */
152
+ // NOTE: listings decode key suffixes with `TextDecoder`, a JavaScript polyfill on React Native, where
153
+ // stored values are decoded in native code; a key is binary (tag, length, id), so the engine's text
154
+ // reads cannot decode it. Ids are short and mostly base64url ASCII. If this shows in a device
155
+ // profile, decode an all-ASCII suffix with `String.fromCharCode` and fall back to `TextDecoder`.
152
156
  export function actionIdFromKey(key: Uint8Array, blockId: string): string {
153
157
  const blockIdLen = textEncoder.encode(blockId).length;
154
158
  const suffixOffset = 1 + 4 + blockIdLen;
@@ -1,4 +1,13 @@
1
- import { WriteGroup, type CommittedBatch, type FlushOptions, type IKVStore, type WriteGroupEntry, type WriteGroupOptions } from '@optimystic/db-p2p';
1
+ import {
2
+ WriteGroup,
3
+ asStoredText,
4
+ textValueCodec,
5
+ type CommittedBatch,
6
+ type FlushOptions,
7
+ type IKVStore,
8
+ type WriteGroupEntry,
9
+ type WriteGroupOptions,
10
+ } from '@optimystic/db-p2p';
2
11
  import { drain, type LevelDBLike } from './leveldb-like.js';
3
12
  import { kvKey, kvKeyToString, kvPrefixRange } from './keys.js';
4
13
 
@@ -6,10 +15,6 @@ import { kvKey, kvKeyToString, kvPrefixRange } from './keys.js';
6
15
  export type LevelDBKVStoreOptions = WriteGroupOptions;
7
16
 
8
17
  const textEncoder = new TextEncoder();
9
- // Built on first use, not at module load: Hermes (React Native) has no native `TextDecoder`, so a
10
- // module-scope construction fails the import itself whenever it runs ahead of the host's polyfill.
11
- let textDecoderInstance: TextDecoder | undefined;
12
- const textDecoder = (): TextDecoder => textDecoderInstance ??= new TextDecoder();
13
18
 
14
19
  /**
15
20
  * LevelDB-backed `IKVStore` adapter for React Native peers.
@@ -29,32 +34,36 @@ const textDecoder = (): TextDecoder => textDecoderInstance ??= new TextDecoder()
29
34
  * treats every window, and each batch carries its own data. A failed batch latches the store, after
30
35
  * which every write and flush throws `StoreFailedError` (rule 5 of the flush contract on
31
36
  * `RawStoreDriver.flush`); reads keep serving the overlay.
37
+ *
38
+ * Values stay text until they reach LevelDB: the overlay holds the string, a batch encodes it with
39
+ * `TextEncoder` (native in Hermes), and a read from the store is decoded from UTF-8 by the engine
40
+ * (`LevelDBLike.getText`), so no read constructs a `TextDecoder`, which Hermes has only as a slow
41
+ * polyfill.
32
42
  */
33
43
  export class LevelDBKVStore implements IKVStore {
34
- private readonly group: WriteGroup<string>;
44
+ private readonly group: WriteGroup<string, string>;
35
45
 
36
46
  constructor(
37
47
  private readonly db: LevelDBLike,
38
48
  private readonly prefix: string = 'optimystic:txn:',
39
49
  options: LevelDBKVStoreOptions = {},
40
50
  ) {
41
- this.group = new WriteGroup<string>(key => key, {
51
+ this.group = new WriteGroup<string, string>(key => key, {
42
52
  commit: entries => this.commit(entries),
43
53
  // Every commit is as durable as this store can make it when it resolves, so nothing is ever owed a sync.
44
54
  sync: () => Promise.resolve(),
45
- }, options);
55
+ }, { ...options, storedBytes: textValueCodec.storedBytes });
46
56
  }
47
57
 
48
58
  async get(key: string): Promise<string | undefined> {
49
59
  const held = this.group.lookup(key);
50
- if (held !== undefined) return held === null ? undefined : textDecoder().decode(held);
51
- const bytes = await this.db.get(kvKey(this.prefix + key));
52
- if (!bytes) return undefined;
53
- return textDecoder().decode(bytes);
60
+ if (held !== undefined) return held ?? undefined;
61
+ return this.db.getText(kvKey(this.prefix + key));
54
62
  }
55
63
 
64
+ /** Held as the text it reads back as once stored, so an overlay hit and a read from the store agree on an ill-formed string. */
56
65
  async set(key: string, value: string): Promise<void> {
57
- this.group.put(key, textEncoder.encode(value));
66
+ this.group.put(key, asStoredText(value));
58
67
  }
59
68
 
60
69
  async delete(key: string): Promise<void> {
@@ -89,11 +98,11 @@ export class LevelDBKVStore implements IKVStore {
89
98
  return this.group.close();
90
99
  }
91
100
 
92
- private async commit(entries: readonly WriteGroupEntry<string>[]): Promise<CommittedBatch> {
101
+ private async commit(entries: readonly WriteGroupEntry<string, string>[]): Promise<CommittedBatch> {
93
102
  const batch = this.db.batch();
94
103
  for (const { key, value } of entries) {
95
104
  const encoded = kvKey(this.prefix + key);
96
- if (value === undefined) batch.delete(encoded); else batch.put(encoded, value);
105
+ if (value === undefined) batch.delete(encoded); else batch.put(encoded, textEncoder.encode(value));
97
106
  }
98
107
  await batch.write({ sync: this.db.canSync });
99
108
  return { durable: Promise.resolve() };
@@ -36,10 +36,13 @@ export interface LevelDBIteratorOptions {
36
36
  keys?: boolean;
37
37
  }
38
38
 
39
- /** Cursor over a `LevelDBLike` range scan. Caller must `close()` exactly once. */
40
- export interface LevelDBIteratorLike {
39
+ /** Range options for a `LevelDBLike.textIterator` scan: an iterator's, less `keys`, since a text scan exists to read values. */
40
+ export type LevelDBTextIteratorOptions = Omit<LevelDBIteratorOptions, 'keys'>;
41
+
42
+ /** Cursor over a `LevelDBLike` range scan, each value a `V` (bytes, or text from `textIterator`). Caller must `close()` exactly once. */
43
+ export interface LevelDBIteratorLike<V = Uint8Array> {
41
44
  /** Return the next entry, or `undefined` when the range is exhausted. */
42
- next(): Promise<[Uint8Array, Uint8Array] | undefined>;
45
+ next(): Promise<[Uint8Array, V] | undefined>;
43
46
  /** Release any native resources held by the iterator. */
44
47
  close(): Promise<void>;
45
48
  }
@@ -78,8 +81,19 @@ export interface LevelDBLike {
78
81
  */
79
82
  readonly canSync: boolean;
80
83
  get(key: Uint8Array): Promise<Uint8Array | undefined>;
84
+ /**
85
+ * The value at `key` as the text its UTF-8 bytes decode to, decoded by the engine rather than by a
86
+ * JavaScript `TextDecoder`, which Hermes provides only as a slow polyfill. Defined for a value that
87
+ * is valid UTF-8, and undefined for any other: every block-storage and key-value value this package
88
+ * stores is `TextEncoder` output, while a journal record, the journal's mark, the identity key and
89
+ * every key are binary, so those are read with `get` and `iterator` alone. Unlike `TextDecoder`,
90
+ * the engine keeps a leading byte-order mark.
91
+ */
92
+ getText(key: Uint8Array): Promise<string | undefined>;
81
93
  batch(): LevelDBWriteBatchLike;
82
94
  iterator(options?: LevelDBIteratorOptions): LevelDBIteratorLike;
95
+ /** `iterator`, each value read as `getText` reads one. */
96
+ textIterator(options?: LevelDBTextIteratorOptions): LevelDBIteratorLike<string>;
83
97
  /** Release the underlying database handle. */
84
98
  close(): Promise<void>;
85
99
  }
@@ -89,8 +103,8 @@ export interface LevelDBLike {
89
103
  * iterator never stays open across consumer awaits — same rationale as the
90
104
  * IndexedDB and SQLite backends.
91
105
  */
92
- export async function drain(iter: LevelDBIteratorLike): Promise<Array<[Uint8Array, Uint8Array]>> {
93
- const out: Array<[Uint8Array, Uint8Array]> = [];
106
+ export async function drain<V>(iter: LevelDBIteratorLike<V>): Promise<Array<[Uint8Array, V]>> {
107
+ const out: Array<[Uint8Array, V]> = [];
94
108
  try {
95
109
  while (true) {
96
110
  const entry = await iter.next();
@@ -1,5 +1,6 @@
1
1
  import type { ActionId, BlockId } from '@optimystic/db-core';
2
2
  import {
3
+ CachedStoreDriver,
3
4
  JournalBatchBackend,
4
5
  JournalRecordDecodeError,
5
6
  KvRawStorage,
@@ -7,10 +8,12 @@ import {
7
8
  decodeJournalRecord,
8
9
  encodeJournalRecord,
9
10
  identityForHandle,
11
+ textValueCodec,
10
12
  type JournalBatchBackendOptions,
11
13
  type JournalContents,
12
14
  type JournalRecord,
13
15
  type JournalStore,
16
+ type SharedCachePool,
14
17
  type StoreDurability,
15
18
  type StoreIdentity,
16
19
  type StoreKey,
@@ -66,8 +69,12 @@ function keyBytes(key: StoreKey): Uint8Array {
66
69
  * driver before it read them, so data an earlier build wrote reads unchanged; and the journal under
67
70
  * its own tag byte, which `JournalBatchBackend` drives.
68
71
  *
69
- * `KvRawStorage` owns all JSON/UTF-8 serialization, so this store only ever reads/writes raw
70
- * `Uint8Array` values; a journal record is bytes too, through `encodeJournalRecord`. Everything
72
+ * `KvRawStorage` owns all JSON serialization, so this store only moves values: it writes the
73
+ * UTF-8 bytes the write group hands it, and reads each value back as the text those bytes decode
74
+ * to, decoded by LevelDB's binding in native code (`LevelDBLike.getText` and `textIterator`), so a
75
+ * read never reaches a JavaScript `TextDecoder` — on React Native a polyfill, measured as the
76
+ * largest single cost of an offline save on an older phone (GitHub #51). A journal record stays
77
+ * bytes, through `encodeJournalRecord`, and is read only by recovery at open. Everything
71
78
  * LevelDB-specific stays here: the tag-range scans (drained snapshot-first before yielding, so a
72
79
  * native iterator never straddles a consumer's `await`), and the one `WriteBatch` each journal
73
80
  * write is.
@@ -93,7 +100,7 @@ function keyBytes(key: StoreKey): Uint8Array {
93
100
  * The handle is shared with `LevelDBKVStore` and `loadOrCreateRNPeerKey`, so there is no `close`
94
101
  * here: the host closes the handle after `storage.close()` has resolved.
95
102
  */
96
- export class LevelDBJournalStore implements JournalStore {
103
+ export class LevelDBJournalStore implements JournalStore<string> {
97
104
  // NOTE: `'process-crash'` holds only while the handle cannot sync (flush contract rule 3 is then
98
105
  // not kept across a power cut: LevelDB's recovery skips a damaged log record and keeps the ones
99
106
  // after it, and no apply is synced). The synced path is built and tested over `classic-level`;
@@ -117,11 +124,11 @@ export class LevelDBJournalStore implements JournalStore {
117
124
 
118
125
  // --- reads: the applied stores ---
119
126
 
120
- async get(key: StoreKey): Promise<Uint8Array | undefined> {
121
- return this.db.get(keyBytes(key));
127
+ async get(key: StoreKey): Promise<string | undefined> {
128
+ return this.db.getText(keyBytes(key));
122
129
  }
123
130
 
124
- async rangeRevisions(blockId: BlockId, lo: number, hi: number): Promise<[number, Uint8Array][]> {
131
+ async rangeRevisions(blockId: BlockId, lo: number, hi: number): Promise<[number, string][]> {
125
132
  // Revs are encoded 8-byte big-endian (`revisionKey`), so byte order == numeric
126
133
  // order and `revisionKey(blockId, hi)` is exactly the inclusive upper bound;
127
134
  // LevelDB's upper bound is exclusive (`lt`), so use `lt = revisionKey(hi + 1)`.
@@ -129,7 +136,7 @@ export class LevelDBJournalStore implements JournalStore {
129
136
  const lt = revisionKey(blockId, hi + 1);
130
137
  // Drained before returning: a native LevelDB iterator must not stay open across the
131
138
  // consumer's awaits (the kernel's drain-before-yield contract).
132
- const entries = await drain(this.db.iterator({ gte, lt }));
139
+ const entries = await drain(this.db.textIterator({ gte, lt }));
133
140
  return entries.map(([key, value]) => [revisionFromKey(key), value]);
134
141
  }
135
142
 
@@ -262,31 +269,53 @@ function putEntries(batch: LevelDBWriteBatchLike, record: JournalRecord): void {
262
269
  }
263
270
  }
264
271
 
265
- /** The write group's and the journal backend's options (`idleFlushMs`, `maxUnsyncedBytes`, the test-only `setTimer` and `now`). */
266
- export type LevelDBRawStorageOptions = WriteGroupOptions & JournalBatchBackendOptions;
272
+ /**
273
+ * The write group's and the journal backend's options (`idleFlushMs`, `maxUnsyncedBytes`, the
274
+ * test-only `setTimer` and `now`), and the read cache's.
275
+ */
276
+ export interface LevelDBRawStorageOptions extends WriteGroupOptions, JournalBatchBackendOptions {
277
+ /** The pool the storage's read cache shares its memory budget with; `defaultCachePool()` by default. */
278
+ readCachePool?: SharedCachePool;
279
+ /** Names the storage in the pool's statistics; `'leveldb'` by default. */
280
+ readCacheLabel?: string;
281
+ }
267
282
 
268
283
  /**
269
- * LevelDB-backed {@link IRawStorage} for React Native peers: the shared {@link KvRawStorage}
270
- * kernel over a {@link WriteGroupDriver} over a {@link JournalBatchBackend} over a
271
- * {@link LevelDBJournalStore}. Every write resolves into the driver's in-memory overlay; `flush()`
272
- * hands the group to the backend as one LevelDB batch — applied before the flush resolves, or,
273
- * for a flush with a window on a handle that can sync, appended as one journal record and applied
274
- * by the deadline. The public name/constructor (`new LevelDBRawStorage(db)`) is unchanged so
275
- * existing imports keep resolving.
284
+ * LevelDB-backed {@link IRawStorage} for React Native peers, every layer holding text: the shared
285
+ * {@link KvRawStorage} kernel over a {@link CachedStoreDriver} (its read cache) over a
286
+ * {@link WriteGroupDriver} over a {@link JournalBatchBackend} over a {@link LevelDBJournalStore}.
287
+ * Every write resolves into the driver's in-memory overlay; `flush()` hands the group to the
288
+ * backend as one LevelDB batch — applied before the flush resolves, or, for a flush with a window on
289
+ * a handle that can sync, appended as one journal record and applied by the deadline. The public
290
+ * name/constructor (`new LevelDBRawStorage(db)`) is unchanged so existing imports keep resolving.
291
+ *
292
+ * The read cache is built in, and there is no option to leave it out: the node's own cache
293
+ * (`withReadCache`) fronts a storage through `RawStorageDriverAdapter`, which carries bytes, so a
294
+ * cold read through it would decode the stored value, re-encode it to bytes and decode it again,
295
+ * twice in JavaScript. Because this storage reports `readCached`, the node and the Quereus plugin
296
+ * pass it through unwrapped. A cache hit is the cached string and one `JSON.parse`. The cache claims
297
+ * the handle in its pool (`SharedCachePool.registerStore`), so a second storage over the same handle
298
+ * while the first is open is refused: two write groups over one store would already break Invariant 1
299
+ * (every write funnels through one `IRawStorage`) in `packages/db-p2p/docs/storage.md`.
276
300
  *
277
- * `listBlockIds`/`getApproximateBytesUsed`/`getStoreIdentity`/`close` are re-declared here as
278
- * always-present (the store always implements the first three, so the backend, driver and kernel
279
- * always wire them, and the driver always has a `close`) — the base declares them optional, but
280
- * every RN consumer relies on them. `close()` applies what is still held and disarms the timers;
281
- * it does not close the shared handle, which the host closes afterwards.
301
+ * `listBlockIds`/`getApproximateBytesUsed`/`getStoreIdentity`/`close`/`readCached` are re-declared
302
+ * here as always-present (the store always implements the first three, so every layer always wires
303
+ * them, the cache always has a `close` and always reports `readCached`) — the base declares them
304
+ * optional, but every RN consumer relies on them. `close()` drops the cache and releases its pool
305
+ * registration, then applies what the write group still holds and disarms the timers; it does not
306
+ * close the shared handle, which the host closes afterwards.
282
307
  */
283
- export class LevelDBRawStorage extends KvRawStorage {
308
+ export class LevelDBRawStorage extends KvRawStorage<string> {
284
309
  declare listBlockIds: () => AsyncIterable<BlockId>;
285
310
  declare getApproximateBytesUsed: () => Promise<number>;
286
311
  declare getStoreIdentity: () => StoreIdentity;
287
312
  declare close: () => Promise<void>;
313
+ // `declare`, not a field: a field would be redefined as `undefined` after `super()` (see the note
314
+ // on `CachedRawStorage.readCached`).
315
+ declare readonly readCached: true;
288
316
 
289
317
  constructor(db: LevelDBLike, options: LevelDBRawStorageOptions = {}) {
290
- super(new WriteGroupDriver(new JournalBatchBackend(new LevelDBJournalStore(db), options), options));
318
+ const writeGroup = new WriteGroupDriver(new JournalBatchBackend(new LevelDBJournalStore(db), options), options, textValueCodec);
319
+ super(new CachedStoreDriver(writeGroup, options.readCachePool, options.readCacheLabel ?? 'leveldb', textValueCodec), textValueCodec);
291
320
  }
292
321
  }
package/src/rn-opener.ts CHANGED
@@ -2,6 +2,7 @@ import type {
2
2
  LevelDBIteratorLike,
3
3
  LevelDBIteratorOptions,
4
4
  LevelDBLike,
5
+ LevelDBTextIteratorOptions,
5
6
  LevelDBWriteBatchLike,
6
7
  LevelDBWriteOptions,
7
8
  } from './leveldb-like.js';
@@ -18,6 +19,8 @@ import type {
18
19
  export interface RNLevelDBNative {
19
20
  put(key: ArrayBuffer | string, value: ArrayBuffer | string): void;
20
21
  getBuf(key: ArrayBuffer | string): ArrayBuffer | null;
22
+ /** The value decoded from UTF-8 in native code (JSI's `String::createFromUtf8`), or `null` when absent. */
23
+ getStr(key: ArrayBuffer | string): string | null;
21
24
  delete(key: ArrayBuffer | string): void;
22
25
  close(): void;
23
26
  newIterator(): RNLevelDBIteratorNative;
@@ -39,6 +42,8 @@ export interface RNLevelDBIteratorNative {
39
42
  prev(): void;
40
43
  keyBuf(): ArrayBuffer;
41
44
  valueBuf(): ArrayBuffer;
45
+ /** The current value decoded from UTF-8 in native code, as `getStr` decodes one. */
46
+ valueStr(): string;
42
47
  close(): void;
43
48
  }
44
49
 
@@ -111,12 +116,20 @@ class RNLevelDBAdapter implements LevelDBLike {
111
116
  return result === null ? undefined : new Uint8Array(result);
112
117
  }
113
118
 
119
+ async getText(key: Uint8Array): Promise<string | undefined> {
120
+ return this.native.getStr(toArrayBuffer(key)) ?? undefined;
121
+ }
122
+
114
123
  batch(): LevelDBWriteBatchLike {
115
124
  return new RNLevelDBWriteBatchAdapter(this.native, new this.WriteBatch());
116
125
  }
117
126
 
118
127
  iterator(options: LevelDBIteratorOptions = {}): LevelDBIteratorLike {
119
- return new RNLevelDBIteratorAdapter(this.native.newIterator(), options);
128
+ return new RNLevelDBIteratorAdapter(this.native.newIterator(), options, options.keys ? noValue : bytesValue);
129
+ }
130
+
131
+ textIterator(options: LevelDBTextIteratorOptions = {}): LevelDBIteratorLike<string> {
132
+ return new RNLevelDBIteratorAdapter(this.native.newIterator(), options, textValue);
120
133
  }
121
134
 
122
135
  async close(): Promise<void> {
@@ -153,17 +166,27 @@ class RNLevelDBWriteBatchAdapter implements LevelDBWriteBatchLike {
153
166
  }
154
167
  }
155
168
 
156
- class RNLevelDBIteratorAdapter implements LevelDBIteratorLike {
169
+ /** How an iterator adapter reads the value at the native iterator's position. */
170
+ type ReadValue<V> = (iter: RNLevelDBIteratorNative) => V;
171
+
172
+ const bytesValue: ReadValue<Uint8Array> = iter => new Uint8Array(iter.valueBuf());
173
+ const textValue: ReadValue<string> = iter => iter.valueStr();
174
+ /** A `keys: true` scan wants only keys, so the `valueBuf` native call is skipped. */
175
+ const noValue: ReadValue<Uint8Array> = () => new Uint8Array(0);
176
+
177
+ /** One positioning and bounds walk for both value kinds; only {@link ReadValue} differs. */
178
+ class RNLevelDBIteratorAdapter<V> implements LevelDBIteratorLike<V> {
157
179
  private positioned = false;
158
180
  private yielded = 0;
159
181
  private done = false;
160
182
 
161
183
  constructor(
162
184
  private readonly iter: RNLevelDBIteratorNative,
163
- private readonly opts: LevelDBIteratorOptions,
185
+ private readonly opts: LevelDBTextIteratorOptions,
186
+ private readonly readValue: ReadValue<V>,
164
187
  ) {}
165
188
 
166
- async next(): Promise<[Uint8Array, Uint8Array] | undefined> {
189
+ async next(): Promise<[Uint8Array, V] | undefined> {
167
190
  if (this.done) return undefined;
168
191
  if (this.opts.limit !== undefined && this.yielded >= this.opts.limit) {
169
192
  this.done = true;
@@ -207,8 +230,7 @@ class RNLevelDBIteratorAdapter implements LevelDBIteratorLike {
207
230
  }
208
231
  }
209
232
 
210
- // `keys: true` means caller wants only keys; skip the `valueBuf` native call.
211
- const value = this.opts.keys ? new Uint8Array(0) : new Uint8Array(this.iter.valueBuf());
233
+ const value = this.readValue(this.iter);
212
234
  this.yielded++;
213
235
  return [key, value];
214
236
  }