@livestore/livestore 0.5.0-dev.1 → 0.5.1

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.
Files changed (36) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/QueryCache.d.ts.map +1 -1
  3. package/dist/QueryCache.js +1 -2
  4. package/dist/QueryCache.js.map +1 -1
  5. package/dist/ReactiveStateSqliteDb.d.ts +9 -0
  6. package/dist/ReactiveStateSqliteDb.d.ts.map +1 -0
  7. package/dist/ReactiveStateSqliteDb.js +6 -0
  8. package/dist/ReactiveStateSqliteDb.js.map +1 -0
  9. package/dist/SqliteDbWrapper.d.ts +11 -9
  10. package/dist/SqliteDbWrapper.d.ts.map +1 -1
  11. package/dist/SqliteDbWrapper.js +65 -14
  12. package/dist/SqliteDbWrapper.js.map +1 -1
  13. package/dist/SqliteDbWrapper.test.js +18 -0
  14. package/dist/SqliteDbWrapper.test.js.map +1 -1
  15. package/dist/live-queries/db-query.test.js +4 -0
  16. package/dist/live-queries/db-query.test.js.map +1 -1
  17. package/dist/store/create-store.d.ts.map +1 -1
  18. package/dist/store/create-store.js +47 -17
  19. package/dist/store/create-store.js.map +1 -1
  20. package/dist/store/store-types.d.ts +2 -2
  21. package/dist/store/store-types.d.ts.map +1 -1
  22. package/dist/store/store-types.js.map +1 -1
  23. package/dist/store/store.d.ts +2 -2
  24. package/dist/store/store.d.ts.map +1 -1
  25. package/dist/store/store.js +32 -34
  26. package/dist/store/store.js.map +1 -1
  27. package/package.json +12 -12
  28. package/src/QueryCache.ts +1 -3
  29. package/src/ReactiveStateSqliteDb.ts +10 -0
  30. package/src/SqliteDbWrapper.test.ts +21 -0
  31. package/src/SqliteDbWrapper.ts +81 -19
  32. package/src/live-queries/__snapshots__/db-query.test.ts.snap +223 -278
  33. package/src/live-queries/db-query.test.ts +4 -0
  34. package/src/store/create-store.ts +68 -22
  35. package/src/store/store-types.ts +11 -2
  36. package/src/store/store.ts +101 -102
@@ -25,6 +25,10 @@ Vitest.describe('otel', () => {
25
25
  if (key === 'code.stacktrace') {
26
26
  return '<STACKTRACE>'
27
27
  }
28
+ // Savepoint ids are process-local counters, not part of the query tracing contract.
29
+ if (key === 'sql.query' && typeof val === 'string') {
30
+ return val.replace(/livestore_savepoint_\d+/g, 'livestore_savepoint_<id>')
31
+ }
28
32
  return val
29
33
  })
30
34
  }
