@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,111 @@
|
|
|
1
|
+
import { HashManagerCore } from "./HashManagerCore.js";
|
|
2
|
+
import { xxhashNew } from "../../string_and_binary/hash.js";
|
|
3
|
+
import { HashAlgorithms } from "../../common/models/setting.const.js";
|
|
4
|
+
class XXHashHashManager extends HashManagerCore {
|
|
5
|
+
/**
|
|
6
|
+
* Instance of XXHash API used for hashing operations.
|
|
7
|
+
*/
|
|
8
|
+
xxhash;
|
|
9
|
+
/**
|
|
10
|
+
* Constructs a new XXHashHashManager.
|
|
11
|
+
* @param options - Options for the hash manager core.
|
|
12
|
+
*/
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Initialises the XXHash API instance.
|
|
18
|
+
* @returns A promise resolving to true when initialisation is complete.
|
|
19
|
+
*/
|
|
20
|
+
async processInitialise() {
|
|
21
|
+
this.xxhash = await xxhashNew();
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class XXHash32RawHashManager extends XXHashHashManager {
|
|
26
|
+
/**
|
|
27
|
+
* Determines whether this manager is available for the specified algorithm.
|
|
28
|
+
* @param hashAlg - The hash algorithm to check.
|
|
29
|
+
* @returns True if available, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
static isAvailableFor(hashAlg) {
|
|
32
|
+
return hashAlg === HashAlgorithms.LEGACY;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Computes a hash for the given piece using encryption.
|
|
36
|
+
* @param piece - The input string to hash.
|
|
37
|
+
* @returns A promise resolving to the hash string.
|
|
38
|
+
*/
|
|
39
|
+
computeHashWithEncryption(piece) {
|
|
40
|
+
return Promise.resolve(
|
|
41
|
+
(this.xxhash.h32Raw(new TextEncoder().encode(piece)) ^ this.hashedPassphrase32 ^ piece.length).toString(36)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Computes a hash for the given piece without encryption.
|
|
46
|
+
* @param piece - The input string to hash.
|
|
47
|
+
* @returns A promise resolving to the hash string.
|
|
48
|
+
*/
|
|
49
|
+
computeHashWithoutEncryption(piece) {
|
|
50
|
+
return Promise.resolve((this.xxhash.h32Raw(new TextEncoder().encode(piece)) ^ piece.length).toString(36));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class XXHash64HashManager extends XXHashHashManager {
|
|
54
|
+
/**
|
|
55
|
+
* Determines whether this manager is available for the specified algorithm.
|
|
56
|
+
* @param hashAlg - The hash algorithm to check.
|
|
57
|
+
* @returns True if available, false otherwise.
|
|
58
|
+
*/
|
|
59
|
+
static isAvailableFor(hashAlg) {
|
|
60
|
+
return hashAlg === HashAlgorithms.XXHASH64;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Computes a hash for the given piece using encryption.
|
|
64
|
+
* @param piece - The input string to hash.
|
|
65
|
+
* @returns A promise resolving to the hash string.
|
|
66
|
+
*/
|
|
67
|
+
computeHashWithEncryption(piece) {
|
|
68
|
+
return Promise.resolve(this.xxhash.h64(`${piece}-${this.hashedPassphrase}-${piece.length}`).toString(36));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Computes a hash for the given piece without encryption.
|
|
72
|
+
* @param piece - The input string to hash.
|
|
73
|
+
* @returns A promise resolving to the hash string.
|
|
74
|
+
*/
|
|
75
|
+
computeHashWithoutEncryption(piece) {
|
|
76
|
+
return Promise.resolve(this.xxhash.h64(`${piece}-${piece.length}`).toString(36));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
class FallbackWasmHashManager extends XXHashHashManager {
|
|
80
|
+
/**
|
|
81
|
+
* Determines whether this manager is available for the specified algorithm.
|
|
82
|
+
* Always returns true as a fallback.
|
|
83
|
+
* @param hashAlg - The hash algorithm to check.
|
|
84
|
+
* @returns True.
|
|
85
|
+
*/
|
|
86
|
+
static isAvailableFor(hashAlg) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Computes a hash for the given piece using encryption.
|
|
91
|
+
* @param piece - The input string to hash.
|
|
92
|
+
* @returns A promise resolving to the hash string.
|
|
93
|
+
*/
|
|
94
|
+
computeHashWithEncryption(piece) {
|
|
95
|
+
return Promise.resolve(this.xxhash.h32(`${piece}-${this.hashedPassphrase}-${piece.length}`).toString(36));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Computes a hash for the given piece without encryption.
|
|
99
|
+
* @param piece - The input string to hash.
|
|
100
|
+
* @returns A promise resolving to the hash string.
|
|
101
|
+
*/
|
|
102
|
+
computeHashWithoutEncryption(piece) {
|
|
103
|
+
return Promise.resolve(this.xxhash.h32(`${piece}-${piece.length}`).toString(36));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
FallbackWasmHashManager,
|
|
108
|
+
XXHash32RawHashManager,
|
|
109
|
+
XXHash64HashManager,
|
|
110
|
+
XXHashHashManager
|
|
111
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DocumentID, EntryLeaf } from "../../common/types.js";
|
|
2
|
+
import type { IReadLayer } from "./ChunkLayerInterfaces.js";
|
|
3
|
+
import type { ChunkReadOptions } from "./types.js";
|
|
4
|
+
import { ChunkDeliveryCoordinator } from "../ChunkDeliveryCoordinator.js";
|
|
5
|
+
export type ChunkAvailabilityRecheck = (ids: readonly DocumentID[]) => Promise<readonly (EntryLeaf | false)[]>;
|
|
6
|
+
/**
|
|
7
|
+
* Waits only for a delivery lifecycle which is already observable when the
|
|
8
|
+
* local miss is handled. It does not guess at an arrival delay.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ArrivalWaitLayer implements IReadLayer {
|
|
11
|
+
private readonly recheckAvailability?;
|
|
12
|
+
private readonly waitingMap;
|
|
13
|
+
private readonly eventEmitter;
|
|
14
|
+
private readonly deliveryCoordinator;
|
|
15
|
+
private readonly ownsDeliveryCoordinator;
|
|
16
|
+
private readonly stopObservingActivity;
|
|
17
|
+
constructor(eventEmitter: (eventName: string, data: DocumentID[]) => void, deliveryCoordinator?: ChunkDeliveryCoordinator, recheckAvailability?: ChunkAvailabilityRecheck);
|
|
18
|
+
private enqueueWaiting;
|
|
19
|
+
private settle;
|
|
20
|
+
private settleAfterObservedActivity;
|
|
21
|
+
private refreshActivity;
|
|
22
|
+
/** Handle a chunk document becoming available. */
|
|
23
|
+
onChunkArrived(doc: EntryLeaf, deleted?: boolean): void;
|
|
24
|
+
/** Handle an explicit remote-missing result. */
|
|
25
|
+
onMissingChunk(id: DocumentID): void;
|
|
26
|
+
read(ids: DocumentID[], options: ChunkReadOptions, next: (remaining: DocumentID[]) => Promise<(EntryLeaf | false)[]>): Promise<(EntryLeaf | false)[]>;
|
|
27
|
+
clearWaiting(): void;
|
|
28
|
+
tearDown(): void;
|
|
29
|
+
getWaitingCount(): number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { promiseWithResolvers } from "octagonal-wheels/promises";
|
|
2
|
+
import { ChunkDeliveryCoordinator } from "../ChunkDeliveryCoordinator.js";
|
|
3
|
+
import { LOG_LEVEL_VERBOSE, Logger } from "../../common/logger.js";
|
|
4
|
+
class ArrivalWaitLayer {
|
|
5
|
+
constructor(eventEmitter, deliveryCoordinator, recheckAvailability) {
|
|
6
|
+
this.recheckAvailability = recheckAvailability;
|
|
7
|
+
this.eventEmitter = eventEmitter;
|
|
8
|
+
this.deliveryCoordinator = deliveryCoordinator ?? new ChunkDeliveryCoordinator();
|
|
9
|
+
this.ownsDeliveryCoordinator = deliveryCoordinator === void 0;
|
|
10
|
+
this.stopObservingActivity = this.deliveryCoordinator.onChanged((ids) => this.refreshActivity(ids));
|
|
11
|
+
}
|
|
12
|
+
recheckAvailability;
|
|
13
|
+
waitingMap = /* @__PURE__ */ new Map();
|
|
14
|
+
eventEmitter;
|
|
15
|
+
deliveryCoordinator;
|
|
16
|
+
ownsDeliveryCoordinator;
|
|
17
|
+
stopObservingActivity;
|
|
18
|
+
enqueueWaiting(id) {
|
|
19
|
+
const previous = this.waitingMap.get(id);
|
|
20
|
+
if (previous) return previous.resolver.promise;
|
|
21
|
+
const resolver = promiseWithResolvers();
|
|
22
|
+
this.waitingMap.set(id, { activityVersion: 0, observedActivity: false, resolver });
|
|
23
|
+
return resolver.promise;
|
|
24
|
+
}
|
|
25
|
+
settle(id, value) {
|
|
26
|
+
const queue = this.waitingMap.get(id);
|
|
27
|
+
if (!queue) return;
|
|
28
|
+
this.waitingMap.delete(id);
|
|
29
|
+
queue.resolver.resolve(value);
|
|
30
|
+
}
|
|
31
|
+
async settleAfterObservedActivity(ids) {
|
|
32
|
+
const candidates = ids.flatMap((id) => {
|
|
33
|
+
const queue = this.waitingMap.get(id);
|
|
34
|
+
if (!queue?.observedActivity || this.deliveryCoordinator.isActivityActiveFor(id)) return [];
|
|
35
|
+
const version = ++queue.activityVersion;
|
|
36
|
+
return [{ id, version }];
|
|
37
|
+
});
|
|
38
|
+
if (candidates.length === 0) return;
|
|
39
|
+
let results;
|
|
40
|
+
try {
|
|
41
|
+
results = this.recheckAvailability ? await this.recheckAvailability(candidates.map(({ id }) => id)) : candidates.map(() => false);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
Logger("Could not recheck chunk availability after finite delivery activity completed.", LOG_LEVEL_VERBOSE);
|
|
44
|
+
Logger(error, LOG_LEVEL_VERBOSE);
|
|
45
|
+
results = candidates.map(() => false);
|
|
46
|
+
}
|
|
47
|
+
for (let index = 0; index < candidates.length; index++) {
|
|
48
|
+
const { id, version } = candidates[index];
|
|
49
|
+
const queue = this.waitingMap.get(id);
|
|
50
|
+
if (!queue || queue.activityVersion !== version) continue;
|
|
51
|
+
const result = results[index] ?? false;
|
|
52
|
+
if (result) {
|
|
53
|
+
this.settle(id, result);
|
|
54
|
+
} else if (this.deliveryCoordinator.isActivityActiveFor(id)) {
|
|
55
|
+
this.refreshActivity([id]);
|
|
56
|
+
} else {
|
|
57
|
+
this.settle(id, false);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
refreshActivity(ids = [...this.waitingMap.keys()]) {
|
|
62
|
+
const completedActivityIds = [];
|
|
63
|
+
for (const id of ids) {
|
|
64
|
+
const queue = this.waitingMap.get(id);
|
|
65
|
+
if (!queue) continue;
|
|
66
|
+
if (this.deliveryCoordinator.isActivityActiveFor(id)) {
|
|
67
|
+
queue.observedActivity = true;
|
|
68
|
+
queue.activityVersion++;
|
|
69
|
+
} else if (queue.observedActivity) {
|
|
70
|
+
completedActivityIds.push(id);
|
|
71
|
+
} else {
|
|
72
|
+
this.settle(id, false);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (completedActivityIds.length > 0) {
|
|
76
|
+
void this.settleAfterObservedActivity(completedActivityIds);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Handle a chunk document becoming available. */
|
|
80
|
+
onChunkArrived(doc, deleted = false) {
|
|
81
|
+
this.settle(doc._id, doc._deleted || deleted ? false : doc);
|
|
82
|
+
}
|
|
83
|
+
/** Handle an explicit remote-missing result. */
|
|
84
|
+
onMissingChunk(id) {
|
|
85
|
+
this.settle(id, false);
|
|
86
|
+
}
|
|
87
|
+
async read(ids, options, next) {
|
|
88
|
+
const waitForDelivery = options.waitForDelivery ?? (options.timeout === void 0 || options.timeout > 0);
|
|
89
|
+
if (!waitForDelivery || ids.length === 0) return ids.map(() => false);
|
|
90
|
+
const tasks = ids.map((id) => this.enqueueWaiting(id));
|
|
91
|
+
if (!options.preventRemoteRequest) {
|
|
92
|
+
this.eventEmitter("missingChunks", ids);
|
|
93
|
+
}
|
|
94
|
+
this.refreshActivity(ids);
|
|
95
|
+
return await Promise.all(tasks);
|
|
96
|
+
}
|
|
97
|
+
clearWaiting() {
|
|
98
|
+
for (const id of [...this.waitingMap.keys()]) {
|
|
99
|
+
this.settle(id, false);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
tearDown() {
|
|
103
|
+
this.stopObservingActivity();
|
|
104
|
+
this.clearWaiting();
|
|
105
|
+
if (this.ownsDeliveryCoordinator) {
|
|
106
|
+
this.deliveryCoordinator.dispose();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
getWaitingCount() {
|
|
110
|
+
return this.waitingMap.size;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
ArrivalWaitLayer
|
|
115
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { DocumentID, EntryLeaf } from "../../common/types.js";
|
|
2
|
+
import type { IReadLayer, IWriteLayer } from "./ChunkLayerInterfaces.js";
|
|
3
|
+
import type { ChunkReadOptions, ChunkWriteOptions, WriteResult } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Cache layer - manages in-memory cache of chunks.
|
|
6
|
+
* Implements both IReadLayer and IWriteLayer for unified cache management.
|
|
7
|
+
* This layer is self-contained and handles cache operations for both read and write operations.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CacheLayer implements IReadLayer, IWriteLayer {
|
|
10
|
+
private caches;
|
|
11
|
+
private maxCacheSize;
|
|
12
|
+
allocCount: number;
|
|
13
|
+
derefCount: number;
|
|
14
|
+
constructor(maxCacheSize: number);
|
|
15
|
+
/**
|
|
16
|
+
* Get a cached chunk
|
|
17
|
+
*/
|
|
18
|
+
getCachedChunk(id: DocumentID): EntryLeaf | false;
|
|
19
|
+
/**
|
|
20
|
+
* Find chunk ID by data content
|
|
21
|
+
*/
|
|
22
|
+
getChunkIDFromCache(data: string): DocumentID | false;
|
|
23
|
+
/**
|
|
24
|
+
* Cache a chunk
|
|
25
|
+
*/
|
|
26
|
+
cacheChunk(chunk: EntryLeaf): void;
|
|
27
|
+
/**
|
|
28
|
+
* Reorder chunk for LRU (move to end)
|
|
29
|
+
*/
|
|
30
|
+
reorderChunk(id: DocumentID): void;
|
|
31
|
+
/**
|
|
32
|
+
* Delete a cached chunk
|
|
33
|
+
*/
|
|
34
|
+
deleteCachedChunk(id: DocumentID): void;
|
|
35
|
+
/**
|
|
36
|
+
* Clear all caches
|
|
37
|
+
*/
|
|
38
|
+
clearCaches(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Tear down the layer (clear caches on shutdown)
|
|
41
|
+
*/
|
|
42
|
+
tearDown(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get current cache statistics
|
|
45
|
+
*/
|
|
46
|
+
getStatistics(): {
|
|
47
|
+
size: number;
|
|
48
|
+
allocCount: number;
|
|
49
|
+
derefCount: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* IReadLayer implementation - read from cache
|
|
53
|
+
*/
|
|
54
|
+
read(ids: DocumentID[], options: ChunkReadOptions, next: (remaining: DocumentID[]) => Promise<(EntryLeaf | false)[]>): Promise<(EntryLeaf | false)[]>;
|
|
55
|
+
/**
|
|
56
|
+
* IWriteLayer implementation - cache chunks after database write
|
|
57
|
+
*/
|
|
58
|
+
write(chunks: EntryLeaf[], options: ChunkWriteOptions, origin: DocumentID, next: (remaining: EntryLeaf[]) => Promise<WriteResult>): Promise<WriteResult>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { FallbackWeakRef } from "octagonal-wheels/common/polyfill";
|
|
2
|
+
class CacheLayer {
|
|
3
|
+
caches = /* @__PURE__ */ new Map();
|
|
4
|
+
maxCacheSize;
|
|
5
|
+
allocCount = 0;
|
|
6
|
+
derefCount = 0;
|
|
7
|
+
constructor(maxCacheSize) {
|
|
8
|
+
this.maxCacheSize = maxCacheSize;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get a cached chunk
|
|
12
|
+
*/
|
|
13
|
+
getCachedChunk(id) {
|
|
14
|
+
if (!this.caches.has(id)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const weakRef = this.caches.get(id);
|
|
18
|
+
if (weakRef) {
|
|
19
|
+
const cachedChunk = weakRef.deref();
|
|
20
|
+
if (cachedChunk) {
|
|
21
|
+
return cachedChunk;
|
|
22
|
+
} else {
|
|
23
|
+
this.derefCount++;
|
|
24
|
+
this.deleteCachedChunk(id);
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Find chunk ID by data content
|
|
32
|
+
*/
|
|
33
|
+
getChunkIDFromCache(data) {
|
|
34
|
+
for (const [id, weakRef] of this.caches) {
|
|
35
|
+
const chunk = weakRef.deref();
|
|
36
|
+
if (chunk) {
|
|
37
|
+
if (chunk.data === data) {
|
|
38
|
+
return id;
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
this.derefCount++;
|
|
42
|
+
this.deleteCachedChunk(id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Cache a chunk
|
|
49
|
+
*/
|
|
50
|
+
cacheChunk(chunk) {
|
|
51
|
+
if (this.getCachedChunk(chunk._id)) {
|
|
52
|
+
this.reorderChunk(chunk._id);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.caches.set(chunk._id, new FallbackWeakRef(chunk));
|
|
56
|
+
this.allocCount++;
|
|
57
|
+
if (this.caches.size > this.maxCacheSize) {
|
|
58
|
+
do {
|
|
59
|
+
const firstKey = this.caches.keys().next().value;
|
|
60
|
+
if (firstKey) {
|
|
61
|
+
this.caches.delete(firstKey);
|
|
62
|
+
}
|
|
63
|
+
} while (this.caches.size > this.maxCacheSize);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Reorder chunk for LRU (move to end)
|
|
68
|
+
*/
|
|
69
|
+
reorderChunk(id) {
|
|
70
|
+
const chunk = this.getCachedChunk(id);
|
|
71
|
+
if (chunk) {
|
|
72
|
+
this.caches.delete(id);
|
|
73
|
+
this.caches.set(id, new FallbackWeakRef(chunk));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Delete a cached chunk
|
|
78
|
+
*/
|
|
79
|
+
deleteCachedChunk(id) {
|
|
80
|
+
if (this.caches.has(id)) {
|
|
81
|
+
this.caches.delete(id);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Clear all caches
|
|
86
|
+
*/
|
|
87
|
+
clearCaches() {
|
|
88
|
+
this.caches.clear();
|
|
89
|
+
this.allocCount = 0;
|
|
90
|
+
this.derefCount = 0;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Tear down the layer (clear caches on shutdown)
|
|
94
|
+
*/
|
|
95
|
+
tearDown() {
|
|
96
|
+
this.clearCaches();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get current cache statistics
|
|
100
|
+
*/
|
|
101
|
+
getStatistics() {
|
|
102
|
+
return {
|
|
103
|
+
size: this.caches.size,
|
|
104
|
+
allocCount: this.allocCount,
|
|
105
|
+
derefCount: this.derefCount
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* IReadLayer implementation - read from cache
|
|
110
|
+
*/
|
|
111
|
+
async read(ids, options, next) {
|
|
112
|
+
if (options.skipCache) {
|
|
113
|
+
return next(ids);
|
|
114
|
+
}
|
|
115
|
+
const resultMap = /* @__PURE__ */ new Map();
|
|
116
|
+
const remainingIds = [];
|
|
117
|
+
for (const id of ids) {
|
|
118
|
+
const cached = this.getCachedChunk(id);
|
|
119
|
+
if (cached) {
|
|
120
|
+
this.reorderChunk(id);
|
|
121
|
+
resultMap.set(id, cached);
|
|
122
|
+
} else {
|
|
123
|
+
remainingIds.push(id);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (remainingIds.length === 0) {
|
|
127
|
+
return ids.map((id) => resultMap.get(id) || false);
|
|
128
|
+
}
|
|
129
|
+
const nextResults = await next(remainingIds);
|
|
130
|
+
const nextResultMap = new Map(remainingIds.map((id, index) => [id, nextResults[index]]));
|
|
131
|
+
return ids.map((id) => resultMap.get(id) ?? nextResultMap.get(id) ?? false);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* IWriteLayer implementation - cache chunks after database write
|
|
135
|
+
*/
|
|
136
|
+
async write(chunks, options, origin, next) {
|
|
137
|
+
const filtered = [];
|
|
138
|
+
const cachedCount = chunks.length;
|
|
139
|
+
for (const chunk of chunks) {
|
|
140
|
+
const cached = this.getCachedChunk(chunk._id);
|
|
141
|
+
if (!cached) {
|
|
142
|
+
filtered.push(chunk);
|
|
143
|
+
} else {
|
|
144
|
+
this.reorderChunk(chunk._id);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const result = await next(filtered);
|
|
148
|
+
if (result.result && !options.skipCache) {
|
|
149
|
+
for (const chunk of chunks) {
|
|
150
|
+
this.cacheChunk(chunk);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (result.processed) {
|
|
154
|
+
result.processed.cached = cachedCount - filtered.length;
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
CacheLayer
|
|
161
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DocumentID, EntryLeaf } from "../../common/types.js";
|
|
2
|
+
import type { ChunkReadOptions, ChunkWriteOptions, WriteResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Interface for read layers in the chunk reading pipeline.
|
|
5
|
+
* Each layer processes a chunk read request and passes it to the next layer.
|
|
6
|
+
*/
|
|
7
|
+
export interface IReadLayer {
|
|
8
|
+
/**
|
|
9
|
+
* Process a read request for the given chunk IDs.
|
|
10
|
+
* The next layer in the pipeline should be called to continue processing.
|
|
11
|
+
*
|
|
12
|
+
* @param ids - The chunk IDs to read
|
|
13
|
+
* @param options - Read options
|
|
14
|
+
* @param next - The next layer to process the remaining IDs
|
|
15
|
+
* @returns A promise that resolves to an array of chunks or false values
|
|
16
|
+
*/
|
|
17
|
+
read(ids: DocumentID[], options: ChunkReadOptions, next: (remaining: DocumentID[]) => Promise<(EntryLeaf | false)[]>): Promise<(EntryLeaf | false)[]>;
|
|
18
|
+
tearDown?(): void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Interface for write layers in the chunk writing pipeline.
|
|
22
|
+
* Each layer processes chunk write requests and passes them to the next layer.
|
|
23
|
+
*/
|
|
24
|
+
export interface IWriteLayer {
|
|
25
|
+
/**
|
|
26
|
+
* Process a write request for the given chunks.
|
|
27
|
+
* The next layer in the pipeline should be called to continue processing.
|
|
28
|
+
*
|
|
29
|
+
* @param chunks - The chunks to write
|
|
30
|
+
* @param options - Write options
|
|
31
|
+
* @param origin - The origin of the write request
|
|
32
|
+
* @param next - The next layer to process the remaining chunks
|
|
33
|
+
* @returns A promise that resolves to the write result
|
|
34
|
+
*/
|
|
35
|
+
write(chunks: EntryLeaf[], options: ChunkWriteOptions, origin: DocumentID, next: (remaining: EntryLeaf[]) => Promise<WriteResult>): Promise<WriteResult>;
|
|
36
|
+
tearDown?(): void;
|
|
37
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EntryLeaf, DocumentID, EntryDoc } from "../../common/types.js";
|
|
2
|
+
import type { IReadLayer } from "./ChunkLayerInterfaces.js";
|
|
3
|
+
import type { ChunkReadOptions } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Database read layer - reads chunks from the database
|
|
6
|
+
*/
|
|
7
|
+
export declare class DatabaseReadLayer implements IReadLayer {
|
|
8
|
+
private database;
|
|
9
|
+
constructor(database: PouchDB.Database<EntryDoc>);
|
|
10
|
+
private isChunkDoc;
|
|
11
|
+
private getError;
|
|
12
|
+
private isMissingError;
|
|
13
|
+
read(ids: DocumentID[], options: ChunkReadOptions, next: (remaining: DocumentID[]) => Promise<(EntryLeaf | false)[]>): Promise<(EntryLeaf | false)[]>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Logger, LOG_LEVEL_VERBOSE } from "octagonal-wheels/common/logger";
|
|
2
|
+
import { LiveSyncError } from "../../common/LSError.js";
|
|
3
|
+
class DatabaseReadLayer {
|
|
4
|
+
constructor(database) {
|
|
5
|
+
this.database = database;
|
|
6
|
+
}
|
|
7
|
+
database;
|
|
8
|
+
isChunkDoc(doc) {
|
|
9
|
+
return doc && typeof doc._id === "string" && doc.type === "leaf";
|
|
10
|
+
}
|
|
11
|
+
getError(error) {
|
|
12
|
+
if (error instanceof Error) {
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
if (typeof error === "object" && error !== null && "error" in error && error.error instanceof Error) {
|
|
16
|
+
return error.error;
|
|
17
|
+
}
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
isMissingError(error) {
|
|
21
|
+
if (typeof error !== "object" || error === null) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if ("status" in error && error.status === 404) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if ("error" in error && error.error === "not_found") {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if ("error" in error) {
|
|
31
|
+
return this.isMissingError(error.error);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
async read(ids, options, next) {
|
|
36
|
+
if (ids.length === 0) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const resultMap = /* @__PURE__ */ new Map();
|
|
40
|
+
const remainingIds = [];
|
|
41
|
+
try {
|
|
42
|
+
const results = await this.database.allDocs({ keys: ids, include_docs: true });
|
|
43
|
+
for (const row of results.rows) {
|
|
44
|
+
if ("doc" in row && row.doc && this.isChunkDoc(row.doc)) {
|
|
45
|
+
const chunk = row.doc;
|
|
46
|
+
resultMap.set(chunk._id, chunk);
|
|
47
|
+
} else if (!this.isMissingError(row)) {
|
|
48
|
+
throw new LiveSyncError(`Failed to read chunk ${row.key}`, {
|
|
49
|
+
status: 404,
|
|
50
|
+
cause: this.getError(row)
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
const idFromRow = typeof row.key === "string" ? row.key : void 0;
|
|
54
|
+
if (idFromRow) {
|
|
55
|
+
remainingIds.push(idFromRow);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error instanceof LiveSyncError) {
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
Logger(`Database read error!`, LOG_LEVEL_VERBOSE);
|
|
64
|
+
Logger(error, LOG_LEVEL_VERBOSE);
|
|
65
|
+
return ids.map(() => false);
|
|
66
|
+
}
|
|
67
|
+
if (remainingIds.length === 0) {
|
|
68
|
+
return ids.map((id) => resultMap.get(id) ?? false);
|
|
69
|
+
}
|
|
70
|
+
const nextResults = await next(remainingIds);
|
|
71
|
+
const nextResultMap = new Map(remainingIds.map((id, index) => [id, nextResults[index]]));
|
|
72
|
+
const mergedResults = [...ids.map((id) => resultMap.get(id) ?? nextResultMap.get(id) ?? false)];
|
|
73
|
+
return mergedResults;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
DatabaseReadLayer
|
|
78
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EntryLeaf, DocumentID, EntryDoc } from "../../common/types.js";
|
|
2
|
+
import type { IWriteLayer } from "./ChunkLayerInterfaces.js";
|
|
3
|
+
import type { ChunkWriteOptions, WriteResult } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Database write layer - writes chunks to the database
|
|
6
|
+
*/
|
|
7
|
+
export declare class DatabaseWriteLayer implements IWriteLayer {
|
|
8
|
+
private database;
|
|
9
|
+
constructor(database: PouchDB.Database<EntryDoc>);
|
|
10
|
+
write(chunks: EntryLeaf[], options: ChunkWriteOptions | undefined, origin: DocumentID, next: (remaining: EntryLeaf[]) => Promise<WriteResult>): Promise<WriteResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LiveSyncError } from "../../common/LSError.js";
|
|
2
|
+
class DatabaseWriteLayer {
|
|
3
|
+
constructor(database) {
|
|
4
|
+
this.database = database;
|
|
5
|
+
}
|
|
6
|
+
database;
|
|
7
|
+
async write(chunks, options = void 0, origin, next) {
|
|
8
|
+
if (chunks.length === 0) {
|
|
9
|
+
return next([]);
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const result = await this.database.bulkDocs(chunks, { new_edits: !options?.force });
|
|
13
|
+
const failed = result.filter((res) => "error" in res);
|
|
14
|
+
if (failed.some((res) => res.status !== 409)) {
|
|
15
|
+
throw new LiveSyncError(`Failed to write chunks: ${failed.map((res) => res.error).join(", ")}`, {
|
|
16
|
+
status: 500
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const conflictedChunkIDs = failed.filter((res) => typeof res.id === "string").map((res) => res.id);
|
|
20
|
+
const nextResult = await next(chunks);
|
|
21
|
+
const writeResult = {
|
|
22
|
+
result: true,
|
|
23
|
+
processed: {
|
|
24
|
+
cached: nextResult.processed.cached,
|
|
25
|
+
hotPack: nextResult.processed.hotPack,
|
|
26
|
+
written: result.length - failed.length,
|
|
27
|
+
duplicated: conflictedChunkIDs.length
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
if (conflictedChunkIDs.length > 0) {
|
|
31
|
+
}
|
|
32
|
+
return writeResult;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof LiveSyncError) {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
throw new LiveSyncError(`Database write layer error!`, { status: 500, cause: error });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
DatabaseWriteLayer
|
|
43
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EntryLeaf, DocumentID } from "../../common/types.js";
|
|
2
|
+
import type { IWriteLayer } from "./ChunkLayerInterfaces.js";
|
|
3
|
+
import type { ChunkWriteOptions, WriteResult } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Hot pack layer - placeholder for hot pack processing
|
|
6
|
+
*/
|
|
7
|
+
export declare class HotPackLayer implements IWriteLayer {
|
|
8
|
+
write(chunks: EntryLeaf[], options: ChunkWriteOptions, origin: DocumentID, next: (remaining: EntryLeaf[]) => Promise<WriteResult>): Promise<WriteResult>;
|
|
9
|
+
}
|