woltage
Version:
A CQRS and Event-Sourcing Framework
59 lines (58 loc) • 1.81 kB
TypeScript
import { z } from 'zod/v4';
type NewEventData<TPayload extends z.ZodType, TMeta = any> = {
aggregateId?: string;
payload: z.infer<TPayload>;
meta?: TMeta;
};
type EventData<TPayload extends z.ZodType, TMeta = any> = NewEventData<TPayload> & {
id: string;
type: string;
version: number;
timestamp: number;
aggregateId: string;
correlationId: string;
causationId: string | null;
meta: TMeta;
position: bigint;
};
export type EventConstructionData<TPayload extends z.ZodType, TMeta = any> = EventData<TPayload, TMeta> | NewEventData<TPayload, TMeta>;
export type EventIdentity = {
type: string;
version: number;
};
export default class Event<TPayload extends z.ZodType = any, TMeta = any> implements EventData<TPayload, TMeta> {
['constructor']: typeof Event;
static schema: z.ZodType;
static version: number;
static toString(): string;
static get type(): string;
static get identity(): string;
static validate(payload: unknown): unknown;
static fromJSON(data: EventData<any>, shouldValidate?: boolean): Event<any, any>;
id: string;
timestamp: number;
aggregateId: string;
payload: z.infer<TPayload>;
correlationId: string;
causationId: string | null;
meta: TMeta;
position: bigint;
constructor(data: EventConstructionData<TPayload, TMeta>, shouldValidate?: boolean);
toString(): string;
get type(): string;
get version(): number;
get identity(): string;
toJSON(): {
id: string;
type: string;
version: number;
timestamp: number;
aggregateId: string;
payload: z.core.output<TPayload>;
correlationId: string;
causationId: string | null;
meta: TMeta;
position: bigint;
};
}
export {};