@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,95 @@
|
|
|
1
|
+
import type { JsonLike } from "../../rpc/index.js";
|
|
2
|
+
import type { P2PSyncSetting, EntryDoc } from "../../common/types.js";
|
|
3
|
+
import type { SimpleStore } from "../../common/utils.js";
|
|
4
|
+
import type { Confirm } from "../../interfaces/Confirm.js";
|
|
5
|
+
import type { AsyncActivityRunner } from "../../interfaces/AsyncActivityRunner.js";
|
|
6
|
+
import type { LiveSyncEventHub } from "../../hub/hub.js";
|
|
7
|
+
import type { MessageTranslator } from "../../services/base/MessageTranslator.js";
|
|
8
|
+
export declare const DIRECTION_REQUEST = "request";
|
|
9
|
+
export type DIRECTION_REQUEST = typeof DIRECTION_REQUEST;
|
|
10
|
+
export declare const DIRECTION_RESPONSE = "response";
|
|
11
|
+
export type DIRECTION_RESPONSE = typeof DIRECTION_RESPONSE;
|
|
12
|
+
export declare const DEFAULT_RPC_TIMEOUT = 30000;
|
|
13
|
+
export declare const BULK_GET_RPC_TIMEOUT = 40000;
|
|
14
|
+
export type BindableFunction = (...args: any[]) => any;
|
|
15
|
+
export type NonPrivateMethodKeys<T> = {
|
|
16
|
+
[K in keyof T]: K extends `_${string}` ? never : K extends `constructor` ? never : T[K] extends BindableFunction ? K : never;
|
|
17
|
+
}[keyof T];
|
|
18
|
+
export type BindableObject<T = any> = {
|
|
19
|
+
[k in NonPrivateMethodKeys<T>]: T[k] extends BindableFunction ? T[k] : never;
|
|
20
|
+
};
|
|
21
|
+
export type ConnectionInfo = {
|
|
22
|
+
relayURIs: string[];
|
|
23
|
+
roomId: string;
|
|
24
|
+
password: string;
|
|
25
|
+
appId: string;
|
|
26
|
+
};
|
|
27
|
+
export declare class ResponsePreventedError extends Error {
|
|
28
|
+
constructor(message: string);
|
|
29
|
+
}
|
|
30
|
+
export type Request<T = JsonLike[]> = {
|
|
31
|
+
type: string;
|
|
32
|
+
direction: DIRECTION_REQUEST;
|
|
33
|
+
seq: number;
|
|
34
|
+
args: T;
|
|
35
|
+
};
|
|
36
|
+
export type Response<T = JsonLike> = {
|
|
37
|
+
type: string;
|
|
38
|
+
direction: DIRECTION_RESPONSE;
|
|
39
|
+
seq: number;
|
|
40
|
+
data?: T;
|
|
41
|
+
error?: JsonLike;
|
|
42
|
+
};
|
|
43
|
+
export type DeviceInfo = {
|
|
44
|
+
currentPeerId: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
version?: string;
|
|
47
|
+
platform?: string;
|
|
48
|
+
decision?: DeviceDecisions;
|
|
49
|
+
};
|
|
50
|
+
export type DeviceInfoForRequest = {
|
|
51
|
+
currentPeerId: string;
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
export type FullFilledDeviceInfo = {
|
|
55
|
+
currentPeerId: string;
|
|
56
|
+
name: string;
|
|
57
|
+
version: string;
|
|
58
|
+
platform: string;
|
|
59
|
+
decision?: DeviceDecisions;
|
|
60
|
+
};
|
|
61
|
+
export declare enum DeviceDecisions {
|
|
62
|
+
ACCEPT = "accepted",
|
|
63
|
+
REJECT = "rejected",
|
|
64
|
+
IGNORE = "ignore"
|
|
65
|
+
}
|
|
66
|
+
export declare const ID_P2PKnownDevices = "_local/P2PKnownDevices";
|
|
67
|
+
export type KnownDevices = {
|
|
68
|
+
_id: typeof ID_P2PKnownDevices;
|
|
69
|
+
devices: {
|
|
70
|
+
[deviceName: string]: DeviceDecisions;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export type Payload = Request | Response;
|
|
74
|
+
export interface ReplicatorHost {
|
|
75
|
+
deviceName: string;
|
|
76
|
+
platform: string;
|
|
77
|
+
confirm: Confirm;
|
|
78
|
+
}
|
|
79
|
+
export interface ReplicatorHostEnv extends ReplicatorHost {
|
|
80
|
+
/** Event channel owned by the containing Commonlib service composition. */
|
|
81
|
+
events: LiveSyncEventHub;
|
|
82
|
+
/** Message translation owned by the containing Commonlib service composition. */
|
|
83
|
+
translate: MessageTranslator;
|
|
84
|
+
settings: P2PSyncSetting;
|
|
85
|
+
db: PouchDB.Database<EntryDoc>;
|
|
86
|
+
simpleStore: SimpleStore<unknown>;
|
|
87
|
+
runFiniteReplicationActivity?: AsyncActivityRunner["run"];
|
|
88
|
+
processReplicatedDocs(docs: Array<PouchDB.Core.ExistingDocument<EntryDoc>>): void | Promise<void>;
|
|
89
|
+
}
|
|
90
|
+
export type Advertisement = {
|
|
91
|
+
peerId: string;
|
|
92
|
+
name: string;
|
|
93
|
+
platform: string;
|
|
94
|
+
};
|
|
95
|
+
export declare const KEY_DEVICE_DECISIONS = "p2p-device-decisions";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const DIRECTION_REQUEST = "request";
|
|
2
|
+
const DIRECTION_RESPONSE = "response";
|
|
3
|
+
const DEFAULT_RPC_TIMEOUT = 3e4;
|
|
4
|
+
const BULK_GET_RPC_TIMEOUT = 4e4;
|
|
5
|
+
class ResponsePreventedError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`Response prevented: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var DeviceDecisions = /* @__PURE__ */ ((DeviceDecisions2) => {
|
|
11
|
+
DeviceDecisions2["ACCEPT"] = "accepted";
|
|
12
|
+
DeviceDecisions2["REJECT"] = "rejected";
|
|
13
|
+
DeviceDecisions2["IGNORE"] = "ignore";
|
|
14
|
+
return DeviceDecisions2;
|
|
15
|
+
})(DeviceDecisions || {});
|
|
16
|
+
const ID_P2PKnownDevices = "_local/P2PKnownDevices";
|
|
17
|
+
const KEY_DEVICE_DECISIONS = "p2p-device-decisions";
|
|
18
|
+
export {
|
|
19
|
+
BULK_GET_RPC_TIMEOUT,
|
|
20
|
+
DEFAULT_RPC_TIMEOUT,
|
|
21
|
+
DIRECTION_REQUEST,
|
|
22
|
+
DIRECTION_RESPONSE,
|
|
23
|
+
DeviceDecisions,
|
|
24
|
+
ID_P2PKnownDevices,
|
|
25
|
+
KEY_DEVICE_DECISIONS,
|
|
26
|
+
ResponsePreventedError
|
|
27
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { NecessaryServices } from "../../interfaces/ServiceModule.js";
|
|
2
|
+
import type { UseP2PReplicatorResult } from "./UseP2PReplicatorResult.js";
|
|
3
|
+
/**
|
|
4
|
+
* ServiceFeature: Registers event handlers for P2P replication and manages the lifecycle of a LiveSyncTrysteroReplicator instance.
|
|
5
|
+
* @param host
|
|
6
|
+
*/
|
|
7
|
+
export declare function useP2PReplicatorCommands(host: NecessaryServices<"API" | "setting", never>, { replicator }: UseP2PReplicatorResult): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Logger, LOG_LEVEL_NOTICE } from "octagonal-wheels/common/logger";
|
|
2
|
+
function useP2PReplicatorCommands(host, { replicator }) {
|
|
3
|
+
host.services.API.addCommand({
|
|
4
|
+
id: "p2p-establish-connection",
|
|
5
|
+
name: "P2P Sync : Connect to the Signalling Server",
|
|
6
|
+
checkCallback: (isChecking) => {
|
|
7
|
+
if (!replicator) return false;
|
|
8
|
+
if (isChecking) return !(replicator.server?.isServing ?? false);
|
|
9
|
+
void replicator.open();
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
host.services.API.addCommand({
|
|
13
|
+
id: "p2p-close-connection",
|
|
14
|
+
name: "P2P Sync : Disconnect from the Signalling Server",
|
|
15
|
+
checkCallback: (isChecking) => {
|
|
16
|
+
if (!replicator) return false;
|
|
17
|
+
if (isChecking) return replicator.server?.isServing ?? false;
|
|
18
|
+
Logger("Closing P2P Connection", LOG_LEVEL_NOTICE);
|
|
19
|
+
void replicator.close();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
useP2PReplicatorCommands
|
|
25
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NecessaryServices } from "../../interfaces/ServiceModule.js";
|
|
2
|
+
import { LiveSyncTrysteroReplicator } from "./LiveSyncTrysteroReplicator.js";
|
|
3
|
+
import { type UseP2PReplicatorResult } from "./UseP2PReplicatorResult.js";
|
|
4
|
+
/**
|
|
5
|
+
* Factory type: given a replicator instance, returns the openReplicationUI callback for that instance.
|
|
6
|
+
* Injected by the host platform (e.g. Obsidian). CLI/headless environments omit this.
|
|
7
|
+
*/
|
|
8
|
+
export type OpenReplicationUIFactory = (replicator: LiveSyncTrysteroReplicator) => (showResult: boolean) => Promise<boolean | void>;
|
|
9
|
+
/** Same shape as OpenReplicationUIFactory, used for the rebuild/replicateAllFromServer flow. */
|
|
10
|
+
export type OpenRebuildUIFactory = OpenReplicationUIFactory;
|
|
11
|
+
/**
|
|
12
|
+
* ServiceFeature: P2P Replicator integration and lifecycle management.
|
|
13
|
+
* Registers a LiveSyncTrysteroReplicator instance as the active replicator when P2P is enabled in settings,
|
|
14
|
+
* and binds it to lifecycle events for proper initialization and cleanup.
|
|
15
|
+
* @param host
|
|
16
|
+
*/
|
|
17
|
+
export declare function useP2PReplicatorFeature(host: NecessaryServices<"API" | "appLifecycle" | "setting" | "vault" | "database" | "databaseEvents" | "keyValueDB" | "replication" | "config" | "UI" | "replicator" | "remote", never>, openReplicationUIFactory?: OpenReplicationUIFactory, openRebuildUIFactory?: OpenRebuildUIFactory): UseP2PReplicatorResult;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Logger, LOG_LEVEL_VERBOSE } from "octagonal-wheels/common/logger";
|
|
2
|
+
import { AutoAccepting, REMOTE_P2P } from "../../common/types.js";
|
|
3
|
+
import { LiveSyncTrysteroReplicator } from "./LiveSyncTrysteroReplicator.js";
|
|
4
|
+
import {} from "./UseP2PReplicatorResult.js";
|
|
5
|
+
import { addP2PEventHandlers } from "./addP2PEventHandlers.js";
|
|
6
|
+
import { compatGlobal } from "../../common/coreEnvFunctions.js";
|
|
7
|
+
function useP2PReplicatorFeature(host, openReplicationUIFactory, openRebuildUIFactory) {
|
|
8
|
+
let replicator = new LiveSyncTrysteroReplicator({
|
|
9
|
+
services: host.services
|
|
10
|
+
});
|
|
11
|
+
if (openReplicationUIFactory) {
|
|
12
|
+
replicator.env.openReplicationUI = openReplicationUIFactory(replicator);
|
|
13
|
+
}
|
|
14
|
+
if (openRebuildUIFactory) {
|
|
15
|
+
replicator.env.openRebuildUI = openRebuildUIFactory(replicator);
|
|
16
|
+
}
|
|
17
|
+
const activeReplicator = {
|
|
18
|
+
get replicator() {
|
|
19
|
+
return replicator;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
addP2PEventHandlers(activeReplicator.replicator, host.services.context.events);
|
|
23
|
+
host.services.replicator.getNewReplicator.addHandler(
|
|
24
|
+
async (settingOverride = {}) => {
|
|
25
|
+
const settings = { ...host.services.setting.currentSettings(), ...settingOverride };
|
|
26
|
+
if (settings.remoteType == REMOTE_P2P) {
|
|
27
|
+
const existingReplicator = replicator;
|
|
28
|
+
try {
|
|
29
|
+
await existingReplicator?.close();
|
|
30
|
+
} catch (e) {
|
|
31
|
+
Logger(`Error closing existing p2p replicator`);
|
|
32
|
+
Logger(e, LOG_LEVEL_VERBOSE);
|
|
33
|
+
}
|
|
34
|
+
const newReplicator = new LiveSyncTrysteroReplicator({ services: host.services });
|
|
35
|
+
if (openReplicationUIFactory) {
|
|
36
|
+
newReplicator.env.openReplicationUI = openReplicationUIFactory(newReplicator);
|
|
37
|
+
}
|
|
38
|
+
if (openRebuildUIFactory) {
|
|
39
|
+
newReplicator.env.openRebuildUI = openRebuildUIFactory(newReplicator);
|
|
40
|
+
}
|
|
41
|
+
replicator = newReplicator;
|
|
42
|
+
return replicator;
|
|
43
|
+
}
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
host.services.appLifecycle.onUnload.addHandler(async () => {
|
|
48
|
+
await replicator?.close();
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
host.services.appLifecycle.onSuspending.addHandler(async () => {
|
|
52
|
+
await replicator?.close();
|
|
53
|
+
return true;
|
|
54
|
+
});
|
|
55
|
+
host.services.databaseEvents.onDatabaseInitialisation.addHandler(async () => {
|
|
56
|
+
await replicator?.close();
|
|
57
|
+
return true;
|
|
58
|
+
});
|
|
59
|
+
host.services.appLifecycle.onResumed.addHandler(() => {
|
|
60
|
+
const settings = host.services.setting.currentSettings();
|
|
61
|
+
if (settings.P2P_Enabled && settings.P2P_AutoStart) {
|
|
62
|
+
compatGlobal.setTimeout(() => void replicator?.open(), 100);
|
|
63
|
+
}
|
|
64
|
+
return Promise.resolve(true);
|
|
65
|
+
});
|
|
66
|
+
host.services.setting.suspendExtraSync.addHandler(() => {
|
|
67
|
+
const s = host.services.setting.currentSettings();
|
|
68
|
+
if (s.remoteType !== REMOTE_P2P) {
|
|
69
|
+
s.P2P_Enabled = false;
|
|
70
|
+
}
|
|
71
|
+
s.P2P_AutoAccepting = AutoAccepting.NONE;
|
|
72
|
+
s.P2P_AutoBroadcast = false;
|
|
73
|
+
s.P2P_AutoStart = false;
|
|
74
|
+
s.P2P_AutoSyncPeers = "";
|
|
75
|
+
s.P2P_AutoWatchPeers = "";
|
|
76
|
+
return Promise.resolve(true);
|
|
77
|
+
});
|
|
78
|
+
return activeReplicator;
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
useP2PReplicatorFeature
|
|
82
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RpcSession } from "./RpcSession.js";
|
|
2
|
+
import { type JsonLike, type RpcMethodHandler, type RpcRegisterOptions, type RpcRoomOptions } from "./types.js";
|
|
3
|
+
export declare class RpcRoom {
|
|
4
|
+
private options;
|
|
5
|
+
private pending;
|
|
6
|
+
private inboundCalls;
|
|
7
|
+
private methods;
|
|
8
|
+
private sessions;
|
|
9
|
+
private outgoingChunkMap;
|
|
10
|
+
private incomingChunkMap;
|
|
11
|
+
private incomingChunkTimers;
|
|
12
|
+
private peerVersion;
|
|
13
|
+
private disposer;
|
|
14
|
+
constructor(options: RpcRoomOptions);
|
|
15
|
+
close(): void;
|
|
16
|
+
session(peerId: string): RpcSession;
|
|
17
|
+
register<T extends JsonLike[], U>(method: string, handler: RpcMethodHandler<T, U>, options?: RpcRegisterOptions): void;
|
|
18
|
+
invoke(peerId: string, method: string, args: JsonLike[], timeoutMs?: number): Promise<JsonLike>;
|
|
19
|
+
cancel(peerId: string, requestId: string): Promise<void>;
|
|
20
|
+
private sendEnvelope;
|
|
21
|
+
private scheduleMissingAck;
|
|
22
|
+
private onWireMessage;
|
|
23
|
+
private onEnvelopePayload;
|
|
24
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { compatGlobal } from "../common/coreEnvFunctions.js";
|
|
2
|
+
import { IncomingChunkBuffer, estimateBytes, splitIntoChunks } from "./chunking.js";
|
|
3
|
+
import { asRpcErrorShape, RpcError } from "./errors.js";
|
|
4
|
+
import { RpcSession } from "./RpcSession.js";
|
|
5
|
+
import {
|
|
6
|
+
RPC_VERSION_MAJOR,
|
|
7
|
+
RPC_VERSION_MINOR
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
function newId(prefix) {
|
|
10
|
+
return `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
11
|
+
}
|
|
12
|
+
function validNamespacedMethod(method) {
|
|
13
|
+
return method.includes(".") || method.includes("/");
|
|
14
|
+
}
|
|
15
|
+
class RpcRoom {
|
|
16
|
+
options;
|
|
17
|
+
pending = /* @__PURE__ */ new Map();
|
|
18
|
+
inboundCalls = /* @__PURE__ */ new Map();
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- This is a generic type for method handlers, so we can't be more specific about the types here.
|
|
20
|
+
methods = /* @__PURE__ */ new Map();
|
|
21
|
+
sessions = /* @__PURE__ */ new Map();
|
|
22
|
+
outgoingChunkMap = /* @__PURE__ */ new Map();
|
|
23
|
+
incomingChunkMap = /* @__PURE__ */ new Map();
|
|
24
|
+
incomingChunkTimers = /* @__PURE__ */ new Map();
|
|
25
|
+
peerVersion = /* @__PURE__ */ new Map();
|
|
26
|
+
disposer;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.options = {
|
|
29
|
+
maxWirePayloadBytes: options.maxWirePayloadBytes ?? 32 * 1024,
|
|
30
|
+
chunkMissingRetryMs: options.chunkMissingRetryMs ?? 350,
|
|
31
|
+
...options
|
|
32
|
+
};
|
|
33
|
+
this.disposer = this.options.transport.onMessage((msg, peerId) => {
|
|
34
|
+
void this.onWireMessage(msg, peerId);
|
|
35
|
+
});
|
|
36
|
+
if (this.options.transport.onPeerJoin) {
|
|
37
|
+
this.options.transport.onPeerJoin((peerId) => {
|
|
38
|
+
void this.sendEnvelope(peerId, {
|
|
39
|
+
kind: "handshake",
|
|
40
|
+
versionMajor: RPC_VERSION_MAJOR,
|
|
41
|
+
versionMinor: RPC_VERSION_MINOR
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (this.options.transport.onPeerLeave) {
|
|
46
|
+
this.options.transport.onPeerLeave((peerId) => {
|
|
47
|
+
this.sessions.delete(peerId);
|
|
48
|
+
this.peerVersion.delete(peerId);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
close() {
|
|
53
|
+
this.disposer?.();
|
|
54
|
+
this.pending.forEach((pending) => pending.reject(new RpcError("NOT_CONNECTED", "Room closed")));
|
|
55
|
+
this.pending.clear();
|
|
56
|
+
this.inboundCalls.clear();
|
|
57
|
+
this.methods.clear();
|
|
58
|
+
this.sessions.clear();
|
|
59
|
+
this.outgoingChunkMap.clear();
|
|
60
|
+
this.incomingChunkMap.clear();
|
|
61
|
+
this.incomingChunkTimers.forEach((h) => compatGlobal.clearTimeout(h));
|
|
62
|
+
this.incomingChunkTimers.clear();
|
|
63
|
+
}
|
|
64
|
+
session(peerId) {
|
|
65
|
+
const existing = this.sessions.get(peerId);
|
|
66
|
+
if (existing) return existing;
|
|
67
|
+
const s = new RpcSession(this, peerId);
|
|
68
|
+
this.sessions.set(peerId, s);
|
|
69
|
+
return s;
|
|
70
|
+
}
|
|
71
|
+
register(method, handler, options = {}) {
|
|
72
|
+
if (!validNamespacedMethod(method)) {
|
|
73
|
+
throw new RpcError("PROTOCOL_ERROR", `Method must be namespaced: ${method}`);
|
|
74
|
+
}
|
|
75
|
+
this.methods.set(method, {
|
|
76
|
+
handler,
|
|
77
|
+
serial: options.serial ?? false,
|
|
78
|
+
queue: Promise.resolve()
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async invoke(peerId, method, args, timeoutMs = 3e4) {
|
|
82
|
+
if (!validNamespacedMethod(method)) {
|
|
83
|
+
throw new RpcError("PROTOCOL_ERROR", `Method must be namespaced: ${method}`);
|
|
84
|
+
}
|
|
85
|
+
const requestId = newId("req");
|
|
86
|
+
const p = new Promise((resolve, reject) => {
|
|
87
|
+
const pending = { resolve, reject };
|
|
88
|
+
if (timeoutMs > 0) {
|
|
89
|
+
pending.timeoutHandle = compatGlobal.setTimeout(() => {
|
|
90
|
+
this.pending.delete(requestId);
|
|
91
|
+
reject(new RpcError("TIMEOUT", `RPC timed out: ${method}`));
|
|
92
|
+
}, timeoutMs);
|
|
93
|
+
}
|
|
94
|
+
this.pending.set(requestId, pending);
|
|
95
|
+
});
|
|
96
|
+
await this.sendEnvelope(peerId, {
|
|
97
|
+
kind: "request",
|
|
98
|
+
requestId,
|
|
99
|
+
method,
|
|
100
|
+
args
|
|
101
|
+
});
|
|
102
|
+
return await p;
|
|
103
|
+
}
|
|
104
|
+
async cancel(peerId, requestId) {
|
|
105
|
+
await this.sendEnvelope(peerId, {
|
|
106
|
+
kind: "cancel",
|
|
107
|
+
requestId
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async sendEnvelope(peerId, envelope) {
|
|
111
|
+
const serialized = JSON.stringify(envelope);
|
|
112
|
+
if (estimateBytes(serialized) <= this.options.maxWirePayloadBytes) {
|
|
113
|
+
await this.options.transport.send({ wire: "raw", payload: serialized }, peerId);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const streamId = newId("stream");
|
|
117
|
+
const chunks = splitIntoChunks(serialized, this.options.maxWirePayloadBytes);
|
|
118
|
+
this.outgoingChunkMap.set(streamId, { peerId, chunks });
|
|
119
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
120
|
+
await this.options.transport.send(
|
|
121
|
+
{
|
|
122
|
+
wire: "chunk",
|
|
123
|
+
streamId,
|
|
124
|
+
index: i,
|
|
125
|
+
total: chunks.length,
|
|
126
|
+
payload: chunks[i]
|
|
127
|
+
},
|
|
128
|
+
peerId
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
scheduleMissingAck(streamId, peerId) {
|
|
133
|
+
const existing = this.incomingChunkTimers.get(streamId);
|
|
134
|
+
if (existing) compatGlobal.clearTimeout(existing);
|
|
135
|
+
const handle = compatGlobal.setTimeout(() => {
|
|
136
|
+
const state = this.incomingChunkMap.get(streamId);
|
|
137
|
+
if (!state || state.isComplete()) return;
|
|
138
|
+
const missing = state.missingIndices();
|
|
139
|
+
void this.options.transport.send({ wire: "chunk-ack", streamId, missing }, peerId);
|
|
140
|
+
}, this.options.chunkMissingRetryMs);
|
|
141
|
+
this.incomingChunkTimers.set(streamId, handle);
|
|
142
|
+
}
|
|
143
|
+
async onWireMessage(message, peerId) {
|
|
144
|
+
if (message.wire === "raw") {
|
|
145
|
+
await this.onEnvelopePayload(message.payload, peerId);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (message.wire === "chunk") {
|
|
149
|
+
let state2 = this.incomingChunkMap.get(message.streamId);
|
|
150
|
+
if (!state2) {
|
|
151
|
+
state2 = new IncomingChunkBuffer(message.total);
|
|
152
|
+
this.incomingChunkMap.set(message.streamId, state2);
|
|
153
|
+
}
|
|
154
|
+
state2.add(message.index, message.payload);
|
|
155
|
+
this.scheduleMissingAck(message.streamId, peerId);
|
|
156
|
+
if (state2.isComplete()) {
|
|
157
|
+
const timer = this.incomingChunkTimers.get(message.streamId);
|
|
158
|
+
if (timer) compatGlobal.clearTimeout(timer);
|
|
159
|
+
this.incomingChunkTimers.delete(message.streamId);
|
|
160
|
+
this.incomingChunkMap.delete(message.streamId);
|
|
161
|
+
await this.options.transport.send(
|
|
162
|
+
{ wire: "chunk-ack", streamId: message.streamId, missing: [] },
|
|
163
|
+
peerId
|
|
164
|
+
);
|
|
165
|
+
await this.onEnvelopePayload(state2.toPayload(), peerId);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const state = this.outgoingChunkMap.get(message.streamId);
|
|
170
|
+
if (!state) return;
|
|
171
|
+
if (message.missing.length === 0) {
|
|
172
|
+
this.outgoingChunkMap.delete(message.streamId);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
for (const index of message.missing) {
|
|
176
|
+
const payload = state.chunks[index];
|
|
177
|
+
if (payload === void 0) continue;
|
|
178
|
+
await this.options.transport.send(
|
|
179
|
+
{
|
|
180
|
+
wire: "chunk",
|
|
181
|
+
streamId: message.streamId,
|
|
182
|
+
index,
|
|
183
|
+
total: state.chunks.length,
|
|
184
|
+
payload
|
|
185
|
+
},
|
|
186
|
+
state.peerId
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async onEnvelopePayload(payload, peerId) {
|
|
191
|
+
let envelope;
|
|
192
|
+
try {
|
|
193
|
+
envelope = JSON.parse(payload);
|
|
194
|
+
} catch (ex) {
|
|
195
|
+
this.options.onProtocolWarning?.("Invalid payload", peerId);
|
|
196
|
+
this.options.onProtocolWarning?.(String(ex), peerId);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (envelope.kind === "handshake") {
|
|
200
|
+
this.peerVersion.set(peerId, { major: envelope.versionMajor, minor: envelope.versionMinor });
|
|
201
|
+
if (envelope.versionMajor !== RPC_VERSION_MAJOR) {
|
|
202
|
+
this.options.onProtocolWarning?.(
|
|
203
|
+
`RPC major mismatch: local=${RPC_VERSION_MAJOR}, remote=${envelope.versionMajor}`,
|
|
204
|
+
peerId
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (envelope.kind === "cancel") {
|
|
210
|
+
const ctx2 = this.inboundCalls.get(envelope.requestId);
|
|
211
|
+
if (ctx2) ctx2.cancelled = true;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (envelope.kind === "response") {
|
|
215
|
+
const pending = this.pending.get(envelope.requestId);
|
|
216
|
+
if (!pending) return;
|
|
217
|
+
this.pending.delete(envelope.requestId);
|
|
218
|
+
if (pending.timeoutHandle) compatGlobal.clearTimeout(pending.timeoutHandle);
|
|
219
|
+
if (envelope.ok === true) {
|
|
220
|
+
pending.resolve(envelope.data);
|
|
221
|
+
} else {
|
|
222
|
+
pending.reject(new RpcError(envelope.error.code, envelope.error.message, envelope.error.details));
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const accepted = await this.options.canAcceptRequest?.(peerId, envelope.method);
|
|
227
|
+
if (accepted === false) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const version = this.peerVersion.get(peerId);
|
|
231
|
+
if (version && version.major !== RPC_VERSION_MAJOR) {
|
|
232
|
+
await this.sendEnvelope(peerId, {
|
|
233
|
+
kind: "response",
|
|
234
|
+
requestId: envelope.requestId,
|
|
235
|
+
ok: false,
|
|
236
|
+
error: {
|
|
237
|
+
code: "REMOTE_ERROR",
|
|
238
|
+
message: `RPC major mismatch: local=${RPC_VERSION_MAJOR}, remote=${version.major}`
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (version && version.minor !== RPC_VERSION_MINOR) {
|
|
244
|
+
this.options.onProtocolWarning?.(
|
|
245
|
+
`RPC minor mismatch: local=${RPC_VERSION_MINOR}, remote=${version.minor}`,
|
|
246
|
+
peerId
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
const method = this.methods.get(envelope.method);
|
|
250
|
+
if (!method) {
|
|
251
|
+
await this.sendEnvelope(peerId, {
|
|
252
|
+
kind: "response",
|
|
253
|
+
requestId: envelope.requestId,
|
|
254
|
+
ok: false,
|
|
255
|
+
error: {
|
|
256
|
+
code: "REMOTE_ERROR",
|
|
257
|
+
message: `Method not found: ${envelope.method}`
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const ctx = { cancelled: false };
|
|
263
|
+
this.inboundCalls.set(envelope.requestId, ctx);
|
|
264
|
+
const runner = async () => {
|
|
265
|
+
try {
|
|
266
|
+
if (ctx.cancelled) {
|
|
267
|
+
throw new RpcError("CANCELLED", "Invocation cancelled");
|
|
268
|
+
}
|
|
269
|
+
const data = await method.handler(peerId, ...envelope.args);
|
|
270
|
+
if (ctx.cancelled) {
|
|
271
|
+
throw new RpcError("CANCELLED", "Invocation cancelled");
|
|
272
|
+
}
|
|
273
|
+
await this.sendEnvelope(peerId, {
|
|
274
|
+
kind: "response",
|
|
275
|
+
requestId: envelope.requestId,
|
|
276
|
+
ok: true,
|
|
277
|
+
data
|
|
278
|
+
});
|
|
279
|
+
} catch (ex) {
|
|
280
|
+
await this.sendEnvelope(peerId, {
|
|
281
|
+
kind: "response",
|
|
282
|
+
requestId: envelope.requestId,
|
|
283
|
+
ok: false,
|
|
284
|
+
error: asRpcErrorShape(ex)
|
|
285
|
+
});
|
|
286
|
+
} finally {
|
|
287
|
+
this.inboundCalls.delete(envelope.requestId);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
if (method.serial) {
|
|
291
|
+
method.queue = method.queue.then(runner, runner);
|
|
292
|
+
await method.queue;
|
|
293
|
+
} else {
|
|
294
|
+
await runner();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
export {
|
|
299
|
+
RpcRoom
|
|
300
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JsonLike } from "./types.js";
|
|
2
|
+
import type { RpcRoom } from "./RpcRoom.js";
|
|
3
|
+
export declare class RpcSession {
|
|
4
|
+
readonly peerId: string;
|
|
5
|
+
private room;
|
|
6
|
+
constructor(room: RpcRoom, peerId: string);
|
|
7
|
+
call<T = JsonLike>(method: string, args?: JsonLike[], timeoutMs?: number): Promise<T>;
|
|
8
|
+
createProxy<T extends object>(namespace: string): T;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RpcError } from "./errors.js";
|
|
2
|
+
class RpcSession {
|
|
3
|
+
peerId;
|
|
4
|
+
room;
|
|
5
|
+
constructor(room, peerId) {
|
|
6
|
+
this.room = room;
|
|
7
|
+
this.peerId = peerId;
|
|
8
|
+
}
|
|
9
|
+
async call(method, args = [], timeoutMs) {
|
|
10
|
+
if (!this.peerId) {
|
|
11
|
+
throw new RpcError("NOT_CONNECTED", "Peer is not connected");
|
|
12
|
+
}
|
|
13
|
+
return await this.room.invoke(this.peerId, method, args, timeoutMs);
|
|
14
|
+
}
|
|
15
|
+
createProxy(namespace) {
|
|
16
|
+
const session = this;
|
|
17
|
+
return new Proxy(
|
|
18
|
+
{},
|
|
19
|
+
{
|
|
20
|
+
get(_target, propKey) {
|
|
21
|
+
if (typeof propKey !== "string") return void 0;
|
|
22
|
+
return async (...args) => {
|
|
23
|
+
return await session.call(`${namespace}.${propKey}`, args);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
RpcSession
|
|
32
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function estimateBytes(text: string): number;
|
|
2
|
+
export declare function splitIntoChunks(payload: string, maxBytes: number): string[];
|
|
3
|
+
export declare class IncomingChunkBuffer {
|
|
4
|
+
total: number;
|
|
5
|
+
parts: Map<number, string>;
|
|
6
|
+
constructor(total: number);
|
|
7
|
+
add(index: number, payload: string): void;
|
|
8
|
+
missingIndices(): number[];
|
|
9
|
+
isComplete(): boolean;
|
|
10
|
+
toPayload(): string;
|
|
11
|
+
}
|