tests: vaults-2 (#2368)
This commit is contained in:
@@ -47,7 +47,7 @@ import {
|
||||
IntegrityService,
|
||||
InternalEventBus,
|
||||
KeySystemKeyManager,
|
||||
RemoveItemsLocally,
|
||||
DiscardItemsLocally,
|
||||
RevisionManager,
|
||||
SelfContactManager,
|
||||
StatusService,
|
||||
@@ -118,6 +118,7 @@ import {
|
||||
ContactBelongsToVault,
|
||||
DeleteContact,
|
||||
VaultLockService,
|
||||
RemoveItemsFromMemory,
|
||||
} from '@standardnotes/services'
|
||||
import { ItemManager } from '../../Services/Items/ItemManager'
|
||||
import { PayloadManager } from '../../Services/Payloads/PayloadManager'
|
||||
@@ -222,8 +223,16 @@ export class Dependencies {
|
||||
return new DecryptBackupFile(this.get(TYPES.EncryptionService))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.RemoveItemsLocally, () => {
|
||||
return new RemoveItemsLocally(this.get(TYPES.ItemManager), this.get(TYPES.DiskStorageService))
|
||||
this.factory.set(TYPES.DiscardItemsLocally, () => {
|
||||
return new DiscardItemsLocally(this.get(TYPES.ItemManager), this.get(TYPES.DiskStorageService))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.RemoveItemsFromMemory, () => {
|
||||
return new RemoveItemsFromMemory(
|
||||
this.get(TYPES.DiskStorageService),
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.PayloadManager),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.FindContact, () => {
|
||||
@@ -442,7 +451,7 @@ export class Dependencies {
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.KeySystemKeyManager),
|
||||
this.get(TYPES.SyncService),
|
||||
this.get(TYPES.RemoveItemsLocally),
|
||||
this.get(TYPES.DiscardItemsLocally),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -555,7 +564,7 @@ export class Dependencies {
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.CreateNewDefaultItemsKey),
|
||||
this.get(TYPES.RemoveItemsLocally),
|
||||
this.get(TYPES.DiscardItemsLocally),
|
||||
this.get(TYPES.FindDefaultItemsKey),
|
||||
)
|
||||
})
|
||||
@@ -723,6 +732,7 @@ export class Dependencies {
|
||||
this.get(TYPES.ConvertToSharedVault),
|
||||
this.get(TYPES.DeleteSharedVault),
|
||||
this.get(TYPES.IsVaultOwner),
|
||||
this.get(TYPES.DiscardItemsLocally),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
@@ -1221,6 +1231,7 @@ export class Dependencies {
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.DiskStorageService),
|
||||
this.get(TYPES.RemoveItemsFromMemory),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -89,7 +89,7 @@ export const TYPES = {
|
||||
GetRevision: Symbol.for('GetRevision'),
|
||||
DeleteRevision: Symbol.for('DeleteRevision'),
|
||||
ImportDataUseCase: Symbol.for('ImportDataUseCase'),
|
||||
RemoveItemsLocally: Symbol.for('RemoveItemsLocally'),
|
||||
DiscardItemsLocally: Symbol.for('DiscardItemsLocally'),
|
||||
FindContact: Symbol.for('FindContact'),
|
||||
GetAllContacts: Symbol.for('GetAllContacts'),
|
||||
CreateOrEditContact: Symbol.for('CreateOrEditContact'),
|
||||
@@ -150,6 +150,7 @@ export const TYPES = {
|
||||
EncryptTypeAPayloadWithKeyLookup: Symbol.for('EncryptTypeAPayloadWithKeyLookup'),
|
||||
DecryptBackupFile: Symbol.for('DecryptBackupFile'),
|
||||
IsVaultOwner: Symbol.for('IsVaultOwner'),
|
||||
RemoveItemsFromMemory: Symbol.for('RemoveItemsFromMemory'),
|
||||
|
||||
// Mappers
|
||||
SessionStorageMapper: Symbol.for('SessionStorageMapper'),
|
||||
|
||||
@@ -18,7 +18,7 @@ export class Migration2_20_0 extends Migration {
|
||||
const items = this.services.itemManager.getItems(contentType)
|
||||
|
||||
for (const item of items) {
|
||||
this.services.itemManager.removeItemLocally(item)
|
||||
this.services.itemManager.removeItemFromMemory(item)
|
||||
await this.services.storageService.deletePayloadWithUuid(item.uuid)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export class Migration2_36_0 extends Migration {
|
||||
const items = this.services.itemManager.getItems(contentType)
|
||||
|
||||
for (const item of items) {
|
||||
this.services.itemManager.removeItemLocally(item)
|
||||
this.services.itemManager.removeItemFromMemory(item)
|
||||
await this.services.storageService.deletePayloadWithUuid(item.uuid)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,14 +816,14 @@ export class ItemManager extends Services.AbstractService implements Services.It
|
||||
/**
|
||||
* Important: Caller must coordinate with storage service separately to delete item from persistent database.
|
||||
*/
|
||||
public removeItemLocally(item: Models.AnyItemInterface): void {
|
||||
this.removeItemsLocally([item])
|
||||
public removeItemFromMemory(item: Models.AnyItemInterface): void {
|
||||
this.removeItemsFromMemory([item])
|
||||
}
|
||||
|
||||
/**
|
||||
* Important: Caller must coordinate with storage service separately to delete item from persistent database.
|
||||
*/
|
||||
public removeItemsLocally(items: Models.AnyItemInterface[]): void {
|
||||
public removeItemsFromMemory(items: Models.AnyItemInterface[]): void {
|
||||
this.collection.discard(items)
|
||||
this.payloadManager.removePayloadLocally(items.map((item) => item.payload))
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ export class DiskStorageService
|
||||
private values!: StorageValuesObject
|
||||
|
||||
constructor(
|
||||
private deviceInterface: DeviceInterface,
|
||||
private device: DeviceInterface,
|
||||
private identifier: string,
|
||||
protected override internalEventBus: InternalEventBusInterface,
|
||||
) {
|
||||
@@ -82,7 +82,7 @@ export class DiskStorageService
|
||||
}
|
||||
|
||||
public override deinit() {
|
||||
;(this.deviceInterface as unknown) = undefined
|
||||
;(this.device as unknown) = undefined
|
||||
;(this.encryptionProvider as unknown) = undefined
|
||||
this.storagePersistable = false
|
||||
super.deinit()
|
||||
@@ -104,9 +104,9 @@ export class DiskStorageService
|
||||
this.persistencePolicy = persistencePolicy
|
||||
|
||||
if (this.persistencePolicy === StoragePersistencePolicies.Ephemeral) {
|
||||
await this.deviceInterface.clearNamespacedKeychainValue(this.identifier)
|
||||
await this.deviceInterface.removeAllDatabaseEntries(this.identifier)
|
||||
await this.deviceInterface.removeRawStorageValuesForIdentifier(this.identifier)
|
||||
await this.device.clearNamespacedKeychainValue(this.identifier)
|
||||
await this.device.removeAllDatabaseEntries(this.identifier)
|
||||
await this.device.removeRawStorageValuesForIdentifier(this.identifier)
|
||||
await this.clearAllPayloads()
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ export class DiskStorageService
|
||||
}
|
||||
|
||||
public async initializeFromDisk(): Promise<void> {
|
||||
const value = await this.deviceInterface.getRawStorageValue(this.getPersistenceKey())
|
||||
const value = await this.device.getRawStorageValue(this.getPersistenceKey())
|
||||
const values = value ? JSON.parse(value as string) : undefined
|
||||
|
||||
await this.setInitialValues(values)
|
||||
@@ -240,7 +240,7 @@ export class DiskStorageService
|
||||
return values
|
||||
}
|
||||
|
||||
await this.deviceInterface?.setRawStorageValue(this.getPersistenceKey(), JSON.stringify(values))
|
||||
await this.device?.setRawStorageValue(this.getPersistenceKey(), JSON.stringify(values))
|
||||
|
||||
return values
|
||||
})
|
||||
@@ -385,7 +385,11 @@ export class DiskStorageService
|
||||
}
|
||||
|
||||
public async getAllRawPayloads(): Promise<FullyFormedTransferPayload[]> {
|
||||
return this.deviceInterface.getAllDatabaseEntries(this.identifier)
|
||||
return this.device.getAllDatabaseEntries(this.identifier)
|
||||
}
|
||||
|
||||
public async getRawPayloads(uuids: string[]): Promise<FullyFormedTransferPayload[]> {
|
||||
return this.device.getDatabaseEntries(this.identifier, uuids)
|
||||
}
|
||||
|
||||
public async savePayload(payload: FullyFormedPayloadInterface): Promise<void> {
|
||||
@@ -440,7 +444,7 @@ export class DiskStorageService
|
||||
const exportedDeleted = deleted.map(CreateDeletedLocalStorageContextPayload)
|
||||
|
||||
return this.executeCriticalFunction(async () => {
|
||||
return this.deviceInterface?.saveDatabaseEntries(
|
||||
return this.device?.saveDatabaseEntries(
|
||||
[...exportedEncrypted, ...exportedDecrypted, ...exportedDeleted],
|
||||
this.identifier,
|
||||
)
|
||||
@@ -453,19 +457,19 @@ export class DiskStorageService
|
||||
|
||||
public async deletePayloadsWithUuids(uuids: string[]): Promise<void> {
|
||||
await this.executeCriticalFunction(async () => {
|
||||
await Promise.all(uuids.map((uuid) => this.deviceInterface.removeDatabaseEntry(uuid, this.identifier)))
|
||||
await Promise.all(uuids.map((uuid) => this.device.removeDatabaseEntry(uuid, this.identifier)))
|
||||
})
|
||||
}
|
||||
|
||||
public async deletePayloadWithUuid(uuid: string) {
|
||||
return this.executeCriticalFunction(async () => {
|
||||
await this.deviceInterface.removeDatabaseEntry(uuid, this.identifier)
|
||||
await this.device.removeDatabaseEntry(uuid, this.identifier)
|
||||
})
|
||||
}
|
||||
|
||||
public async clearAllPayloads() {
|
||||
return this.executeCriticalFunction(async () => {
|
||||
return this.deviceInterface.removeAllDatabaseEntries(this.identifier)
|
||||
return this.device.removeAllDatabaseEntries(this.identifier)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -474,9 +478,9 @@ export class DiskStorageService
|
||||
await this.clearValues()
|
||||
await this.clearAllPayloads()
|
||||
|
||||
await this.deviceInterface.removeRawStorageValue(namespacedKey(this.identifier, RawStorageKey.SnjsVersion))
|
||||
await this.device.removeRawStorageValue(namespacedKey(this.identifier, RawStorageKey.SnjsVersion))
|
||||
|
||||
await this.deviceInterface.removeRawStorageValue(this.getPersistenceKey())
|
||||
await this.device.removeRawStorageValue(this.getPersistenceKey())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user