1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 09:43:23 +00:00
Files
browser/libs/common/src/platform/messaging/helpers.ts
Justin Baur 25f55e1368 [PM-7978] Create ForegroundSyncService For Delegating fullSync Calls (#9192)
* Create ForegroundSyncService For Delegating `fullSync` calls to the background

* Relax `isExternalMessage` to Allow For Typed Payload

* Null Coalesce The `startListening` Method

* Filter To Only External Messages
2024-05-15 12:11:06 -04:00

24 lines
712 B
TypeScript

import { MonoTypeOperatorFunction, map } from "rxjs";
import { Message, CommandDefinition } from "./types";
export const getCommand = (commandDefinition: CommandDefinition<object> | string) => {
if (typeof commandDefinition === "string") {
return commandDefinition;
} else {
return commandDefinition.command;
}
};
export const EXTERNAL_SOURCE_TAG = Symbol("externalSource");
export const isExternalMessage = (message: Record<PropertyKey, unknown>) => {
return message?.[EXTERNAL_SOURCE_TAG] === true;
};
export const tagAsExternal: MonoTypeOperatorFunction<Message<object>> = map(
(message: Message<object>) => {
return Object.assign(message, { [EXTERNAL_SOURCE_TAG]: true });
},
);