mindoodb 0.0.1
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 +263 -0
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts +5 -0
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts.map +1 -0
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js +17 -0
- package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js.map +1 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +111 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +237 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -0
- package/dist/appendonlystores/network/HttpTransport.d.ts +78 -0
- package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -0
- package/dist/appendonlystores/network/HttpTransport.js +356 -0
- package/dist/appendonlystores/network/HttpTransport.js.map +1 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +131 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +248 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -0
- package/dist/appendonlystores/network/index.d.ts +8 -0
- package/dist/appendonlystores/network/index.d.ts.map +1 -0
- package/dist/appendonlystores/network/index.js +21 -0
- package/dist/appendonlystores/network/index.js.map +1 -0
- package/dist/browser/crypto/BrowserCryptoAdapter.d.ts +14 -0
- package/dist/browser/crypto/BrowserCryptoAdapter.d.ts.map +1 -0
- package/dist/browser/crypto/BrowserCryptoAdapter.js +30 -0
- package/dist/browser/crypto/BrowserCryptoAdapter.js.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +26 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/core/BaseMindooDB.d.ts +182 -0
- package/dist/core/BaseMindooDB.d.ts.map +1 -0
- package/dist/core/BaseMindooDB.js +1701 -0
- package/dist/core/BaseMindooDB.js.map +1 -0
- package/dist/core/BaseMindooTenant.d.ts +155 -0
- package/dist/core/BaseMindooTenant.d.ts.map +1 -0
- package/dist/core/BaseMindooTenant.js +673 -0
- package/dist/core/BaseMindooTenant.js.map +1 -0
- package/dist/core/BaseMindooTenantDirectory.d.ts +99 -0
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -0
- package/dist/core/BaseMindooTenantDirectory.js +776 -0
- package/dist/core/BaseMindooTenantDirectory.js.map +1 -0
- package/dist/core/BaseMindooTenantFactory.d.ts +91 -0
- package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -0
- package/dist/core/BaseMindooTenantFactory.js +297 -0
- package/dist/core/BaseMindooTenantFactory.js.map +1 -0
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts +111 -0
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts.map +1 -0
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js +293 -0
- package/dist/core/appendonlystores/InMemoryContentAddressedStore.js.map +1 -0
- package/dist/core/appendonlystores/network/AuthenticationService.d.ts +78 -0
- package/dist/core/appendonlystores/network/AuthenticationService.d.ts.map +1 -0
- package/dist/core/appendonlystores/network/AuthenticationService.js +297 -0
- package/dist/core/appendonlystores/network/AuthenticationService.js.map +1 -0
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts +174 -0
- package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -0
- package/dist/core/appendonlystores/network/NetworkTransport.js +3 -0
- package/dist/core/appendonlystores/network/NetworkTransport.js.map +1 -0
- package/dist/core/appendonlystores/network/types.d.ts +135 -0
- package/dist/core/appendonlystores/network/types.d.ts.map +1 -0
- package/dist/core/appendonlystores/network/types.js +35 -0
- package/dist/core/appendonlystores/network/types.js.map +1 -0
- package/dist/core/appendonlystores/types.d.ts +157 -0
- package/dist/core/appendonlystores/types.d.ts.map +1 -0
- package/dist/core/appendonlystores/types.js +3 -0
- package/dist/core/appendonlystores/types.js.map +1 -0
- package/dist/core/crypto/CryptoAdapter.d.ts +19 -0
- package/dist/core/crypto/CryptoAdapter.d.ts.map +1 -0
- package/dist/core/crypto/CryptoAdapter.js +3 -0
- package/dist/core/crypto/CryptoAdapter.js.map +1 -0
- package/dist/core/crypto/MindooDocSigner.d.ts +106 -0
- package/dist/core/crypto/MindooDocSigner.d.ts.map +1 -0
- package/dist/core/crypto/MindooDocSigner.js +192 -0
- package/dist/core/crypto/MindooDocSigner.js.map +1 -0
- package/dist/core/crypto/RSAEncryption.d.ts +62 -0
- package/dist/core/crypto/RSAEncryption.d.ts.map +1 -0
- package/dist/core/crypto/RSAEncryption.js +167 -0
- package/dist/core/crypto/RSAEncryption.js.map +1 -0
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +17 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +53 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts +33 -0
- package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js +27 -0
- package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js.map +1 -0
- package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.d.ts +31 -0
- package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.js +3 -0
- package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.js.map +1 -0
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts +52 -0
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +106 -0
- package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKey.d.ts +44 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKey.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKey.js +107 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKey.js.map +1 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts +28 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js +133 -0
- package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualView.d.ts +109 -0
- package/dist/core/indexing/virtualviews/VirtualView.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualView.js +504 -0
- package/dist/core/indexing/virtualviews/VirtualView.js.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewColumn.d.ts +59 -0
- package/dist/core/indexing/virtualviews/VirtualViewColumn.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewColumn.js +70 -0
- package/dist/core/indexing/virtualviews/VirtualViewColumn.js.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts +49 -0
- package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewDataChange.js +69 -0
- package/dist/core/indexing/virtualviews/VirtualViewDataChange.js.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts +121 -0
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.js +365 -0
- package/dist/core/indexing/virtualviews/VirtualViewEntryData.js.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts +131 -0
- package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewFactory.js +236 -0
- package/dist/core/indexing/virtualviews/VirtualViewFactory.js.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts +330 -0
- package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/VirtualViewNavigator.js +1010 -0
- package/dist/core/indexing/virtualviews/VirtualViewNavigator.js.map +1 -0
- package/dist/core/indexing/virtualviews/index.d.ts +53 -0
- package/dist/core/indexing/virtualviews/index.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/index.js +89 -0
- package/dist/core/indexing/virtualviews/index.js.map +1 -0
- package/dist/core/indexing/virtualviews/types.d.ts +115 -0
- package/dist/core/indexing/virtualviews/types.d.ts.map +1 -0
- package/dist/core/indexing/virtualviews/types.js +175 -0
- package/dist/core/indexing/virtualviews/types.js.map +1 -0
- package/dist/core/keys/KeyBag.d.ts +122 -0
- package/dist/core/keys/KeyBag.d.ts.map +1 -0
- package/dist/core/keys/KeyBag.js +401 -0
- package/dist/core/keys/KeyBag.js.map +1 -0
- package/dist/core/types.d.ts +1004 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +10 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/userid/index.d.ts +53 -0
- package/dist/core/userid/index.d.ts.map +1 -0
- package/dist/core/userid/index.js +3 -0
- package/dist/core/userid/index.js.map +1 -0
- package/dist/core/utils/idGeneration.d.ts +109 -0
- package/dist/core/utils/idGeneration.d.ts.map +1 -0
- package/dist/core/utils/idGeneration.js +182 -0
- package/dist/core/utils/idGeneration.js.map +1 -0
- package/dist/core/utils/index.d.ts +5 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/index.js +19 -0
- package/dist/core/utils/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/node/crypto/NodeCryptoAdapter.d.ts +16 -0
- package/dist/node/crypto/NodeCryptoAdapter.d.ts.map +1 -0
- package/dist/node/crypto/NodeCryptoAdapter.js +53 -0
- package/dist/node/crypto/NodeCryptoAdapter.js.map +1 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +26 -0
- package/dist/node/index.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryContentAddressedStoreFactory = exports.InMemoryContentAddressedStore = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A simple in-memory implementation of ContentAddressedStore for testing purposes.
|
|
6
|
+
*
|
|
7
|
+
* Uses dual-index storage:
|
|
8
|
+
* - Metadata indexed by entry id (primary key)
|
|
9
|
+
* - Encrypted bytes indexed by contentHash (for deduplication)
|
|
10
|
+
*
|
|
11
|
+
* This allows multiple entries to share the same encrypted bytes if they have
|
|
12
|
+
* the same contentHash, enabling storage-level deduplication.
|
|
13
|
+
*/
|
|
14
|
+
class InMemoryContentAddressedStore {
|
|
15
|
+
constructor(dbId) {
|
|
16
|
+
/** Metadata indexed by entry id */
|
|
17
|
+
this.entries = new Map();
|
|
18
|
+
/** Encrypted bytes indexed by contentHash (deduplicated) */
|
|
19
|
+
this.contentStore = new Map();
|
|
20
|
+
/** Index for finding entries by docId (for efficient doc queries) */
|
|
21
|
+
this.docIndex = new Map(); // docId -> Set<entryId>
|
|
22
|
+
this.dbId = dbId;
|
|
23
|
+
}
|
|
24
|
+
getId() {
|
|
25
|
+
return this.dbId;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Store one or more entries.
|
|
29
|
+
* - Metadata is stored by entry id (always unique)
|
|
30
|
+
* - Encrypted bytes are deduplicated by contentHash (same bytes stored once)
|
|
31
|
+
*
|
|
32
|
+
* @param entries The entries to store
|
|
33
|
+
* @return A promise that resolves when all entries are stored
|
|
34
|
+
*/
|
|
35
|
+
async putEntries(entries) {
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
// Check if we already have this entry by id (no-op if exists)
|
|
38
|
+
if (this.entries.has(entry.id)) {
|
|
39
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Entry ${entry.id} already exists, skipping`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// Separate metadata from encrypted data
|
|
43
|
+
const { encryptedData, ...metadata } = entry;
|
|
44
|
+
// Store metadata by id
|
|
45
|
+
this.entries.set(entry.id, metadata);
|
|
46
|
+
// Store bytes by contentHash (deduplication happens here)
|
|
47
|
+
if (!this.contentStore.has(entry.contentHash)) {
|
|
48
|
+
this.contentStore.set(entry.contentHash, encryptedData);
|
|
49
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Stored content for hash ${entry.contentHash.substring(0, 8)}...`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Content ${entry.contentHash.substring(0, 8)}... already exists (deduplicated)`);
|
|
53
|
+
}
|
|
54
|
+
// Update document index
|
|
55
|
+
if (!this.docIndex.has(entry.docId)) {
|
|
56
|
+
this.docIndex.set(entry.docId, new Set());
|
|
57
|
+
}
|
|
58
|
+
this.docIndex.get(entry.docId).add(entry.id);
|
|
59
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Stored entry ${entry.id} for doc ${entry.docId}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get entries by their IDs.
|
|
64
|
+
* Returns only entries that exist in this store.
|
|
65
|
+
*
|
|
66
|
+
* @param ids The IDs of the entries to fetch
|
|
67
|
+
* @return A list of entries (may be shorter than input if some don't exist)
|
|
68
|
+
*/
|
|
69
|
+
async getEntries(ids) {
|
|
70
|
+
const result = [];
|
|
71
|
+
for (const id of ids) {
|
|
72
|
+
const metadata = this.entries.get(id);
|
|
73
|
+
if (metadata) {
|
|
74
|
+
const encryptedData = this.contentStore.get(metadata.contentHash);
|
|
75
|
+
if (encryptedData) {
|
|
76
|
+
result.push({ ...metadata, encryptedData });
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.warn(`[InMemoryContentAddressedStore:${this.dbId}] Content ${metadata.contentHash} not found for entry ${id}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.warn(`[InMemoryContentAddressedStore:${this.dbId}] Entry ${id} not found`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Retrieved ${result.length} entries out of ${ids.length} requested`);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check which IDs from the provided list exist in this store.
|
|
91
|
+
*
|
|
92
|
+
* @param ids The IDs to check
|
|
93
|
+
* @return A list of IDs that exist in this store
|
|
94
|
+
*/
|
|
95
|
+
async hasEntries(ids) {
|
|
96
|
+
const existing = [];
|
|
97
|
+
for (const id of ids) {
|
|
98
|
+
if (this.entries.has(id)) {
|
|
99
|
+
existing.push(id);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Found ${existing.length} existing entries out of ${ids.length} checked`);
|
|
103
|
+
return existing;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Find entries in the store that are not listed in the given list of IDs.
|
|
107
|
+
* Used for synchronization to identify which entries we have that the peer doesn't.
|
|
108
|
+
*
|
|
109
|
+
* @param knownIds The list of entry IDs we already have
|
|
110
|
+
* @return A list of entry metadata for entries we have that aren't in knownIds
|
|
111
|
+
*/
|
|
112
|
+
async findNewEntries(knownIds) {
|
|
113
|
+
// Create a Set of IDs we already have for fast lookup
|
|
114
|
+
const knownIdsSet = new Set(knownIds);
|
|
115
|
+
// Find all entries we have that are not in the provided list
|
|
116
|
+
const newEntries = [];
|
|
117
|
+
for (const [id, metadata] of this.entries) {
|
|
118
|
+
if (!knownIdsSet.has(id)) {
|
|
119
|
+
newEntries.push(metadata);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Found ${newEntries.length} new entries out of ${this.entries.size} total`);
|
|
123
|
+
return newEntries;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Find entries in the store for a specific document that are not listed in the given list of IDs.
|
|
127
|
+
*
|
|
128
|
+
* @param knownIds The list of entry IDs we already have
|
|
129
|
+
* @param docId The ID of the document
|
|
130
|
+
* @return A list of entry metadata for entries we have that aren't in knownIds
|
|
131
|
+
*/
|
|
132
|
+
async findNewEntriesForDoc(knownIds, docId) {
|
|
133
|
+
// Create a Set of IDs we already have for fast lookup
|
|
134
|
+
const knownIdsSet = new Set(knownIds);
|
|
135
|
+
// Get entry IDs for this specific document
|
|
136
|
+
const docEntryIds = this.docIndex.get(docId) || new Set();
|
|
137
|
+
// Find all entries for this doc that are not in the provided list
|
|
138
|
+
const newEntries = [];
|
|
139
|
+
for (const id of docEntryIds) {
|
|
140
|
+
if (!knownIdsSet.has(id)) {
|
|
141
|
+
const metadata = this.entries.get(id);
|
|
142
|
+
if (metadata) {
|
|
143
|
+
newEntries.push(metadata);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Found ${newEntries.length} new entries for doc ${docId} out of ${docEntryIds.size} total`);
|
|
148
|
+
return newEntries;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get all entry IDs in the store.
|
|
152
|
+
* Used for synchronization to identify which entries we have.
|
|
153
|
+
*
|
|
154
|
+
* @return A list of all entry IDs in the store
|
|
155
|
+
*/
|
|
156
|
+
async getAllIds() {
|
|
157
|
+
const ids = Array.from(this.entries.keys());
|
|
158
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Returning ${ids.length} entry IDs`);
|
|
159
|
+
return ids;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Resolve the dependency chain starting from an entry ID.
|
|
163
|
+
* Returns IDs in dependency order (oldest first), traversing backward through dependencyIds.
|
|
164
|
+
*
|
|
165
|
+
* @param startId The entry ID to start traversal from
|
|
166
|
+
* @param options Optional traversal options:
|
|
167
|
+
* - stopAtEntryType: Stop when encountering an entry of this type (e.g., "doc_snapshot")
|
|
168
|
+
* - maxDepth: Maximum number of hops to traverse
|
|
169
|
+
* - includeStart: Whether to include startId in the result (default: true)
|
|
170
|
+
* @return A list of entry IDs in dependency order (oldest first)
|
|
171
|
+
*/
|
|
172
|
+
async resolveDependencies(startId, options) {
|
|
173
|
+
const stopAtEntryType = options?.stopAtEntryType;
|
|
174
|
+
const maxDepth = options?.maxDepth;
|
|
175
|
+
const includeStart = options?.includeStart !== false; // default: true
|
|
176
|
+
const result = [];
|
|
177
|
+
const visited = new Set();
|
|
178
|
+
const queue = [{ id: startId, depth: 0 }];
|
|
179
|
+
while (queue.length > 0) {
|
|
180
|
+
const { id, depth } = queue.shift();
|
|
181
|
+
// Skip if already visited
|
|
182
|
+
if (visited.has(id)) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
visited.add(id);
|
|
186
|
+
// Check max depth
|
|
187
|
+
if (maxDepth !== undefined && depth > maxDepth) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
// Get the entry metadata
|
|
191
|
+
const entry = this.entries.get(id);
|
|
192
|
+
if (!entry) {
|
|
193
|
+
console.warn(`[InMemoryContentAddressedStore:${this.dbId}] Entry ${id} not found during dependency resolution`);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
// Check stop condition
|
|
197
|
+
if (stopAtEntryType && entry.entryType === stopAtEntryType && id !== startId) {
|
|
198
|
+
// Include the stop entry but don't traverse its dependencies
|
|
199
|
+
result.push(id);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
// Add to result (unless it's the start ID and includeStart is false)
|
|
203
|
+
if (id !== startId || includeStart) {
|
|
204
|
+
result.push(id);
|
|
205
|
+
}
|
|
206
|
+
// Queue dependencies for traversal
|
|
207
|
+
for (const depId of entry.dependencyIds) {
|
|
208
|
+
if (!visited.has(depId)) {
|
|
209
|
+
queue.push({ id: depId, depth: depth + 1 });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Reverse to get oldest first (we traversed from newest to oldest)
|
|
214
|
+
result.reverse();
|
|
215
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Resolved ${result.length} dependencies for ${startId}`);
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Purge all entries for a specific document from the store.
|
|
220
|
+
* This breaks append-only semantics but is required for GDPR compliance.
|
|
221
|
+
*
|
|
222
|
+
* After purging, all entries for the specified document will be removed
|
|
223
|
+
* from the store. Content bytes that are no longer referenced by any
|
|
224
|
+
* entry will also be cleaned up.
|
|
225
|
+
*
|
|
226
|
+
* @param docId The document ID whose entries should be purged
|
|
227
|
+
* @return A promise that resolves when the purge is complete
|
|
228
|
+
*/
|
|
229
|
+
async purgeDocHistory(docId) {
|
|
230
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Purging entry history for document: ${docId}`);
|
|
231
|
+
// Get all entry IDs for this document
|
|
232
|
+
const docEntryIds = this.docIndex.get(docId);
|
|
233
|
+
if (!docEntryIds || docEntryIds.size === 0) {
|
|
234
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] No entries found for document ${docId}, nothing to purge`);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
// Collect contentHashes that might become orphaned
|
|
238
|
+
const contentHashesToCheck = new Set();
|
|
239
|
+
// Remove each entry
|
|
240
|
+
for (const id of docEntryIds) {
|
|
241
|
+
const metadata = this.entries.get(id);
|
|
242
|
+
if (metadata) {
|
|
243
|
+
contentHashesToCheck.add(metadata.contentHash);
|
|
244
|
+
this.entries.delete(id);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Remove document from docIndex
|
|
248
|
+
this.docIndex.delete(docId);
|
|
249
|
+
// Clean up orphaned content (no remaining entries reference it)
|
|
250
|
+
for (const contentHash of contentHashesToCheck) {
|
|
251
|
+
let isReferenced = false;
|
|
252
|
+
for (const [, meta] of this.entries) {
|
|
253
|
+
if (meta.contentHash === contentHash) {
|
|
254
|
+
isReferenced = true;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!isReferenced) {
|
|
259
|
+
this.contentStore.delete(contentHash);
|
|
260
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Cleaned up orphaned content ${contentHash.substring(0, 8)}...`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
console.log(`[InMemoryContentAddressedStore:${this.dbId}] Purged ${docEntryIds.size} entries for document ${docId}`);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get storage statistics for debugging/monitoring.
|
|
267
|
+
* @returns Object with entry count, content count, and doc count
|
|
268
|
+
*/
|
|
269
|
+
getStats() {
|
|
270
|
+
return {
|
|
271
|
+
entryCount: this.entries.size,
|
|
272
|
+
contentCount: this.contentStore.size,
|
|
273
|
+
docCount: this.docIndex.size,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.InMemoryContentAddressedStore = InMemoryContentAddressedStore;
|
|
278
|
+
/**
|
|
279
|
+
* Factory for creating InMemoryContentAddressedStore instances.
|
|
280
|
+
* Each database gets its own isolated in-memory store.
|
|
281
|
+
*/
|
|
282
|
+
class InMemoryContentAddressedStoreFactory {
|
|
283
|
+
createStore(dbId, _options) {
|
|
284
|
+
// For in-memory stores, we use a single store for both documents and attachments
|
|
285
|
+
// Note: options are ignored for in-memory stores but accepted for interface compatibility
|
|
286
|
+
return {
|
|
287
|
+
docStore: new InMemoryContentAddressedStore(dbId),
|
|
288
|
+
// attachmentStore not provided - will use docStore for attachments
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
exports.InMemoryContentAddressedStoreFactory = InMemoryContentAddressedStoreFactory;
|
|
293
|
+
//# sourceMappingURL=InMemoryContentAddressedStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryContentAddressedStore.js","sourceRoot":"","sources":["../../../src/core/appendonlystores/InMemoryContentAddressedStore.ts"],"names":[],"mappings":";;;AAWA;;;;;;;;;GASG;AACH,MAAa,6BAA6B;IAYxC,YAAY,IAAY;QATxB,mCAAmC;QAC3B,YAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;QAE7D,4DAA4D;QACpD,iBAAY,GAA4B,IAAI,GAAG,EAAE,CAAC;QAE1D,qEAAqE;QAC7D,aAAQ,GAA6B,IAAI,GAAG,EAAE,CAAC,CAAC,wBAAwB;QAG9E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,OAAqB;QACpC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,8DAA8D;YAC9D,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC/B,OAAO,CAAC,GAAG,CAAC,kCAAkC,IAAI,CAAC,IAAI,WAAW,KAAK,CAAC,EAAE,2BAA2B,CAAC,CAAC;gBACvG,SAAS;YACX,CAAC;YAED,wCAAwC;YACxC,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,CAAC;YAE7C,uBAAuB;YACvB,IAAI,CAAC,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ACH,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,kCAAkC,IAAI,CAAC,IAAI,YAAY,WAAW,CAAC,IAAI,yBAAyB,KAAK,EAAE,CAAC,CAAC;IACvH,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YAC7B,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI;YACpC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;SAC7B,CAAC;IACJ,CAAC;CACF;AAlTD,sEAkTC;AAED;;;GAGG;AACH,MAAa,oCAAoC;IAC/C,WAAW,CAAC,IAAY,EAAE,QAA2B;QACnD,iFAAiF;QACjF,0FAA0F;QAC1F,OAAO;YACL,QAAQ,EAAE,IAAI,6BAA6B,CAAC,IAAI,CAAC;YACjD,mEAAmE;SACpE,CAAC;IACJ,CAAC;CACF;AATD,oFASC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { CryptoAdapter } from "../../crypto/CryptoAdapter";
|
|
2
|
+
import type { MindooTenantDirectory } from "../../types";
|
|
3
|
+
import type { AuthResult, NetworkAuthTokenPayload } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Authentication service for network sync operations.
|
|
6
|
+
*
|
|
7
|
+
* Handles:
|
|
8
|
+
* - Challenge generation (UUID v7)
|
|
9
|
+
* - Signature verification using user's public signing key
|
|
10
|
+
* - JWT token generation and validation
|
|
11
|
+
* - User revocation checks
|
|
12
|
+
*
|
|
13
|
+
* Security features:
|
|
14
|
+
* - Single-use challenges prevent replay attacks
|
|
15
|
+
* - Challenge expiration (5 minutes default)
|
|
16
|
+
* - Token expiration (1 hour default)
|
|
17
|
+
* - Revocation checks against tenant directory
|
|
18
|
+
*/
|
|
19
|
+
export declare class AuthenticationService {
|
|
20
|
+
private cryptoAdapter;
|
|
21
|
+
private directory;
|
|
22
|
+
private tenantId;
|
|
23
|
+
private challenges;
|
|
24
|
+
private jwtSecret;
|
|
25
|
+
private challengeExpirationMs;
|
|
26
|
+
private tokenExpirationMs;
|
|
27
|
+
constructor(cryptoAdapter: CryptoAdapter, directory: MindooTenantDirectory, tenantId: string, options?: {
|
|
28
|
+
jwtSecret?: Uint8Array;
|
|
29
|
+
challengeExpirationMs?: number;
|
|
30
|
+
tokenExpirationMs?: number;
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Generate a challenge for a user to sign.
|
|
34
|
+
*
|
|
35
|
+
* @param username The username requesting authentication
|
|
36
|
+
* @returns The challenge string (UUID v7)
|
|
37
|
+
* @throws NetworkError if user not found or revoked
|
|
38
|
+
*/
|
|
39
|
+
generateChallenge(username: string): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Authenticate a user by verifying their signed challenge.
|
|
42
|
+
*
|
|
43
|
+
* @param challenge The challenge string
|
|
44
|
+
* @param signature The Ed25519 signature of the challenge
|
|
45
|
+
* @returns AuthResult with success status and JWT token
|
|
46
|
+
*/
|
|
47
|
+
authenticate(challenge: string, signature: Uint8Array): Promise<AuthResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Validate a JWT token.
|
|
50
|
+
*
|
|
51
|
+
* @param token The JWT token to validate
|
|
52
|
+
* @returns The token payload if valid, null otherwise
|
|
53
|
+
*/
|
|
54
|
+
validateToken(token: string): Promise<NetworkAuthTokenPayload | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Verify an Ed25519 signature.
|
|
57
|
+
*/
|
|
58
|
+
private verifySignature;
|
|
59
|
+
/**
|
|
60
|
+
* Generate a JWT token.
|
|
61
|
+
* Uses HMAC-SHA256 for signing.
|
|
62
|
+
*/
|
|
63
|
+
private generateToken;
|
|
64
|
+
/**
|
|
65
|
+
* Verify and decode a JWT token.
|
|
66
|
+
*/
|
|
67
|
+
private verifyToken;
|
|
68
|
+
/**
|
|
69
|
+
* Clean up expired challenges.
|
|
70
|
+
*/
|
|
71
|
+
private cleanupExpiredChallenges;
|
|
72
|
+
private base64UrlEncode;
|
|
73
|
+
private base64UrlDecode;
|
|
74
|
+
private uint8ArrayToBase64Url;
|
|
75
|
+
private base64UrlToUint8Array;
|
|
76
|
+
private base64ToUint8Array;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=AuthenticationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthenticationService.d.ts","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/AuthenticationService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAEV,UAAU,EACV,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,SAAS,CAAwB;IACzC,OAAO,CAAC,QAAQ,CAAS;IAGzB,OAAO,CAAC,UAAU,CAAyC;IAG3D,OAAO,CAAC,SAAS,CAAa;IAG9B,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,iBAAiB,CAAS;gBAGhC,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,qBAAqB,EAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,UAAU,CAAC;QACvB,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;IAcH;;;;;;OAMG;IACG,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoC1D;;;;;;OAMG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAwEjF;;;;;OAKG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM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