@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
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VERSIONING_DOCID,
|
|
3
|
+
LOG_LEVEL_NOTICE,
|
|
4
|
+
LOG_LEVEL_VERBOSE,
|
|
5
|
+
SuffixDatabaseName
|
|
6
|
+
} from "../common/types.js";
|
|
7
|
+
import { Logger } from "../common/logger.js";
|
|
8
|
+
import { isErrorOfMissingDoc } from "./utils_couchdb.js";
|
|
9
|
+
import { EVENT_CHUNK_FETCHED } from "../managers/ChunkFetcher.js";
|
|
10
|
+
import { FallbackWeakRef } from "octagonal-wheels/common/polyfill";
|
|
11
|
+
import { LiveSyncManagers } from "../managers/LiveSyncManagers.js";
|
|
12
|
+
import { createInstanceLogFunction } from "../services/lib/logUtils.js";
|
|
13
|
+
const REMOTE_CHUNK_FETCHED = "remote-chunk-fetched";
|
|
14
|
+
function getNoFromRev(rev) {
|
|
15
|
+
if (!rev) return 0;
|
|
16
|
+
return parseInt(rev.split("-")[0]);
|
|
17
|
+
}
|
|
18
|
+
class LiveSyncLocalDB {
|
|
19
|
+
auth;
|
|
20
|
+
dbname;
|
|
21
|
+
settings;
|
|
22
|
+
localDatabase;
|
|
23
|
+
_log;
|
|
24
|
+
_managers;
|
|
25
|
+
get managers() {
|
|
26
|
+
if (!this._managers) {
|
|
27
|
+
throw new Error("Managers are not ready yet.");
|
|
28
|
+
}
|
|
29
|
+
return this._managers;
|
|
30
|
+
}
|
|
31
|
+
isReady = false;
|
|
32
|
+
needScanning = false;
|
|
33
|
+
env;
|
|
34
|
+
clearCaches() {
|
|
35
|
+
this._managers?.clearCaches();
|
|
36
|
+
}
|
|
37
|
+
async _prepareHashFunctions() {
|
|
38
|
+
await this._managers?.prepareHashFunction();
|
|
39
|
+
}
|
|
40
|
+
onunload() {
|
|
41
|
+
void this.env.services.databaseEvents.onUnloadDatabase(this);
|
|
42
|
+
this.localDatabase.removeAllListeners();
|
|
43
|
+
}
|
|
44
|
+
refreshSettings() {
|
|
45
|
+
const settings = this.env.services.setting.currentSettings();
|
|
46
|
+
this.settings = settings;
|
|
47
|
+
void this._prepareHashFunctions();
|
|
48
|
+
}
|
|
49
|
+
offRemoteChunkFetchedHandler;
|
|
50
|
+
constructor(dbname, env) {
|
|
51
|
+
this.auth = {
|
|
52
|
+
username: "",
|
|
53
|
+
password: ""
|
|
54
|
+
};
|
|
55
|
+
this.dbname = dbname;
|
|
56
|
+
this.env = env;
|
|
57
|
+
this._log = createInstanceLogFunction("LiveSyncLocalDB", this.env.services.API);
|
|
58
|
+
this.refreshSettings();
|
|
59
|
+
}
|
|
60
|
+
async close() {
|
|
61
|
+
this._log("Database closed (by close)");
|
|
62
|
+
this.isReady = false;
|
|
63
|
+
this.offRemoteChunkFetchedHandler?.();
|
|
64
|
+
if (this.localDatabase != null) {
|
|
65
|
+
await this.localDatabase.close();
|
|
66
|
+
}
|
|
67
|
+
await this.env.services.databaseEvents.onUnloadDatabase(this);
|
|
68
|
+
}
|
|
69
|
+
onNewLeaf(chunk) {
|
|
70
|
+
this.managers.chunkManager?.emitEvent(EVENT_CHUNK_FETCHED, chunk);
|
|
71
|
+
}
|
|
72
|
+
async initializeDatabase() {
|
|
73
|
+
await this._prepareHashFunctions();
|
|
74
|
+
if (this.localDatabase != null) {
|
|
75
|
+
this.localDatabase.removeAllListeners();
|
|
76
|
+
await this.localDatabase.close();
|
|
77
|
+
}
|
|
78
|
+
this.localDatabase = null;
|
|
79
|
+
this.localDatabase = this.env.services.database.createPouchDBInstance(
|
|
80
|
+
this.dbname + SuffixDatabaseName,
|
|
81
|
+
{
|
|
82
|
+
auto_compaction: false,
|
|
83
|
+
revs_limit: 100,
|
|
84
|
+
deterministic_revs: true
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
const manager = new LiveSyncManagers({
|
|
88
|
+
database: this.localDatabase,
|
|
89
|
+
APIService: this.env.services.API,
|
|
90
|
+
pathService: this.env.services.path,
|
|
91
|
+
replicatorService: this.env.services.replicator,
|
|
92
|
+
settingService: this.env.services.setting,
|
|
93
|
+
databaseService: this.env.services.database
|
|
94
|
+
});
|
|
95
|
+
this._managers = manager;
|
|
96
|
+
if (!await this.env.services.databaseEvents.onDatabaseInitialisation(this)) {
|
|
97
|
+
this._log("Initializing Database has been failed on some module", LOG_LEVEL_NOTICE);
|
|
98
|
+
}
|
|
99
|
+
this._log("Opening Database...");
|
|
100
|
+
this._log("Database info", LOG_LEVEL_VERBOSE);
|
|
101
|
+
this._log(JSON.stringify(await this.localDatabase.info(), null, 2), LOG_LEVEL_VERBOSE);
|
|
102
|
+
await this.managers.initialise();
|
|
103
|
+
this.localDatabase.on("close", () => {
|
|
104
|
+
this._log("Database closed.");
|
|
105
|
+
this.isReady = false;
|
|
106
|
+
this.localDatabase.removeAllListeners();
|
|
107
|
+
this.env.services.replicator.getActiveReplicator()?.closeReplication();
|
|
108
|
+
void this.managers.teardownManagers();
|
|
109
|
+
});
|
|
110
|
+
const _instance = new FallbackWeakRef(this);
|
|
111
|
+
const unload = this.env.services.context.events.onEvent(REMOTE_CHUNK_FETCHED, (chunk) => {
|
|
112
|
+
if (_instance.deref() == null) {
|
|
113
|
+
unload();
|
|
114
|
+
}
|
|
115
|
+
_instance.deref()?.onNewLeaf(chunk);
|
|
116
|
+
});
|
|
117
|
+
this.offRemoteChunkFetchedHandler = unload;
|
|
118
|
+
this.isReady = true;
|
|
119
|
+
if (!await this.env.services.databaseEvents.onDatabaseHasReady()) {
|
|
120
|
+
this._log(
|
|
121
|
+
"Some module has prevented the database from being ready. The database is initialised but not ready for use.",
|
|
122
|
+
LOG_LEVEL_NOTICE
|
|
123
|
+
);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
this._log("Database is now ready.");
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Retrieve all used and existing chunks in the database.
|
|
131
|
+
* @param includeDeleted include deleted chunks in the result.
|
|
132
|
+
* @returns {used: Set<string>, existing: Map<string, EntryLeaf>} used: Set of chunk ids that are used in the database. existing: Map of chunk id and EntryLeaf that are existing in the database.
|
|
133
|
+
*/
|
|
134
|
+
async allChunks(includeDeleted = false) {
|
|
135
|
+
const used = /* @__PURE__ */ new Set();
|
|
136
|
+
const existing = /* @__PURE__ */ new Map();
|
|
137
|
+
let since = 0;
|
|
138
|
+
do {
|
|
139
|
+
const changes = await this.localDatabase.changes({
|
|
140
|
+
since,
|
|
141
|
+
limit: 100,
|
|
142
|
+
include_docs: true,
|
|
143
|
+
conflicts: true,
|
|
144
|
+
style: includeDeleted ? "all_docs" : "main_only"
|
|
145
|
+
});
|
|
146
|
+
if (changes.results.length == 0) {
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
for (const change of changes.results) {
|
|
150
|
+
const doc = change.doc;
|
|
151
|
+
if (doc.type == "leaf") {
|
|
152
|
+
if (doc._deleted) {
|
|
153
|
+
if (!includeDeleted) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
existing.set(doc._id, doc);
|
|
158
|
+
}
|
|
159
|
+
if ("children" in doc) {
|
|
160
|
+
if (change.deleted) {
|
|
161
|
+
if (!doc._conflicts || doc._conflicts.length == 0) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
doc.children.forEach((e) => used.add(e));
|
|
166
|
+
if (doc._conflicts) {
|
|
167
|
+
const revs = await this.localDatabase.get(doc._id, { revs: true, revs_info: true });
|
|
168
|
+
const mineRevInfo = revs._revs_info || [];
|
|
169
|
+
const keepRevs = /* @__PURE__ */ new Set();
|
|
170
|
+
for (const conflict of doc._conflicts) {
|
|
171
|
+
const conflictedRevs = await this.localDatabase.get(doc._id, {
|
|
172
|
+
rev: conflict,
|
|
173
|
+
revs: true,
|
|
174
|
+
revs_info: true
|
|
175
|
+
});
|
|
176
|
+
const conflictedRevInfo = conflictedRevs._revs_info || [];
|
|
177
|
+
const diffRevs = mineRevInfo.filter(
|
|
178
|
+
(e) => !conflictedRevInfo.some((f) => f.rev == e.rev && f.status == e.status)
|
|
179
|
+
);
|
|
180
|
+
const diffRevs2 = conflictedRevInfo.filter(
|
|
181
|
+
(e) => !mineRevInfo.some((f) => f.rev == e.rev && f.status == e.status)
|
|
182
|
+
);
|
|
183
|
+
const diffRevs3 = diffRevs.concat(diffRevs2);
|
|
184
|
+
const sameRevs = mineRevInfo.filter((e) => conflictedRevInfo.some((f) => f.rev == e.rev && f.status == e.status)).filter((e) => e.status == "available").sort((a, b) => getNoFromRev(b.rev) - getNoFromRev(a.rev));
|
|
185
|
+
const sameRevsTop = sameRevs.length > 0 ? [sameRevs[0].rev] : [];
|
|
186
|
+
const keepRevList = [
|
|
187
|
+
...diffRevs3.filter((e) => e.status == "available").map((e) => e.rev),
|
|
188
|
+
...sameRevsTop
|
|
189
|
+
];
|
|
190
|
+
keepRevList.forEach((e) => keepRevs.add(e));
|
|
191
|
+
}
|
|
192
|
+
const detail = await this.localDatabase.bulkGet({
|
|
193
|
+
docs: [...keepRevs.values()].map((e) => ({ id: doc._id, rev: e }))
|
|
194
|
+
});
|
|
195
|
+
for (const e of detail.results) {
|
|
196
|
+
if ("docs" in e) {
|
|
197
|
+
const docs = e.docs;
|
|
198
|
+
for (const doc2 of docs) {
|
|
199
|
+
if ("ok" in doc2) {
|
|
200
|
+
if ("children" in doc2.ok) {
|
|
201
|
+
doc2.ok.children.forEach((e2) => used.add(e2));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
since = changes.results[changes.results.length - 1].seq;
|
|
211
|
+
} while (true);
|
|
212
|
+
return { used, existing };
|
|
213
|
+
}
|
|
214
|
+
async resetDatabase() {
|
|
215
|
+
await this.managers.teardownManagers();
|
|
216
|
+
this.env.services.replicator.getActiveReplicator()?.closeReplication();
|
|
217
|
+
if (!await this.env.services.databaseEvents.onResetDatabase(this)) {
|
|
218
|
+
Logger("Database reset has been prevented or failed on some modules.", LOG_LEVEL_NOTICE);
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
Logger("Database closed for reset Database.");
|
|
222
|
+
this.isReady = false;
|
|
223
|
+
await this.localDatabase.destroy();
|
|
224
|
+
this.localDatabase = null;
|
|
225
|
+
await this.initializeDatabase();
|
|
226
|
+
this._log("Local Database Reset", LOG_LEVEL_NOTICE);
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
async *findEntries(startKey, endKey, opt) {
|
|
230
|
+
const pageLimit = 100;
|
|
231
|
+
let nextKey = startKey;
|
|
232
|
+
if (endKey == "") endKey = "\u{10FFFF}";
|
|
233
|
+
let req = this.allDocsRaw({ limit: pageLimit, startkey: nextKey, endkey: endKey, include_docs: true, ...opt });
|
|
234
|
+
do {
|
|
235
|
+
const docs = await req;
|
|
236
|
+
if (docs.rows.length === 0) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
nextKey = `${docs.rows[docs.rows.length - 1].id}`;
|
|
240
|
+
req = this.allDocsRaw({
|
|
241
|
+
limit: pageLimit,
|
|
242
|
+
skip: 1,
|
|
243
|
+
startkey: nextKey,
|
|
244
|
+
endkey: endKey,
|
|
245
|
+
include_docs: true,
|
|
246
|
+
...opt
|
|
247
|
+
});
|
|
248
|
+
for (const row of docs.rows) {
|
|
249
|
+
const doc = row.doc;
|
|
250
|
+
if (!("type" in doc)) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (doc.type == "newnote" || doc.type == "plain") {
|
|
254
|
+
yield doc;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} while (nextKey != "");
|
|
258
|
+
}
|
|
259
|
+
async *findAllDocs(opt) {
|
|
260
|
+
const targets = [
|
|
261
|
+
() => this.findEntries("", "_", opt ?? {}),
|
|
262
|
+
() => this.findEntries("_\u{10FFFF}", "h:", opt ?? {}),
|
|
263
|
+
() => this.findEntries(`h:\u{10FFFF}`, "", opt ?? {})
|
|
264
|
+
];
|
|
265
|
+
for (const targetFun of targets) {
|
|
266
|
+
yield* targetFun();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async *findEntryNames(startKey, endKey, opt) {
|
|
270
|
+
const pageLimit = 100;
|
|
271
|
+
let nextKey = startKey;
|
|
272
|
+
if (endKey == "") endKey = "\u{10FFFF}";
|
|
273
|
+
let req = this.allDocsRaw({ limit: pageLimit, startkey: nextKey, endkey: endKey, ...opt });
|
|
274
|
+
do {
|
|
275
|
+
const docs = await req;
|
|
276
|
+
if (docs.rows.length == 0) {
|
|
277
|
+
nextKey = "";
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
nextKey = `${docs.rows[docs.rows.length - 1].key}`;
|
|
281
|
+
req = this.allDocsRaw({ limit: pageLimit, skip: 1, startkey: nextKey, endkey: endKey, ...opt });
|
|
282
|
+
for (const row of docs.rows) {
|
|
283
|
+
yield row.id;
|
|
284
|
+
}
|
|
285
|
+
} while (nextKey != "");
|
|
286
|
+
}
|
|
287
|
+
async *findAllDocNames(opt) {
|
|
288
|
+
const targets = [
|
|
289
|
+
() => this.findEntryNames("", "_", opt ?? {}),
|
|
290
|
+
() => this.findEntryNames("_\u{10FFFF}", "h:", opt ?? {}),
|
|
291
|
+
() => this.findEntryNames(`h:\u{10FFFF}`, "i:", opt ?? {}),
|
|
292
|
+
() => this.findEntryNames(`i:\u{10FFFF}`, "ix:", opt ?? {}),
|
|
293
|
+
() => this.findEntryNames(`ix:\u{10FFFF}`, "ps:", opt ?? {}),
|
|
294
|
+
() => this.findEntryNames(`ps:\u{10FFFF}`, "", opt ?? {})
|
|
295
|
+
];
|
|
296
|
+
for (const targetFun of targets) {
|
|
297
|
+
const target = targetFun();
|
|
298
|
+
for await (const f of target) {
|
|
299
|
+
if (f.startsWith("_")) continue;
|
|
300
|
+
if (f == VERSIONING_DOCID) continue;
|
|
301
|
+
yield f;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async *findAllNormalDocs(opt) {
|
|
306
|
+
const targets = [
|
|
307
|
+
() => this.findEntries("", "_", opt ?? {}),
|
|
308
|
+
() => this.findEntries("_\u{10FFFF}", "h:", opt ?? {}),
|
|
309
|
+
() => this.findEntries(`h:\u{10FFFF}`, "i:", opt ?? {}),
|
|
310
|
+
() => this.findEntries(`i:\u{10FFFF}`, "ix:", opt ?? {}),
|
|
311
|
+
() => this.findEntries(`ix:\u{10FFFF}`, "ps:", opt ?? {}),
|
|
312
|
+
() => this.findEntries(`ps:\u{10FFFF}`, "", opt ?? {})
|
|
313
|
+
];
|
|
314
|
+
for (const targetFun of targets) {
|
|
315
|
+
const target = targetFun();
|
|
316
|
+
for await (const f of target) {
|
|
317
|
+
if (f._id.startsWith("_")) continue;
|
|
318
|
+
if (f.type != "newnote" && f.type != "plain") continue;
|
|
319
|
+
yield f;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async removeRevision(docId, revision) {
|
|
324
|
+
try {
|
|
325
|
+
const doc = await this.localDatabase.get(docId, { rev: revision });
|
|
326
|
+
doc._deleted = true;
|
|
327
|
+
await this.localDatabase.put(doc);
|
|
328
|
+
return true;
|
|
329
|
+
} catch (ex) {
|
|
330
|
+
if (isErrorOfMissingDoc(ex)) {
|
|
331
|
+
Logger(`Remove revision: Missing target revision, ${docId}-${revision}`, LOG_LEVEL_VERBOSE);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
getRaw(docId, options) {
|
|
337
|
+
return this.localDatabase.get(docId, options || {});
|
|
338
|
+
}
|
|
339
|
+
removeRaw(docId, revision, options) {
|
|
340
|
+
return this.localDatabase.remove(docId, revision, options || {});
|
|
341
|
+
}
|
|
342
|
+
putRaw(doc, options) {
|
|
343
|
+
return this.localDatabase.put(doc, options || {});
|
|
344
|
+
}
|
|
345
|
+
allDocsRaw(options) {
|
|
346
|
+
return this.localDatabase.allDocs(options);
|
|
347
|
+
}
|
|
348
|
+
bulkDocsRaw(docs, options) {
|
|
349
|
+
return this.localDatabase.bulkDocs(docs, options || {});
|
|
350
|
+
}
|
|
351
|
+
// For compatibility
|
|
352
|
+
isTargetFile(filenameSrc) {
|
|
353
|
+
return this.managers.entryManager.isTargetFile(filenameSrc);
|
|
354
|
+
}
|
|
355
|
+
async getDBEntryMeta(path, opt, includeDeleted = false) {
|
|
356
|
+
return await this.managers.entryManager.getDBEntryMeta(path, opt, includeDeleted);
|
|
357
|
+
}
|
|
358
|
+
async getDBEntry(path, opt, dump = false, waitForReady = true, includeDeleted = false) {
|
|
359
|
+
return await this.managers.entryManager.getDBEntry(path, opt, dump, waitForReady, includeDeleted);
|
|
360
|
+
}
|
|
361
|
+
async getDBEntryFromMeta(meta, dump = false, waitForReady = true) {
|
|
362
|
+
return await this.managers.entryManager.getDBEntryFromMeta(meta, dump, waitForReady);
|
|
363
|
+
}
|
|
364
|
+
async deleteDBEntry(path, opt) {
|
|
365
|
+
return await this.managers.entryManager.deleteDBEntry(path, opt);
|
|
366
|
+
}
|
|
367
|
+
async putDBEntry(note, onlyChunks, conflictBaseRev) {
|
|
368
|
+
return await this.managers.entryManager.putDBEntry(note, onlyChunks, conflictBaseRev);
|
|
369
|
+
}
|
|
370
|
+
async getConflictedDoc(path, rev) {
|
|
371
|
+
return await this.managers.conflictManager.getConflictedDoc(path, rev);
|
|
372
|
+
}
|
|
373
|
+
async tryAutoMerge(path, enableMarkdownAutoMerge) {
|
|
374
|
+
return await this.managers.conflictManager.tryAutoMerge(path, enableMarkdownAutoMerge);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
export {
|
|
378
|
+
LiveSyncLocalDB,
|
|
379
|
+
REMOTE_CHUNK_FETCHED,
|
|
380
|
+
getNoFromRev
|
|
381
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type SomeDocument<T extends object> = PouchDB.Core.ExistingDocument<T> & PouchDB.Core.ChangesMeta;
|
|
2
|
+
/**
|
|
3
|
+
* Minimal subset of the PouchDB public API required by {@link replicateShim}.
|
|
4
|
+
* Both a real `PouchDB.Database` and an {@link RpcPouchDBProxy} satisfy this
|
|
5
|
+
* interface, allowing replication across an RPC transport.
|
|
6
|
+
*/
|
|
7
|
+
export type PouchDBShim<T extends object> = {
|
|
8
|
+
info: () => Promise<PouchDB.Core.DatabaseInfo>;
|
|
9
|
+
changes: (options: PouchDB.Core.ChangesOptions) => PromiseLike<PouchDB.Core.ChangesResponse<T>>;
|
|
10
|
+
revsDiff: (diff: PouchDB.Core.RevisionDiffOptions) => Promise<PouchDB.Core.RevisionDiffResponse>;
|
|
11
|
+
bulkDocs: (docs: PouchDB.Core.PutDocument<T>[], options?: PouchDB.Core.BulkDocsOptions) => Promise<(PouchDB.Core.Response | PouchDB.Core.Error)[]>;
|
|
12
|
+
bulkGet: (options: PouchDB.Core.BulkGetOptions) => Promise<PouchDB.Core.BulkGetResponse<T>>;
|
|
13
|
+
put: (doc: PouchDB.Core.PutDocument<T>, options?: PouchDB.Core.PutOptions) => Promise<PouchDB.Core.Response>;
|
|
14
|
+
get: (id: string, options?: PouchDB.Core.GetOptions) => Promise<T & PouchDB.Core.IdMeta & PouchDB.Core.GetMeta>;
|
|
15
|
+
};
|
|
16
|
+
type CompatibleDatabase<T extends object> = PouchDB.Database<SomeDocument<T>> | PouchDBShim<SomeDocument<T>>;
|
|
17
|
+
/** Upserts a document by `id`, calling `func` to produce the updated version. */
|
|
18
|
+
export declare function upsert<V extends object, TDB extends CompatibleDatabase<object> = CompatibleDatabase<any>, T extends SomeDocument<V> = SomeDocument<V>>(db: TDB, id: string, func: (doc: T) => T): Promise<T>;
|
|
19
|
+
export type ShimReplicationOptionBase = {
|
|
20
|
+
rewind?: boolean;
|
|
21
|
+
batch_size?: number;
|
|
22
|
+
};
|
|
23
|
+
export type ShimReplicationOneShot = {
|
|
24
|
+
live?: false;
|
|
25
|
+
controller?: AbortController;
|
|
26
|
+
} & ShimReplicationOptionBase;
|
|
27
|
+
export type ShimReplicationOptionContinuous = {
|
|
28
|
+
live: true;
|
|
29
|
+
controller: AbortController;
|
|
30
|
+
} & ShimReplicationOptionBase;
|
|
31
|
+
export type ShimReplicationOption = ShimReplicationOneShot | ShimReplicationOptionContinuous;
|
|
32
|
+
export type ProgressInfo = {
|
|
33
|
+
lastSeq: number;
|
|
34
|
+
maxSeqInBatch: number;
|
|
35
|
+
};
|
|
36
|
+
export type ShimReplicationProgressReportFunc<T extends object> = (progress: SomeDocument<T>[], progressInfo: ProgressInfo) => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Replicate documents from `sourceDB` into `targetDB` using a CouchDB-style
|
|
39
|
+
* checkpoint protocol.
|
|
40
|
+
*
|
|
41
|
+
* Both parameters accept either a real `PouchDB.Database` or any object
|
|
42
|
+
* implementing {@link PouchDBShim} — including {@link RpcPouchDBProxy} — so
|
|
43
|
+
* replication can span an RPC transport boundary.
|
|
44
|
+
*
|
|
45
|
+
* @param targetDB Destination database (usually local).
|
|
46
|
+
* @param sourceDB Source database (may be remote / RPC-backed).
|
|
47
|
+
* @param progress Called after each batch with the written documents.
|
|
48
|
+
* @param option Replication options (live mode, batch size, abort signal).
|
|
49
|
+
*/
|
|
50
|
+
export declare function replicateShim<T extends CompatibleDatabase<V>, U extends CompatibleDatabase<V>, V extends object>(targetDB: T, sourceDB: U, progress: ShimReplicationProgressReportFunc<V>, option?: ShimReplicationOption): Promise<void>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { serialized } from "octagonal-wheels/concurrency/lock";
|
|
2
|
+
import { Logger } from "../common/logger.js";
|
|
3
|
+
import { LOG_LEVEL_VERBOSE } from "../common/types.js";
|
|
4
|
+
async function upsert(db, id, func) {
|
|
5
|
+
try {
|
|
6
|
+
const doc = await db.get(id);
|
|
7
|
+
const updated = func(doc);
|
|
8
|
+
const result = await db.put(updated, {});
|
|
9
|
+
if (result && result.ok) {
|
|
10
|
+
return updated;
|
|
11
|
+
}
|
|
12
|
+
throw new Error("Failed to update");
|
|
13
|
+
} catch (ex) {
|
|
14
|
+
const isNotFound = ex?.name === "not_found" || ex?.reason === "missing" || ex?.message === "missing" || ex?.message === "not_found";
|
|
15
|
+
if (isNotFound) {
|
|
16
|
+
const seed = func({ _id: id });
|
|
17
|
+
const result = await db.put(seed, {});
|
|
18
|
+
if (result && result.ok) {
|
|
19
|
+
return seed;
|
|
20
|
+
}
|
|
21
|
+
throw new Error("Failed to insert");
|
|
22
|
+
}
|
|
23
|
+
throw ex;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function parseSeq(seq) {
|
|
27
|
+
return parseInt(String(seq).split("-")[0], 10);
|
|
28
|
+
}
|
|
29
|
+
function buildRevsDiffParam(changesResults) {
|
|
30
|
+
const param = {};
|
|
31
|
+
for (const { id, changes } of changesResults) {
|
|
32
|
+
param[id] = [...param[id] ?? [], ...changes.map((c) => c.rev)];
|
|
33
|
+
}
|
|
34
|
+
return param;
|
|
35
|
+
}
|
|
36
|
+
function sortBySeq(docs, changesResults) {
|
|
37
|
+
const maxSeqById = /* @__PURE__ */ new Map();
|
|
38
|
+
for (const { id, seq } of changesResults) {
|
|
39
|
+
maxSeqById.set(id, Math.max(maxSeqById.get(id) ?? 0, parseSeq(seq)));
|
|
40
|
+
}
|
|
41
|
+
return docs.slice().sort((a, b) => (maxSeqById.get(a._id) ?? 0) - (maxSeqById.get(b._id) ?? 0));
|
|
42
|
+
}
|
|
43
|
+
async function replicateShim(targetDB, sourceDB, progress, option = {}) {
|
|
44
|
+
try {
|
|
45
|
+
const [targetDBInfo, sourceDBInfo] = await Promise.all([targetDB.info(), sourceDB.info()]);
|
|
46
|
+
const maxNumSeq = parseSeq(sourceDBInfo.update_seq);
|
|
47
|
+
await serialized(`replication-${targetDBInfo.db_name}-${sourceDBInfo.db_name}`, async () => {
|
|
48
|
+
Logger(
|
|
49
|
+
`Replication ${sourceDBInfo.db_name} (${sourceDBInfo.update_seq}) \u2192 ${targetDBInfo.db_name} (${targetDBInfo.update_seq})`,
|
|
50
|
+
LOG_LEVEL_VERBOSE
|
|
51
|
+
);
|
|
52
|
+
const { db_name: targetName } = targetDBInfo;
|
|
53
|
+
const { db_name: sourceName } = sourceDBInfo;
|
|
54
|
+
const sourceCheckpointID = `_local/replication-checkpoint-mark-${targetName}-${sourceName}`;
|
|
55
|
+
const { mark } = await upsert(sourceDB, sourceCheckpointID, (doc) => ({
|
|
56
|
+
...doc,
|
|
57
|
+
mark: option.rewind ? String(Date.now()) : doc.mark ?? String(Date.now())
|
|
58
|
+
}));
|
|
59
|
+
Logger(`Replication mark: ${mark}`, LOG_LEVEL_VERBOSE);
|
|
60
|
+
const targetCheckpointID = `_local/replication-checkpoint-${targetName}-${mark}`;
|
|
61
|
+
const checkpoint = await upsert(targetDB, targetCheckpointID, (doc) => ({
|
|
62
|
+
...doc,
|
|
63
|
+
since: doc.since ?? ""
|
|
64
|
+
}));
|
|
65
|
+
let since = checkpoint.since;
|
|
66
|
+
Logger(`Starting from seq ${since}`, LOG_LEVEL_VERBOSE);
|
|
67
|
+
const batchSize = option.batch_size ?? 33;
|
|
68
|
+
while (true) {
|
|
69
|
+
const changes = await sourceDB.changes({ since, style: "all_docs", limit: batchSize });
|
|
70
|
+
if (changes.results.length === 0) break;
|
|
71
|
+
if (option.controller?.signal?.aborted) break;
|
|
72
|
+
const changesResults = changes.results;
|
|
73
|
+
const revsDiffParam = buildRevsDiffParam(changesResults);
|
|
74
|
+
const diff = await targetDB.revsDiff(revsDiffParam);
|
|
75
|
+
const missingRequests = Object.entries(diff).filter(([, entry]) => entry.missing !== void 0).flatMap(([id, entry]) => entry.missing.map((rev) => ({ id, rev })));
|
|
76
|
+
if (missingRequests.length > 0) {
|
|
77
|
+
const bulkGetResult = await sourceDB.bulkGet({ docs: missingRequests, revs: true });
|
|
78
|
+
const fetchedDocs = bulkGetResult.results.flatMap((r) => r.docs).filter((d) => "ok" in d).map((d) => d.ok);
|
|
79
|
+
await targetDB.bulkDocs(fetchedDocs, { new_edits: false });
|
|
80
|
+
const uniqueIds = [...new Set(changesResults.map((c) => c.id))];
|
|
81
|
+
const refreshResult = await targetDB.bulkGet({ docs: uniqueIds.map((id) => ({ id })) });
|
|
82
|
+
const refreshedDocs = refreshResult.results.flatMap((r) => r.docs).filter((d) => "ok" in d).map((d) => d.ok);
|
|
83
|
+
const orderedDocs = sortBySeq(refreshedDocs, changesResults);
|
|
84
|
+
const lastSeqNum = parseSeq(changes.last_seq);
|
|
85
|
+
try {
|
|
86
|
+
await progress(orderedDocs, { lastSeq: lastSeqNum, maxSeqInBatch: maxNumSeq });
|
|
87
|
+
} catch (ex) {
|
|
88
|
+
Logger(`Progress callback failed during shim-replication`, LOG_LEVEL_VERBOSE);
|
|
89
|
+
Logger(ex, LOG_LEVEL_VERBOSE);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
since = changes.last_seq;
|
|
93
|
+
await upsert(targetDB, targetCheckpointID, (doc) => ({
|
|
94
|
+
...doc,
|
|
95
|
+
since
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
} catch (ex) {
|
|
100
|
+
Logger(`Replication failed`, LOG_LEVEL_VERBOSE);
|
|
101
|
+
Logger(ex, LOG_LEVEL_VERBOSE);
|
|
102
|
+
throw ex;
|
|
103
|
+
}
|
|
104
|
+
Logger(`Replication completed`, LOG_LEVEL_VERBOSE);
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
replicateShim,
|
|
108
|
+
upsert
|
|
109
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EntryDoc } from "../common/models/db.definition.js";
|
|
2
|
+
import type { AnyEntry, EntryLeaf } from "../common/models/db.type.js";
|
|
3
|
+
type DBSequence = number | string;
|
|
4
|
+
export type FetchChangesForInitialSyncProgress = {
|
|
5
|
+
totalFetched: number;
|
|
6
|
+
totalValidFetched: number;
|
|
7
|
+
targetSeq: number | string;
|
|
8
|
+
docsToFetch: number;
|
|
9
|
+
totalBytes: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Fetches initial data from CouchDB as a stream and writes it into PouchDB.
|
|
13
|
+
* @param downloadToDB PouchDB instance.
|
|
14
|
+
* @param remoteDbUrl CouchDB database URL (for example: 'https://xxx.com/mydb').
|
|
15
|
+
* @param decryptFunction Function to decrypt each document.
|
|
16
|
+
* @param since Sequence ID to start fetching changes from (default is '0').
|
|
17
|
+
*/
|
|
18
|
+
export declare function fetchChangesForInitialSync(downloadToDB: PouchDB.Database, remoteDbUrl: string, authHeader: string, decryptFunction: (doc: EntryDoc) => Promise<AnyEntry | EntryLeaf>, since?: number | string, onProgress?: (progress: FetchChangesForInitialSyncProgress) => void, onCheckpoint?: (sequence: DBSequence) => void | Promise<void>): Promise<void>;
|
|
19
|
+
export {};
|