feat: add type definition to signal recipients

follows more the notifications way of setting recipients and is more
future proof

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2024-03-13 13:10:55 +02:00
parent b76d0cd4f9
commit 6c1547a4fb
9 changed files with 41 additions and 18 deletions
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { DefaultSignalsService } from './DefaultSignalsService';
import { SignalPayload } from './types';
describe('DefaultSignalsService', () => {
const mockEvents = {
@@ -24,9 +25,9 @@ describe('DefaultSignalsService', () => {
const service = DefaultSignalsService.create({ events: mockEvents });
it('should publish signal', () => {
const signal = {
const signal: SignalPayload = {
channel: 'test-channel',
recipients: null,
recipients: { type: 'broadcast' },
message: { msg: 'hello world' },
};
service.publish(signal);
+3 -1
View File
@@ -25,7 +25,9 @@ export type SignalsServiceOptions = {
/** @public */
export type SignalPayload<TMessage extends JsonObject = JsonObject> = {
recipients: string[] | string | null;
recipients:
| { type: 'user'; entityRefs: string | string[] }
| { type: 'broadcast' };
channel: string;
message: TMessage;
};