effect-cqrs 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +326 -2
- package/dist/Aggregate.d.ts +127 -0
- package/dist/Aggregate.d.ts.map +1 -0
- package/dist/Aggregate.js +59 -0
- package/dist/Aggregate.js.map +1 -0
- package/dist/AggregateService.d.ts +154 -0
- package/dist/AggregateService.d.ts.map +1 -0
- package/dist/AggregateService.js +407 -0
- package/dist/AggregateService.js.map +1 -0
- package/dist/Causation.d.ts +34 -0
- package/dist/Causation.d.ts.map +1 -0
- package/dist/Causation.js +32 -0
- package/dist/Causation.js.map +1 -0
- package/dist/Checkpoints.d.ts +19 -0
- package/dist/Checkpoints.d.ts.map +1 -0
- package/dist/Checkpoints.js +18 -0
- package/dist/Checkpoints.js.map +1 -0
- package/dist/EventStore.d.ts +132 -0
- package/dist/EventStore.d.ts.map +1 -0
- package/dist/EventStore.js +156 -0
- package/dist/EventStore.js.map +1 -0
- package/dist/EventVersions.d.ts +64 -0
- package/dist/EventVersions.d.ts.map +1 -0
- package/dist/EventVersions.js +55 -0
- package/dist/EventVersions.js.map +1 -0
- package/dist/Fixture.d.ts +106 -0
- package/dist/Fixture.d.ts.map +1 -0
- package/dist/Fixture.js +149 -0
- package/dist/Fixture.js.map +1 -0
- package/dist/Metadata.d.ts +42 -0
- package/dist/Metadata.d.ts.map +1 -0
- package/dist/Metadata.js +39 -0
- package/dist/Metadata.js.map +1 -0
- package/dist/PostgresEventStore.d.ts +30 -0
- package/dist/PostgresEventStore.d.ts.map +1 -0
- package/dist/PostgresEventStore.js +153 -0
- package/dist/PostgresEventStore.js.map +1 -0
- package/dist/Saga.d.ts +105 -0
- package/dist/Saga.d.ts.map +1 -0
- package/dist/Saga.js +97 -0
- package/dist/Saga.js.map +1 -0
- package/dist/SqliteEventStore.d.ts +25 -0
- package/dist/SqliteEventStore.d.ts.map +1 -0
- package/dist/SqliteEventStore.js +142 -0
- package/dist/SqliteEventStore.js.map +1 -0
- package/dist/ViewModel.d.ts +90 -0
- package/dist/ViewModel.d.ts.map +1 -0
- package/dist/ViewModel.js +172 -0
- package/dist/ViewModel.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/package.json +89 -3
- package/src/Aggregate.ts +205 -0
- package/src/AggregateService.ts +705 -0
- package/src/Causation.ts +48 -0
- package/src/Checkpoints.ts +23 -0
- package/src/EventStore.ts +270 -0
- package/src/EventVersions.ts +104 -0
- package/src/Fixture.ts +298 -0
- package/src/Metadata.ts +52 -0
- package/src/PostgresEventStore.ts +199 -0
- package/src/Saga.ts +176 -0
- package/src/SqliteEventStore.ts +196 -0
- package/src/ViewModel.ts +350 -0
- package/src/index.ts +12 -0
package/src/ViewModel.ts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The read side: projections of events into whatever storage a query needs.
|
|
3
|
+
*
|
|
4
|
+
* Moleculer-cqrs pushes events to view models over the broker, so an event sent
|
|
5
|
+
* while a service is down is lost until someone replays. Here each view model
|
|
6
|
+
* pulls from the store from its own checkpoint, so it can't miss anything, and
|
|
7
|
+
* delivery is at least once: a handler can see an event again after a crash and
|
|
8
|
+
* should be idempotent.
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
Context,
|
|
12
|
+
Duration,
|
|
13
|
+
Effect,
|
|
14
|
+
Layer,
|
|
15
|
+
Option,
|
|
16
|
+
Ref,
|
|
17
|
+
Schedule,
|
|
18
|
+
Schema,
|
|
19
|
+
Semaphore,
|
|
20
|
+
Stream,
|
|
21
|
+
SubscriptionRef
|
|
22
|
+
} from "effect"
|
|
23
|
+
import type { DateTime } from "effect"
|
|
24
|
+
import type * as Aggregate from "./Aggregate.ts"
|
|
25
|
+
import { makeEventDecoder } from "./AggregateService.ts"
|
|
26
|
+
import * as Causation from "./Causation.ts"
|
|
27
|
+
import { Checkpoints } from "./Checkpoints.ts"
|
|
28
|
+
import { type EventFilter, EventStore, type EventStoreError, type StoredEvent } from "./EventStore.ts"
|
|
29
|
+
|
|
30
|
+
export class UnknownViewModel extends Schema.TaggedError<UnknownViewModel>()("UnknownViewModel", {
|
|
31
|
+
name: Schema.String
|
|
32
|
+
}) {}
|
|
33
|
+
|
|
34
|
+
export class ViewModelError extends Schema.TaggedError<ViewModelError>()("ViewModelError", {
|
|
35
|
+
viewModel: Schema.String,
|
|
36
|
+
/** The event being processed, `0` when the failure happened outside any event. */
|
|
37
|
+
position: Schema.Int,
|
|
38
|
+
cause: Schema.Defect()
|
|
39
|
+
}) {}
|
|
40
|
+
|
|
41
|
+
export type Handlers<Event extends Aggregate.Tagged> = {
|
|
42
|
+
readonly [Tag in Event["_tag"]]?: (
|
|
43
|
+
event: Extract<Event, { readonly _tag: Tag }>,
|
|
44
|
+
meta: Aggregate.EventMeta
|
|
45
|
+
) => Effect.Effect<unknown, any, any>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type HandlerError<H> = {
|
|
49
|
+
readonly [K in keyof H]-?: NonNullable<H[K]> extends (...args: any) => Effect.Effect<any, infer E, any> ? E : never
|
|
50
|
+
}[keyof H]
|
|
51
|
+
|
|
52
|
+
type HandlerContext<H> = {
|
|
53
|
+
readonly [K in keyof H]-?: NonNullable<H[K]> extends (...args: any) => Effect.Effect<any, any, infer R> ? R : never
|
|
54
|
+
}[keyof H]
|
|
55
|
+
|
|
56
|
+
export interface ViewModel<out Name extends string, out E, out R> {
|
|
57
|
+
readonly name: Name
|
|
58
|
+
readonly aggregates: ReadonlyArray<Aggregate.Any>
|
|
59
|
+
readonly handlers: Record<string, (event: never, meta: Aggregate.EventMeta) => Effect.Effect<unknown, E, R>>
|
|
60
|
+
/** Clears everything the view model stored, before a replay rebuilds it. */
|
|
61
|
+
readonly dispose: Effect.Effect<void, E, R>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type Any = ViewModel<string, any, any>
|
|
65
|
+
|
|
66
|
+
export type Context<V extends Any> = V extends ViewModel<any, any, infer R> ? R : never
|
|
67
|
+
|
|
68
|
+
/** Handlers are keyed by event tag, and events without one are skipped. */
|
|
69
|
+
export const make = <
|
|
70
|
+
const Name extends string,
|
|
71
|
+
const Aggregates extends ReadonlyArray<Aggregate.Any>,
|
|
72
|
+
const H extends Handlers<Aggregate.Event<Aggregates[number]>>,
|
|
73
|
+
E = never,
|
|
74
|
+
R = never
|
|
75
|
+
>(options: {
|
|
76
|
+
readonly name: Name
|
|
77
|
+
readonly aggregates: Aggregates
|
|
78
|
+
readonly handlers: H
|
|
79
|
+
readonly dispose: Effect.Effect<void, E, R>
|
|
80
|
+
}): ViewModel<Name, E | HandlerError<H>, R | HandlerContext<H>> => options as any
|
|
81
|
+
|
|
82
|
+
export interface ReplayOptions {
|
|
83
|
+
readonly viewModels: ReadonlyArray<string>
|
|
84
|
+
readonly startTime?: DateTime.Utc | undefined
|
|
85
|
+
readonly finishTime?: DateTime.Utc | undefined
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ReplayResult {
|
|
89
|
+
readonly viewModels: ReadonlyArray<string>
|
|
90
|
+
readonly eventCount: number
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface Status {
|
|
94
|
+
readonly name: string
|
|
95
|
+
readonly position: number
|
|
96
|
+
/** The failure the view model is retrying, while it is stalled on one. */
|
|
97
|
+
readonly lastError: Option.Option<ViewModelError>
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class ViewModels extends Context.Service<ViewModels, {
|
|
101
|
+
/**
|
|
102
|
+
* Disposes the named view models and rebuilds them from their events. A time
|
|
103
|
+
* window limits which events are replayed: the view model then resumes from
|
|
104
|
+
* the present and events outside the window stay out of it.
|
|
105
|
+
*/
|
|
106
|
+
replay(options: ReplayOptions): Effect.Effect<ReplayResult, UnknownViewModel | ViewModelError>
|
|
107
|
+
/**
|
|
108
|
+
* Waits until every view model has processed `position`, defaulting to the
|
|
109
|
+
* latest event. Pair it with `CommandResult.position` to read your own writes.
|
|
110
|
+
* A view model stalled on a failure doesn't catch up, so consider a timeout.
|
|
111
|
+
*/
|
|
112
|
+
caughtUp(position?: number): Effect.Effect<void, EventStoreError>
|
|
113
|
+
readonly status: Effect.Effect<ReadonlyArray<Status>>
|
|
114
|
+
}>()("effect-cqrs/ViewModels") {}
|
|
115
|
+
|
|
116
|
+
// Stalled view models keep their place so events are never processed out of order.
|
|
117
|
+
const retryDelay = (attempt: number) => Duration.millis(Math.min(100 * 2 ** attempt, 30_000))
|
|
118
|
+
|
|
119
|
+
// Following the log moves a few events at a time, and a checkpoint for each of those
|
|
120
|
+
// moves is a commit per view model per event. Saving less often only means that a
|
|
121
|
+
// crash repeats more, which handlers already have to cope with.
|
|
122
|
+
const checkpointInterval = 500
|
|
123
|
+
|
|
124
|
+
// How far behind a view model can be and still read the tail everyone shares. It is
|
|
125
|
+
// one page of the store, so a shared read never has to page.
|
|
126
|
+
const tailSize = 500
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Reads the end of the log once for all view models. When they are caught up they
|
|
130
|
+
* wake on the same append and want the same few events, so each reading them for
|
|
131
|
+
* itself is most of what a view model costs.
|
|
132
|
+
*/
|
|
133
|
+
const makeTail = (store: EventStore["Service"], viewModels: ReadonlyArray<Any>) => {
|
|
134
|
+
const filter: EventFilter = {
|
|
135
|
+
aggregateNames: Array.from(new Set(viewModels.flatMap((viewModel) => viewModel.aggregates.map(({ name }) => name)))),
|
|
136
|
+
eventTypes: Array.from(new Set(viewModels.flatMap((viewModel) => Object.keys(viewModel.handlers))))
|
|
137
|
+
}
|
|
138
|
+
const decoded = new WeakMap<StoredEvent, unknown>()
|
|
139
|
+
let last: { readonly afterPosition: number; readonly latest: number; readonly events: ReadonlyArray<StoredEvent> } | undefined
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
read: (afterPosition: number, latest: number) =>
|
|
143
|
+
Effect.suspend(() =>
|
|
144
|
+
last?.afterPosition === afterPosition && last.latest === latest
|
|
145
|
+
? Effect.succeed(last.events)
|
|
146
|
+
: Stream.runCollect(store.read({ ...filter, afterPosition })).pipe(
|
|
147
|
+
Effect.tap((events) => Effect.sync(() => void (last = { afterPosition, latest, events })))
|
|
148
|
+
)
|
|
149
|
+
),
|
|
150
|
+
decoded
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type Tail = ReturnType<typeof makeTail>
|
|
155
|
+
|
|
156
|
+
const makeRunner = Effect.fnUntraced(function*<V extends Any>(viewModel: V, tail: Tail) {
|
|
157
|
+
const store = yield* EventStore
|
|
158
|
+
const checkpoints = yield* Checkpoints
|
|
159
|
+
const context = yield* Effect.context<Context<V>>()
|
|
160
|
+
const provide = <A, E>(effect: Effect.Effect<A, E, any>) => Effect.provideContext(effect, context) as Effect.Effect<A, E>
|
|
161
|
+
const semaphore = yield* Semaphore.make(1)
|
|
162
|
+
const name = viewModel.name
|
|
163
|
+
|
|
164
|
+
const fail = (position: number) => (cause: unknown) => new ViewModelError({ viewModel: name, position, cause })
|
|
165
|
+
|
|
166
|
+
const checkpoint = yield* checkpoints.get(name)
|
|
167
|
+
const position = yield* SubscriptionRef.make(checkpoint)
|
|
168
|
+
const saved = yield* Ref.make(checkpoint)
|
|
169
|
+
const lastError = yield* Ref.make(Option.none<ViewModelError>())
|
|
170
|
+
const stall = yield* Ref.make({ position: -1, attempts: 0 })
|
|
171
|
+
|
|
172
|
+
const decoders = new Map(viewModel.aggregates.map((aggregate) => [aggregate.name, makeEventDecoder(aggregate)]))
|
|
173
|
+
const filter: EventFilter = {
|
|
174
|
+
aggregateNames: Array.from(decoders.keys()),
|
|
175
|
+
eventTypes: Object.keys(viewModel.handlers)
|
|
176
|
+
}
|
|
177
|
+
const wants = (stored: StoredEvent) =>
|
|
178
|
+
decoders.has(stored.aggregateName) && Object.hasOwn(viewModel.handlers, stored.type)
|
|
179
|
+
|
|
180
|
+
const decode = (stored: StoredEvent) => decoders.get(stored.aggregateName)!(stored)
|
|
181
|
+
|
|
182
|
+
// Events from the tail are the same objects for everyone, so the first to decode one
|
|
183
|
+
// does it for the rest.
|
|
184
|
+
const decodeShared = (stored: StoredEvent) =>
|
|
185
|
+
tail.decoded.has(stored)
|
|
186
|
+
? Effect.succeed(tail.decoded.get(stored))
|
|
187
|
+
: decode(stored).pipe(Effect.tap((event) => Effect.sync(() => void tail.decoded.set(stored, event))))
|
|
188
|
+
|
|
189
|
+
const handle = (decodeEvent: (stored: StoredEvent) => Effect.Effect<unknown, unknown>) => (stored: StoredEvent) =>
|
|
190
|
+
Effect.gen(function*() {
|
|
191
|
+
const event = yield* decodeEvent(stored)
|
|
192
|
+
// Commands the handler runs record this event as their cause.
|
|
193
|
+
yield* viewModel.handlers[stored.type]!(event as never, stored).pipe(Causation.causedBy(stored))
|
|
194
|
+
}).pipe(
|
|
195
|
+
Effect.mapError(fail(stored.position)),
|
|
196
|
+
Effect.catchDefect((defect) => Effect.fail(fail(stored.position)(defect)))
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
const save = (to: number) =>
|
|
200
|
+
checkpoints.set(name, to).pipe(
|
|
201
|
+
Effect.mapError(fail(0)),
|
|
202
|
+
Effect.andThen(Ref.set(saved, to))
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
const advance = (to: number) =>
|
|
206
|
+
Ref.get(saved).pipe(
|
|
207
|
+
Effect.flatMap((last) => to < last || to - last >= checkpointInterval ? save(to) : Effect.void),
|
|
208
|
+
Effect.andThen(SubscriptionRef.set(position, to))
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
// Finalizers run last to first, so this one sees the fiber below already stopped.
|
|
212
|
+
yield* Effect.addFinalizer(() => SubscriptionRef.get(position).pipe(Effect.flatMap(save), Effect.ignore))
|
|
213
|
+
|
|
214
|
+
// A crash repeats at most what came after the last saved checkpoint: two batches.
|
|
215
|
+
const processBatch = (batch: ReadonlyArray<StoredEvent>, decodeEvent: typeof decode | typeof decodeShared) =>
|
|
216
|
+
Effect.forEach(batch, handle(decodeEvent), { discard: true }).pipe(
|
|
217
|
+
Effect.andThen(advance(batch[batch.length - 1]!.position))
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
const consume = (eventFilter: EventFilter, onBatch: (size: number) => Effect.Effect<void>) =>
|
|
221
|
+
store.read(eventFilter).pipe(
|
|
222
|
+
Stream.mapError(fail(0)),
|
|
223
|
+
Stream.runForEachArray((batch) => processBatch(batch, decode).pipe(Effect.andThen(onBatch(batch.length))))
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
const follow = (afterPosition: number, latest: number) =>
|
|
227
|
+
tail.read(afterPosition, latest).pipe(
|
|
228
|
+
Effect.mapError(fail(0)),
|
|
229
|
+
Effect.map((events) => events.filter(wants)),
|
|
230
|
+
Effect.flatMap((events) => events.length === 0 ? Effect.void : processBatch(events, decodeShared))
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
// Moves past the end of the log even when the last events were not for this view model.
|
|
234
|
+
const settle = (head: number) =>
|
|
235
|
+
SubscriptionRef.get(position).pipe(
|
|
236
|
+
Effect.flatMap((current) => current < head ? advance(head) : Effect.void)
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
const catchUp = (latest: number) =>
|
|
240
|
+
Effect.gen(function*() {
|
|
241
|
+
const afterPosition = yield* SubscriptionRef.get(position)
|
|
242
|
+
if (latest <= afterPosition) return
|
|
243
|
+
if (latest - afterPosition <= tailSize) yield* follow(afterPosition, latest)
|
|
244
|
+
else yield* consume({ ...filter, afterPosition }, () => Effect.void)
|
|
245
|
+
yield* settle(latest)
|
|
246
|
+
}).pipe(
|
|
247
|
+
semaphore.withPermit,
|
|
248
|
+
provide
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
// Failing again at the same place doubles the delay. Having moved on means that
|
|
252
|
+
// stall is over, so the next one starts from the shortest delay.
|
|
253
|
+
const backOff = (error: ViewModelError) =>
|
|
254
|
+
Effect.gen(function*() {
|
|
255
|
+
const current = yield* SubscriptionRef.get(position)
|
|
256
|
+
const attempt = yield* Ref.modify(stall, (last) => {
|
|
257
|
+
const attempts = last.position === current ? last.attempts + 1 : 0
|
|
258
|
+
return [attempts, { position: current, attempts }] as const
|
|
259
|
+
})
|
|
260
|
+
yield* Ref.set(lastError, Option.some(error))
|
|
261
|
+
yield* Effect.logError(`View model ${name} failed, retrying`, error)
|
|
262
|
+
yield* Effect.sleep(retryDelay(attempt))
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
yield* store.changes.pipe(
|
|
266
|
+
Stream.filterEffect((latest) => Effect.map(SubscriptionRef.get(position), (current) => latest > current)),
|
|
267
|
+
Stream.runForEach((latest) =>
|
|
268
|
+
catchUp(latest).pipe(
|
|
269
|
+
Effect.tapError(backOff),
|
|
270
|
+
Effect.retry(Schedule.forever),
|
|
271
|
+
Effect.andThen(Ref.set(lastError, Option.none()))
|
|
272
|
+
)
|
|
273
|
+
),
|
|
274
|
+
Effect.forkScoped
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
const replay = (range: Pick<ReplayOptions, "startTime" | "finishTime">) =>
|
|
278
|
+
Effect.gen(function*() {
|
|
279
|
+
// The checkpoint is cleared first: a crash in between then replays over
|
|
280
|
+
// old data, which is safe for idempotent handlers, instead of leaving a
|
|
281
|
+
// disposed view model that resumes from a stale position.
|
|
282
|
+
yield* advance(0)
|
|
283
|
+
yield* viewModel.dispose.pipe(Effect.mapError(fail(0)))
|
|
284
|
+
const head = yield* store.head.pipe(Effect.mapError(fail(0)))
|
|
285
|
+
const count = yield* Ref.make(0)
|
|
286
|
+
yield* consume({ ...filter, ...range }, (size) => Ref.update(count, (n) => n + size))
|
|
287
|
+
yield* settle(head)
|
|
288
|
+
return yield* Ref.get(count)
|
|
289
|
+
}).pipe(semaphore.withPermit, provide)
|
|
290
|
+
|
|
291
|
+
const caughtUp = (target: number) =>
|
|
292
|
+
SubscriptionRef.changes(position).pipe(
|
|
293
|
+
Stream.filter((current) => current >= target),
|
|
294
|
+
Stream.runHead,
|
|
295
|
+
Effect.asVoid
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
const status = Effect.gen(function*() {
|
|
299
|
+
return {
|
|
300
|
+
name,
|
|
301
|
+
position: yield* SubscriptionRef.get(position),
|
|
302
|
+
lastError: yield* Ref.get(lastError)
|
|
303
|
+
} satisfies Status
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
return { name, replay, caughtUp, status }
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
/** Starts the view models in the background for as long as the layer lives. */
|
|
310
|
+
export const layer = <const VMs extends ReadonlyArray<Any>>(
|
|
311
|
+
viewModels: VMs
|
|
312
|
+
): Layer.Layer<ViewModels, EventStoreError, EventStore | Checkpoints | Context<VMs[number]>> =>
|
|
313
|
+
Layer.effect(
|
|
314
|
+
ViewModels,
|
|
315
|
+
Effect.gen(function*() {
|
|
316
|
+
const store = yield* EventStore
|
|
317
|
+
const tail = makeTail(store, viewModels)
|
|
318
|
+
const runners = yield* Effect.forEach(viewModels, (viewModel) => makeRunner(viewModel, tail))
|
|
319
|
+
|
|
320
|
+
const replay = Effect.fn("ViewModels.replay")(function*(options: ReplayOptions) {
|
|
321
|
+
const selected = yield* Effect.forEach(options.viewModels, (name) => {
|
|
322
|
+
const runner = runners.find((runner) => runner.name === name)
|
|
323
|
+
return runner === undefined ? new UnknownViewModel({ name }) : Effect.succeed(runner)
|
|
324
|
+
})
|
|
325
|
+
const counts = yield* Effect.forEach(
|
|
326
|
+
selected,
|
|
327
|
+
(runner) => runner.replay({ startTime: options.startTime, finishTime: options.finishTime }),
|
|
328
|
+
{ concurrency: "unbounded" }
|
|
329
|
+
)
|
|
330
|
+
return {
|
|
331
|
+
viewModels: options.viewModels,
|
|
332
|
+
eventCount: counts.reduce((total, count) => total + count, 0)
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
const caughtUp = Effect.fn("ViewModels.caughtUp")(function*(position?: number) {
|
|
337
|
+
const target = position ?? (yield* store.head)
|
|
338
|
+
yield* Effect.forEach(runners, (runner) => runner.caughtUp(target), {
|
|
339
|
+
concurrency: "unbounded",
|
|
340
|
+
discard: true
|
|
341
|
+
})
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
return ViewModels.of({
|
|
345
|
+
replay,
|
|
346
|
+
caughtUp,
|
|
347
|
+
status: Effect.forEach(runners, (runner) => runner.status)
|
|
348
|
+
})
|
|
349
|
+
})
|
|
350
|
+
)
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * as Aggregate from "./Aggregate.ts"
|
|
2
|
+
export * as AggregateService from "./AggregateService.ts"
|
|
3
|
+
export * as Causation from "./Causation.ts"
|
|
4
|
+
export * as Checkpoints from "./Checkpoints.ts"
|
|
5
|
+
export * as EventStore from "./EventStore.ts"
|
|
6
|
+
export * as EventVersions from "./EventVersions.ts"
|
|
7
|
+
export * as Fixture from "./Fixture.ts"
|
|
8
|
+
export * as Metadata from "./Metadata.ts"
|
|
9
|
+
export * as PostgresEventStore from "./PostgresEventStore.ts"
|
|
10
|
+
export * as Saga from "./Saga.ts"
|
|
11
|
+
export * as SqliteEventStore from "./SqliteEventStore.ts"
|
|
12
|
+
export * as ViewModel from "./ViewModel.ts"
|