@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.
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/API/DirectFileManipulator.d.ts +2 -0
- package/dist/API/DirectFileManipulator.js +4 -0
- package/dist/API/DirectFileManipulatorV2.d.ts +150 -0
- package/dist/API/DirectFileManipulatorV2.js +424 -0
- package/dist/API/processSetting.d.ts +41 -0
- package/dist/API/processSetting.js +140 -0
- package/dist/ContentSplitter/ContentSplitter.d.ts +28 -0
- package/dist/ContentSplitter/ContentSplitter.js +5 -0
- package/dist/ContentSplitter/ContentSplitterBase.d.ts +51 -0
- package/dist/ContentSplitter/ContentSplitterBase.js +83 -0
- package/dist/ContentSplitter/ContentSplitterRabinKarp.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterRabinKarp.js +32 -0
- package/dist/ContentSplitter/ContentSplitterV1.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterV1.js +34 -0
- package/dist/ContentSplitter/ContentSplitterV2.d.ts +9 -0
- package/dist/ContentSplitter/ContentSplitterV2.js +34 -0
- package/dist/ContentSplitter/ContentSplitters.d.ts +12 -0
- package/dist/ContentSplitter/ContentSplitters.js +29 -0
- package/dist/bureau/bureau.d.ts +7 -0
- package/dist/bureau/bureau.js +5 -0
- package/dist/common/ConnectionString.d.ts +30 -0
- package/dist/common/ConnectionString.js +179 -0
- package/dist/common/LSError.d.ts +48 -0
- package/dist/common/LSError.js +112 -0
- package/dist/common/configForDoc.d.ts +79 -0
- package/dist/common/configForDoc.js +312 -0
- package/dist/common/coreEnvFunctions.d.ts +21 -0
- package/dist/common/coreEnvFunctions.js +22 -0
- package/dist/common/coreEnvVars.d.ts +3 -0
- package/dist/common/coreEnvVars.js +6 -0
- package/dist/common/i18n.d.ts +18 -0
- package/dist/common/i18n.js +7193 -0
- package/dist/common/logger.d.ts +2 -0
- package/dist/common/logger.js +1 -0
- package/dist/common/messages/combinedMessages.dev.d.ts +7 -0
- package/dist/common/messages/combinedMessages.dev.js +44 -0
- package/dist/common/messages/combinedMessages.prod.d.ts +9264 -0
- package/dist/common/messages/combinedMessages.prod.js +9271 -0
- package/dist/common/messages/de.d.ts +297 -0
- package/dist/common/messages/de.js +7 -0
- package/dist/common/messages/def.d.ts +1119 -0
- package/dist/common/messages/def.js +7 -0
- package/dist/common/messages/es.d.ts +689 -0
- package/dist/common/messages/es.js +7 -0
- package/dist/common/messages/fr.d.ts +582 -0
- package/dist/common/messages/fr.js +7 -0
- package/dist/common/messages/he.d.ts +583 -0
- package/dist/common/messages/he.js +7 -0
- package/dist/common/messages/ja.d.ts +838 -0
- package/dist/common/messages/ja.js +7 -0
- package/dist/common/messages/ko.d.ts +800 -0
- package/dist/common/messages/ko.js +7 -0
- package/dist/common/messages/ru.d.ts +858 -0
- package/dist/common/messages/ru.js +7 -0
- package/dist/common/messages/zh-tw.d.ts +384 -0
- package/dist/common/messages/zh-tw.js +7 -0
- package/dist/common/messages/zh.d.ts +1093 -0
- package/dist/common/messages/zh.js +7 -0
- package/dist/common/messagesJson/de.json +295 -0
- package/dist/common/messagesJson/en.json +1117 -0
- package/dist/common/messagesJson/es.json +687 -0
- package/dist/common/messagesJson/fr.json +580 -0
- package/dist/common/messagesJson/he.json +581 -0
- package/dist/common/messagesJson/ja.json +836 -0
- package/dist/common/messagesJson/ko.json +798 -0
- package/dist/common/messagesJson/ru.json +856 -0
- package/dist/common/messagesJson/zh-tw.json +382 -0
- package/dist/common/messagesJson/zh.json +1091 -0
- package/dist/common/models/auth.type.d.ts +41 -0
- package/dist/common/models/auth.type.js +0 -0
- package/dist/common/models/db.const.d.ts +20 -0
- package/dist/common/models/db.const.js +28 -0
- package/dist/common/models/db.definition.d.ts +56 -0
- package/dist/common/models/db.definition.js +6 -0
- package/dist/common/models/db.type.d.ts +142 -0
- package/dist/common/models/db.type.js +0 -0
- package/dist/common/models/diff.definition.d.ts +16 -0
- package/dist/common/models/diff.definition.js +0 -0
- package/dist/common/models/fileaccess.const.d.ts +7 -0
- package/dist/common/models/fileaccess.const.js +16 -0
- package/dist/common/models/fileaccess.type.d.ts +72 -0
- package/dist/common/models/fileaccess.type.js +0 -0
- package/dist/common/models/redflag.const.d.ts +32 -0
- package/dist/common/models/redflag.const.js +27 -0
- package/dist/common/models/setting.const.d.ts +49 -0
- package/dist/common/models/setting.const.defaults.d.ts +3 -0
- package/dist/common/models/setting.const.defaults.js +185 -0
- package/dist/common/models/setting.const.js +68 -0
- package/dist/common/models/setting.const.preferred.d.ts +5 -0
- package/dist/common/models/setting.const.preferred.js +35 -0
- package/dist/common/models/setting.const.qr.d.ts +2 -0
- package/dist/common/models/setting.const.qr.js +174 -0
- package/dist/common/models/setting.type.d.ts +900 -0
- package/dist/common/models/setting.type.js +8 -0
- package/dist/common/models/shared.const.behabiour.d.ts +28 -0
- package/dist/common/models/shared.const.behabiour.js +36 -0
- package/dist/common/models/shared.const.d.ts +5 -0
- package/dist/common/models/shared.const.js +12 -0
- package/dist/common/models/shared.const.symbols.d.ts +9 -0
- package/dist/common/models/shared.const.symbols.js +20 -0
- package/dist/common/models/shared.definition.configNames.d.ts +36 -0
- package/dist/common/models/shared.definition.configNames.js +203 -0
- package/dist/common/models/shared.definition.d.ts +22 -0
- package/dist/common/models/shared.definition.js +24 -0
- package/dist/common/models/shared.type.util.d.ts +8 -0
- package/dist/common/models/shared.type.util.js +0 -0
- package/dist/common/models/sync.definition.d.ts +18 -0
- package/dist/common/models/sync.definition.js +20 -0
- package/dist/common/models/tweak.definition.d.ts +191 -0
- package/dist/common/models/tweak.definition.js +77 -0
- package/dist/common/rosetta.d.ts +42 -0
- package/dist/common/rosetta.js +57 -0
- package/dist/common/settingConstants.d.ts +216 -0
- package/dist/common/settingConstants.js +434 -0
- package/dist/common/typeUtils.d.ts +17 -0
- package/dist/common/typeUtils.js +51 -0
- package/dist/common/types.d.ts +107 -0
- package/dist/common/types.js +212 -0
- package/dist/common/utils.d.ts +129 -0
- package/dist/common/utils.doc.d.ts +11 -0
- package/dist/common/utils.doc.js +35 -0
- package/dist/common/utils.js +583 -0
- package/dist/common/utils.object.d.ts +2 -0
- package/dist/common/utils.object.js +14 -0
- package/dist/common/utils.patch.d.ts +8 -0
- package/dist/common/utils.patch.js +178 -0
- package/dist/common/utils.type.d.ts +1 -0
- package/dist/common/utils.type.js +0 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.js +14 -0
- package/dist/databases/IndexedDBKeyValueDatabase.d.ts +26 -0
- package/dist/databases/IndexedDBKeyValueDatabase.js +130 -0
- package/dist/dataobject/StoredMap.d.ts +12 -0
- package/dist/dataobject/StoredMap.js +47 -0
- package/dist/dev/checks.d.ts +5 -0
- package/dist/dev/checks.js +38 -0
- package/dist/encryption/encryptHKDF.d.ts +3 -0
- package/dist/encryption/encryptHKDF.js +7 -0
- package/dist/encryption/stringEncryption.d.ts +27 -0
- package/dist/encryption/stringEncryption.js +59 -0
- package/dist/events/coreEvents.d.ts +54 -0
- package/dist/events/coreEvents.js +46 -0
- package/dist/hub/hub.d.ts +11 -0
- package/dist/hub/hub.js +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/interfaces/AsyncActivityRunner.d.ts +18 -0
- package/dist/interfaces/AsyncActivityRunner.js +7 -0
- package/dist/interfaces/Confirm.d.ts +17 -0
- package/dist/interfaces/Confirm.js +0 -0
- package/dist/interfaces/DatabaseFileAccess.d.ts +14 -0
- package/dist/interfaces/DatabaseFileAccess.js +0 -0
- package/dist/interfaces/DatabaseRebuilder.d.ts +13 -0
- package/dist/interfaces/DatabaseRebuilder.js +0 -0
- package/dist/interfaces/FileHandler.d.ts +13 -0
- package/dist/interfaces/FileHandler.js +0 -0
- package/dist/interfaces/KeyValueDatabase.d.ts +11 -0
- package/dist/interfaces/KeyValueDatabase.js +0 -0
- package/dist/interfaces/ServiceModule.d.ts +59 -0
- package/dist/interfaces/ServiceModule.js +19 -0
- package/dist/interfaces/StorageAccess.d.ts +44 -0
- package/dist/interfaces/StorageAccess.js +0 -0
- package/dist/interfaces/StorageEventManager.d.ts +16 -0
- package/dist/interfaces/StorageEventManager.js +5 -0
- package/dist/managers/ChangeManager.d.ts +61 -0
- package/dist/managers/ChangeManager.js +104 -0
- package/dist/managers/ChunkDeliveryCoordinator.d.ts +51 -0
- package/dist/managers/ChunkDeliveryCoordinator.js +136 -0
- package/dist/managers/ChunkFetcher.d.ts +44 -0
- package/dist/managers/ChunkFetcher.js +251 -0
- package/dist/managers/ChunkManager.d.ts +2 -0
- package/dist/managers/ChunkManager.js +4 -0
- package/dist/managers/ConflictManager.d.ts +37 -0
- package/dist/managers/ConflictManager.js +322 -0
- package/dist/managers/EntryManager/EntryManager.d.ts +37 -0
- package/dist/managers/EntryManager/EntryManager.js +73 -0
- package/dist/managers/EntryManager/EntryManagerImpls.d.ts +74 -0
- package/dist/managers/EntryManager/EntryManagerImpls.js +499 -0
- package/dist/managers/HashManager/HashManager.d.ts +60 -0
- package/dist/managers/HashManager/HashManager.js +97 -0
- package/dist/managers/HashManager/HashManagerCore.d.ts +114 -0
- package/dist/managers/HashManager/HashManagerCore.js +99 -0
- package/dist/managers/HashManager/PureJSHashManager.d.ts +77 -0
- package/dist/managers/HashManager/PureJSHashManager.js +84 -0
- package/dist/managers/HashManager/XXHashHashManager.d.ts +96 -0
- package/dist/managers/HashManager/XXHashHashManager.js +111 -0
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.d.ts +30 -0
- package/dist/managers/LayeredChunkManager/ArrivalWaitLayer.js +115 -0
- package/dist/managers/LayeredChunkManager/CacheLayer.d.ts +59 -0
- package/dist/managers/LayeredChunkManager/CacheLayer.js +161 -0
- package/dist/managers/LayeredChunkManager/ChunkLayerInterfaces.d.ts +37 -0
- package/dist/managers/LayeredChunkManager/ChunkLayerInterfaces.js +0 -0
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.d.ts +14 -0
- package/dist/managers/LayeredChunkManager/DatabaseReadLayer.js +78 -0
- package/dist/managers/LayeredChunkManager/DatabaseWriteLayer.d.ts +11 -0
- package/dist/managers/LayeredChunkManager/DatabaseWriteLayer.js +43 -0
- package/dist/managers/LayeredChunkManager/HotPackLayer.d.ts +9 -0
- package/dist/managers/LayeredChunkManager/HotPackLayer.js +8 -0
- package/dist/managers/LayeredChunkManager/types.d.ts +39 -0
- package/dist/managers/LayeredChunkManager/types.js +0 -0
- package/dist/managers/LayeredChunkManager.d.ts +53 -0
- package/dist/managers/LayeredChunkManager.js +240 -0
- package/dist/managers/LiveSyncManagers.d.ts +48 -0
- package/dist/managers/LiveSyncManagers.js +136 -0
- package/dist/managers/StorageEventManager.d.ts +135 -0
- package/dist/managers/StorageEventManager.js +564 -0
- package/dist/managers/StorageProcessingManager.d.ts +14 -0
- package/dist/managers/StorageProcessingManager.js +48 -0
- package/dist/managers/adapters/IStorageEventConverterAdapter.d.ts +16 -0
- package/dist/managers/adapters/IStorageEventConverterAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventManagerAdapter.d.ts +18 -0
- package/dist/managers/adapters/IStorageEventManagerAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventPersistenceAdapter.d.ts +15 -0
- package/dist/managers/adapters/IStorageEventPersistenceAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventStatusAdapter.d.ts +13 -0
- package/dist/managers/adapters/IStorageEventStatusAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventTypeGuardAdapter.d.ts +16 -0
- package/dist/managers/adapters/IStorageEventTypeGuardAdapter.js +0 -0
- package/dist/managers/adapters/IStorageEventWatchAdapter.d.ts +21 -0
- package/dist/managers/adapters/IStorageEventWatchAdapter.js +0 -0
- package/dist/managers/adapters/index.d.ts +6 -0
- package/dist/managers/adapters/index.js +0 -0
- package/dist/mock_and_interop/stores.d.ts +21 -0
- package/dist/mock_and_interop/stores.js +15 -0
- package/dist/mock_and_interop/wrapper.d.ts +7 -0
- package/dist/mock_and_interop/wrapper.js +37 -0
- package/dist/mods.d.ts +1 -0
- package/dist/mods.js +18 -0
- package/dist/platform/browser/index.d.ts +1 -0
- package/dist/platform/browser/index.js +10 -0
- package/dist/platform/browser/storage.d.ts +35 -0
- package/dist/platform/browser/storage.js +139 -0
- package/dist/platform/node/index.d.ts +23 -0
- package/dist/platform/node/index.js +33 -0
- package/dist/platform/node/storage.d.ts +31 -0
- package/dist/platform/node/storage.js +104 -0
- package/dist/platform/storagePath.d.ts +7 -0
- package/dist/platform/storagePath.js +20 -0
- package/dist/pouchdb/LiveSyncDBFunctions.d.ts +14 -0
- package/dist/pouchdb/LiveSyncDBFunctions.js +129 -0
- package/dist/pouchdb/LiveSyncLocalDB.d.ts +196 -0
- package/dist/pouchdb/LiveSyncLocalDB.js +381 -0
- package/dist/pouchdb/PouchDBConstructor.d.ts +3 -0
- package/dist/pouchdb/PouchDBConstructor.js +0 -0
- package/dist/pouchdb/ReplicatorShim.d.ts +51 -0
- package/dist/pouchdb/ReplicatorShim.js +109 -0
- package/dist/pouchdb/StreamingFetch.d.ts +19 -0
- package/dist/pouchdb/StreamingFetch.js +263 -0
- package/dist/pouchdb/chunks.d.ts +38 -0
- package/dist/pouchdb/chunks.js +314 -0
- package/dist/pouchdb/compress.d.ts +11 -0
- package/dist/pouchdb/compress.js +99 -0
- package/dist/pouchdb/encryption.d.ts +20 -0
- package/dist/pouchdb/encryption.js +458 -0
- package/dist/pouchdb/negotiation.d.ts +9 -0
- package/dist/pouchdb/negotiation.js +109 -0
- package/dist/pouchdb/pouchdb-browser.d.ts +2 -0
- package/dist/pouchdb/pouchdb-browser.js +96 -0
- package/dist/pouchdb/pouchdb-http.d.ts +2 -0
- package/dist/pouchdb/pouchdb-http.js +94 -0
- package/dist/pouchdb/pouchdb-test.d.ts +2 -0
- package/dist/pouchdb/pouchdb-test.js +12 -0
- package/dist/pouchdb/utils_couchdb.d.ts +4 -0
- package/dist/pouchdb/utils_couchdb.js +38 -0
- package/dist/replication/LiveSyncAbstractReplicator.d.ts +69 -0
- package/dist/replication/LiveSyncAbstractReplicator.js +92 -0
- package/dist/replication/SyncParamsHandler.d.ts +35 -0
- package/dist/replication/SyncParamsHandler.js +118 -0
- package/dist/replication/couchdb/LiveSyncReplicator.d.ts +85 -0
- package/dist/replication/couchdb/LiveSyncReplicator.js +1132 -0
- package/dist/replication/httplib.d.ts +75 -0
- package/dist/replication/httplib.js +187 -0
- package/dist/replication/journal/JournalSyncCore.d.ts +70 -0
- package/dist/replication/journal/JournalSyncCore.js +737 -0
- package/dist/replication/journal/JournalSyncTypes.d.ts +9 -0
- package/dist/replication/journal/JournalSyncTypes.js +11 -0
- package/dist/replication/journal/LiveSyncJournalReplicator.d.ts +40 -0
- package/dist/replication/journal/LiveSyncJournalReplicator.js +294 -0
- package/dist/replication/journal/LiveSyncJournalReplicatorEnv.d.ts +3 -0
- package/dist/replication/journal/LiveSyncJournalReplicatorEnv.js +0 -0
- package/dist/replication/journal/objectstore/JournalStorageAdapter.d.ts +15 -0
- package/dist/replication/journal/objectstore/JournalStorageAdapter.js +0 -0
- package/dist/replication/journal/objectstore/MinioStorageAdapter.d.ts +21 -0
- package/dist/replication/journal/objectstore/MinioStorageAdapter.js +204 -0
- package/dist/replication/trystero/LiveSyncTrysteroReplicator.d.ts +90 -0
- package/dist/replication/trystero/LiveSyncTrysteroReplicator.js +380 -0
- package/dist/replication/trystero/P2PLogCollector.d.ts +8 -0
- package/dist/replication/trystero/P2PLogCollector.js +91 -0
- package/dist/replication/trystero/P2PReplicatorBase.d.ts +19 -0
- package/dist/replication/trystero/P2PReplicatorBase.js +0 -0
- package/dist/replication/trystero/P2PReplicatorCore.d.ts +12 -0
- package/dist/replication/trystero/P2PReplicatorCore.js +126 -0
- package/dist/replication/trystero/P2PReplicatorPaneCommon.d.ts +41 -0
- package/dist/replication/trystero/P2PReplicatorPaneCommon.js +20 -0
- package/dist/replication/trystero/ProxiedDB.d.ts +13 -0
- package/dist/replication/trystero/ProxiedDB.js +20 -0
- package/dist/replication/trystero/TrysteroReplicator.d.ts +152 -0
- package/dist/replication/trystero/TrysteroReplicator.js +683 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PClient.d.ts +19 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PClient.js +80 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PConnection.d.ts +2 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PConnection.js +4 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PServer.d.ts +117 -0
- package/dist/replication/trystero/TrysteroReplicatorP2PServer.js +540 -0
- package/dist/replication/trystero/UseP2PReplicatorResult.d.ts +11 -0
- package/dist/replication/trystero/UseP2PReplicatorResult.js +0 -0
- package/dist/replication/trystero/addP2PEventHandlers.d.ts +35 -0
- package/dist/replication/trystero/addP2PEventHandlers.js +43 -0
- package/dist/replication/trystero/rpcCompat.d.ts +1 -0
- package/dist/replication/trystero/rpcCompat.js +9 -0
- package/dist/replication/trystero/types.d.ts +95 -0
- package/dist/replication/trystero/types.js +27 -0
- package/dist/replication/trystero/useP2PReplicatorCommands.d.ts +7 -0
- package/dist/replication/trystero/useP2PReplicatorCommands.js +25 -0
- package/dist/replication/trystero/useP2PReplicatorFeature.d.ts +17 -0
- package/dist/replication/trystero/useP2PReplicatorFeature.js +82 -0
- package/dist/rpc/RpcRoom.d.ts +24 -0
- package/dist/rpc/RpcRoom.js +300 -0
- package/dist/rpc/RpcSession.d.ts +9 -0
- package/dist/rpc/RpcSession.js +32 -0
- package/dist/rpc/chunking.d.ts +11 -0
- package/dist/rpc/chunking.js +58 -0
- package/dist/rpc/errors.d.ts +8 -0
- package/dist/rpc/errors.js +26 -0
- package/dist/rpc/index.d.ts +6 -0
- package/dist/rpc/index.js +12 -0
- package/dist/rpc/pouchdb/RpcPouchDBProxy.d.ts +75 -0
- package/dist/rpc/pouchdb/RpcPouchDBProxy.js +115 -0
- package/dist/rpc/pouchdb/RpcPouchDBServer.d.ts +16 -0
- package/dist/rpc/pouchdb/RpcPouchDBServer.js +55 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.d.ts +24 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.js +208 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.types.d.ts +64 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.types.js +12 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.utils.d.ts +33 -0
- package/dist/rpc/transports/DiagRTCPeerConnections.utils.js +217 -0
- package/dist/rpc/transports/TrysteroTransport.d.ts +216 -0
- package/dist/rpc/transports/TrysteroTransport.js +134 -0
- package/dist/rpc/transports/trysteroUtils.d.ts +3 -0
- package/dist/rpc/transports/trysteroUtils.js +37 -0
- package/dist/rpc/types.d.ts +75 -0
- package/dist/rpc/types.js +6 -0
- package/dist/serviceFeatures/checkRemoteSize.d.ts +28 -0
- package/dist/serviceFeatures/checkRemoteSize.js +178 -0
- package/dist/serviceFeatures/offlineScanner.d.ts +128 -0
- package/dist/serviceFeatures/offlineScanner.js +553 -0
- package/dist/serviceFeatures/prepareDatabaseForUse.d.ts +20 -0
- package/dist/serviceFeatures/prepareDatabaseForUse.js +39 -0
- package/dist/serviceFeatures/remoteConfig.d.ts +46 -0
- package/dist/serviceFeatures/remoteConfig.js +247 -0
- package/dist/serviceFeatures/setupObsidian/qrCode.d.ts +4 -0
- package/dist/serviceFeatures/setupObsidian/qrCode.js +67 -0
- package/dist/serviceFeatures/setupObsidian/setupUri.d.ts +7 -0
- package/dist/serviceFeatures/setupObsidian/setupUri.js +70 -0
- package/dist/serviceFeatures/setupObsidian/types.d.ts +2 -0
- package/dist/serviceFeatures/setupObsidian/types.js +0 -0
- package/dist/serviceFeatures/targetFilter.d.ts +24 -0
- package/dist/serviceFeatures/targetFilter.js +178 -0
- package/dist/serviceModules/FileAccessBase.d.ts +93 -0
- package/dist/serviceModules/FileAccessBase.js +219 -0
- package/dist/serviceModules/Rebuilder.d.ts +92 -0
- package/dist/serviceModules/Rebuilder.js +449 -0
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.d.ts +40 -0
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.js +306 -0
- package/dist/serviceModules/ServiceFileAccessBase.d.ts +64 -0
- package/dist/serviceModules/ServiceFileAccessBase.js +312 -0
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +52 -0
- package/dist/serviceModules/ServiceFileHandlerBase.js +493 -0
- package/dist/serviceModules/ServiceModuleBase.d.ts +10 -0
- package/dist/serviceModules/ServiceModuleBase.js +13 -0
- package/dist/serviceModules/adapters/IConversionAdapter.d.ts +15 -0
- package/dist/serviceModules/adapters/IConversionAdapter.js +0 -0
- package/dist/serviceModules/adapters/IFileSystemAdapter.d.ts +47 -0
- package/dist/serviceModules/adapters/IFileSystemAdapter.js +0 -0
- package/dist/serviceModules/adapters/IPathAdapter.d.ts +15 -0
- package/dist/serviceModules/adapters/IPathAdapter.js +0 -0
- package/dist/serviceModules/adapters/IStorageAdapter.d.ts +56 -0
- package/dist/serviceModules/adapters/IStorageAdapter.js +0 -0
- package/dist/serviceModules/adapters/ITypeGuardAdapter.d.ts +14 -0
- package/dist/serviceModules/adapters/ITypeGuardAdapter.js +0 -0
- package/dist/serviceModules/adapters/IVaultAdapter.d.ts +51 -0
- package/dist/serviceModules/adapters/IVaultAdapter.js +0 -0
- package/dist/serviceModules/adapters/index.d.ts +6 -0
- package/dist/serviceModules/adapters/index.js +0 -0
- package/dist/services/BrowserServices.d.ts +36 -0
- package/dist/services/BrowserServices.js +123 -0
- package/dist/services/HeadlessServices.d.ts +14 -0
- package/dist/services/HeadlessServices.js +144 -0
- package/dist/services/InjectableServices.d.ts +1 -0
- package/dist/services/InjectableServices.js +4 -0
- package/dist/services/ServiceHub.d.ts +82 -0
- package/dist/services/ServiceHub.js +66 -0
- package/dist/services/base/APIService.d.ts +93 -0
- package/dist/services/base/APIService.js +44 -0
- package/dist/services/base/AppLifecycleService.d.ts +132 -0
- package/dist/services/base/AppLifecycleService.js +123 -0
- package/dist/services/base/ConfigService.d.ts +7 -0
- package/dist/services/base/ConfigService.js +6 -0
- package/dist/services/base/ConflictService.d.ts +54 -0
- package/dist/services/base/ConflictService.js +22 -0
- package/dist/services/base/ControlService.d.ts +54 -0
- package/dist/services/base/ControlService.js +103 -0
- package/dist/services/base/DatabaseEventService.d.ts +38 -0
- package/dist/services/base/DatabaseEventService.js +38 -0
- package/dist/services/base/DatabaseService.d.ts +40 -0
- package/dist/services/base/DatabaseService.js +79 -0
- package/dist/services/base/FileProcessingService.d.ts +25 -0
- package/dist/services/base/FileProcessingService.js +28 -0
- package/dist/services/base/IService.d.ts +284 -0
- package/dist/services/base/IService.js +1 -0
- package/dist/services/base/KeyValueDBService.d.ts +42 -0
- package/dist/services/base/KeyValueDBService.js +133 -0
- package/dist/services/base/MessageTranslator.d.ts +6 -0
- package/dist/services/base/MessageTranslator.js +4 -0
- package/dist/services/base/PathService.d.ts +38 -0
- package/dist/services/base/PathService.js +66 -0
- package/dist/services/base/RemoteService.d.ts +61 -0
- package/dist/services/base/RemoteService.js +212 -0
- package/dist/services/base/ReplicationService.d.ts +92 -0
- package/dist/services/base/ReplicationService.js +261 -0
- package/dist/services/base/ReplicatorService.d.ts +66 -0
- package/dist/services/base/ReplicatorService.js +164 -0
- package/dist/services/base/ServiceBase.d.ts +33 -0
- package/dist/services/base/ServiceBase.js +27 -0
- package/dist/services/base/SettingService.d.ts +112 -0
- package/dist/services/base/SettingService.js +543 -0
- package/dist/services/base/TestService.d.ts +28 -0
- package/dist/services/base/TestService.js +19 -0
- package/dist/services/base/TweakValueService.d.ts +40 -0
- package/dist/services/base/TweakValueService.js +6 -0
- package/dist/services/base/UnresolvedErrorManager.d.ts +15 -0
- package/dist/services/base/UnresolvedErrorManager.js +44 -0
- package/dist/services/base/VaultService.d.ts +69 -0
- package/dist/services/base/VaultService.js +70 -0
- package/dist/services/implements/base/SvelteDialog.d.ts +79 -0
- package/dist/services/implements/base/SvelteDialog.js +134 -0
- package/dist/services/implements/base/UIService.d.ts +24 -0
- package/dist/services/implements/base/UIService.js +37 -0
- package/dist/services/implements/browser/BrowserAPIService.d.ts +54 -0
- package/dist/services/implements/browser/BrowserAPIService.js +298 -0
- package/dist/services/implements/browser/BrowserDatabaseService.d.ts +7 -0
- package/dist/services/implements/browser/BrowserDatabaseService.js +10 -0
- package/dist/services/implements/browser/ConfigServiceBrowserCompat.d.ts +16 -0
- package/dist/services/implements/browser/ConfigServiceBrowserCompat.js +23 -0
- package/dist/services/implements/headless/HeadlessAPIService.d.ts +52 -0
- package/dist/services/implements/headless/HeadlessAPIService.js +127 -0
- package/dist/services/implements/headless/HeadlessDatabaseService.d.ts +7 -0
- package/dist/services/implements/headless/HeadlessDatabaseService.js +10 -0
- package/dist/services/implements/injectable/InjectableAPIService.d.ts +7 -0
- package/dist/services/implements/injectable/InjectableAPIService.js +18 -0
- package/dist/services/implements/injectable/InjectableAppLifecycleService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableAppLifecycleService.js +14 -0
- package/dist/services/implements/injectable/InjectableConflictService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableConflictService.js +14 -0
- package/dist/services/implements/injectable/InjectableDatabaseEventService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableDatabaseEventService.js +7 -0
- package/dist/services/implements/injectable/InjectableFileProcessingService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableFileProcessingService.js +6 -0
- package/dist/services/implements/injectable/InjectablePathService.d.ts +12 -0
- package/dist/services/implements/injectable/InjectablePathService.js +36 -0
- package/dist/services/implements/injectable/InjectableRemoteService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableRemoteService.js +7 -0
- package/dist/services/implements/injectable/InjectableReplicationService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableReplicationService.js +6 -0
- package/dist/services/implements/injectable/InjectableReplicatorService.d.ts +4 -0
- package/dist/services/implements/injectable/InjectableReplicatorService.js +7 -0
- package/dist/services/implements/injectable/InjectableServiceHub.d.ts +72 -0
- package/dist/services/implements/injectable/InjectableServiceHub.js +125 -0
- package/dist/services/implements/injectable/InjectableServices.d.ts +36 -0
- package/dist/services/implements/injectable/InjectableServices.js +1 -0
- package/dist/services/implements/injectable/InjectableSettingService.d.ts +11 -0
- package/dist/services/implements/injectable/InjectableSettingService.js +33 -0
- package/dist/services/implements/injectable/InjectableTestService.d.ts +5 -0
- package/dist/services/implements/injectable/InjectableTestService.js +8 -0
- package/dist/services/implements/injectable/InjectableTweakValueService.d.ts +15 -0
- package/dist/services/implements/injectable/InjectableTweakValueService.js +12 -0
- package/dist/services/implements/injectable/InjectableVaultService.d.ts +9 -0
- package/dist/services/implements/injectable/InjectableVaultService.js +20 -0
- package/dist/services/lib/HandlerUtils.d.ts +374 -0
- package/dist/services/lib/HandlerUtils.js +412 -0
- package/dist/services/lib/logUtils.d.ts +13 -0
- package/dist/services/lib/logUtils.js +28 -0
- package/dist/services/lib/remoteActivity.d.ts +13 -0
- package/dist/services/lib/remoteActivity.js +11 -0
- package/dist/string_and_binary/chunks.d.ts +10 -0
- package/dist/string_and_binary/chunks.js +561 -0
- package/dist/string_and_binary/convert.d.ts +8 -0
- package/dist/string_and_binary/convert.js +46 -0
- package/dist/string_and_binary/hash.d.ts +2 -0
- package/dist/string_and_binary/hash.js +1 -0
- package/dist/string_and_binary/path.d.ts +35 -0
- package/dist/string_and_binary/path.js +240 -0
- package/dist/worker/bg.common.d.ts +2 -0
- package/dist/worker/bg.common.js +6 -0
- package/dist/worker/bg.worker.d.ts +1 -0
- package/dist/worker/bg.worker.encryption.d.ts +7 -0
- package/dist/worker/bg.worker.encryption.js +30 -0
- package/dist/worker/bg.worker.js +14 -0
- package/dist/worker/bg.worker.splitting.d.ts +6 -0
- package/dist/worker/bg.worker.splitting.js +36 -0
- package/dist/worker/bgWorker.d.ts +25 -0
- package/dist/worker/bgWorker.direct.d.ts +40 -0
- package/dist/worker/bgWorker.direct.js +65 -0
- package/dist/worker/bgWorker.encryption.d.ts +22 -0
- package/dist/worker/bgWorker.encryption.js +40 -0
- package/dist/worker/bgWorker.js +348 -0
- package/dist/worker/bgWorker.splitting.d.ts +27 -0
- package/dist/worker/bgWorker.splitting.js +123 -0
- package/dist/worker/universalTypes.d.ts +63 -0
- package/dist/worker/universalTypes.js +4 -0
- package/docs/development.md +51 -0
- package/docs/platform-storage.md +60 -0
- package/docs/releasing.md +69 -0
- package/package.json +693 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 vorotamoroz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Self-hosted LiveSync Commonlib
|
|
2
|
+
|
|
3
|
+
Commonlib provides the shared data, storage, and replication primitives used by Self-hosted LiveSync, its CLI, Webapp, and WebPeer.
|
|
4
|
+
|
|
5
|
+
The package is pre-1.0. Pin an exact reviewed version, and treat `compat/*` subpaths as migration-only interfaces. A source-directory import, Git submodule, or consumer-defined TypeScript alias is not a supported package boundary.
|
|
6
|
+
|
|
7
|
+
## Package entry points
|
|
8
|
+
|
|
9
|
+
- `@vrtmrz/livesync-commonlib` contains the deliberately small root API.
|
|
10
|
+
- `@vrtmrz/livesync-commonlib/context` contains host-context and translation injection contracts.
|
|
11
|
+
- `@vrtmrz/livesync-commonlib/browser` contains browser-only adapters, including rooted File System Access API storage.
|
|
12
|
+
- `@vrtmrz/livesync-commonlib/node` contains Node-only capabilities and rooted storage.
|
|
13
|
+
- `@vrtmrz/livesync-commonlib/rpc` contains the focused RPC API.
|
|
14
|
+
- `@vrtmrz/livesync-commonlib/compat/*` contains temporary explicit exports required by existing Self-hosted LiveSync consumers.
|
|
15
|
+
|
|
16
|
+
Import only the entry point required by the current runtime. Browser code must not import the Node entry.
|
|
17
|
+
|
|
18
|
+
## Rooted storage
|
|
19
|
+
|
|
20
|
+
Both platform storage factories receive an existing root from the host. They never select a directory, request browser permission, infer a process directory, or persist a handle.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createFileSystemAccessStorage } from '@vrtmrz/livesync-commonlib/browser';
|
|
24
|
+
|
|
25
|
+
declare const authorisedRoot: FileSystemDirectoryHandle;
|
|
26
|
+
const storage = createFileSystemAccessStorage({ rootHandle: authorisedRoot });
|
|
27
|
+
await storage.write('notes/example.md', '# Example');
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { createNodeStorage } from '@vrtmrz/livesync-commonlib/node';
|
|
32
|
+
|
|
33
|
+
const storage = createNodeStorage({ rootPath: '/srv/livesync' });
|
|
34
|
+
await storage.write('notes/example.md', '# Example');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
See [the platform storage contract](docs/platform-storage.md) for path, ownership, and permission details.
|
|
38
|
+
|
|
39
|
+
## API status
|
|
40
|
+
|
|
41
|
+
The package is currently an infrastructure and compatibility boundary. `DirectFileManipulator` is useful for existing integrations, but its enumeration, watch ownership, failure, conflict, concurrency, and disposal semantics are not yet a stable high-level SDK contract.
|
|
42
|
+
|
|
43
|
+
TODO: define and document the first high-level client façade before declaring list, get, put, delete, watch, and close behaviour stable.
|
|
44
|
+
|
|
45
|
+
Development and package validation are documented in [the developer guide](docs/development.md).
|
|
46
|
+
|
|
47
|
+
## Licence
|
|
48
|
+
|
|
49
|
+
MIT
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The API for manipulating files stored in the CouchDB by Self-hosted LiveSync or its families.
|
|
3
|
+
*/
|
|
4
|
+
import { type DocumentID, type FilePathWithPrefix, type EntryHasPath, type FilePath, type EntryDoc, type NewEntry, type PlainEntry, type LoadedEntry, type HashAlgorithm, type RemoteDBSettings, type ChunkSplitterVersion, type SyncParameters, type E2EEAlgorithm } from "../common/types.js";
|
|
5
|
+
import { LiveSyncLocalDB, type LiveSyncLocalDBEnv } from "../pouchdb/LiveSyncLocalDB.js";
|
|
6
|
+
import { HeadlessServiceHub } from "../services/HeadlessServices.js";
|
|
7
|
+
import { HeadlessDatabaseService } from "../services/implements/headless/HeadlessDatabaseService.js";
|
|
8
|
+
import { ServiceContext } from "../services/base/ServiceBase.js";
|
|
9
|
+
export type DirectFileManipulatorOptions = {
|
|
10
|
+
url: string;
|
|
11
|
+
username: string;
|
|
12
|
+
password: string;
|
|
13
|
+
passphrase: string | undefined;
|
|
14
|
+
database: string;
|
|
15
|
+
obfuscatePassphrase: string | undefined;
|
|
16
|
+
useDynamicIterationCount?: boolean;
|
|
17
|
+
customChunkSize?: number;
|
|
18
|
+
minimumChunkSize?: number;
|
|
19
|
+
hashAlg?: HashAlgorithm;
|
|
20
|
+
useEden?: boolean;
|
|
21
|
+
maxChunksInEden?: number;
|
|
22
|
+
maxTotalLengthInEden?: number;
|
|
23
|
+
maxAgeInEden?: number;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated use chunkSplitterVersion instead.
|
|
26
|
+
*/
|
|
27
|
+
enableChunkSplitterV2?: boolean;
|
|
28
|
+
enableCompression?: boolean;
|
|
29
|
+
handleFilenameCaseSensitive?: boolean;
|
|
30
|
+
doNotUseFixedRevisionForChunks?: boolean;
|
|
31
|
+
chunkSplitterVersion?: ChunkSplitterVersion;
|
|
32
|
+
E2EEAlgorithm?: E2EEAlgorithm;
|
|
33
|
+
};
|
|
34
|
+
export type ReadyEntry = (NewEntry | PlainEntry) & {
|
|
35
|
+
data: string[];
|
|
36
|
+
};
|
|
37
|
+
export type MetaEntry = (NewEntry | PlainEntry) & {
|
|
38
|
+
children: string[];
|
|
39
|
+
};
|
|
40
|
+
export type FileInfo = {
|
|
41
|
+
ctime: number;
|
|
42
|
+
mtime: number;
|
|
43
|
+
size: number;
|
|
44
|
+
};
|
|
45
|
+
export type EnumerateConditions = {
|
|
46
|
+
startKey?: string;
|
|
47
|
+
endKey?: string;
|
|
48
|
+
ids?: string[];
|
|
49
|
+
metaOnly: boolean;
|
|
50
|
+
};
|
|
51
|
+
export declare class DirectFileManipulator implements LiveSyncLocalDBEnv {
|
|
52
|
+
liveSyncLocalDB: LiveSyncLocalDB;
|
|
53
|
+
options: DirectFileManipulatorOptions;
|
|
54
|
+
ready: {
|
|
55
|
+
promise: Promise<void>;
|
|
56
|
+
resolve: (value: void | PromiseLike<void>) => void;
|
|
57
|
+
reject: (reason?: any) => void;
|
|
58
|
+
};
|
|
59
|
+
services: HeadlessServiceHub<ServiceContext>;
|
|
60
|
+
init(): Promise<void>;
|
|
61
|
+
getBoundDatabaseService(options: () => DirectFileManipulatorOptions): typeof HeadlessDatabaseService;
|
|
62
|
+
constructor(options: DirectFileManipulatorOptions);
|
|
63
|
+
$$id2path(id: DocumentID, entry?: EntryHasPath, stripPrefix?: boolean): FilePathWithPrefix;
|
|
64
|
+
$$path2id(filename: FilePathWithPrefix | FilePath, prefix?: string): Promise<DocumentID>;
|
|
65
|
+
getInitialSyncParameters(setting: RemoteDBSettings): Promise<SyncParameters>;
|
|
66
|
+
getSyncParameters(setting: RemoteDBSettings): Promise<SyncParameters>;
|
|
67
|
+
putSyncParameters(setting: RemoteDBSettings, params: SyncParameters): Promise<boolean>;
|
|
68
|
+
getReplicationPBKDF2Salt(setting: RemoteDBSettings, refresh?: boolean): Promise<Uint8Array<ArrayBuffer>>;
|
|
69
|
+
$everyOnInitializeDatabase(db: LiveSyncLocalDB): Promise<boolean>;
|
|
70
|
+
getSettings(): RemoteDBSettings;
|
|
71
|
+
close(): Promise<void>;
|
|
72
|
+
path2id(filename: FilePathWithPrefix | FilePath, prefix?: string): Promise<DocumentID>;
|
|
73
|
+
get settings(): RemoteDBSettings;
|
|
74
|
+
/**
|
|
75
|
+
* Get specific document from the Remote Database by path.
|
|
76
|
+
* @param path
|
|
77
|
+
* @param metaOnly if it has been enabled, the note does not contains the content.
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
get(path: FilePathWithPrefix, metaOnly?: boolean): Promise<false | LoadedEntry>;
|
|
81
|
+
/**
|
|
82
|
+
* Get specific document from the Remote Database by ID.
|
|
83
|
+
* @param path
|
|
84
|
+
* @param metaOnly if it has been enabled, the note does not contains the content.
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
getById(id: string, metaOnly?: boolean): Promise<false | MetaEntry | ReadyEntry>;
|
|
88
|
+
getByMeta(doc: MetaEntry): Promise<ReadyEntry>;
|
|
89
|
+
rawGet<T>(id: DocumentID): Promise<false | T>;
|
|
90
|
+
/**
|
|
91
|
+
* Put a note to the remote database
|
|
92
|
+
* @param path
|
|
93
|
+
* @param data
|
|
94
|
+
* @param info
|
|
95
|
+
* @param type
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
put(path: string, data: string[] | Blob, info: FileInfo, _type?: "newnote" | "plain"): Promise<boolean>;
|
|
99
|
+
delete(path: string): Promise<boolean>;
|
|
100
|
+
enumerate(_cond: EnumerateConditions): AsyncGenerator<never, void, unknown>;
|
|
101
|
+
_enumerate(startKey: string, endKey: string, opt: {
|
|
102
|
+
metaOnly: boolean;
|
|
103
|
+
}): AsyncGenerator<ReadyEntry, AsyncGenerator<(import("../common/types.js").DatabaseEntry & import("../common/types.js").EntryBase & import("../common/types.js").EntryWithEden & {
|
|
104
|
+
path: FilePathWithPrefix;
|
|
105
|
+
children: string[];
|
|
106
|
+
type: import("../common/models/db.type.js").EntryTypes["NOTE_BINARY"];
|
|
107
|
+
} & PouchDB.Core.AllDocsMeta & PouchDB.Core.IdMeta & PouchDB.Core.RevisionIdMeta) | (import("../common/types.js").DatabaseEntry & import("../common/types.js").EntryBase & import("../common/types.js").EntryWithEden & {
|
|
108
|
+
path: FilePathWithPrefix;
|
|
109
|
+
children: string[];
|
|
110
|
+
type: import("../common/models/db.type.js").EntryTypes["NOTE_PLAIN"];
|
|
111
|
+
} & PouchDB.Core.AllDocsMeta & PouchDB.Core.IdMeta & PouchDB.Core.RevisionIdMeta) | (import("../common/types.js").DatabaseEntry & import("../common/types.js").EntryBase & import("../common/types.js").EntryWithEden & {
|
|
112
|
+
path: FilePathWithPrefix;
|
|
113
|
+
children: string[];
|
|
114
|
+
type: import("../common/models/db.type.js").EntryTypes["NOTE_BINARY"];
|
|
115
|
+
} & {
|
|
116
|
+
deleted?: boolean;
|
|
117
|
+
} & PouchDB.Core.AllDocsMeta & PouchDB.Core.IdMeta & PouchDB.Core.RevisionIdMeta) | (import("../common/types.js").DatabaseEntry & import("../common/types.js").EntryBase & import("../common/types.js").EntryWithEden & {
|
|
118
|
+
path: FilePathWithPrefix;
|
|
119
|
+
children: string[];
|
|
120
|
+
type: import("../common/models/db.type.js").EntryTypes["NOTE_BINARY"];
|
|
121
|
+
} & {
|
|
122
|
+
data: string | string[];
|
|
123
|
+
datatype: import("../common/types.js").EntryTypeNotes;
|
|
124
|
+
} & PouchDB.Core.AllDocsMeta & PouchDB.Core.IdMeta & PouchDB.Core.RevisionIdMeta) | (import("../common/types.js").DatabaseEntry & import("../common/types.js").EntryBase & import("../common/types.js").EntryWithEden & {
|
|
125
|
+
path: FilePathWithPrefix;
|
|
126
|
+
children: string[];
|
|
127
|
+
type: import("../common/models/db.type.js").EntryTypes["NOTE_PLAIN"];
|
|
128
|
+
} & {
|
|
129
|
+
data: string | string[];
|
|
130
|
+
datatype: import("../common/types.js").EntryTypeNotes;
|
|
131
|
+
} & PouchDB.Core.AllDocsMeta & PouchDB.Core.IdMeta & PouchDB.Core.RevisionIdMeta) | (import("../common/types.js").DatabaseEntry & import("../common/types.js").EntryBase & import("../common/types.js").EntryWithEden & {
|
|
132
|
+
path: FilePathWithPrefix;
|
|
133
|
+
children: string[];
|
|
134
|
+
type: import("../common/models/db.type.js").EntryTypes["NOTE_BINARY"];
|
|
135
|
+
} & {
|
|
136
|
+
deleted?: boolean;
|
|
137
|
+
} & {
|
|
138
|
+
data: string | string[];
|
|
139
|
+
datatype: import("../common/types.js").EntryTypeNotes;
|
|
140
|
+
} & PouchDB.Core.AllDocsMeta & PouchDB.Core.IdMeta & PouchDB.Core.RevisionIdMeta), void, unknown>, unknown>;
|
|
141
|
+
enumerateAllNormalDocs(opt: {
|
|
142
|
+
metaOnly: boolean;
|
|
143
|
+
}): AsyncGenerator<ReadyEntry, void, unknown>;
|
|
144
|
+
watching: boolean;
|
|
145
|
+
changes: PouchDB.Core.Changes<EntryDoc> | undefined;
|
|
146
|
+
since: string;
|
|
147
|
+
beginWatch(callback: (doc: ReadyEntry, seq?: string | number) => Promise<any> | void, checkIsInterested?: (doc: MetaEntry) => boolean): boolean;
|
|
148
|
+
endWatch(): void;
|
|
149
|
+
followUpdates(callback: (doc: ReadyEntry, seq?: string | number) => Promise<any> | void, checkIsInterested?: (doc: MetaEntry) => boolean): Promise<string | number>;
|
|
150
|
+
}
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_SETTINGS,
|
|
3
|
+
DEFAULT_SYNC_PARAMETERS,
|
|
4
|
+
ProtocolVersions,
|
|
5
|
+
DOCID_SYNC_PARAMETERS,
|
|
6
|
+
E2EEAlgorithms
|
|
7
|
+
} from "../common/types.js";
|
|
8
|
+
import { PouchDB } from "../pouchdb/pouchdb-http.js";
|
|
9
|
+
import { LiveSyncLocalDB } from "../pouchdb/LiveSyncLocalDB.js";
|
|
10
|
+
import { isErrorOfMissingDoc } from "../pouchdb/utils_couchdb.js";
|
|
11
|
+
import { replicationFilter } from "../pouchdb/compress.js";
|
|
12
|
+
import { disableEncryption } from "../pouchdb/encryption.js";
|
|
13
|
+
import { enableEncryption } from "../pouchdb/encryption.js";
|
|
14
|
+
import {
|
|
15
|
+
LEVEL_INFO,
|
|
16
|
+
LEVEL_VERBOSE,
|
|
17
|
+
LOG_LEVEL_INFO,
|
|
18
|
+
LOG_LEVEL_NOTICE,
|
|
19
|
+
LOG_LEVEL_VERBOSE,
|
|
20
|
+
Logger
|
|
21
|
+
} from "octagonal-wheels/common/logger";
|
|
22
|
+
import { createBlob, determineTypeFromBlob } from "../common/utils.js";
|
|
23
|
+
import { promiseWithResolvers } from "octagonal-wheels/promises";
|
|
24
|
+
import {
|
|
25
|
+
createSyncParamsHanderForServer,
|
|
26
|
+
SyncParamsFetchError,
|
|
27
|
+
SyncParamsNotFoundError,
|
|
28
|
+
SyncParamsUpdateError
|
|
29
|
+
} from "../replication/SyncParamsHandler.js";
|
|
30
|
+
import { HeadlessServiceHub } from "../services/HeadlessServices.js";
|
|
31
|
+
import { HeadlessDatabaseService } from "../services/implements/headless/HeadlessDatabaseService.js";
|
|
32
|
+
import { ServiceContext } from "../services/base/ServiceBase.js";
|
|
33
|
+
import { compatGlobal } from "../common/coreEnvFunctions.js";
|
|
34
|
+
function isNoteEntry(doc) {
|
|
35
|
+
if (!doc) return false;
|
|
36
|
+
return doc.type == "newnote" || doc.type == "plain";
|
|
37
|
+
}
|
|
38
|
+
function isReadyEntry(doc) {
|
|
39
|
+
if (!doc) return false;
|
|
40
|
+
return "data" in doc;
|
|
41
|
+
}
|
|
42
|
+
class DirectFileManipulator {
|
|
43
|
+
liveSyncLocalDB;
|
|
44
|
+
options;
|
|
45
|
+
ready = promiseWithResolvers();
|
|
46
|
+
services;
|
|
47
|
+
async init() {
|
|
48
|
+
await this.services.appLifecycle.onReady();
|
|
49
|
+
await this.liveSyncLocalDB.initializeDatabase();
|
|
50
|
+
this.ready.resolve();
|
|
51
|
+
this.liveSyncLocalDB.refreshSettings();
|
|
52
|
+
}
|
|
53
|
+
getBoundDatabaseService(options) {
|
|
54
|
+
const _option = options;
|
|
55
|
+
return class HeadlessDatabaseServiceExt extends HeadlessDatabaseService {
|
|
56
|
+
createPouchDBInstance(_name, _options) {
|
|
57
|
+
const option = _option();
|
|
58
|
+
return new PouchDB(option.url + "/" + option.database, {
|
|
59
|
+
auth: { username: option.username, password: option.password }
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
constructor(options) {
|
|
65
|
+
this.options = options;
|
|
66
|
+
const getSettings = () => this.settings;
|
|
67
|
+
const context = new ServiceContext();
|
|
68
|
+
this.services = new HeadlessServiceHub(context, {
|
|
69
|
+
pouchDB: PouchDB,
|
|
70
|
+
database: this.getBoundDatabaseService(() => this.options)
|
|
71
|
+
});
|
|
72
|
+
this.services.setting.saveData.setHandler((data) => {
|
|
73
|
+
console.warn("Saving settings is not supported in DirectFileManipulator.");
|
|
74
|
+
return Promise.resolve();
|
|
75
|
+
});
|
|
76
|
+
this.services.setting.loadData.setHandler(() => {
|
|
77
|
+
console.warn("Loading settings is not supported in DirectFileManipulator.");
|
|
78
|
+
return Promise.resolve(getSettings());
|
|
79
|
+
});
|
|
80
|
+
this.services.databaseEvents.onDatabaseInitialisation.addHandler(this.$everyOnInitializeDatabase.bind(this));
|
|
81
|
+
this.liveSyncLocalDB = new LiveSyncLocalDB(this.options.url, this);
|
|
82
|
+
void this.init();
|
|
83
|
+
}
|
|
84
|
+
$$id2path(id, entry, stripPrefix) {
|
|
85
|
+
return this.services.path.id2path(id, entry, stripPrefix);
|
|
86
|
+
}
|
|
87
|
+
async $$path2id(filename, prefix) {
|
|
88
|
+
return await this.services.path.path2id(filename, prefix);
|
|
89
|
+
}
|
|
90
|
+
// $$createPouchDBInstance<T extends object>(
|
|
91
|
+
// _name?: string,
|
|
92
|
+
// _options?: PouchDB.Configuration.DatabaseConfiguration
|
|
93
|
+
// ): PouchDB.Database<T> {
|
|
94
|
+
// return new PouchDB(this.options.url + "/" + this.options.database, {
|
|
95
|
+
// auth: { username: this.options.username, password: this.options.password },
|
|
96
|
+
// });
|
|
97
|
+
// }
|
|
98
|
+
getInitialSyncParameters(setting) {
|
|
99
|
+
return Promise.resolve({
|
|
100
|
+
...DEFAULT_SYNC_PARAMETERS,
|
|
101
|
+
protocolVersion: ProtocolVersions.ADVANCED_E2EE
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async getSyncParameters(setting) {
|
|
105
|
+
try {
|
|
106
|
+
const downloadedSyncParams = await this.rawGet(DOCID_SYNC_PARAMETERS);
|
|
107
|
+
if (!downloadedSyncParams) {
|
|
108
|
+
throw new SyncParamsNotFoundError(`Sync parameters have not been found in the database.`);
|
|
109
|
+
}
|
|
110
|
+
return downloadedSyncParams;
|
|
111
|
+
} catch (ex) {
|
|
112
|
+
Logger(`Could not retrieve remote sync parameters`, LOG_LEVEL_INFO);
|
|
113
|
+
throw SyncParamsFetchError.fromError(ex);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async putSyncParameters(setting, params) {
|
|
117
|
+
try {
|
|
118
|
+
const ret = await this.liveSyncLocalDB.putRaw(params);
|
|
119
|
+
if (ret.ok) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
throw new SyncParamsUpdateError(`Could not store remote sync parameters`);
|
|
123
|
+
} catch (ex) {
|
|
124
|
+
Logger(`Could not store remote sync parameters`, LOG_LEVEL_INFO);
|
|
125
|
+
throw SyncParamsUpdateError.fromError(ex);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async getReplicationPBKDF2Salt(setting, refresh) {
|
|
129
|
+
const server = `${setting.couchDB_URI.replace(/\/+$/, "")}/${setting.couchDB_DBNAME}`;
|
|
130
|
+
const manager = createSyncParamsHanderForServer(server, {
|
|
131
|
+
put: (params) => this.putSyncParameters(setting, params),
|
|
132
|
+
get: () => this.getSyncParameters(setting),
|
|
133
|
+
create: () => this.getInitialSyncParameters(setting)
|
|
134
|
+
});
|
|
135
|
+
return await manager.getPBKDF2Salt(refresh);
|
|
136
|
+
}
|
|
137
|
+
$everyOnInitializeDatabase(db) {
|
|
138
|
+
replicationFilter(db.localDatabase, this.options.enableCompression ?? false);
|
|
139
|
+
disableEncryption();
|
|
140
|
+
if (this.options.passphrase && typeof this.options.passphrase === "string") {
|
|
141
|
+
enableEncryption(
|
|
142
|
+
db.localDatabase,
|
|
143
|
+
this.options.passphrase,
|
|
144
|
+
this.options.useDynamicIterationCount ?? false,
|
|
145
|
+
false,
|
|
146
|
+
async () => await this.getReplicationPBKDF2Salt(this.getSettings()),
|
|
147
|
+
this.options.E2EEAlgorithm ?? E2EEAlgorithms.V2
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return Promise.resolve(true);
|
|
151
|
+
}
|
|
152
|
+
getSettings() {
|
|
153
|
+
return this.settings;
|
|
154
|
+
}
|
|
155
|
+
async close() {
|
|
156
|
+
await this.liveSyncLocalDB.close();
|
|
157
|
+
return this.liveSyncLocalDB.onunload();
|
|
158
|
+
}
|
|
159
|
+
async path2id(filename, prefix) {
|
|
160
|
+
return await this.services.path.path2id(filename, prefix);
|
|
161
|
+
}
|
|
162
|
+
get settings() {
|
|
163
|
+
const retObj = {
|
|
164
|
+
...DEFAULT_SETTINGS,
|
|
165
|
+
...{
|
|
166
|
+
minimumChunkSize: this.options.minimumChunkSize ?? DEFAULT_SETTINGS.minimumChunkSize,
|
|
167
|
+
encrypt: this.options.passphrase ? true : false,
|
|
168
|
+
passphrase: this.options.passphrase ?? "",
|
|
169
|
+
deleteMetadataOfDeletedFiles: DEFAULT_SETTINGS.deleteMetadataOfDeletedFiles,
|
|
170
|
+
customChunkSize: this.options.customChunkSize ?? DEFAULT_SETTINGS.customChunkSize,
|
|
171
|
+
doNotPaceReplication: DEFAULT_SETTINGS.doNotPaceReplication,
|
|
172
|
+
hashAlg: this.options.hashAlg ?? DEFAULT_SETTINGS.hashAlg,
|
|
173
|
+
useEden: this.options.useEden ?? DEFAULT_SETTINGS.useEden,
|
|
174
|
+
maxChunksInEden: this.options.maxChunksInEden ?? DEFAULT_SETTINGS.maxChunksInEden,
|
|
175
|
+
maxTotalLengthInEden: this.options.maxTotalLengthInEden ?? DEFAULT_SETTINGS.maxTotalLengthInEden,
|
|
176
|
+
maxAgeInEden: this.options.maxAgeInEden ?? DEFAULT_SETTINGS.maxAgeInEden,
|
|
177
|
+
enableChunkSplitterV2: this.options.enableChunkSplitterV2 ?? DEFAULT_SETTINGS.enableChunkSplitterV2,
|
|
178
|
+
chunkSplitterVersion: this.options.chunkSplitterVersion ?? DEFAULT_SETTINGS.chunkSplitterVersion,
|
|
179
|
+
disableWorkerForGeneratingChunks: true,
|
|
180
|
+
processSmallFilesInUIThread: true,
|
|
181
|
+
doNotUseFixedRevisionForChunks: this.options.doNotUseFixedRevisionForChunks ?? DEFAULT_SETTINGS.doNotUseFixedRevisionForChunks,
|
|
182
|
+
couchDB_URI: this.options.url,
|
|
183
|
+
couchDB_DBNAME: this.options.database,
|
|
184
|
+
couchDB_USER: this.options.username,
|
|
185
|
+
couchDB_PASSWORD: this.options.password,
|
|
186
|
+
accessKey: "",
|
|
187
|
+
secretKey: "",
|
|
188
|
+
bucket: "",
|
|
189
|
+
region: "",
|
|
190
|
+
endpoint: "",
|
|
191
|
+
enableCompression: this.options.enableCompression ?? DEFAULT_SETTINGS.enableCompression,
|
|
192
|
+
handleFilenameCaseSensitive: this.options.handleFilenameCaseSensitive ?? DEFAULT_SETTINGS.handleFilenameCaseSensitive,
|
|
193
|
+
E2EEAlgorithm: this.options.E2EEAlgorithm ?? E2EEAlgorithms.V2
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
return retObj;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get specific document from the Remote Database by path.
|
|
200
|
+
* @param path
|
|
201
|
+
* @param metaOnly if it has been enabled, the note does not contains the content.
|
|
202
|
+
* @returns
|
|
203
|
+
*/
|
|
204
|
+
async get(path, metaOnly = false) {
|
|
205
|
+
if (metaOnly) {
|
|
206
|
+
return await this.liveSyncLocalDB.getDBEntryMeta(path);
|
|
207
|
+
} else {
|
|
208
|
+
return await this.liveSyncLocalDB.getDBEntry(path);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get specific document from the Remote Database by ID.
|
|
213
|
+
* @param path
|
|
214
|
+
* @param metaOnly if it has been enabled, the note does not contains the content.
|
|
215
|
+
* @returns
|
|
216
|
+
*/
|
|
217
|
+
async getById(id, metaOnly = false) {
|
|
218
|
+
const meta = await this.liveSyncLocalDB.getRaw(id);
|
|
219
|
+
if (!isNoteEntry(meta)) return false;
|
|
220
|
+
if (metaOnly) {
|
|
221
|
+
return meta;
|
|
222
|
+
}
|
|
223
|
+
return this.getByMeta(meta);
|
|
224
|
+
}
|
|
225
|
+
async getByMeta(doc) {
|
|
226
|
+
const docX = await this.liveSyncLocalDB.getDBEntryFromMeta(doc);
|
|
227
|
+
if (!isReadyEntry(docX)) {
|
|
228
|
+
throw new Error(`Corrupted document: ${doc.path}`);
|
|
229
|
+
}
|
|
230
|
+
return docX;
|
|
231
|
+
}
|
|
232
|
+
async rawGet(id) {
|
|
233
|
+
try {
|
|
234
|
+
const doc = await this.liveSyncLocalDB.getRaw(id);
|
|
235
|
+
return doc;
|
|
236
|
+
} catch (ex) {
|
|
237
|
+
if (isErrorOfMissingDoc(ex)) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
throw ex;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Put a note to the remote database
|
|
245
|
+
* @param path
|
|
246
|
+
* @param data
|
|
247
|
+
* @param info
|
|
248
|
+
* @param type
|
|
249
|
+
* @returns
|
|
250
|
+
*/
|
|
251
|
+
async put(path, data, info, _type = "plain") {
|
|
252
|
+
const id = await this.path2id(path);
|
|
253
|
+
const saveData = data instanceof Blob ? data : createBlob(data);
|
|
254
|
+
const datatype = determineTypeFromBlob(saveData);
|
|
255
|
+
const putDoc = {
|
|
256
|
+
_id: id,
|
|
257
|
+
path,
|
|
258
|
+
data: saveData,
|
|
259
|
+
ctime: info.ctime,
|
|
260
|
+
mtime: info.mtime,
|
|
261
|
+
size: info.size,
|
|
262
|
+
type: datatype,
|
|
263
|
+
eden: {},
|
|
264
|
+
children: [],
|
|
265
|
+
datatype
|
|
266
|
+
};
|
|
267
|
+
Logger(`PUT: UPLOADING: ${path}`, LOG_LEVEL_VERBOSE);
|
|
268
|
+
const ret = await this.liveSyncLocalDB.putDBEntry(putDoc);
|
|
269
|
+
if (ret) {
|
|
270
|
+
Logger(`PUT: DONE: ${path}`, LOG_LEVEL_INFO);
|
|
271
|
+
return true;
|
|
272
|
+
} else {
|
|
273
|
+
Logger(`PUT: FAILED: ${path}`, LOG_LEVEL_NOTICE);
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async delete(path) {
|
|
278
|
+
Logger(`DELETE: START: ${path}`, LOG_LEVEL_VERBOSE);
|
|
279
|
+
const ret = await this.liveSyncLocalDB.deleteDBEntry(path);
|
|
280
|
+
if (ret) {
|
|
281
|
+
Logger(`DELETE: DONE: ${path}`, LOG_LEVEL_INFO);
|
|
282
|
+
return true;
|
|
283
|
+
} else {
|
|
284
|
+
Logger(`DELETE: FAILED: ${path}`, LOG_LEVEL_INFO);
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Untested
|
|
289
|
+
async *enumerate(_cond) {
|
|
290
|
+
}
|
|
291
|
+
async *_enumerate(startKey, endKey, opt) {
|
|
292
|
+
if (opt.metaOnly) return this.liveSyncLocalDB.findEntries(startKey, endKey, {});
|
|
293
|
+
for await (const f of this.liveSyncLocalDB.findEntries(startKey, endKey, {})) {
|
|
294
|
+
yield await this.getByMeta(f);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async *enumerateAllNormalDocs(opt) {
|
|
298
|
+
const targets = [
|
|
299
|
+
this._enumerate("", "h:", opt),
|
|
300
|
+
this._enumerate(`h:\u{10FFFF}`, "i:", opt),
|
|
301
|
+
this._enumerate(`i:\u{10FFFF}`, "ix:", opt),
|
|
302
|
+
this._enumerate(`ix:\u{10FFFF}`, "ps:", opt),
|
|
303
|
+
this._enumerate(`ps:\u{10FFFF}`, "\u{10FFFF}", opt)
|
|
304
|
+
];
|
|
305
|
+
for (const target of targets) {
|
|
306
|
+
for await (const f of target) {
|
|
307
|
+
yield f;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
watching = false;
|
|
312
|
+
// _abortController?: AbortController;
|
|
313
|
+
changes;
|
|
314
|
+
since = "";
|
|
315
|
+
beginWatch(callback, checkIsInterested) {
|
|
316
|
+
if (this.watching) return false;
|
|
317
|
+
this.watching = true;
|
|
318
|
+
this.changes = this.liveSyncLocalDB.localDatabase.changes({
|
|
319
|
+
include_docs: true,
|
|
320
|
+
since: this.since,
|
|
321
|
+
selector: {
|
|
322
|
+
type: { $ne: "leaf" }
|
|
323
|
+
},
|
|
324
|
+
live: true
|
|
325
|
+
}).on("change", async (change) => {
|
|
326
|
+
const doc = change.doc;
|
|
327
|
+
if (!doc) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (!isNoteEntry(doc)) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (checkIsInterested) {
|
|
334
|
+
if (!checkIsInterested(doc)) {
|
|
335
|
+
Logger(`WATCH: SKIP ${doc.path}: OUT OF TARGET FOLDER`, LOG_LEVEL_VERBOSE, "watch");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
Logger(`WATCH: PROCESSING: ${doc.path}`, LEVEL_VERBOSE, "watch");
|
|
340
|
+
const docX = await this.getByMeta(doc);
|
|
341
|
+
try {
|
|
342
|
+
await callback(docX, change.seq);
|
|
343
|
+
Logger(`WATCH: PROCESS DONE: ${doc.path}`, LEVEL_INFO, "watch");
|
|
344
|
+
} catch (ex) {
|
|
345
|
+
Logger(`WATCH: PROCESS FAILED`, LEVEL_INFO, "watch");
|
|
346
|
+
Logger(ex, LEVEL_VERBOSE, "watch");
|
|
347
|
+
}
|
|
348
|
+
}).on("complete", () => {
|
|
349
|
+
Logger(`WATCH: FINISHED`, LEVEL_INFO, "watch");
|
|
350
|
+
this.watching = false;
|
|
351
|
+
this.changes = void 0;
|
|
352
|
+
}).on("error", (err) => {
|
|
353
|
+
Logger(`WATCH: ERROR: `, LEVEL_INFO, "watch");
|
|
354
|
+
Logger(err, LEVEL_VERBOSE, "watch");
|
|
355
|
+
if (this.watching) {
|
|
356
|
+
Logger(`WATCH: CONNECTION HAS BEEN CLOSED, RECONNECTING...`, LEVEL_INFO, "watch");
|
|
357
|
+
this.watching = false;
|
|
358
|
+
this.changes = void 0;
|
|
359
|
+
compatGlobal.setTimeout(() => {
|
|
360
|
+
this.beginWatch(callback, checkIsInterested);
|
|
361
|
+
}, 1e4);
|
|
362
|
+
} else {
|
|
363
|
+
Logger(`WATCH: CONNECTION HAS BEEN CLOSED.`, LEVEL_INFO, "watch");
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
endWatch() {
|
|
368
|
+
if (this.changes) {
|
|
369
|
+
Logger(`WATCH: CANCELLING PROCESS.`, LEVEL_INFO, "watch");
|
|
370
|
+
this.changes.cancel();
|
|
371
|
+
Logger(`WATCH: CANCELLING SIGNAL HAS BEEN SENT.`, LEVEL_INFO, "watch");
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
async followUpdates(callback, checkIsInterested) {
|
|
375
|
+
try {
|
|
376
|
+
if (this.since == "") {
|
|
377
|
+
this.since = "0";
|
|
378
|
+
}
|
|
379
|
+
Logger(`FOLLOW: START: (since:${this.since})`, LEVEL_INFO, "followUpdates");
|
|
380
|
+
const last = await this.liveSyncLocalDB.localDatabase.changes({
|
|
381
|
+
include_docs: true,
|
|
382
|
+
since: this.since,
|
|
383
|
+
filter: "replicate/pull",
|
|
384
|
+
live: false
|
|
385
|
+
}).on("change", async (change) => {
|
|
386
|
+
const doc = change.doc;
|
|
387
|
+
if (!doc) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (!isNoteEntry(doc)) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (checkIsInterested) {
|
|
394
|
+
if (!checkIsInterested(doc)) {
|
|
395
|
+
Logger(`FOLLOW: SKIP ${doc._id}: OUT OF TARGET FOLDER`, LOG_LEVEL_VERBOSE, "watch");
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
Logger(`FOLLOW: PROCESSING: ${doc.path}`, LEVEL_VERBOSE, "watch");
|
|
400
|
+
const docX = await this.getByMeta(doc);
|
|
401
|
+
try {
|
|
402
|
+
await callback(docX, change.seq);
|
|
403
|
+
Logger(`FOLLOW: PROCESS DONE: ${doc.path}`, LEVEL_INFO, "watch");
|
|
404
|
+
} catch (ex) {
|
|
405
|
+
Logger(`FOLLOW: PROCESS FAILED`, LEVEL_INFO, "watch");
|
|
406
|
+
Logger(ex, LEVEL_VERBOSE, "watch");
|
|
407
|
+
}
|
|
408
|
+
}).on("complete", () => {
|
|
409
|
+
Logger(`FOLLOW: FINISHED AT ${this.since}`, LEVEL_INFO, "watch");
|
|
410
|
+
this.watching = false;
|
|
411
|
+
this.changes = void 0;
|
|
412
|
+
}).on("error", (err) => {
|
|
413
|
+
Logger(`FOLLOW: ERROR at ${this.since}: ${err}`, LEVEL_INFO, "watch");
|
|
414
|
+
});
|
|
415
|
+
return last.last_seq;
|
|
416
|
+
} catch (e) {
|
|
417
|
+
Logger(`FOLLOW: ERROR: ${e}`, LEVEL_INFO, "watch");
|
|
418
|
+
}
|
|
419
|
+
return this.since;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
export {
|
|
423
|
+
DirectFileManipulator
|
|
424
|
+
};
|