/** * Typed event definitions for the unstable event-log system. * * An `Event` is the durable contract shared by writers, handlers, journals, and * replicas. It gives an event a stable tag, derives the aggregate or entity * primary key from the decoded payload, and records the schemas used for the * payload, handler result, and handler errors. The payload schema is also used * to derive the SchemaBinary encoding for journal entries and remote * replication. * * @stability unstable * @since 4.0.0 */ import * as SchemaBinary from "../encoding/SchemaBinary.ts"; import * as Schema from "../Schema.ts"; /** * Unique type identifier used to mark event log event definitions. * * @stability unstable * @category type IDs * @since 4.0.0 */ export type TypeId = "~effect/eventlog/Event"; /** * Runtime type identifier used to mark event log event definitions. * * @stability unstable * @category type IDs * @since 4.0.0 */ export declare const TypeId: TypeId; /** * Returns `true` when a value is an event log event definition. * * @stability unstable * @category guards * @since 4.0.0 */ export declare const isEvent: (u: unknown) => u is Event; /** * Definition of an event type that can be written to an `EventLog`. * * **Details** * * An event definition contains its tag, primary-key function, payload schema, * SchemaBinary payload codec, success schema, and error schema. * * @stability unstable * @category models * @since 4.0.0 */ export interface Event { readonly [TypeId]: TypeId; readonly tag: Tag; readonly primaryKey: (payload: Schema.Schema.Type) => string; readonly payload: Payload; readonly payloadSchemaBinary: SchemaBinary.toCodec; readonly success: Success; readonly error: Error; } /** * Marker service associated with the handler for an event tag. * * **Details** * * `ToService` derives this service from an `Event` so handler layers can expose * which events they implement. * * @stability unstable * @category models * @since 4.0.0 */ export interface EventHandler { readonly _: unique symbol; readonly tag: Tag; } /** * Type-erased event log event definition. * * **Details** * * It preserves the runtime tag, primary-key function, payload schema, success * schema, and error schema without retaining the original type parameters. * * @stability unstable * @category models * @since 4.0.0 */ export interface Any { readonly [TypeId]: TypeId; readonly tag: string; readonly primaryKey: (payload: any) => string; readonly payload: Schema.Top; readonly payloadSchemaBinary: SchemaBinary.toCodec; readonly success: Schema.Top; readonly error: Schema.Top; } /** * Type-erased event definition with its runtime properties available * structurally. * * @stability unstable * @category models * @since 4.0.0 */ export interface AnyWithProps extends Any { } /** * Derives the handler service marker for an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type ToService = A extends Event ? EventHandler<_Tag> : never; /** * Extracts the tag string from an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type Tag = A extends Event ? _Tag : never; /** * Extracts the error schema from an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type ErrorSchema = A extends Event ? _Error : never; /** * Decoded error value type for an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type Error = Schema.Schema.Type>; /** * Returns an event definition type whose error schema also includes the provided * error schema. * * @stability unstable * @category utility types * @since 4.0.0 */ export type AddError = A extends Event ? Event<_Tag, _Payload, _Success, _Error | Error> : never; /** * Extracts the payload schema from an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type PayloadSchema = A extends Event ? _Payload : never; /** * Extracts the payload schema for the event in a union with the specified tag. * * @stability unstable * @category utility types * @since 4.0.0 */ export type PayloadSchemaWithTag = A extends Event ? _Payload : never; /** * Decoded payload value type for an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type Payload = Schema.Schema.Type>; /** * Tagged payload value for an event definition. * * **Details** * * The result contains `_tag` set to the event tag and `payload` set to the * decoded payload value. * * @stability unstable * @category utility types * @since 4.0.0 */ export type TaggedPayload = A extends Event ? { readonly _tag: _Tag; readonly payload: Schema.Schema.Type<_Payload>; } : never; /** * Extracts the success schema from an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type SuccessSchema = A extends Event ? _Success : never; /** * Decoded success value type for an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type Success = Schema.Schema.Type>; /** * Schema services required by a client for an event definition. * * **Details** * * This includes payload encoding services plus success and error decoding * services. * * @stability unstable * @category utility types * @since 4.0.0 */ export type ServicesClient = A extends Event ? _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] : never; /** * Schema services required by a server for an event definition. * * **Details** * * This includes payload decoding services plus success and error encoding * services. * * @stability unstable * @category utility types * @since 4.0.0 */ export type ServicesServer = A extends Event ? _Payload["DecodingServices"] | _Success["EncodingServices"] | _Error["EncodingServices"] : never; /** * All schema services required to encode and decode the payload, success, and * error schemas for an event definition. * * @stability unstable * @category utility types * @since 4.0.0 */ export type Services = A extends Event ? _Payload["DecodingServices"] | _Success["EncodingServices"] | _Error["EncodingServices"] | _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] : never; /** * Extracts the event definition with the specified tag from an event union. * * @stability unstable * @category utility types * @since 4.0.0 */ export type WithTag = Extract; /** * Removes event definitions with the specified tag from an event union. * * @stability unstable * @category utility types * @since 4.0.0 */ export type ExcludeTag = Exclude; /** * Decoded payload value type for the event in a union with the specified tag. * * @stability unstable * @category utility types * @since 4.0.0 */ export type PayloadWithTag = Payload>; /** * Decoded success value type for the event in a union with the specified tag. * * @stability unstable * @category utility types * @since 4.0.0 */ export type SuccessWithTag = Success>; /** * Decoded error value type for the event in a union with the specified tag. * * @stability unstable * @category utility types * @since 4.0.0 */ export type ErrorWithTag = Error>; /** * Client-side schema services required for the event in a union with the specified * tag. * * @stability unstable * @category utility types * @since 4.0.0 */ export type ServicesClientWithTag = ServicesClient>; /** * Creates an event log event definition. * * **Details** * * If omitted, the payload and success schemas default to `Schema.Void`, the error * schema defaults to `Schema.Never`, and the SchemaBinary payload codec is derived * from the payload schema. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare function make(options: { readonly tag: Tag; readonly primaryKey: (payload: Schema.Schema.Type) => string; readonly payload?: Payload | undefined; readonly success?: Success | undefined; readonly error?: Error | undefined; }): Event; /** * Adds another error schema to an event definition. * * **Details** * * The returned event keeps the same tag, primary key, payload, and success schema * while replacing the error schema with a union of the existing and new errors. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare function addError(event: A, error: Error2): AddError; //# sourceMappingURL=Event.d.ts.map