mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
[PM-7837] Move SyncService to Platform Ownership (#9055)
* Move * Update References In Unowned Files * Update References In Vault Files * Update Web AppComponent * Add Import
This commit is contained in:
38
libs/common/src/platform/sync/sync-event-args.ts
Normal file
38
libs/common/src/platform/sync/sync-event-args.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { SyncResponse } from "./sync.response";
|
||||
|
||||
type SyncStatus = "Started" | "Completed";
|
||||
|
||||
type SyncEventArgsBase<T extends SyncStatus> = {
|
||||
status: T;
|
||||
};
|
||||
|
||||
type SyncCompletedEventArgsBase<T extends boolean> = SyncEventArgsBase<"Completed"> & {
|
||||
successfully: T;
|
||||
};
|
||||
|
||||
type SyncSuccessfullyCompletedEventArgs = SyncCompletedEventArgsBase<true> & {
|
||||
data: SyncResponse;
|
||||
};
|
||||
|
||||
export type SyncEventArgs =
|
||||
| SyncSuccessfullyCompletedEventArgs
|
||||
| SyncCompletedEventArgsBase<false>
|
||||
| SyncEventArgsBase<"Started">;
|
||||
|
||||
/**
|
||||
* Helper function to filter only on successfully completed syncs
|
||||
* @returns a function that can be used in a `.pipe(filter(...))` from an observable
|
||||
* @example
|
||||
* ```
|
||||
* of<SyncEventArgs>({ status: "Completed", successfully: true, data: new SyncResponse() })
|
||||
* .pipe(filter(isSuccessfullyCompleted))
|
||||
* .subscribe(event => {
|
||||
* console.log(event.data);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function isSuccessfullyCompleted(
|
||||
syncEvent: SyncEventArgs,
|
||||
): syncEvent is SyncSuccessfullyCompletedEventArgs {
|
||||
return syncEvent.status === "Completed" && syncEvent.successfully;
|
||||
}
|
||||
Reference in New Issue
Block a user