File size: 10,486 Bytes
31e8457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b110ca
 
31e8457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b110ca
 
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
 
 
 
 
 
1b110ca
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
 
 
 
1b110ca
 
31e8457
 
 
 
 
1b110ca
 
 
31e8457
 
 
 
1b110ca
 
 
31e8457
 
 
 
1b110ca
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
 
 
 
 
 
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
 
31e8457
 
 
 
1b110ca
 
 
31e8457
 
 
 
1b110ca
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
 
 
 
 
 
 
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
 
 
1b110ca
 
31e8457
1b110ca
31e8457
 
 
 
 
 
 
 
 
1b110ca
 
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
31e8457
 
 
 
1b110ca
 
31e8457
 
 
 
1b110ca
 
31e8457
 
 
 
1b110ca
 
31e8457
 
 
 
1b110ca
 
31e8457
 
 
 
1b110ca
 
31e8457
 
 
 
1b110ca
 
31e8457
 
 
 
 
 
 
 
 
1b110ca
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
 
1b110ca
 
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
1b110ca
 
 
 
 
 
 
 
31e8457
1b110ca
31e8457
 
 
 
 
1b110ca
 
 
31e8457
1b110ca
31e8457
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
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<EventJournal, "effect/eventlog/EventJournal", {
    /**
     * Read all the entries in the journal.
     */
    readonly entries: Effect.Effect<ReadonlyArray<Entry>, EventJournalError>;
    /**
     * Write an event to the journal, performing an effect before committing the
     * event.
     */
    readonly write: <A, E, R>(options: {
        readonly event: string;
        readonly primaryKey: string;
        readonly payload: Uint8Array;
        readonly effect: (entry: Entry) => Effect.Effect<A, E, R>;
    }) => Effect.Effect<A, EventJournalError | E, R>;
    /**
     * 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<RemoteEntry>;
        readonly compact?: ((uncommitted: ReadonlyArray<RemoteEntry>) => Effect.Effect<ReadonlyArray<Entry>, EventJournalError>) | undefined;
        readonly effect: (options: {
            readonly entry: Entry;
            readonly conflicts: ReadonlyArray<Entry>;
        }) => Effect.Effect<void, EventJournalError>;
    }) => Effect.Effect<{
        readonly duplicateEntries: ReadonlyArray<Entry>;
    }, EventJournalError>;
    /**
     * Return the uncommitted entries for a remote source.
     */
    readonly withRemoteUncommited: <A, E, R>(remoteId: RemoteId, f: (entries: ReadonlyArray<Entry>) => Effect.Effect<A, E, R>) => Effect.Effect<A, EventJournalError | E, R>;
    /**
     * Retrieve the last known sequence number for a remote source.
     */
    readonly nextRemoteSequence: (remoteId: RemoteId) => Effect.Effect<number, EventJournalError>;
    /**
     * The entries added to the local journal.
     */
    readonly changes: Effect.Effect<PubSub.Subscription<Entry>, never, Scope>;
    /**
     * Remove all data
     */
    readonly destroy: Effect.Effect<void, EventJournalError>;
    /**
     * Run an effect with a lock on the journal.
     */
    readonly withLock: (storeId: StoreId) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
}>;
/**
 * 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 <A extends Record<string, any> = {}>(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<A>;
/**
 * 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<RemoteIdTypeId>;
/**
 * Schema for branded remote event journal identifiers.
 *
 * @category remote
 * @since 4.0.0
 */
export declare const RemoteId: Schema.brand<Schema.Uint8Array, "effect/eventlog/EventJournal/RemoteId">;
/**
 * 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<ArrayBuffer> & Brand<EntryIdTypeId>;
/**
 * Schema for branded event journal entry identifiers.
 *
 * @category entry
 * @since 4.0.0
 */
export declare const EntryId: Schema.brand<Schema.instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, "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<EntryId>;
/**
 * 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<Entry, Schema.Struct<{
    readonly id: Schema.brand<Schema.instanceOf<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, "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<Msgpack.schema<typeof Entry>>;
    /**
     * 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<readonly Uint8Array<ArrayBuffer>[], 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<readonly Entry[], Schema.SchemaError, never>;
    /**
     * Ordering for committed entries by their event journal entry id.
     *
     * @since 4.0.0
     */
    static Order: Order.Order<Entry>;
    /**
     * 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<RemoteEntry, Schema.Struct<{
    readonly remoteSequence: Schema.Number;
    readonly entry: typeof Entry;
}>, {}>;
/**
 * 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<EventJournal["Service"]>;
/**
 * 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<EventJournal>;
/**
 * 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<EventJournal["Service"], EventJournalError, Scope>;
/**
 * 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<EventJournal, EventJournalError>;
export {};
//# sourceMappingURL=EventJournal.d.ts.map