@livestore/adapter-node 0.0.0-snapshot-2ef046b02334f52613d31dbe06af53487685edc0 → 0.0.0-snapshot-8115ad48d5a57244358c943ecc92bb0a30274b87
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/dist/.tsbuildinfo +1 -1
- package/dist/client-session/in-memory-adapter.d.ts +1 -1
- package/dist/client-session/in-memory-adapter.d.ts.map +1 -1
- package/dist/client-session/in-memory-adapter.js +10 -10
- package/dist/client-session/in-memory-adapter.js.map +1 -1
- package/dist/client-session/persisted-adapter.js +2 -2
- package/dist/client-session/persisted-adapter.js.map +1 -1
- package/dist/make-leader-worker.d.ts.map +1 -1
- package/dist/make-leader-worker.js +13 -13
- package/dist/make-leader-worker.js.map +1 -1
- package/dist/worker-schema.d.ts +14 -8
- package/dist/worker-schema.d.ts.map +1 -1
- package/dist/worker-schema.js +7 -7
- package/dist/worker-schema.js.map +1 -1
- package/package.json +9 -9
- package/src/client-session/in-memory-adapter.ts +11 -11
- package/src/client-session/persisted-adapter.ts +2 -2
- package/src/make-leader-worker.ts +17 -23
- package/src/worker-schema.ts +14 -6
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
90
|
-
Effect.andThen(LeaderThreadCtx, (_) => _.
|
|
84
|
+
ExportEventlog: () =>
|
|
85
|
+
Effect.andThen(LeaderThreadCtx, (_) => _.dbEventlog.export()).pipe(
|
|
91
86
|
UnexpectedError.mapToUnexpectedError,
|
|
92
|
-
Effect.withSpan('@livestore/adapter-node:worker:
|
|
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
|
|
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,
|
|
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
|
-
//
|
|
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' | '
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
273
|
+
eventlog: dbEventlog.metadata.persistenceInfo,
|
|
280
274
|
},
|
|
281
275
|
}
|
|
282
276
|
}).pipe(Effect.provide(FetchHttpClient.layer)),
|
package/src/worker-schema.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
BootStatus,
|
|
3
|
+
Devtools,
|
|
4
|
+
LeaderAheadError,
|
|
5
|
+
LeaderPullCursor,
|
|
6
|
+
MigrationsReport,
|
|
7
|
+
SyncState,
|
|
8
|
+
UnexpectedError,
|
|
9
|
+
} from '@livestore/common'
|
|
10
|
+
import { EventId, LiveStoreEvent } from '@livestore/common/schema'
|
|
3
11
|
import { Schema, Transferable } from '@livestore/utils/effect'
|
|
4
12
|
|
|
5
13
|
export const WorkerArgv = Schema.parseJson(
|
|
@@ -84,7 +92,7 @@ export namespace LeaderWorkerInner {
|
|
|
84
92
|
|
|
85
93
|
export class PullStream extends Schema.TaggedRequest<PullStream>()('PullStream', {
|
|
86
94
|
payload: {
|
|
87
|
-
cursor:
|
|
95
|
+
cursor: LeaderPullCursor,
|
|
88
96
|
},
|
|
89
97
|
success: Schema.Struct({
|
|
90
98
|
payload: SyncState.PayloadUpstream,
|
|
@@ -95,7 +103,7 @@ export namespace LeaderWorkerInner {
|
|
|
95
103
|
|
|
96
104
|
export class PushToLeader extends Schema.TaggedRequest<PushToLeader>()('PushToLeader', {
|
|
97
105
|
payload: {
|
|
98
|
-
batch: Schema.Array(
|
|
106
|
+
batch: Schema.Array(LiveStoreEvent.AnyEncoded),
|
|
99
107
|
},
|
|
100
108
|
success: Schema.Void,
|
|
101
109
|
failure: Schema.Union(UnexpectedError, LeaderAheadError),
|
|
@@ -116,7 +124,7 @@ export namespace LeaderWorkerInner {
|
|
|
116
124
|
failure: UnexpectedError,
|
|
117
125
|
}) {}
|
|
118
126
|
|
|
119
|
-
export class
|
|
127
|
+
export class ExportEventlog extends Schema.TaggedRequest<ExportEventlog>()('ExportEventlog', {
|
|
120
128
|
payload: {},
|
|
121
129
|
success: Transferable.Uint8Array,
|
|
122
130
|
failure: UnexpectedError,
|
|
@@ -155,7 +163,7 @@ export namespace LeaderWorkerInner {
|
|
|
155
163
|
PushToLeader,
|
|
156
164
|
Export,
|
|
157
165
|
GetRecreateSnapshot,
|
|
158
|
-
|
|
166
|
+
ExportEventlog,
|
|
159
167
|
GetLeaderHead,
|
|
160
168
|
GetLeaderSyncState,
|
|
161
169
|
Shutdown,
|