UNPKG

@codeforbreakfast/eventsourcing-protocol-default

Version:

Default implementation of the event sourcing protocol over any transport - Standard protocol implementation with message serialization, command correlation, and subscription management

143 lines 6.8 kB
import { Effect, Stream, Schema, Layer } from 'effect'; import { type Client, type TransportError } from '@codeforbreakfast/eventsourcing-transport-contracts'; declare const CommandTimeoutError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "CommandTimeoutError"; } & Readonly<A>; export declare class CommandTimeoutError extends CommandTimeoutError_base<{ readonly commandId: string; readonly timeoutMs: number; }> { } declare const ProtocolValidationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "ProtocolValidationError"; } & Readonly<A>; export declare class ProtocolValidationError extends ProtocolValidationError_base<{ readonly message: string; readonly rawData: unknown; readonly cause?: unknown; }> { } declare const ProtocolStateError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & { readonly _tag: "ProtocolStateError"; } & Readonly<A>; export declare class ProtocolStateError extends ProtocolStateError_base<{ readonly operation: string; readonly reason: string; }> { } export declare const Command: Schema.Struct<{ id: typeof Schema.String; target: typeof Schema.String; name: typeof Schema.String; payload: typeof Schema.Unknown; }>; export type Command = typeof Command.Type; export declare const Event: Schema.Struct<{ position: Schema.Struct<{ streamId: Schema.brand<Schema.filter<typeof Schema.String>, "EventStreamId">; eventNumber: Schema.filter<typeof Schema.Number>; }>; type: typeof Schema.String; data: typeof Schema.Unknown; timestamp: typeof Schema.Date; }>; export type Event = typeof Event.Type; export declare const CommandResult: Schema.Union<[Schema.Struct<{ _tag: Schema.Literal<["Success"]>; position: Schema.Struct<{ streamId: Schema.brand<Schema.filter<typeof Schema.String>, "EventStreamId">; eventNumber: Schema.filter<typeof Schema.Number>; }>; }>, Schema.Struct<{ _tag: Schema.Literal<["Failure"]>; error: typeof Schema.String; }>]>; export type CommandResult = typeof CommandResult.Type; export declare const CommandMessage: Schema.Struct<{ type: Schema.Literal<["command"]>; id: typeof Schema.String; target: typeof Schema.String; name: typeof Schema.String; payload: typeof Schema.Unknown; }>; export type CommandMessage = typeof CommandMessage.Type; export declare const SubscribeMessage: Schema.Struct<{ type: Schema.Literal<["subscribe"]>; streamId: typeof Schema.String; }>; export type SubscribeMessage = typeof SubscribeMessage.Type; export declare const CommandResultMessage: Schema.Struct<{ type: Schema.Literal<["command_result"]>; commandId: typeof Schema.String; success: typeof Schema.Boolean; position: Schema.optional<Schema.Struct<{ streamId: Schema.brand<Schema.filter<typeof Schema.String>, "EventStreamId">; eventNumber: Schema.filter<typeof Schema.Number>; }>>; error: Schema.optional<typeof Schema.String>; }>; export type CommandResultMessage = typeof CommandResultMessage.Type; export declare const EventMessage: Schema.Struct<{ type: Schema.Literal<["event"]>; streamId: typeof Schema.String; position: Schema.Struct<{ streamId: Schema.brand<Schema.filter<typeof Schema.String>, "EventStreamId">; eventNumber: Schema.filter<typeof Schema.Number>; }>; eventType: typeof Schema.String; data: typeof Schema.Unknown; timestamp: typeof Schema.DateFromString; }>; export type EventMessage = typeof EventMessage.Type; export declare const IncomingMessage: Schema.Union<[Schema.Struct<{ type: Schema.Literal<["command_result"]>; commandId: typeof Schema.String; success: typeof Schema.Boolean; position: Schema.optional<Schema.Struct<{ streamId: Schema.brand<Schema.filter<typeof Schema.String>, "EventStreamId">; eventNumber: Schema.filter<typeof Schema.Number>; }>>; error: Schema.optional<typeof Schema.String>; }>, Schema.Struct<{ type: Schema.Literal<["event"]>; streamId: typeof Schema.String; position: Schema.Struct<{ streamId: Schema.brand<Schema.filter<typeof Schema.String>, "EventStreamId">; eventNumber: Schema.filter<typeof Schema.Number>; }>; eventType: typeof Schema.String; data: typeof Schema.Unknown; timestamp: typeof Schema.DateFromString; }>]>; export type IncomingMessage = typeof IncomingMessage.Type; export interface ProtocolService { readonly sendCommand: (command: Command) => Effect.Effect<CommandResult, TransportError | CommandTimeoutError | ProtocolValidationError, never>; readonly subscribe: (streamId: string) => Effect.Effect<Stream.Stream<Event, ProtocolValidationError, never>, TransportError | ProtocolValidationError, never>; } declare const Protocol_base: import("effect/Context").TagClass<Protocol, "Protocol", ProtocolService> & Effect.Tag.Proxy<Protocol, ProtocolService> & { use: <X>(body: (_: ProtocolService) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, Protocol | R> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, import("effect/Cause").UnknownException, Protocol> : Effect.Effect<X, never, Protocol>; }; export declare class Protocol extends Protocol_base { } export declare const ProtocolLive: (transport: Client.Transport) => Layer.Layer<Protocol, TransportError, never>; export declare const sendCommand: (command: Command) => Effect.Effect<{ readonly position: { readonly streamId: string & import("effect/Brand").Brand<"EventStreamId">; readonly eventNumber: number; }; readonly _tag: "Success"; } | { readonly _tag: "Failure"; readonly error: string; }, CommandTimeoutError | ProtocolValidationError | TransportError, Protocol>; export declare const subscribe: (streamId: string) => Effect.Effect<Stream.Stream<{ readonly position: { readonly streamId: string & import("effect/Brand").Brand<"EventStreamId">; readonly eventNumber: number; }; readonly type: string; readonly data: unknown; readonly timestamp: Date; }, ProtocolValidationError, never>, ProtocolValidationError | TransportError, Protocol>; export {}; //# sourceMappingURL=protocol.d.ts.map