mindoodb 0.0.3 → 0.0.5
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-server.md +1030 -0
- package/README.md +14 -26
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +27 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +270 -121
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.d.ts +15 -0
- package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -1
- package/dist/appendonlystores/network/HttpTransport.js +235 -10
- package/dist/appendonlystores/network/HttpTransport.js.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +5 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +40 -4
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts +10 -3
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.d.ts.map +1 -1
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js +138 -13
- package/dist/browser/appendonlystores/IndexedDBContentAddressedStore.js.map +1 -1
- package/dist/browser/cache/IndexedDBLocalCacheStore.d.ts +21 -0
- package/dist/browser/cache/IndexedDBLocalCacheStore.d.ts.map +1 -0
- package/dist/browser/cache/IndexedDBLocalCacheStore.js +106 -0
- package/dist/browser/cache/IndexedDBLocalCacheStore.js.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +9 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/core/BaseMindooDB.d.ts +108 -13
- package/dist/core/BaseMindooDB.d.ts.map +1 -1
- package/dist/core/BaseMindooDB.js +1268 -292
- package/dist/core/BaseMindooDB.js.map +1 -1
- package/dist/core/BaseMindooTenant.d.ts +31 -1
- package/dist/core/BaseMindooTenant.d.ts.map +1 -1
- package/dist/core/BaseMindooTenant.js +212 -129
- package/dist/core/BaseMindooTenant.js.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts +13 -10
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.js +134 -27
- package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
- package/dist/core/BaseMindooTenantFactory.d.ts +5 -1
- package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantFactory.js +46 -69
- package/dist/core/BaseMindooTenantFactory.js.map +1 -1
- package/dist/core/MindooDBServerAdmin.d.ts +241 -0
- package/dist/core/MindooDBServerAdmin.d.ts.map +1 -0
- package/dist/core/MindooDBServerAdmin.js +401 -0
- package/dist/core/MindooDBServerAdmin.js.map +1 -0
- package/dist/core/appendonlystores/AttachmentReadPlanner.d.ts +22 -0
- package/dist/core/appendonlystores/AttachmentReadPlanner.d.ts.map +1 -0
- package/dist/core/appendonlystores/AttachmentReadPlanner.js +124 -0
- package/dist/core/appendonlystores/AttachmentReadPlanner.js.map +1 -0
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts +10 -4
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts.map +1 -1
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js +44 -9
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js.map +1 -1
- package/dist/core/appendonlystores/MaterializationPlanner.d.ts +84 -0
- package/dist/core/appendonlystores/MaterializationPlanner.d.ts.map +1 -0
- package/dist/core/appendonlystores/MaterializationPlanner.js +326 -0
- package/dist/core/appendonlystores/MaterializationPlanner.js.map +1 -0
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts +33 -0
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.d.ts +35 -0
- package/dist/core/appendonlystores/network/types.d.ts.map +1 -1
- package/dist/core/appendonlystores/network/types.js +2 -0
- package/dist/core/appendonlystores/network/types.js.map +1 -1
- package/dist/core/appendonlystores/types.d.ts +174 -3
- package/dist/core/appendonlystores/types.d.ts.map +1 -1
- package/dist/core/cache/CacheManager.d.ts +75 -0
- package/dist/core/cache/CacheManager.d.ts.map +1 -0
- package/dist/core/cache/CacheManager.js +101 -0
- package/dist/core/cache/CacheManager.js.map +1 -0
- package/dist/core/cache/EncryptedLocalCacheStore.d.ts +41 -0
- package/dist/core/cache/EncryptedLocalCacheStore.d.ts.map +1 -0
- package/dist/core/cache/EncryptedLocalCacheStore.js +120 -0
- package/dist/core/cache/EncryptedLocalCacheStore.js.map +1 -0
- package/dist/core/cache/LocalCacheStore.d.ts +50 -0
- package/dist/core/cache/LocalCacheStore.d.ts.map +1 -0
- package/dist/core/cache/LocalCacheStore.js +39 -0
- package/dist/core/cache/LocalCacheStore.js.map +1 -0
- package/dist/core/crypto/privateKeyEncryption.d.ts +5 -0
- package/dist/core/crypto/privateKeyEncryption.d.ts.map +1 -0
- package/dist/core/crypto/privateKeyEncryption.js +87 -0
- package/dist/core/crypto/privateKeyEncryption.js.map +1 -0
- package/dist/core/index.d.ts +13 -6
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +13 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts +4 -1
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +39 -11
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -1
- package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts +1 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js +3 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualView.d.ts +43 -0
- package/dist/core/indexing/virtualviews/VirtualView.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualView.js +173 -0
- package/dist/core/indexing/virtualviews/VirtualView.js.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts +7 -0
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts.map +1 -1
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.js +28 -0
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.js.map +1 -1
- package/dist/core/keys/KeyBag.d.ts +38 -14
- package/dist/core/keys/KeyBag.d.ts.map +1 -1
- package/dist/core/keys/KeyBag.js +102 -76
- package/dist/core/keys/KeyBag.js.map +1 -1
- package/dist/core/keys/KeyContext.d.ts +3 -3
- package/dist/core/keys/KeyContext.d.ts.map +1 -1
- package/dist/core/keys/KeyContext.js +10 -4
- package/dist/core/keys/KeyContext.js.map +1 -1
- package/dist/core/types.d.ts +341 -22
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +7 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/utils/idGeneration.d.ts.map +1 -1
- package/dist/core/utils/idGeneration.js +37 -3
- package/dist/core/utils/idGeneration.js.map +1 -1
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.d.ts +31 -7
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.d.ts.map +1 -1
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.js +139 -17
- package/dist/node/appendonlystores/BasicOnDiskContentAddressedStore.js.map +1 -1
- package/dist/node/attachments/writeAttachmentToFile.d.ts +15 -0
- package/dist/node/attachments/writeAttachmentToFile.d.ts.map +1 -0
- package/dist/node/attachments/writeAttachmentToFile.js +73 -0
- package/dist/node/attachments/writeAttachmentToFile.js.map +1 -0
- package/dist/node/cache/FileSystemLocalCacheStore.d.ts +17 -0
- package/dist/node/cache/FileSystemLocalCacheStore.d.ts.map +1 -0
- package/dist/node/cache/FileSystemLocalCacheStore.js +128 -0
- package/dist/node/cache/FileSystemLocalCacheStore.js.map +1 -0
- package/dist/node/cli/change-identity-password.d.ts +7 -0
- package/dist/node/cli/change-identity-password.d.ts.map +1 -0
- package/dist/node/cli/change-identity-password.js +67 -0
- package/dist/node/cli/change-identity-password.js.map +1 -0
- package/dist/node/cli/cli-utils.d.ts +16 -0
- package/dist/node/cli/cli-utils.d.ts.map +1 -0
- package/dist/node/cli/cli-utils.js +113 -0
- package/dist/node/cli/cli-utils.js.map +1 -0
- package/dist/node/cli/identity-export-public.d.ts +4 -0
- package/dist/node/cli/identity-export-public.d.ts.map +1 -0
- package/dist/node/cli/identity-export-public.js +55 -0
- package/dist/node/cli/identity-export-public.js.map +1 -0
- package/dist/node/cli/identity-info.d.ts +4 -0
- package/dist/node/cli/identity-info.d.ts.map +1 -0
- package/dist/node/cli/identity-info.js +57 -0
- package/dist/node/cli/identity-info.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 +4 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/server/CapabilityMatcher.d.ts +45 -0
- package/dist/node/server/CapabilityMatcher.d.ts.map +1 -0
- package/dist/node/server/CapabilityMatcher.js +117 -0
- package/dist/node/server/CapabilityMatcher.js.map +1 -0
- package/dist/node/server/MindooDBServer.d.ts +94 -0
- package/dist/node/server/MindooDBServer.d.ts.map +1 -0
- package/dist/node/server/MindooDBServer.js +1256 -0
- package/dist/node/server/MindooDBServer.js.map +1 -0
- package/dist/node/server/ServerSync.d.ts +41 -0
- package/dist/node/server/ServerSync.d.ts.map +1 -0
- package/dist/node/server/ServerSync.js +187 -0
- package/dist/node/server/ServerSync.js.map +1 -0
- package/dist/node/server/StoreFactory.d.ts +45 -0
- package/dist/node/server/StoreFactory.d.ts.map +1 -0
- package/dist/node/server/StoreFactory.js +89 -0
- package/dist/node/server/StoreFactory.js.map +1 -0
- package/dist/node/server/SystemAdminAuth.d.ts +65 -0
- package/dist/node/server/SystemAdminAuth.d.ts.map +1 -0
- package/dist/node/server/SystemAdminAuth.js +200 -0
- package/dist/node/server/SystemAdminAuth.js.map +1 -0
- package/dist/node/server/SystemIpAllowlist.d.ts +21 -0
- package/dist/node/server/SystemIpAllowlist.d.ts.map +1 -0
- package/dist/node/server/SystemIpAllowlist.js +210 -0
- package/dist/node/server/SystemIpAllowlist.js.map +1 -0
- package/dist/node/server/TenantManager.d.ts +100 -0
- package/dist/node/server/TenantManager.d.ts.map +1 -0
- package/dist/node/server/TenantManager.js +615 -0
- package/dist/node/server/TenantManager.js.map +1 -0
- package/dist/node/server/add-to-network.d.ts +20 -0
- package/dist/node/server/add-to-network.d.ts.map +1 -0
- package/dist/node/server/add-to-network.js +275 -0
- package/dist/node/server/add-to-network.js.map +1 -0
- package/dist/node/server/config.d.ts +51 -0
- package/dist/node/server/config.d.ts.map +1 -0
- package/dist/node/server/config.js +218 -0
- package/dist/node/server/config.js.map +1 -0
- package/dist/node/server/resolveServerPassword.d.ts +7 -0
- package/dist/node/server/resolveServerPassword.d.ts.map +1 -0
- package/dist/node/server/resolveServerPassword.js +25 -0
- package/dist/node/server/resolveServerPassword.js.map +1 -0
- package/dist/node/server/server.d.ts +22 -0
- package/dist/node/server/server.d.ts.map +1 -0
- package/dist/node/server/server.js +225 -0
- package/dist/node/server/server.js.map +1 -0
- package/dist/node/server/serverinit.d.ts +21 -0
- package/dist/node/server/serverinit.d.ts.map +1 -0
- package/dist/node/server/serverinit.js +317 -0
- package/dist/node/server/serverinit.js.map +1 -0
- package/dist/node/server/types.d.ts +167 -0
- package/dist/node/server/types.d.ts.map +1 -0
- package/dist/node/server/types.js +24 -0
- package/dist/node/server/types.js.map +1 -0
- package/dist/node/server/validation.d.ts +47 -0
- package/dist/node/server/validation.d.ts.map +1 -0
- package/dist/node/server/validation.js +114 -0
- package/dist/node/server/validation.js.map +1 -0
- package/dist/reactnative/cache/MMKVLocalCacheStore.d.ts +48 -0
- package/dist/reactnative/cache/MMKVLocalCacheStore.d.ts.map +1 -0
- package/dist/reactnative/cache/MMKVLocalCacheStore.js +113 -0
- package/dist/reactnative/cache/MMKVLocalCacheStore.js.map +1 -0
- package/dist/reactnative/index.d.ts +1 -0
- package/dist/reactnative/index.d.ts.map +1 -1
- package/dist/reactnative/index.js +4 -1
- package/dist/reactnative/index.js.map +1 -1
- package/package.json +15 -3
|
@@ -69,10 +69,10 @@ export interface AwaitIndexReadyOptions {
|
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Cursor used by cursor-based store scans.
|
|
72
|
-
* Entries are ordered by (
|
|
72
|
+
* Entries are ordered by (receiptOrder, id) ascending.
|
|
73
73
|
*/
|
|
74
74
|
export interface StoreScanCursor {
|
|
75
|
-
|
|
75
|
+
receiptOrder: number;
|
|
76
76
|
id: string;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
@@ -104,6 +104,126 @@ export interface StoreIdBloomSummary {
|
|
|
104
104
|
salt: string;
|
|
105
105
|
bitsetBase64: string;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Options for causal document materialization planning.
|
|
109
|
+
* The planner computes which snapshot (if any) should be used and which
|
|
110
|
+
* change entries still need to be applied to reconstruct the latest state.
|
|
111
|
+
*/
|
|
112
|
+
export interface MaterializationPlanOptions {
|
|
113
|
+
/**
|
|
114
|
+
* If true, include planner diagnostics to aid debugging and tuning.
|
|
115
|
+
*/
|
|
116
|
+
includeDiagnostics?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Debug and observability details for materialization planning.
|
|
120
|
+
*/
|
|
121
|
+
export interface MaterializationPlanDiagnostics {
|
|
122
|
+
/**
|
|
123
|
+
* Current tip entries for the document (entries with no descendants in the
|
|
124
|
+
* doc graph among change/create/delete entries).
|
|
125
|
+
*/
|
|
126
|
+
headEntryIds: string[];
|
|
127
|
+
/**
|
|
128
|
+
* Number of latest-state entries causally covered by the selected snapshot.
|
|
129
|
+
*/
|
|
130
|
+
coveredLatestEntryCount: number;
|
|
131
|
+
/**
|
|
132
|
+
* Number of latest-state entries not covered by the selected snapshot.
|
|
133
|
+
*/
|
|
134
|
+
uncoveredLatestEntryCount: number;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Store-level causal replay plan for one document.
|
|
138
|
+
*/
|
|
139
|
+
export interface DocumentMaterializationPlan {
|
|
140
|
+
/**
|
|
141
|
+
* Document ID this plan is for.
|
|
142
|
+
*/
|
|
143
|
+
docId: string;
|
|
144
|
+
/**
|
|
145
|
+
* Snapshot entry to load first (if present).
|
|
146
|
+
*/
|
|
147
|
+
snapshotEntryId: string | null;
|
|
148
|
+
/**
|
|
149
|
+
* Change entry IDs to apply after the snapshot (or from empty doc if no snapshot).
|
|
150
|
+
* The order is dependency-first (oldest first).
|
|
151
|
+
*/
|
|
152
|
+
entryIdsToApply: string[];
|
|
153
|
+
/**
|
|
154
|
+
* Optional debug details.
|
|
155
|
+
*/
|
|
156
|
+
diagnostics?: MaterializationPlanDiagnostics;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Batched materialization planning result.
|
|
160
|
+
*/
|
|
161
|
+
export interface DocumentMaterializationBatchPlan {
|
|
162
|
+
/**
|
|
163
|
+
* Per-document plans.
|
|
164
|
+
*/
|
|
165
|
+
plans: DocumentMaterializationPlan[];
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Byte-range request for attachment reads.
|
|
169
|
+
*/
|
|
170
|
+
export interface AttachmentReadPlanOptions {
|
|
171
|
+
/**
|
|
172
|
+
* Inclusive start byte within the plaintext attachment.
|
|
173
|
+
*/
|
|
174
|
+
startByte: number;
|
|
175
|
+
/**
|
|
176
|
+
* Exclusive end byte within the plaintext attachment.
|
|
177
|
+
* Defaults to the attachment size.
|
|
178
|
+
*/
|
|
179
|
+
endByteExclusive?: number;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* One planned attachment chunk covering a plaintext byte window.
|
|
183
|
+
*/
|
|
184
|
+
export interface AttachmentReadPlanChunk {
|
|
185
|
+
/**
|
|
186
|
+
* Store entry ID of the chunk.
|
|
187
|
+
*/
|
|
188
|
+
id: string;
|
|
189
|
+
/**
|
|
190
|
+
* Inclusive plaintext start byte of this chunk within the full attachment.
|
|
191
|
+
*/
|
|
192
|
+
startByte: number;
|
|
193
|
+
/**
|
|
194
|
+
* Exclusive plaintext end byte of this chunk within the full attachment.
|
|
195
|
+
*/
|
|
196
|
+
endByteExclusive: number;
|
|
197
|
+
/**
|
|
198
|
+
* Plaintext size of this chunk as stored in metadata.
|
|
199
|
+
*/
|
|
200
|
+
originalSize: number;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Store-level plan for reading a plaintext attachment byte range.
|
|
204
|
+
*/
|
|
205
|
+
export interface AttachmentReadPlan {
|
|
206
|
+
/**
|
|
207
|
+
* Declared plaintext attachment size.
|
|
208
|
+
*/
|
|
209
|
+
attachmentSize: number;
|
|
210
|
+
/**
|
|
211
|
+
* Inclusive requested start byte.
|
|
212
|
+
*/
|
|
213
|
+
startByte: number;
|
|
214
|
+
/**
|
|
215
|
+
* Exclusive requested end byte.
|
|
216
|
+
*/
|
|
217
|
+
endByteExclusive: number;
|
|
218
|
+
/**
|
|
219
|
+
* Ordered chunk plans needed to satisfy the read.
|
|
220
|
+
*/
|
|
221
|
+
chunkPlans: AttachmentReadPlanChunk[];
|
|
222
|
+
/**
|
|
223
|
+
* Number of bytes to skip from the first planned chunk.
|
|
224
|
+
*/
|
|
225
|
+
offsetInFirstChunk: number;
|
|
226
|
+
}
|
|
107
227
|
/**
|
|
108
228
|
* Result of creating stores for a database.
|
|
109
229
|
* Contains the document store and an optional separate attachment store.
|
|
@@ -184,6 +304,34 @@ export interface ContentAddressedStore {
|
|
|
184
304
|
* @return A list of entries (may be shorter than input if some don't exist)
|
|
185
305
|
*/
|
|
186
306
|
getEntries(ids: string[]): Promise<StoreEntry[]>;
|
|
307
|
+
/**
|
|
308
|
+
* Get metadata for a single entry without loading its encrypted payload.
|
|
309
|
+
*
|
|
310
|
+
* This is useful for dependency planning and attachment range access where
|
|
311
|
+
* callers only need dependency links, sizes, or timestamps before deciding
|
|
312
|
+
* which payload entries to fetch.
|
|
313
|
+
*
|
|
314
|
+
* @param id The entry ID to look up
|
|
315
|
+
* @return The entry metadata, or null if the entry does not exist
|
|
316
|
+
*/
|
|
317
|
+
getEntryMetadata(id: string): Promise<StoreEntryMetadata | null>;
|
|
318
|
+
/**
|
|
319
|
+
* Optionally plan a plaintext attachment read range.
|
|
320
|
+
*
|
|
321
|
+
* Implementations may optimize metadata traversal (for example via batching,
|
|
322
|
+
* dependency pre-resolution, or caching) while callers still receive a
|
|
323
|
+
* backend-agnostic chunk plan.
|
|
324
|
+
*
|
|
325
|
+
* Custom stores do not need to implement this from scratch: core helper
|
|
326
|
+
* planners can compose existing methods like `getEntryMetadata()` and
|
|
327
|
+
* `resolveDependencies()`.
|
|
328
|
+
*
|
|
329
|
+
* @param lastChunkId The newest attachment chunk entry ID
|
|
330
|
+
* @param attachmentSize Declared plaintext attachment size
|
|
331
|
+
* @param options Requested plaintext byte window
|
|
332
|
+
* @return A read plan for the requested attachment bytes
|
|
333
|
+
*/
|
|
334
|
+
planAttachmentReadByWalkingMetadata?(lastChunkId: string, attachmentSize: number, options: AttachmentReadPlanOptions): Promise<AttachmentReadPlan>;
|
|
187
335
|
/**
|
|
188
336
|
* Check which IDs from the provided list exist in this store.
|
|
189
337
|
*
|
|
@@ -231,7 +379,7 @@ export interface ContentAddressedStore {
|
|
|
231
379
|
* Cursor-based metadata scan.
|
|
232
380
|
* Preferred for large stores to avoid known-id set exchange.
|
|
233
381
|
*
|
|
234
|
-
* Ordering is deterministic: (
|
|
382
|
+
* Ordering is deterministic: (receiptOrder ASC, id ASC).
|
|
235
383
|
* Returned entries are strictly after `cursor`.
|
|
236
384
|
*/
|
|
237
385
|
scanEntriesSince?(cursor: StoreScanCursor | null, limit?: number, filters?: StoreScanFilters): Promise<StoreScanResult>;
|
|
@@ -240,6 +388,17 @@ export interface ContentAddressedStore {
|
|
|
240
388
|
* Callers must still perform exact reconciliation for correctness.
|
|
241
389
|
*/
|
|
242
390
|
getIdBloomSummary?(): Promise<StoreIdBloomSummary>;
|
|
391
|
+
/**
|
|
392
|
+
* Plan causal materialization for a single document.
|
|
393
|
+
* This allows callers to fetch only required entries instead of scanning/applying
|
|
394
|
+
* full history every time.
|
|
395
|
+
*/
|
|
396
|
+
planDocumentMaterialization(docId: string, options?: MaterializationPlanOptions): Promise<DocumentMaterializationPlan>;
|
|
397
|
+
/**
|
|
398
|
+
* Plan causal materialization for multiple documents in one call.
|
|
399
|
+
* Batch planning is important for high-latency network stores to reduce round trips.
|
|
400
|
+
*/
|
|
401
|
+
planDocumentMaterializationBatch(docIds: string[], options?: MaterializationPlanOptions): Promise<DocumentMaterializationBatchPlan>;
|
|
243
402
|
/**
|
|
244
403
|
* Resolve the dependency chain starting from an entry ID.
|
|
245
404
|
* Returns IDs in dependency order, traversing backward through dependencyIds.
|
|
@@ -289,5 +448,17 @@ export interface ContentAddressedStore {
|
|
|
289
448
|
* Optional status API for metadata-segment compaction observability.
|
|
290
449
|
*/
|
|
291
450
|
getCompactionStatus?(): Promise<StoreCompactionStatus>;
|
|
451
|
+
/**
|
|
452
|
+
* Optional unique fingerprint for local cache scoping.
|
|
453
|
+
* Must be stable across restarts and unique per store backend/location.
|
|
454
|
+
*
|
|
455
|
+
* Examples:
|
|
456
|
+
* - On-disk store: "disk:/data/myapp/contacts"
|
|
457
|
+
* - IndexedDB store: "idb:default/contacts"
|
|
458
|
+
* - Network store: "net:https://sync.example.com/contacts"
|
|
459
|
+
*
|
|
460
|
+
* If not implemented, BaseMindooDB falls back to getId().
|
|
461
|
+
*/
|
|
462
|
+
getCacheIdentity?(): string;
|
|
292
463
|
}
|
|
293
464
|
//# 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;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAE3C;;;OAGG;IACH,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAE3C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;IACrC,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,yBAAyB,EAAE,MAAM,CAAC;IAClC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,wBAAwB,EAAE,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,MAAM,CAA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ACzB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAExC;;;OAGG;IACH,gCAAgC,CAC9B,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,gCAAgC,CAAC,CAAC;IAE7C;;;;;;;;;;;;;;;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;IAEvD;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,IAAI,MAAM,CAAC;CAC7B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { LocalCacheStore } from "./LocalCacheStore";
|
|
2
|
+
import { Logger } from "../logging";
|
|
3
|
+
/**
|
|
4
|
+
* Interface that cacheable consumers (BaseMindooDB, VirtualView) implement
|
|
5
|
+
* so the CacheManager can flush their dirty state.
|
|
6
|
+
*/
|
|
7
|
+
export interface ICacheable {
|
|
8
|
+
/**
|
|
9
|
+
* A unique key identifying this cacheable in the cache store.
|
|
10
|
+
* For BaseMindooDB: tenantId + "/" + store.getCacheIdentity()
|
|
11
|
+
* For VirtualView: viewId + "/" + version
|
|
12
|
+
*/
|
|
13
|
+
getCachePrefix(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Export the current dirty state to the cache store.
|
|
16
|
+
* Called by CacheManager during flush.
|
|
17
|
+
*
|
|
18
|
+
* @param store The cache store to write to
|
|
19
|
+
* @returns The number of entries written
|
|
20
|
+
*/
|
|
21
|
+
flushToCache(store: LocalCacheStore): Promise<number>;
|
|
22
|
+
/**
|
|
23
|
+
* Clear the dirty tracking state after a successful flush.
|
|
24
|
+
*/
|
|
25
|
+
clearDirty(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this cacheable has any dirty state to flush.
|
|
28
|
+
*/
|
|
29
|
+
hasDirtyState(): boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface CacheManagerOptions {
|
|
32
|
+
/** Flush interval in milliseconds. Default: 5000 (5s) */
|
|
33
|
+
flushIntervalMs?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Coordinates periodic cache persistence for all registered cacheables
|
|
37
|
+
* (databases, virtual views) within a tenant.
|
|
38
|
+
*
|
|
39
|
+
* Tracks dirty state and flushes periodically or on demand.
|
|
40
|
+
*/
|
|
41
|
+
export declare class CacheManager {
|
|
42
|
+
private store;
|
|
43
|
+
private cacheables;
|
|
44
|
+
private flushIntervalMs;
|
|
45
|
+
private timer;
|
|
46
|
+
private flushInProgress;
|
|
47
|
+
private disposed;
|
|
48
|
+
private logger;
|
|
49
|
+
constructor(store: LocalCacheStore, options?: CacheManagerOptions, logger?: Logger);
|
|
50
|
+
getStore(): LocalCacheStore;
|
|
51
|
+
/**
|
|
52
|
+
* Register a cacheable consumer. It will be included in periodic flushes.
|
|
53
|
+
*/
|
|
54
|
+
register(cacheable: ICacheable): void;
|
|
55
|
+
/**
|
|
56
|
+
* Deregister a cacheable consumer (e.g. on db.close()).
|
|
57
|
+
* Triggers an immediate flush for this cacheable before removal.
|
|
58
|
+
*/
|
|
59
|
+
deregister(cacheable: ICacheable): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Notify the CacheManager that something changed.
|
|
62
|
+
* Schedules a flush if one is not already pending.
|
|
63
|
+
*/
|
|
64
|
+
markDirty(): void;
|
|
65
|
+
private scheduleFlush;
|
|
66
|
+
/**
|
|
67
|
+
* Immediately flush all dirty cacheables.
|
|
68
|
+
*/
|
|
69
|
+
flush(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Flush all pending state and stop the periodic timer.
|
|
72
|
+
*/
|
|
73
|
+
dispose(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=CacheManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheManager.d.ts","sourceRoot":"","sources":["../../../src/core/cache/CacheManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAoC,MAAM,YAAY,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,cAAc,IAAI,MAAM,CAAC;IAEzB;;;;;;OAMG;IACH,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEtD;;OAEG;IACH,UAAU,IAAI,IAAI,CAAC;IAEnB;;OAEG;IACH,aAAa,IAAI,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,UAAU,CAA8B;IAChD,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,KAAK,CAA8C;IAC3D,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,MAAM,CAAS;gBAEX,KAAK,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,MAAM;IAMlF,QAAQ,IAAI,eAAe;IAI3B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;IAIrC;;;OAGG;IACG,UAAU,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAYtD;;;OAGG;IACH,SAAS,IAAI,IAAI;IAKjB,OAAO,CAAC,aAAa;IAQrB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB5B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ/B"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheManager = void 0;
|
|
4
|
+
const logging_1 = require("../logging");
|
|
5
|
+
/**
|
|
6
|
+
* Coordinates periodic cache persistence for all registered cacheables
|
|
7
|
+
* (databases, virtual views) within a tenant.
|
|
8
|
+
*
|
|
9
|
+
* Tracks dirty state and flushes periodically or on demand.
|
|
10
|
+
*/
|
|
11
|
+
class CacheManager {
|
|
12
|
+
constructor(store, options, logger) {
|
|
13
|
+
this.cacheables = new Set();
|
|
14
|
+
this.timer = null;
|
|
15
|
+
this.flushInProgress = false;
|
|
16
|
+
this.disposed = false;
|
|
17
|
+
this.store = store;
|
|
18
|
+
this.flushIntervalMs = options?.flushIntervalMs ?? 5000;
|
|
19
|
+
this.logger = logger || new logging_1.MindooLogger((0, logging_1.getDefaultLogLevel)(), "CacheManager", true);
|
|
20
|
+
}
|
|
21
|
+
getStore() {
|
|
22
|
+
return this.store;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Register a cacheable consumer. It will be included in periodic flushes.
|
|
26
|
+
*/
|
|
27
|
+
register(cacheable) {
|
|
28
|
+
this.cacheables.add(cacheable);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Deregister a cacheable consumer (e.g. on db.close()).
|
|
32
|
+
* Triggers an immediate flush for this cacheable before removal.
|
|
33
|
+
*/
|
|
34
|
+
async deregister(cacheable) {
|
|
35
|
+
if (cacheable.hasDirtyState()) {
|
|
36
|
+
try {
|
|
37
|
+
await cacheable.flushToCache(this.store);
|
|
38
|
+
cacheable.clearDirty();
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
this.logger.warn(`Failed to flush cache for ${cacheable.getCachePrefix()} on deregister: ${e}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.cacheables.delete(cacheable);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Notify the CacheManager that something changed.
|
|
48
|
+
* Schedules a flush if one is not already pending.
|
|
49
|
+
*/
|
|
50
|
+
markDirty() {
|
|
51
|
+
if (this.disposed)
|
|
52
|
+
return;
|
|
53
|
+
this.scheduleFlush();
|
|
54
|
+
}
|
|
55
|
+
scheduleFlush() {
|
|
56
|
+
if (this.timer !== null)
|
|
57
|
+
return;
|
|
58
|
+
this.timer = setTimeout(async () => {
|
|
59
|
+
this.timer = null;
|
|
60
|
+
await this.flush();
|
|
61
|
+
}, this.flushIntervalMs);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Immediately flush all dirty cacheables.
|
|
65
|
+
*/
|
|
66
|
+
async flush() {
|
|
67
|
+
if (this.flushInProgress)
|
|
68
|
+
return;
|
|
69
|
+
this.flushInProgress = true;
|
|
70
|
+
try {
|
|
71
|
+
for (const cacheable of this.cacheables) {
|
|
72
|
+
if (!cacheable.hasDirtyState())
|
|
73
|
+
continue;
|
|
74
|
+
try {
|
|
75
|
+
const count = await cacheable.flushToCache(this.store);
|
|
76
|
+
cacheable.clearDirty();
|
|
77
|
+
this.logger.debug(`Flushed ${count} entries for ${cacheable.getCachePrefix()}`);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
this.logger.warn(`Cache flush failed for ${cacheable.getCachePrefix()}: ${e}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
this.flushInProgress = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Flush all pending state and stop the periodic timer.
|
|
90
|
+
*/
|
|
91
|
+
async dispose() {
|
|
92
|
+
this.disposed = true;
|
|
93
|
+
if (this.timer !== null) {
|
|
94
|
+
clearTimeout(this.timer);
|
|
95
|
+
this.timer = null;
|
|
96
|
+
}
|
|
97
|
+
await this.flush();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.CacheManager = CacheManager;
|
|
101
|
+
//# sourceMappingURL=CacheManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheManager.js","sourceRoot":"","sources":["../../../src/core/cache/CacheManager.ts"],"names":[],"mappings":";;;AACA,wCAAsE;AAuCtE;;;;;GAKG;AACH,MAAa,YAAY;IASvB,YAAY,KAAsB,EAAE,OAA6B,EAAE,MAAe;QAP1E,eAAU,GAAoB,IAAI,GAAG,EAAE,CAAC;QAExC,UAAK,GAAyC,IAAI,CAAC;QACnD,oBAAe,GAAY,KAAK,CAAC;QACjC,aAAQ,GAAY,KAAK,CAAC;QAIhC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,eAAe,GAAG,OAAO,EAAE,eAAe,IAAI,IAAI,CAAC;QACxD,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,sBAAY,CAAC,IAAA,4BAAkB,GAAE,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;IACvF,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,SAAqB;QAC5B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC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AC,MAAM,CAAC,KAAK,CAAC,WAAW,KAAK,gBAAgB,SAAS,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;gBAClF,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,SAAS,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;gBACjF,CAAC;YACH,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC/B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;QACD,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF;AA9FD,oCA8FC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { LocalCacheStore } from "./LocalCacheStore";
|
|
2
|
+
import { CryptoAdapter } from "../crypto/CryptoAdapter";
|
|
3
|
+
import { Logger } from "../logging";
|
|
4
|
+
/**
|
|
5
|
+
* Transparent encryption wrapper around any {@link LocalCacheStore}.
|
|
6
|
+
*
|
|
7
|
+
* - Encrypts values on `put()`, decrypts on `get()`
|
|
8
|
+
* - Keys (type + id) are passed through unmodified
|
|
9
|
+
* - Uses AES-256-GCM with a key derived from the user's password via PBKDF2
|
|
10
|
+
* - If decryption fails (password changed, corruption) returns `null`
|
|
11
|
+
*/
|
|
12
|
+
export declare class EncryptedLocalCacheStore implements LocalCacheStore {
|
|
13
|
+
private inner;
|
|
14
|
+
private cryptoAdapter;
|
|
15
|
+
private derivedKey;
|
|
16
|
+
private keyPromise;
|
|
17
|
+
private logger;
|
|
18
|
+
/**
|
|
19
|
+
* @param inner The underlying (plaintext) cache store
|
|
20
|
+
* @param userPassword The user's password used to derive the encryption key
|
|
21
|
+
* @param cryptoAdapter Platform-agnostic crypto interface
|
|
22
|
+
* @param logger Optional logger
|
|
23
|
+
*/
|
|
24
|
+
constructor(inner: LocalCacheStore, userPassword: string, cryptoAdapter: CryptoAdapter, logger?: Logger);
|
|
25
|
+
private deriveKey;
|
|
26
|
+
private getKey;
|
|
27
|
+
/**
|
|
28
|
+
* Ensure the Uint8Array owns its entire backing ArrayBuffer (byteOffset=0,
|
|
29
|
+
* byteLength=buffer.byteLength). Some React Native crypto polyfills
|
|
30
|
+
* access `.buffer` directly, which would read wrong data for sub-views.
|
|
31
|
+
*/
|
|
32
|
+
private static ensureOwnedBuffer;
|
|
33
|
+
private encrypt;
|
|
34
|
+
private decrypt;
|
|
35
|
+
get(type: string, id: string): Promise<Uint8Array | null>;
|
|
36
|
+
put(type: string, id: string, value: Uint8Array): Promise<void>;
|
|
37
|
+
delete(type: string, id: string): Promise<void>;
|
|
38
|
+
list(type: string): Promise<string[]>;
|
|
39
|
+
clear(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=EncryptedLocalCacheStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EncryptedLocalCacheStore.d.ts","sourceRoot":"","sources":["../../../src/core/cache/EncryptedLocalCacheStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAoC,MAAM,YAAY,CAAC;AAEtE;;;;;;;GAOG;AACH,qBAAa,wBAAyB,YAAW,eAAe;IAC9D,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,UAAU,CAA0B;IAC5C,OAAO,CAAC,UAAU,CAAmC;IACrD,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;;OAKG;gBAED,KAAK,EAAE,eAAe,EACtB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,aAAa,EAC5B,MAAM,CAAC,EAAE,MAAM;YAQH,SAAS;YAqCT,MAAM;IAKpB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;YASlB,OAAO;YAqBP,OAAO;IA6Bf,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAMzD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/D,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIrC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EncryptedLocalCacheStore = void 0;
|
|
4
|
+
const pbkdf2Iterations_1 = require("../crypto/pbkdf2Iterations");
|
|
5
|
+
const logging_1 = require("../logging");
|
|
6
|
+
/**
|
|
7
|
+
* Transparent encryption wrapper around any {@link LocalCacheStore}.
|
|
8
|
+
*
|
|
9
|
+
* - Encrypts values on `put()`, decrypts on `get()`
|
|
10
|
+
* - Keys (type + id) are passed through unmodified
|
|
11
|
+
* - Uses AES-256-GCM with a key derived from the user's password via PBKDF2
|
|
12
|
+
* - If decryption fails (password changed, corruption) returns `null`
|
|
13
|
+
*/
|
|
14
|
+
class EncryptedLocalCacheStore {
|
|
15
|
+
/**
|
|
16
|
+
* @param inner The underlying (plaintext) cache store
|
|
17
|
+
* @param userPassword The user's password used to derive the encryption key
|
|
18
|
+
* @param cryptoAdapter Platform-agnostic crypto interface
|
|
19
|
+
* @param logger Optional logger
|
|
20
|
+
*/
|
|
21
|
+
constructor(inner, userPassword, cryptoAdapter, logger) {
|
|
22
|
+
this.derivedKey = null;
|
|
23
|
+
this.keyPromise = null;
|
|
24
|
+
this.inner = inner;
|
|
25
|
+
this.cryptoAdapter = cryptoAdapter;
|
|
26
|
+
this.logger = logger || new logging_1.MindooLogger((0, logging_1.getDefaultLogLevel)(), "EncryptedLocalCacheStore", true);
|
|
27
|
+
this.keyPromise = this.deriveKey(userPassword);
|
|
28
|
+
}
|
|
29
|
+
async deriveKey(password) {
|
|
30
|
+
const subtle = this.cryptoAdapter.getSubtle();
|
|
31
|
+
const saltString = "mindoodb-cache-encryption:v1";
|
|
32
|
+
const salt = new TextEncoder().encode(saltString);
|
|
33
|
+
const passwordInput = new TextEncoder().encode(password);
|
|
34
|
+
const baseKey = await subtle.importKey("raw", passwordInput.buffer, "PBKDF2", false, ["deriveKey"]);
|
|
35
|
+
const iterations = (0, pbkdf2Iterations_1.resolvePbkdf2Iterations)(pbkdf2Iterations_1.DEFAULT_PBKDF2_ITERATIONS);
|
|
36
|
+
if (iterations !== pbkdf2Iterations_1.DEFAULT_PBKDF2_ITERATIONS) {
|
|
37
|
+
this.logger.warn(`Using overridden PBKDF2 iterations for cache key derivation: ${iterations}`);
|
|
38
|
+
}
|
|
39
|
+
const key = await subtle.deriveKey({
|
|
40
|
+
name: "PBKDF2",
|
|
41
|
+
salt: salt.buffer,
|
|
42
|
+
iterations,
|
|
43
|
+
hash: "SHA-256",
|
|
44
|
+
}, baseKey, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
45
|
+
this.derivedKey = key;
|
|
46
|
+
return key;
|
|
47
|
+
}
|
|
48
|
+
async getKey() {
|
|
49
|
+
if (this.derivedKey)
|
|
50
|
+
return this.derivedKey;
|
|
51
|
+
return this.keyPromise;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Ensure the Uint8Array owns its entire backing ArrayBuffer (byteOffset=0,
|
|
55
|
+
* byteLength=buffer.byteLength). Some React Native crypto polyfills
|
|
56
|
+
* access `.buffer` directly, which would read wrong data for sub-views.
|
|
57
|
+
*/
|
|
58
|
+
static ensureOwnedBuffer(arr) {
|
|
59
|
+
if (arr.byteOffset !== 0 || arr.byteLength !== arr.buffer.byteLength) {
|
|
60
|
+
const copy = new Uint8Array(arr.byteLength);
|
|
61
|
+
copy.set(arr);
|
|
62
|
+
return copy;
|
|
63
|
+
}
|
|
64
|
+
return arr;
|
|
65
|
+
}
|
|
66
|
+
async encrypt(plaintext) {
|
|
67
|
+
const subtle = this.cryptoAdapter.getSubtle();
|
|
68
|
+
const key = await this.getKey();
|
|
69
|
+
const iv = new Uint8Array(12);
|
|
70
|
+
this.cryptoAdapter.getRandomValues(iv);
|
|
71
|
+
const safeData = EncryptedLocalCacheStore.ensureOwnedBuffer(plaintext);
|
|
72
|
+
const ciphertext = await subtle.encrypt({ name: "AES-GCM", iv: iv.buffer, tagLength: 128 }, key, safeData.buffer);
|
|
73
|
+
// Format: IV (12 bytes) + ciphertext+tag (variable)
|
|
74
|
+
const result = new Uint8Array(12 + ciphertext.byteLength);
|
|
75
|
+
result.set(iv, 0);
|
|
76
|
+
result.set(new Uint8Array(ciphertext), 12);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
async decrypt(data) {
|
|
80
|
+
if (data.length < 12 + 16) {
|
|
81
|
+
this.logger.warn("Encrypted cache entry too short, treating as corrupt");
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const subtle = this.cryptoAdapter.getSubtle();
|
|
86
|
+
const key = await this.getKey();
|
|
87
|
+
// .slice() creates copies with their own backing ArrayBuffer
|
|
88
|
+
const iv = data.slice(0, 12);
|
|
89
|
+
const ciphertext = data.slice(12);
|
|
90
|
+
const plaintext = await subtle.decrypt({ name: "AES-GCM", iv: iv.buffer, tagLength: 128 }, key, ciphertext.buffer);
|
|
91
|
+
return new Uint8Array(plaintext);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
this.logger.warn(`Cache decryption failed (password changed or data corrupt): ${e}`);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// --- LocalCacheStore interface ---
|
|
99
|
+
async get(type, id) {
|
|
100
|
+
const encrypted = await this.inner.get(type, id);
|
|
101
|
+
if (!encrypted)
|
|
102
|
+
return null;
|
|
103
|
+
return this.decrypt(encrypted);
|
|
104
|
+
}
|
|
105
|
+
async put(type, id, value) {
|
|
106
|
+
const encrypted = await this.encrypt(value);
|
|
107
|
+
return this.inner.put(type, id, encrypted);
|
|
108
|
+
}
|
|
109
|
+
async delete(type, id) {
|
|
110
|
+
return this.inner.delete(type, id);
|
|
111
|
+
}
|
|
112
|
+
async list(type) {
|
|
113
|
+
return this.inner.list(type);
|
|
114
|
+
}
|
|
115
|
+
async clear() {
|
|
116
|
+
return this.inner.clear();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.EncryptedLocalCacheStore = EncryptedLocalCacheStore;
|
|
120
|
+
//# sourceMappingURL=EncryptedLocalCacheStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EncryptedLocalCacheStore.js","sourceRoot":"","sources":["../../../src/core/cache/EncryptedLocalCacheStore.ts"],"names":[],"mappings":";;;AAEA,iEAAgG;AAChG,wCAAsE;AAEtE;;;;;;;GAOG;AACH,MAAa,wBAAwB;IAOnC;;;;;OAKG;IACH,YACE,KAAsB,EACtB,YAAoB,EACpB,aAA4B,EAC5B,MAAe;QAdT,eAAU,GAAqB,IAAI,CAAC;QACpC,eAAU,GAA8B,IAAI,CAAC;QAenD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CA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C;IACjC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,EAAU,EAAE,KAAiB;QACnD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,EAAU;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF;AAzJD,4DAyJC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple mutable key-value store for local cache data.
|
|
3
|
+
*
|
|
4
|
+
* Keys are structured as (type, id) pairs where:
|
|
5
|
+
* - `type` groups related entries (e.g. "db-meta", "doc", "vv")
|
|
6
|
+
* - `id` is caller-defined and may include tenant/store/doc scoping
|
|
7
|
+
*
|
|
8
|
+
* All values are opaque `Uint8Array`. Encryption is handled externally
|
|
9
|
+
* (e.g. by wrapping with {@link EncryptedLocalCacheStore}).
|
|
10
|
+
*
|
|
11
|
+
* One implementation per platform (Node.js filesystem, IndexedDB, MMKV),
|
|
12
|
+
* but the interface is open for custom implementations.
|
|
13
|
+
*/
|
|
14
|
+
export interface LocalCacheStore {
|
|
15
|
+
/**
|
|
16
|
+
* Retrieve a cached value.
|
|
17
|
+
* @returns The value, or `null` if not found.
|
|
18
|
+
*/
|
|
19
|
+
get(type: string, id: string): Promise<Uint8Array | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Store (or overwrite) a cached value.
|
|
22
|
+
*/
|
|
23
|
+
put(type: string, id: string, value: Uint8Array): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Delete a single cached value.
|
|
26
|
+
*/
|
|
27
|
+
delete(type: string, id: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* List all ids stored under the given type.
|
|
30
|
+
*/
|
|
31
|
+
list(type: string): Promise<string[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Wipe all data from the cache store.
|
|
34
|
+
*/
|
|
35
|
+
clear(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Trivial in-memory implementation of {@link LocalCacheStore}.
|
|
39
|
+
* Useful for tests and as a reference implementation.
|
|
40
|
+
*/
|
|
41
|
+
export declare class InMemoryLocalCacheStore implements LocalCacheStore {
|
|
42
|
+
private data;
|
|
43
|
+
private toKey;
|
|
44
|
+
get(type: string, id: string): Promise<Uint8Array | null>;
|
|
45
|
+
put(type: string, id: string, value: Uint8Array): Promise<void>;
|
|
46
|
+
delete(type: string, id: string): Promise<void>;
|
|
47
|
+
list(type: string): Promise<string[]>;
|
|
48
|
+
clear(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=LocalCacheStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalCacheStore.d.ts","sourceRoot":"","sources":["../../../src/core/cache/LocalCacheStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAE1D;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;OAE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