@vrtmrz/livesync-commonlib 0.1.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (516) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -0
  3. package/dist/API/DirectFileManipulator.d.ts +2 -0
  4. package/dist/API/DirectFileManipulator.js +4 -0
  5. package/dist/API/DirectFileManipulatorV2.d.ts +150 -0
  6. package/dist/API/DirectFileManipulatorV2.js +424 -0
  7. package/dist/API/processSetting.d.ts +41 -0
  8. package/dist/API/processSetting.js +140 -0
  9. package/dist/ContentSplitter/ContentSplitter.d.ts +28 -0
  10. package/dist/ContentSplitter/ContentSplitter.js +5 -0
  11. package/dist/ContentSplitter/ContentSplitterBase.d.ts +51 -0
  12. package/dist/ContentSplitter/ContentSplitterBase.js +83 -0
  13. package/dist/ContentSplitter/ContentSplitterRabinKarp.d.ts +9 -0
  14. package/dist/ContentSplitter/ContentSplitterRabinKarp.js +32 -0
  15. package/dist/ContentSplitter/ContentSplitterV1.d.ts +9 -0
  16. package/dist/ContentSplitter/ContentSplitterV1.js +34 -0
  17. package/dist/ContentSplitter/ContentSplitterV2.d.ts +9 -0
  18. package/dist/ContentSplitter/ContentSplitterV2.js +34 -0
  19. package/dist/ContentSplitter/ContentSplitters.d.ts +12 -0
  20. package/dist/ContentSplitter/ContentSplitters.js +29 -0
  21. package/dist/bureau/bureau.d.ts +7 -0
  22. package/dist/bureau/bureau.js +5 -0
  23. package/dist/common/ConnectionString.d.ts +30 -0
  24. package/dist/common/ConnectionString.js +179 -0
  25. package/dist/common/LSError.d.ts +48 -0
  26. package/dist/common/LSError.js +112 -0
  27. package/dist/common/configForDoc.d.ts +79 -0
  28. package/dist/common/configForDoc.js +312 -0
  29. package/dist/common/coreEnvFunctions.d.ts +21 -0
  30. package/dist/common/coreEnvFunctions.js +22 -0
  31. package/dist/common/coreEnvVars.d.ts +3 -0
  32. package/dist/common/coreEnvVars.js +6 -0
  33. package/dist/common/i18n.d.ts +18 -0
  34. package/dist/common/i18n.js +7193 -0
  35. package/dist/common/logger.d.ts +2 -0
  36. package/dist/common/logger.js +1 -0
  37. package/dist/common/messages/combinedMessages.dev.d.ts +7 -0
  38. package/dist/common/messages/combinedMessages.dev.js +44 -0
  39. package/dist/common/messages/combinedMessages.prod.d.ts +9264 -0
  40. package/dist/common/messages/combinedMessages.prod.js +9271 -0
  41. package/dist/common/messages/de.d.ts +297 -0
  42. package/dist/common/messages/de.js +7 -0
  43. package/dist/common/messages/def.d.ts +1119 -0
  44. package/dist/common/messages/def.js +7 -0
  45. package/dist/common/messages/es.d.ts +689 -0
  46. package/dist/common/messages/es.js +7 -0
  47. package/dist/common/messages/fr.d.ts +582 -0
  48. package/dist/common/messages/fr.js +7 -0
  49. package/dist/common/messages/he.d.ts +583 -0
  50. package/dist/common/messages/he.js +7 -0
  51. package/dist/common/messages/ja.d.ts +838 -0
  52. package/dist/common/messages/ja.js +7 -0
  53. package/dist/common/messages/ko.d.ts +800 -0
  54. package/dist/common/messages/ko.js +7 -0
  55. package/dist/common/messages/ru.d.ts +858 -0
  56. package/dist/common/messages/ru.js +7 -0
  57. package/dist/common/messages/zh-tw.d.ts +384 -0
  58. package/dist/common/messages/zh-tw.js +7 -0
  59. package/dist/common/messages/zh.d.ts +1093 -0
  60. package/dist/common/messages/zh.js +7 -0
  61. package/dist/common/messagesJson/de.json +295 -0
  62. package/dist/common/messagesJson/en.json +1117 -0
  63. package/dist/common/messagesJson/es.json +687 -0
  64. package/dist/common/messagesJson/fr.json +580 -0
  65. package/dist/common/messagesJson/he.json +581 -0
  66. package/dist/common/messagesJson/ja.json +836 -0
  67. package/dist/common/messagesJson/ko.json +798 -0
  68. package/dist/common/messagesJson/ru.json +856 -0
  69. package/dist/common/messagesJson/zh-tw.json +382 -0
  70. package/dist/common/messagesJson/zh.json +1091 -0
  71. package/dist/common/models/auth.type.d.ts +41 -0
  72. package/dist/common/models/auth.type.js +0 -0
  73. package/dist/common/models/db.const.d.ts +20 -0
  74. package/dist/common/models/db.const.js +28 -0
  75. package/dist/common/models/db.definition.d.ts +56 -0
  76. package/dist/common/models/db.definition.js +6 -0
  77. package/dist/common/models/db.type.d.ts +142 -0
  78. package/dist/common/models/db.type.js +0 -0
  79. package/dist/common/models/diff.definition.d.ts +16 -0
  80. package/dist/common/models/diff.definition.js +0 -0
  81. package/dist/common/models/fileaccess.const.d.ts +7 -0
  82. package/dist/common/models/fileaccess.const.js +16 -0
  83. package/dist/common/models/fileaccess.type.d.ts +72 -0
  84. package/dist/common/models/fileaccess.type.js +0 -0
  85. package/dist/common/models/redflag.const.d.ts +32 -0
  86. package/dist/common/models/redflag.const.js +27 -0
  87. package/dist/common/models/setting.const.d.ts +49 -0
  88. package/dist/common/models/setting.const.defaults.d.ts +3 -0
  89. package/dist/common/models/setting.const.defaults.js +185 -0
  90. package/dist/common/models/setting.const.js +68 -0
  91. package/dist/common/models/setting.const.preferred.d.ts +5 -0
  92. package/dist/common/models/setting.const.preferred.js +35 -0
  93. package/dist/common/models/setting.const.qr.d.ts +2 -0
  94. package/dist/common/models/setting.const.qr.js +174 -0
  95. package/dist/common/models/setting.type.d.ts +900 -0
  96. package/dist/common/models/setting.type.js +8 -0
  97. package/dist/common/models/shared.const.behabiour.d.ts +28 -0
  98. package/dist/common/models/shared.const.behabiour.js +36 -0
  99. package/dist/common/models/shared.const.d.ts +5 -0
  100. package/dist/common/models/shared.const.js +12 -0
  101. package/dist/common/models/shared.const.symbols.d.ts +9 -0
  102. package/dist/common/models/shared.const.symbols.js +20 -0
  103. package/dist/common/models/shared.definition.configNames.d.ts +36 -0
  104. package/dist/common/models/shared.definition.configNames.js +203 -0
  105. package/dist/common/models/shared.definition.d.ts +22 -0
  106. package/dist/common/models/shared.definition.js +24 -0
  107. package/dist/common/models/shared.type.util.d.ts +8 -0
  108. package/dist/common/models/shared.type.util.js +0 -0
  109. package/dist/common/models/sync.definition.d.ts +18 -0
  110. package/dist/common/models/sync.definition.js +20 -0
  111. package/dist/common/models/tweak.definition.d.ts +191 -0
  112. package/dist/common/models/tweak.definition.js +77 -0
  113. package/dist/common/rosetta.d.ts +42 -0
  114. package/dist/common/rosetta.js +57 -0
  115. package/dist/common/settingConstants.d.ts +216 -0
  116. package/dist/common/settingConstants.js +434 -0
  117. package/dist/common/typeUtils.d.ts +17 -0
  118. package/dist/common/typeUtils.js +51 -0
  119. package/dist/common/types.d.ts +107 -0
  120. package/dist/common/types.js +212 -0
  121. package/dist/common/utils.d.ts +129 -0
  122. package/dist/common/utils.doc.d.ts +11 -0
  123. package/dist/common/utils.doc.js +35 -0
  124. package/dist/common/utils.js +583 -0
  125. package/dist/common/utils.object.d.ts +2 -0
  126. package/dist/common/utils.object.js +14 -0
  127. package/dist/common/utils.patch.d.ts +8 -0
  128. package/dist/common/utils.patch.js +178 -0
  129. package/dist/common/utils.type.d.ts +1 -0
  130. package/dist/common/utils.type.js +0 -0
  131. package/dist/context.d.ts +8 -0
  132. package/dist/context.js +14 -0
  133. package/dist/databases/IndexedDBKeyValueDatabase.d.ts +26 -0
  134. package/dist/databases/IndexedDBKeyValueDatabase.js +130 -0
  135. package/dist/dataobject/StoredMap.d.ts +12 -0
  136. package/dist/dataobject/StoredMap.js +47 -0
  137. package/dist/dev/checks.d.ts +5 -0
  138. package/dist/dev/checks.js +38 -0
  139. package/dist/encryption/encryptHKDF.d.ts +3 -0
  140. package/dist/encryption/encryptHKDF.js +7 -0
  141. package/dist/encryption/stringEncryption.d.ts +27 -0
  142. package/dist/encryption/stringEncryption.js +59 -0
  143. package/dist/events/coreEvents.d.ts +54 -0
  144. package/dist/events/coreEvents.js +46 -0
  145. package/dist/hub/hub.d.ts +11 -0
  146. package/dist/hub/hub.js +7 -0
  147. package/dist/index.d.ts +1 -0
  148. package/dist/index.js +4 -0
  149. package/dist/interfaces/AsyncActivityRunner.d.ts +18 -0
  150. package/dist/interfaces/AsyncActivityRunner.js +7 -0
  151. package/dist/interfaces/Confirm.d.ts +17 -0
  152. package/dist/interfaces/Confirm.js +0 -0
  153. package/dist/interfaces/DatabaseFileAccess.d.ts +14 -0
  154. package/dist/interfaces/DatabaseFileAccess.js +0 -0
  155. package/dist/interfaces/DatabaseRebuilder.d.ts +13 -0
  156. package/dist/interfaces/DatabaseRebuilder.js +0 -0
  157. package/dist/interfaces/FileHandler.d.ts +13 -0
  158. package/dist/interfaces/FileHandler.js +0 -0
  159. package/dist/interfaces/KeyValueDatabase.d.ts +11 -0
  160. package/dist/interfaces/KeyValueDatabase.js +0 -0
  161. package/dist/interfaces/ServiceModule.d.ts +59 -0
  162. package/dist/interfaces/ServiceModule.js +19 -0
  163. package/dist/interfaces/StorageAccess.d.ts +44 -0
  164. package/dist/interfaces/StorageAccess.js +0 -0
  165. package/dist/interfaces/StorageEventManager.d.ts +16 -0
  166. package/dist/interfaces/StorageEventManager.js +5 -0
  167. package/dist/managers/ChangeManager.d.ts +61 -0
  168. package/dist/managers/ChangeManager.js +104 -0
  169. package/dist/managers/ChunkDeliveryCoordinator.d.ts +51 -0
  170. package/dist/managers/ChunkDeliveryCoordinator.js +136 -0
  171. package/dist/managers/ChunkFetcher.d.ts +44 -0
  172. package/dist/managers/ChunkFetcher.js +251 -0
  173. package/dist/managers/ChunkManager.d.ts +2 -0
  174. package/dist/managers/ChunkManager.js +4 -0
  175. package/dist/managers/ConflictManager.d.ts +37 -0
  176. package/dist/managers/ConflictManager.js +322 -0
  177. package/dist/managers/EntryManager/EntryManager.d.ts +37 -0
  178. package/dist/managers/EntryManager/EntryManager.js +73 -0
  179. package/dist/managers/EntryManager/EntryManagerImpls.d.ts +74 -0
  180. package/dist/managers/EntryManager/EntryManagerImpls.js +499 -0
  181. package/dist/managers/HashManager/HashManager.d.ts +60 -0
  182. package/dist/managers/HashManager/HashManager.js +97 -0
  183. package/dist/managers/HashManager/HashManagerCore.d.ts +114 -0
  184. package/dist/managers/HashManager/HashManagerCore.js +99 -0
  185. package/dist/managers/HashManager/PureJSHashManager.d.ts +77 -0
  186. package/dist/managers/HashManager/PureJSHashManager.js +84 -0
  187. package/dist/managers/HashManager/XXHashHashManager.d.ts +96 -0
  188. package/dist/managers/HashManager/XXHashHashManager.js +111 -0
  189. package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.d.ts +30 -0
  190. package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.js +115 -0
  191. package/dist/managers/LayeredChunkManager/CacheLayer.d.ts +59 -0
  192. package/dist/managers/LayeredChunkManager/CacheLayer.js +161 -0
  193. package/dist/managers/LayeredChunkManager/ChunkLayerInterfaces.d.ts +37 -0
  194. package/dist/managers/LayeredChunkManager/ChunkLayerInterfaces.js +0 -0
  195. package/dist/managers/LayeredChunkManager/DatabaseReadLayer.d.ts +14 -0
  196. package/dist/managers/LayeredChunkManager/DatabaseReadLayer.js +78 -0
  197. package/dist/managers/LayeredChunkManager/DatabaseWriteLayer.d.ts +11 -0
  198. package/dist/managers/LayeredChunkManager/DatabaseWriteLayer.js +43 -0
  199. package/dist/managers/LayeredChunkManager/HotPackLayer.d.ts +9 -0
  200. package/dist/managers/LayeredChunkManager/HotPackLayer.js +8 -0
  201. package/dist/managers/LayeredChunkManager/types.d.ts +39 -0
  202. package/dist/managers/LayeredChunkManager/types.js +0 -0
  203. package/dist/managers/LayeredChunkManager.d.ts +53 -0
  204. package/dist/managers/LayeredChunkManager.js +240 -0
  205. package/dist/managers/LiveSyncManagers.d.ts +48 -0
  206. package/dist/managers/LiveSyncManagers.js +136 -0
  207. package/dist/managers/StorageEventManager.d.ts +135 -0
  208. package/dist/managers/StorageEventManager.js +564 -0
  209. package/dist/managers/StorageProcessingManager.d.ts +14 -0
  210. package/dist/managers/StorageProcessingManager.js +48 -0
  211. package/dist/managers/adapters/IStorageEventConverterAdapter.d.ts +16 -0
  212. package/dist/managers/adapters/IStorageEventConverterAdapter.js +0 -0
  213. package/dist/managers/adapters/IStorageEventManagerAdapter.d.ts +18 -0
  214. package/dist/managers/adapters/IStorageEventManagerAdapter.js +0 -0
  215. package/dist/managers/adapters/IStorageEventPersistenceAdapter.d.ts +15 -0
  216. package/dist/managers/adapters/IStorageEventPersistenceAdapter.js +0 -0
  217. package/dist/managers/adapters/IStorageEventStatusAdapter.d.ts +13 -0
  218. package/dist/managers/adapters/IStorageEventStatusAdapter.js +0 -0
  219. package/dist/managers/adapters/IStorageEventTypeGuardAdapter.d.ts +16 -0
  220. package/dist/managers/adapters/IStorageEventTypeGuardAdapter.js +0 -0
  221. package/dist/managers/adapters/IStorageEventWatchAdapter.d.ts +21 -0
  222. package/dist/managers/adapters/IStorageEventWatchAdapter.js +0 -0
  223. package/dist/managers/adapters/index.d.ts +6 -0
  224. package/dist/managers/adapters/index.js +0 -0
  225. package/dist/mock_and_interop/stores.d.ts +21 -0
  226. package/dist/mock_and_interop/stores.js +15 -0
  227. package/dist/mock_and_interop/wrapper.d.ts +7 -0
  228. package/dist/mock_and_interop/wrapper.js +37 -0
  229. package/dist/mods.d.ts +1 -0
  230. package/dist/mods.js +18 -0
  231. package/dist/platform/browser/index.d.ts +1 -0
  232. package/dist/platform/browser/index.js +10 -0
  233. package/dist/platform/browser/storage.d.ts +35 -0
  234. package/dist/platform/browser/storage.js +139 -0
  235. package/dist/platform/node/index.d.ts +23 -0
  236. package/dist/platform/node/index.js +33 -0
  237. package/dist/platform/node/storage.d.ts +31 -0
  238. package/dist/platform/node/storage.js +104 -0
  239. package/dist/platform/storagePath.d.ts +7 -0
  240. package/dist/platform/storagePath.js +20 -0
  241. package/dist/pouchdb/LiveSyncDBFunctions.d.ts +14 -0
  242. package/dist/pouchdb/LiveSyncDBFunctions.js +129 -0
  243. package/dist/pouchdb/LiveSyncLocalDB.d.ts +196 -0
  244. package/dist/pouchdb/LiveSyncLocalDB.js +381 -0
  245. package/dist/pouchdb/PouchDBConstructor.d.ts +3 -0
  246. package/dist/pouchdb/PouchDBConstructor.js +0 -0
  247. package/dist/pouchdb/ReplicatorShim.d.ts +51 -0
  248. package/dist/pouchdb/ReplicatorShim.js +109 -0
  249. package/dist/pouchdb/StreamingFetch.d.ts +19 -0
  250. package/dist/pouchdb/StreamingFetch.js +263 -0
  251. package/dist/pouchdb/chunks.d.ts +38 -0
  252. package/dist/pouchdb/chunks.js +314 -0
  253. package/dist/pouchdb/compress.d.ts +11 -0
  254. package/dist/pouchdb/compress.js +99 -0
  255. package/dist/pouchdb/encryption.d.ts +20 -0
  256. package/dist/pouchdb/encryption.js +458 -0
  257. package/dist/pouchdb/negotiation.d.ts +9 -0
  258. package/dist/pouchdb/negotiation.js +109 -0
  259. package/dist/pouchdb/pouchdb-browser.d.ts +2 -0
  260. package/dist/pouchdb/pouchdb-browser.js +96 -0
  261. package/dist/pouchdb/pouchdb-http.d.ts +2 -0
  262. package/dist/pouchdb/pouchdb-http.js +94 -0
  263. package/dist/pouchdb/pouchdb-test.d.ts +2 -0
  264. package/dist/pouchdb/pouchdb-test.js +12 -0
  265. package/dist/pouchdb/utils_couchdb.d.ts +4 -0
  266. package/dist/pouchdb/utils_couchdb.js +38 -0
  267. package/dist/replication/LiveSyncAbstractReplicator.d.ts +69 -0
  268. package/dist/replication/LiveSyncAbstractReplicator.js +92 -0
  269. package/dist/replication/SyncParamsHandler.d.ts +35 -0
  270. package/dist/replication/SyncParamsHandler.js +118 -0
  271. package/dist/replication/couchdb/LiveSyncReplicator.d.ts +85 -0
  272. package/dist/replication/couchdb/LiveSyncReplicator.js +1132 -0
  273. package/dist/replication/httplib.d.ts +75 -0
  274. package/dist/replication/httplib.js +187 -0
  275. package/dist/replication/journal/JournalSyncCore.d.ts +70 -0
  276. package/dist/replication/journal/JournalSyncCore.js +737 -0
  277. package/dist/replication/journal/JournalSyncTypes.d.ts +9 -0
  278. package/dist/replication/journal/JournalSyncTypes.js +11 -0
  279. package/dist/replication/journal/LiveSyncJournalReplicator.d.ts +40 -0
  280. package/dist/replication/journal/LiveSyncJournalReplicator.js +294 -0
  281. package/dist/replication/journal/LiveSyncJournalReplicatorEnv.d.ts +3 -0
  282. package/dist/replication/journal/LiveSyncJournalReplicatorEnv.js +0 -0
  283. package/dist/replication/journal/objectstore/JournalStorageAdapter.d.ts +15 -0
  284. package/dist/replication/journal/objectstore/JournalStorageAdapter.js +0 -0
  285. package/dist/replication/journal/objectstore/MinioStorageAdapter.d.ts +21 -0
  286. package/dist/replication/journal/objectstore/MinioStorageAdapter.js +204 -0
  287. package/dist/replication/trystero/LiveSyncTrysteroReplicator.d.ts +90 -0
  288. package/dist/replication/trystero/LiveSyncTrysteroReplicator.js +380 -0
  289. package/dist/replication/trystero/P2PLogCollector.d.ts +8 -0
  290. package/dist/replication/trystero/P2PLogCollector.js +91 -0
  291. package/dist/replication/trystero/P2PReplicatorBase.d.ts +19 -0
  292. package/dist/replication/trystero/P2PReplicatorBase.js +0 -0
  293. package/dist/replication/trystero/P2PReplicatorCore.d.ts +12 -0
  294. package/dist/replication/trystero/P2PReplicatorCore.js +126 -0
  295. package/dist/replication/trystero/P2PReplicatorPaneCommon.d.ts +41 -0
  296. package/dist/replication/trystero/P2PReplicatorPaneCommon.js +20 -0
  297. package/dist/replication/trystero/ProxiedDB.d.ts +13 -0
  298. package/dist/replication/trystero/ProxiedDB.js +20 -0
  299. package/dist/replication/trystero/TrysteroReplicator.d.ts +152 -0
  300. package/dist/replication/trystero/TrysteroReplicator.js +683 -0
  301. package/dist/replication/trystero/TrysteroReplicatorP2PClient.d.ts +19 -0
  302. package/dist/replication/trystero/TrysteroReplicatorP2PClient.js +80 -0
  303. package/dist/replication/trystero/TrysteroReplicatorP2PConnection.d.ts +2 -0
  304. package/dist/replication/trystero/TrysteroReplicatorP2PConnection.js +4 -0
  305. package/dist/replication/trystero/TrysteroReplicatorP2PServer.d.ts +117 -0
  306. package/dist/replication/trystero/TrysteroReplicatorP2PServer.js +540 -0
  307. package/dist/replication/trystero/UseP2PReplicatorResult.d.ts +11 -0
  308. package/dist/replication/trystero/UseP2PReplicatorResult.js +0 -0
  309. package/dist/replication/trystero/addP2PEventHandlers.d.ts +35 -0
  310. package/dist/replication/trystero/addP2PEventHandlers.js +43 -0
  311. package/dist/replication/trystero/rpcCompat.d.ts +1 -0
  312. package/dist/replication/trystero/rpcCompat.js +9 -0
  313. package/dist/replication/trystero/types.d.ts +95 -0
  314. package/dist/replication/trystero/types.js +27 -0
  315. package/dist/replication/trystero/useP2PReplicatorCommands.d.ts +7 -0
  316. package/dist/replication/trystero/useP2PReplicatorCommands.js +25 -0
  317. package/dist/replication/trystero/useP2PReplicatorFeature.d.ts +17 -0
  318. package/dist/replication/trystero/useP2PReplicatorFeature.js +82 -0
  319. package/dist/rpc/RpcRoom.d.ts +24 -0
  320. package/dist/rpc/RpcRoom.js +300 -0
  321. package/dist/rpc/RpcSession.d.ts +9 -0
  322. package/dist/rpc/RpcSession.js +32 -0
  323. package/dist/rpc/chunking.d.ts +11 -0
  324. package/dist/rpc/chunking.js +58 -0
  325. package/dist/rpc/errors.d.ts +8 -0
  326. package/dist/rpc/errors.js +26 -0
  327. package/dist/rpc/index.d.ts +6 -0
  328. package/dist/rpc/index.js +12 -0
  329. package/dist/rpc/pouchdb/RpcPouchDBProxy.d.ts +75 -0
  330. package/dist/rpc/pouchdb/RpcPouchDBProxy.js +115 -0
  331. package/dist/rpc/pouchdb/RpcPouchDBServer.d.ts +16 -0
  332. package/dist/rpc/pouchdb/RpcPouchDBServer.js +55 -0
  333. package/dist/rpc/transports/DiagRTCPeerConnections.d.ts +24 -0
  334. package/dist/rpc/transports/DiagRTCPeerConnections.js +208 -0
  335. package/dist/rpc/transports/DiagRTCPeerConnections.types.d.ts +64 -0
  336. package/dist/rpc/transports/DiagRTCPeerConnections.types.js +12 -0
  337. package/dist/rpc/transports/DiagRTCPeerConnections.utils.d.ts +33 -0
  338. package/dist/rpc/transports/DiagRTCPeerConnections.utils.js +217 -0
  339. package/dist/rpc/transports/TrysteroTransport.d.ts +216 -0
  340. package/dist/rpc/transports/TrysteroTransport.js +134 -0
  341. package/dist/rpc/transports/trysteroUtils.d.ts +3 -0
  342. package/dist/rpc/transports/trysteroUtils.js +37 -0
  343. package/dist/rpc/types.d.ts +75 -0
  344. package/dist/rpc/types.js +6 -0
  345. package/dist/serviceFeatures/checkRemoteSize.d.ts +28 -0
  346. package/dist/serviceFeatures/checkRemoteSize.js +178 -0
  347. package/dist/serviceFeatures/offlineScanner.d.ts +128 -0
  348. package/dist/serviceFeatures/offlineScanner.js +553 -0
  349. package/dist/serviceFeatures/prepareDatabaseForUse.d.ts +20 -0
  350. package/dist/serviceFeatures/prepareDatabaseForUse.js +39 -0
  351. package/dist/serviceFeatures/remoteConfig.d.ts +46 -0
  352. package/dist/serviceFeatures/remoteConfig.js +247 -0
  353. package/dist/serviceFeatures/setupObsidian/qrCode.d.ts +4 -0
  354. package/dist/serviceFeatures/setupObsidian/qrCode.js +67 -0
  355. package/dist/serviceFeatures/setupObsidian/setupUri.d.ts +7 -0
  356. package/dist/serviceFeatures/setupObsidian/setupUri.js +70 -0
  357. package/dist/serviceFeatures/setupObsidian/types.d.ts +2 -0
  358. package/dist/serviceFeatures/setupObsidian/types.js +0 -0
  359. package/dist/serviceFeatures/targetFilter.d.ts +24 -0
  360. package/dist/serviceFeatures/targetFilter.js +178 -0
  361. package/dist/serviceModules/FileAccessBase.d.ts +93 -0
  362. package/dist/serviceModules/FileAccessBase.js +219 -0
  363. package/dist/serviceModules/Rebuilder.d.ts +92 -0
  364. package/dist/serviceModules/Rebuilder.js +449 -0
  365. package/dist/serviceModules/ServiceDatabaseFileAccessBase.d.ts +40 -0
  366. package/dist/serviceModules/ServiceDatabaseFileAccessBase.js +306 -0
  367. package/dist/serviceModules/ServiceFileAccessBase.d.ts +64 -0
  368. package/dist/serviceModules/ServiceFileAccessBase.js +312 -0
  369. package/dist/serviceModules/ServiceFileHandlerBase.d.ts +52 -0
  370. package/dist/serviceModules/ServiceFileHandlerBase.js +493 -0
  371. package/dist/serviceModules/ServiceModuleBase.d.ts +10 -0
  372. package/dist/serviceModules/ServiceModuleBase.js +13 -0
  373. package/dist/serviceModules/adapters/IConversionAdapter.d.ts +15 -0
  374. package/dist/serviceModules/adapters/IConversionAdapter.js +0 -0
  375. package/dist/serviceModules/adapters/IFileSystemAdapter.d.ts +47 -0
  376. package/dist/serviceModules/adapters/IFileSystemAdapter.js +0 -0
  377. package/dist/serviceModules/adapters/IPathAdapter.d.ts +15 -0
  378. package/dist/serviceModules/adapters/IPathAdapter.js +0 -0
  379. package/dist/serviceModules/adapters/IStorageAdapter.d.ts +56 -0
  380. package/dist/serviceModules/adapters/IStorageAdapter.js +0 -0
  381. package/dist/serviceModules/adapters/ITypeGuardAdapter.d.ts +14 -0
  382. package/dist/serviceModules/adapters/ITypeGuardAdapter.js +0 -0
  383. package/dist/serviceModules/adapters/IVaultAdapter.d.ts +51 -0
  384. package/dist/serviceModules/adapters/IVaultAdapter.js +0 -0
  385. package/dist/serviceModules/adapters/index.d.ts +6 -0
  386. package/dist/serviceModules/adapters/index.js +0 -0
  387. package/dist/services/BrowserServices.d.ts +36 -0
  388. package/dist/services/BrowserServices.js +123 -0
  389. package/dist/services/HeadlessServices.d.ts +14 -0
  390. package/dist/services/HeadlessServices.js +144 -0
  391. package/dist/services/InjectableServices.d.ts +1 -0
  392. package/dist/services/InjectableServices.js +4 -0
  393. package/dist/services/ServiceHub.d.ts +82 -0
  394. package/dist/services/ServiceHub.js +66 -0
  395. package/dist/services/base/APIService.d.ts +93 -0
  396. package/dist/services/base/APIService.js +44 -0
  397. package/dist/services/base/AppLifecycleService.d.ts +132 -0
  398. package/dist/services/base/AppLifecycleService.js +123 -0
  399. package/dist/services/base/ConfigService.d.ts +7 -0
  400. package/dist/services/base/ConfigService.js +6 -0
  401. package/dist/services/base/ConflictService.d.ts +54 -0
  402. package/dist/services/base/ConflictService.js +22 -0
  403. package/dist/services/base/ControlService.d.ts +54 -0
  404. package/dist/services/base/ControlService.js +103 -0
  405. package/dist/services/base/DatabaseEventService.d.ts +38 -0
  406. package/dist/services/base/DatabaseEventService.js +38 -0
  407. package/dist/services/base/DatabaseService.d.ts +40 -0
  408. package/dist/services/base/DatabaseService.js +79 -0
  409. package/dist/services/base/FileProcessingService.d.ts +25 -0
  410. package/dist/services/base/FileProcessingService.js +28 -0
  411. package/dist/services/base/IService.d.ts +284 -0
  412. package/dist/services/base/IService.js +1 -0
  413. package/dist/services/base/KeyValueDBService.d.ts +42 -0
  414. package/dist/services/base/KeyValueDBService.js +133 -0
  415. package/dist/services/base/MessageTranslator.d.ts +6 -0
  416. package/dist/services/base/MessageTranslator.js +4 -0
  417. package/dist/services/base/PathService.d.ts +38 -0
  418. package/dist/services/base/PathService.js +66 -0
  419. package/dist/services/base/RemoteService.d.ts +61 -0
  420. package/dist/services/base/RemoteService.js +212 -0
  421. package/dist/services/base/ReplicationService.d.ts +92 -0
  422. package/dist/services/base/ReplicationService.js +261 -0
  423. package/dist/services/base/ReplicatorService.d.ts +66 -0
  424. package/dist/services/base/ReplicatorService.js +164 -0
  425. package/dist/services/base/ServiceBase.d.ts +33 -0
  426. package/dist/services/base/ServiceBase.js +27 -0
  427. package/dist/services/base/SettingService.d.ts +112 -0
  428. package/dist/services/base/SettingService.js +543 -0
  429. package/dist/services/base/TestService.d.ts +28 -0
  430. package/dist/services/base/TestService.js +19 -0
  431. package/dist/services/base/TweakValueService.d.ts +40 -0
  432. package/dist/services/base/TweakValueService.js +6 -0
  433. package/dist/services/base/UnresolvedErrorManager.d.ts +15 -0
  434. package/dist/services/base/UnresolvedErrorManager.js +44 -0
  435. package/dist/services/base/VaultService.d.ts +69 -0
  436. package/dist/services/base/VaultService.js +70 -0
  437. package/dist/services/implements/base/SvelteDialog.d.ts +79 -0
  438. package/dist/services/implements/base/SvelteDialog.js +134 -0
  439. package/dist/services/implements/base/UIService.d.ts +24 -0
  440. package/dist/services/implements/base/UIService.js +37 -0
  441. package/dist/services/implements/browser/BrowserAPIService.d.ts +54 -0
  442. package/dist/services/implements/browser/BrowserAPIService.js +298 -0
  443. package/dist/services/implements/browser/BrowserDatabaseService.d.ts +7 -0
  444. package/dist/services/implements/browser/BrowserDatabaseService.js +10 -0
  445. package/dist/services/implements/browser/ConfigServiceBrowserCompat.d.ts +16 -0
  446. package/dist/services/implements/browser/ConfigServiceBrowserCompat.js +23 -0
  447. package/dist/services/implements/headless/HeadlessAPIService.d.ts +52 -0
  448. package/dist/services/implements/headless/HeadlessAPIService.js +127 -0
  449. package/dist/services/implements/headless/HeadlessDatabaseService.d.ts +7 -0
  450. package/dist/services/implements/headless/HeadlessDatabaseService.js +10 -0
  451. package/dist/services/implements/injectable/InjectableAPIService.d.ts +7 -0
  452. package/dist/services/implements/injectable/InjectableAPIService.js +18 -0
  453. package/dist/services/implements/injectable/InjectableAppLifecycleService.d.ts +11 -0
  454. package/dist/services/implements/injectable/InjectableAppLifecycleService.js +14 -0
  455. package/dist/services/implements/injectable/InjectableConflictService.d.ts +11 -0
  456. package/dist/services/implements/injectable/InjectableConflictService.js +14 -0
  457. package/dist/services/implements/injectable/InjectableDatabaseEventService.d.ts +4 -0
  458. package/dist/services/implements/injectable/InjectableDatabaseEventService.js +7 -0
  459. package/dist/services/implements/injectable/InjectableFileProcessingService.d.ts +4 -0
  460. package/dist/services/implements/injectable/InjectableFileProcessingService.js +6 -0
  461. package/dist/services/implements/injectable/InjectablePathService.d.ts +12 -0
  462. package/dist/services/implements/injectable/InjectablePathService.js +36 -0
  463. package/dist/services/implements/injectable/InjectableRemoteService.d.ts +4 -0
  464. package/dist/services/implements/injectable/InjectableRemoteService.js +7 -0
  465. package/dist/services/implements/injectable/InjectableReplicationService.d.ts +4 -0
  466. package/dist/services/implements/injectable/InjectableReplicationService.js +6 -0
  467. package/dist/services/implements/injectable/InjectableReplicatorService.d.ts +4 -0
  468. package/dist/services/implements/injectable/InjectableReplicatorService.js +7 -0
  469. package/dist/services/implements/injectable/InjectableServiceHub.d.ts +72 -0
  470. package/dist/services/implements/injectable/InjectableServiceHub.js +125 -0
  471. package/dist/services/implements/injectable/InjectableServices.d.ts +36 -0
  472. package/dist/services/implements/injectable/InjectableServices.js +1 -0
  473. package/dist/services/implements/injectable/InjectableSettingService.d.ts +11 -0
  474. package/dist/services/implements/injectable/InjectableSettingService.js +33 -0
  475. package/dist/services/implements/injectable/InjectableTestService.d.ts +5 -0
  476. package/dist/services/implements/injectable/InjectableTestService.js +8 -0
  477. package/dist/services/implements/injectable/InjectableTweakValueService.d.ts +15 -0
  478. package/dist/services/implements/injectable/InjectableTweakValueService.js +12 -0
  479. package/dist/services/implements/injectable/InjectableVaultService.d.ts +9 -0
  480. package/dist/services/implements/injectable/InjectableVaultService.js +20 -0
  481. package/dist/services/lib/HandlerUtils.d.ts +374 -0
  482. package/dist/services/lib/HandlerUtils.js +412 -0
  483. package/dist/services/lib/logUtils.d.ts +13 -0
  484. package/dist/services/lib/logUtils.js +28 -0
  485. package/dist/services/lib/remoteActivity.d.ts +13 -0
  486. package/dist/services/lib/remoteActivity.js +11 -0
  487. package/dist/string_and_binary/chunks.d.ts +10 -0
  488. package/dist/string_and_binary/chunks.js +561 -0
  489. package/dist/string_and_binary/convert.d.ts +8 -0
  490. package/dist/string_and_binary/convert.js +46 -0
  491. package/dist/string_and_binary/hash.d.ts +2 -0
  492. package/dist/string_and_binary/hash.js +1 -0
  493. package/dist/string_and_binary/path.d.ts +35 -0
  494. package/dist/string_and_binary/path.js +240 -0
  495. package/dist/worker/bg.common.d.ts +2 -0
  496. package/dist/worker/bg.common.js +6 -0
  497. package/dist/worker/bg.worker.d.ts +1 -0
  498. package/dist/worker/bg.worker.encryption.d.ts +7 -0
  499. package/dist/worker/bg.worker.encryption.js +30 -0
  500. package/dist/worker/bg.worker.js +14 -0
  501. package/dist/worker/bg.worker.splitting.d.ts +6 -0
  502. package/dist/worker/bg.worker.splitting.js +36 -0
  503. package/dist/worker/bgWorker.d.ts +25 -0
  504. package/dist/worker/bgWorker.direct.d.ts +40 -0
  505. package/dist/worker/bgWorker.direct.js +65 -0
  506. package/dist/worker/bgWorker.encryption.d.ts +22 -0
  507. package/dist/worker/bgWorker.encryption.js +40 -0
  508. package/dist/worker/bgWorker.js +348 -0
  509. package/dist/worker/bgWorker.splitting.d.ts +27 -0
  510. package/dist/worker/bgWorker.splitting.js +123 -0
  511. package/dist/worker/universalTypes.d.ts +63 -0
  512. package/dist/worker/universalTypes.js +4 -0
  513. package/docs/development.md +51 -0
  514. package/docs/platform-storage.md +60 -0
  515. package/docs/releasing.md +69 -0
  516. package/package.json +693 -0
