UNPKG

@codeforbreakfast/eventsourcing-store-postgres

Version:

Production-ready PostgreSQL event store with Effect integration - Scalable, ACID-compliant event persistence with type-safe database operations and streaming

76 lines 4.97 kB
import { SqlClient } from '@effect/sql'; import { Effect, Layer, Schema, Stream } from 'effect'; import { EventStreamId, type EventStore, EventStoreError } from '@codeforbreakfast/eventsourcing-store'; import { NotificationListener, type NotificationPayload } from './notificationListener'; import { SubscriptionManager, type SubscriptionManagerService } from './subscriptionManager'; interface EventRowServiceInterface { readonly insert: (row: EventRow) => Effect.Effect<EventRow, unknown, never>; readonly selectAllEventsInStream: (streamId: EventStreamId) => Effect.Effect<readonly EventRow[], unknown, never>; readonly selectAllEvents: (nullValue: Schema.Schema.Type<typeof Schema.Null>) => Effect.Effect<readonly EventRow[], unknown, never>; } declare const EventRowService_base: import("effect/Context").TagClass<EventRowService, "EventRowService", EventRowServiceInterface> & Effect.Tag.Proxy<EventRowService, EventRowServiceInterface> & { use: <X>(body: (_: EventRowServiceInterface) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, R | EventRowService> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, import("effect/Cause").UnknownException, EventRowService> : Effect.Effect<X, never, EventRowService>; }; export declare class EventRowService extends EventRowService_base { } declare const EventRow_base: Schema.Class<EventRow, { stream_id: Schema.brand<Schema.filter<typeof Schema.String>, "EventStreamId">; event_number: Schema.filter<typeof Schema.Number>; event_payload: typeof Schema.String; }, Schema.Struct.Encoded<{ stream_id: Schema.brand<Schema.filter<typeof Schema.String>, "EventStreamId">; event_number: Schema.filter<typeof Schema.Number>; event_payload: typeof Schema.String; }>, never, { readonly stream_id: string & import("effect/Brand").Brand<"EventStreamId">; } & { readonly event_number: number; } & { readonly event_payload: string; }, {}, {}>; declare class EventRow extends EventRow_base { } /** * Layer that provides EventRowService */ export declare const EventRowServiceLive: Layer.Layer<EventRowService, EventStoreError, SqlClient.SqlClient>; /** * Combined layer that provides all the required services for real-time event subscriptions * Organized into logical groups for better understanding and testability */ export declare const EventSubscriptionServicesLive: Layer.Layer<import("./eventStreamTracker").EventStreamTracker | NotificationListener | SubscriptionManager, import("@codeforbreakfast/eventsourcing-store").EventStoreConnectionError, import("@effect/sql-pg/PgClient").PgClient>; /** * Create a SQL-based EventStore with subscription support and PostgreSQL LISTEN/NOTIFY */ export declare const makeSqlEventStoreWithSubscriptionManager: (subscriptionManager: SubscriptionManagerService, notificationListener: Readonly<{ readonly listen: (streamId: EventStreamId) => Effect.Effect<void, EventStoreError, never>; readonly unlisten: (streamId: EventStreamId) => Effect.Effect<void, EventStoreError, never>; readonly listenAll: Effect.Effect<void, EventStoreError, never>; readonly unlistenAll: Effect.Effect<void, EventStoreError, never>; readonly notifications: Stream.Stream<{ readonly streamId: EventStreamId; readonly payload: NotificationPayload; readonly isAllEvents: boolean; }, EventStoreError, never>; readonly start: Effect.Effect<void, EventStoreError, never>; readonly stop: Effect.Effect<void, EventStoreError, never>; }>) => Effect.Effect<EventStore<string>, EventStoreError, EventRowService>; declare const SqlEventStore_base: import("effect/Context").TagClass<SqlEventStore, "SqlEventStore", EventStore<string>> & Effect.Tag.Proxy<SqlEventStore, EventStore<string>> & { use: <X>(body: (_: EventStore<string>) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, R | SqlEventStore> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, import("effect/Cause").UnknownException, SqlEventStore> : Effect.Effect<X, never, SqlEventStore>; }; /** * Layer that provides a SQL EventStore with properly shared SubscriptionManager and NotificationListener */ export declare class SqlEventStore extends SqlEventStore_base { } /** * Main SQL EventStore layer with simplified dependency management * Uses the logical layer groups defined above for clearer composition */ export declare const SqlEventStoreLive: Layer.Layer<SqlEventStore, import("@codeforbreakfast/eventsourcing-store").EventStoreConnectionError | EventStoreError, SqlClient.SqlClient | import("@effect/sql-pg/PgClient").PgClient>; /** * Backward-compatible function - requires SubscriptionManager and NotificationListener in context */ export declare const sqlEventStore: Effect.Effect<EventStore<string>, EventStoreError, EventRowService | SubscriptionManager | NotificationListener>; export {}; //# sourceMappingURL=sqlEventStore.d.ts.map