/** * Represents a standard event structure used in the RPC system. * * @remarks * Events are the primary mechanism for communication between the client and worker. * They carry a type identifier and a payload. * * @template Payload - The type of the data carried by the event. */ export type Event = { /** * The unique identifier for the event type. */ type: string; /** * The data associated with the event. */ payload: Payload; }; /** * A callable interface that creates an event and provides utilities for matching it. * * @template Payload - The type of the payload this event creator accepts and produces. */ export interface EventCreator { /** * Creates an event instance with the given payload. * * @param payload - The data to include in the event. * @returns A new Event object. */ (payload: Payload): Event; /** * The string type identifier associated with this event creator. */ type: string; /** * Type guard to check if a generic event matches this creator's type. * * @param event - The event to check. * @returns True if the event matches this creator's type, narrowing the payload type. */ match(event: Event): event is Event; } /** * Generates a new event creator function with matching capabilities. * * @remarks * This factory function produces an `EventCreator` which acts as both a factory for creating * events of a specific type and a utility for checking if an incoming event matches that type. * * @template Payload - The type of the payload for the created events. * @param type - A unique string identifier for the event type. * @returns An `EventCreator` function with static `type` and `match` properties. * * @example * ```ts * const MY_EVENT = createEvent<{ id: string }>("MY_EVENT"); * * // Create an event * const event = MY_EVENT({ id: "123" }); * * // Check if an event matches * if (MY_EVENT.match(someEvent)) { * console.log(someEvent.payload.id); // Type-safe access * } * ``` */ export declare function createEvent(type: string): EventCreator; /** * Type guard to determine if a value is a valid Event object. * * @remarks * Checks if the value is a non-null object containing a "type" property. * * @param value - The value to inspect. * @returns True if the value conforms to the `Event` interface. * * @example * ```ts * if (isEvent(someValue)) { * console.log(someValue.type); * } * ``` */ export declare function isEvent(value: unknown): value is Event;