refactor: application dependency management (#2363)
This commit is contained in:
@@ -26,17 +26,16 @@ export class AppContext {
|
||||
}
|
||||
|
||||
enableLogging() {
|
||||
const syncService = this.application.syncService
|
||||
const payloadManager = this.application.payloadManager
|
||||
const payloadManager = this.application.payloads
|
||||
|
||||
syncService.getServiceName = () => {
|
||||
this.application.sync.getServiceName = () => {
|
||||
return `${this.identifier}—SyncService`
|
||||
}
|
||||
payloadManager.getServiceName = () => {
|
||||
return `${this.identifier}-PayloadManager`
|
||||
}
|
||||
|
||||
syncService.loggingEnabled = true
|
||||
this.application.sync.loggingEnabled = true
|
||||
payloadManager.loggingEnabled = true
|
||||
}
|
||||
|
||||
@@ -51,7 +50,7 @@ export class AppContext {
|
||||
}
|
||||
|
||||
get vaults() {
|
||||
return this.application.vaultService
|
||||
return this.application.vaults
|
||||
}
|
||||
|
||||
get sessions() {
|
||||
@@ -67,31 +66,51 @@ export class AppContext {
|
||||
}
|
||||
|
||||
get payloads() {
|
||||
return this.application.payloadManager
|
||||
return this.application.payloads
|
||||
}
|
||||
|
||||
get encryption() {
|
||||
return this.application.encryptionService
|
||||
return this.application.encryption
|
||||
}
|
||||
|
||||
get keyRecovery() {
|
||||
return this.application.dependencies.get(TYPES.KeyRecoveryService)
|
||||
}
|
||||
|
||||
get singletons() {
|
||||
return this.application.dependencies.get(TYPES.SingletonManager)
|
||||
}
|
||||
|
||||
get history() {
|
||||
return this.application.dependencies.get(TYPES.HistoryManager)
|
||||
}
|
||||
|
||||
get subscriptions() {
|
||||
return this.application.dependencies.get(TYPES.SubscriptionManager)
|
||||
}
|
||||
|
||||
get contacts() {
|
||||
return this.application.contactService
|
||||
return this.application.contacts
|
||||
}
|
||||
|
||||
get sharedVaults() {
|
||||
return this.application.sharedVaultService
|
||||
return this.application.sharedVaults
|
||||
}
|
||||
|
||||
get files() {
|
||||
return this.application.fileService
|
||||
return this.application.files
|
||||
}
|
||||
|
||||
get keys() {
|
||||
return this.application.keySystemKeyManager
|
||||
return this.application.dependencies.get(TYPES.KeySystemKeyManager)
|
||||
}
|
||||
|
||||
get operators() {
|
||||
return this.application.dependencies.get(TYPES.EncryptionOperators)
|
||||
}
|
||||
|
||||
get asymmetric() {
|
||||
return this.application.asymmetricMessageService
|
||||
return this.application.asymmetric
|
||||
}
|
||||
|
||||
get publicKey() {
|
||||
@@ -115,20 +134,20 @@ export class AppContext {
|
||||
}
|
||||
|
||||
disableIntegrityAutoHeal() {
|
||||
this.application.syncService.emitOutOfSyncRemotePayloads = () => {
|
||||
this.application.sync.emitOutOfSyncRemotePayloads = () => {
|
||||
console.warn('Integrity self-healing is disabled for this test')
|
||||
}
|
||||
}
|
||||
|
||||
disableKeyRecovery() {
|
||||
this.application.keyRecoveryService.beginKeyRecovery = () => {
|
||||
this.keyRecovery.beginKeyRecovery = () => {
|
||||
console.warn('Key recovery is disabled for this test')
|
||||
}
|
||||
}
|
||||
|
||||
handleChallenge = (challenge) => {
|
||||
if (this.ignoringChallenges) {
|
||||
this.application.challengeService.cancelChallenge(challenge)
|
||||
this.application.challenges.cancelChallenge(challenge)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -178,15 +197,12 @@ export class AppContext {
|
||||
},
|
||||
})
|
||||
|
||||
return this.application.syncService.handleSuccessServerResponse(
|
||||
{ payloadsSavedOrSaving: [], options: {} },
|
||||
response,
|
||||
)
|
||||
return this.application.sync.handleSuccessServerResponse({ payloadsSavedOrSaving: [], options: {} }, response)
|
||||
}
|
||||
|
||||
resolveWhenKeyRecovered(uuid) {
|
||||
return new Promise((resolve) => {
|
||||
this.application.keyRecoveryService.addEventObserver((_eventName, keys) => {
|
||||
this.keyRecovery.addEventObserver((_eventName, keys) => {
|
||||
if (Uuids(keys).includes(uuid)) {
|
||||
resolve()
|
||||
}
|
||||
@@ -196,7 +212,7 @@ export class AppContext {
|
||||
|
||||
resolveWhenSharedVaultUserKeysResolved() {
|
||||
return new Promise((resolve) => {
|
||||
this.application.vaultService.collaboration.addEventObserver((eventName) => {
|
||||
this.application.vaults.collaboration.addEventObserver((eventName) => {
|
||||
if (eventName === SharedVaultServiceEvent.SharedVaultStatusChanged) {
|
||||
resolve()
|
||||
}
|
||||
@@ -206,7 +222,7 @@ export class AppContext {
|
||||
|
||||
async awaitSignInEvent() {
|
||||
return new Promise((resolve) => {
|
||||
this.application.userService.addEventObserver((eventName) => {
|
||||
this.application.user.addEventObserver((eventName) => {
|
||||
if (eventName === AccountEvent.SignedInOrRegistered) {
|
||||
resolve()
|
||||
}
|
||||
@@ -235,7 +251,7 @@ export class AppContext {
|
||||
|
||||
awaitNextSucessfulSync() {
|
||||
return new Promise((resolve) => {
|
||||
const removeObserver = this.application.syncService.addEventObserver((event) => {
|
||||
const removeObserver = this.application.sync.addEventObserver((event) => {
|
||||
if (event === SyncEvent.SyncCompletedWithAllItemsUploadedAndDownloaded) {
|
||||
removeObserver()
|
||||
resolve()
|
||||
@@ -246,7 +262,7 @@ export class AppContext {
|
||||
|
||||
awaitNextSyncEvent(eventName) {
|
||||
return new Promise((resolve) => {
|
||||
const removeObserver = this.application.syncService.addEventObserver((event, data) => {
|
||||
const removeObserver = this.application.sync.addEventObserver((event, data) => {
|
||||
if (event === eventName) {
|
||||
removeObserver()
|
||||
resolve(data)
|
||||
@@ -257,7 +273,7 @@ export class AppContext {
|
||||
|
||||
awaitNextSyncSharedVaultFromScratchEvent() {
|
||||
return new Promise((resolve) => {
|
||||
const removeObserver = this.application.syncService.addEventObserver((event, data) => {
|
||||
const removeObserver = this.application.sync.addEventObserver((event, data) => {
|
||||
if (event === SyncEvent.PaginatedSyncRequestCompleted && data?.options?.sharedVaultUuids) {
|
||||
removeObserver()
|
||||
resolve(data)
|
||||
@@ -268,7 +284,7 @@ export class AppContext {
|
||||
|
||||
resolveWithUploadedPayloads() {
|
||||
return new Promise((resolve) => {
|
||||
this.application.syncService.addEventObserver((event, data) => {
|
||||
this.application.sync.addEventObserver((event, data) => {
|
||||
if (event === SyncEvent.PaginatedSyncRequestCompleted) {
|
||||
resolve(data.uploadedPayloads)
|
||||
}
|
||||
@@ -278,7 +294,7 @@ export class AppContext {
|
||||
|
||||
resolveWithConflicts() {
|
||||
return new Promise((resolve) => {
|
||||
this.application.syncService.addEventObserver((event, response) => {
|
||||
this.application.sync.addEventObserver((event, response) => {
|
||||
if (event === SyncEvent.PaginatedSyncRequestCompleted) {
|
||||
resolve(response.rawConflictObjects)
|
||||
}
|
||||
@@ -288,7 +304,7 @@ export class AppContext {
|
||||
|
||||
resolveWhenSavedSyncPayloadsIncludesItemUuid(uuid) {
|
||||
return new Promise((resolve) => {
|
||||
this.application.syncService.addEventObserver((event, response) => {
|
||||
this.application.sync.addEventObserver((event, response) => {
|
||||
if (event === SyncEvent.PaginatedSyncRequestCompleted) {
|
||||
const savedPayload = response.savedPayloads.find((payload) => payload.uuid === uuid)
|
||||
if (savedPayload) {
|
||||
@@ -301,7 +317,7 @@ export class AppContext {
|
||||
|
||||
resolveWhenSavedSyncPayloadsIncludesItemThatIsDuplicatedOf(uuid) {
|
||||
return new Promise((resolve) => {
|
||||
this.application.syncService.addEventObserver((event, response) => {
|
||||
this.application.sync.addEventObserver((event, response) => {
|
||||
if (event === SyncEvent.PaginatedSyncRequestCompleted) {
|
||||
const savedPayload = response.savedPayloads.find((payload) => payload.duplicate_of === uuid)
|
||||
if (savedPayload) {
|
||||
@@ -354,7 +370,7 @@ export class AppContext {
|
||||
|
||||
resolveWhenUserMessagesProcessingCompletes() {
|
||||
return new Promise((resolve) => {
|
||||
const objectToSpy = this.application.userEventService
|
||||
const objectToSpy = this.application.dependencies.get(TYPES.UserEventService)
|
||||
sinon.stub(objectToSpy, 'handleReceivedUserEvents').callsFake(async (params) => {
|
||||
objectToSpy.handleReceivedUserEvents.restore()
|
||||
const result = await objectToSpy.handleReceivedUserEvents(params)
|
||||
@@ -364,12 +380,36 @@ export class AppContext {
|
||||
})
|
||||
}
|
||||
|
||||
resolveWhenAllInboundAsymmetricMessagesAreDeleted() {
|
||||
return new Promise((resolve) => {
|
||||
const objectToSpy = this.application.dependencies.get(TYPES.AsymmetricMessageServer)
|
||||
sinon.stub(objectToSpy, 'deleteAllInboundMessages').callsFake(async (params) => {
|
||||
objectToSpy.deleteAllInboundMessages.restore()
|
||||
const result = await objectToSpy.deleteAllInboundMessages(params)
|
||||
resolve()
|
||||
return result
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
resolveWhenAllInboundSharedVaultInvitesAreDeleted() {
|
||||
return new Promise((resolve) => {
|
||||
const objectToSpy = this.application.sharedVaults.invitesServer
|
||||
sinon.stub(objectToSpy, 'deleteAllInboundInvites').callsFake(async (params) => {
|
||||
objectToSpy.deleteAllInboundInvites.restore()
|
||||
const result = await objectToSpy.deleteAllInboundInvites(params)
|
||||
resolve()
|
||||
return result
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
resolveWhenSharedVaultServiceSendsContactShareMessage() {
|
||||
return new Promise((resolve) => {
|
||||
const objectToSpy = this.sharedVaults
|
||||
sinon.stub(objectToSpy, 'shareContactWithUserAdministeredSharedVaults').callsFake(async (contact) => {
|
||||
objectToSpy.shareContactWithUserAdministeredSharedVaults.restore()
|
||||
const result = await objectToSpy.shareContactWithUserAdministeredSharedVaults(contact)
|
||||
sinon.stub(objectToSpy, 'shareContactWithVaults').callsFake(async (contact) => {
|
||||
objectToSpy.shareContactWithVaults.restore()
|
||||
const result = await objectToSpy.shareContactWithVaults(contact)
|
||||
resolve()
|
||||
return result
|
||||
})
|
||||
@@ -405,14 +445,14 @@ export class AppContext {
|
||||
}
|
||||
|
||||
awaitUserPrefsSingletonCreation() {
|
||||
const preferences = this.application.preferencesService.preferences
|
||||
const preferences = this.application.preferences.preferences
|
||||
if (preferences) {
|
||||
return
|
||||
}
|
||||
|
||||
let didCompleteRelevantSync = false
|
||||
return new Promise((resolve) => {
|
||||
this.application.syncService.addEventObserver((eventName, data) => {
|
||||
this.application.sync.addEventObserver((eventName, data) => {
|
||||
if (!didCompleteRelevantSync) {
|
||||
if (data?.savedPayloads) {
|
||||
const matching = data.savedPayloads.find((p) => {
|
||||
@@ -430,7 +470,7 @@ export class AppContext {
|
||||
|
||||
awaitUserPrefsSingletonResolution() {
|
||||
return new Promise((resolve) => {
|
||||
this.application.preferencesService.addEventObserver((eventName) => {
|
||||
this.application.preferences.addEventObserver((eventName) => {
|
||||
if (eventName === PreferencesServiceEvent.PreferencesChanged) {
|
||||
resolve()
|
||||
}
|
||||
@@ -473,7 +513,7 @@ export class AppContext {
|
||||
}
|
||||
|
||||
findPayload(uuid) {
|
||||
return this.application.payloadManager.findPayload(uuid)
|
||||
return this.application.payloads.findPayload(uuid)
|
||||
}
|
||||
|
||||
get itemsKeys() {
|
||||
@@ -491,15 +531,15 @@ export class AppContext {
|
||||
}
|
||||
|
||||
disableKeyRecoveryServerSignIn() {
|
||||
this.application.keyRecoveryService.performServerSignIn = () => {
|
||||
console.warn('application.keyRecoveryService.performServerSignIn has been stubbed with an empty implementation')
|
||||
this.keyRecovery.performServerSignIn = () => {
|
||||
console.warn('application.keyRecovery.performServerSignIn has been stubbed with an empty implementation')
|
||||
}
|
||||
}
|
||||
|
||||
preventKeyRecoveryOfKeys(ids) {
|
||||
const originalImpl = this.application.keyRecoveryService.handleUndecryptableItemsKeys
|
||||
const originalImpl = this.keyRecovery.handleUndecryptableItemsKeys
|
||||
|
||||
this.application.keyRecoveryService.handleUndecryptableItemsKeys = function (keys) {
|
||||
this.keyRecovery.handleUndecryptableItemsKeys = function (keys) {
|
||||
const filtered = keys.filter((k) => !ids.includes(k.uuid))
|
||||
|
||||
originalImpl.apply(this, [filtered])
|
||||
@@ -520,18 +560,18 @@ export class AppContext {
|
||||
const payload = createNotePayload(title, text)
|
||||
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.setItemDirty(item)
|
||||
await this.application.syncService.sync(MaximumSyncOptions)
|
||||
await this.application.sync.sync(MaximumSyncOptions)
|
||||
const note = this.application.items.findItem(payload.uuid)
|
||||
|
||||
return note
|
||||
}
|
||||
|
||||
lockSyncing() {
|
||||
this.application.syncService.lockSyncing()
|
||||
this.application.sync.lockSyncing()
|
||||
}
|
||||
|
||||
unlockSyncing() {
|
||||
this.application.syncService.unlockSyncing()
|
||||
this.application.sync.unlockSyncing()
|
||||
}
|
||||
|
||||
async deleteItemAndSync(item) {
|
||||
@@ -624,7 +664,9 @@ export class AppContext {
|
||||
|
||||
await Utils.sleep(2)
|
||||
} catch (error) {
|
||||
console.warn(`Mock events service not available. You are probalby running a test suite for home server: ${error.message}`)
|
||||
console.warn(
|
||||
`Mock events service not available. You are probalby running a test suite for home server: ${error.message}`,
|
||||
)
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -632,7 +674,9 @@ export class AppContext {
|
||||
|
||||
await Utils.sleep(1)
|
||||
} catch (error) {
|
||||
console.warn(`Home server not available. You are probalby running a test suite for self hosted setup: ${error.message}`)
|
||||
console.warn(
|
||||
`Home server not available. You are probalby running a test suite for self hosted setup: ${error.message}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export const createTrustedContactForUserOfContext = async (
|
||||
contextAddingNewContact,
|
||||
contextImportingContactInfoFrom,
|
||||
) => {
|
||||
const contact = await contextAddingNewContact.application.contactService.createOrEditTrustedContact({
|
||||
const contact = await contextAddingNewContact.contacts.createOrEditTrustedContact({
|
||||
name: 'John Doe',
|
||||
publicKey: contextImportingContactInfoFrom.publicKey,
|
||||
signingPublicKey: contextImportingContactInfoFrom.signingPublicKey,
|
||||
@@ -27,6 +27,10 @@ export const createTrustedContactForUserOfContext = async (
|
||||
|
||||
export const acceptAllInvites = async (context) => {
|
||||
const inviteRecords = context.sharedVaults.getCachedPendingInviteRecords()
|
||||
if (inviteRecords.length === 0) {
|
||||
throw new Error('No pending invites to accept')
|
||||
}
|
||||
|
||||
for (const record of inviteRecords) {
|
||||
await context.sharedVaults.acceptPendingSharedVaultInvite(record)
|
||||
}
|
||||
@@ -72,7 +76,7 @@ export const createSharedVaultWithUnacceptedButTrustedInvite = async (
|
||||
const contact = await createTrustedContactForUserOfContext(context, contactContext)
|
||||
await createTrustedContactForUserOfContext(contactContext, context)
|
||||
|
||||
const invite = await context.sharedVaults.inviteContactToSharedVault(sharedVault, contact, permissions)
|
||||
const invite = (await context.sharedVaults.inviteContactToSharedVault(sharedVault, contact, permissions)).getValue()
|
||||
await contactContext.sync()
|
||||
|
||||
return { sharedVault, contact, contactContext, deinitContactContext, invite }
|
||||
@@ -87,7 +91,7 @@ export const createSharedVaultWithUnacceptedAndUntrustedInvite = async (
|
||||
const { contactContext, deinitContactContext } = await createContactContext()
|
||||
const contact = await createTrustedContactForUserOfContext(context, contactContext)
|
||||
|
||||
const invite = await context.sharedVaults.inviteContactToSharedVault(sharedVault, contact, permissions)
|
||||
const invite = (await context.sharedVaults.inviteContactToSharedVault(sharedVault, contact, permissions)).getValue()
|
||||
await contactContext.sync()
|
||||
|
||||
return { sharedVault, contact, contactContext, deinitContactContext, invite }
|
||||
|
||||
@@ -8,10 +8,10 @@ export async function safeDeinit(application) {
|
||||
return
|
||||
}
|
||||
|
||||
await application.diskStorageService.awaitPersist()
|
||||
await application.storage.awaitPersist()
|
||||
|
||||
/** Limit waiting to 1s */
|
||||
await Promise.race([sleep(1), application.syncService?.awaitCurrentSyncs()])
|
||||
await Promise.race([sleep(1), application.sync?.awaitCurrentSyncs()])
|
||||
|
||||
await application.prepareForDeinit()
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ export async function createAppContext({ identifier, crypto, email, password, ho
|
||||
}
|
||||
|
||||
export function disableIntegrityAutoHeal(application) {
|
||||
application.syncService.emitOutOfSyncRemotePayloads = () => {
|
||||
application.sync.emitOutOfSyncRemotePayloads = () => {
|
||||
console.warn('Integrity self-healing is disabled for this test')
|
||||
}
|
||||
}
|
||||
@@ -112,12 +112,12 @@ export function registerUserToApplication({ application, email, password, epheme
|
||||
}
|
||||
|
||||
export async function setOldVersionPasscode({ application, passcode, version }) {
|
||||
const identifier = await application.encryptionService.crypto.generateUUID()
|
||||
const operator = application.encryptionService.operators.operatorForVersion(version)
|
||||
const identifier = await application.encryption.crypto.generateUUID()
|
||||
const operator = application.dependencies.get(TYPES.EncryptionOperators).operatorForVersion(version)
|
||||
const key = await operator.createRootKey(identifier, passcode, KeyParamsOrigination.PasscodeCreate)
|
||||
await application.encryptionService.setNewRootKeyWrapper(key)
|
||||
await application.userService.rewriteItemsKeys()
|
||||
await application.syncService.sync(syncOptions)
|
||||
await application.encryption.setNewRootKeyWrapper(key)
|
||||
await application.user.rewriteItemsKeys()
|
||||
await application.sync.sync(syncOptions)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,25 +127,26 @@ export async function setOldVersionPasscode({ application, passcode, version })
|
||||
export async function registerOldUser({ application, email, password, version }) {
|
||||
if (!email) email = Utils.generateUuid()
|
||||
if (!password) password = Utils.generateUuid()
|
||||
const operator = application.encryptionService.operators.operatorForVersion(version)
|
||||
const operator = application.dependencies.get(TYPES.EncryptionOperators).operatorForVersion(version)
|
||||
const accountKey = await operator.createRootKey(email, password, KeyParamsOrigination.Registration)
|
||||
|
||||
const response = await application.userApiService.register({
|
||||
const response = await application.dependencies.get(TYPES.UserApiService).register({
|
||||
email: email,
|
||||
serverPassword: accountKey.serverPassword,
|
||||
keyParams: accountKey.keyParams,
|
||||
})
|
||||
|
||||
/** Mark all existing items as dirty. */
|
||||
await application.mutator.changeItems(application.itemManager.items, (m) => {
|
||||
await application.mutator.changeItems(application.items.items, (m) => {
|
||||
m.dirty = true
|
||||
})
|
||||
await application.sessionManager.handleSuccessAuthResponse(response, accountKey)
|
||||
await application.sessions.handleSuccessAuthResponse(response, accountKey)
|
||||
application.notifyEvent(ApplicationEvent.SignedIn)
|
||||
await application.syncService.sync({
|
||||
await application.sync.sync({
|
||||
mode: SyncMode.DownloadFirst,
|
||||
...syncOptions,
|
||||
})
|
||||
await application.encryptionService.decryptErroredPayloads()
|
||||
await application.encryption.decryptErroredPayloads()
|
||||
}
|
||||
|
||||
export function createStorageItemPayload(contentType) {
|
||||
@@ -182,13 +183,13 @@ export async function createSyncedNote(application, title, text) {
|
||||
const payload = createNotePayload(title, text)
|
||||
const item = await application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
await application.mutator.setItemDirty(item)
|
||||
await application.syncService.sync(syncOptions)
|
||||
await application.sync.sync(syncOptions)
|
||||
const note = application.items.findItem(payload.uuid)
|
||||
return note
|
||||
}
|
||||
|
||||
export async function getStoragePayloadsOfType(application, type) {
|
||||
const rawPayloads = await application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await application.storage.getAllRawPayloads()
|
||||
return rawPayloads
|
||||
.filter((rp) => rp.content_type === type)
|
||||
.map((rp) => {
|
||||
@@ -263,7 +264,7 @@ export async function restartApplication(application) {
|
||||
}
|
||||
|
||||
export async function storagePayloadCount(application) {
|
||||
const payloads = await application.diskStorageService.getAllRawPayloads()
|
||||
const payloads = await application.storage.getAllRawPayloads()
|
||||
return payloads.length
|
||||
}
|
||||
|
||||
@@ -397,28 +398,28 @@ export async function insertItemWithOverride(application, contentType, content,
|
||||
errorDecrypting,
|
||||
})
|
||||
|
||||
await application.payloadManager.emitPayload(encrypted)
|
||||
await application.payloads.emitPayload(encrypted)
|
||||
} else {
|
||||
const decrypted = new DecryptedPayload({
|
||||
...item.payload.ejected(),
|
||||
})
|
||||
await application.payloadManager.emitPayload(decrypted)
|
||||
await application.payloads.emitPayload(decrypted)
|
||||
}
|
||||
|
||||
return application.itemManager.findAnyItem(item.uuid)
|
||||
return application.items.findAnyItem(item.uuid)
|
||||
}
|
||||
|
||||
export async function alternateUuidForItem(application, uuid) {
|
||||
const item = application.itemManager.findItem(uuid)
|
||||
const item = application.items.findItem(uuid)
|
||||
const payload = new DecryptedPayload(item)
|
||||
const results = await PayloadsByAlternatingUuid(payload, application.payloadManager.getMasterCollection())
|
||||
await application.payloadManager.emitPayloads(results, PayloadEmitSource.LocalChanged)
|
||||
await application.syncService.persistPayloads(results)
|
||||
return application.itemManager.findItem(results[0].uuid)
|
||||
const results = await PayloadsByAlternatingUuid(payload, application.payloads.getMasterCollection())
|
||||
await application.payloads.emitPayloads(results, PayloadEmitSource.LocalChanged)
|
||||
await application.sync.persistPayloads(results)
|
||||
return application.items.findItem(results[0].uuid)
|
||||
}
|
||||
|
||||
export async function markDirtyAndSyncItem(application, itemToLookupUuidFor) {
|
||||
const item = application.itemManager.findItem(itemToLookupUuidFor.uuid)
|
||||
const item = application.items.findItem(itemToLookupUuidFor.uuid)
|
||||
if (!item) {
|
||||
throw Error('Attempting to save non-inserted item')
|
||||
}
|
||||
@@ -433,11 +434,11 @@ export async function changePayloadTimeStampAndSync(application, payload, timest
|
||||
|
||||
await application.sync.sync(syncOptions)
|
||||
|
||||
return application.itemManager.findAnyItem(payload.uuid)
|
||||
return application.items.findAnyItem(payload.uuid)
|
||||
}
|
||||
|
||||
export async function changePayloadTimeStamp(application, payload, timestamp, contentOverride) {
|
||||
payload = application.payloadManager.collection.find(payload.uuid)
|
||||
payload = application.payloads.collection.find(payload.uuid)
|
||||
const changedPayload = new DecryptedPayload({
|
||||
...payload,
|
||||
dirty: true,
|
||||
@@ -451,11 +452,11 @@ export async function changePayloadTimeStamp(application, payload, timestamp, co
|
||||
|
||||
await application.mutator.emitItemFromPayload(changedPayload)
|
||||
|
||||
return application.itemManager.findAnyItem(payload.uuid)
|
||||
return application.items.findAnyItem(payload.uuid)
|
||||
}
|
||||
|
||||
export async function changePayloadUpdatedAt(application, payload, updatedAt) {
|
||||
const latestPayload = application.payloadManager.collection.find(payload.uuid)
|
||||
const latestPayload = application.payloads.collection.find(payload.uuid)
|
||||
|
||||
const changedPayload = new DecryptedPayload({
|
||||
...latestPayload.ejected(),
|
||||
@@ -468,7 +469,7 @@ export async function changePayloadUpdatedAt(application, payload, updatedAt) {
|
||||
}
|
||||
|
||||
export async function changePayloadTimeStampDeleteAndSync(application, payload, timestamp, syncOptions) {
|
||||
payload = application.payloadManager.collection.find(payload.uuid)
|
||||
payload = application.payloads.collection.find(payload.uuid)
|
||||
const changedPayload = new DeletedPayload({
|
||||
...payload,
|
||||
content: undefined,
|
||||
@@ -478,6 +479,6 @@ export async function changePayloadTimeStampDeleteAndSync(application, payload,
|
||||
updated_at_timestamp: timestamp,
|
||||
})
|
||||
|
||||
await application.payloadManager.emitPayload(changedPayload)
|
||||
await application.payloads.emitPayload(changedPayload)
|
||||
await application.sync.sync(syncOptions)
|
||||
}
|
||||
|
||||
@@ -139,8 +139,8 @@ export default class FakeWebCrypto {
|
||||
const data = {
|
||||
message,
|
||||
nonce,
|
||||
senderSecretKey,
|
||||
recipientPublicKey,
|
||||
senderSecretKey,
|
||||
}
|
||||
return btoa(JSON.stringify(data))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user