@livestore/adapter-node 0.3.0-dev.27 → 0.3.0-dev.29

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.
@@ -11,14 +11,9 @@ if (process.execArgv.includes('--inspect')) {
11
11
  import type { SyncOptions } from '@livestore/common'
12
12
  import { Devtools, liveStoreStorageFormatVersion, UnexpectedError } from '@livestore/common'
13
13
  import type { DevtoolsOptions, LeaderSqliteDb } from '@livestore/common/leader-thread'
14
- import {
15
- configureConnection,
16
- LeaderThreadCtx,
17
- makeLeaderThreadLayer,
18
- Mutationlog,
19
- } from '@livestore/common/leader-thread'
14
+ import { configureConnection, Eventlog, LeaderThreadCtx, makeLeaderThreadLayer } from '@livestore/common/leader-thread'
20
15
  import type { LiveStoreSchema } from '@livestore/common/schema'
21
- import { MutationEvent } from '@livestore/common/schema'
16
+ import { LiveStoreEvent } from '@livestore/common/schema'
22
17
  import { makeNodeDevtoolsChannel } from '@livestore/devtools-node-common/web-channel'
23
18
  import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm'
24
19
  import { sqliteDbFactory } from '@livestore/sqlite-wasm/node'
@@ -69,7 +64,7 @@ export const makeWorkerEffect = (options: WorkerOptions) => {
69
64
  PushToLeader: ({ batch }) =>
70
65
  Effect.andThen(LeaderThreadCtx, (_) =>
71
66
  _.syncProcessor.push(
72
- batch.map((item) => new MutationEvent.EncodedWithMeta(item)),
67
+ batch.map((item) => new LiveStoreEvent.EncodedWithMeta(item)),
73
68
  // We'll wait in order to keep back pressure on the client session
74
69
  { waitForProcessing: true },
75
70
  ),
@@ -86,15 +81,15 @@ export const makeWorkerEffect = (options: WorkerOptions) => {
86
81
  UnexpectedError.mapToUnexpectedError,
87
82
  Effect.withSpan('@livestore/adapter-node:worker:Export'),
88
83
  ),
89
- ExportMutationlog: () =>
90
- Effect.andThen(LeaderThreadCtx, (_) => _.dbMutationLog.export()).pipe(
84
+ ExportEventlog: () =>
85
+ Effect.andThen(LeaderThreadCtx, (_) => _.dbEventlog.export()).pipe(
91
86
  UnexpectedError.mapToUnexpectedError,
92
- Effect.withSpan('@livestore/adapter-node:worker:ExportMutationlog'),
87
+ Effect.withSpan('@livestore/adapter-node:worker:ExportEventlog'),
93
88
  ),
94
89
  GetLeaderHead: () =>
95
90
  Effect.gen(function* () {
96
91
  const workerCtx = yield* LeaderThreadCtx
97
- return Mutationlog.getClientHeadFromDb(workerCtx.dbMutationLog)
92
+ return Eventlog.getClientHeadFromDb(workerCtx.dbEventlog)
98
93
  }).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/adapter-node:worker:GetLeaderHead')),
99
94
  GetLeaderSyncState: () =>
100
95
  Effect.gen(function* () {
@@ -120,14 +115,14 @@ export const makeWorkerEffect = (options: WorkerOptions) => {
120
115
  ),
121
116
  Shutdown: () =>
122
117
  Effect.gen(function* () {
123
- // const { db, dbMutationLog } = yield* LeaderThreadCtx
118
+ // const { db, dbEventlog } = yield* LeaderThreadCtx
124
119
  yield* Effect.logDebug('[@livestore/adapter-node:worker] Shutdown')
125
120
 
126
121
  // if (devtools.enabled) {
127
122
  // yield* FiberSet.clear(devtools.connections)
128
123
  // }
129
124
  // db.close()
130
- // dbMutationLog.close()
125
+ // dbEventlog.close()
131
126
 
132
127
  // Buy some time for Otel to flush
133
128
  // TODO find a cleaner way to do this
@@ -178,26 +173,25 @@ const makeLeaderThread = ({
178
173
 
179
174
  const schemaHashSuffix = schema.migrationOptions.strategy === 'manual' ? 'fixed' : schema.hash.toString()
180
175
 
181
- const makeDb = (kind: 'app' | 'mutationlog') =>
176
+ const makeDb = (kind: 'app' | 'eventlog') =>
182
177
  makeSqliteDb({
183
178
  _tag: 'fs',
184
179
  directory: path.join(baseDirectory ?? '', storeId),
185
- fileName:
186
- kind === 'app' ? getAppDbFileName(schemaHashSuffix) : `mutationlog@${liveStoreStorageFormatVersion}.db`,
180
+ fileName: kind === 'app' ? getAppDbFileName(schemaHashSuffix) : `eventlog@${liveStoreStorageFormatVersion}.db`,
187
181
  // TODO enable WAL for nodejs
188
182
  configureDb: (db) =>
189
183
  configureConnection(db, { foreignKeys: true }).pipe(Effect.provide(runtime), Effect.runSync),
190
184
  }).pipe(Effect.acquireRelease((db) => Effect.sync(() => db.close())))
191
185
 
192
186
  // Might involve some async work, so we're running them concurrently
193
- const [dbReadModel, dbMutationLog] = yield* Effect.all([makeDb('app'), makeDb('mutationlog')], { concurrency: 2 })
187
+ const [dbReadModel, dbEventlog] = yield* Effect.all([makeDb('app'), makeDb('eventlog')], { concurrency: 2 })
194
188
 
195
189
  const devtoolsOptions = yield* makeDevtoolsOptions({
196
190
  devtoolsEnabled: devtools.enabled,
197
191
  devtoolsPort: devtools.port,
198
192
  devtoolsHost: devtools.host,
199
193
  dbReadModel,
200
- dbMutationLog,
194
+ dbEventlog,
201
195
  storeId,
202
196
  clientId,
203
197
  schemaPath,
@@ -212,7 +206,7 @@ const makeLeaderThread = ({
212
206
  makeSqliteDb,
213
207
  syncOptions,
214
208
  dbReadModel,
215
- dbMutationLog,
209
+ dbEventlog,
216
210
  devtoolsOptions,
217
211
  shutdownChannel,
218
212
  syncPayload,
@@ -229,7 +223,7 @@ const getAppDbFileName = (suffix: string) => `app${suffix}@${liveStoreStorageFor
229
223
  const makeDevtoolsOptions = ({
230
224
  devtoolsEnabled,
231
225
  dbReadModel,
232
- dbMutationLog,
226
+ dbEventlog,
233
227
  storeId,
234
228
  clientId,
235
229
  devtoolsPort,
@@ -238,7 +232,7 @@ const makeDevtoolsOptions = ({
238
232
  }: {
239
233
  devtoolsEnabled: boolean
240
234
  dbReadModel: LeaderSqliteDb
241
- dbMutationLog: LeaderSqliteDb
235
+ dbEventlog: LeaderSqliteDb
242
236
  storeId: string
243
237
  clientId: string
244
238
  devtoolsPort: number
@@ -276,7 +270,7 @@ const makeDevtoolsOptions = ({
276
270
  devtoolsWebChannel,
277
271
  persistenceInfo: {
278
272
  readModel: dbReadModel.metadata.persistenceInfo,
279
- mutationLog: dbMutationLog.metadata.persistenceInfo,
273
+ eventlog: dbEventlog.metadata.persistenceInfo,
280
274
  },
281
275
  }
282
276
  }).pipe(Effect.provide(FetchHttpClient.layer)),
@@ -7,7 +7,7 @@ import {
7
7
  SyncState,
8
8
  UnexpectedError,
9
9
  } from '@livestore/common'
10
- import { EventId, MutationEvent } from '@livestore/common/schema'
10
+ import { EventId, LiveStoreEvent } from '@livestore/common/schema'
11
11
  import { Schema, Transferable } from '@livestore/utils/effect'
12
12
 
13
13
  export const WorkerArgv = Schema.parseJson(
@@ -103,7 +103,7 @@ export namespace LeaderWorkerInner {
103
103
 
104
104
  export class PushToLeader extends Schema.TaggedRequest<PushToLeader>()('PushToLeader', {
105
105
  payload: {
106
- batch: Schema.Array(MutationEvent.AnyEncoded),
106
+ batch: Schema.Array(LiveStoreEvent.AnyEncoded),
107
107
  },
108
108
  success: Schema.Void,
109
109
  failure: Schema.Union(UnexpectedError, LeaderAheadError),
@@ -124,7 +124,7 @@ export namespace LeaderWorkerInner {
124
124
  failure: UnexpectedError,
125
125
  }) {}
126
126
 
127
- export class ExportMutationlog extends Schema.TaggedRequest<ExportMutationlog>()('ExportMutationlog', {
127
+ export class ExportEventlog extends Schema.TaggedRequest<ExportEventlog>()('ExportEventlog', {
128
128
  payload: {},
129
129
  success: Transferable.Uint8Array,
130
130
  failure: UnexpectedError,
@@ -163,7 +163,7 @@ export namespace LeaderWorkerInner {
163
163
  PushToLeader,
164
164
  Export,
165
165
  GetRecreateSnapshot,
166
- ExportMutationlog,
166
+ ExportEventlog,
167
167
  GetLeaderHead,
168
168
  GetLeaderSyncState,
169
169
  Shutdown,
package/tmp/pack.tgz CHANGED
Binary file
@@ -1,30 +0,0 @@
1
- import { Effect, Queue, Stream } from '@livestore/utils/effect'
2
- import { PlatformNode } from '@livestore/utils/node'
3
-
4
- const main = Effect.gen(function* () {
5
- const queue = yield* Queue.unbounded<number>()
6
-
7
- yield* Queue.shutdown(queue)
8
-
9
- // yield* Effect.gen(function* () {
10
- // yield* Queue.offer(queue, 1)
11
- // yield* Queue.shutdown(queue)
12
- // }).pipe(Effect.delay(200), Effect.forkScoped)
13
-
14
- yield* Effect.addFinalizer((exit) => Effect.log('finalizer', exit))
15
-
16
- // const exit = yield* Stream.fromQueue(queue).pipe(
17
- // Stream.tap((n) => Effect.log(n)),
18
- // Stream.runDrain,
19
- // Effect.exit,
20
- // )
21
-
22
- const exit = yield* Effect.andThen(Effect.void, () => Stream.fromQueue(queue)).pipe(
23
- Stream.unwrap,
24
- Stream.tap((n) => Effect.log(n)),
25
- Stream.runDrain,
26
- Effect.exit,
27
- )
28
-
29
- console.log('exit', exit)
30
- }).pipe(Effect.scoped, PlatformNode.NodeRuntime.runMain)