keri-ts 2.0.0 → 2.1.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/esm/keri/npm/src/acdc/chaining.js +223 -89
- package/esm/keri/npm/src/acdc/observing.js +2 -2
- package/esm/keri/npm/src/acdc/regbasing.js +20 -29
- package/esm/keri/npm/src/acdc/regengine.js +4 -6
- package/esm/keri/npm/src/acdc/registering.js +13 -10
- package/esm/keri/npm/src/acdc/registraring.js +4 -9
- package/esm/keri/npm/src/acdc/salting.js +127 -25
- package/esm/keri/npm/src/acdc/unblinding.js +2 -4
- package/esm/keri/npm/src/app/bootstrap/oobiery.js +1 -1
- package/esm/keri/npm/src/app/credentials/root-replicating.js +123 -0
- package/esm/keri/npm/src/app/credentials/verifying.js +21 -3
- package/esm/keri/npm/src/app/delivery/forwarding.js +49 -7
- package/esm/keri/npm/src/app/exchanges/exchanging.js +11 -12
- package/esm/keri/npm/src/app/identity/configing.js +17 -43
- package/esm/keri/npm/src/app/identity/habbing.js +54 -35
- package/esm/keri/npm/src/app/identity/keeping.js +1 -1
- package/esm/keri/npm/src/app/identity/lmdb-habery.js +12 -0
- package/esm/keri/npm/src/app/ipex/ipex-graph.js +7 -70
- package/esm/keri/npm/src/app/ipex/ipex-grouping.js +8 -5
- package/esm/keri/npm/src/app/ipex/ipex-v2.js +21 -5
- package/esm/keri/npm/src/app/ipex/ipexing.js +1 -1
- package/esm/keri/npm/src/app/mailbox/mailboxing.js +5 -9
- package/esm/keri/npm/src/app/multisig/group-members.js +14 -0
- package/esm/keri/npm/src/app/multisig/grouping.js +4 -3
- package/esm/keri/npm/src/app/multisig/multisig-workflows.js +7 -2
- package/esm/keri/npm/src/app/notifications/notifying.js +5 -9
- package/esm/keri/npm/src/app/protocol/protocol-processing.js +35 -3
- package/esm/keri/npm/src/app/queries/witness-inquisitor.js +2 -2
- package/esm/keri/npm/src/app/runtime/agent-runtime.js +7 -10
- package/esm/keri/npm/src/app/transport/byte-source.js +6 -42
- package/esm/keri/npm/src/app/transport/cesr-egress.js +77 -13
- package/esm/keri/npm/src/app/transport/file-bytes.js +41 -0
- package/esm/keri/npm/src/app/transport/http-messenger.js +14 -9
- package/esm/keri/npm/src/app/transport/message-source.js +1 -1
- package/esm/keri/npm/src/app/transport/messengering.js +3 -4
- package/esm/keri/npm/src/app/transport/node-http-client.js +21 -0
- package/esm/keri/npm/src/app/transport/tcp-dialer.js +14 -0
- package/esm/keri/npm/src/app/witness/receipt-client.js +2 -2
- package/esm/keri/npm/src/cli/common/context.js +2 -2
- package/esm/keri/npm/src/cli/common/existing.js +3 -5
- package/esm/keri/npm/src/cli/credentials/ipex.js +2 -1
- package/esm/keri/npm/src/cli/endpoints/oobi-clean.js +4 -3
- package/esm/keri/npm/src/cli/endpoints/oobi.js +2 -2
- package/esm/keri/npm/src/cli/identity/challenge.js +2 -2
- package/esm/keri/npm/src/cli/identity/incept.js +2 -2
- package/esm/keri/npm/src/cli/identity/init.js +4 -3
- package/esm/keri/npm/src/cli/identity/interact.js +2 -2
- package/esm/keri/npm/src/cli/identity/rotate.js +2 -2
- package/esm/keri/npm/src/cli/messaging/exchange.js +2 -2
- package/esm/keri/npm/src/cli/messaging/multisig.js +61 -3
- package/esm/keri/npm/src/cli/tools/annotate.js +2 -1
- package/esm/keri/npm/src/cli/tools/benchmark.js +2 -1
- package/esm/keri/npm/src/cli/tools/db-dump.js +1 -4
- package/esm/keri/npm/src/core/bytes.js +9 -0
- package/esm/keri/npm/src/core/kel/delegation-ancestry.js +92 -0
- package/esm/keri/npm/src/core/kel/eventing.js +1 -2
- package/esm/keri/npm/src/core/kel/kever.js +11 -9
- package/esm/keri/npm/src/core/mailbox/kram-policy.js +2 -3
- package/esm/keri/npm/src/core/mailbox/kram-pruning.js +15 -22
- package/esm/keri/npm/src/core/mailbox/kram-staging.js +2 -2
- package/esm/keri/npm/src/core/routing.js +2 -2
- package/esm/keri/npm/src/db/basing.js +149 -203
- package/esm/keri/npm/src/db/core/dber.js +1062 -0
- package/esm/keri/npm/src/db/core/index.js +4 -2
- package/esm/keri/npm/src/db/core/lmdb-opener.js +30 -0
- package/esm/keri/npm/src/db/core/lmdber.js +199 -1067
- package/esm/keri/npm/src/db/core/memstore.js +532 -0
- package/esm/keri/npm/src/db/core/path-manager.js +109 -223
- package/esm/keri/npm/src/db/core/store-owner.js +104 -0
- package/esm/keri/npm/src/db/core/webdber.js +252 -0
- package/esm/keri/npm/src/db/escrowing.js +2 -2
- package/esm/keri/npm/src/db/exchange/exchange-nests.js +3 -2
- package/esm/keri/npm/src/db/keeping.js +27 -121
- package/esm/keri/npm/src/db/koming.js +1 -1
- package/esm/keri/npm/src/db/lmdb-stores.js +68 -0
- package/esm/keri/npm/src/db/lmdb.js +6 -0
- package/esm/keri/npm/src/db/mailbox/mailboxing.js +12 -65
- package/esm/keri/npm/src/db/noting.js +11 -55
- package/esm/keri/npm/src/db/reger.js +43 -105
- package/esm/keri/npm/src/db/replay/witness-replay.js +2 -20
- package/esm/keri/npm/src/db/subing.js +1 -1
- package/esm/keri/npm/src/npm/db-lmdb.js +3 -0
- package/esm/keri/npm/src/npm/runtime-node.js +3 -0
- package/esm/keri/npm/src/runtime/index.js +9 -10
- package/esm/keri/npm/src/runtime/node.js +14 -0
- package/esm/keri/npm/src/vdr/eventing.js +1 -1
- package/esm/keri/npm/src/vdr/tel-publication.js +3 -3
- package/esm/keri/npm/src/version.js +2 -2
- package/package.json +11 -4
- package/types/acdc/chaining.d.ts +56 -6
- package/types/acdc/chaining.d.ts.map +1 -1
- package/types/acdc/regbasing.d.ts +7 -6
- package/types/acdc/regbasing.d.ts.map +1 -1
- package/types/acdc/regengine.d.ts.map +1 -1
- package/types/acdc/registering.d.ts +8 -4
- package/types/acdc/registering.d.ts.map +1 -1
- package/types/acdc/registraring.d.ts.map +1 -1
- package/types/acdc/salting.d.ts +53 -6
- package/types/acdc/salting.d.ts.map +1 -1
- package/types/acdc/unblinding.d.ts.map +1 -1
- package/types/app/credentials/root-replicating.d.ts +85 -0
- package/types/app/credentials/root-replicating.d.ts.map +1 -0
- package/types/app/credentials/verifying.d.ts +2 -1
- package/types/app/credentials/verifying.d.ts.map +1 -1
- package/types/app/delivery/forwarding.d.ts +10 -0
- package/types/app/delivery/forwarding.d.ts.map +1 -1
- package/types/app/exchanges/exchanging.d.ts +2 -0
- package/types/app/exchanges/exchanging.d.ts.map +1 -1
- package/types/app/identity/configing.d.ts +7 -5
- package/types/app/identity/configing.d.ts.map +1 -1
- package/types/app/identity/habbing.d.ts +23 -5
- package/types/app/identity/habbing.d.ts.map +1 -1
- package/types/app/identity/keeping.d.ts +1 -1
- package/types/app/identity/lmdb-habery.d.ts +6 -0
- package/types/app/identity/lmdb-habery.d.ts.map +1 -0
- package/types/app/ipex/ipex-graph.d.ts +4 -4
- package/types/app/ipex/ipex-graph.d.ts.map +1 -1
- package/types/app/ipex/ipex-grouping.d.ts.map +1 -1
- package/types/app/ipex/ipex-v2.d.ts +11 -2
- package/types/app/ipex/ipex-v2.d.ts.map +1 -1
- package/types/app/ipex/ipexing.d.ts +3 -0
- package/types/app/ipex/ipexing.d.ts.map +1 -1
- package/types/app/mailbox/mailboxing.d.ts +1 -1
- package/types/app/mailbox/mailboxing.d.ts.map +1 -1
- package/types/app/multisig/group-members.d.ts +9 -0
- package/types/app/multisig/group-members.d.ts.map +1 -1
- package/types/app/multisig/grouping.d.ts.map +1 -1
- package/types/app/multisig/multisig-workflows.d.ts +2 -1
- package/types/app/multisig/multisig-workflows.d.ts.map +1 -1
- package/types/app/notifications/notifying.d.ts +1 -1
- package/types/app/notifications/notifying.d.ts.map +1 -1
- package/types/app/protocol/parsering.d.ts +3 -1
- package/types/app/protocol/parsering.d.ts.map +1 -1
- package/types/app/protocol/protocol-processing.d.ts +2 -0
- package/types/app/protocol/protocol-processing.d.ts.map +1 -1
- package/types/app/runtime/agent-runtime.d.ts +7 -0
- package/types/app/runtime/agent-runtime.d.ts.map +1 -1
- package/types/app/transport/byte-source.d.ts +13 -10
- package/types/app/transport/byte-source.d.ts.map +1 -1
- package/types/app/transport/cesr-egress.d.ts +21 -7
- package/types/app/transport/cesr-egress.d.ts.map +1 -1
- package/types/app/transport/file-bytes.d.ts +11 -0
- package/types/app/transport/file-bytes.d.ts.map +1 -0
- package/types/app/transport/http-client.d.ts +3 -0
- package/types/app/transport/http-client.d.ts.map +1 -1
- package/types/app/transport/http-messenger.d.ts +15 -10
- package/types/app/transport/http-messenger.d.ts.map +1 -1
- package/types/app/transport/message-source.d.ts +1 -1
- package/types/app/transport/messengering.d.ts +2 -2
- package/types/app/transport/messengering.d.ts.map +1 -1
- package/types/app/transport/node-http-client.d.ts +10 -0
- package/types/app/transport/node-http-client.d.ts.map +1 -0
- package/types/app/transport/tcp-dialer.d.ts +21 -0
- package/types/app/transport/tcp-dialer.d.ts.map +1 -0
- package/types/cli/common/existing.d.ts.map +1 -1
- package/types/cli/credentials/ipex.d.ts.map +1 -1
- package/types/cli/endpoints/oobi-clean.d.ts.map +1 -1
- package/types/cli/identity/init.d.ts.map +1 -1
- package/types/cli/index.d.ts +1 -1
- package/types/cli/index.d.ts.map +1 -1
- package/types/cli/messaging/multisig.d.ts +10 -1
- package/types/cli/messaging/multisig.d.ts.map +1 -1
- package/types/cli/tools/annotate.d.ts.map +1 -1
- package/types/cli/tools/benchmark.d.ts.map +1 -1
- package/types/cli/tools/db-dump.d.ts.map +1 -1
- package/types/core/bytes.d.ts +2 -0
- package/types/core/bytes.d.ts.map +1 -1
- package/types/core/kel/delegation-ancestry.d.ts +41 -0
- package/types/core/kel/delegation-ancestry.d.ts.map +1 -0
- package/types/core/kel/eventing.d.ts.map +1 -1
- package/types/core/kel/kever.d.ts +5 -4
- package/types/core/kel/kever.d.ts.map +1 -1
- package/types/core/mailbox/kram-policy.d.ts.map +1 -1
- package/types/core/mailbox/kram-pruning.d.ts +1 -3
- package/types/core/mailbox/kram-pruning.d.ts.map +1 -1
- package/types/db/basing.d.ts +14 -23
- package/types/db/basing.d.ts.map +1 -1
- package/types/db/core/dber.d.ts +505 -0
- package/types/db/core/dber.d.ts.map +1 -0
- package/types/db/core/index.d.ts +4 -2
- package/types/db/core/index.d.ts.map +1 -1
- package/types/db/core/lmdb-opener.d.ts +17 -0
- package/types/db/core/lmdb-opener.d.ts.map +1 -0
- package/types/db/core/lmdber.d.ts +60 -383
- package/types/db/core/lmdber.d.ts.map +1 -1
- package/types/db/core/memstore.d.ts +129 -0
- package/types/db/core/memstore.d.ts.map +1 -0
- package/types/db/core/path-manager.d.ts +22 -45
- package/types/db/core/path-manager.d.ts.map +1 -1
- package/types/db/core/store-owner.d.ts +59 -0
- package/types/db/core/store-owner.d.ts.map +1 -0
- package/types/db/core/webdber.d.ts +127 -0
- package/types/db/core/webdber.d.ts.map +1 -0
- package/types/db/escrowing.d.ts +3 -3
- package/types/db/escrowing.d.ts.map +1 -1
- package/types/db/exchange/exchange-nests.d.ts.map +1 -1
- package/types/db/keeping.d.ts +9 -23
- package/types/db/keeping.d.ts.map +1 -1
- package/types/db/koming.d.ts +7 -8
- package/types/db/koming.d.ts.map +1 -1
- package/types/db/lmdb-stores.d.ts +45 -0
- package/types/db/lmdb-stores.d.ts.map +1 -0
- package/types/db/lmdb.d.ts +7 -0
- package/types/db/lmdb.d.ts.map +1 -0
- package/types/db/mailbox/mailboxing.d.ts +7 -21
- package/types/db/mailbox/mailboxing.d.ts.map +1 -1
- package/types/db/noting.d.ts +7 -12
- package/types/db/noting.d.ts.map +1 -1
- package/types/db/reger.d.ts +7 -11
- package/types/db/reger.d.ts.map +1 -1
- package/types/db/replay/witness-replay.d.ts +0 -2
- package/types/db/replay/witness-replay.d.ts.map +1 -1
- package/types/db/subing.d.ts +24 -25
- package/types/db/subing.d.ts.map +1 -1
- package/types/npm/db-lmdb.d.ts +4 -0
- package/types/npm/db-lmdb.d.ts.map +1 -0
- package/types/npm/runtime-node.d.ts +4 -0
- package/types/npm/runtime-node.d.ts.map +1 -0
- package/types/runtime/index.d.ts +9 -10
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/node.d.ts +15 -0
- package/types/runtime/node.d.ts.map +1 -0
- package/types/version.d.ts +2 -2
- package/esm/keri/npm/src/acdc/relating.js +0 -59
- package/esm/keri/npm/src/db/baser-defaults.js +0 -11
- package/types/acdc/relating.d.ts +0 -21
- package/types/acdc/relating.d.ts.map +0 -1
- package/types/db/baser-defaults.d.ts +0 -5
- package/types/db/baser-defaults.d.ts.map +0 -1
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory `DBer` backend: one bytewise-sorted row array per table.
|
|
3
|
+
*
|
|
4
|
+
* ADR-0015 owns the semantics and `LMDBer` is the reference where the ADR is
|
|
5
|
+
* silent. Nothing here may reach `lmdb`, `node:` or the `Deno` global.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - each table's `rows` stay sorted by key, then by value on a dupsort table;
|
|
9
|
+
* - stored rows are immutable and every byte array entering or leaving is a
|
|
10
|
+
* fresh copy, so callers can neither reach nor alias store state;
|
|
11
|
+
* - every mutation runs inside `transaction` and logs its exact inverse.
|
|
12
|
+
*/
|
|
13
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
14
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
15
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
16
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
17
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
18
|
+
};
|
|
19
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
20
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
21
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
22
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
23
|
+
};
|
|
24
|
+
var _MemStore_instances, _MemStore_name, _MemStore_base, _MemStore_temp, _MemStore_opened, _MemStore_created, _MemStore_tables, _MemStore_version, _MemStore_writeVersion, _MemStore_undo, _MemStore_depth, _MemStore_discard, _MemStore_walk, _MemStore_resolve, _MemStore_logRow, _MemStore_insert, _MemStore_removeAt, _MemStore_removeRange;
|
|
25
|
+
import { b, bytesHex, t } from "cesr-ts";
|
|
26
|
+
import { compareBytes, startsWith } from "../../core/bytes.js";
|
|
27
|
+
import { DatabaseKeyError, DatabaseNotOpenError, DatabaseOperationError } from "../../core/errors.js";
|
|
28
|
+
import { BaseDBer, MAX_KEY_BYTES } from "./dber.js";
|
|
29
|
+
const DEFAULT_DB_VERSION = "1.0.0";
|
|
30
|
+
const EMPTY = new Uint8Array(0);
|
|
31
|
+
/** Copy into a plain `Uint8Array`; `slice` on a Node `Buffer` would alias its source. */
|
|
32
|
+
function copyBytes(bytes) {
|
|
33
|
+
return new Uint8Array(bytes);
|
|
34
|
+
}
|
|
35
|
+
function assertWritableKey(key) {
|
|
36
|
+
if (key.length === 0 || key.length > MAX_KEY_BYTES) {
|
|
37
|
+
throw new DatabaseKeyError(`Key is empty, too big, or wrong size: ${key.length} bytes`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function assertDupValueSize(val) {
|
|
41
|
+
if (val.length === 0 || val.length > MAX_KEY_BYTES) {
|
|
42
|
+
throw new DatabaseKeyError(`Duplicate value is empty or larger than ${MAX_KEY_BYTES} bytes: ${val.length} bytes`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Point reads and deletes reject an empty key; an over-long key can only be absent. */
|
|
46
|
+
function isStorableKey(key) {
|
|
47
|
+
if (key.length === 0)
|
|
48
|
+
throw new DatabaseKeyError("Key is empty, too big, or wrong size: 0 bytes");
|
|
49
|
+
return key.length <= MAX_KEY_BYTES;
|
|
50
|
+
}
|
|
51
|
+
function isThenable(value) {
|
|
52
|
+
return (typeof value === "object" || typeof value === "function") && value !== null
|
|
53
|
+
&& typeof value.then === "function";
|
|
54
|
+
}
|
|
55
|
+
/** One named table. A plain table ignores values when ordering and identifying rows. */
|
|
56
|
+
class MemTable {
|
|
57
|
+
constructor(name, dupsort, rows = []) {
|
|
58
|
+
Object.defineProperty(this, "name", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: name
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(this, "dupsort", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: dupsort
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(this, "rows", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: rows
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** Binary search for the first row satisfying a predicate monotone in sort order. */
|
|
78
|
+
seek(isPast) {
|
|
79
|
+
let low = 0;
|
|
80
|
+
let high = this.rows.length;
|
|
81
|
+
while (low < high) {
|
|
82
|
+
const mid = (low + high) >>> 1;
|
|
83
|
+
if (isPast(this.rows[mid])) {
|
|
84
|
+
high = mid;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
low = mid + 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return low;
|
|
91
|
+
}
|
|
92
|
+
compare(row, key, value) {
|
|
93
|
+
const order = compareBytes(row.key, key);
|
|
94
|
+
return order !== 0 || !this.dupsort || value === undefined ? order : compareBytes(row.value, value);
|
|
95
|
+
}
|
|
96
|
+
/** First row not below `(key, value)`; without a value, the key's first duplicate. */
|
|
97
|
+
lowerBound(key, value) {
|
|
98
|
+
return this.seek((row) => this.compare(row, key, value) >= 0);
|
|
99
|
+
}
|
|
100
|
+
/** First row above `(key, value)`; without a value, the row past every duplicate of the key. */
|
|
101
|
+
upperBound(key, value) {
|
|
102
|
+
return this.seek((row) => this.compare(row, key, value) > 0);
|
|
103
|
+
}
|
|
104
|
+
/** True when `index` holds exactly `(key, value)`, or `key` when no value is given. */
|
|
105
|
+
matches(index, key, value) {
|
|
106
|
+
return index < this.rows.length && this.compare(this.rows[index], key, value) === 0;
|
|
107
|
+
}
|
|
108
|
+
/** The `[low, high)` row range whose keys begin with `top`. */
|
|
109
|
+
branch(top) {
|
|
110
|
+
return [
|
|
111
|
+
this.lowerBound(top),
|
|
112
|
+
this.seek((row) => compareBytes(row.key, top) > 0 && !startsWith(row.key, top)),
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Sorted in-memory store with real commit and rollback.
|
|
118
|
+
*
|
|
119
|
+
* Contents belong to the instance. They survive `close` and `reopen` until
|
|
120
|
+
* `close(true)` or `reopen({ clear: true })`, including on a `temp` store,
|
|
121
|
+
* which is what `LMDBer` does with its reused temp path. Each reopen rebinds
|
|
122
|
+
* table handles, so a handle from before it is refused.
|
|
123
|
+
*
|
|
124
|
+
* Scans hold a position, not an index: each step re-seeks past the last row
|
|
125
|
+
* yielded, so a concurrent insert, delete or rollback cannot skip or repeat an
|
|
126
|
+
* untouched row. A scan inside a writer sees that writer's rows as they change.
|
|
127
|
+
*/
|
|
128
|
+
export class MemStore extends BaseDBer {
|
|
129
|
+
constructor(options = {}) {
|
|
130
|
+
super();
|
|
131
|
+
_MemStore_instances.add(this);
|
|
132
|
+
_MemStore_name.set(this, void 0);
|
|
133
|
+
_MemStore_base.set(this, void 0);
|
|
134
|
+
_MemStore_temp.set(this, void 0);
|
|
135
|
+
_MemStore_opened.set(this, false);
|
|
136
|
+
/** True once a writable open has created the contents, like LMDB's data file. */
|
|
137
|
+
_MemStore_created.set(this, false);
|
|
138
|
+
_MemStore_tables.set(this, new Map());
|
|
139
|
+
_MemStore_version.set(this, null);
|
|
140
|
+
_MemStore_writeVersion.set(this, 0);
|
|
141
|
+
/** One log for every transaction depth; a savepoint is just an index into it. */
|
|
142
|
+
_MemStore_undo.set(this, []);
|
|
143
|
+
_MemStore_depth.set(this, 0);
|
|
144
|
+
Object.defineProperty(this, "readonly", {
|
|
145
|
+
enumerable: true,
|
|
146
|
+
configurable: true,
|
|
147
|
+
writable: true,
|
|
148
|
+
value: void 0
|
|
149
|
+
});
|
|
150
|
+
__classPrivateFieldSet(this, _MemStore_name, options.name || "main", "f");
|
|
151
|
+
__classPrivateFieldSet(this, _MemStore_base, options.base || "", "f");
|
|
152
|
+
__classPrivateFieldSet(this, _MemStore_temp, options.temp ?? false, "f");
|
|
153
|
+
this.readonly = options.readonly ?? false;
|
|
154
|
+
}
|
|
155
|
+
get name() {
|
|
156
|
+
return __classPrivateFieldGet(this, _MemStore_name, "f");
|
|
157
|
+
}
|
|
158
|
+
get base() {
|
|
159
|
+
return __classPrivateFieldGet(this, _MemStore_base, "f");
|
|
160
|
+
}
|
|
161
|
+
get opened() {
|
|
162
|
+
return __classPrivateFieldGet(this, _MemStore_opened, "f");
|
|
163
|
+
}
|
|
164
|
+
get temp() {
|
|
165
|
+
return __classPrivateFieldGet(this, _MemStore_temp, "f");
|
|
166
|
+
}
|
|
167
|
+
get inWriteTransaction() {
|
|
168
|
+
this.assertOpen();
|
|
169
|
+
return __classPrivateFieldGet(this, _MemStore_depth, "f") > 0;
|
|
170
|
+
}
|
|
171
|
+
/** Counts commits that wrote rows; it keeps counting across reopen of one instance. */
|
|
172
|
+
get writeVersion() {
|
|
173
|
+
this.assertOpen();
|
|
174
|
+
return __classPrivateFieldGet(this, _MemStore_writeVersion, "f");
|
|
175
|
+
}
|
|
176
|
+
/** Open or reopen the contents. A readonly open of never-created contents reports `false`. */
|
|
177
|
+
*reopen(options = {}) {
|
|
178
|
+
this.readonly = options.readonly ?? this.readonly;
|
|
179
|
+
__classPrivateFieldSet(this, _MemStore_temp, options.temp ?? __classPrivateFieldGet(this, _MemStore_temp, "f"), "f");
|
|
180
|
+
if (options.clear) {
|
|
181
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_discard).call(this);
|
|
182
|
+
}
|
|
183
|
+
__classPrivateFieldSet(this, _MemStore_opened, false, "f");
|
|
184
|
+
if (this.readonly && !__classPrivateFieldGet(this, _MemStore_created, "f"))
|
|
185
|
+
return false;
|
|
186
|
+
const existed = __classPrivateFieldGet(this, _MemStore_created, "f");
|
|
187
|
+
__classPrivateFieldSet(this, _MemStore_tables, new Map([...__classPrivateFieldGet(this, _MemStore_tables, "f")].map(([name, table]) => [name, new MemTable(name, table.dupsort, table.rows)])), "f");
|
|
188
|
+
__classPrivateFieldSet(this, _MemStore_created, true, "f");
|
|
189
|
+
__classPrivateFieldSet(this, _MemStore_opened, true, "f");
|
|
190
|
+
if (!this.readonly && (!existed || __classPrivateFieldGet(this, _MemStore_temp, "f"))) {
|
|
191
|
+
this.setVer(DEFAULT_DB_VERSION);
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
/** Close the store, deleting its contents when `clear` is set. Repeating is harmless. */
|
|
196
|
+
*close(clear = false) {
|
|
197
|
+
if (clear) {
|
|
198
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_discard).call(this);
|
|
199
|
+
}
|
|
200
|
+
__classPrivateFieldSet(this, _MemStore_opened, false, "f");
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Bind a table, creating it on a writable store. The flag from creation wins
|
|
205
|
+
* over a later differing request. An absent table on a readonly store yields
|
|
206
|
+
* no handle, as `LMDBer` does, so optional bindings can probe `hasTable`.
|
|
207
|
+
*/
|
|
208
|
+
openTable(name, options = {}) {
|
|
209
|
+
this.assertOpen();
|
|
210
|
+
if (!name)
|
|
211
|
+
throw new DatabaseKeyError("Table name must not be empty");
|
|
212
|
+
const existing = __classPrivateFieldGet(this, _MemStore_tables, "f").get(name);
|
|
213
|
+
if (existing)
|
|
214
|
+
return existing;
|
|
215
|
+
if (this.readonly)
|
|
216
|
+
return undefined;
|
|
217
|
+
const table = new MemTable(name, options.dupsort ?? false);
|
|
218
|
+
__classPrivateFieldGet(this, _MemStore_tables, "f").set(name, table);
|
|
219
|
+
if (__classPrivateFieldGet(this, _MemStore_depth, "f") > 0) {
|
|
220
|
+
__classPrivateFieldGet(this, _MemStore_undo, "f").push({ revert: () => __classPrivateFieldGet(this, _MemStore_tables, "f").delete(name) });
|
|
221
|
+
}
|
|
222
|
+
return table;
|
|
223
|
+
}
|
|
224
|
+
hasTable(name) {
|
|
225
|
+
this.assertOpen();
|
|
226
|
+
if (!name)
|
|
227
|
+
throw new DatabaseKeyError("Table name must not be empty");
|
|
228
|
+
return __classPrivateFieldGet(this, _MemStore_tables, "f").has(name);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Run `fn` atomically. Only the outermost commit publishes; a nested
|
|
232
|
+
* transaction is a savepoint, and any throw restores the state at its start.
|
|
233
|
+
* A thenable result is a caller-contract error, rolled back like a throw.
|
|
234
|
+
*/
|
|
235
|
+
transaction(fn) {
|
|
236
|
+
this.assertOpen();
|
|
237
|
+
if (this.readonly)
|
|
238
|
+
throw new DatabaseOperationError(`Store "${__classPrivateFieldGet(this, _MemStore_name, "f")}" is read-only`);
|
|
239
|
+
const savepoint = __classPrivateFieldGet(this, _MemStore_undo, "f").length;
|
|
240
|
+
__classPrivateFieldSet(this, _MemStore_depth, __classPrivateFieldGet(this, _MemStore_depth, "f") + 1, "f");
|
|
241
|
+
try {
|
|
242
|
+
const result = fn();
|
|
243
|
+
if (isThenable(result))
|
|
244
|
+
throw new DatabaseOperationError("Transaction callback must be synchronous");
|
|
245
|
+
if (__classPrivateFieldGet(this, _MemStore_depth, "f") === 1) {
|
|
246
|
+
const changes = __classPrivateFieldGet(this, _MemStore_undo, "f").flatMap((entry) => entry.change ? [entry.change] : []);
|
|
247
|
+
if (changes.length > 0) {
|
|
248
|
+
__classPrivateFieldSet(this, _MemStore_writeVersion, __classPrivateFieldGet(this, _MemStore_writeVersion, "f") + 1, "f");
|
|
249
|
+
this.committed(changes);
|
|
250
|
+
}
|
|
251
|
+
__classPrivateFieldGet(this, _MemStore_undo, "f").length = 0;
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
while (__classPrivateFieldGet(this, _MemStore_undo, "f").length > savepoint) {
|
|
257
|
+
__classPrivateFieldGet(this, _MemStore_undo, "f").pop().revert();
|
|
258
|
+
}
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
__classPrivateFieldSet(this, _MemStore_depth, __classPrivateFieldGet(this, _MemStore_depth, "f") - 1, "f");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/** Told each outermost commit that wrote rows, in order. Nothing rolled back ever reaches it. */
|
|
266
|
+
committed(_changes) { }
|
|
267
|
+
/**
|
|
268
|
+
* Replace the contents with a persisted snapshot, for a backend that loads
|
|
269
|
+
* before `reopen`. Rows are copied and sorted here, so a backend's own order
|
|
270
|
+
* cannot break the sorted-row invariant; a repeated row identity is corrupt.
|
|
271
|
+
*/
|
|
272
|
+
loadContents(tables, version) {
|
|
273
|
+
__classPrivateFieldSet(this, _MemStore_tables, new Map(tables.map(({ name, dupsort, rows }) => {
|
|
274
|
+
const table = new MemTable(name, dupsort, rows.map((row) => ({ key: copyBytes(row.key), value: copyBytes(row.value) })));
|
|
275
|
+
const order = (a, c) => compareBytes(a.key, c.key) || (dupsort ? compareBytes(a.value, c.value) : 0);
|
|
276
|
+
table.rows.sort(order);
|
|
277
|
+
if (table.rows.some((row, index) => index > 0 && order(table.rows[index - 1], row) === 0)) {
|
|
278
|
+
throw new DatabaseOperationError(`Persisted table "${name}" repeats a row`);
|
|
279
|
+
}
|
|
280
|
+
return [name, table];
|
|
281
|
+
})), "f");
|
|
282
|
+
__classPrivateFieldSet(this, _MemStore_version, version, "f");
|
|
283
|
+
__classPrivateFieldSet(this, _MemStore_created, version !== null || tables.length > 0, "f");
|
|
284
|
+
}
|
|
285
|
+
*flushed() {
|
|
286
|
+
this.assertOpen();
|
|
287
|
+
}
|
|
288
|
+
/** This backend retains no read view, so an open store has nothing to discard. */
|
|
289
|
+
refreshRead() {
|
|
290
|
+
this.assertOpen();
|
|
291
|
+
}
|
|
292
|
+
getVer() {
|
|
293
|
+
this.assertOpen();
|
|
294
|
+
return __classPrivateFieldGet(this, _MemStore_version, "f") || null;
|
|
295
|
+
}
|
|
296
|
+
setVer(val) {
|
|
297
|
+
this.transaction(() => {
|
|
298
|
+
const prior = __classPrivateFieldGet(this, _MemStore_version, "f");
|
|
299
|
+
__classPrivateFieldSet(this, _MemStore_version, t(b(val)), "f");
|
|
300
|
+
__classPrivateFieldGet(this, _MemStore_undo, "f").push({
|
|
301
|
+
change: { kind: "version", before: prior, after: __classPrivateFieldGet(this, _MemStore_version, "f") },
|
|
302
|
+
revert: () => __classPrivateFieldSet(this, _MemStore_version, prior, "f"),
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
*scan(table, options = {}) {
|
|
307
|
+
for (const row of __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_walk).call(this, table, options, false)) {
|
|
308
|
+
yield { key: copyBytes(row.key), value: copyBytes(row.value) };
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
*scanKeys(table, options = {}) {
|
|
312
|
+
for (const row of __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_walk).call(this, table, options, true)) {
|
|
313
|
+
yield copyBytes(row.key);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
assertOpen() {
|
|
317
|
+
if (!__classPrivateFieldGet(this, _MemStore_opened, "f"))
|
|
318
|
+
throw new DatabaseNotOpenError(`Store "${__classPrivateFieldGet(this, _MemStore_name, "f")}" is not open`);
|
|
319
|
+
}
|
|
320
|
+
putRow(table, key, val) {
|
|
321
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
322
|
+
this.transaction(() => __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_insert).call(this, mem, key, val));
|
|
323
|
+
}
|
|
324
|
+
/** On a dupsort table `val` selects one duplicate; a plain table ignores it, as LMDB does. */
|
|
325
|
+
removeRow(table, key, val) {
|
|
326
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
327
|
+
return this.transaction(() => {
|
|
328
|
+
if (!isStorableKey(key))
|
|
329
|
+
return false;
|
|
330
|
+
if (val === undefined || !mem.dupsort)
|
|
331
|
+
return __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_removeRange).call(this, mem, mem.lowerBound(key), mem.upperBound(key));
|
|
332
|
+
if (val.length === 0)
|
|
333
|
+
return false; // an empty duplicate can never be stored
|
|
334
|
+
assertDupValueSize(val);
|
|
335
|
+
const index = mem.lowerBound(key, val);
|
|
336
|
+
if (!mem.matches(index, key, val))
|
|
337
|
+
return false;
|
|
338
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_removeAt).call(this, mem, index);
|
|
339
|
+
return true;
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/** Insert only when `key` is absent; on a dupsort table any existing duplicate counts. */
|
|
343
|
+
putVal(table, key, val) {
|
|
344
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
345
|
+
return this.transaction(() => {
|
|
346
|
+
assertWritableKey(key);
|
|
347
|
+
if (mem.matches(mem.lowerBound(key), key))
|
|
348
|
+
return false;
|
|
349
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_insert).call(this, mem, key, val);
|
|
350
|
+
return true;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/** Overwrite a plain key's value; on a dupsort table this adds a duplicate. */
|
|
354
|
+
setVal(table, key, val) {
|
|
355
|
+
this.putRow(table, key, val);
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
getVal(table, key) {
|
|
359
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
360
|
+
if (!isStorableKey(key))
|
|
361
|
+
return null;
|
|
362
|
+
const index = mem.lowerBound(key);
|
|
363
|
+
return mem.matches(index, key) ? copyBytes(mem.rows[index].value) : null;
|
|
364
|
+
}
|
|
365
|
+
delVal(table, key, val) {
|
|
366
|
+
return this.removeRow(table, key, val);
|
|
367
|
+
}
|
|
368
|
+
cnt(table) {
|
|
369
|
+
return __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table).rows.length;
|
|
370
|
+
}
|
|
371
|
+
cntAll(table) {
|
|
372
|
+
return this.cnt(table);
|
|
373
|
+
}
|
|
374
|
+
cntTop(table, top = EMPTY) {
|
|
375
|
+
const [low, high] = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table).branch(top);
|
|
376
|
+
return high - low;
|
|
377
|
+
}
|
|
378
|
+
delTop(table, top = EMPTY) {
|
|
379
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
380
|
+
const [low, high] = mem.branch(top);
|
|
381
|
+
return high > low && this.transaction(() => __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_removeRange).call(this, mem, low, high));
|
|
382
|
+
}
|
|
383
|
+
*getTopItemIter(table, top = EMPTY) {
|
|
384
|
+
for (const row of __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_walk).call(this, table, { start: top }, false)) {
|
|
385
|
+
if (!startsWith(row.key, top))
|
|
386
|
+
return;
|
|
387
|
+
yield [copyBytes(row.key), copyBytes(row.value)];
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/** Add each value not already present; reports `false` if any supplied value existed. */
|
|
391
|
+
putVals(table, key, vals) {
|
|
392
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
393
|
+
const existing = new Set(this.getVals(table, key).map((val) => bytesHex(val)));
|
|
394
|
+
let result = true;
|
|
395
|
+
this.transaction(() => {
|
|
396
|
+
for (const val of vals) {
|
|
397
|
+
const hex = bytesHex(val);
|
|
398
|
+
if (existing.has(hex)) {
|
|
399
|
+
result = false;
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_insert).call(this, mem, key, val);
|
|
403
|
+
existing.add(hex);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
return result;
|
|
407
|
+
}
|
|
408
|
+
addVal(table, key, val) {
|
|
409
|
+
return this.putVals(table, key, [val]);
|
|
410
|
+
}
|
|
411
|
+
/** Duplicate reads treat an empty or over-long key as simply absent, as `LMDBer` does. */
|
|
412
|
+
getVals(table, key) {
|
|
413
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
414
|
+
if (key.length === 0 || key.length > MAX_KEY_BYTES)
|
|
415
|
+
return [];
|
|
416
|
+
return mem.rows.slice(mem.lowerBound(key), mem.upperBound(key)).map((row) => copyBytes(row.value));
|
|
417
|
+
}
|
|
418
|
+
getValLast(table, key) {
|
|
419
|
+
return this.getVals(table, key).at(-1) ?? null;
|
|
420
|
+
}
|
|
421
|
+
*getValsIter(table, key) {
|
|
422
|
+
yield* this.getVals(table, key);
|
|
423
|
+
}
|
|
424
|
+
/** Count duplicates. Like LMDB, a plain table holding `key` refuses this dupsort-only call. */
|
|
425
|
+
cntVals(table, key) {
|
|
426
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
427
|
+
if (key.length === 0 || key.length > MAX_KEY_BYTES)
|
|
428
|
+
return 0;
|
|
429
|
+
const count = mem.upperBound(key) - mem.lowerBound(key);
|
|
430
|
+
if (count > 0 && !mem.dupsort)
|
|
431
|
+
throw new DatabaseOperationError("Duplicate count requires a dupsort table");
|
|
432
|
+
return count;
|
|
433
|
+
}
|
|
434
|
+
delVals(table, key) {
|
|
435
|
+
return this.removeRow(table, key);
|
|
436
|
+
}
|
|
437
|
+
/** First duplicate at `key` not below `start`; `start` is an unvalidated scan-style bound. */
|
|
438
|
+
seekVal(table, key, start) {
|
|
439
|
+
const mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
440
|
+
if (key.length === 0 || key.length > MAX_KEY_BYTES)
|
|
441
|
+
return null;
|
|
442
|
+
const bound = start?.length ? start : undefined;
|
|
443
|
+
const index = mem.lowerBound(key, bound);
|
|
444
|
+
if (!mem.matches(index, key))
|
|
445
|
+
return null;
|
|
446
|
+
if (bound !== undefined && !mem.dupsort) {
|
|
447
|
+
throw new DatabaseOperationError("Duplicate seek requires a dupsort table");
|
|
448
|
+
}
|
|
449
|
+
return copyBytes(mem.rows[index].value);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
_MemStore_name = new WeakMap(), _MemStore_base = new WeakMap(), _MemStore_temp = new WeakMap(), _MemStore_opened = new WeakMap(), _MemStore_created = new WeakMap(), _MemStore_tables = new WeakMap(), _MemStore_version = new WeakMap(), _MemStore_writeVersion = new WeakMap(), _MemStore_undo = new WeakMap(), _MemStore_depth = new WeakMap(), _MemStore_instances = new WeakSet(), _MemStore_discard = function _MemStore_discard() {
|
|
453
|
+
__classPrivateFieldSet(this, _MemStore_tables, new Map(), "f");
|
|
454
|
+
__classPrivateFieldSet(this, _MemStore_version, null, "f");
|
|
455
|
+
__classPrivateFieldSet(this, _MemStore_created, false, "f");
|
|
456
|
+
}, _MemStore_walk = function
|
|
457
|
+
/**
|
|
458
|
+
* Walk rows in order, re-seeking from the last row after every yield so the
|
|
459
|
+
* table may change between steps. Empty bounds count as absent and a bound
|
|
460
|
+
* applies to the whole key, including all of its duplicates.
|
|
461
|
+
*/
|
|
462
|
+
* _MemStore_walk(table, options, distinct) {
|
|
463
|
+
const reverse = options.reverse ?? false;
|
|
464
|
+
const start = options.start?.length ? options.start : undefined;
|
|
465
|
+
const end = options.end?.length ? options.end : undefined;
|
|
466
|
+
let mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
467
|
+
let index;
|
|
468
|
+
if (start === undefined) {
|
|
469
|
+
index = reverse ? mem.rows.length - 1 : 0;
|
|
470
|
+
}
|
|
471
|
+
else if (reverse) {
|
|
472
|
+
index = (options.exclusiveStart ? mem.lowerBound(start) : mem.upperBound(start)) - 1;
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
index = options.exclusiveStart ? mem.upperBound(start) : mem.lowerBound(start);
|
|
476
|
+
}
|
|
477
|
+
for (let count = 0; options.limit === undefined || count < options.limit; count++) {
|
|
478
|
+
const row = mem.rows[index];
|
|
479
|
+
if (row === undefined)
|
|
480
|
+
return;
|
|
481
|
+
if (end !== undefined && (reverse ? compareBytes(row.key, end) <= 0 : compareBytes(row.key, end) >= 0))
|
|
482
|
+
return;
|
|
483
|
+
yield row;
|
|
484
|
+
mem = __classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_resolve).call(this, table);
|
|
485
|
+
const value = distinct ? undefined : row.value;
|
|
486
|
+
index = reverse ? mem.lowerBound(row.key, value) - 1 : mem.upperBound(row.key, value);
|
|
487
|
+
}
|
|
488
|
+
}, _MemStore_resolve = function _MemStore_resolve(table) {
|
|
489
|
+
this.assertOpen();
|
|
490
|
+
const mem = table;
|
|
491
|
+
if (!mem || __classPrivateFieldGet(this, _MemStore_tables, "f").get(mem.name) !== mem) {
|
|
492
|
+
throw new DatabaseOperationError("Table handle is not valid for this open store");
|
|
493
|
+
}
|
|
494
|
+
return mem;
|
|
495
|
+
}, _MemStore_logRow = function _MemStore_logRow(mem, before, after, revert) {
|
|
496
|
+
const key = (before ?? after).key;
|
|
497
|
+
const [was, now] = [before?.value ?? null, after?.value ?? null];
|
|
498
|
+
__classPrivateFieldGet(this, _MemStore_undo, "f").push({
|
|
499
|
+
change: { kind: "row", table: mem.name, dupsort: mem.dupsort, key, before: was, after: now },
|
|
500
|
+
revert,
|
|
501
|
+
});
|
|
502
|
+
}, _MemStore_insert = function _MemStore_insert(mem, key, val) {
|
|
503
|
+
assertWritableKey(key);
|
|
504
|
+
if (mem.dupsort) {
|
|
505
|
+
assertDupValueSize(val);
|
|
506
|
+
}
|
|
507
|
+
const index = mem.lowerBound(key, val);
|
|
508
|
+
const row = { key: copyBytes(key), value: copyBytes(val) };
|
|
509
|
+
if (!mem.matches(index, key, val)) {
|
|
510
|
+
mem.rows.splice(index, 0, row);
|
|
511
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_logRow).call(this, mem, null, row, () => mem.rows.splice(index, 1));
|
|
512
|
+
}
|
|
513
|
+
else if (!mem.dupsort) {
|
|
514
|
+
const prior = mem.rows[index];
|
|
515
|
+
mem.rows[index] = row;
|
|
516
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_logRow).call(this, mem, prior, row, () => mem.rows[index] = prior);
|
|
517
|
+
}
|
|
518
|
+
}, _MemStore_removeAt = function _MemStore_removeAt(mem, index) {
|
|
519
|
+
const [row] = mem.rows.splice(index, 1);
|
|
520
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_logRow).call(this, mem, row, null, () => mem.rows.splice(index, 0, row));
|
|
521
|
+
}, _MemStore_removeRange = function _MemStore_removeRange(mem, low, high) {
|
|
522
|
+
for (let index = high - 1; index >= low; index--) {
|
|
523
|
+
__classPrivateFieldGet(this, _MemStore_instances, "m", _MemStore_removeAt).call(this, mem, index);
|
|
524
|
+
}
|
|
525
|
+
return high > low;
|
|
526
|
+
};
|
|
527
|
+
/** A `StoreOpener` of closed, independent in-memory stores. Place is meaningless here. */
|
|
528
|
+
export class MemStoreOpener {
|
|
529
|
+
create(_family, identity) {
|
|
530
|
+
return new MemStore(identity);
|
|
531
|
+
}
|
|
532
|
+
}
|