@@ -7,6 +7,7 @@ import {
7
7
  type ClientSession,
8
8
  type ClientSessionDevtoolsChannel,
9
9
  type IntentionalShutdownCause,
10
+ type MaterializationJournal,
10
11
  type MaterializeError,
11
12
  type MigrationsReport,
12
13
  provideOtel,
@@ -320,7 +321,31 @@ export const createStore = <
320
321
 
321
322
  yield* validateStoreId(storeId)
322
323
 
323
- yield* Effect.addFinalizer((_) => Scope.close(lifetimeScope, _))
324
+ /**
325
+ * Started at most once by either `store.shutdown()` or the closing of the scope `createStore` runs in, so both
326
+ * paths share one bounded drain. See `startTeardown` below.
327
+ */
328
+ let teardownFiber: Fiber.Fiber<void> | undefined
329
+ let startTeardownRef: ((exit: Exit.Exit<unknown, unknown>) => Effect.Effect<Fiber.Fiber<void>>) | undefined
330
+
331
+ // Closing the caller's scope is an orderly shutdown too: queued session events are drained to the leader before
332
+ // the lifetime scope (and with it an in-process leader) closes. If creation failed before the teardown existed,
333
+ // there is nothing to drain and the lifetime scope is closed directly.
334
+ yield* Effect.addFinalizer((exit) => {
335
+ if (startTeardownRef === undefined) return Scope.close(lifetimeScope, exit)
336
+ // A teardown started earlier by `store.shutdown()` has already reported its outcome to that caller (and to
337
+ // `shutdownDeferred`). Only a drain started by this scope close is reported here, and never by failing the
338
+ // close itself.
339
+ const startedByScopeClose = teardownFiber === undefined
340
+ return startTeardownRef(exit).pipe(
341
+ Effect.flatMap(awaitTeardownWithSoftBound),
342
+ Effect.catchCause((cause) =>
343
+ startedByScopeClose === true
344
+ ? Effect.logError('@livestore/livestore:shutdown: drain on scope close failed', cause)
345
+ : Effect.void,
346
+ ),
347
+ )
348
+ })
324
349
 
325
350
  const debugInstanceId = debug?.instanceId ?? nanoid(10)
326
351
  const resolvedSyncPayloadSchema = (syncPayloadSchema ?? Schema.Json) as TSyncPayloadSchema
@@ -353,18 +378,18 @@ export const createStore = <
353
378
  const services = yield* Effect.context<Scope.Scope>()
354
379
  let shutdownSyncProcessor: ((exit: Exit.Exit<unknown, unknown>) => Effect.Effect<void>) | undefined
355
380
 
356
- const shutdown = (
357
- exit: Exit.Exit<IntentionalShutdownCause, UnknownError | MaterializeError | BackendIdMismatchError>,
358
- ) =>
359
- Effect.gen(function* () {
360
- // Hard outer bound on the DETACHED teardown: the processor drain `awaitEmpty`s the
361
- // leader-push worker, which never completes if the leader is dead/unresponsive. Without a
362
- // bound the drain would block forever, so `Scope.close(lifetimeScope)` (in `ensuring`)
363
- // would never run and the lifetime scope + its resources would leak indefinitely (a later
364
- // `createStore`/registry dispose on the same `storeId` would observe a never-closed store).
365
- // Drain up to the bound, then force-close the scope regardless. The bound exceeds the
366
- // caller-side wait below so an in-flight (but progressing) push is not cut short.
367
- const closeFiber = yield* (shutdownSyncProcessor?.(exit) ?? Effect.void).pipe(
381
+ /**
382
+ * Drains the session sync processor (for a successful exit) and then closes the lifetime scope, detached so the
383
+ * shutdown flow cannot interrupt itself. The processor drain waits for the leader-push worker, which never
384
+ * completes if the leader is dead or unresponsive. Without a bound `Scope.close(lifetimeScope)` would never
385
+ * run and the lifetime scope would leak (a later `createStore`/registry dispose on the same `storeId` would
386
+ * observe a never-closed store). The bound exceeds the caller-side soft wait so an in-flight but progressing
387
+ * push is not cut short.
388
+ */
389
+ const startTeardown = (exit: Exit.Exit<unknown, unknown>): Effect.Effect<Fiber.Fiber<void>> =>
390
+ Effect.suspend(() => {
391
+ if (teardownFiber !== undefined) return Effect.succeed(teardownFiber)
392
+ return (shutdownSyncProcessor?.(exit) ?? Effect.void).pipe(
368
393
  Effect.timeoutOrElse({
369
394
  duration: SHUTDOWN_DRAIN_HARD_TIMEOUT_MS,
370
395
  orElse: () =>
@@ -373,17 +398,25 @@ export const createStore = <
373
398
  ),
374
399
  }),
375
400
  Effect.ensuring(Scope.close(lifetimeScope, exit)),
401
+ Effect.provide(services),
376
402
  Effect.forkDetach,
403
+ Effect.tap((fiber) =>
404
+ Effect.sync(() => {
405
+ teardownFiber = fiber
406
+ }),
407
+ ),
377
408
  )
378
- // Caller-side soft wait: stop blocking the shutdown() caller after 1s without cancelling
379
- // the detached teardown above (which remains bounded by SHUTDOWN_DRAIN_HARD_TIMEOUT_MS).
380
- yield* Fiber.join(closeFiber).pipe(
381
- Effect.logWarnIfTakesLongerThan({ label: '@livestore/livestore:shutdown', duration: 500 }),
382
- Effect.timeoutOrElse({
383
- duration: 1000,
384
- orElse: () => Effect.logError('@livestore/livestore:shutdown: Timed out after 1 second'),
385
- }),
386
- )
409
+ })
410
+ startTeardownRef = startTeardown
411
+
412
+ const shutdown = (
413
+ exit: Exit.Exit<
414
+ IntentionalShutdownCause,
415
+ UnknownError | MaterializeError | MaterializationJournal.MaterializationJournalError | BackendIdMismatchError
416
+ >,
417
+ ) =>
418
+ Effect.gen(function* () {
419
+ yield* awaitTeardownWithSoftBound(yield* startTeardown(exit))
387
420
 
388
421
  if (shutdownDeferred !== undefined) {
389
422
  yield* Deferred.done(shutdownDeferred, exit)
@@ -523,3 +556,16 @@ const getDevtoolsEnabled = (disableDevtools: boolean | 'auto' | undefined) => {
523
556
 
524
557
  return false
525
558
  }
559
+
560
+ /**
561
+ * Caller-side soft wait: stops blocking whoever triggered the shutdown after 1s without cancelling the detached
562
+ * teardown, which remains bounded by `SHUTDOWN_DRAIN_HARD_TIMEOUT_MS`.
563
+ */
564
+ const awaitTeardownWithSoftBound = (teardown: Fiber.Fiber<void>) =>
565
+ Fiber.join(teardown).pipe(
566
+ Effect.logWarnIfTakesLongerThan({ label: '@livestore/livestore:shutdown', duration: 500 }),
567
+ Effect.timeoutOrElse({
568
+ duration: 1000,
569
+ orElse: () => Effect.logError('@livestore/livestore:shutdown: Timed out after 1 second'),
570
+ }),
571
+ )
@@ -6,6 +6,7 @@ import {
6
6
  type ClientSessionSyncProcessor,
7
7
  type IntentionalShutdownCause,
8
8
  isQueryBuilder,
9
+ type MaterializationJournal,
9
10
  type MaterializeError,
10
11
  type QueryBuilder,
11
12
  type StoreInterrupted,
@@ -52,11 +53,19 @@ export type LiveStoreContext<TSchema extends LiveStoreSchema = LiveStoreSchema.A
52
53
 
53
54
  export type ShutdownDeferred = Deferred.Deferred<
54
55
  IntentionalShutdownCause,
55
- UnknownError | StoreInterrupted | MaterializeError | BackendIdMismatchError
56
+ | UnknownError
57
+ | StoreInterrupted
58
+ | MaterializeError
59
+ | MaterializationJournal.MaterializationJournalError
60
+ | BackendIdMismatchError
56
61
  >
57
62
  export const makeShutdownDeferred: Effect.Effect<ShutdownDeferred> = Deferred.make<
58
63
  IntentionalShutdownCause,
59
- UnknownError | StoreInterrupted | MaterializeError | BackendIdMismatchError
64
+ | UnknownError
65
+ | StoreInterrupted
66
+ | MaterializeError
67
+ | MaterializationJournal.MaterializationJournalError
68
+ | BackendIdMismatchError
60
69
  >()
61
70
 
62
71
  /**
@@ -10,13 +10,14 @@ import {
10
10
  IntentionalShutdownCause,
11
11
  isQueryBuilder,
12
12
  liveStoreVersion,
13
+ MaterializationJournal,
13
14
  MaterializeError,
14
15
  MaterializerHashMismatchError,
15
16
  makeClientSessionSyncProcessor,
16
17
  prepareBindValues,
17
18
  QueryBuilderAstSymbol,
18
19
  resolveSessionIdSymbolInBindValues,
19
- SqliteDbHelper,
20
+ StateSqliteDb,
20
21
  StateHead,
21
22
  type StorageMode,
22
23
  type SyncState,
@@ -33,6 +34,7 @@ import {
33
34
  Exit,
34
35
  Fiber,
35
36
  Inspectable,
37
+ Layer,
36
38
  Option,
37
39
  OtelTracer,
38
40
  Queue,
@@ -47,6 +49,7 @@ import { makeReactivityGraph } from '../live-queries/base-class.ts'
47
49
  import { makeExecBeforeFirstRun } from '../live-queries/client-document-get-query.ts'
48
50
  import { queryDb } from '../live-queries/db-query.ts'
49
51
  import type { Ref } from '../reactive.ts'
52
+ import * as ReactiveStateSqliteDb from '../ReactiveStateSqliteDb.ts'
50
53
  import { SqliteDbWrapper } from '../SqliteDbWrapper.ts'
51
54
  import { ReferenceCountedSet } from '../utils/data-structures.ts'
52
55
  import { downloadBlob, exposeDebugUtils } from '../utils/dev.ts'
@@ -209,100 +212,112 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TConte
209
212
  this.storageMode = clientSession.leaderThread.initialState.storageMode
210
213
 
211
214
  const reactivityGraph = makeReactivityGraph()
212
- const stateHead = StateHead.make({ dbState: clientSession.sqliteDb })
215
+ const sqliteDbWrapper = new SqliteDbWrapper({ otel: otelOptions, db: clientSession.sqliteDb })
216
+ // Journal rollback must invalidate cached reads too. Both roles use the same connection, with the state
217
+ // services consuming its cache-aware adapter instead of bypassing it during changeset/savepoint rollback.
218
+ const stateDbLayer = StateSqliteDb.layer(sqliteDbWrapper.serviceDb)
219
+ const reactiveStateDbLayer = ReactiveStateSqliteDb.layer(sqliteDbWrapper)
220
+ const stateServicesLayer = Layer.mergeAll(MaterializationJournal.layer, StateHead.layer).pipe(
221
+ Layer.provide(stateDbLayer),
222
+ )
223
+ const materializationLayer = Layer.mergeAll(stateDbLayer, reactiveStateDbLayer, stateServicesLayer)
224
+ // Build the services once: `materializeEvent` runs for every committed and replayed event, and providing the layer
225
+ // there rebuilt the journal and state-head services each time. None of them owns resources, so the build scope can
226
+ // close right away.
227
+ const materializationContext = Layer.build(materializationLayer).pipe(
228
+ Effect.scoped,
229
+ Effect.runSyncWith(effectContext.services),
230
+ )
213
231
 
214
232
  const syncProcessor = makeClientSessionSyncProcessor({
215
233
  schema,
216
234
  clientSession,
217
- materializeEvent: Effect.fn('client-session-sync-processor:materialize-event')(
218
- (eventEncoded, { materializerHashLeader }) =>
219
- // We need to use `Effect.gen` (even though we're using `Effect.fn`) so that we can pass `this` to the function
220
- Effect.gen({ self: this }, function* () {
221
- const resolution = yield* resolveEventDef(schema, {
222
- operation: '@livestore/livestore:store:materializeEvent',
223
- event: eventEncoded,
224
- })
225
-
226
- if (resolution._tag === 'unknown') {
227
- // Runtime schema doesn't know this event yet; skip materialization but
228
- // keep the log entry so upgraded clients can replay it later.
229
- yield* stateHead.set(eventEncoded.seqNum)
230
- return {
231
- writeTables: new Set<string>(),
232
- sessionChangeset: { _tag: 'no-op' as const },
233
- materializerHash: Option.none(),
234
- }
235
- }
235
+ // No span per event: the processor traces each commit batch and pull step, and replaying a rebase materializes
236
+ // every pending event, where a span per event was a large share of the step's main-thread time.
237
+ materializeEvent: (eventEncoded, { materializerHashLeader }) =>
238
+ Effect.gen(function* () {
239
+ const materializationJournal = yield* MaterializationJournal.MaterializationJournal
240
+ const dbState = yield* ReactiveStateSqliteDb.ReactiveStateSqliteDb
241
+ const resolution = yield* resolveEventDef(schema, {
242
+ operation: '@livestore/livestore:store:materializeEvent',
243
+ event: eventEncoded,
244
+ })
236
245
 
237
- const { eventDef, materializer } = resolution
238
-
239
- const execArgsArr = getExecStatementsFromMaterializer({
240
- eventDef,
241
- materializer,
242
- dbState: this[StoreInternalsSymbol].sqliteDbWrapper,
243
- event: { decoded: undefined, encoded: eventEncoded },
244
- })
245
-
246
- const materializerHash =
247
- isDevEnv() === true ? Option.some(hashMaterializerResults(execArgsArr)) : Option.none()
248
-
249
- // Hash mismatch detection only occurs during the pull path (when receiving events from the leader).
250
- // During push path (local commits), materializerHashLeader is always Option.none(), so this condition
251
- // will never be met. The check happens when the same event comes back from the leader during sync,
252
- // allowing us to compare the leader's computed hash with our local re-materialization hash.
253
- if (
254
- materializerHashLeader._tag === 'Some' &&
255
- materializerHash._tag === 'Some' &&
256
- materializerHashLeader.value !== materializerHash.value
257
- ) {
258
- return yield* MaterializerHashMismatchError.make({ eventName: eventEncoded.name })
246
+ if (resolution._tag === 'unknown') {
247
+ // Runtime schema doesn't know this event yet; skip materialization but
248
+ // keep the log entry so upgraded clients can replay it later.
249
+ yield* materializationJournal.record({ key: eventEncoded.seqNum, changeset: null })
250
+ return {
251
+ writeTables: new Set<string>(),
252
+ materializerHash: Option.none(),
259
253
  }
254
+ }
260
255
 
261
- const span = yield* OtelTracer.currentOtelSpan.pipe(Effect.orDie)
262
- const otelContext = otel.trace.setSpan(otel.context.active(), span)
263
-
264
- const writeTablesForEvent = new Set<string>()
265
-
266
- const exec = () => {
267
- for (const {
268
- statementSql,
269
- bindValues,
270
- writeTables = this[StoreInternalsSymbol].sqliteDbWrapper.getTablesUsed(statementSql),
271
- } of execArgsArr) {
272
- try {
273
- this[StoreInternalsSymbol].sqliteDbWrapper.cachedExecute(statementSql, bindValues, {
274
- otelContext,
275
- writeTables,
276
- })
277
- } catch (cause) {
278
- // TOOD refactor with `SqliteError`
279
- throw UnknownError.make({
280
- cause,
281
- note: `Error executing materializer for event "${eventEncoded.name}".\nStatement: ${statementSql}\nBind values: ${JSON.stringify(bindValues)}`,
282
- })
283
- }
256
+ const { eventDef, materializer } = resolution
284
257
 
285
- // durationMsTotal += durationMs
286
- for (const table of writeTables) {
287
- writeTablesForEvent.add(table)
288
- }
258
+ const execArgsArr = getExecStatementsFromMaterializer({
259
+ eventDef,
260
+ materializer,
261
+ dbState,
262
+ event: { decoded: undefined, encoded: eventEncoded },
263
+ })
264
+
265
+ const materializerHash =
266
+ isDevEnv() === true ? Option.some(hashMaterializerResults(execArgsArr)) : Option.none()
267
+
268
+ // Hash mismatch detection only occurs during the pull path (when receiving events from the leader).
269
+ // During push path (local commits), materializerHashLeader is always Option.none(), so this condition
270
+ // will never be met. The check happens when the same event comes back from the leader during sync,
271
+ // allowing us to compare the leader's computed hash with our local re-materialization hash.
272
+ if (
273
+ materializerHashLeader._tag === 'Some' &&
274
+ materializerHash._tag === 'Some' &&
275
+ materializerHashLeader.value !== materializerHash.value
276
+ ) {
277
+ return yield* MaterializerHashMismatchError.make({ eventName: eventEncoded.name })
278
+ }
289
279
 
290
- this[StoreInternalsSymbol].sqliteDbWrapper.debug.head = eventEncoded.seqNum
280
+ const span = yield* OtelTracer.currentOtelSpan.pipe(Effect.orDie)
281
+ const otelContext = otel.trace.setSpan(otel.context.active(), span)
282
+
283
+ const writeTablesForEvent = new Set<string>()
284
+
285
+ const exec = () => {
286
+ for (const { statementSql, bindValues, writeTables = dbState.getTablesUsed(statementSql) } of execArgsArr) {
287
+ try {
288
+ dbState.cachedExecute(statementSql, bindValues, {
289
+ otelContext,
290
+ writeTables,
291
+ })
292
+ } catch (cause) {
293
+ // TOOD refactor with `SqliteError`
294
+ throw UnknownError.make({
295
+ cause,
296
+ note: `Error executing materializer for event "${eventEncoded.name}".\nStatement: ${statementSql}\nBind values: ${JSON.stringify(bindValues)}`,
297
+ })
291
298
  }
299
+
300
+ // durationMsTotal += durationMs
301
+ for (const table of writeTables) {
302
+ writeTablesForEvent.add(table)
303
+ }
304
+
305
+ dbState.debug.head = eventEncoded.seqNum
292
306
  }
307
+ }
293
308
 
294
- const sessionChangeset = this[StoreInternalsSymbol].sqliteDbWrapper.withChangeset(exec).changeset
295
- yield* stateHead.set(eventEncoded.seqNum)
309
+ const changeset = dbState.withChangeset(exec).changeset
310
+ yield* materializationJournal.record({ key: eventEncoded.seqNum, changeset })
296
311
 
297
- return { writeTables: writeTablesForEvent, sessionChangeset, materializerHash }
298
- }).pipe(
299
- SqliteDbHelper.withSavepoint(clientSession.sqliteDb),
300
- Effect.mapError((cause) => MaterializeError.make({ cause })),
312
+ return { writeTables: writeTablesForEvent, materializerHash }
313
+ }).pipe(
314
+ Effect.provideContext(materializationContext),
315
+ Effect.mapError((cause) =>
316
+ MaterializationJournal.isMaterializationJournalError(cause) === true
317
+ ? cause
318
+ : MaterializeError.make({ cause }),
301
319
  ),
302
- ),
303
- rollback: (changeset) => {
304
- this[StoreInternalsSymbol].sqliteDbWrapper.rollback(changeset)
305
- },
320
+ ),
306
321
  refreshTables: (tables) => {
307
322
  const tablesToUpdate = [] as [Ref<null, ReactivityGraphContext, RefreshReason>, null][]
308
323
  for (const tableName of tables) {
@@ -318,7 +333,7 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TConte
318
333
  }),
319
334
  },
320
335
  confirmUnsavedChanges,
321
- }).pipe(Effect.provideService(StateHead.StateHead, stateHead), Effect.runSyncWith(effectContext.services))
336
+ }).pipe(Effect.provideContext(materializationContext), Effect.runSyncWith(effectContext.services))
322
337
 
323
338
  // TODO generalize the `tableRefs` concept to allow finer-grained refs
324
339
  const tableRefs: { [key: string]: Ref<null, ReactivityGraphContext, RefreshReason> } = {}
@@ -387,9 +402,6 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TConte
387
402
  yield* syncProcessor.boot
388
403
  })
389
404
 
390
- // Build Sqlite wrapper last to avoid using getters before internals are set
391
- const sqliteDbWrapper = new SqliteDbWrapper({ otel: otelOptions, db: clientSession.sqliteDb })
392
-
393
405
  // Initialize internals bag
394
406
  this[StoreInternalsSymbol] = {
395
407
  eventSchema: LiveStoreEvent.Client.makeSchemaMemo(schema) as Schema.Codec<
@@ -871,22 +883,7 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TConte
871
883
 
872
884
  if (events.length === 0) return
873
885
 
874
- const localServices = yield* Effect.context()
875
-
876
- const encodedEvents = yield* this[StoreInternalsSymbol].syncProcessor.encodeEvents(events)
877
-
878
- const { writeTables } = yield* Effect.try({
879
- try: () => {
880
- const materialize = () =>
881
- this[StoreInternalsSymbol].syncProcessor
882
- .materializeEvents(encodedEvents)
883
- .pipe(Effect.runSyncWith(localServices))
884
- return events.length > 1 ? this[StoreInternalsSymbol].sqliteDbWrapper.txn(materialize) : materialize()
885
- },
886
- catch: (cause) => UnknownError.make({ cause }),
887
- })
888
-
889
- yield* this[StoreInternalsSymbol].syncProcessor.push(encodedEvents)
886
+ const { writeTables } = yield* this[StoreInternalsSymbol].syncProcessor.commit(events)
890
887
 
891
888
  const tablesToUpdate: [Ref<null, ReactivityGraphContext, RefreshReason>, null][] = []
892
889
  for (const tableName of writeTables) {
@@ -1159,7 +1156,9 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TConte
1159
1156
  *
1160
1157
  * This is called automatically when the store was created using the React or Effect API.
1161
1158
  */
1162
- shutdown = (cause?: Cause.Cause<UnknownError | MaterializeError>): Effect.Effect<void> => {
1159
+ shutdown = (
1160
+ cause?: Cause.Cause<UnknownError | MaterializeError | MaterializationJournal.MaterializationJournalError>,
1161
+ ): Effect.Effect<void> => {
1163
1162
  this[StoreInternalsSymbol].isShutdown = true
1164
1163
  return this[StoreInternalsSymbol].clientSession.shutdown(
1165
1164
  cause !== undefined ? Exit.failCause(cause) : Exit.succeed(IntentionalShutdownCause.make({ reason: 'manual' })),