mindoodb 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -19
- package/dist/__mocks__/expo-standard-web-crypto.d.ts +10 -0
- package/dist/__mocks__/expo-standard-web-crypto.d.ts.map +1 -0
- package/dist/__mocks__/expo-standard-web-crypto.js +22 -0
- package/dist/__mocks__/expo-standard-web-crypto.js.map +1 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.d.ts +8 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.d.ts.map +1 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.js +16 -0
- package/dist/appendonlystores/BasicOnDiskContentAddressedStoreFactory.js.map +1 -0
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts +1 -1
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts.map +1 -1
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js +2 -2
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +11 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +94 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.d.ts +13 -2
- package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.js +86 -0
- package/dist/appendonlystores/network/HttpTransport.js.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +19 -2
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +96 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/index.d.ts +1 -1
- package/dist/appendonlystores/network/index.d.ts.map +1 -1
- package/dist/appendonlystores/network/index.js.map +1 -1
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts +61 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js +685 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.d.ts +25 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.d.ts.map +1 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.js +41 -0
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStoreFactory.js.map +1 -0
- package/dist/browser/index.d.ts +5 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +13 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/core/BaseMindooDB.d.ts +12 -0
- package/dist/core/BaseMindooDB.d.ts.map +1 -1
- package/dist/core/BaseMindooDB.js +210 -108
- package/dist/core/BaseMindooDB.js.map +1 -1
- package/dist/core/BaseMindooTenant.d.ts +40 -6
- package/dist/core/BaseMindooTenant.d.ts.map +1 -1
- package/dist/core/BaseMindooTenant.js +179 -21
- package/dist/core/BaseMindooTenant.js.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.js +10 -0
- package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
- package/dist/core/BaseMindooTenantFactory.d.ts +22 -28
- package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantFactory.js +161 -65
- package/dist/core/BaseMindooTenantFactory.js.map +1 -1
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.d.ts +68 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.d.ts.map +1 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.js +659 -0
- package/dist/core/appendonlystores/BasicOnDiskContentAddressedStore.js.map +1 -0
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts +43 -3
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts.map +1 -1
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js +162 -23
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js.map +1 -1
- package/dist/core/appendonlystores/bloom.d.ts +85 -0
- package/dist/core/appendonlystores/bloom.d.ts.map +1 -0
- package/dist/core/appendonlystores/bloom.js +228 -0
- package/dist/core/appendonlystores/bloom.js.map +1 -0
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts +22 -2
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.d.ts +10 -0
- package/dist/core/appendonlystores/network/types.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.js.map +1 -1
- package/dist/core/appendonlystores/types.d.ts +123 -0
- package/dist/core/appendonlystores/types.d.ts.map +1 -1
- package/dist/core/automerge-adapter.d.ts +15 -0
- package/dist/core/automerge-adapter.d.ts.map +1 -0
- package/dist/core/automerge-adapter.js +73 -0
- package/dist/core/automerge-adapter.js.map +1 -0
- package/dist/core/crypto/pbkdf2Iterations.d.ts +12 -0
- package/dist/core/crypto/pbkdf2Iterations.d.ts.map +1 -0
- package/dist/core/crypto/pbkdf2Iterations.js +55 -0
- package/dist/core/crypto/pbkdf2Iterations.js.map +1 -0
- package/dist/core/index.d.ts +7 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +30 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/keys/KeyBag.d.ts +32 -12
- package/dist/core/keys/KeyBag.d.ts.map +1 -1
- package/dist/core/keys/KeyBag.js +86 -26
- package/dist/core/keys/KeyBag.js.map +1 -1
- package/dist/core/keys/KeyContext.d.ts +4 -0
- package/dist/core/keys/KeyContext.d.ts.map +1 -0
- package/dist/core/keys/KeyContext.js +11 -0
- package/dist/core/keys/KeyContext.js.map +1 -0
- package/dist/core/types.d.ts +218 -50
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -1
- package/dist/core/uri/MindooURI.d.ts +58 -0
- package/dist/core/uri/MindooURI.d.ts.map +1 -0
- package/dist/core/uri/MindooURI.js +169 -0
- package/dist/core/uri/MindooURI.js.map +1 -0
- package/dist/core/userid/index.d.ts +0 -10
- package/dist/core/userid/index.d.ts.map +1 -1
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.d.ts +541 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.d.ts.map +1 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.js +1334 -0
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.js.map +1 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +5 -1
- package/dist/node/index.js.map +1 -1
- package/dist/reactnative/crypto/AESAdapter.d.ts +18 -0
- package/dist/reactnative/crypto/AESAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/AESAdapter.js +112 -0
- package/dist/reactnative/crypto/AESAdapter.js.map +1 -0
- package/dist/reactnative/crypto/Ed25519Adapter.d.ts +34 -0
- package/dist/reactnative/crypto/Ed25519Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/Ed25519Adapter.js +386 -0
- package/dist/reactnative/crypto/Ed25519Adapter.js.map +1 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.d.ts +23 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.js +51 -0
- package/dist/reactnative/crypto/ExpoGoCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/HMACAdapter.d.ts +13 -0
- package/dist/reactnative/crypto/HMACAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/HMACAdapter.js +50 -0
- package/dist/reactnative/crypto/HMACAdapter.js.map +1 -0
- package/dist/reactnative/crypto/KeyFormatConverter.d.ts +21 -0
- package/dist/reactnative/crypto/KeyFormatConverter.d.ts.map +1 -0
- package/dist/reactnative/crypto/KeyFormatConverter.js +72 -0
- package/dist/reactnative/crypto/KeyFormatConverter.js.map +1 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.d.ts +19 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.js +67 -0
- package/dist/reactnative/crypto/PBKDF2Adapter.js.map +1 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.d.ts +37 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.js +72 -0
- package/dist/reactnative/crypto/QuickCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/RSAAdapter.d.ts +38 -0
- package/dist/reactnative/crypto/RSAAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/RSAAdapter.js +184 -0
- package/dist/reactnative/crypto/RSAAdapter.js.map +1 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.d.ts +33 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.js +61 -0
- package/dist/reactnative/crypto/ReactNativeCryptoAdapter.js.map +1 -0
- package/dist/reactnative/crypto/SHA256Adapter.d.ts +9 -0
- package/dist/reactnative/crypto/SHA256Adapter.d.ts.map +1 -0
- package/dist/reactnative/crypto/SHA256Adapter.js +29 -0
- package/dist/reactnative/crypto/SHA256Adapter.js.map +1 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.d.ts +63 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.d.ts.map +1 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.js +350 -0
- package/dist/reactnative/crypto/SubtleCryptoPolyfill.js.map +1 -0
- package/dist/reactnative/index.d.ts +8 -0
- package/dist/reactnative/index.d.ts.map +1 -0
- package/dist/reactnative/index.js +38 -0
- package/dist/reactnative/index.js.map +1 -0
- package/package.json +51 -6
- package/patches/PATCHES.md +111 -0
- package/patches/react-native+0.76.9.patch +34 -0
- package/patches/react-native-quick-crypto+1.0.7.patch +42 -0
- package/scripts/cli.js +21 -0
- package/scripts/setup-react-native.js +228 -0
- package/templates/reactnative/App.js +252 -0
- package/templates/reactnative/app.json +29 -0
- package/templates/reactnative/babel.config.js +6 -0
- package/templates/reactnative/index.js +26 -0
- package/templates/reactnative/metro.config.snippet.js +39 -0
- package/templates/reactnative/mindoodb-polyfills.js +116 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bloom filter for compact set-membership summaries of store entry IDs.
|
|
4
|
+
*
|
|
5
|
+
* During network sync, a local store needs to determine which of its entry IDs
|
|
6
|
+
* are missing from a remote store. Naively this requires sending every local ID
|
|
7
|
+
* to the remote for an exact `hasEntries` check — an O(n) network round-trip
|
|
8
|
+
* that dominates sync latency for large stores.
|
|
9
|
+
*
|
|
10
|
+
* A bloom filter provides a probabilistic shortcut: the remote store serializes
|
|
11
|
+
* its full ID set into a compact bitset ({@link StoreIdBloomSummary}) and sends
|
|
12
|
+
* it to the local side in a single response. The local side then tests each of
|
|
13
|
+
* its own IDs against the bloom filter:
|
|
14
|
+
*
|
|
15
|
+
* - **Definite negative** — the ID is certainly absent on the remote; no
|
|
16
|
+
* round-trip needed, the entry can be pushed immediately.
|
|
17
|
+
* - **Probable positive** — the ID *might* exist on the remote (subject to a
|
|
18
|
+
* configurable false-positive rate, default 1 %). Only these IDs require a
|
|
19
|
+
* follow-up `hasEntries` call to confirm.
|
|
20
|
+
*
|
|
21
|
+
* This is used by {@link BasicOnDiskContentAddressedStore.getIdBloomSummary} and
|
|
22
|
+
* consumed by the sync loop in `BaseMindooDB` to partition IDs into
|
|
23
|
+
* "definitely missing" and "maybe existing" buckets before making any network
|
|
24
|
+
* calls.
|
|
25
|
+
*
|
|
26
|
+
* ### Implementation details
|
|
27
|
+
*
|
|
28
|
+
* - Uses **enhanced double hashing** (FNV-1a + DJB2) to derive `k` bit
|
|
29
|
+
* positions from a single ID string, avoiding the need for `k` independent
|
|
30
|
+
* hash functions.
|
|
31
|
+
* - Bit-array size and hash count are computed from the classic bloom filter
|
|
32
|
+
* formulas to satisfy the requested false-positive rate.
|
|
33
|
+
* - The filter is versioned (`"bloom-v1"`) so future changes to hashing or
|
|
34
|
+
* encoding remain backward-compatible.
|
|
35
|
+
*
|
|
36
|
+
* @module bloom
|
|
37
|
+
*/
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.createIdBloomSummary = createIdBloomSummary;
|
|
40
|
+
exports.bloomMightContainId = bloomMightContainId;
|
|
41
|
+
/** Cross-platform Uint8Array -> base64 string. */
|
|
42
|
+
function uint8ArrayToBase64(bytes) {
|
|
43
|
+
let binary = "";
|
|
44
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
45
|
+
binary += String.fromCharCode(bytes[i]);
|
|
46
|
+
}
|
|
47
|
+
return btoa(binary);
|
|
48
|
+
}
|
|
49
|
+
/** Cross-platform base64 string -> Uint8Array. */
|
|
50
|
+
function base64ToUint8Array(base64) {
|
|
51
|
+
const binary = atob(base64);
|
|
52
|
+
const bytes = new Uint8Array(binary.length);
|
|
53
|
+
for (let i = 0; i < binary.length; i++) {
|
|
54
|
+
bytes[i] = binary.charCodeAt(i);
|
|
55
|
+
}
|
|
56
|
+
return bytes;
|
|
57
|
+
}
|
|
58
|
+
/** Default probability of a false positive (1 %). */
|
|
59
|
+
const DEFAULT_FALSE_POSITIVE_RATE = 0.01;
|
|
60
|
+
/** Salt mixed into every hash to namespace this bloom filter version. */
|
|
61
|
+
const DEFAULT_SALT = "mindoodb-bloom-v1";
|
|
62
|
+
/**
|
|
63
|
+
* FNV-1a 32-bit hash.
|
|
64
|
+
*
|
|
65
|
+
* Used as the first of two independent hash bases for enhanced double hashing.
|
|
66
|
+
* FNV-1a is fast, has good avalanche properties, and is simple to implement
|
|
67
|
+
* without external dependencies.
|
|
68
|
+
*/
|
|
69
|
+
function fnv1a32(input) {
|
|
70
|
+
let hash = 0x811c9dc5;
|
|
71
|
+
for (let i = 0; i < input.length; i++) {
|
|
72
|
+
hash ^= input.charCodeAt(i);
|
|
73
|
+
hash = Math.imul(hash, 0x01000193);
|
|
74
|
+
}
|
|
75
|
+
return hash >>> 0;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* DJB2 32-bit hash (Daniel J. Bernstein).
|
|
79
|
+
*
|
|
80
|
+
* Used as the second hash base. Chosen for its simplicity and because it is
|
|
81
|
+
* sufficiently independent from FNV-1a to give good bit dispersion when
|
|
82
|
+
* combined via enhanced double hashing: h(i) = h1 + i * h2.
|
|
83
|
+
*/
|
|
84
|
+
function djb2_32(input) {
|
|
85
|
+
let hash = 5381;
|
|
86
|
+
for (let i = 0; i < input.length; i++) {
|
|
87
|
+
hash = ((hash << 5) + hash + input.charCodeAt(i)) >>> 0;
|
|
88
|
+
}
|
|
89
|
+
return hash >>> 0;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Compute the optimal bit-array size and number of hash functions for a bloom
|
|
93
|
+
* filter given the expected item count and desired false-positive rate.
|
|
94
|
+
*
|
|
95
|
+
* Uses the standard formulas:
|
|
96
|
+
* m = -(n * ln(p)) / (ln2)^2 (bit count)
|
|
97
|
+
* k = (m / n) * ln2 (hash count)
|
|
98
|
+
*
|
|
99
|
+
* A minimum of 64 bits and 1 hash is enforced so the filter remains valid
|
|
100
|
+
* even for very small or empty sets.
|
|
101
|
+
*
|
|
102
|
+
* @param itemCount Expected number of distinct IDs.
|
|
103
|
+
* @param falsePositiveRate Target false-positive probability (0 < p < 1).
|
|
104
|
+
* @returns Optimal `bitCount` and `hashCount`.
|
|
105
|
+
*/
|
|
106
|
+
function computeBloomShape(itemCount, falsePositiveRate) {
|
|
107
|
+
if (itemCount <= 0) {
|
|
108
|
+
return { bitCount: 64, hashCount: 2 };
|
|
109
|
+
}
|
|
110
|
+
const ln2 = Math.log(2);
|
|
111
|
+
const bitCount = Math.max(64, Math.ceil((-itemCount * Math.log(falsePositiveRate)) / (ln2 * ln2)));
|
|
112
|
+
const hashCount = Math.max(1, Math.round((bitCount / itemCount) * ln2));
|
|
113
|
+
return { bitCount, hashCount };
|
|
114
|
+
}
|
|
115
|
+
/** Set a single bit in a byte-packed bitset. */
|
|
116
|
+
function setBit(bitset, bitIndex) {
|
|
117
|
+
const byteIndex = Math.floor(bitIndex / 8);
|
|
118
|
+
const bitOffset = bitIndex % 8;
|
|
119
|
+
bitset[byteIndex] |= 1 << bitOffset;
|
|
120
|
+
}
|
|
121
|
+
/** Test whether a single bit is set in a byte-packed bitset. */
|
|
122
|
+
function getBit(bitset, bitIndex) {
|
|
123
|
+
const byteIndex = Math.floor(bitIndex / 8);
|
|
124
|
+
const bitOffset = bitIndex % 8;
|
|
125
|
+
return (bitset[byteIndex] & (1 << bitOffset)) !== 0;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Derive `hashCount` bit-positions for an ID using enhanced double hashing.
|
|
129
|
+
*
|
|
130
|
+
* Enhanced double hashing computes k positions as:
|
|
131
|
+
* index_i = (h1 + i * h2) mod bitCount
|
|
132
|
+
*
|
|
133
|
+
* where h1 = FNV-1a(salt + id) and h2 = DJB2(id + salt). The salt is
|
|
134
|
+
* prepended/appended in opposite order to reduce correlation between the two
|
|
135
|
+
* hash values.
|
|
136
|
+
*
|
|
137
|
+
* @param id The entry ID to hash.
|
|
138
|
+
* @param bitCount Total bits in the bloom filter.
|
|
139
|
+
* @param hashCount Number of bit positions to produce.
|
|
140
|
+
* @param salt Version-specific salt string.
|
|
141
|
+
* @returns Array of `hashCount` bit-positions in [0, bitCount).
|
|
142
|
+
*/
|
|
143
|
+
function bloomIndexes(id, bitCount, hashCount, salt) {
|
|
144
|
+
const h1 = fnv1a32(`${salt}:${id}`);
|
|
145
|
+
const h2 = djb2_32(`${id}:${salt}`) || 1;
|
|
146
|
+
const indexes = [];
|
|
147
|
+
for (let i = 0; i < hashCount; i++) {
|
|
148
|
+
indexes.push((h1 + i * h2) % bitCount);
|
|
149
|
+
}
|
|
150
|
+
return indexes;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Build a bloom filter summary from a list of entry IDs.
|
|
154
|
+
*
|
|
155
|
+
* The resulting {@link StoreIdBloomSummary} is a compact, serializable
|
|
156
|
+
* representation that can be transferred over the network (e.g. in sync
|
|
157
|
+
* protocol responses) and later queried with {@link bloomMightContainId}.
|
|
158
|
+
*
|
|
159
|
+
* Typical usage in the on-disk store:
|
|
160
|
+
* ```ts
|
|
161
|
+
* const ids = await store.getAllIds();
|
|
162
|
+
* const summary = createIdBloomSummary(ids);
|
|
163
|
+
* // send summary to the syncing peer
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @param ids Array of entry ID strings to include in the filter.
|
|
167
|
+
* @param falsePositiveRate Target false-positive probability (default 1 %).
|
|
168
|
+
* @returns A serializable bloom filter summary (base64-encoded bitset).
|
|
169
|
+
*/
|
|
170
|
+
function createIdBloomSummary(ids, falsePositiveRate = DEFAULT_FALSE_POSITIVE_RATE) {
|
|
171
|
+
const { bitCount, hashCount } = computeBloomShape(ids.length, falsePositiveRate);
|
|
172
|
+
const bitset = new Uint8Array(Math.ceil(bitCount / 8));
|
|
173
|
+
for (const id of ids) {
|
|
174
|
+
const indexes = bloomIndexes(id, bitCount, hashCount, DEFAULT_SALT);
|
|
175
|
+
for (const idx of indexes) {
|
|
176
|
+
setBit(bitset, idx);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
version: "bloom-v1",
|
|
181
|
+
totalIds: ids.length,
|
|
182
|
+
bitCount,
|
|
183
|
+
hashCount,
|
|
184
|
+
salt: DEFAULT_SALT,
|
|
185
|
+
bitsetBase64: uint8ArrayToBase64(bitset),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Test whether an entry ID *might* be present in a bloom filter summary.
|
|
190
|
+
*
|
|
191
|
+
* - Returns `false` only when the ID is **definitely absent** — at least one
|
|
192
|
+
* of its bit-positions is unset, so the ID was never inserted.
|
|
193
|
+
* - Returns `true` when the ID **might be present** — all bit-positions are
|
|
194
|
+
* set, but this could be a false positive (probability ≤ the configured
|
|
195
|
+
* false-positive rate).
|
|
196
|
+
*
|
|
197
|
+
* If the summary version is unrecognized, conservatively returns `true` to
|
|
198
|
+
* avoid incorrectly skipping entries during sync.
|
|
199
|
+
*
|
|
200
|
+
* Used in the sync loop to partition local IDs:
|
|
201
|
+
* ```ts
|
|
202
|
+
* for (const id of localIds) {
|
|
203
|
+
* if (bloomMightContainId(remoteBloom, id)) {
|
|
204
|
+
* maybeExisting.push(id); // needs exact hasEntries() check
|
|
205
|
+
* } else {
|
|
206
|
+
* definitelyMissing.push(id); // can push without round-trip
|
|
207
|
+
* }
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @param summary The bloom filter summary obtained from the remote store.
|
|
212
|
+
* @param id The entry ID to test.
|
|
213
|
+
* @returns `true` if the ID might be in the set; `false` if it is definitely not.
|
|
214
|
+
*/
|
|
215
|
+
function bloomMightContainId(summary, id) {
|
|
216
|
+
if (summary.version !== "bloom-v1") {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
const bitset = base64ToUint8Array(summary.bitsetBase64);
|
|
220
|
+
const indexes = bloomIndexes(id, summary.bitCount, summary.hashCount, summary.salt);
|
|
221
|
+
for (const idx of indexes) {
|
|
222
|
+
if (!getBit(bitset, idx)) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}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
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StoreEntry, StoreEntryMetadata, StoreEntryType } from "../../types";
|
|
2
|
-
import type { NetworkEncryptedEntry, AuthResult } from "./types";
|
|
1
|
+
import type { StoreEntry, StoreEntryMetadata, StoreEntryType, StoreScanCursor, StoreScanFilters, StoreScanResult, StoreIdBloomSummary, StoreCompactionStatus } from "../../types";
|
|
2
|
+
import type { NetworkEncryptedEntry, AuthResult, NetworkSyncCapabilities } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Abstract interface for network communication in MindooDB sync.
|
|
5
5
|
*
|
|
@@ -45,6 +45,11 @@ export interface NetworkTransport {
|
|
|
45
45
|
* @throws NetworkError with type USER_REVOKED if user has been revoked
|
|
46
46
|
*/
|
|
47
47
|
authenticate(challenge: string, signature: Uint8Array): Promise<AuthResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Get advertised sync capabilities from the remote endpoint.
|
|
50
|
+
* Optional for backward compatibility.
|
|
51
|
+
*/
|
|
52
|
+
getCapabilities?(token: string): Promise<NetworkSyncCapabilities>;
|
|
48
53
|
/**
|
|
49
54
|
* Find entries that the remote has which we don't have locally.
|
|
50
55
|
*
|
|
@@ -85,6 +90,21 @@ export interface NetworkTransport {
|
|
|
85
90
|
* @throws NetworkError with type USER_REVOKED if user has been revoked since token was issued
|
|
86
91
|
*/
|
|
87
92
|
findEntries(token: string, type: StoreEntryType, creationDateFrom: number | null, creationDateUntil: number | null): Promise<StoreEntryMetadata[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Cursor-based metadata scan from remote store.
|
|
95
|
+
*
|
|
96
|
+
* Optional transport capability. Implementations that do not support this
|
|
97
|
+
* can omit it; callers should fall back to findNewEntries/getAllIds paths.
|
|
98
|
+
*/
|
|
99
|
+
scanEntriesSince?(token: string, cursor: StoreScanCursor | null, limit?: number, filters?: StoreScanFilters): Promise<StoreScanResult>;
|
|
100
|
+
/**
|
|
101
|
+
* Optional probabilistic ID summary for sync optimization.
|
|
102
|
+
*/
|
|
103
|
+
getIdBloomSummary?(token: string): Promise<StoreIdBloomSummary>;
|
|
104
|
+
/**
|
|
105
|
+
* Optional compaction observability for remote store monitoring.
|
|
106
|
+
*/
|
|
107
|
+
getCompactionStatus?(token: string): Promise<StoreCompactionStatus>;
|
|
88
108
|
/**
|
|
89
109
|
* Get entries from the remote store.
|
|
90
110
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkTransport.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/NetworkTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"NetworkTransport.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/NetworkTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAE1F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpD;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAE5E;;;OAGG;IACH,eAAe,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAElE;;;;;;;;;;;OAWG;IACH,cAAc,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAEjC;;;;;;;;;;;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5C;;;;;;;;;;;;;;;OAeG;IACH,mBAAmB,CACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -106,6 +106,16 @@ export interface AuthResult {
|
|
|
106
106
|
*/
|
|
107
107
|
error?: string;
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Advertised sync capabilities for transport-level feature negotiation.
|
|
111
|
+
* Used by clients to choose fast paths while preserving compatibility.
|
|
112
|
+
*/
|
|
113
|
+
export interface NetworkSyncCapabilities {
|
|
114
|
+
protocolVersion: string;
|
|
115
|
+
supportsCursorScan: boolean;
|
|
116
|
+
supportsIdBloomSummary: boolean;
|
|
117
|
+
supportsCompactionStatus: boolean;
|
|
118
|
+
}
|
|
109
119
|
/**
|
|
110
120
|
* Network transport error types for error handling.
|
|
111
121
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D;;;;;;;;;;OAUG;IACH,mBAAmB,EAAE,UAAU,CA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gBAAgB,EACtC,OAAO,EAAE,MAAM;CAKlB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D;;;;;;;;;;OAUG;IACH,mBAAmB,EAAE,UAAU,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,sBAAsB,EAAE,OAAO,CAAC;IAChC,wBAAwB,EAAE,OAAO,CAAC;CACnC;AAED;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,kCAAkC;IAClC,aAAa,kBAAkB;IAC/B,4BAA4B;IAC5B,YAAY,iBAAiB;IAC7B,oCAAoC;IACpC,iBAAiB,sBAAsB;IACvC,wCAAwC;IACxC,iBAAiB,sBAAsB;IACvC,kCAAkC;IAClC,aAAa,kBAAkB;IAC/B,wBAAwB;IACxB,YAAY,iBAAiB;IAC7B,kCAAkC;IAClC,cAAc,mBAAmB;CAClC;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;aAEnB,IAAI,EAAE,gBAAgB;gBAAtB,IAAI,EAAE,gBAAgB,EACtC,OAAO,EAAE,MAAM;CAKlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/types.ts"],"names":[],"mappings":";;;AAwIA;;GAEG;AACH,IAAY,gBAeX;AAfD,WAAY,gBAAgB;IAC1B,kCAAkC;IAClC,mDAA+B,CAAA;IAC/B,4BAA4B;IAC5B,iDAA6B,CAAA;IAC7B,oCAAoC;IACpC,2DAAuC,CAAA;IACvC,wCAAwC;IACxC,2DAAuC,CAAA;IACvC,kCAAkC;IAClC,mDAA+B,CAAA;IAC/B,wBAAwB;IACxB,iDAA6B,CAAA;IAC7B,kCAAkC;IAClC,qDAAiC,CAAA;AACnC,CAAC,EAfW,gBAAgB,gCAAhB,gBAAgB,QAe3B;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YACkB,IAAsB,EACtC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAkB;QAItC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AARD,oCAQC"}
|
|
@@ -10,8 +10,100 @@ import type { StoreEntry, StoreEntryMetadata, StoreEntryType } from "../types";
|
|
|
10
10
|
* - syncMode: "eager" | "lazy" - Synchronization strategy
|
|
11
11
|
*/
|
|
12
12
|
export interface OpenStoreOptions {
|
|
13
|
+
/**
|
|
14
|
+
* If true, local persisted data is cleared during store initialization.
|
|
15
|
+
* Useful for deterministic test setups that need a clean slate.
|
|
16
|
+
*/
|
|
17
|
+
clearLocalDataOnStartup?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Optional base path for persistent store implementations.
|
|
20
|
+
* In-memory and remote stores can ignore this option.
|
|
21
|
+
*/
|
|
22
|
+
basePath?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Controls whether store-level indexing is enabled.
|
|
25
|
+
* Implementations may fall back to scan-based behavior when false.
|
|
26
|
+
*/
|
|
27
|
+
indexingEnabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Minimum number of metadata segment files before compaction runs.
|
|
30
|
+
* Applies to append-only on-disk stores. Use 0 or negative to disable.
|
|
31
|
+
*/
|
|
32
|
+
metadataSegmentCompactionMinFiles?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum total bytes of metadata segment files before compaction runs.
|
|
35
|
+
* Applies to append-only on-disk stores. Use 0 or negative to disable.
|
|
36
|
+
*/
|
|
37
|
+
metadataSegmentCompactionMaxBytes?: number;
|
|
13
38
|
[key: string]: unknown;
|
|
14
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents index build state for stores that support indexing.
|
|
42
|
+
*/
|
|
43
|
+
export interface StoreIndexBuildStatus {
|
|
44
|
+
phase: "idle" | "building" | "ready";
|
|
45
|
+
indexingEnabled: boolean;
|
|
46
|
+
progress01: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Optional compaction status for stores using appendable index segments.
|
|
50
|
+
*/
|
|
51
|
+
export interface StoreCompactionStatus {
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
compactionMinFiles: number;
|
|
54
|
+
compactionMaxBytes: number;
|
|
55
|
+
totalCompactions: number;
|
|
56
|
+
totalCompactedFiles: number;
|
|
57
|
+
totalCompactedBytes: number;
|
|
58
|
+
totalCompactionDurationMs: number;
|
|
59
|
+
lastCompactionAt: number | null;
|
|
60
|
+
lastCompactedFiles: number;
|
|
61
|
+
lastCompactedBytes: number;
|
|
62
|
+
lastCompactionDurationMs: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Options for waiting on index readiness.
|
|
66
|
+
*/
|
|
67
|
+
export interface AwaitIndexReadyOptions {
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Cursor used by cursor-based store scans.
|
|
72
|
+
* Entries are ordered by (createdAt, id) ascending.
|
|
73
|
+
*/
|
|
74
|
+
export interface StoreScanCursor {
|
|
75
|
+
createdAt: number;
|
|
76
|
+
id: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Optional filters for cursor-based metadata scans.
|
|
80
|
+
*/
|
|
81
|
+
export interface StoreScanFilters {
|
|
82
|
+
docId?: string;
|
|
83
|
+
entryTypes?: StoreEntryType[];
|
|
84
|
+
creationDateFrom?: number | null;
|
|
85
|
+
creationDateUntil?: number | null;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Result payload for cursor-based metadata scans.
|
|
89
|
+
*/
|
|
90
|
+
export interface StoreScanResult {
|
|
91
|
+
entries: StoreEntryMetadata[];
|
|
92
|
+
nextCursor: StoreScanCursor | null;
|
|
93
|
+
hasMore: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Bloom filter summary over entry IDs for sync optimization.
|
|
97
|
+
* Can be exchanged between stores/transports to reduce hasEntries checks.
|
|
98
|
+
*/
|
|
99
|
+
export interface StoreIdBloomSummary {
|
|
100
|
+
version: "bloom-v1";
|
|
101
|
+
totalIds: number;
|
|
102
|
+
bitCount: number;
|
|
103
|
+
hashCount: number;
|
|
104
|
+
salt: string;
|
|
105
|
+
bitsetBase64: string;
|
|
106
|
+
}
|
|
15
107
|
/**
|
|
16
108
|
* Result of creating stores for a database.
|
|
17
109
|
* Contains the document store and an optional separate attachment store.
|
|
@@ -135,6 +227,19 @@ export interface ContentAddressedStore {
|
|
|
135
227
|
* @return A list of all entry IDs in the store
|
|
136
228
|
*/
|
|
137
229
|
getAllIds(): Promise<string[]>;
|
|
230
|
+
/**
|
|
231
|
+
* Cursor-based metadata scan.
|
|
232
|
+
* Preferred for large stores to avoid known-id set exchange.
|
|
233
|
+
*
|
|
234
|
+
* Ordering is deterministic: (createdAt ASC, id ASC).
|
|
235
|
+
* Returned entries are strictly after `cursor`.
|
|
236
|
+
*/
|
|
237
|
+
scanEntriesSince?(cursor: StoreScanCursor | null, limit?: number, filters?: StoreScanFilters): Promise<StoreScanResult>;
|
|
238
|
+
/**
|
|
239
|
+
* Optional probabilistic summary over entry IDs for sync optimization.
|
|
240
|
+
* Callers must still perform exact reconciliation for correctness.
|
|
241
|
+
*/
|
|
242
|
+
getIdBloomSummary?(): Promise<StoreIdBloomSummary>;
|
|
138
243
|
/**
|
|
139
244
|
* Resolve the dependency chain starting from an entry ID.
|
|
140
245
|
* Returns IDs in dependency order, traversing backward through dependencyIds.
|
|
@@ -166,5 +271,23 @@ export interface ContentAddressedStore {
|
|
|
166
271
|
* @throws Error if the store implementation does not support purging
|
|
167
272
|
*/
|
|
168
273
|
purgeDocHistory(docId: string): Promise<void>;
|
|
274
|
+
/**
|
|
275
|
+
* Optional lifecycle hook for stores that persist local data.
|
|
276
|
+
* Implementations should delete all local store data and reset in-memory state.
|
|
277
|
+
*/
|
|
278
|
+
clearAllLocalData?(): Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* Optional readiness API for stores with background index creation.
|
|
281
|
+
* Stores without indexing should resolve immediately with ready status.
|
|
282
|
+
*/
|
|
283
|
+
awaitIndexReady?(options?: AwaitIndexReadyOptions): Promise<StoreIndexBuildStatus>;
|
|
284
|
+
/**
|
|
285
|
+
* Optional status API for index build progress.
|
|
286
|
+
*/
|
|
287
|
+
getIndexBuildStatus?(): StoreIndexBuildStatus;
|
|
288
|
+
/**
|
|
289
|
+
* Optional status API for metadata-segment compaction observability.
|
|
290
|
+
*/
|
|
291
|
+
getCompactionStatus?(): Promise<StoreCompactionStatus>;
|
|
169
292
|
}
|
|
170
293
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/appendonlystores/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/E;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,EAAE,qBAAqB,CAAC;IAEhC;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;;;;;OAOG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;CAC1E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,KAAK,IAAI,MAAM,CAAC;IAEhB;;;;;;;OAOG;IACH,UAAU,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD;;;;;;OAMG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAEjD;;;;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;;;;OAWG;IACH,WAAW,CACT,IAAI,EAAE,cAAc,EACpB,gBAAgB,EAAE,MAAM,GAAG,IAAI,EAC/B,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAC/B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAEjC;;;;;OAKG;IACH,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE/B;;;;;;OAMG;IACH,gBAAgB,CAAC,CACf,MAAM,EAAE,eAAe,GAAG,IAAI,EAC9B,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,eAAe,CAAC,CAAC;IAE5B;;;OAGG;IACH,iBAAiB,CAAC,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAEnD;;;;;;;;;;;;;;;OAeG;IACH,mBAAmB,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAErB;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;;OAGG;IACH,iBAAiB,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpC;;;OAGG;IACH,eAAe,CAAC,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAEnF;;OAEG;IACH,mBAAmB,CAAC,IAAI,qBAAqB,CAAC;IAE9C;;OAEG;IACH,mBAAmB,CAAC,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACxD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-specific Automerge adapter for MindooDB
|
|
3
|
+
*
|
|
4
|
+
* - React Native: Uses react-native-automerge-generated (native Rust via UniFFI)
|
|
5
|
+
* - Browser/Node.js: Uses @automerge/automerge (WASM)
|
|
6
|
+
*
|
|
7
|
+
* Both implementations now provide the same WASM-compatible API.
|
|
8
|
+
*/
|
|
9
|
+
import * as AutomergeWasm from "@automerge/automerge";
|
|
10
|
+
type AutomergeAPI = typeof AutomergeWasm;
|
|
11
|
+
declare let Automerge: AutomergeAPI;
|
|
12
|
+
declare let isNative: boolean;
|
|
13
|
+
export { Automerge, isNative };
|
|
14
|
+
export default Automerge;
|
|
15
|
+
//# sourceMappingURL=automerge-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"automerge-adapter.d.ts","sourceRoot":"","sources":["../../src/core/automerge-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,aAAa,MAAM,sBAAsB,CAAC;AAGtD,KAAK,YAAY,GAAG,OAAO,aAAa,CAAC;AAGzC,QAAA,IAAI,SAAS,EAAE,YAAY,CAAC;AAC5B,QAAA,IAAI,QAAQ,SAAQ,CAAC;AAyBrB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAC/B,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Platform-specific Automerge adapter for MindooDB
|
|
4
|
+
*
|
|
5
|
+
* - React Native: Uses react-native-automerge-generated (native Rust via UniFFI)
|
|
6
|
+
* - Browser/Node.js: Uses @automerge/automerge (WASM)
|
|
7
|
+
*
|
|
8
|
+
* Both implementations now provide the same WASM-compatible API.
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.isNative = exports.Automerge = void 0;
|
|
45
|
+
const AutomergeWasm = __importStar(require("@automerge/automerge"));
|
|
46
|
+
// Runtime detection of available Automerge implementation
|
|
47
|
+
let Automerge;
|
|
48
|
+
let isNative = false;
|
|
49
|
+
exports.isNative = isNative;
|
|
50
|
+
try {
|
|
51
|
+
// Try to load native Automerge (React Native only)
|
|
52
|
+
// @ts-ignore - Module may not exist on Node.js/Browser
|
|
53
|
+
const nativeModule = require('react-native-automerge-generated');
|
|
54
|
+
if (nativeModule?.Automerge) {
|
|
55
|
+
// Use the WASM-compatible API from react-native-automerge-generated
|
|
56
|
+
exports.Automerge = Automerge = nativeModule.Automerge;
|
|
57
|
+
exports.isNative = isNative = true;
|
|
58
|
+
console.log('[MindooDB] ✓ Using native Rust Automerge (react-native-automerge-generated)');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Module loaded but Automerge API not available
|
|
62
|
+
exports.Automerge = Automerge = AutomergeWasm;
|
|
63
|
+
console.log('[MindooDB] ⚠ Native module loaded but Automerge API unavailable, using WASM');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// Native module not available (Browser/Node.js)
|
|
68
|
+
exports.Automerge = Automerge = AutomergeWasm;
|
|
69
|
+
exports.isNative = isNative = false;
|
|
70
|
+
console.log('[MindooDB] ℹ Using WASM Automerge (Browser/Node.js mode)');
|
|
71
|
+
}
|
|
72
|
+
exports.default = Automerge;
|
|
73
|
+
//# sourceMappingURL=automerge-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"automerge-adapter.js","sourceRoot":"","sources":["../../src/core/automerge-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oEAAsD;AAKtD,0DAA0D;AAC1D,IAAI,SAAuB,CAAC;AAC5B,IAAI,QAAQ,GAAG,KAAK,CAAC;AAyBD,4BAAQ;AAvB5B,IAAI,CAAC;IACH,mDAAmD;IACnD,uDAAuD;IACvD,MAAM,YAAY,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;IAEjE,IAAI,YAAY,EAAE,SAAS,EAAE,CAAC;QAC5B,oEAAoE;QACpE,oBAAA,SAAS,GAAG,YAAY,CAAC,SAAyB,CAAC;QACnD,mBAAA,QAAQ,GAAG,IAAI,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,6EAA6E,CAAC,CAAC;IAC7F,CAAC;SAAM,CAAC;QACN,gDAAgD;QAChD,oBAAA,SAAS,GAAG,aAAa,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,6EAA6E,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,gDAAgD;IAChD,oBAAA,SAAS,GAAG,aAAa,CAAC;IAC1B,mBAAA,QAAQ,GAAG,KAAK,CAAC;IACjB,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC;AAC1E,CAAC;AAID,kBAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const DEFAULT_PBKDF2_ITERATIONS = 310000;
|
|
2
|
+
export declare const MIN_PBKDF2_ITERATIONS = 60000;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve PBKDF2 iterations from runtime overrides with safe bounds.
|
|
5
|
+
*
|
|
6
|
+
* Override order:
|
|
7
|
+
* 1) globalThis.__MINDOODB_PBKDF2_ITERATIONS (useful for RN/Expo runtime config)
|
|
8
|
+
* 2) process.env.MINDOODB_PBKDF2_ITERATIONS
|
|
9
|
+
* 3) defaultIterations
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolvePbkdf2Iterations(defaultIterations?: number): number;
|
|
12
|
+
//# sourceMappingURL=pbkdf2Iterations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbkdf2Iterations.d.ts","sourceRoot":"","sources":["../../../src/core/crypto/pbkdf2Iterations.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,SAAS,CAAC;AAChD,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAE3C;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,iBAAiB,GAAE,MAAkC,GAAG,MAAM,CAgBrG"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MIN_PBKDF2_ITERATIONS = exports.DEFAULT_PBKDF2_ITERATIONS = void 0;
|
|
4
|
+
exports.resolvePbkdf2Iterations = resolvePbkdf2Iterations;
|
|
5
|
+
exports.DEFAULT_PBKDF2_ITERATIONS = 310000;
|
|
6
|
+
exports.MIN_PBKDF2_ITERATIONS = 60000;
|
|
7
|
+
/**
|
|
8
|
+
* Resolve PBKDF2 iterations from runtime overrides with safe bounds.
|
|
9
|
+
*
|
|
10
|
+
* Override order:
|
|
11
|
+
* 1) globalThis.__MINDOODB_PBKDF2_ITERATIONS (useful for RN/Expo runtime config)
|
|
12
|
+
* 2) process.env.MINDOODB_PBKDF2_ITERATIONS
|
|
13
|
+
* 3) defaultIterations
|
|
14
|
+
*/
|
|
15
|
+
function resolvePbkdf2Iterations(defaultIterations = exports.DEFAULT_PBKDF2_ITERATIONS) {
|
|
16
|
+
const override = readOverride();
|
|
17
|
+
if (override === undefined) {
|
|
18
|
+
return defaultIterations;
|
|
19
|
+
}
|
|
20
|
+
const parsed = Number(override);
|
|
21
|
+
if (!Number.isFinite(parsed)) {
|
|
22
|
+
return defaultIterations;
|
|
23
|
+
}
|
|
24
|
+
const intValue = Math.floor(parsed);
|
|
25
|
+
if (intValue < exports.MIN_PBKDF2_ITERATIONS) {
|
|
26
|
+
return exports.MIN_PBKDF2_ITERATIONS;
|
|
27
|
+
}
|
|
28
|
+
return intValue;
|
|
29
|
+
}
|
|
30
|
+
function readOverride() {
|
|
31
|
+
try {
|
|
32
|
+
if (typeof globalThis !== "undefined") {
|
|
33
|
+
const g = globalThis;
|
|
34
|
+
if (g.__MINDOODB_PBKDF2_ITERATIONS !== undefined) {
|
|
35
|
+
return g.__MINDOODB_PBKDF2_ITERATIONS;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// no-op
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
if (typeof process !== "undefined" && process.env) {
|
|
44
|
+
const fromEnv = process.env.MINDOODB_PBKDF2_ITERATIONS;
|
|
45
|
+
if (fromEnv !== undefined) {
|
|
46
|
+
return fromEnv;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// no-op
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=pbkdf2Iterations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbkdf2Iterations.js","sourceRoot":"","sources":["../../../src/core/crypto/pbkdf2Iterations.ts"],"names":[],"mappings":";;;AAWA,0DAgBC;AA3BY,QAAA,yBAAyB,GAAG,MAAM,CAAC;AACnC,QAAA,qBAAqB,GAAG,KAAK,CAAC;AAE3C;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CAAC,oBAA4B,iCAAyB;IAC3F,MAAM,QAAQ,GAAG,YAAY,EAAE,CAAC;IAChC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,IAAI,QAAQ,GAAG,6BAAqB,EAAE,CAAC;QACrC,OAAO,6BAAqB,CAAC;IAC/B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,YAAY;IACnB,IAAI,CAAC;QACH,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE,CAAC;YACtC,MAAM,CAAC,GAAG,UAA4E,CAAC;YACvF,IAAI,CAAC,CAAC,4BAA4B,KAAK,SAAS,EAAE,CAAC;gBACjD,OAAO,CAAC,CAAC,4BAA4B,CAAC;YACxC,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,QAAQ;IAC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