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.
Files changed (170) hide show
  1. package/README.md +263 -0
  2. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts +5 -0
  3. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts.map +1 -0
  4. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js +17 -0
  5. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js.map +1 -0
  6. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +111 -0
  7. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -0
  8. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +237 -0
  9. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -0
  10. package/dist/appendonlystores/network/HttpTransport.d.ts +78 -0
  11. package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -0
  12. package/dist/appendonlystores/network/HttpTransport.js +356 -0
  13. package/dist/appendonlystores/network/HttpTransport.js.map +1 -0
  14. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +131 -0
  15. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -0
  16. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +248 -0
  17. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -0
  18. package/dist/appendonlystores/network/index.d.ts +8 -0
  19. package/dist/appendonlystores/network/index.d.ts.map +1 -0
  20. package/dist/appendonlystores/network/index.js +21 -0
  21. package/dist/appendonlystores/network/index.js.map +1 -0
  22. package/dist/browser/crypto/BrowserCryptoAdapter.d.ts +14 -0
  23. package/dist/browser/crypto/BrowserCryptoAdapter.d.ts.map +1 -0
  24. package/dist/browser/crypto/BrowserCryptoAdapter.js +30 -0
  25. package/dist/browser/crypto/BrowserCryptoAdapter.js.map +1 -0
  26. package/dist/browser/index.d.ts +3 -0
  27. package/dist/browser/index.d.ts.map +1 -0
  28. package/dist/browser/index.js +26 -0
  29. package/dist/browser/index.js.map +1 -0
  30. package/dist/core/BaseMindooDB.d.ts +182 -0
  31. package/dist/core/BaseMindooDB.d.ts.map +1 -0
  32. package/dist/core/BaseMindooDB.js +1701 -0
  33. package/dist/core/BaseMindooDB.js.map +1 -0
  34. package/dist/core/BaseMindooTenant.d.ts +155 -0
  35. package/dist/core/BaseMindooTenant.d.ts.map +1 -0
  36. package/dist/core/BaseMindooTenant.js +673 -0
  37. package/dist/core/BaseMindooTenant.js.map +1 -0
  38. package/dist/core/BaseMindooTenantDirectory.d.ts +99 -0
  39. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -0
  40. package/dist/core/BaseMindooTenantDirectory.js +776 -0
  41. package/dist/core/BaseMindooTenantDirectory.js.map +1 -0
  42. package/dist/core/BaseMindooTenantFactory.d.ts +91 -0
  43. package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -0
  44. package/dist/core/BaseMindooTenantFactory.js +297 -0
  45. package/dist/core/BaseMindooTenantFactory.js.map +1 -0
  46. package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts +111 -0
  47. package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts.map +1 -0
  48. package/dist/core/appendonlystores/InMemoryContentAddressedStore.js +293 -0
  49. package/dist/core/appendonlystores/InMemoryContentAddressedStore.js.map +1 -0
  50. package/dist/core/appendonlystores/network/AuthenticationService.d.ts +78 -0
  51. package/dist/core/appendonlystores/network/AuthenticationService.d.ts.map +1 -0
  52. package/dist/core/appendonlystores/network/AuthenticationService.js +297 -0
  53. package/dist/core/appendonlystores/network/AuthenticationService.js.map +1 -0
  54. package/dist/core/appendonlystores/network/NetworkTransport.d.ts +174 -0
  55. package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -0
  56. package/dist/core/appendonlystores/network/NetworkTransport.js +3 -0
  57. package/dist/core/appendonlystores/network/NetworkTransport.js.map +1 -0
  58. package/dist/core/appendonlystores/network/types.d.ts +135 -0
  59. package/dist/core/appendonlystores/network/types.d.ts.map +1 -0
  60. package/dist/core/appendonlystores/network/types.js +35 -0
  61. package/dist/core/appendonlystores/network/types.js.map +1 -0
  62. package/dist/core/appendonlystores/types.d.ts +157 -0
  63. package/dist/core/appendonlystores/types.d.ts.map +1 -0
  64. package/dist/core/appendonlystores/types.js +3 -0
  65. package/dist/core/appendonlystores/types.js.map +1 -0
  66. package/dist/core/crypto/CryptoAdapter.d.ts +19 -0
  67. package/dist/core/crypto/CryptoAdapter.d.ts.map +1 -0
  68. package/dist/core/crypto/CryptoAdapter.js +3 -0
  69. package/dist/core/crypto/CryptoAdapter.js.map +1 -0
  70. package/dist/core/crypto/MindooDocSigner.d.ts +106 -0
  71. package/dist/core/crypto/MindooDocSigner.d.ts.map +1 -0
  72. package/dist/core/crypto/MindooDocSigner.js +192 -0
  73. package/dist/core/crypto/MindooDocSigner.js.map +1 -0
  74. package/dist/core/crypto/RSAEncryption.d.ts +62 -0
  75. package/dist/core/crypto/RSAEncryption.d.ts.map +1 -0
  76. package/dist/core/crypto/RSAEncryption.js +167 -0
  77. package/dist/core/crypto/RSAEncryption.js.map +1 -0
  78. package/dist/core/errors.d.ts +10 -0
  79. package/dist/core/errors.d.ts.map +1 -0
  80. package/dist/core/errors.js +17 -0
  81. package/dist/core/errors.js.map +1 -0
  82. package/dist/core/index.d.ts +14 -0
  83. package/dist/core/index.d.ts.map +1 -0
  84. package/dist/core/index.js +53 -0
  85. package/dist/core/index.js.map +1 -0
  86. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts +33 -0
  87. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts.map +1 -0
  88. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js +27 -0
  89. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js.map +1 -0
  90. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.d.ts +31 -0
  91. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.d.ts.map +1 -0
  92. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.js +3 -0
  93. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.js.map +1 -0
  94. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts +52 -0
  95. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts.map +1 -0
  96. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +106 -0
  97. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -0
  98. package/dist/core/indexing/virtualviews/ViewEntrySortKey.d.ts +44 -0
  99. package/dist/core/indexing/virtualviews/ViewEntrySortKey.d.ts.map +1 -0
  100. package/dist/core/indexing/virtualviews/ViewEntrySortKey.js +107 -0
  101. package/dist/core/indexing/virtualviews/ViewEntrySortKey.js.map +1 -0
  102. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts +28 -0
  103. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts.map +1 -0
  104. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js +133 -0
  105. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js.map +1 -0
  106. package/dist/core/indexing/virtualviews/VirtualView.d.ts +109 -0
  107. package/dist/core/indexing/virtualviews/VirtualView.d.ts.map +1 -0
  108. package/dist/core/indexing/virtualviews/VirtualView.js +504 -0
  109. package/dist/core/indexing/virtualviews/VirtualView.js.map +1 -0
  110. package/dist/core/indexing/virtualviews/VirtualViewColumn.d.ts +59 -0
  111. package/dist/core/indexing/virtualviews/VirtualViewColumn.d.ts.map +1 -0
  112. package/dist/core/indexing/virtualviews/VirtualViewColumn.js +70 -0
  113. package/dist/core/indexing/virtualviews/VirtualViewColumn.js.map +1 -0
  114. package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts +49 -0
  115. package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts.map +1 -0
  116. package/dist/core/indexing/virtualviews/VirtualViewDataChange.js +69 -0
  117. package/dist/core/indexing/virtualviews/VirtualViewDataChange.js.map +1 -0
  118. package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts +121 -0
  119. package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts.map +1 -0
  120. package/dist/core/indexing/virtualviews/VirtualViewEntryData.js +365 -0
  121. package/dist/core/indexing/virtualviews/VirtualViewEntryData.js.map +1 -0
  122. package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts +131 -0
  123. package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts.map +1 -0
  124. package/dist/core/indexing/virtualviews/VirtualViewFactory.js +236 -0
  125. package/dist/core/indexing/virtualviews/VirtualViewFactory.js.map +1 -0
  126. package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts +330 -0
  127. package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts.map +1 -0
  128. package/dist/core/indexing/virtualviews/VirtualViewNavigator.js +1010 -0
  129. package/dist/core/indexing/virtualviews/VirtualViewNavigator.js.map +1 -0
  130. package/dist/core/indexing/virtualviews/index.d.ts +53 -0
  131. package/dist/core/indexing/virtualviews/index.d.ts.map +1 -0
  132. package/dist/core/indexing/virtualviews/index.js +89 -0
  133. package/dist/core/indexing/virtualviews/index.js.map +1 -0
  134. package/dist/core/indexing/virtualviews/types.d.ts +115 -0
  135. package/dist/core/indexing/virtualviews/types.d.ts.map +1 -0
  136. package/dist/core/indexing/virtualviews/types.js +175 -0
  137. package/dist/core/indexing/virtualviews/types.js.map +1 -0
  138. package/dist/core/keys/KeyBag.d.ts +122 -0
  139. package/dist/core/keys/KeyBag.d.ts.map +1 -0
  140. package/dist/core/keys/KeyBag.js +401 -0
  141. package/dist/core/keys/KeyBag.js.map +1 -0
  142. package/dist/core/types.d.ts +1004 -0
  143. package/dist/core/types.d.ts.map +1 -0
  144. package/dist/core/types.js +10 -0
  145. package/dist/core/types.js.map +1 -0
  146. package/dist/core/userid/index.d.ts +53 -0
  147. package/dist/core/userid/index.d.ts.map +1 -0
  148. package/dist/core/userid/index.js +3 -0
  149. package/dist/core/userid/index.js.map +1 -0
  150. package/dist/core/utils/idGeneration.d.ts +109 -0
  151. package/dist/core/utils/idGeneration.d.ts.map +1 -0
  152. package/dist/core/utils/idGeneration.js +182 -0
  153. package/dist/core/utils/idGeneration.js.map +1 -0
  154. package/dist/core/utils/index.d.ts +5 -0
  155. package/dist/core/utils/index.d.ts.map +1 -0
  156. package/dist/core/utils/index.js +19 -0
  157. package/dist/core/utils/index.js.map +1 -0
  158. package/dist/index.d.ts +7 -0
  159. package/dist/index.d.ts.map +1 -0
  160. package/dist/index.js +40 -0
  161. package/dist/index.js.map +1 -0
  162. package/dist/node/crypto/NodeCryptoAdapter.d.ts +16 -0
  163. package/dist/node/crypto/NodeCryptoAdapter.d.ts.map +1 -0
  164. package/dist/node/crypto/NodeCryptoAdapter.js +53 -0
  165. package/dist/node/crypto/NodeCryptoAdapter.js.map +1 -0
  166. package/dist/node/index.d.ts +3 -0
  167. package/dist/node/index.d.ts.map +1 -0
  168. package/dist/node/index.js +26 -0
  169. package/dist/node/index.js.map +1 -0
  170. package/package.json +58 -0
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServerNetworkContentAddressedStore = void 0;
4
+ const types_1 = require("../../core/appendonlystores/network/types");
5
+ const RSAEncryption_1 = require("../../core/crypto/RSAEncryption");
6
+ /**
7
+ * Server-side network handler for ContentAddressedStore operations.
8
+ *
9
+ * This class handles incoming sync requests from clients:
10
+ * 1. Validates authentication tokens
11
+ * 2. Retrieves entries from the local store
12
+ * 3. Encrypts entries with the requesting user's RSA public key
13
+ * 4. Returns encrypted entries to the client
14
+ *
15
+ * This is not a ContentAddressedStore implementation itself, but rather
16
+ * a service that wraps a local ContentAddressedStore and handles network requests.
17
+ */
18
+ class ServerNetworkContentAddressedStore {
19
+ /**
20
+ * Create a new ServerNetworkContentAddressedStore.
21
+ *
22
+ * @param localStore The local store containing the actual data
23
+ * @param directory The tenant directory for user lookup
24
+ * @param authService The authentication service for token validation
25
+ * @param cryptoAdapter The crypto adapter for encryption
26
+ */
27
+ constructor(localStore, directory, authService, cryptoAdapter) {
28
+ this.localStore = localStore;
29
+ this.directory = directory;
30
+ this.authService = authService;
31
+ this.cryptoAdapter = cryptoAdapter;
32
+ this.rsaEncryption = new RSAEncryption_1.RSAEncryption(cryptoAdapter);
33
+ }
34
+ /**
35
+ * Get the ID of the underlying store.
36
+ */
37
+ getId() {
38
+ return this.localStore.getId();
39
+ }
40
+ /**
41
+ * Handle a challenge request from a client.
42
+ *
43
+ * @param username The username requesting authentication
44
+ * @returns The challenge string
45
+ */
46
+ async handleChallengeRequest(username) {
47
+ console.log(`[ServerNetworkContentAddressedStore] Handling challenge request for user: ${username}`);
48
+ return this.authService.generateChallenge(username);
49
+ }
50
+ /**
51
+ * Handle an authentication request from a client.
52
+ *
53
+ * @param challenge The challenge string
54
+ * @param signature The client's signature
55
+ * @returns The authentication result with JWT token
56
+ */
57
+ async handleAuthenticate(challenge, signature) {
58
+ console.log(`[ServerNetworkContentAddressedStore] Handling authentication for challenge: ${challenge}`);
59
+ return this.authService.authenticate(challenge, signature);
60
+ }
61
+ /**
62
+ * Handle a findNewEntries request from a client.
63
+ *
64
+ * @param token The JWT access token
65
+ * @param knownIds The entry IDs the client already has
66
+ * @returns List of new entry metadata
67
+ */
68
+ async handleFindNewEntries(token, knownIds) {
69
+ console.log(`[ServerNetworkContentAddressedStore] Handling findNewEntries request`);
70
+ // Validate token
71
+ const tokenPayload = await this.validateToken(token);
72
+ console.log(`[ServerNetworkContentAddressedStore] Token validated for user: ${tokenPayload.sub}`);
73
+ // Find new entries
74
+ const newEntries = await this.localStore.findNewEntries(knownIds);
75
+ console.log(`[ServerNetworkContentAddressedStore] Found ${newEntries.length} new entries`);
76
+ return newEntries;
77
+ }
78
+ /**
79
+ * Handle a findNewEntriesForDoc request from a client.
80
+ * This is an optimized version that only returns entries for a specific document.
81
+ *
82
+ * @param token The JWT access token
83
+ * @param knownIds The entry IDs the client already has for this document
84
+ * @param docId The document ID to filter by
85
+ * @returns List of new entry metadata for the specified document
86
+ */
87
+ async handleFindNewEntriesForDoc(token, knownIds, docId) {
88
+ console.log(`[ServerNetworkContentAddressedStore] Handling findNewEntriesForDoc request for doc ${docId}`);
89
+ // Validate token
90
+ const tokenPayload = await this.validateToken(token);
91
+ console.log(`[ServerNetworkContentAddressedStore] Token validated for user: ${tokenPayload.sub}`);
92
+ // Find new entries for the specific document
93
+ const newEntries = await this.localStore.findNewEntriesForDoc(knownIds, docId);
94
+ console.log(`[ServerNetworkContentAddressedStore] Found ${newEntries.length} new entries for doc ${docId}`);
95
+ return newEntries;
96
+ }
97
+ /**
98
+ * Handle a getEntries request from a client.
99
+ * Encrypts the entries with the client's RSA public key.
100
+ *
101
+ * @param token The JWT access token
102
+ * @param ids The IDs of entries to retrieve
103
+ * @returns The entries with RSA-encrypted payloads
104
+ */
105
+ async handleGetEntries(token, ids) {
106
+ console.log(`[ServerNetworkContentAddressedStore] Handling getEntries request for ${ids.length} entries`);
107
+ // Validate token
108
+ const tokenPayload = await this.validateToken(token);
109
+ const username = tokenPayload.sub;
110
+ console.log(`[ServerNetworkContentAddressedStore] Token validated for user: ${username}`);
111
+ // Get user's public encryption key
112
+ const userKeys = await this.directory.getUserPublicKeys(username);
113
+ if (!userKeys) {
114
+ throw new types_1.NetworkError(types_1.NetworkErrorType.USER_NOT_FOUND, `User ${username} not found or revoked`);
115
+ }
116
+ console.log(`[ServerNetworkContentAddressedStore] Retrieved encryption key for user: ${username}`);
117
+ // Get the entries from local store
118
+ const entries = await this.localStore.getEntries(ids);
119
+ console.log(`[ServerNetworkContentAddressedStore] Retrieved ${entries.length} entries from local store`);
120
+ // Encrypt each entry with the user's RSA public key
121
+ const encryptedEntries = await this.encryptEntriesForUser(entries, userKeys.encryptionPublicKey);
122
+ console.log(`[ServerNetworkContentAddressedStore] Encrypted ${encryptedEntries.length} entries for user: ${username}`);
123
+ return encryptedEntries;
124
+ }
125
+ /**
126
+ * Handle a putEntries request from a client.
127
+ *
128
+ * @param token The JWT access token
129
+ * @param entries The entries to store
130
+ */
131
+ async handlePutEntries(token, entries) {
132
+ console.log(`[ServerNetworkContentAddressedStore] Handling putEntries request for ${entries.length} entries`);
133
+ // Validate token
134
+ const tokenPayload = await this.validateToken(token);
135
+ console.log(`[ServerNetworkContentAddressedStore] Token validated for user: ${tokenPayload.sub}`);
136
+ // Process each entry
137
+ for (const entry of entries) {
138
+ // Verify the entry was created by a trusted user
139
+ const isValidKey = await this.directory.validatePublicSigningKey(entry.createdByPublicKey);
140
+ if (!isValidKey) {
141
+ throw new types_1.NetworkError(types_1.NetworkErrorType.INVALID_SIGNATURE, `Entry ${entry.id} was not signed by a trusted user`);
142
+ }
143
+ }
144
+ // Store all entries
145
+ await this.localStore.putEntries(entries);
146
+ console.log(`[ServerNetworkContentAddressedStore] Successfully stored ${entries.length} entries`);
147
+ }
148
+ /**
149
+ * Handle a hasEntries request from a client.
150
+ * Checks which of the provided IDs exist in the store.
151
+ *
152
+ * @param token The JWT access token
153
+ * @param ids The IDs to check for existence
154
+ * @returns List of IDs that exist in the store
155
+ */
156
+ async handleHasEntries(token, ids) {
157
+ console.log(`[ServerNetworkContentAddressedStore] Handling hasEntries request for ${ids.length} IDs`);
158
+ // Validate token
159
+ const tokenPayload = await this.validateToken(token);
160
+ console.log(`[ServerNetworkContentAddressedStore] Token validated for user: ${tokenPayload.sub}`);
161
+ // Check which IDs exist in local store
162
+ const existingIds = await this.localStore.hasEntries(ids);
163
+ console.log(`[ServerNetworkContentAddressedStore] Found ${existingIds.length} existing entries out of ${ids.length} checked`);
164
+ return existingIds;
165
+ }
166
+ /**
167
+ * Handle a getAllIds request from a client.
168
+ * This is used by clients to determine which entries they need to push.
169
+ *
170
+ * @param token The JWT access token
171
+ * @returns List of all entry IDs in the store
172
+ */
173
+ async handleGetAllIds(token) {
174
+ console.log(`[ServerNetworkContentAddressedStore] Handling getAllIds request`);
175
+ // Validate token
176
+ const tokenPayload = await this.validateToken(token);
177
+ console.log(`[ServerNetworkContentAddressedStore] Token validated for user: ${tokenPayload.sub}`);
178
+ // Get all entry IDs from local store
179
+ const allIds = await this.localStore.getAllIds();
180
+ console.log(`[ServerNetworkContentAddressedStore] Returning ${allIds.length} entry IDs`);
181
+ return allIds;
182
+ }
183
+ /**
184
+ * Handle a resolveDependencies request from a client.
185
+ * Resolves the dependency chain starting from an entry ID.
186
+ *
187
+ * @param token The JWT access token
188
+ * @param startId The entry ID to start traversal from
189
+ * @param options Optional traversal options
190
+ * @returns List of entry IDs in dependency order
191
+ */
192
+ async handleResolveDependencies(token, startId, options) {
193
+ console.log(`[ServerNetworkContentAddressedStore] Handling resolveDependencies request for ${startId}`);
194
+ // Validate token
195
+ const tokenPayload = await this.validateToken(token);
196
+ console.log(`[ServerNetworkContentAddressedStore] Token validated for user: ${tokenPayload.sub}`);
197
+ // Resolve dependencies in local store
198
+ const resolvedIds = await this.localStore.resolveDependencies(startId, options);
199
+ console.log(`[ServerNetworkContentAddressedStore] Resolved ${resolvedIds.length} dependencies`);
200
+ return resolvedIds;
201
+ }
202
+ /**
203
+ * Validate a JWT token and return the payload.
204
+ *
205
+ * @param token The JWT token
206
+ * @returns The token payload
207
+ * @throws NetworkError if token is invalid
208
+ */
209
+ async validateToken(token) {
210
+ const payload = await this.authService.validateToken(token);
211
+ if (!payload) {
212
+ throw new types_1.NetworkError(types_1.NetworkErrorType.INVALID_TOKEN, "Invalid or expired token");
213
+ }
214
+ return payload;
215
+ }
216
+ /**
217
+ * Encrypt entries with a user's RSA public key.
218
+ * Transforms StoreEntry[] to NetworkEncryptedEntry[].
219
+ */
220
+ async encryptEntriesForUser(entries, encryptionPublicKey) {
221
+ const results = [];
222
+ // Import the public key once for all entries
223
+ const publicKey = await this.rsaEncryption.importPublicKey(encryptionPublicKey);
224
+ for (const entry of entries) {
225
+ // Encrypt the payload with RSA
226
+ const rsaEncryptedPayload = await this.rsaEncryption.encrypt(entry.encryptedData, publicKey);
227
+ // Create NetworkEncryptedEntry with all metadata plus RSA-encrypted payload
228
+ const encryptedEntry = {
229
+ entryType: entry.entryType,
230
+ id: entry.id,
231
+ contentHash: entry.contentHash,
232
+ docId: entry.docId,
233
+ dependencyIds: entry.dependencyIds,
234
+ createdAt: entry.createdAt,
235
+ createdByPublicKey: entry.createdByPublicKey,
236
+ decryptionKeyId: entry.decryptionKeyId,
237
+ signature: entry.signature,
238
+ originalSize: entry.originalSize,
239
+ encryptedSize: entry.encryptedSize,
240
+ rsaEncryptedPayload,
241
+ };
242
+ results.push(encryptedEntry);
243
+ }
244
+ return results;
245
+ }
246
+ }
247
+ exports.ServerNetworkContentAddressedStore = ServerNetworkContentAddressedStore;
248
+ //# sourceMappingURL=ServerNetworkContentAddressedStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServerNetworkContentAddressedStore.js","sourceRoot":"","sources":["../../../src/appendonlystores/network/ServerNetworkContentAddressedStore.ts"],"names":[],"mappings":";;;AAIA,qEAA2F;AAC3F,mEAAgE;AAGhE;;;;;;;;;;;GAWG;AACH,MAAa,kCAAkC;IAO7C;;;;;;;OAOG;IACH,YACE,UAAiC,EACjC,SAAgC,EAChC,WAAkC,EAClC,aAA4B;QAE5B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,IAAI,6BAAa,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,sBAAsB,C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+1,8 @@
1
+ export type { NetworkEncryptedEntry, UserPublicKeys, NetworkAuthTokenPayload, AuthChallenge, AuthResult, } from "../../core/appendonlystores/network/types";
2
+ export { NetworkError, NetworkErrorType } from "../../core/appendonlystores/network/types";
3
+ export type { NetworkTransport, NetworkTransportConfig } from "../../core/appendonlystores/network/NetworkTransport";
4
+ export { ClientNetworkContentAddressedStore } from "./ClientNetworkContentAddressedStore";
5
+ export { ServerNetworkContentAddressedStore } from "./ServerNetworkContentAddressedStore";
6
+ export { AuthenticationService } from "../../core/appendonlystores/network/AuthenticationService";
7
+ export { HttpTransport } from "./HttpTransport";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/appendonlystores/network/index.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,qBAAqB,EACrB,cAAc,EACd,uBAAuB,EACvB,aAAa,EACb,UAAU,GACX,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAG3F,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AAGrH,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAG1F,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAG1F,OAAO,EAAE,qBAAqB,EAAE,MAAM,2DAA2D,CAAC;AAGlG,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // Network synchronization module for MindooDB
3
+ // Provides secure network-based ContentAddressedStore implementations
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.HttpTransport = exports.AuthenticationService = exports.ServerNetworkContentAddressedStore = exports.ClientNetworkContentAddressedStore = exports.NetworkErrorType = exports.NetworkError = void 0;
6
+ var types_1 = require("../../core/appendonlystores/network/types");
7
+ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return types_1.NetworkError; } });
8
+ Object.defineProperty(exports, "NetworkErrorType", { enumerable: true, get: function () { return types_1.NetworkErrorType; } });
9
+ // Client-side
10
+ var ClientNetworkContentAddressedStore_1 = require("./ClientNetworkContentAddressedStore");
11
+ Object.defineProperty(exports, "ClientNetworkContentAddressedStore", { enumerable: true, get: function () { return ClientNetworkContentAddressedStore_1.ClientNetworkContentAddressedStore; } });
12
+ // Server-side
13
+ var ServerNetworkContentAddressedStore_1 = require("./ServerNetworkContentAddressedStore");
14
+ Object.defineProperty(exports, "ServerNetworkContentAddressedStore", { enumerable: true, get: function () { return ServerNetworkContentAddressedStore_1.ServerNetworkContentAddressedStore; } });
15
+ // Authentication
16
+ var AuthenticationService_1 = require("../../core/appendonlystores/network/AuthenticationService");
17
+ Object.defineProperty(exports, "AuthenticationService", { enumerable: true, get: function () { return AuthenticationService_1.AuthenticationService; } });
18
+ // Transport implementations
19
+ var HttpTransport_1 = require("./HttpTransport");
20
+ Object.defineProperty(exports, "HttpTransport", { enumerable: true, get: function () { return HttpTransport_1.HttpTransport; } });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/appendonlystores/network/index.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,sEAAsE;;;AAUtE,mEAA2F;AAAlF,qGAAA,YAAY,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAKvC,cAAc;AACd,2FAA0F;AAAjF,wJAAA,kCAAkC,OAAA;AAE3C,cAAc;AACd,2FAA0F;AAAjF,wJAAA,kCAAkC,OAAA;AAE3C,iBAAiB;AACjB,mGAAkG;AAAzF,8HAAA,qBAAqB,OAAA;AAE9B,4BAA4B;AAC5B,iDAAgD;AAAvC,8GAAA,aAAa,OAAA"}
@@ -0,0 +1,14 @@
1
+ import type { CryptoAdapter } from "../../core/crypto/CryptoAdapter";
2
+ /**
3
+ * Browser implementation of CryptoAdapter.
4
+ * Uses window.crypto which is available in modern browsers.
5
+ */
6
+ export declare class BrowserCryptoAdapter implements CryptoAdapter {
7
+ getSubtle(): SubtleCrypto;
8
+ getRandomValues(array: Uint8Array): Uint8Array;
9
+ }
10
+ /**
11
+ * Factory function to create the BrowserCryptoAdapter.
12
+ */
13
+ export declare function createCryptoAdapter(): CryptoAdapter;
14
+ //# sourceMappingURL=BrowserCryptoAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowserCryptoAdapter.d.ts","sourceRoot":"","sources":["../../../src/browser/crypto/BrowserCryptoAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,aAAa;IACxD,SAAS,IAAI,YAAY;IAOzB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;CAM/C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrowserCryptoAdapter = void 0;
4
+ exports.createCryptoAdapter = createCryptoAdapter;
5
+ /**
6
+ * Browser implementation of CryptoAdapter.
7
+ * Uses window.crypto which is available in modern browsers.
8
+ */
9
+ class BrowserCryptoAdapter {
10
+ getSubtle() {
11
+ if (typeof window === "undefined" || !window.crypto || !window.crypto.subtle) {
12
+ throw new Error("Web Crypto API not available in browser environment");
13
+ }
14
+ return window.crypto.subtle;
15
+ }
16
+ getRandomValues(array) {
17
+ if (typeof window === "undefined" || !window.crypto || !window.crypto.getRandomValues) {
18
+ throw new Error("getRandomValues not available in browser environment");
19
+ }
20
+ return window.crypto.getRandomValues(array);
21
+ }
22
+ }
23
+ exports.BrowserCryptoAdapter = BrowserCryptoAdapter;
24
+ /**
25
+ * Factory function to create the BrowserCryptoAdapter.
26
+ */
27
+ function createCryptoAdapter() {
28
+ return new BrowserCryptoAdapter();
29
+ }
30
+ //# sourceMappingURL=BrowserCryptoAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrowserCryptoAdapter.js","sourceRoot":"","sources":["../../../src/browser/crypto/BrowserCryptoAdapter.ts"],"names":[],"mappings":";;;AAyBA,kDAEC;AAzBD;;;GAGG;AACH,MAAa,oBAAoB;IAC/B,SAAS;QACP,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YAC7E,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,eAAe,CAAC,KAAiB;QAC/B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;YACtF,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;CACF;AAdD,oDAcC;AAED;;GAEG;AACH,SAAgB,mBAAmB;IACjC,OAAO,IAAI,oBAAoB,EAAE,CAAC;AACpC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "../core";
2
+ export { BrowserCryptoAdapter, createCryptoAdapter } from "./crypto/BrowserCryptoAdapter";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // Browser-specific exports
3
+ // Re-exports everything from core plus browser-specific implementations
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.createCryptoAdapter = exports.BrowserCryptoAdapter = void 0;
20
+ // Re-export all core exports
21
+ __exportStar(require("../core"), exports);
22
+ // Browser-specific crypto adapter
23
+ var BrowserCryptoAdapter_1 = require("./crypto/BrowserCryptoAdapter");
24
+ Object.defineProperty(exports, "BrowserCryptoAdapter", { enumerable: true, get: function () { return BrowserCryptoAdapter_1.BrowserCryptoAdapter; } });
25
+ Object.defineProperty(exports, "createCryptoAdapter", { enumerable: true, get: function () { return BrowserCryptoAdapter_1.createCryptoAdapter; } });
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":";AAAA,2BAA2B;AAC3B,wEAAwE;;;;;;;;;;;;;;;;;AAExE,6BAA6B;AAC7B,0CAAwB;AAExB,kCAAkC;AAClC,sEAA0F;AAAjF,4HAAA,oBAAoB,OAAA;AAAE,2HAAA,mBAAmB,OAAA"}
@@ -0,0 +1,182 @@
1
+ import { MindooDB, MindooDoc, MindooTenant, ProcessChangesCursor, ProcessChangesResult, AttachmentConfig, SigningKeyPair } from "./types";
2
+ import { BaseMindooTenant } from "./BaseMindooTenant";
3
+ import type { ContentAddressedStore } from "./appendonlystores/types";
4
+ /**
5
+ * BaseMindooDB is a platform-agnostic implementation of MindooDB
6
+ * that works in both browser and server environments.
7
+ *
8
+ * It receives MindooTenant and ContentAddressedStore in the constructor,
9
+ * allowing platform-specific implementations of those interfaces.
10
+ *
11
+ * Dependencies:
12
+ * - @automerge/automerge: For CRDT document management
13
+ * - Web Crypto API: Available in both browser (window.crypto) and Node.js (crypto)
14
+ * - Ed25519 signing/verification (Node.js 15+, Chrome 92+)
15
+ * - AES-256-GCM encryption (widely supported)
16
+ *
17
+ * TODO: Verify Automerge 2.x API methods:
18
+ * - Automerge.getChangeHash(change) - verify method name
19
+ * - Automerge.getHeads(doc) - verify method name
20
+ * - Automerge.load(bytes) - verify method name for snapshots
21
+ * - Automerge.applyChanges(doc, changes) - verify method signature
22
+ */
23
+ export declare class BaseMindooDB implements MindooDB {
24
+ private tenant;
25
+ private store;
26
+ private attachmentStore;
27
+ private chunkSizeBytes;
28
+ private _isAdminOnlyDb;
29
+ private index;
30
+ private indexLookup;
31
+ private docCache;
32
+ private processedEntryIds;
33
+ private automergeHashToEntryId;
34
+ constructor(tenant: BaseMindooTenant, store: ContentAddressedStore, attachmentStore?: ContentAddressedStore, attachmentConfig?: AttachmentConfig, adminOnlyDb?: boolean);
35
+ /**
36
+ * Get the admin public key from the tenant.
37
+ * Only used when adminOnlyDb is true.
38
+ */
39
+ private getAdminPublicKey;
40
+ isAdminOnlyDb(): boolean;
41
+ /**
42
+ * Compare two index entries for sorting.
43
+ * Returns negative if a < b, positive if a > b, 0 if equal.
44
+ * Sorts by lastModified first, then by docId for uniqueness.
45
+ */
46
+ private compareIndexEntries;
47
+ /**
48
+ * Update the index entry for a document.
49
+ * When a document changes, it's removed from its current position and inserted
50
+ * at the correct sorted position to maintain order by (lastModified, docId).
51
+ *
52
+ * @param docId The document ID
53
+ * @param lastModified The new last modified timestamp
54
+ * @param isDeleted Whether the document is deleted
55
+ */
56
+ private updateIndex;
57
+ /**
58
+ * Register an automerge hash -> entry ID mapping for a document.
59
+ * This is used to resolve Automerge dependency hashes to entry IDs.
60
+ */
61
+ private registerAutomergeHashMapping;
62
+ /**
63
+ * Get the entry ID for an automerge hash within a document.
64
+ * Returns null if not found.
65
+ */
66
+ private getEntryIdForAutomergeHash;
67
+ /**
68
+ * Resolve Automerge dependency hashes to entry IDs for a document.
69
+ * Returns the entry IDs for the given automerge hashes.
70
+ */
71
+ private resolveAutomergeDepsToEntryIds;
72
+ /**
73
+ * Get the SubtleCrypto instance from the tenant's crypto adapter.
74
+ */
75
+ private getSubtle;
76
+ /**
77
+ * Initialize the database instance.
78
+ */
79
+ initialize(): Promise<void>;
80
+ /**
81
+ * Sync changes from the content-addressed store by finding new entries and processing them.
82
+ * This method can be called multiple times to incrementally sync new entries.
83
+ * On first call (when processedEntryIds is empty), it will process all entries.
84
+ */
85
+ syncStoreChanges(): Promise<void>;
86
+ getStore(): ContentAddressedStore;
87
+ getAttachmentStore(): ContentAddressedStore | undefined;
88
+ getTenant(): MindooTenant;
89
+ createDocument(): Promise<MindooDoc>;
90
+ createEncryptedDocument(decryptionKeyId?: string): Promise<MindooDoc>;
91
+ createDocumentWithSigningKey(signingKeyPair: SigningKeyPair, signingKeyPassword: string, decryptionKeyId?: string): Promise<MindooDoc>;
92
+ /**
93
+ * Internal method to create a new document.
94
+ * Handles both regular document creation (signed by current user) and
95
+ * document creation with a custom signing key (e.g., for directory operations).
96
+ */
97
+ private createDocumentInternal;
98
+ getDocument(docId: string): Promise<MindooDoc>;
99
+ getDocumentAtTimestamp(docId: string, timestamp: number): Promise<MindooDoc | null>;
100
+ getAllDocumentIds(): Promise<string[]>;
101
+ deleteDocument(docId: string): Promise<void>;
102
+ deleteDocumentWithSigningKey(docId: string, signingKeyPair: SigningKeyPair, signingKeyPassword: string): Promise<void>;
103
+ /**
104
+ * Internal method to delete a document.
105
+ * Handles both regular deletion (signed by current user) and
106
+ * deletion with a custom signing key (e.g., for directory operations).
107
+ */
108
+ private deleteDocInternal;
109
+ changeDoc(doc: MindooDoc, changeFunc: (doc: MindooDoc) => void | Promise<void>): Promise<void>;
110
+ changeDocWithSigningKey(doc: MindooDoc, changeFunc: (doc: MindooDoc) => void | Promise<void>, signingKeyPair: SigningKeyPair, signingKeyPassword: string): Promise<void>;
111
+ private changeDocInternal;
112
+ processChangesSince(cursor: ProcessChangesCursor | null, limit: number, callback: (change: MindooDoc, currentCursor: ProcessChangesCursor) => boolean | void): Promise<ProcessChangesCursor>;
113
+ iterateChangesSince(cursor: ProcessChangesCursor | null, pageSize?: number): AsyncGenerator<ProcessChangesResult, void, unknown>;
114
+ /**
115
+ * Internal method to load a document from the content-addressed store
116
+ */
117
+ private loadDocumentInternal;
118
+ /**
119
+ * Wrap an internal document in the MindooDoc interface.
120
+ * This is the read-only wrapper - write methods throw errors.
121
+ */
122
+ private wrapDocument;
123
+ /**
124
+ * Get an attachment reference by ID from a document's _attachments array.
125
+ */
126
+ private getAttachmentRefInternal;
127
+ /**
128
+ * Internal method to fetch and concatenate all chunks for an attachment.
129
+ */
130
+ private getAttachmentInternal;
131
+ /**
132
+ * Internal method to get a byte range from an attachment.
133
+ */
134
+ private getAttachmentRangeInternal;
135
+ /**
136
+ * Internal async generator to stream attachment data.
137
+ */
138
+ private streamAttachmentInternal;
139
+ /**
140
+ * Get the effective attachment store (attachment store if configured, otherwise doc store).
141
+ */
142
+ private getEffectiveAttachmentStore;
143
+ /**
144
+ * Internal method to add an attachment by chunking the file and storing chunks.
145
+ */
146
+ private addAttachmentInternal;
147
+ /**
148
+ * Internal method to add an attachment from a streaming data source.
149
+ * Memory efficient - processes data chunk by chunk without loading entire file into memory.
150
+ */
151
+ private addAttachmentStreamInternal;
152
+ /**
153
+ * Internal method to append data to an existing attachment.
154
+ */
155
+ private appendToAttachmentInternal;
156
+ /**
157
+ * Pull changes from a remote content-addressed store.
158
+ *
159
+ * This method:
160
+ * 1. Finds entries in the remote store that we don't have locally
161
+ * 2. Retrieves those entries from the remote store
162
+ * 3. Stores them in our local store
163
+ * 4. Syncs the local store to process the new entries
164
+ *
165
+ * @param remoteStore The remote store to pull entries from
166
+ * @return A promise that resolves when the pull is complete
167
+ */
168
+ pullChangesFrom(remoteStore: ContentAddressedStore): Promise<void>;
169
+ /**
170
+ * Push changes to a remote content-addressed store.
171
+ *
172
+ * This method:
173
+ * 1. Finds entries in our local store that the remote doesn't have
174
+ * 2. Retrieves those entries from our local store
175
+ * 3. Stores them in the remote store
176
+ *
177
+ * @param remoteStore The remote store to push entries to
178
+ * @return A promise that resolves when the push is complete
179
+ */
180
+ pushChangesTo(remoteStore: ContentAddressedStore): Promise<void>;
181
+ }
182
+ //# sourceMappingURL=BaseMindooDB.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseMindooDB.d.ts","sourceRoot":"","sources":["../../src/core/BaseMindooDB.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,SAAS,EAKT,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,EAEpB,gBAAgB,EAChB,cAAc,EACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AA2BtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,YAAa,YAAW,QAAQ;IAC3C,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,eAAe,CAAoC;IAC3D,OAAO,CAAC,cAAc,CAAS;IAG/B,OAAO,CAAC,cAAc,CAAU;IAIhC,OAAO,CAAC,KAAK,CAA0E;IAGvF,OAAO,CAAC,WAAW,CAAkC;IAGrD,OAAO,CAAC,QAAQ,CAAuC;IAGvD,OAAO,CAAC,iBAAiB,CAAgB;IAIzC,OAAO,CAAC,sBAAsB,CAA+C;gBAG3E,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAA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