@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,52 @@
1
+ import type { AnyEntry, FilePath, FilePathWithPrefix, MetaEntry, UXFileInfo, UXFileInfoStub, UXInternalFileInfoStub } from "../common/types.js";
2
+ import type { LiveSyncEventHub } from "../hub/hub.js";
3
+ import type { IFileHandler } from "../interfaces/FileHandler.js";
4
+ import { ServiceModuleBase } from "./ServiceModuleBase.js";
5
+ import type { APIService } from "../services/base/APIService.js";
6
+ import type { DatabaseFileAccess } from "../interfaces/DatabaseFileAccess.js";
7
+ import type { StorageAccess } from "../interfaces/StorageAccess.js";
8
+ import type { FileProcessingService } from "../services/base/FileProcessingService.js";
9
+ import type { ReplicationService } from "../services/base/ReplicationService.js";
10
+ import type { ConflictService } from "../services/base/ConflictService.js";
11
+ import type { PathService } from "../services/base/PathService.js";
12
+ import type { SettingService } from "../services/base/SettingService.js";
13
+ import type { VaultService } from "../services/base/VaultService.js";
14
+ export interface ServiceFileHandlerDependencies {
15
+ events: LiveSyncEventHub;
16
+ API: APIService;
17
+ databaseFileAccess: DatabaseFileAccess;
18
+ storageAccess: StorageAccess;
19
+ fileProcessing: FileProcessingService;
20
+ replication: ReplicationService;
21
+ conflict: ConflictService;
22
+ path: PathService;
23
+ setting: SettingService;
24
+ vault: VaultService;
25
+ }
26
+ export declare abstract class ServiceFileHandlerBase extends ServiceModuleBase<ServiceFileHandlerDependencies> implements IFileHandler {
27
+ private events;
28
+ private databaseFileAccess;
29
+ private storageAccess;
30
+ private conflict;
31
+ private path;
32
+ private setting;
33
+ private vault;
34
+ constructor(services: ServiceFileHandlerDependencies);
35
+ get db(): DatabaseFileAccess;
36
+ get storage(): StorageAccess;
37
+ getPath(entry: AnyEntry): FilePathWithPrefix;
38
+ getPathWithoutPrefix(entry: AnyEntry): FilePathWithPrefix;
39
+ readFileFromStub(file: UXFileInfoStub | UXFileInfo): Promise<UXFileInfo>;
40
+ private infoToStub;
41
+ storeFileToDB(info: UXFileInfoStub | UXFileInfo | UXInternalFileInfoStub | FilePathWithPrefix, force?: boolean, onlyChunks?: boolean): Promise<boolean>;
42
+ deleteFileFromDB(info: UXFileInfoStub | UXInternalFileInfoStub | FilePath): Promise<boolean>;
43
+ renameFileInDB(info: UXFileInfoStub | UXFileInfo, oldPath: FilePath | FilePathWithPrefix): Promise<boolean>;
44
+ deleteRevisionFromDB(info: UXFileInfoStub | FilePath | FilePathWithPrefix, rev: string): Promise<boolean | undefined>;
45
+ resolveConflictedByDeletingRevision(info: UXFileInfoStub | FilePath, rev: string): Promise<boolean | undefined>;
46
+ dbToStorageWithSpecificRev(info: UXFileInfoStub | UXFileInfo | FilePath | null, rev: string, force?: boolean): Promise<boolean>;
47
+ dbToStorage(entryInfo: MetaEntry | FilePathWithPrefix, info: UXFileInfoStub | UXFileInfo | FilePath | null, force?: boolean): Promise<boolean>;
48
+ private preserveUnsyncedStorageAsConflict;
49
+ private _anyHandlerProcessesFileEvent;
50
+ _anyProcessReplicatedDoc(entry: MetaEntry): Promise<boolean>;
51
+ createAllChunks(showingNotice?: boolean): Promise<void>;
52
+ }
@@ -0,0 +1,493 @@
1
+ import { LOG_LEVEL_INFO, LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE } from "octagonal-wheels/common/logger";
2
+ import { serialized } from "octagonal-wheels/concurrency/lock";
3
+ import {
4
+ createBlob,
5
+ getDocDataAsArray,
6
+ isDocContentSame,
7
+ isTextBlob,
8
+ readAsBlob,
9
+ readContent
10
+ } from "../common/utils.js";
11
+ import { EVENT_CONFLICT_CANCELLED } from "../events/coreEvents.js";
12
+ import { shouldBeIgnored, stripAllPrefixes } from "../string_and_binary/path.js";
13
+ import { Semaphore } from "octagonal-wheels/concurrency/semaphore";
14
+ import { ServiceModuleBase } from "./ServiceModuleBase.js";
15
+ import { getStoragePathFromUXFileInfo } from "../common/typeUtils.js";
16
+ import { EVEN } from "../common/models/shared.const.symbols.js";
17
+ import { tryGetFilePath } from "../common/utils.doc.js";
18
+ async function isIncomingTextClearExtension(incomingContent, localContent) {
19
+ const incomingBlob = createBlob(incomingContent);
20
+ const localBlob = createBlob(localContent);
21
+ if (!isTextBlob(incomingBlob) || !isTextBlob(localBlob)) {
22
+ return false;
23
+ }
24
+ const incomingText = await incomingBlob.text();
25
+ const localText = await localBlob.text();
26
+ return incomingText.startsWith(localText) || incomingText.endsWith(localText);
27
+ }
28
+ async function serializedByKeys(keys, callback) {
29
+ const [key, ...remainingKeys] = keys;
30
+ if (key === void 0) return await callback();
31
+ return await serialized(key, () => serializedByKeys(remainingKeys, callback));
32
+ }
33
+ function getParentPath(path) {
34
+ const lastSeparator = path.lastIndexOf("/");
35
+ return lastSeparator < 0 ? "" : path.slice(0, lastSeparator);
36
+ }
37
+ function isFolderInfo(info) {
38
+ return info?.isFolder === true;
39
+ }
40
+ class ServiceFileHandlerBase extends ServiceModuleBase {
41
+ events;
42
+ databaseFileAccess;
43
+ storageAccess;
44
+ conflict;
45
+ path;
46
+ setting;
47
+ vault;
48
+ constructor(services) {
49
+ super(services);
50
+ this.events = services.events;
51
+ this.databaseFileAccess = services.databaseFileAccess;
52
+ this.storageAccess = services.storageAccess;
53
+ this.conflict = services.conflict;
54
+ this.path = services.path;
55
+ this.setting = services.setting;
56
+ this.vault = services.vault;
57
+ services.fileProcessing.processFileEvent.addHandler(this._anyHandlerProcessesFileEvent.bind(this), 100);
58
+ services.replication.processSynchroniseResult.addHandler(this._anyProcessReplicatedDoc.bind(this), 100);
59
+ }
60
+ get db() {
61
+ return this.databaseFileAccess;
62
+ }
63
+ get storage() {
64
+ return this.storageAccess;
65
+ }
66
+ getPath(entry) {
67
+ return this.path.getPath(entry);
68
+ }
69
+ getPathWithoutPrefix(entry) {
70
+ return stripAllPrefixes(this.path.getPath(entry));
71
+ }
72
+ async readFileFromStub(file) {
73
+ if ("body" in file && file.body) {
74
+ return file;
75
+ }
76
+ const readFile = await this.storage.readStubContent(file);
77
+ if (!readFile) {
78
+ throw new Error(`File ${file.path} is not exist on the storage`);
79
+ }
80
+ return readFile;
81
+ }
82
+ async infoToStub(info) {
83
+ if (info == null) return null;
84
+ const file = typeof info === "string" ? await this.storage.getFileStub(info) : info;
85
+ return file;
86
+ }
87
+ async storeFileToDB(info, force = false, onlyChunks = false) {
88
+ const file = await this.infoToStub(info);
89
+ if (file == null) {
90
+ this._log(`File ${tryGetFilePath(info)} is not exist on the storage`, LOG_LEVEL_VERBOSE);
91
+ return false;
92
+ }
93
+ if (file.isInternal) {
94
+ this._log(
95
+ `Internal file ${file.path} is not allowed to be processed on processFileEvent`,
96
+ LOG_LEVEL_VERBOSE
97
+ );
98
+ return false;
99
+ }
100
+ const entry = await this.db.fetchEntry(file, void 0, true, true);
101
+ if (!entry || entry.deleted || entry._deleted) {
102
+ const readFile = await this.readFileFromStub(file);
103
+ if (!onlyChunks) {
104
+ return await this.db.store(readFile);
105
+ } else {
106
+ return await this.db.createChunks(readFile, false, true);
107
+ }
108
+ }
109
+ let shouldApplied = false;
110
+ if (!force && !onlyChunks) {
111
+ if (this.path.compareFileFreshness(file, entry) !== EVEN) {
112
+ shouldApplied = true;
113
+ }
114
+ let readFile = void 0;
115
+ if (!shouldApplied) {
116
+ readFile = await this.readFileFromStub(file);
117
+ if (!readFile) {
118
+ this._log(`File ${file.path} is not exist on the storage`, LOG_LEVEL_NOTICE);
119
+ return false;
120
+ }
121
+ if (await isDocContentSame(getDocDataAsArray(entry.data), readFile.body)) {
122
+ this.path.markChangesAreSame(readFile, readFile.stat.mtime, entry.mtime);
123
+ } else {
124
+ shouldApplied = true;
125
+ }
126
+ }
127
+ if (!shouldApplied) {
128
+ this._log(`File ${file.path} is not changed`, LOG_LEVEL_VERBOSE);
129
+ return true;
130
+ }
131
+ if (!readFile) readFile = await this.readFileFromStub(file);
132
+ if (onlyChunks) {
133
+ return await this.db.createChunks(readFile, false, true);
134
+ } else {
135
+ return await this.db.store(readFile, false, true);
136
+ }
137
+ } else {
138
+ const readFile = await this.readFileFromStub(file);
139
+ if (onlyChunks) {
140
+ return await this.db.createChunks(readFile, true, true);
141
+ } else {
142
+ return await this.db.store(readFile, true, true);
143
+ }
144
+ }
145
+ }
146
+ async deleteFileFromDB(info) {
147
+ const file = await this.infoToStub(info);
148
+ if (file == null) {
149
+ const path = typeof info === "string" ? info : tryGetFilePath(info);
150
+ if (path === void 0) {
151
+ this._log(`File ${tryGetFilePath(info)} is not exist on the storage`, LOG_LEVEL_VERBOSE);
152
+ return false;
153
+ }
154
+ const entryByPath = await this.db.fetchEntry(path, void 0, true, true);
155
+ if (!entryByPath || entryByPath.deleted || entryByPath._deleted) {
156
+ this._log(
157
+ `File ${path} is not exist on the storage nor the database (or already deleted)`,
158
+ LOG_LEVEL_VERBOSE
159
+ );
160
+ return false;
161
+ }
162
+ this._log(`File ${path} is missing on storage; deleting from the database by path`, LOG_LEVEL_INFO);
163
+ return await this.db.delete(path);
164
+ }
165
+ if (file.isInternal) {
166
+ this._log(
167
+ `Internal file ${file.path} is not allowed to be processed on processFileEvent`,
168
+ LOG_LEVEL_VERBOSE
169
+ );
170
+ return false;
171
+ }
172
+ const entry = await this.db.fetchEntry(file, void 0, true, true);
173
+ if (!entry || entry.deleted || entry._deleted) {
174
+ this._log(`File ${file.path} is not exist or already deleted on the database`, LOG_LEVEL_VERBOSE);
175
+ return false;
176
+ }
177
+ const conflictedRevs = await this.db.getConflictedRevs(file);
178
+ if (conflictedRevs.length > 0) {
179
+ return await this.db.delete(file, entry._rev);
180
+ }
181
+ return await this.db.delete(file);
182
+ }
183
+ async renameFileInDB(info, oldPath) {
184
+ const newPath = getStoragePathFromUXFileInfo(info);
185
+ const [oldDocumentId, newDocumentId] = await Promise.all([
186
+ this.path.path2id(oldPath),
187
+ this.path.path2id(newPath)
188
+ ]);
189
+ if (oldDocumentId === newDocumentId) {
190
+ this._log(`Updating the stored path for case-only rename: ${oldPath} -> ${newPath}`, LOG_LEVEL_VERBOSE);
191
+ return await this.storeFileToDB(info, true);
192
+ }
193
+ const oldEntry = await this.db.fetchEntryMeta(oldPath, void 0, true);
194
+ if (!await this.storeFileToDB(info, true)) {
195
+ this._log(`Failed to store rename target; preserving source in the database: ${oldPath}`, LOG_LEVEL_NOTICE);
196
+ return false;
197
+ }
198
+ if (!oldEntry || oldEntry.deleted || oldEntry._deleted) {
199
+ this._log(`Rename source is not present in the database: ${oldPath}`, LOG_LEVEL_VERBOSE);
200
+ return true;
201
+ }
202
+ const oldFile = {
203
+ path: oldPath,
204
+ name: oldPath.split("/").pop() ?? info.name,
205
+ stat: info.stat,
206
+ deleted: true
207
+ };
208
+ return await this.deleteFileFromDB(oldFile);
209
+ }
210
+ async deleteRevisionFromDB(info, rev) {
211
+ return await this.db.delete(info, rev);
212
+ }
213
+ async resolveConflictedByDeletingRevision(info, rev) {
214
+ const path = getStoragePathFromUXFileInfo(info);
215
+ if (!await this.deleteRevisionFromDB(info, rev)) {
216
+ this._log(`Failed to delete the conflicted revision ${rev} of ${path}`, LOG_LEVEL_VERBOSE);
217
+ return false;
218
+ }
219
+ if (!await this.dbToStorageWithSpecificRev(info, rev, true)) {
220
+ this._log(`Failed to apply the resolved revision ${rev} of ${path} to the storage`, LOG_LEVEL_VERBOSE);
221
+ return false;
222
+ }
223
+ }
224
+ async dbToStorageWithSpecificRev(info, rev, force) {
225
+ const file = await this.infoToStub(info);
226
+ if (file == null) {
227
+ this._log(`File ${tryGetFilePath(info)} is not exist on the storage`, LOG_LEVEL_VERBOSE);
228
+ return false;
229
+ }
230
+ const docEntry = await this.db.fetchEntryMeta(file, rev, true);
231
+ if (!docEntry) {
232
+ this._log(`File ${file.path} is not exist on the database`, LOG_LEVEL_VERBOSE);
233
+ return false;
234
+ }
235
+ return await this.dbToStorage(docEntry, file, force);
236
+ }
237
+ async dbToStorage(entryInfo, info, force) {
238
+ const file = await this.infoToStub(info);
239
+ const mode = file == null ? "create" : "modify";
240
+ const pathFromEntryInfo = typeof entryInfo === "string" ? entryInfo : this.getPath(entryInfo);
241
+ const docEntry = await this.db.fetchEntryMeta(pathFromEntryInfo, void 0, true);
242
+ if (!docEntry) {
243
+ this._log(`File ${pathFromEntryInfo} is not exist on the database`, LOG_LEVEL_VERBOSE);
244
+ return false;
245
+ }
246
+ const path = this.getPath(docEntry);
247
+ const settings = this.setting.currentSettings();
248
+ const revs = await this.db.getConflictedRevs(path);
249
+ if (revs.length > 0) {
250
+ if (settings.writeDocumentsIfConflicted) {
251
+ } else {
252
+ await this.conflict.queueCheckForIfOpen(path);
253
+ return true;
254
+ }
255
+ }
256
+ let existDoc = await this.storage.getStub(path);
257
+ if (isFolderInfo(existDoc)) {
258
+ this._log(`Folder ${path} is already exist on the storage as a folder`, LOG_LEVEL_VERBOSE);
259
+ return true;
260
+ }
261
+ const existOnDB = !(docEntry._deleted || docEntry.deleted || false);
262
+ if (!existOnDB && !existDoc) {
263
+ this._log(`File ${path} seems to be deleted, but already not on storage`, LOG_LEVEL_VERBOSE);
264
+ return true;
265
+ }
266
+ if (!existOnDB && existDoc) {
267
+ if (!force && !settings.writeDocumentsIfConflicted && await this.preserveUnsyncedStorageAsConflict(path, existDoc, docEntry)) {
268
+ return true;
269
+ }
270
+ await this.storage.deleteVaultItem(path);
271
+ return true;
272
+ }
273
+ if (existDoc && existDoc.path !== path) {
274
+ const [existingDocumentId, targetDocumentId] = await Promise.all([
275
+ this.path.path2id(existDoc.path),
276
+ this.path.path2id(path)
277
+ ]);
278
+ if (existingDocumentId !== targetDocumentId) {
279
+ this._log(
280
+ `Refusing to overwrite ${existDoc.path} while applying the distinct path ${path}`,
281
+ LOG_LEVEL_NOTICE
282
+ );
283
+ return false;
284
+ }
285
+ if (getParentPath(existDoc.path) !== getParentPath(path)) {
286
+ this._log(
287
+ `Refusing to apply a filename case change across differently cased parent directories: ${existDoc.path} -> ${path}`,
288
+ LOG_LEVEL_NOTICE
289
+ );
290
+ return false;
291
+ }
292
+ const renamedFile = await this.storage.renameFile(existDoc, path);
293
+ if (!renamedFile) {
294
+ this._log(`Could not apply the stored filename case: ${existDoc.path} -> ${path}`, LOG_LEVEL_NOTICE);
295
+ return false;
296
+ }
297
+ existDoc = renamedFile;
298
+ }
299
+ const docRead = await this.db.fetchEntryFromMeta(docEntry);
300
+ if (!docRead) {
301
+ this._log(`File ${path} is not exist on the database`, LOG_LEVEL_VERBOSE);
302
+ return false;
303
+ }
304
+ if (!settings.processSizeMismatchedFiles) {
305
+ if (docRead.size != 0 && docRead.size !== readAsBlob(docRead).size) {
306
+ this._log(
307
+ `File ${path} seems to be corrupted! Writing prevented. (${docRead.size} != ${readAsBlob(docRead).size})`,
308
+ LOG_LEVEL_NOTICE
309
+ );
310
+ return false;
311
+ }
312
+ }
313
+ const docData = readContent(docRead);
314
+ if (existDoc && !force) {
315
+ let shouldApplied = false;
316
+ const freshness = this.path.compareFileFreshness(existDoc, docEntry);
317
+ if (freshness !== EVEN) {
318
+ shouldApplied = true;
319
+ }
320
+ if (!shouldApplied) {
321
+ const readFile = await this.readFileFromStub(existDoc);
322
+ if (await isDocContentSame(docData, readFile.body)) {
323
+ shouldApplied = false;
324
+ this.path.markChangesAreSame(docRead, docRead.mtime, existDoc.stat.mtime);
325
+ } else {
326
+ shouldApplied = true;
327
+ }
328
+ }
329
+ if (!shouldApplied) {
330
+ this._log(`File ${docRead.path} is not changed`, LOG_LEVEL_VERBOSE);
331
+ return true;
332
+ }
333
+ if (!force && !settings.writeDocumentsIfConflicted && await this.preserveUnsyncedStorageAsConflict(path, existDoc, docEntry, docData)) {
334
+ return true;
335
+ }
336
+ } else {
337
+ this._log(
338
+ `File ${docRead.path} ${existDoc ? "(new) " : ""} ${force ? " (forced)" : ""}`,
339
+ LOG_LEVEL_VERBOSE
340
+ );
341
+ }
342
+ await this.storage.ensureDir(path);
343
+ const ret = await this.storage.writeFileAuto(path, docData, { ctime: docRead.ctime, mtime: docRead.mtime });
344
+ await this.storage.touched(path);
345
+ this.storage.triggerFileEvent(mode, path);
346
+ return ret;
347
+ }
348
+ async preserveUnsyncedStorageAsConflict(path, existDoc, incomingEntry, incomingContent) {
349
+ const readFile = await this.readFileFromStub(existDoc);
350
+ if (incomingContent && await isDocContentSame(incomingContent, readFile.body)) {
351
+ return false;
352
+ }
353
+ if (incomingContent && await isIncomingTextClearExtension(incomingContent, readFile.body)) {
354
+ return false;
355
+ }
356
+ if (!incomingEntry._rev) {
357
+ return false;
358
+ }
359
+ if (await this.db.hasContentInRevisionHistory(path, readFile.body, incomingEntry._rev)) {
360
+ return false;
361
+ }
362
+ const stored = await this.db.storeAsConflictedRevision(readFile, incomingEntry._rev, true);
363
+ if (!stored) {
364
+ this._log(`Prevented overwriting unsynchronised local changes for ${path}`, LOG_LEVEL_NOTICE);
365
+ return true;
366
+ }
367
+ this._log(`Preserved unsynchronised local changes as a conflict for ${path}`, LOG_LEVEL_NOTICE);
368
+ await this.conflict.queueCheckFor(path);
369
+ return true;
370
+ }
371
+ async _anyHandlerProcessesFileEvent(item) {
372
+ const eventItem = item.args;
373
+ const type = item.type;
374
+ const path = eventItem.file.path;
375
+ if (!await this.vault.isTargetFile(path)) {
376
+ this._log(`File ${path} is not the target file`, LOG_LEVEL_VERBOSE);
377
+ return false;
378
+ }
379
+ if (shouldBeIgnored(path)) {
380
+ this._log(`File ${path} should be ignored`, LOG_LEVEL_VERBOSE);
381
+ return false;
382
+ }
383
+ if (type === "RENAME" && !eventItem.oldPath) {
384
+ this._log(`Rename event for ${path} has no source path`, LOG_LEVEL_VERBOSE);
385
+ return false;
386
+ }
387
+ const eventPaths = type === "RENAME" ? [path, eventItem.oldPath] : [path];
388
+ const documentIds = await Promise.all(eventPaths.map((eventPath) => this.path.path2id(eventPath)));
389
+ const lockKeys = [...new Set(documentIds)].sort().map((documentId) => `processFileEvent-${documentId}`);
390
+ return await serializedByKeys(lockKeys, async () => {
391
+ switch (type) {
392
+ case "CREATE":
393
+ case "CHANGED":
394
+ return await this.storeFileToDB(item.args.file);
395
+ case "DELETE":
396
+ return await this.deleteFileFromDB(item.args.file);
397
+ case "RENAME":
398
+ return await this.renameFileInDB(
399
+ item.args.file,
400
+ item.args.oldPath
401
+ );
402
+ case "INTERNAL":
403
+ return false;
404
+ default:
405
+ this._log(`Unsupported event type: ${type}`, LOG_LEVEL_VERBOSE);
406
+ return false;
407
+ }
408
+ });
409
+ }
410
+ async _anyProcessReplicatedDoc(entry) {
411
+ return await serialized(`processReplicatedDoc-${entry._id}`, async () => {
412
+ if (!await this.vault.isTargetFile(entry.path)) {
413
+ this._log(`File ${entry.path} is not the target file`, LOG_LEVEL_VERBOSE);
414
+ return false;
415
+ }
416
+ if (this.vault.isFileSizeTooLarge(entry.size)) {
417
+ this._log(`File ${entry.path} is too large (on database) to be processed`, LOG_LEVEL_VERBOSE);
418
+ return false;
419
+ }
420
+ if (shouldBeIgnored(entry.path)) {
421
+ this._log(`File ${entry.path} should be ignored`, LOG_LEVEL_VERBOSE);
422
+ return false;
423
+ }
424
+ const path = this.getPath(entry);
425
+ const targetFile = await this.storage.getStub(this.getPathWithoutPrefix(entry));
426
+ if (isFolderInfo(targetFile)) {
427
+ this._log(`${path} is already exist as the folder`);
428
+ return true;
429
+ } else {
430
+ if (targetFile && this.vault.isFileSizeTooLarge(targetFile.stat.size)) {
431
+ this._log(`File ${targetFile.path} is too large (on storage) to be processed`, LOG_LEVEL_VERBOSE);
432
+ return false;
433
+ }
434
+ this._log(
435
+ `Processing ${path} (${entry._id.substring(0, 8)} :${entry._rev?.substring(0, 5)}) : Started...`,
436
+ LOG_LEVEL_VERBOSE
437
+ );
438
+ this.events.emitEvent(EVENT_CONFLICT_CANCELLED, path);
439
+ const ret = await this.dbToStorage(entry, targetFile);
440
+ this._log(`Processing ${path} (${entry._id.substring(0, 8)} :${entry._rev?.substring(0, 5)}) : Done`);
441
+ return ret;
442
+ }
443
+ });
444
+ }
445
+ async createAllChunks(showingNotice) {
446
+ this._log("Collecting local files on the storage", LOG_LEVEL_VERBOSE);
447
+ const semaphore = Semaphore(10);
448
+ let processed = 0;
449
+ const filesStorageSrc = await this.storage.getFiles();
450
+ const incProcessed = () => {
451
+ processed++;
452
+ if (processed % 25 == 0)
453
+ this._log(
454
+ `Creating missing chunks: ${processed} of ${total} files`,
455
+ showingNotice ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
456
+ "chunkCreation"
457
+ );
458
+ };
459
+ const total = filesStorageSrc.length;
460
+ const procAllChunks = filesStorageSrc.map(async (file) => {
461
+ if (!await this.vault.isTargetFile(file)) {
462
+ incProcessed();
463
+ return true;
464
+ }
465
+ if (this.vault.isFileSizeTooLarge(file.stat.size)) {
466
+ incProcessed();
467
+ return true;
468
+ }
469
+ if (shouldBeIgnored(file.path)) {
470
+ incProcessed();
471
+ return true;
472
+ }
473
+ const release = await semaphore.acquire();
474
+ incProcessed();
475
+ try {
476
+ await this.storeFileToDB(file, false, true);
477
+ } catch (ex) {
478
+ this._log(ex, LOG_LEVEL_VERBOSE);
479
+ } finally {
480
+ release();
481
+ }
482
+ });
483
+ await Promise.all(procAllChunks);
484
+ this._log(
485
+ `Creating chunks Done: ${processed} of ${total} files`,
486
+ showingNotice ? LOG_LEVEL_NOTICE : LOG_LEVEL_INFO,
487
+ "chunkCreation"
488
+ );
489
+ }
490
+ }
491
+ export {
492
+ ServiceFileHandlerBase
493
+ };
@@ -0,0 +1,10 @@
1
+ import type { APIService } from "../services/base/APIService.js";
2
+ import { createInstanceLogFunction } from "../services/lib/logUtils.js";
3
+ export interface ServiceModuleBaseDependencies {
4
+ API: APIService;
5
+ }
6
+ export declare abstract class ServiceModuleBase<T extends ServiceModuleBaseDependencies> {
7
+ _log: ReturnType<typeof createInstanceLogFunction>;
8
+ get name(): string;
9
+ constructor(services: T);
10
+ }
@@ -0,0 +1,13 @@
1
+ import { createInstanceLogFunction } from "../services/lib/logUtils.js";
2
+ class ServiceModuleBase {
3
+ _log;
4
+ get name() {
5
+ return this.constructor.name;
6
+ }
7
+ constructor(services) {
8
+ this._log = createInstanceLogFunction(this.name, services.API);
9
+ }
10
+ }
11
+ export {
12
+ ServiceModuleBase
13
+ };
@@ -0,0 +1,15 @@
1
+ import type { UXFileInfoStub, UXFolderInfo } from "../../common/types.js";
2
+ /**
3
+ * Conversion adapter interface
4
+ * Converts between native file system types and universal types
5
+ */
6
+ export interface IConversionAdapter<TNativeFile = any, TNativeFolder = any> {
7
+ /**
8
+ * Convert a native file object to a universal file info stub
9
+ */
10
+ nativeFileToUXFileInfoStub(file: TNativeFile): UXFileInfoStub;
11
+ /**
12
+ * Convert a native folder object to a universal folder info
13
+ */
14
+ nativeFolderToUXFolder(folder: TNativeFolder): UXFolderInfo;
15
+ }
@@ -0,0 +1,47 @@
1
+ import type { FilePath, UXStat } from "../../common/types.js";
2
+ import type { IPathAdapter } from "./IPathAdapter.js";
3
+ import type { ITypeGuardAdapter } from "./ITypeGuardAdapter.js";
4
+ import type { IConversionAdapter } from "./IConversionAdapter.js";
5
+ import type { IStorageAdapter } from "./IStorageAdapter.js";
6
+ import type { IVaultAdapter } from "./IVaultAdapter.js";
7
+ /**
8
+ * Main file system adapter interface
9
+ * Composes all other adapters and provides platform-specific operations
10
+ */
11
+ export interface IFileSystemAdapter<TNativeAbstractFile = any, TNativeFile = any, TNativeFolder = any, TStat extends UXStat = UXStat> {
12
+ /** Path operations */
13
+ readonly path: IPathAdapter<TNativeAbstractFile>;
14
+ /** Type guard operations */
15
+ readonly typeGuard: ITypeGuardAdapter<TNativeFile, TNativeFolder>;
16
+ /** Conversion operations */
17
+ readonly conversion: IConversionAdapter<TNativeFile, TNativeFolder>;
18
+ /** Storage operations */
19
+ readonly storage: IStorageAdapter<TStat>;
20
+ /** Vault operations */
21
+ readonly vault: IVaultAdapter<TNativeFile>;
22
+ /**
23
+ * Get a file or folder by path (case-sensitive)
24
+ */
25
+ getAbstractFileByPath(path: FilePath | string): Promise<TNativeAbstractFile | null>;
26
+ /**
27
+ * Get a file or folder by path (case-insensitive)
28
+ */
29
+ getAbstractFileByPathInsensitive(path: FilePath | string): Promise<TNativeAbstractFile | null>;
30
+ /**
31
+ * Get all files in the vault
32
+ */
33
+ getFiles(): Promise<TNativeFile[]>;
34
+ /**
35
+ * Rename a file and refresh any platform-specific caches
36
+ */
37
+ renameFile(file: TNativeFile, newPath: string): Promise<TNativeFile>;
38
+ /**
39
+ * Get file statistics from a native file object
40
+ */
41
+ statFromNative(file: TNativeFile): Promise<UXStat>;
42
+ /**
43
+ * Reconcile internal file state
44
+ * Platform-specific operation for syncing internal metadata
45
+ */
46
+ reconcileInternalFile(path: string): Promise<void>;
47
+ }
@@ -0,0 +1,15 @@
1
+ import type { FilePath } from "../../common/types.js";
2
+ /**
3
+ * Path operations adapter interface
4
+ * Handles path normalization and extraction
5
+ */
6
+ export interface IPathAdapter<TNativeAbstractFile = any> {
7
+ /**
8
+ * Get the path from a file object or return the path string as-is
9
+ */
10
+ getPath(file: TNativeAbstractFile | string): FilePath;
11
+ /**
12
+ * Normalize a path according to the platform's conventions
13
+ */
14
+ normalisePath(path: string): string;
15
+ }
File without changes