import type { Brand } from "../../Brand.ts"; import * as Context from "../../Context.ts"; import * as DateTime from "../../DateTime.ts"; import * as Effect from "../../Effect.ts"; import * as Layer from "../../Layer.ts"; import * as Order from "../../Order.ts"; import * as PubSub from "../../PubSub.ts"; import * as Schema from "../../Schema.ts"; import type { Scope } from "../../Scope.ts"; import * as Msgpack from "../encoding/Msgpack.ts"; import type { StoreId } from "./EventLogMessage.ts"; declare const EventJournal_base: Context.ServiceClass, EventJournalError>; /** * Write an event to the journal, performing an effect before committing the * event. */ readonly write: (options: { readonly event: string; readonly primaryKey: string; readonly payload: Uint8Array; readonly effect: (entry: Entry) => Effect.Effect; }) => Effect.Effect; /** * Write events from a remote source to the journal. * * **Details** * * Effects run sequentially in compaction bracket order. */ readonly writeFromRemote: (options: { readonly remoteId: RemoteId; readonly entries: ReadonlyArray; readonly compact?: ((uncommitted: ReadonlyArray) => Effect.Effect, EventJournalError>) | undefined; readonly effect: (options: { readonly entry: Entry; readonly conflicts: ReadonlyArray; }) => Effect.Effect; }) => Effect.Effect<{ readonly duplicateEntries: ReadonlyArray; }, EventJournalError>; /** * Return the uncommitted entries for a remote source. */ readonly withRemoteUncommited: (remoteId: RemoteId, f: (entries: ReadonlyArray) => Effect.Effect) => Effect.Effect; /** * Retrieve the last known sequence number for a remote source. */ readonly nextRemoteSequence: (remoteId: RemoteId) => Effect.Effect; /** * The entries added to the local journal. */ readonly changes: Effect.Effect, never, Scope>; /** * Remove all data */ readonly destroy: Effect.Effect; /** * Run an effect with a lock on the journal. */ readonly withLock: (storeId: StoreId) => (effect: Effect.Effect) => Effect.Effect; }>; /** * Context service for storing and replaying event journal entries. * * **Details** * * The service writes local entries, imports entries from remote journals, exposes * a stream of local changes, and provides per-store locking. * * @category context * @since 4.0.0 */ export declare class EventJournal extends EventJournal_base { } declare const TypeId: "effect/eventlog/EventJournal/EventJournalError"; declare const EventJournalError_base: new = {}>(args: import("../../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("../../Cause.ts").YieldableError & { readonly _tag: "EventJournalError"; } & Readonly; /** * Error raised by event journal operations. * * **Details** * * The error records the journal method that failed and the underlying cause. * * @category errors * @since 4.0.0 */ export declare class EventJournalError extends EventJournalError_base<{ readonly method: string; readonly cause: unknown; }> { /** * Marks this value as an event journal error for runtime guards. * * @since 4.0.0 */ readonly [TypeId]: "effect/eventlog/EventJournal/EventJournalError"; } /** * Brand identifier used for `RemoteId` values. * * @category type IDs * @since 4.0.0 */ export type RemoteIdTypeId = "effect/eventlog/EventJournal/RemoteId"; /** * Runtime brand identifier used for `RemoteId` values. * * @category type IDs * @since 4.0.0 */ export declare const RemoteIdTypeId: RemoteIdTypeId; /** * Branded byte identifier for a remote event journal source. * * @category remote * @since 4.0.0 */ export type RemoteId = Uint8Array & Brand; /** * Schema for branded remote event journal identifiers. * * @category remote * @since 4.0.0 */ export declare const RemoteId: Schema.brand; /** * Generates a new random `RemoteId`. * * **When to use** * * Use when generating a fresh event-log remote id internally and the UUID bytes * are trusted to satisfy the brand. * * **Gotchas** * * This is unsafe because the generated UUID bytes are cast to the brand without * schema validation. * * @category remote * @since 4.0.0 */ export declare const makeRemoteIdUnsafe: () => RemoteId; /** * Runtime brand identifier used for `EntryId` values. * * @category type IDs * @since 4.0.0 */ export declare const EntryIdTypeId: EntryIdTypeId; /** * Brand identifier used for `EntryId` values. * * @category type IDs * @since 4.0.0 */ export type EntryIdTypeId = "effect/eventlog/EventJournal/EntryId"; /** * Branded byte identifier for an event journal entry. * * @category entry * @since 4.0.0 */ export type EntryId = Uint8Array & Brand; /** * Schema for branded event journal entry identifiers. * * @category entry * @since 4.0.0 */ export declare const EntryId: Schema.brand, Uint8Array>, "effect/eventlog/EventJournal/EntryId">; /** * Provides an Ordering instance for entry identifiers based on their raw UUID bytes. * * @category entry * @since 4.0.0 */ export declare const EntryIdOrder: Order.Order; /** * Generates a UUID v7 `EntryId`, optionally using the supplied millisecond * timestamp. * * **When to use** * * Use when generating an event-log entry id internally and the UUID v7 bytes * are trusted to satisfy the brand. * * **Gotchas** * * This is unsafe because the generated UUID bytes are cast to the brand without * schema validation. * * @category entry * @since 4.0.0 */ export declare const makeEntryIdUnsafe: (options?: { msecs?: number; }) => EntryId; /** * Extracts the millisecond timestamp encoded in a UUID v7 `EntryId`. * * @category entry * @since 4.0.0 */ export declare const entryIdMillis: (entryId: EntryId) => number; declare const Entry_base: Schema.Class, Uint8Array>, "effect/eventlog/EventJournal/EntryId">; readonly event: Schema.String; readonly primaryKey: Schema.String; readonly payload: Schema.Uint8Array; }>, {}>; /** * Schema for a committed event journal entry. * * **Details** * * An entry records its ID, event tag, primary key, and MessagePack-encoded * payload, with helpers for array MessagePack encoding and creation timestamps. * * @category entry * @since 4.0.0 */ export declare class Entry extends Entry_base { /** * MessagePack schema for arrays of committed event journal entries. * * @since 4.0.0 */ static arrayMsgpack: Schema.$Array>; /** * Encodes arrays of committed entries with the MessagePack entry schema. * * @since 4.0.0 */ static encodeArray: (input: unknown, options?: import("../../SchemaAST.ts").ParseOptions) => Effect.Effect[], Schema.SchemaError, never>; /** * Decodes arrays of committed entries with the MessagePack entry schema. * * @since 4.0.0 */ static decodeArray: (input: unknown, options?: import("../../SchemaAST.ts").ParseOptions) => Effect.Effect; /** * Ordering for committed entries by their event journal entry id. * * @since 4.0.0 */ static Order: Order.Order; /** * String representation of the entry id. * * @since 4.0.0 */ get idString(): string; /** * Creation timestamp encoded in the UUID v7 entry id, in epoch milliseconds. * * @since 4.0.0 */ get createdAtMillis(): number; /** * Creation timestamp encoded in the UUID v7 entry id, as a UTC date-time. * * @since 4.0.0 */ get createdAt(): DateTime.Utc; } declare const RemoteEntry_base: Schema.Class, {}>; /** * Schema for an event journal entry received from a remote source. * * **Details** * * It pairs the remote sequence number with the journal entry payload. * * @category entry * @since 4.0.0 */ export declare class RemoteEntry extends RemoteEntry_base { } /** * Creates an in-memory `EventJournal` service. * * **Gotchas** * * Entries, remote tracking state, and locks live only in the current process and * are lost when the service is discarded. * * @category memory * @since 4.0.0 */ export declare const makeMemory: Effect.Effect; /** * Layer that provides an in-memory `EventJournal`. * * **Gotchas** * * All journal data is stored in process memory and is not persisted across layer * lifetimes. * * @category memory * @since 4.0.0 */ export declare const layerMemory: Layer.Layer; /** * Creates an `EventJournal` backed by IndexedDB. * * **Details** * * The journal stores entries and remote replication metadata in the configured * browser database, publishes local changes, and requires `Scope` so the database * connection can be closed when the scope ends. * * @category indexed db * @since 4.0.0 */ export declare const makeIndexedDb: (options?: { readonly database?: string; }) => Effect.Effect; /** * Provides `EventJournal` using the IndexedDB-backed implementation created by * `makeIndexedDb`. * * @category indexed db * @since 4.0.0 */ export declare const layerIndexedDb: (options?: { readonly database?: string; }) => Layer.Layer; export {}; //# sourceMappingURL=EventJournal.d.ts.map