@@ -0,0 +1,261 @@
1
+ import {
2
+ LOG_LEVEL_INFO,
3
+ LOG_LEVEL_NOTICE,
4
+ LOG_LEVEL_VERBOSE
5
+ } from "../../common/types.js";
6
+ import { handlers } from "../lib/HandlerUtils.js";
7
+ import { ServiceBase } from "./ServiceBase.js";
8
+ import { reactiveSource } from "octagonal-wheels/dataobject/reactive";
9
+ import { createInstanceLogFunction, MARK_LOG_NETWORK_ERROR } from "../lib/logUtils.js";
10
+ import { UnresolvedErrorManager } from "./UnresolvedErrorManager.js";
11
+ import { isLockAcquired, shareRunningResult } from "octagonal-wheels/concurrency/lock";
12
+ const REPLICATION_ON_EVENT_FORECASTED_TIME = 5e3;
13
+ class ReplicationService extends ServiceBase {
14
+ _unresolvedErrorManager;
15
+ showError(msg, max_log_level = LOG_LEVEL_NOTICE) {
16
+ this._unresolvedErrorManager.showError(msg, max_log_level);
17
+ }
18
+ clearErrors() {
19
+ this._unresolvedErrorManager.clearErrors();
20
+ }
21
+ _log;
22
+ settingService;
23
+ appLifecycleService;
24
+ replicatorService;
25
+ APIService;
26
+ fileProcessing;
27
+ databaseService;
28
+ constructor(context, dependencies) {
29
+ super(context);
30
+ this.appLifecycleService = dependencies.appLifecycleService;
31
+ this.settingService = dependencies.settingService;
32
+ this.replicatorService = dependencies.replicatorService;
33
+ this.APIService = dependencies.APIService;
34
+ this.fileProcessing = dependencies.fileProcessingService;
35
+ this.databaseService = dependencies.databaseService;
36
+ this._log = createInstanceLogFunction("ReplicationService", dependencies.APIService);
37
+ this._unresolvedErrorManager = new UnresolvedErrorManager(dependencies.appLifecycleService, this.context.events);
38
+ }
39
+ /**
40
+ * Process a synchronisation result document.
41
+ */
42
+ processSynchroniseResult = handlers().anySuccess("processSynchroniseResult");
43
+ /**
44
+ * Process a synchronisation result document for optional entries i.e., hidden files.
45
+ */
46
+ processOptionalSynchroniseResult = handlers().anySuccess(
47
+ "processOptionalSynchroniseResult"
48
+ );
49
+ /**
50
+ * Process an array of synchronisation result documents.
51
+ * @param docs An array of documents to parse and handle.
52
+ */
53
+ parseSynchroniseResult = handlers().all("parseSynchroniseResult");
54
+ /**
55
+ * Process a virtual document (e.g., for customisation sync).
56
+ */
57
+ processVirtualDocument = handlers().anySuccess("processVirtualDocument");
58
+ /**
59
+ * An event triggered before starting replication.
60
+ */
61
+ onBeforeReplicate = handlers().bailFirstFailure("onBeforeReplicate");
62
+ /**
63
+ *
64
+ */
65
+ onCheckReplicationReady = handlers().bailFirstFailure("onCheckReplicationReady");
66
+ /**
67
+ * Check if the replication is ready to start.
68
+ * @param showMessage Whether to show messages to the user.
69
+ */
70
+ async isReplicationReady(showMessage = false) {
71
+ if (!this.appLifecycleService.isReady()) {
72
+ this._log(`Not ready`);
73
+ return false;
74
+ }
75
+ const currentSettings = this.settingService.currentSettings();
76
+ if (isLockAcquired("cleanup")) {
77
+ this._log(this.context.translate("Replicator.Message.Cleaned"), LOG_LEVEL_NOTICE);
78
+ return false;
79
+ }
80
+ if (currentSettings.versionUpFlash != "") {
81
+ this._log(this.context.translate("Replicator.Message.VersionUpFlash"), LOG_LEVEL_NOTICE);
82
+ return false;
83
+ }
84
+ if (!await this.fileProcessing.commitPendingFileEvents()) {
85
+ this.showError(this.context.translate("Replicator.Message.Pending"), LOG_LEVEL_NOTICE);
86
+ return false;
87
+ }
88
+ if (!this.APIService.isOnline) {
89
+ this.showError("Network is offline", showMessage ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO);
90
+ return false;
91
+ }
92
+ if (!await this.onBeforeReplicate(showMessage)) {
93
+ const hasNetworkError = (await this.appLifecycleService.getUnresolvedMessages()).flat().some((e) => typeof e == "string" && e.indexOf(MARK_LOG_NETWORK_ERROR) !== -1);
94
+ if (!hasNetworkError) {
95
+ this.showError(this.context.translate("Replicator.Message.SomeModuleFailed"), LOG_LEVEL_NOTICE);
96
+ } else {
97
+ this._log(this.context.translate("Replicator.Message.SomeModuleFailed"), LOG_LEVEL_INFO);
98
+ }
99
+ return false;
100
+ }
101
+ this.clearErrors();
102
+ return true;
103
+ }
104
+ onReplicationFailed = handlers().bailFirstFailure("onReplicationFailed");
105
+ async performReplicationRequest(showMessage) {
106
+ const activeReplicator = this.replicatorService.getActiveReplicator();
107
+ if (!activeReplicator) {
108
+ this._log(`No active replicator found`, showMessage ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO);
109
+ return false;
110
+ }
111
+ const settings = this.settingService.currentSettings();
112
+ return await activeReplicator.openReplication(settings, false, !!showMessage, false);
113
+ }
114
+ /**
115
+ * Perform replication and handle a failed result.
116
+ * @param showMessage Whether to show replication progress messages.
117
+ */
118
+ async performReplication(showMessage) {
119
+ const result = await this.performReplicationRequest(showMessage);
120
+ if (!result) return await this.onReplicationFailed(showMessage);
121
+ return result;
122
+ }
123
+ /**
124
+ * Start the replication process.
125
+ * @param showMessage Whether to show messages to the user.
126
+ */
127
+ async replicate(showMessage) {
128
+ try {
129
+ const checkBeforeReplicate = await this.isReplicationReady(showMessage);
130
+ if (!checkBeforeReplicate) return false;
131
+ const result = await this.replicatorService.runFiniteReplicationActivity(
132
+ () => this.performReplicationRequest(showMessage),
133
+ { label: "replication" }
134
+ );
135
+ if (!result) return await this.onReplicationFailed(showMessage);
136
+ return result;
137
+ } finally {
138
+ this.previousReplicated = Date.now();
139
+ }
140
+ }
141
+ previousReplicated = 0;
142
+ /**
143
+ * Start the replication process triggered by an event (e.g., file change).
144
+ * @param showMessage Whether to show messages to the user.
145
+ */
146
+ replicateByEvent(showMessage) {
147
+ return shareRunningResult(`replication`, async () => {
148
+ const currentSettings = this.settingService.currentSettings();
149
+ const least = currentSettings.syncMinimumInterval;
150
+ if (least > 0) {
151
+ const now = Date.now();
152
+ const elapsed = now - this.previousReplicated;
153
+ if (elapsed < least) {
154
+ this._log(
155
+ `Replication triggered by event is rate limited. Elapsed: ${elapsed}ms, Least interval: ${least}ms`,
156
+ LOG_LEVEL_VERBOSE
157
+ );
158
+ return Promise.resolve(true);
159
+ }
160
+ this.previousReplicated = now + REPLICATION_ON_EVENT_FORECASTED_TIME;
161
+ return await this.replicate();
162
+ }
163
+ return this.replicate();
164
+ });
165
+ }
166
+ /**
167
+ * Check if there is a connection failure with the remote database.
168
+ */
169
+ checkConnectionFailure = handlers().firstResult("checkConnectionFailure");
170
+ databaseQueueCount = reactiveSource(0);
171
+ storageApplyingCount = reactiveSource(0);
172
+ replicationResultCount = reactiveSource(0);
173
+ getActiveReplicatorFor(usage) {
174
+ const activeReplicator = this.replicatorService.getActiveReplicator();
175
+ if (!activeReplicator) {
176
+ this._log(`Active replicator not found during ${usage}`, LOG_LEVEL_NOTICE);
177
+ return false;
178
+ }
179
+ return activeReplicator;
180
+ }
181
+ async replicateAllToRemote(showingNotice = false, sendChunksInBulkDisabled = false) {
182
+ if (!this.appLifecycleService.isReady()) return false;
183
+ if (!await this.onBeforeReplicate(showingNotice)) {
184
+ this._log(this.context.translate("Replicator.Message.SomeModuleFailed"), LOG_LEVEL_NOTICE);
185
+ return false;
186
+ }
187
+ const currentSettings = this.settingService.currentSettings();
188
+ const activeReplicator = this.getActiveReplicatorFor("sending data to remote");
189
+ if (!activeReplicator) {
190
+ return false;
191
+ }
192
+ if (!sendChunksInBulkDisabled) {
193
+ if (activeReplicator?.isChunkSendingSupported) {
194
+ if (await this.APIService.confirm.askYesNoDialog(
195
+ "Do you want to send all chunks before replication?",
196
+ {
197
+ defaultOption: "No",
198
+ timeout: 20
199
+ }
200
+ ) == "yes") {
201
+ await activeReplicator.sendChunks(currentSettings, void 0, true, 0);
202
+ }
203
+ }
204
+ }
205
+ const ret = await activeReplicator.replicateAllToServer(currentSettings, showingNotice);
206
+ if (ret) return true;
207
+ const checkResult = await this.checkConnectionFailure();
208
+ if (checkResult == "CHECKAGAIN")
209
+ return await activeReplicator.replicateAllToServer(currentSettings, showingNotice);
210
+ return !checkResult;
211
+ }
212
+ async replicateAllFromRemote(showingNotice = false) {
213
+ if (!this.appLifecycleService.isReady()) return false;
214
+ const activeReplicator = this.getActiveReplicatorFor("fetching data from remote");
215
+ if (!activeReplicator) {
216
+ return false;
217
+ }
218
+ const currentSettings = this.settingService.currentSettings();
219
+ const ret = await activeReplicator.replicateAllFromServer(currentSettings, showingNotice);
220
+ if (ret) return true;
221
+ const checkResult = await this.checkConnectionFailure();
222
+ if (checkResult == "CHECKAGAIN")
223
+ return await activeReplicator.replicateAllFromServer(currentSettings, showingNotice);
224
+ return !checkResult;
225
+ }
226
+ _getReplicatorAndPerform(action, perform) {
227
+ const activeReplicator = this.getActiveReplicatorFor(action);
228
+ if (!activeReplicator) {
229
+ return Promise.resolve();
230
+ }
231
+ const currentSettings = this.settingService.currentSettings();
232
+ return perform(currentSettings, activeReplicator);
233
+ }
234
+ async markLocked(lockByClean = false) {
235
+ return await this._getReplicatorAndPerform(
236
+ "marking remote locked",
237
+ async (currentSettings, activeReplicator) => {
238
+ return await activeReplicator.markRemoteLocked(currentSettings, true, lockByClean);
239
+ }
240
+ );
241
+ }
242
+ async markUnlocked() {
243
+ return await this._getReplicatorAndPerform(
244
+ "marking remote unlocked",
245
+ async (currentSettings, activeReplicator) => {
246
+ return await activeReplicator.markRemoteLocked(currentSettings, false, false);
247
+ }
248
+ );
249
+ }
250
+ async markResolved() {
251
+ return await this._getReplicatorAndPerform(
252
+ "marking remote resolved",
253
+ async (currentSettings, activeReplicator) => {
254
+ return await activeReplicator.markRemoteResolved(currentSettings);
255
+ }
256
+ );
257
+ }
258
+ }
259
+ export {
260
+ ReplicationService
261
+ };
@@ -0,0 +1,66 @@
1
+ import type { LiveSyncAbstractReplicator } from "../../replication/LiveSyncAbstractReplicator.js";
2
+ import type { IReplicatorService } from "./IService.js";
3
+ import { ServiceBase, type ServiceContext } from "./ServiceBase.js";
4
+ import type { SettingService } from "./SettingService.js";
5
+ import type { AppLifecycleService } from "./AppLifecycleService.js";
6
+ import { UnresolvedErrorManager } from "./UnresolvedErrorManager.js";
7
+ import type { DatabaseEventService } from "./DatabaseEventService.js";
8
+ import { type AsyncActivityOptions, type AsyncActivityRunner } from "../../interfaces/AsyncActivityRunner.js";
9
+ export interface ReplicatorServiceDependencies {
10
+ settingService: SettingService;
11
+ appLifecycleService: AppLifecycleService;
12
+ databaseEventService: DatabaseEventService;
13
+ activityRunner?: AsyncActivityRunner;
14
+ }
15
+ /**
16
+ * The ReplicatorService provides methods for managing replication.
17
+ */
18
+ export declare abstract class ReplicatorService<T extends ServiceContext = ServiceContext> extends ServiceBase<T> implements IReplicatorService {
19
+ protected dependencies: ReplicatorServiceDependencies;
20
+ readonly boundedRemoteActivityCount: import("octagonal-wheels/dataobject/reactive_v2").ReactiveSource<number>;
21
+ readonly finiteReplicationActivityCount: import("octagonal-wheels/dataobject/reactive_v2").ReactiveSource<number>;
22
+ _log: (msg: unknown, level?: import("octagonal-wheels/common/logger").LOG_LEVEL, key?: string) => void;
23
+ private settingService;
24
+ private databaseEventService;
25
+ private _activeReplicator;
26
+ private _replicatorType;
27
+ private appLifecycleService;
28
+ _unresolvedErrorManager: UnresolvedErrorManager;
29
+ constructor(context: T, dependencies: ReplicatorServiceDependencies);
30
+ /**
31
+ * Runs one finite remote operation while exposing its lifetime to host policy and status UI.
32
+ * Continuous replication must not use this boundary.
33
+ */
34
+ runBoundedRemoteActivity<TValue>(task: () => TValue | PromiseLike<TValue>, options?: AsyncActivityOptions): Promise<TValue>;
35
+ /** Runs one finite replication and exposes its document-delivery lifetime. */
36
+ runFiniteReplicationActivity<TValue>(task: () => TValue | PromiseLike<TValue>, options?: AsyncActivityOptions): Promise<TValue>;
37
+ private runRemoteActivity;
38
+ private suspendReplication;
39
+ private reinitialiseReplicator;
40
+ private disposeReplicator;
41
+ private _initialiseReplicator;
42
+ /**
43
+ * Close the active replication if any.
44
+ * Not used currently.
45
+ */
46
+ readonly onCloseActiveReplication: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
47
+ /**
48
+ * Get a new replicator instance based on the provided settings.
49
+ */
50
+ readonly getNewReplicator: import("../lib/HandlerUtils.js").MultipleHandlerFunction<(settingOverride?: Partial<import("../../common/types.js").ObsidianLiveSyncSettings>) => Promise<LiveSyncAbstractReplicator | undefined | false>, unknown>;
51
+ readonly onReplicatorInitialised: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
52
+ /**
53
+ * Get the currently active replicator instance.
54
+ * If no active replicator, return undefined but that is the fatal situation (on Obsidian).
55
+ */
56
+ getActiveReplicator(): LiveSyncAbstractReplicator | undefined;
57
+ replicationStatics: import("octagonal-wheels/dataobject/reactive_v2").ReactiveSource<{
58
+ sent: number;
59
+ arrived: number;
60
+ maxPullSeq: number;
61
+ maxPushSeq: number;
62
+ lastSyncPullSeq: number;
63
+ lastSyncPushSeq: number;
64
+ syncStatus: import("../../common/types.js").DatabaseConnectingStatus;
65
+ }>;
66
+ }
@@ -0,0 +1,164 @@
1
+ import { handlers } from "../lib/HandlerUtils.js";
2
+ import { ServiceBase } from "./ServiceBase.js";
3
+ import { createInstanceLogFunction } from "../lib/logUtils.js";
4
+ import { UnresolvedErrorManager } from "./UnresolvedErrorManager.js";
5
+ import { yieldMicrotask } from "octagonal-wheels/promises";
6
+ import { LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "../../common/logger.js";
7
+ import { RemoteTypes } from "../../common/types.js";
8
+ import { DEFAULT_REPLICATION_STATICS } from "../../common/models/shared.definition.js";
9
+ import { reactiveSource } from "octagonal-wheels/dataobject/reactive";
10
+ import {
11
+ runWithOptionalActivity
12
+ } from "../../interfaces/AsyncActivityRunner.js";
13
+ class ReplicatorService extends ServiceBase {
14
+ constructor(context, dependencies) {
15
+ super(context);
16
+ this.dependencies = dependencies;
17
+ this.appLifecycleService = dependencies.appLifecycleService;
18
+ this._unresolvedErrorManager = new UnresolvedErrorManager(dependencies.appLifecycleService, this.context.events);
19
+ this.settingService = dependencies.settingService;
20
+ this.settingService.onRealiseSetting.addHandler(this._initialiseReplicator.bind(this));
21
+ this.databaseEventService = dependencies.databaseEventService;
22
+ this.databaseEventService.onResetDatabase.addHandler(this.disposeReplicator.bind(this));
23
+ this.databaseEventService.onDatabaseInitialisation.addHandler(this.disposeReplicator.bind(this));
24
+ this.databaseEventService.onDatabaseInitialised.addHandler(this.reinitialiseReplicator.bind(this));
25
+ this.databaseEventService.onDatabaseHasReady.addHandler(this.reinitialiseReplicator.bind(this));
26
+ this.appLifecycleService.onSuspending.addHandler(this.suspendReplication.bind(this));
27
+ }
28
+ dependencies;
29
+ boundedRemoteActivityCount = reactiveSource(0);
30
+ finiteReplicationActivityCount = reactiveSource(0);
31
+ _log = createInstanceLogFunction("ReplicatorService");
32
+ settingService;
33
+ databaseEventService;
34
+ _activeReplicator;
35
+ _replicatorType;
36
+ appLifecycleService;
37
+ _unresolvedErrorManager;
38
+ /**
39
+ * Runs one finite remote operation while exposing its lifetime to host policy and status UI.
40
+ * Continuous replication must not use this boundary.
41
+ */
42
+ async runBoundedRemoteActivity(task, options) {
43
+ return await this.runRemoteActivity(task, options, false);
44
+ }
45
+ /** Runs one finite replication and exposes its document-delivery lifetime. */
46
+ async runFiniteReplicationActivity(task, options) {
47
+ return await this.runRemoteActivity(task, options, true);
48
+ }
49
+ async runRemoteActivity(task, options, isFiniteReplication) {
50
+ this.boundedRemoteActivityCount.value++;
51
+ if (isFiniteReplication) {
52
+ this.finiteReplicationActivityCount.value++;
53
+ }
54
+ try {
55
+ return await runWithOptionalActivity(this.dependencies.activityRunner, task, options);
56
+ } finally {
57
+ if (isFiniteReplication) {
58
+ this.finiteReplicationActivityCount.value--;
59
+ }
60
+ this.boundedRemoteActivityCount.value--;
61
+ }
62
+ }
63
+ suspendReplication() {
64
+ const activeReplicator = this._activeReplicator;
65
+ if (activeReplicator) {
66
+ activeReplicator.closeReplication();
67
+ }
68
+ return Promise.resolve(true);
69
+ }
70
+ async reinitialiseReplicator() {
71
+ await this.disposeReplicator();
72
+ await yieldMicrotask();
73
+ return this._initialiseReplicator();
74
+ }
75
+ async disposeReplicator() {
76
+ this._log("Detect database reset, closing active replicator if exists.");
77
+ if (this._activeReplicator) {
78
+ await Promise.resolve(this._activeReplicator.closeReplication());
79
+ }
80
+ this._activeReplicator = void 0;
81
+ this._replicatorType = void 0;
82
+ return true;
83
+ }
84
+ async _initialiseReplicator() {
85
+ const message = this.context.translate("Replicator.Message.InitialiseFatalError");
86
+ const setting = this.settingService.currentSettings();
87
+ if (!setting) {
88
+ this._activeReplicator = void 0;
89
+ this._replicatorType = void 0;
90
+ this._unresolvedErrorManager.clearError(message);
91
+ return true;
92
+ }
93
+ const replicatorType = setting.remoteType;
94
+ const isCouchDBConfigured = replicatorType === RemoteTypes.REMOTE_COUCHDB && !!setting.couchDB_URI?.trim() && !!setting.couchDB_DBNAME?.trim();
95
+ const isMinioConfigured = replicatorType === RemoteTypes.REMOTE_MINIO && !!setting.endpoint?.trim() && !!setting.bucket?.trim();
96
+ const isP2PEnabled = replicatorType === RemoteTypes.REMOTE_P2P && setting.P2P_Enabled;
97
+ const hasReplicatorConfig = isCouchDBConfigured || isMinioConfigured || isP2PEnabled;
98
+ if (!hasReplicatorConfig) {
99
+ this._activeReplicator = void 0;
100
+ this._replicatorType = void 0;
101
+ this._unresolvedErrorManager.clearError(message);
102
+ this._log("No remote replicator configuration found. Skipping replicator initialisation.");
103
+ return true;
104
+ }
105
+ if (replicatorType === this._replicatorType && this._activeReplicator) {
106
+ this._unresolvedErrorManager.clearError(message);
107
+ this._log("Active replicator has been kept", LOG_LEVEL_VERBOSE);
108
+ return true;
109
+ } else {
110
+ this._log("Acquiring new replicator");
111
+ const newReplicator = await this.getNewReplicator();
112
+ if (!newReplicator) {
113
+ this._unresolvedErrorManager.showError(message, LOG_LEVEL_NOTICE);
114
+ return false;
115
+ }
116
+ if (this._activeReplicator) {
117
+ await Promise.resolve(this._activeReplicator.closeReplication());
118
+ this._log("Active replicator closed", LOG_LEVEL_VERBOSE);
119
+ }
120
+ this._activeReplicator = newReplicator;
121
+ this._replicatorType = replicatorType;
122
+ this.replicationStatics.value = { ...DEFAULT_REPLICATION_STATICS };
123
+ await yieldMicrotask();
124
+ if (!await this.onReplicatorInitialised()) {
125
+ this._log("Failed to initialise the replicator, onReplicatorInitialised reported some problems.");
126
+ this._activeReplicator = void 0;
127
+ this._replicatorType = void 0;
128
+ this._unresolvedErrorManager.showError(message, LOG_LEVEL_NOTICE);
129
+ return false;
130
+ }
131
+ const remoteTypeDisplay = replicatorType === RemoteTypes.REMOTE_COUCHDB ? "CouchDB" : replicatorType;
132
+ this._log(`Replicator (${remoteTypeDisplay}) initialised and activated`, LOG_LEVEL_VERBOSE);
133
+ this._unresolvedErrorManager.clearError(message);
134
+ return true;
135
+ }
136
+ }
137
+ /**
138
+ * Close the active replication if any.
139
+ * Not used currently.
140
+ */
141
+ onCloseActiveReplication = handlers().anySuccess("onCloseActiveReplication");
142
+ /**
143
+ * Get a new replicator instance based on the provided settings.
144
+ */
145
+ getNewReplicator = handlers().firstResult("getNewReplicator");
146
+ onReplicatorInitialised = handlers().bailFirstFailure("onReplicatorInitialised");
147
+ /**
148
+ * Get the currently active replicator instance.
149
+ * If no active replicator, return undefined but that is the fatal situation (on Obsidian).
150
+ */
151
+ getActiveReplicator() {
152
+ const message = "No replicator has been activated or has not been initialised yet.";
153
+ if (!this._activeReplicator) {
154
+ this._unresolvedErrorManager.showError(message, LOG_LEVEL_NOTICE);
155
+ return void 0;
156
+ }
157
+ this._unresolvedErrorManager.clearError(message);
158
+ return this._activeReplicator;
159
+ }
160
+ replicationStatics = reactiveSource({ ...DEFAULT_REPLICATION_STATICS });
161
+ }
162
+ export {
163
+ ReplicatorService
164
+ };
@@ -0,0 +1,33 @@
1
+ import { type LiveSyncEventHub } from "../../hub/hub.js";
2
+ import { type MessageTranslator } from "./MessageTranslator.js";
3
+ /** Capabilities shared by services which belong to one Commonlib client. */
4
+ export interface ServiceContextOptions {
5
+ /** An isolated event channel. A new channel is created when omitted. */
6
+ events?: LiveSyncEventHub;
7
+ /** Host-provided message translation. Keys pass through unchanged when omitted. */
8
+ translate?: MessageTranslator;
9
+ }
10
+ /**
11
+ * Minimum host-owned capabilities required by Commonlib service composition.
12
+ *
13
+ * Hosts may extend this contract with platform-specific capabilities, but the
14
+ * event channel and translator remain instance-selected and must be passed
15
+ * unchanged to every service in one composition.
16
+ */
17
+ export interface ServiceContextContract {
18
+ readonly events: LiveSyncEventHub;
19
+ readonly translate: MessageTranslator;
20
+ }
21
+ /** Instance-owned capabilities shared by a composed set of Commonlib services. */
22
+ export declare class ServiceContext implements ServiceContextContract {
23
+ readonly events: LiveSyncEventHub;
24
+ readonly translate: MessageTranslator;
25
+ constructor(options?: ServiceContextOptions);
26
+ }
27
+ /** Creates a service context without requiring a subclass. */
28
+ export declare function createServiceContext(options?: ServiceContextOptions): ServiceContext;
29
+ export declare abstract class ServiceBase<T extends ServiceContext> {
30
+ /** Context shared by the services which belong to this composition. */
31
+ readonly context: T;
32
+ constructor(context: T);
33
+ }
@@ -0,0 +1,27 @@
1
+ import { createLiveSyncEventHub } from "../../hub/hub.js";
2
+ import {
3
+ passthroughMessageTranslator
4
+ } from "./MessageTranslator.js";
5
+ class ServiceContext {
6
+ events;
7
+ translate;
8
+ constructor(options = {}) {
9
+ this.events = options.events ?? createLiveSyncEventHub();
10
+ this.translate = options.translate ?? passthroughMessageTranslator;
11
+ }
12
+ }
13
+ function createServiceContext(options = {}) {
14
+ return new ServiceContext(options);
15
+ }
16
+ class ServiceBase {
17
+ /** Context shared by the services which belong to this composition. */
18
+ context;
19
+ constructor(context) {
20
+ this.context = context;
21
+ }
22
+ }
23
+ export {
24
+ ServiceBase,
25
+ ServiceContext,
26
+ createServiceContext
27
+ };
@@ -0,0 +1,112 @@
1
+ import { type ObsidianLiveSyncSettings } from "../../common/types.js";
2
+ import type { IAPIService, ISettingService } from "./IService.js";
3
+ import { ServiceBase, type ServiceContext } from "./ServiceBase.js";
4
+ import { createInstanceLogFunction } from "../lib/logUtils.js";
5
+ export interface SettingServiceDependencies {
6
+ APIService: IAPIService;
7
+ }
8
+ export declare abstract class SettingService<T extends ServiceContext = ServiceContext> extends ServiceBase<T> implements ISettingService {
9
+ deviceAndVaultName: string;
10
+ protected APIService: IAPIService;
11
+ protected abstract setItem(key: string, value: string): void;
12
+ protected abstract getItem(key: string): string;
13
+ protected abstract deleteItem(key: string): void;
14
+ _settings: ObsidianLiveSyncSettings;
15
+ get settings(): ObsidianLiveSyncSettings;
16
+ set settings(value: ObsidianLiveSyncSettings);
17
+ protected abstract saveData(setting: ObsidianLiveSyncSettings): Promise<void>;
18
+ protected abstract loadData(): Promise<ObsidianLiveSyncSettings | undefined>;
19
+ private _lastPersistedSettings?;
20
+ _log: ReturnType<typeof createInstanceLogFunction>;
21
+ constructor(context: T, dependencies: SettingServiceDependencies);
22
+ /**
23
+ * Adjust the given settings, e.g., migrate old settings to new format.
24
+ * @param settings The settings to adjust.
25
+ */
26
+ adjustSettings(settings: ObsidianLiveSyncSettings): Promise<ObsidianLiveSyncSettings>;
27
+ /**
28
+ * Get the unique name for identify the device.
29
+ */
30
+ getDeviceAndVaultName(): string;
31
+ /**
32
+ * Set the unique name for identify the device.
33
+ * @param name The unique name to set.
34
+ */
35
+ setDeviceAndVaultName(name: string): void;
36
+ /**
37
+ * Save the current device and vault name to settings, aside from the main settings.
38
+ */
39
+ saveDeviceAndVaultName(): void;
40
+ private additionalSuffixOfDatabaseName;
41
+ private getKey;
42
+ setSmallConfig(key: string, value: string): void;
43
+ getSmallConfig(key: string): string;
44
+ deleteSmallConfig(key: string): void;
45
+ /**
46
+ * Save the current settings to storage.
47
+ */
48
+ saveSettingData(): Promise<void>;
49
+ private encryptRemoteConfigurationUris;
50
+ private decryptRemoteConfigurationUris;
51
+ /**
52
+ * Event triggered before realising the settings.
53
+ * Handlers can return false to abort the realisation process.
54
+ */
55
+ readonly onBeforeRealiseSetting: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
56
+ /**
57
+ * Event triggered after the settings have been realised.
58
+ */
59
+ readonly onSettingRealised: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
60
+ /**
61
+ * Event triggered to realise the settings.
62
+ */
63
+ readonly onRealiseSetting: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
64
+ /**
65
+ * Suspend all synchronisation activities and save to the settings.
66
+ */
67
+ readonly suspendAllSync: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
68
+ /**
69
+ * Suspend extra synchronisation activities, e.g., hidden files sync.
70
+ */
71
+ readonly suspendExtraSync: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<() => Promise<boolean>>;
72
+ /**
73
+ * Suggest enabling optional features to the user.
74
+ */
75
+ readonly suggestOptionalFeatures: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<(opt: {
76
+ enableFetch?: boolean;
77
+ enableOverwrite?: boolean;
78
+ }) => Promise<boolean>>;
79
+ /**
80
+ * Enable an optional feature and save to the settings.
81
+ * It may also raised from `handleSuggestOptionalFeatures` if the user agrees.
82
+ * @param mode The optional feature to enable.
83
+ */
84
+ readonly enableOptionalFeature: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<(mode: keyof OPTIONAL_SYNC_FEATURES) => Promise<boolean>>;
85
+ readonly onSettingLoaded: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<(settings: ObsidianLiveSyncSettings) => Promise<boolean>>;
86
+ readonly onSettingChanged: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<(settings: ObsidianLiveSyncSettings) => Promise<boolean>>;
87
+ readonly onSettingSaved: import("../lib/HandlerUtils.js").BooleanMultipleHandlerFunction<(settings: ObsidianLiveSyncSettings) => Promise<boolean>>;
88
+ readonly onBeforeSaveSettingData: import("../lib/HandlerUtils.js").CollectiveHandlerFunction<(nextSettings: ObsidianLiveSyncSettings, previousSettings: ObsidianLiveSyncSettings) => Promise<(Partial<ObsidianLiveSyncSettings> | void)[]>, unknown>;
89
+ /**
90
+ * Get the current settings.
91
+ */
92
+ currentSettings(): ObsidianLiveSyncSettings;
93
+ updateSettings(updateFn: (settings: ObsidianLiveSyncSettings) => ObsidianLiveSyncSettings, saveImmediately?: boolean): Promise<void>;
94
+ applyExternalSettings(partial: Partial<ObsidianLiveSyncSettings>, saveImmediately?: boolean): Promise<void>;
95
+ applyPartial(partial: Partial<ObsidianLiveSyncSettings>, saveImmediately?: boolean): Promise<void>;
96
+ getPassphrase(settings: ObsidianLiveSyncSettings): Promise<string | false>;
97
+ private usedPassphrase;
98
+ /**
99
+ * Clear any used passphrase from memory.
100
+ */
101
+ clearUsedPassphrase(): void;
102
+ decryptConfigurationItem(encrypted: string, passphrase: string): Promise<string | false>;
103
+ encryptConfigurationItem(src: string, settings: ObsidianLiveSyncSettings): Promise<string>;
104
+ /**
105
+ * Decrypt the given settings.
106
+ * @param settings The settings to decrypt.
107
+ */
108
+ decryptSettings(settings: ObsidianLiveSyncSettings): Promise<ObsidianLiveSyncSettings>;
109
+ loadSettings(): Promise<void>;
110
+ private tryDecodeJson;
111
+ private cloneSettings;
112
+ }