@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,306 @@
|
|
|
1
|
+
import { shouldBeIgnored, isPlainText, stripAllPrefixes } from "../string_and_binary/path.js";
|
|
2
|
+
import { LOG_LEVEL_VERBOSE } from "octagonal-wheels/common/logger";
|
|
3
|
+
import { serialized } from "octagonal-wheels/concurrency/lock_v2";
|
|
4
|
+
import { ServiceModuleBase } from "./ServiceModuleBase.js";
|
|
5
|
+
import { EVENT_FILE_SAVED } from "../events/coreEvents.js";
|
|
6
|
+
import { getDatabasePathFromUXFileInfo, getStoragePathFromUXFileInfo, isInternalMetadata } from "../common/typeUtils.js";
|
|
7
|
+
import { createBlob, createTextBlob, determineTypeFromBlob, isDocContentSame, readContent } from "../common/utils.js";
|
|
8
|
+
import { ICHeader } from "../common/models/fileaccess.const.js";
|
|
9
|
+
class ServiceDatabaseFileAccessBase extends ServiceModuleBase {
|
|
10
|
+
events;
|
|
11
|
+
vault;
|
|
12
|
+
storageAccess;
|
|
13
|
+
path;
|
|
14
|
+
database;
|
|
15
|
+
constructor(services) {
|
|
16
|
+
super(services);
|
|
17
|
+
this.events = services.events;
|
|
18
|
+
this.vault = services.vault;
|
|
19
|
+
this.storageAccess = services.storageAccess;
|
|
20
|
+
this.database = services.database;
|
|
21
|
+
this.path = services.path;
|
|
22
|
+
}
|
|
23
|
+
async checkIsTargetFile(file) {
|
|
24
|
+
const path = getStoragePathFromUXFileInfo(file);
|
|
25
|
+
if (!await this.vault.isTargetFile(path)) {
|
|
26
|
+
this._log(`File is not target: ${path}`, LOG_LEVEL_VERBOSE);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (shouldBeIgnored(path)) {
|
|
30
|
+
this._log(`File should be ignored: ${path}`, LOG_LEVEL_VERBOSE);
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
async delete(file, rev) {
|
|
36
|
+
if (!await this.checkIsTargetFile(file)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
const fullPath = getDatabasePathFromUXFileInfo(file);
|
|
40
|
+
try {
|
|
41
|
+
this._log(`deleteDB By path:${fullPath}`);
|
|
42
|
+
return await this.deleteFromDBbyPath(fullPath, rev);
|
|
43
|
+
} catch (ex) {
|
|
44
|
+
this._log(`Failed to delete ${fullPath}`);
|
|
45
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async createChunks(file, force = false, skipCheck) {
|
|
50
|
+
return await this.__store(file, force, skipCheck, true);
|
|
51
|
+
}
|
|
52
|
+
async store(file, force = false, skipCheck) {
|
|
53
|
+
return await this.__store(file, force, skipCheck, false);
|
|
54
|
+
}
|
|
55
|
+
async storeAsConflictedRevision(file, currentRev, skipCheck) {
|
|
56
|
+
const conflictBaseRev = await this.getParentRev(file, currentRev);
|
|
57
|
+
if (!conflictBaseRev) {
|
|
58
|
+
this._log(`Could not find parent revision for ${file.path} (${currentRev})`, LOG_LEVEL_VERBOSE);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return await this.__store(file, true, skipCheck, false, conflictBaseRev);
|
|
62
|
+
}
|
|
63
|
+
async storeContent(path, content) {
|
|
64
|
+
const blob = createTextBlob(content);
|
|
65
|
+
const bytes = (await blob.arrayBuffer()).byteLength;
|
|
66
|
+
const isInternal = path.startsWith(".") ? true : void 0;
|
|
67
|
+
const dummyUXFileInfo = {
|
|
68
|
+
name: path.split("/").pop(),
|
|
69
|
+
path,
|
|
70
|
+
stat: {
|
|
71
|
+
size: bytes,
|
|
72
|
+
ctime: Date.now(),
|
|
73
|
+
mtime: Date.now(),
|
|
74
|
+
type: "file"
|
|
75
|
+
},
|
|
76
|
+
body: blob,
|
|
77
|
+
isInternal
|
|
78
|
+
};
|
|
79
|
+
return await this.__store(dummyUXFileInfo, true, false, false);
|
|
80
|
+
}
|
|
81
|
+
async __store(file, force = false, skipCheck, onlyChunks, conflictBaseRev) {
|
|
82
|
+
if (!skipCheck) {
|
|
83
|
+
if (!await this.checkIsTargetFile(file)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!file) {
|
|
88
|
+
this._log("File seems bad", LOG_LEVEL_VERBOSE);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const isPlain = isPlainText(file.name);
|
|
92
|
+
const possiblyLarge = !isPlain;
|
|
93
|
+
const content = file.body;
|
|
94
|
+
const datatype = determineTypeFromBlob(content);
|
|
95
|
+
const idPrefix = file.isInternal ? ICHeader : "";
|
|
96
|
+
const fullPath = getStoragePathFromUXFileInfo(file);
|
|
97
|
+
const fullPathOnDB = getDatabasePathFromUXFileInfo(file);
|
|
98
|
+
if (possiblyLarge) this._log(`Processing: ${fullPath}`, LOG_LEVEL_VERBOSE);
|
|
99
|
+
if (file.isInternal) {
|
|
100
|
+
if (file.deleted) {
|
|
101
|
+
file.stat = {
|
|
102
|
+
size: 0,
|
|
103
|
+
ctime: Date.now(),
|
|
104
|
+
mtime: Date.now(),
|
|
105
|
+
type: "file"
|
|
106
|
+
};
|
|
107
|
+
} else if (file.stat == void 0) {
|
|
108
|
+
const stat = await this.storageAccess.statHidden(file.path);
|
|
109
|
+
if (!stat) {
|
|
110
|
+
this._log(`Internal file not found: ${fullPath}`, LOG_LEVEL_VERBOSE);
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
file.stat = stat;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const idMain = await this.path.path2id(fullPath);
|
|
117
|
+
const id = idPrefix + idMain;
|
|
118
|
+
const d = {
|
|
119
|
+
_id: id,
|
|
120
|
+
path: fullPathOnDB,
|
|
121
|
+
data: content,
|
|
122
|
+
ctime: file.stat.ctime,
|
|
123
|
+
mtime: file.stat.mtime,
|
|
124
|
+
size: file.stat.size,
|
|
125
|
+
children: [],
|
|
126
|
+
datatype,
|
|
127
|
+
type: datatype,
|
|
128
|
+
eden: {}
|
|
129
|
+
};
|
|
130
|
+
const msg = `STORAGE -> DB (${datatype}) `;
|
|
131
|
+
const isNotChanged = await serialized("file-" + fullPath, async () => {
|
|
132
|
+
if (conflictBaseRev) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (force) {
|
|
136
|
+
this._log(msg + "Force writing " + fullPath, LOG_LEVEL_VERBOSE);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const old = await this.database.localDatabase.getDBEntry(d.path, void 0, false, true, false);
|
|
141
|
+
if (old !== false) {
|
|
142
|
+
const oldData = { data: old.data, deleted: old._deleted || old.deleted };
|
|
143
|
+
const newData = { data: d.data, deleted: d._deleted || d.deleted };
|
|
144
|
+
if (oldData.deleted != newData.deleted) return false;
|
|
145
|
+
if (!await isDocContentSame(old.data, newData.data)) return false;
|
|
146
|
+
this._log(
|
|
147
|
+
msg + "Skipped (not changed) " + fullPath + (d._deleted || d.deleted ? " (deleted)" : ""),
|
|
148
|
+
LOG_LEVEL_VERBOSE
|
|
149
|
+
);
|
|
150
|
+
this.path.markChangesAreSame(old, d.mtime, old.mtime);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
} catch (ex) {
|
|
154
|
+
this._log(
|
|
155
|
+
msg + "Error, Could not check the diff for the old one." + (force ? "force writing." : "") + fullPath + (d._deleted || d.deleted ? " (deleted)" : ""),
|
|
156
|
+
LOG_LEVEL_VERBOSE
|
|
157
|
+
);
|
|
158
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
159
|
+
return !force;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
});
|
|
163
|
+
if (isNotChanged) {
|
|
164
|
+
this._log(msg + " Skip " + fullPath, LOG_LEVEL_VERBOSE);
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
const ret = await this.database.localDatabase.putDBEntry(d, onlyChunks, conflictBaseRev);
|
|
168
|
+
if (ret !== false) {
|
|
169
|
+
this._log(msg + fullPath);
|
|
170
|
+
this.events.emitEvent(EVENT_FILE_SAVED);
|
|
171
|
+
}
|
|
172
|
+
return ret != false;
|
|
173
|
+
}
|
|
174
|
+
async getParentRev(file, rev) {
|
|
175
|
+
const filename = getDatabasePathFromUXFileInfo(file);
|
|
176
|
+
try {
|
|
177
|
+
const doc = await this.database.localDatabase.getDBEntryMeta(filename, { rev, revs: true }, true);
|
|
178
|
+
if (doc === false) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const revisions = doc._revisions;
|
|
182
|
+
if (!revisions || revisions.ids.length < 2) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
return `${revisions.start - 1}-${revisions.ids[1]}`;
|
|
186
|
+
} catch (ex) {
|
|
187
|
+
this._log(`Could not read revision history for ${filename} (${rev})`, LOG_LEVEL_VERBOSE);
|
|
188
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async hasContentInRevisionHistory(file, content, currentRev) {
|
|
193
|
+
if (!await this.checkIsTargetFile(file)) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
const filename = getDatabasePathFromUXFileInfo(file);
|
|
197
|
+
try {
|
|
198
|
+
const doc = await this.database.localDatabase.getDBEntryMeta(
|
|
199
|
+
filename,
|
|
200
|
+
{ rev: currentRev, revs_info: true },
|
|
201
|
+
true
|
|
202
|
+
);
|
|
203
|
+
if (doc === false) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
const revisions = doc._revs_info;
|
|
207
|
+
const availableRevs = new Set((revisions || []).filter((e) => e.status === "available").map((e) => e.rev));
|
|
208
|
+
if (currentRev) {
|
|
209
|
+
availableRevs.add(currentRev);
|
|
210
|
+
}
|
|
211
|
+
for (const rev of availableRevs) {
|
|
212
|
+
const entry = await this.database.localDatabase.getDBEntry(filename, { rev }, false, true, true);
|
|
213
|
+
if (entry !== false && await isDocContentSame(readContent(entry), content)) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
} catch (ex) {
|
|
218
|
+
this._log(`Could not check revision history for ${filename}`, LOG_LEVEL_VERBOSE);
|
|
219
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
async getConflictedRevs(file) {
|
|
224
|
+
if (!await this.checkIsTargetFile(file)) {
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
const filename = getDatabasePathFromUXFileInfo(file);
|
|
228
|
+
const doc = await this.database.localDatabase.getDBEntryMeta(filename, { conflicts: true }, true);
|
|
229
|
+
if (doc === false) {
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
return doc._conflicts || [];
|
|
233
|
+
}
|
|
234
|
+
async fetch(file, rev, waitForReady, skipCheck = false) {
|
|
235
|
+
if (skipCheck && !await this.checkIsTargetFile(file)) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const entry = await this.fetchEntry(file, rev, waitForReady, true);
|
|
239
|
+
if (entry === false) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
const data = createBlob(readContent(entry));
|
|
243
|
+
const path = stripAllPrefixes(entry.path);
|
|
244
|
+
const fileInfo = {
|
|
245
|
+
name: path.split("/").pop(),
|
|
246
|
+
path,
|
|
247
|
+
stat: {
|
|
248
|
+
size: entry.size,
|
|
249
|
+
ctime: entry.ctime,
|
|
250
|
+
mtime: entry.mtime,
|
|
251
|
+
type: "file"
|
|
252
|
+
},
|
|
253
|
+
body: data,
|
|
254
|
+
deleted: entry.deleted || entry._deleted
|
|
255
|
+
};
|
|
256
|
+
if (isInternalMetadata(entry.path)) {
|
|
257
|
+
fileInfo.isInternal = true;
|
|
258
|
+
}
|
|
259
|
+
return fileInfo;
|
|
260
|
+
}
|
|
261
|
+
async fetchEntryMeta(file, rev, skipCheck = false) {
|
|
262
|
+
const dbFileName = getDatabasePathFromUXFileInfo(file);
|
|
263
|
+
if (skipCheck && !await this.checkIsTargetFile(file)) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
const doc = await this.database.localDatabase.getDBEntryMeta(dbFileName, rev ? { rev } : void 0, true);
|
|
267
|
+
if (doc === false) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return doc;
|
|
271
|
+
}
|
|
272
|
+
async fetchEntryFromMeta(meta, waitForReady = true, skipCheck = false) {
|
|
273
|
+
if (skipCheck && !await this.checkIsTargetFile(meta.path)) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const doc = await this.database.localDatabase.getDBEntryFromMeta(meta, false, waitForReady);
|
|
277
|
+
if (doc === false) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
return doc;
|
|
281
|
+
}
|
|
282
|
+
async fetchEntry(file, rev, waitForReady = true, skipCheck = false) {
|
|
283
|
+
if (skipCheck && !await this.checkIsTargetFile(file)) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
const entry = await this.fetchEntryMeta(file, rev, true);
|
|
287
|
+
if (entry === false) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
const doc = await this.fetchEntryFromMeta(entry, waitForReady, true);
|
|
291
|
+
return doc;
|
|
292
|
+
}
|
|
293
|
+
async deleteFromDBbyPath(fullPath, rev) {
|
|
294
|
+
if (!await this.checkIsTargetFile(fullPath)) {
|
|
295
|
+
this._log(`deleteFromDBbyPath: File is not target: ${fullPath}`);
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
const opt = rev ? { rev } : void 0;
|
|
299
|
+
const ret = await this.database.localDatabase.deleteDBEntry(fullPath, opt);
|
|
300
|
+
this.events.emitEvent(EVENT_FILE_SAVED);
|
|
301
|
+
return ret;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
export {
|
|
305
|
+
ServiceDatabaseFileAccessBase
|
|
306
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { FilePath, FilePathWithPrefix, UXDataWriteOptions, UXFileInfo, UXFileInfoStub, UXFolderInfo, UXStat } from "../common/types.js";
|
|
2
|
+
import { ServiceModuleBase } from "./ServiceModuleBase.js";
|
|
3
|
+
import type { APIService } from "../services/base/APIService.js";
|
|
4
|
+
import type { IStorageAccessManager, StorageAccess } from "../interfaces/StorageAccess.js";
|
|
5
|
+
import type { AppLifecycleService } from "../services/base/AppLifecycleService.js";
|
|
6
|
+
import type { FileProcessingService } from "../services/base/FileProcessingService.js";
|
|
7
|
+
import { StorageEventManager } from "../interfaces/StorageEventManager.js";
|
|
8
|
+
import { type CustomRegExp } from "../common/utils.js";
|
|
9
|
+
import type { VaultService } from "../services/base/VaultService.js";
|
|
10
|
+
import type { SettingService } from "../services/base/SettingService.js";
|
|
11
|
+
import type { FileAccessBase, ExtractFile, ExtractFolder } from "./FileAccessBase.js";
|
|
12
|
+
import type { IFileSystemAdapter } from "./adapters/index.js";
|
|
13
|
+
export interface StorageAccessBaseDependencies<TAdapter extends IFileSystemAdapter<any, any, any, any>> {
|
|
14
|
+
API: APIService;
|
|
15
|
+
appLifecycle: AppLifecycleService;
|
|
16
|
+
fileProcessing: FileProcessingService;
|
|
17
|
+
vault: VaultService;
|
|
18
|
+
setting: SettingService;
|
|
19
|
+
storageEventManager: StorageEventManager;
|
|
20
|
+
storageAccessManager: IStorageAccessManager;
|
|
21
|
+
vaultAccess: FileAccessBase<TAdapter>;
|
|
22
|
+
}
|
|
23
|
+
export declare class ServiceFileAccessBase<TAdapter extends IFileSystemAdapter<any, any, any, any>> extends ServiceModuleBase<StorageAccessBaseDependencies<TAdapter>> implements StorageAccess {
|
|
24
|
+
private vaultAccess;
|
|
25
|
+
private vaultManager;
|
|
26
|
+
private vault;
|
|
27
|
+
private setting;
|
|
28
|
+
constructor(services: StorageAccessBaseDependencies<TAdapter>);
|
|
29
|
+
restoreState(): Promise<void>;
|
|
30
|
+
_everyOnFirstInitialize(): Promise<boolean>;
|
|
31
|
+
_everyCommitPendingFileEvent(): Promise<boolean>;
|
|
32
|
+
normalisePath(path: string): string;
|
|
33
|
+
writeFileAuto(path: string, data: string | ArrayBuffer, opt?: UXDataWriteOptions): Promise<boolean>;
|
|
34
|
+
readFileAuto(path: string): Promise<string | ArrayBuffer>;
|
|
35
|
+
readFileText(path: string): Promise<string>;
|
|
36
|
+
isExists(path: string): Promise<boolean>;
|
|
37
|
+
renameFile(file: UXFileInfoStub | FilePathWithPrefix, newPath: FilePathWithPrefix): Promise<UXFileInfoStub | null>;
|
|
38
|
+
writeHiddenFileAuto(path: string, data: string | ArrayBuffer, opt?: UXDataWriteOptions): Promise<boolean>;
|
|
39
|
+
appendHiddenFile(path: string, data: string, opt?: UXDataWriteOptions): Promise<boolean>;
|
|
40
|
+
stat(path: string): Promise<UXStat | null>;
|
|
41
|
+
statHidden(path: string): Promise<UXStat | null>;
|
|
42
|
+
removeHidden(path: string): Promise<boolean>;
|
|
43
|
+
readHiddenFileAuto(path: string): Promise<string | ArrayBuffer>;
|
|
44
|
+
readHiddenFileText(path: string): Promise<string>;
|
|
45
|
+
readHiddenFileBinary(path: string): Promise<ArrayBuffer>;
|
|
46
|
+
isExistsIncludeHidden(path: string): Promise<boolean>;
|
|
47
|
+
ensureDir(path: string): Promise<boolean>;
|
|
48
|
+
_triggerFileEvent(event: string, path: string): Promise<void>;
|
|
49
|
+
triggerFileEvent(event: string, path: string): void;
|
|
50
|
+
triggerHiddenFile(path: string): Promise<void>;
|
|
51
|
+
getFileStub(path: string): Promise<UXFileInfoStub | null>;
|
|
52
|
+
readStubContent(stub: UXFileInfoStub): Promise<UXFileInfo | false>;
|
|
53
|
+
getStub(path: string): Promise<UXFileInfoStub | UXFolderInfo | null>;
|
|
54
|
+
getFiles(): Promise<UXFileInfoStub[]>;
|
|
55
|
+
getFileNames(): Promise<FilePath[]>;
|
|
56
|
+
getFilesIncludeHidden(basePath: string, includeFilter?: CustomRegExp[], excludeFilter?: CustomRegExp[], skipFolder?: string[]): Promise<FilePath[]>;
|
|
57
|
+
touched(file: UXFileInfoStub | FilePathWithPrefix): Promise<void>;
|
|
58
|
+
recentlyTouched(file: UXFileInfoStub | FilePathWithPrefix): Promise<boolean>;
|
|
59
|
+
clearTouched(): void;
|
|
60
|
+
delete(file: FilePathWithPrefix | UXFileInfoStub | string, force: boolean): Promise<void>;
|
|
61
|
+
trash(file: FilePathWithPrefix | UXFileInfoStub | string, system: boolean): Promise<void>;
|
|
62
|
+
__deleteVaultItem(file: ExtractFile<TAdapter> | ExtractFolder<TAdapter>): Promise<void>;
|
|
63
|
+
deleteVaultItem(fileSrc: FilePathWithPrefix | UXFileInfoStub | UXFolderInfo): Promise<void>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { LOG_LEVEL_INFO, LOG_LEVEL_VERBOSE } from "octagonal-wheels/common/logger";
|
|
2
|
+
import { ServiceModuleBase } from "./ServiceModuleBase.js";
|
|
3
|
+
import { StorageEventManager } from "../interfaces/StorageEventManager.js";
|
|
4
|
+
import { createBlob, fireAndForget } from "../common/utils.js";
|
|
5
|
+
class ServiceFileAccessBase extends ServiceModuleBase {
|
|
6
|
+
vaultAccess;
|
|
7
|
+
vaultManager;
|
|
8
|
+
vault;
|
|
9
|
+
setting;
|
|
10
|
+
constructor(services) {
|
|
11
|
+
super(services);
|
|
12
|
+
this.vault = services.vault;
|
|
13
|
+
this.setting = services.setting;
|
|
14
|
+
this.vaultManager = services.storageEventManager;
|
|
15
|
+
this.vaultAccess = services.vaultAccess;
|
|
16
|
+
services.appLifecycle.onFirstInitialise.addHandler(this._everyOnFirstInitialize.bind(this));
|
|
17
|
+
services.fileProcessing.commitPendingFileEvents.addHandler(this._everyCommitPendingFileEvent.bind(this));
|
|
18
|
+
}
|
|
19
|
+
restoreState() {
|
|
20
|
+
return this.vaultManager.restoreState();
|
|
21
|
+
}
|
|
22
|
+
async _everyOnFirstInitialize() {
|
|
23
|
+
await this.vaultManager.beginWatch();
|
|
24
|
+
return Promise.resolve(true);
|
|
25
|
+
}
|
|
26
|
+
async _everyCommitPendingFileEvent() {
|
|
27
|
+
await this.vaultManager.waitForIdle();
|
|
28
|
+
return Promise.resolve(true);
|
|
29
|
+
}
|
|
30
|
+
normalisePath(path) {
|
|
31
|
+
return this.vaultAccess.normalisePath(path);
|
|
32
|
+
}
|
|
33
|
+
async writeFileAuto(path, data, opt) {
|
|
34
|
+
const file = await this.vaultAccess.getAbstractFileByPath(path);
|
|
35
|
+
if (this.vaultAccess.isFile(file)) {
|
|
36
|
+
return this.vaultAccess.vaultModify(file, data, opt);
|
|
37
|
+
} else if (file === null) {
|
|
38
|
+
if (!path.endsWith(".md")) {
|
|
39
|
+
await this.vaultAccess.adapterWrite(path, data, opt);
|
|
40
|
+
return await this.vaultAccess.adapterExists(path);
|
|
41
|
+
} else {
|
|
42
|
+
try {
|
|
43
|
+
return await this.vaultAccess.vaultCreate(path, data, opt) !== null;
|
|
44
|
+
} catch (ex) {
|
|
45
|
+
if (ex instanceof Error && ex.message === "File already exists.") {
|
|
46
|
+
await this.vaultAccess.adapterWrite(path, data, opt);
|
|
47
|
+
return await this.vaultAccess.adapterExists(path);
|
|
48
|
+
}
|
|
49
|
+
throw ex;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
this._log(`Could not write file (Possibly already exists as a folder): ${path}`, LOG_LEVEL_VERBOSE);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async readFileAuto(path) {
|
|
58
|
+
const file = await this.vaultAccess.getAbstractFileByPath(path);
|
|
59
|
+
if (this.vaultAccess.isFile(file)) {
|
|
60
|
+
return this.vaultAccess.vaultReadAuto(file);
|
|
61
|
+
} else {
|
|
62
|
+
throw new Error(`Could not read file (Possibly does not exist): ${path}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async readFileText(path) {
|
|
66
|
+
const file = await this.vaultAccess.getAbstractFileByPath(path);
|
|
67
|
+
if (this.vaultAccess.isFile(file)) {
|
|
68
|
+
return this.vaultAccess.vaultRead(file);
|
|
69
|
+
} else {
|
|
70
|
+
throw new Error(`Could not read file (Possibly does not exist): ${path}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async isExists(path) {
|
|
74
|
+
return this.vaultAccess.isFile(await this.vaultAccess.getAbstractFileByPath(path));
|
|
75
|
+
}
|
|
76
|
+
async renameFile(file, newPath) {
|
|
77
|
+
const oldPath = typeof file === "string" ? file : file.path;
|
|
78
|
+
const nativeFile = await this.vaultAccess.getAbstractFileByPath(oldPath);
|
|
79
|
+
if (!this.vaultAccess.isFile(nativeFile)) {
|
|
80
|
+
this._log(`Could not rename file (Possibly does not exist): ${oldPath}`, LOG_LEVEL_VERBOSE);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const renamedNativeFile = await this.vaultAccess.vaultRename(nativeFile, newPath);
|
|
84
|
+
const renamedFile = this.vaultAccess.nativeFileToUXFileInfoStub(renamedNativeFile);
|
|
85
|
+
await this.touched(renamedFile);
|
|
86
|
+
return renamedFile;
|
|
87
|
+
}
|
|
88
|
+
async writeHiddenFileAuto(path, data, opt) {
|
|
89
|
+
try {
|
|
90
|
+
await this.vaultAccess.adapterWrite(path, data, opt);
|
|
91
|
+
return true;
|
|
92
|
+
} catch (e) {
|
|
93
|
+
this._log(`Could not write hidden file: ${path}`, LOG_LEVEL_VERBOSE);
|
|
94
|
+
this._log(e, LOG_LEVEL_VERBOSE);
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async appendHiddenFile(path, data, opt) {
|
|
99
|
+
try {
|
|
100
|
+
await this.vaultAccess.adapterAppend(path, data, opt);
|
|
101
|
+
return true;
|
|
102
|
+
} catch (e) {
|
|
103
|
+
this._log(`Could not append hidden file: ${path}`, LOG_LEVEL_VERBOSE);
|
|
104
|
+
this._log(e, LOG_LEVEL_VERBOSE);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async stat(path) {
|
|
109
|
+
const file = await this.vaultAccess.getAbstractFileByPath(path);
|
|
110
|
+
if (file === null) return Promise.resolve(null);
|
|
111
|
+
if (this.vaultAccess.isFile(file)) {
|
|
112
|
+
const fileWithStat = file;
|
|
113
|
+
return Promise.resolve({
|
|
114
|
+
ctime: fileWithStat.stat.ctime,
|
|
115
|
+
mtime: fileWithStat.stat.mtime,
|
|
116
|
+
size: fileWithStat.stat.size,
|
|
117
|
+
type: "file"
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
throw new Error(`Could not stat file (Possibly does not exist): ${path}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
statHidden(path) {
|
|
124
|
+
return this.vaultAccess.tryAdapterStat(path);
|
|
125
|
+
}
|
|
126
|
+
async removeHidden(path) {
|
|
127
|
+
try {
|
|
128
|
+
await this.vaultAccess.adapterRemove(path);
|
|
129
|
+
if (this.vaultAccess.tryAdapterStat(path) !== null) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
this._log(`Could not remove hidden file: ${path}`, LOG_LEVEL_VERBOSE);
|
|
135
|
+
this._log(e, LOG_LEVEL_VERBOSE);
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async readHiddenFileAuto(path) {
|
|
140
|
+
return await this.vaultAccess.adapterReadAuto(path);
|
|
141
|
+
}
|
|
142
|
+
async readHiddenFileText(path) {
|
|
143
|
+
return await this.vaultAccess.adapterRead(path);
|
|
144
|
+
}
|
|
145
|
+
async readHiddenFileBinary(path) {
|
|
146
|
+
return await this.vaultAccess.adapterReadBinary(path);
|
|
147
|
+
}
|
|
148
|
+
async isExistsIncludeHidden(path) {
|
|
149
|
+
return await this.vaultAccess.tryAdapterStat(path) !== null;
|
|
150
|
+
}
|
|
151
|
+
async ensureDir(path) {
|
|
152
|
+
try {
|
|
153
|
+
await this.vaultAccess.ensureDirectory(path);
|
|
154
|
+
return true;
|
|
155
|
+
} catch (e) {
|
|
156
|
+
this._log(`Could not ensure directory: ${path}`, LOG_LEVEL_VERBOSE);
|
|
157
|
+
this._log(e, LOG_LEVEL_VERBOSE);
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async _triggerFileEvent(event, path) {
|
|
162
|
+
const file = await this.vaultAccess.getAbstractFileByPath(path);
|
|
163
|
+
if (file === null) return;
|
|
164
|
+
this.vaultAccess.trigger(event, file);
|
|
165
|
+
}
|
|
166
|
+
triggerFileEvent(event, path) {
|
|
167
|
+
fireAndForget(async () => await this._triggerFileEvent(event, path));
|
|
168
|
+
}
|
|
169
|
+
async triggerHiddenFile(path) {
|
|
170
|
+
await this.vaultAccess.reconcileInternalFile(path);
|
|
171
|
+
}
|
|
172
|
+
// getFileStub(file: TFile): UXFileInfoStub {
|
|
173
|
+
// return TFileToUXFileInfoStub(file);
|
|
174
|
+
// }
|
|
175
|
+
async getFileStub(path) {
|
|
176
|
+
const file = await this.vaultAccess.getAbstractFileByPath(path);
|
|
177
|
+
if (this.vaultAccess.isFile(file)) {
|
|
178
|
+
return this.vaultAccess.nativeFileToUXFileInfoStub(file);
|
|
179
|
+
} else {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async readStubContent(stub) {
|
|
184
|
+
const file = await this.vaultAccess.getAbstractFileByPath(stub.path);
|
|
185
|
+
if (!this.vaultAccess.isFile(file)) {
|
|
186
|
+
this._log(`Could not read file (Possibly does not exist or a folder): ${stub.path}`, LOG_LEVEL_VERBOSE);
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const data = await this.vaultAccess.vaultReadAuto(file);
|
|
190
|
+
return {
|
|
191
|
+
...stub,
|
|
192
|
+
...this.vaultAccess.nativeFileToUXFileInfoStub(file),
|
|
193
|
+
body: createBlob(data)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async getStub(path) {
|
|
197
|
+
const file = await this.vaultAccess.getAbstractFileByPath(path);
|
|
198
|
+
if (this.vaultAccess.isFile(file)) {
|
|
199
|
+
return this.vaultAccess.nativeFileToUXFileInfoStub(file);
|
|
200
|
+
} else if (this.vaultAccess.isFolder(file)) {
|
|
201
|
+
return this.vaultAccess.nativeFolderToUXFolder(file);
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
async getFiles() {
|
|
206
|
+
const files = await this.vaultAccess.getFiles();
|
|
207
|
+
return files.map((f) => this.vaultAccess.nativeFileToUXFileInfoStub(f));
|
|
208
|
+
}
|
|
209
|
+
async getFileNames() {
|
|
210
|
+
const files = await this.vaultAccess.getFiles();
|
|
211
|
+
return files.map((f) => f.path);
|
|
212
|
+
}
|
|
213
|
+
async getFilesIncludeHidden(basePath, includeFilter, excludeFilter, skipFolder = [".git", ".trash", "node_modules"]) {
|
|
214
|
+
let w;
|
|
215
|
+
try {
|
|
216
|
+
w = await this.vaultAccess.adapterList(basePath);
|
|
217
|
+
} catch (ex) {
|
|
218
|
+
this._log(`Could not traverse(getFilesIncludeHidden):${basePath}`, LOG_LEVEL_INFO);
|
|
219
|
+
this._log(ex, LOG_LEVEL_VERBOSE);
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
skipFolder = skipFolder.map((e) => e.toLowerCase());
|
|
223
|
+
let files = [];
|
|
224
|
+
for (const file of w.files) {
|
|
225
|
+
if (includeFilter && includeFilter.length > 0) {
|
|
226
|
+
if (!includeFilter.some((e) => e.test(file))) continue;
|
|
227
|
+
}
|
|
228
|
+
if (excludeFilter && excludeFilter.some((ee) => ee.test(file))) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (await this.vault.isIgnoredByIgnoreFile(file)) continue;
|
|
232
|
+
files.push(file);
|
|
233
|
+
}
|
|
234
|
+
for (const v of w.folders) {
|
|
235
|
+
const folderName = (v.split("/").pop() ?? "").toLowerCase();
|
|
236
|
+
if (skipFolder.some((e) => folderName === e)) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (excludeFilter && excludeFilter.some((e) => e.test(v))) {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (await this.vault.isIgnoredByIgnoreFile(v)) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
files = files.concat(await this.getFilesIncludeHidden(v, includeFilter, excludeFilter, skipFolder));
|
|
246
|
+
}
|
|
247
|
+
return files;
|
|
248
|
+
}
|
|
249
|
+
async touched(file) {
|
|
250
|
+
const path = typeof file === "string" ? file : file.path;
|
|
251
|
+
await this.vaultAccess.touch(path);
|
|
252
|
+
}
|
|
253
|
+
async recentlyTouched(file) {
|
|
254
|
+
const xFile = typeof file === "string" ? await this.vaultAccess.getAbstractFileByPath(file) : file;
|
|
255
|
+
if (xFile === null) return false;
|
|
256
|
+
if (this.vaultAccess.isFolder(xFile)) return false;
|
|
257
|
+
return this.vaultAccess.recentlyTouched(xFile);
|
|
258
|
+
}
|
|
259
|
+
clearTouched() {
|
|
260
|
+
this.vaultAccess.clearTouched();
|
|
261
|
+
}
|
|
262
|
+
async delete(file, force) {
|
|
263
|
+
const xPath = typeof file === "string" ? file : file.path;
|
|
264
|
+
const xFile = await this.vaultAccess.getAbstractFileByPath(xPath);
|
|
265
|
+
if (xFile === null) return Promise.resolve();
|
|
266
|
+
if (!this.vaultAccess.isFile(xFile) && !this.vaultAccess.isFolder(xFile)) return Promise.resolve();
|
|
267
|
+
return this.vaultAccess.delete(xFile, force);
|
|
268
|
+
}
|
|
269
|
+
async trash(file, system) {
|
|
270
|
+
const xPath = typeof file === "string" ? file : file.path;
|
|
271
|
+
const xFile = await this.vaultAccess.getAbstractFileByPath(xPath);
|
|
272
|
+
if (xFile === null) return Promise.resolve();
|
|
273
|
+
if (!this.vaultAccess.isFile(xFile) && !this.vaultAccess.isFolder(xFile)) return Promise.resolve();
|
|
274
|
+
return this.vaultAccess.trash(xFile, system);
|
|
275
|
+
}
|
|
276
|
+
async __deleteVaultItem(file) {
|
|
277
|
+
const filePath = this.vaultAccess.getPath(file);
|
|
278
|
+
if (this.vaultAccess.isFile(file)) {
|
|
279
|
+
if (!await this.vault.isTargetFile(filePath)) return;
|
|
280
|
+
}
|
|
281
|
+
const dir = file.parent;
|
|
282
|
+
const settings = this.setting.currentSettings();
|
|
283
|
+
if (settings.trashInsteadDelete) {
|
|
284
|
+
await this.vaultAccess.trash(file, false);
|
|
285
|
+
} else {
|
|
286
|
+
await this.vaultAccess.delete(file, true);
|
|
287
|
+
}
|
|
288
|
+
this._log(`xxx <- STORAGE (deleted) ${filePath}`);
|
|
289
|
+
if (dir) {
|
|
290
|
+
this._log(`files: ${dir?.children?.length ?? "unknown"}`);
|
|
291
|
+
if ((dir?.children?.length ?? 0) === 0) {
|
|
292
|
+
if (!settings.doNotDeleteFolder) {
|
|
293
|
+
this._log(
|
|
294
|
+
`All files under the parent directory (${dir.path}) have been deleted, so delete this one.`
|
|
295
|
+
);
|
|
296
|
+
await this.__deleteVaultItem(dir);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
async deleteVaultItem(fileSrc) {
|
|
302
|
+
const path = typeof fileSrc === "string" ? fileSrc : fileSrc.path;
|
|
303
|
+
const file = await this.vaultAccess.getAbstractFileByPath(path);
|
|
304
|
+
if (file === null) return;
|
|
305
|
+
if (this.vaultAccess.isFile(file) || this.vaultAccess.isFolder(file)) {
|
|
306
|
+
return await this.__deleteVaultItem(file);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
export {
|
|
311
|
+
ServiceFileAccessBase
|
|
312
|
+
};
|