feat: add snjs package
This commit is contained in:
29
packages/snjs/lib/Services/Sync/Offline/Operation.ts
Normal file
29
packages/snjs/lib/Services/Sync/Offline/Operation.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
CreateOfflineSyncSavedPayload,
|
||||
DecryptedPayloadInterface,
|
||||
DeletedPayloadInterface,
|
||||
} from '@standardnotes/models'
|
||||
import { ResponseSignalReceiver, SyncSignal } from '@Lib/Services/Sync/Signals'
|
||||
|
||||
import { OfflineSyncResponse } from './Response'
|
||||
|
||||
export class OfflineSyncOperation {
|
||||
/**
|
||||
* @param payloads An array of payloads to sync offline
|
||||
* @param receiver A function that receives callback multiple times during the operation
|
||||
*/
|
||||
constructor(
|
||||
private payloads: (DecryptedPayloadInterface | DeletedPayloadInterface)[],
|
||||
private receiver: ResponseSignalReceiver<OfflineSyncResponse>,
|
||||
) {}
|
||||
|
||||
async run() {
|
||||
const responsePayloads = this.payloads.map((payload) => {
|
||||
return CreateOfflineSyncSavedPayload(payload)
|
||||
})
|
||||
|
||||
const response = new OfflineSyncResponse(responsePayloads)
|
||||
|
||||
await this.receiver(SyncSignal.Response, response)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user