-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathIMessage.ts
More file actions
29 lines (21 loc) · 834 Bytes
/
Copy pathIMessage.ts
File metadata and controls
29 lines (21 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { Identifier } from './Identifier.ts';
import { isObject } from './isObject.ts';
export interface IMessage<TPayload = unknown> {
/** Event or command type */
type: string;
/** Target aggregate identifier for commands, originating aggregate identifier for events */
aggregateId?: Identifier;
/** Aggregate version at the time of the message */
aggregateVersion?: number;
/** Starter event ids of sagas associated with this message, keyed by saga descriptor */
sagaOrigins?: Record<string, string>;
/** Business data */
payload: TPayload;
/** Optional metadata/context (e.g. auth info, request id); set on commands, copied to events */
context?: any;
}
export const isMessage = (obj: unknown): obj is IMessage =>
isObject(obj)
&& 'type' in obj
&& typeof obj.type === 'string'
&& obj.type.length > 0;