@livestore/adapter-node 0.4.0-dev.9 → 0.5.0-dev.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.
Files changed (49) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/client-session/adapter.d.ts +69 -3
  3. package/dist/client-session/adapter.d.ts.map +1 -1
  4. package/dist/client-session/adapter.js +160 -62
  5. package/dist/client-session/adapter.js.map +1 -1
  6. package/dist/devtools/devtools-server.d.ts.map +1 -1
  7. package/dist/devtools/devtools-server.js +25 -19
  8. package/dist/devtools/devtools-server.js.map +1 -1
  9. package/dist/devtools/mod.d.ts +1 -1
  10. package/dist/devtools/mod.d.ts.map +1 -1
  11. package/dist/devtools/mod.js +1 -1
  12. package/dist/devtools/mod.js.map +1 -1
  13. package/dist/devtools/vite-dev-server.d.ts +22 -4
  14. package/dist/devtools/vite-dev-server.d.ts.map +1 -1
  15. package/dist/devtools/vite-dev-server.js +45 -11
  16. package/dist/devtools/vite-dev-server.js.map +1 -1
  17. package/dist/leader-thread-shared.d.ts +8 -7
  18. package/dist/leader-thread-shared.d.ts.map +1 -1
  19. package/dist/leader-thread-shared.js +19 -16
  20. package/dist/leader-thread-shared.js.map +1 -1
  21. package/dist/make-leader-worker.d.ts +5 -3
  22. package/dist/make-leader-worker.d.ts.map +1 -1
  23. package/dist/make-leader-worker.js +75 -59
  24. package/dist/make-leader-worker.js.map +1 -1
  25. package/dist/rpc-worker.d.ts +8 -0
  26. package/dist/rpc-worker.d.ts.map +1 -0
  27. package/dist/rpc-worker.js +5 -0
  28. package/dist/rpc-worker.js.map +1 -0
  29. package/dist/shutdown-channel.d.ts.map +1 -1
  30. package/dist/shutdown-channel.js.map +1 -1
  31. package/dist/webchannel.d.ts +1 -1
  32. package/dist/webchannel.d.ts.map +1 -1
  33. package/dist/webchannel.js +17 -18
  34. package/dist/webchannel.js.map +1 -1
  35. package/dist/worker-schema.d.ts +274 -138
  36. package/dist/worker-schema.d.ts.map +1 -1
  37. package/dist/worker-schema.js +79 -45
  38. package/dist/worker-schema.js.map +1 -1
  39. package/package.json +51 -20
  40. package/src/client-session/adapter.ts +228 -124
  41. package/src/devtools/devtools-server.ts +50 -35
  42. package/src/devtools/mod.ts +1 -1
  43. package/src/devtools/vite-dev-server.ts +65 -15
  44. package/src/leader-thread-shared.ts +37 -34
  45. package/src/make-leader-worker.ts +164 -115
  46. package/src/rpc-worker.ts +28 -0
  47. package/src/shutdown-channel.ts +1 -0
  48. package/src/webchannel.ts +21 -28
  49. package/src/worker-schema.ts +132 -117
@@ -1,3 +1,4 @@
1
+ import type { URL } from 'node:url';
1
2
  import { type Adapter, type SyncOptions } from '@livestore/common';
2
3
  import { Schema } from '@livestore/utils/effect';
3
4
  import type { TestingOverrides } from '../leader-thread-shared.ts';
@@ -41,12 +42,77 @@ export interface NodeAdapterOptions {
41
42
  overrides?: TestingOverrides;
42
43
  };
43
44
  }
44
- /** Runs everything in the same thread. Use `makeWorkerAdapter` for multi-threaded implementation. */
45
+ /**
46
+ * Creates a single-threaded LiveStore adapter for Node.js applications.
47
+ *
48
+ * This adapter runs the leader thread (persistence and sync) in the same thread as
49
+ * your application. Suitable for CLI tools, scripts, and applications where simplicity
50
+ * is preferred over maximum performance.
51
+ *
52
+ * For production servers or performance-critical applications, consider `makeWorkerAdapter`
53
+ * which runs persistence/sync in a separate worker thread.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { makeAdapter } from '@livestore/adapter-node'
58
+ * import { makeWsSync } from '@livestore/sync-cf/client'
59
+ *
60
+ * const adapter = makeAdapter({
61
+ * storage: { type: 'fs', baseDirectory: './data' },
62
+ * sync: {
63
+ * backend: makeWsSync({ url: 'wss://api.example.com/sync' }),
64
+ * },
65
+ * })
66
+ * ```
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * // With DevTools support
71
+ * const adapter = makeAdapter({
72
+ * storage: { type: 'fs', baseDirectory: './data' },
73
+ * devtools: {
74
+ * schemaPath: new URL('./schema.ts', import.meta.url),
75
+ * port: 4242,
76
+ * },
77
+ * })
78
+ * ```
79
+ *
80
+ * @see https://livestore.dev/docs/reference/adapters/node for setup guide
81
+ */
45
82
  export declare const makeAdapter: ({ sync, ...options }: NodeAdapterOptions & {
46
83
  sync?: SyncOptions;
47
84
  }) => Adapter;
48
85
  /**
49
- * Runs persistence and syncing in a worker thread.
86
+ * Creates a multi-threaded LiveStore adapter for Node.js applications.
87
+ *
88
+ * This adapter runs the leader thread (persistence, sync, and heavy SQLite operations)
89
+ * in a separate worker thread, keeping your main thread responsive. Recommended for
90
+ * production servers and performance-critical applications.
91
+ *
92
+ * You must create a worker file that calls `makeLeaderWorker()` and pass its URL
93
+ * to this function.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * // In your main file:
98
+ * import { makeWorkerAdapter } from '@livestore/adapter-node'
99
+ *
100
+ * const adapter = makeWorkerAdapter({
101
+ * storage: { type: 'fs', baseDirectory: './data' },
102
+ * workerUrl: new URL('./livestore.worker.ts', import.meta.url),
103
+ * })
104
+ * ```
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * // In livestore.worker.ts:
109
+ * import { makeLeaderWorker } from '@livestore/adapter-node/worker'
110
+ * import { schema } from './schema'
111
+ *
112
+ * makeLeaderWorker({ schema })
113
+ * ```
114
+ *
115
+ * @see https://livestore.dev/docs/reference/adapters/node for setup guide
50
116
  */
51
117
  export declare const makeWorkerAdapter: ({ workerUrl, workerExtraArgs, ...options }: NodeAdapterOptions & {
52
118
  /**
@@ -57,6 +123,6 @@ export declare const makeWorkerAdapter: ({ workerUrl, workerExtraArgs, ...option
57
123
  * Extra arguments to pass to the worker which can be accessed in the worker
58
124
  * via `getWorkerArgs()`
59
125
  */
60
- workerExtraArgs?: Schema.JsonValue;
126
+ workerExtraArgs?: Schema.Json;
61
127
  }) => Adapter;
62
128
  //# sourceMappingURL=adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/client-session/adapter.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,OAAO,EAQZ,KAAK,WAAW,EAEjB,MAAM,mBAAmB,CAAA;AAO1B,OAAO,EAWL,MAAM,EAKP,MAAM,yBAAyB,CAAA;AAIhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAGlE,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAA;AAEnD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,YAAY,CAAC,WAAW,CAAA;IACjC,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAE1B,QAAQ,CAAC,EAAE;QACT,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;QACxB;;;;WAIG;QACH,IAAI,CAAC,EAAE,MAAM,CAAA;QACb;;WAEG;QACH,IAAI,CAAC,EAAE,MAAM,CAAA;QACb;;;;WAIG;QACH,yBAAyB,CAAC,EAAE,OAAO,CAAA;KACpC,CAAA;IAED,uCAAuC;IACvC,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,gBAAgB,CAAA;KAC7B,CAAA;CACF;AAED,qGAAqG;AACrG,eAAO,MAAM,WAAW,GAAI,sBAGzB,kBAAkB,GAAG;IACtB,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB,KAAG,OAA2F,CAAA;AAE/F;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,4CAI/B,kBAAkB,GAAG;IACtB;;OAEG;IACH,SAAS,EAAE,GAAG,CAAA;IACd;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,SAAS,CAAA;CACnC,KAAG,OAAgH,CAAA"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/client-session/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EA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@@
1
1
  import { hostname } from 'node:os';
2
2
  import path from 'node:path';
3
3
  import * as WT from 'node:worker_threads';
4
- import { ClientSessionLeaderThreadProxy, IntentionalShutdownCause, makeClientSession, UnexpectedError, } from '@livestore/common';
5
- import { Eventlog, LeaderThreadCtx } from '@livestore/common/leader-thread';
4
+ import { ClientSessionLeaderThreadProxy, IntentionalShutdownCause, makeClientSession, UnknownError, } from '@livestore/common';
5
+ import { Eventlog, LeaderThreadCtx, streamEventsWithSyncState } from '@livestore/common/leader-thread';
6
6
  import { LiveStoreEvent } from '@livestore/common/schema';
7
7
  import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm';
8
8
  import { sqliteDbFactory } from '@livestore/sqlite-wasm/node';
9
9
  import { omitUndefineds } from '@livestore/utils';
10
- import { Cause, Effect, Exit, FetchHttpClient, Fiber, FileSystem, Layer, ParseResult, Queue, Schedule, Schema, Stream, SubscriptionRef, Worker, WorkerError, } from '@livestore/utils/effect';
10
+ import { Cause, Effect, Exit, FetchHttpClient, Fiber, FileSystem, Layer, Queue, RpcClient, RpcWorker, Schedule, Schema, Scope, Stream, Subscribable, SubscriptionRef, } from '@livestore/utils/effect';
11
11
  import { PlatformNode } from '@livestore/utils/node';
12
12
  import * as Webmesh from '@livestore/webmesh';
13
13
  import { makeLeaderThread } from "../leader-thread-shared.js";
14
+ import { dieOnRpcClientError, dieOnRpcClientErrorStream } from "../rpc-worker.js";
14
15
  import { makeShutdownChannel } from "../shutdown-channel.js";
15
16
  import * as WorkerSchema from "../worker-schema.js";
16
- /** Runs everything in the same thread. Use `makeWorkerAdapter` for multi-threaded implementation. */
17
+ /**
18
+ * Creates a single-threaded LiveStore adapter for Node.js applications.
19
+ *
20
+ * This adapter runs the leader thread (persistence and sync) in the same thread as
21
+ * your application. Suitable for CLI tools, scripts, and applications where simplicity
22
+ * is preferred over maximum performance.
23
+ *
24
+ * For production servers or performance-critical applications, consider `makeWorkerAdapter`
25
+ * which runs persistence/sync in a separate worker thread.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { makeAdapter } from '@livestore/adapter-node'
30
+ * import { makeWsSync } from '@livestore/sync-cf/client'
31
+ *
32
+ * const adapter = makeAdapter({
33
+ * storage: { type: 'fs', baseDirectory: './data' },
34
+ * sync: {
35
+ * backend: makeWsSync({ url: 'wss://api.example.com/sync' }),
36
+ * },
37
+ * })
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * // With DevTools support
43
+ * const adapter = makeAdapter({
44
+ * storage: { type: 'fs', baseDirectory: './data' },
45
+ * devtools: {
46
+ * schemaPath: new URL('./schema.ts', import.meta.url),
47
+ * port: 4242,
48
+ * },
49
+ * })
50
+ * ```
51
+ *
52
+ * @see https://livestore.dev/docs/reference/adapters/node for setup guide
53
+ */
17
54
  export const makeAdapter = ({ sync, ...options }) => makeAdapterImpl({ ...options, leaderThread: { _tag: 'single-threaded', sync } });
18
55
  /**
19
- * Runs persistence and syncing in a worker thread.
56
+ * Creates a multi-threaded LiveStore adapter for Node.js applications.
57
+ *
58
+ * This adapter runs the leader thread (persistence, sync, and heavy SQLite operations)
59
+ * in a separate worker thread, keeping your main thread responsive. Recommended for
60
+ * production servers and performance-critical applications.
61
+ *
62
+ * You must create a worker file that calls `makeLeaderWorker()` and pass its URL
63
+ * to this function.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * // In your main file:
68
+ * import { makeWorkerAdapter } from '@livestore/adapter-node'
69
+ *
70
+ * const adapter = makeWorkerAdapter({
71
+ * storage: { type: 'fs', baseDirectory: './data' },
72
+ * workerUrl: new URL('./livestore.worker.ts', import.meta.url),
73
+ * })
74
+ * ```
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * // In livestore.worker.ts:
79
+ * import { makeLeaderWorker } from '@livestore/adapter-node/worker'
80
+ * import { schema } from './schema'
81
+ *
82
+ * makeLeaderWorker({ schema })
83
+ * ```
84
+ *
85
+ * @see https://livestore.dev/docs/reference/adapters/node for setup guide
20
86
  */
21
87
  export const makeWorkerAdapter = ({ workerUrl, workerExtraArgs, ...options }) => makeAdapterImpl({ ...options, leaderThread: { _tag: 'multi-threaded', workerUrl, workerExtraArgs } });
22
88
  const makeAdapterImpl = ({ storage, devtools: devtoolsOptionsInput, clientId = hostname(),
23
89
  // TODO make this dynamic and actually support multiple sessions
24
90
  sessionId = 'static', testing, resetPersistence = false, leaderThread: leaderThreadInput, }) => ((adapterArgs) => Effect.gen(function* () {
25
- const { storeId, devtoolsEnabled, shutdown, bootStatusQueue, syncPayload, schema } = adapterArgs;
91
+ const { storeId, devtoolsEnabled, shutdown, bootStatusQueue, syncPayloadEncoded, syncPayloadSchema, schema } = adapterArgs;
26
92
  yield* Queue.offer(bootStatusQueue, { stage: 'loading' });
27
93
  const sqlite3 = yield* Effect.promise(() => loadSqlite3Wasm());
28
94
  const makeSqliteDb = yield* sqliteDbFactory({ sqlite3 });
@@ -37,14 +103,14 @@ sessionId = 'static', testing, resetPersistence = false, leaderThread: leaderThr
37
103
  if (resetPersistence === true) {
38
104
  yield* shutdownChannel
39
105
  .send(IntentionalShutdownCause.make({ reason: 'adapter-reset' }))
40
- .pipe(UnexpectedError.mapToUnexpectedError);
106
+ .pipe(UnknownError.mapToUnknownError);
41
107
  yield* resetNodePersistence({ storage, storeId });
42
108
  }
43
- yield* shutdownChannel.listen.pipe(Stream.flatten(), Stream.tap((cause) => shutdown(cause._tag === 'LiveStore.IntentionalShutdownCause' ? Exit.succeed(cause) : Exit.fail(cause))), Stream.runDrain, Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
109
+ yield* shutdownChannel.listen.pipe(Stream.mapEffect(Effect.fromResult), Stream.tap((cause) => shutdown(cause._tag === 'IntentionalShutdownCause' ? Exit.succeed(cause) : Exit.fail(cause))), Stream.runDrain, Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
44
110
  const syncInMemoryDb = yield* makeSqliteDb({ _tag: 'in-memory' }).pipe(Effect.orDie);
45
111
  // TODO actually implement this multi-session support
46
112
  const lockStatus = yield* SubscriptionRef.make('has-lock');
47
- const devtoolsOptions = devtoolsEnabled && devtoolsOptionsInput !== undefined
113
+ const devtoolsOptions = devtoolsEnabled === true && devtoolsOptionsInput !== undefined
48
114
  ? {
49
115
  enabled: true,
50
116
  schemaPath: typeof devtoolsOptionsInput.schemaPath === 'string'
@@ -66,10 +132,11 @@ sessionId = 'static', testing, resetPersistence = false, leaderThread: leaderThr
66
132
  storage,
67
133
  ...omitUndefineds({
68
134
  syncOptions: leaderThreadInput.sync,
69
- syncPayload,
135
+ syncPayloadEncoded,
136
+ syncPayloadSchema,
70
137
  testing,
71
138
  }),
72
- }).pipe(UnexpectedError.mapToUnexpectedError)
139
+ }).pipe(UnknownError.mapToUnknownError)
73
140
  : yield* makeWorkerLeaderThread({
74
141
  shutdown,
75
142
  storeId,
@@ -80,8 +147,8 @@ sessionId = 'static', testing, resetPersistence = false, leaderThread: leaderThr
80
147
  storage,
81
148
  devtools: devtoolsOptions,
82
149
  bootStatusQueue,
83
- syncPayload,
84
- });
150
+ syncPayloadEncoded,
151
+ }).pipe(UnknownError.mapToUnknownError);
85
152
  syncInMemoryDb.import(initialSnapshot);
86
153
  syncInMemoryDb.debug.head = leaderThread.initialState.leaderHead;
87
154
  const clientSession = yield* makeClientSession({
@@ -89,7 +156,7 @@ sessionId = 'static', testing, resetPersistence = false, leaderThread: leaderThr
89
156
  sqliteDb: syncInMemoryDb,
90
157
  webmeshMode: 'proxy',
91
158
  connectWebmeshNode: Effect.fnUntraced(function* ({ webmeshNode }) {
92
- if (devtoolsOptions.enabled) {
159
+ if (devtoolsOptions.enabled === true) {
93
160
  yield* Webmesh.connectViaWebSocket({
94
161
  node: webmeshNode,
95
162
  url: `ws://${devtoolsOptions.host}:${devtoolsOptions.port}`,
@@ -104,6 +171,7 @@ sessionId = 'static', testing, resetPersistence = false, leaderThread: leaderThr
104
171
  isLeader: true,
105
172
  // Not really applicable for node as there is no "reload the app" concept
106
173
  registerBeforeUnload: (_onBeforeUnload) => () => { },
174
+ origin: undefined,
107
175
  });
108
176
  return clientSession;
109
177
  }).pipe(Effect.withSpan('@livestore/adapter-node:adapter'), Effect.provide(Layer.mergeAll(PlatformNode.NodeFileSystem.layer, FetchHttpClient.layer))));
@@ -114,92 +182,122 @@ const resetNodePersistence = ({ storage, storeId, }) => {
114
182
  const directory = path.join(storage.baseDirectory ?? '', storeId);
115
183
  return Effect.gen(function* () {
116
184
  const fs = yield* FileSystem.FileSystem;
117
- const directoryExists = yield* fs.exists(directory).pipe(UnexpectedError.mapToUnexpectedError);
185
+ const directoryExists = yield* fs.exists(directory).pipe(UnknownError.mapToUnknownError);
118
186
  if (directoryExists === false) {
119
187
  return;
120
188
  }
121
- yield* fs.remove(directory, { recursive: true }).pipe(UnexpectedError.mapToUnexpectedError);
189
+ yield* fs.remove(directory, { recursive: true }).pipe(UnknownError.mapToUnknownError);
122
190
  }).pipe(Effect.retry({ schedule: Schedule.exponentialBackoff10Sec }), Effect.withSpan('@livestore/adapter-node:resetPersistence', { attributes: { directory } }));
123
191
  };
124
- const makeLocalLeaderThread = ({ storeId, clientId, schema, makeSqliteDb, syncOptions, syncPayload, storage, devtools, testing, }) => Effect.gen(function* () {
125
- const layer = yield* Layer.build(makeLeaderThread({
192
+ const makeLocalLeaderThread = ({ storeId, clientId, schema, makeSqliteDb, syncOptions, syncPayloadEncoded, syncPayloadSchema, storage, devtools, testing, }) => Effect.gen(function* () {
193
+ // The single-threaded node adapter runs the leader thread co-located in the same runtime as the
194
+ // client session. Unlike the worker adapters (where the leader lives on its own event loop and drains
195
+ // pushes independently), a co-located leader only makes progress when the surrounding fibers yield.
196
+ //
197
+ // We give the leader thread its own dedicated scope whose teardown finalizer is registered *before*
198
+ // `makeClientSession`. Finalizers run in reverse registration order, so on store shutdown the client
199
+ // session tears down first and only then is the leader thread scope closed — keeping the leader (and
200
+ // its SQLite connections) alive while the client-session pusher's in-flight batch is still being
201
+ // persisted. Building the leader into the ambient store scope instead (via `Layer.build`) interrupts
202
+ // the leader's push drainer concurrently with the client session, dropping the in-flight batch and
203
+ // causing silent data loss on commit-then-shutdown.
204
+ const leaderThreadScope = yield* Scope.make();
205
+ yield* Effect.addFinalizer((exit) => Scope.close(leaderThreadScope, exit));
206
+ const leaderThreadLayer = yield* makeLeaderThread({
126
207
  storeId,
127
208
  clientId,
128
209
  schema,
129
210
  syncOptions,
130
211
  storage,
131
- syncPayload,
212
+ syncPayloadEncoded,
213
+ syncPayloadSchema,
132
214
  devtools,
133
215
  makeSqliteDb,
134
216
  ...omitUndefineds({ testing: testing?.overrides }),
135
- }).pipe(Layer.unwrapScoped));
217
+ }).pipe(Scope.provide(leaderThreadScope));
218
+ const layer = yield* Layer.buildWithScope(leaderThreadLayer, leaderThreadScope);
136
219
  return yield* Effect.gen(function* () {
137
- const { dbState, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState } = yield* LeaderThreadCtx;
220
+ const { dbState, dbEventlog, syncProcessor, extraIncomingMessagesQueue, initialState, networkStatus } = yield* LeaderThreadCtx;
138
221
  const initialLeaderHead = Eventlog.getClientHeadFromDb(dbEventlog);
139
222
  const leaderThread = ClientSessionLeaderThreadProxy.of({
140
223
  events: {
141
224
  pull: ({ cursor }) => syncProcessor.pull({ cursor }),
142
- push: (batch) => syncProcessor.push(batch.map((item) => new LiveStoreEvent.EncodedWithMeta(item)), { waitForProcessing: true }),
225
+ push: (batch) =>
226
+ // Mirror the worker `PushToLeader` handler which runs the leader push uninterruptibly.
227
+ // Together with the dedicated `leaderThreadScope` above, this guarantees an in-flight batch is
228
+ // fully persisted by the (still-live) leader before the co-located pusher fiber is interrupted
229
+ // on store shutdown.
230
+ syncProcessor
231
+ .push(batch.map((item) => new LiveStoreEvent.Client.EncodedWithMeta(item)))
232
+ .pipe(Effect.uninterruptible),
233
+ stream: (options) => streamEventsWithSyncState({
234
+ dbEventlog,
235
+ syncState: syncProcessor.syncState,
236
+ options,
237
+ }),
238
+ },
239
+ initialState: {
240
+ leaderHead: initialLeaderHead,
241
+ migrationsReport: initialState.migrationsReport,
242
+ storageMode: 'persisted',
143
243
  },
144
- initialState: { leaderHead: initialLeaderHead, migrationsReport: initialState.migrationsReport },
145
244
  export: Effect.sync(() => dbState.export()),
146
245
  getEventlogData: Effect.sync(() => dbEventlog.export()),
147
- getSyncState: syncProcessor.syncState,
148
- sendDevtoolsMessage: (message) => extraIncomingMessagesQueue.offer(message),
246
+ syncState: syncProcessor.syncState,
247
+ sendDevtoolsMessage: (message) => Queue.offer(extraIncomingMessagesQueue, message),
248
+ networkStatus,
149
249
  }, { ...omitUndefineds({ overrides: testing?.overrides?.clientSession?.leaderThreadProxy }) });
150
250
  const initialSnapshot = dbState.export();
151
251
  return { leaderThread, initialSnapshot };
152
252
  }).pipe(Effect.provide(layer));
153
253
  });
154
- const makeWorkerLeaderThread = ({ shutdown, storeId, clientId, sessionId, workerUrl, workerExtraArgs, storage, devtools, bootStatusQueue, syncPayload, testing, }) => Effect.gen(function* () {
254
+ const makeWorkerLeaderThread = ({ shutdown, storeId, clientId, sessionId, workerUrl, workerExtraArgs, storage, devtools, bootStatusQueue, syncPayloadEncoded, testing, }) => Effect.gen(function* () {
155
255
  const nodeWorker = new WT.Worker(workerUrl, {
156
- execArgv: process.env.DEBUG_WORKER ? ['--inspect --enable-source-maps'] : ['--enable-source-maps'],
157
- argv: [Schema.encodeSync(WorkerSchema.WorkerArgv)({ storeId, clientId, sessionId, extraArgs: workerExtraArgs })],
256
+ execArgv: process.env.DEBUG_WORKER !== undefined ? ['--inspect --enable-source-maps'] : ['--enable-source-maps'],
257
+ argv: [
258
+ yield* Schema.encodeEffect(WorkerSchema.WorkerArgv)({
259
+ storeId,
260
+ clientId,
261
+ sessionId,
262
+ extraArgs: workerExtraArgs,
263
+ }).pipe(Effect.orDie),
264
+ ],
158
265
  });
159
- const nodeWorkerLayer = yield* Layer.build(PlatformNode.NodeWorker.layer(() => nodeWorker));
160
- const worker = yield* Worker.makePoolSerialized({
161
- size: 1,
162
- concurrency: 100,
163
- initialMessage: () => new WorkerSchema.LeaderWorkerInnerInitialMessage({
164
- storeId,
165
- clientId,
166
- storage,
167
- devtools,
168
- syncPayload,
169
- }),
170
- }).pipe(Effect.provide(nodeWorkerLayer), UnexpectedError.mapToUnexpectedError, Effect.tapErrorCause((cause) => shutdown(Exit.failCause(cause))), Effect.withSpan('@livestore/adapter-node:adapter:setupLeaderThread'));
171
- const runInWorker = (req) => worker.executeEffect(req).pipe(Effect.logWarnIfTakesLongerThan({
172
- label: `@livestore/adapter-node:client-session:runInWorker:${req._tag}`,
266
+ const innerWorkerContext = yield* Layer.build(RpcClient.layerProtocolWorker({ size: 1, concurrency: 100 }).pipe(Layer.provide(PlatformNode.NodeWorker.layer(() => nodeWorker)), Layer.provide(RpcWorker.layerInitialMessage(WorkerSchema.LeaderWorkerInnerInitialMessage.payloadSchema, Effect.succeed({ storeId, clientId, storage, devtools, syncPayloadEncoded })))));
267
+ const worker = yield* RpcClient.make(WorkerSchema.LeaderWorkerInnerRpcs).pipe(Effect.provide(innerWorkerContext), UnknownError.mapToUnknownError, Effect.tapCause((cause) => shutdown(Exit.failCause(cause))), Effect.withSpan('@livestore/adapter-node:adapter:setupLeaderThread'));
268
+ const runInWorker = (tag, effect) => effect.pipe(dieOnRpcClientError, Effect.logWarnIfTakesLongerThan({
269
+ label: `@livestore/adapter-node:client-session:runInWorker:${tag}`,
173
270
  duration: 2000,
174
- }), Effect.withSpan(`@livestore/adapter-node:client-session:runInWorker:${req._tag}`), Effect.mapError((cause) => Schema.is(UnexpectedError)(cause)
175
- ? cause
176
- : ParseResult.isParseError(cause) || Schema.is(WorkerError.WorkerError)(cause)
177
- ? new UnexpectedError({ cause })
178
- : cause), Effect.catchAllDefect((cause) => new UnexpectedError({ cause })));
179
- const runInWorkerStream = (req) => worker.execute(req).pipe(Stream.mapError((cause) => Schema.is(UnexpectedError)(cause)
180
- ? cause
181
- : ParseResult.isParseError(cause) || Schema.is(WorkerError.WorkerError)(cause)
182
- ? new UnexpectedError({ cause })
183
- : cause), Stream.withSpan(`@livestore/adapter-node:client-session:runInWorkerStream:${req._tag}`));
184
- const bootStatusFiber = yield* runInWorkerStream(new WorkerSchema.LeaderWorkerInnerBootStatusStream()).pipe(Stream.tap((bootStatus) => Queue.offer(bootStatusQueue, bootStatus)), Stream.runDrain, Effect.tapErrorCause((cause) => (Cause.isInterruptedOnly(cause) ? Effect.void : shutdown(Exit.failCause(cause)))), Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
185
- yield* Queue.awaitShutdown(bootStatusQueue).pipe(Effect.andThen(Fiber.interrupt(bootStatusFiber)), Effect.tapCauseLogPretty, Effect.forkScoped);
186
- const initialLeaderHead = yield* runInWorker(new WorkerSchema.LeaderWorkerInnerGetLeaderHead());
187
- const bootResult = yield* runInWorker(new WorkerSchema.LeaderWorkerInnerGetRecreateSnapshot()).pipe(Effect.timeout(10_000), UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/adapter-node:client-session:export'));
271
+ }), Effect.withSpan(`@livestore/adapter-node:client-session:runInWorker:${tag}`));
272
+ const runInWorkerStream = (tag, stream) => stream.pipe(dieOnRpcClientErrorStream, Stream.withSpan(`@livestore/adapter-node:client-session:runInWorkerStream:${tag}`));
273
+ const bootStatusFiber = yield* runInWorkerStream('BootStatusStream', worker.BootStatusStream({})).pipe(Stream.tap((bootStatus) => Queue.offer(bootStatusQueue, bootStatus)), Stream.runDrain, Effect.tapCause((cause) => Cause.hasInterruptsOnly(cause) === true ? Effect.void : shutdown(Exit.failCause(cause))), Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
274
+ yield* Queue.await(bootStatusQueue).pipe(Effect.andThen(Fiber.interrupt(bootStatusFiber)), Effect.tapCauseLogPretty, Effect.forkScoped);
275
+ const initialLeaderHead = yield* runInWorker('GetLeaderHead', worker.GetLeaderHead({}));
276
+ const bootResult = yield* runInWorker('GetRecreateSnapshot', worker.GetRecreateSnapshot({})).pipe(Effect.timeoutOrDie(10_000), Effect.withSpan('@livestore/adapter-node:client-session:export'));
188
277
  const leaderThread = ClientSessionLeaderThreadProxy.of({
189
278
  events: {
190
- pull: ({ cursor }) => runInWorkerStream(new WorkerSchema.LeaderWorkerInnerPullStream({ cursor })).pipe(Stream.orDie),
191
- push: (batch) => runInWorker(new WorkerSchema.LeaderWorkerInnerPushToLeader({ batch })).pipe(Effect.withSpan('@livestore/adapter-node:client-session:pushToLeader', {
279
+ pull: ({ cursor }) => runInWorkerStream('PullStream', worker.PullStream({ cursor })).pipe(Stream.orDie),
280
+ push: (batch) => runInWorker('PushToLeader', worker.PushToLeader({ batch })).pipe(Effect.withSpan('@livestore/adapter-node:client-session:pushToLeader', {
192
281
  attributes: { batchSize: batch.length },
193
282
  })),
283
+ stream: (options) => runInWorkerStream('StreamEvents', worker.StreamEvents(options)).pipe(Stream.withSpan('@livestore/adapter-node:client-session:streamEvents'), Stream.orDie),
194
284
  },
195
285
  initialState: {
196
286
  leaderHead: initialLeaderHead,
197
287
  migrationsReport: bootResult.migrationsReport,
288
+ storageMode: 'persisted',
198
289
  },
199
- export: runInWorker(new WorkerSchema.LeaderWorkerInnerExport()).pipe(Effect.timeout(10_000), UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/adapter-node:client-session:export')),
200
- getEventlogData: Effect.dieMessage('Not implemented'),
201
- getSyncState: runInWorker(new WorkerSchema.LeaderWorkerInnerGetLeaderSyncState()).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/adapter-node:client-session:getLeaderSyncState')),
202
- sendDevtoolsMessage: (message) => runInWorker(new WorkerSchema.LeaderWorkerInnerExtraDevtoolsMessage({ message })).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/adapter-node:client-session:devtoolsMessageForLeader')),
290
+ export: runInWorker('Export', worker.Export({})).pipe(Effect.timeoutOrDie(10_000), Effect.withSpan('@livestore/adapter-node:client-session:export')),
291
+ getEventlogData: Effect.die('Not implemented'),
292
+ syncState: Subscribable.make({
293
+ get: runInWorker('GetLeaderSyncState', worker.GetLeaderSyncState({})).pipe(Effect.withSpan('@livestore/adapter-node:client-session:getLeaderSyncState')),
294
+ changes: runInWorkerStream('SyncStateStream', worker.SyncStateStream({})).pipe(Stream.orDie),
295
+ }),
296
+ sendDevtoolsMessage: (message) => runInWorker('ExtraDevtoolsMessage', worker.ExtraDevtoolsMessage({ message })).pipe(Effect.withSpan('@livestore/adapter-node:client-session:devtoolsMessageForLeader')),
297
+ networkStatus: Subscribable.make({
298
+ get: runInWorker('GetNetworkStatus', worker.GetNetworkStatus({})).pipe(Effect.orDie),
299
+ changes: runInWorkerStream('NetworkStatusStream', worker.NetworkStatusStream({})).pipe(Stream.orDie),
300
+ }),
203
301
  }, {
204
302
  ...omitUndefineds({ overrides: testing?.overrides?.clientSession?.leaderThreadProxy }),
205
303
  });
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/client-session/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAGL,8BAA8B,EAC9B,wBAAwB,EAGxB,iBAAiB,EAGjB,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,eAAe,EACf,KAAK,EACL,UAAU,EACV,KAAK,EACL,WAAW,EACX,KAAK,EACL,QAA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,CAChF,MAAM,CAAC,QAAQ,CAAC,iEAAiE,CAAC,CACnF;QACH,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC;YAC/B,GAAG,EAAE,WAAW,CAAC,kBAAkB,EAAE,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACpF,OAAO,EAAE,iBAAiB,CAAC,qBAAqB,EAAE,MAAM,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;SACrG,CAAC;KACH,EACD;QACE,GAAG,cAAc,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC;KACvF,CACF,CAAA;IAED,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAA;AAC/D,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"devtools-server.d.ts","sourceRoot":"","sources":["../../src/devtools/devtools-server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAEL,MAAM,EAQP,MAAM,yBAAyB,CAAA;AAMhC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,gDAKjC;IACD,UAAU,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAC1C,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAAC,WAAW,GAAG,SAAS,CAAA;IAC/D,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,KAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CAmGlD,CAAA"}
1
+ {"version":3,"file":"devtools-server.d.ts","sourceRoot":"","sources":["../../src/devtools/devtools-server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAEL,MAAM,EAQP,MAAM,yBAAyB,CAAA;AAgBhC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,gDAKjC;IACD,UAAU,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAC1C,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAAC,WAAW,GAAG,SAAS,CAAA;IAC/D,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,KAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CAwGlD,CAAA"}
@@ -1,23 +1,31 @@
1
1
  import http from 'node:http';
2
2
  import path from 'node:path';
3
- import { isReadonlyArray, LS_DEV } from '@livestore/utils';
3
+ import { LS_DEV } from '@livestore/utils';
4
4
  import { Deferred, Effect, Exit, Headers, HttpMiddleware, HttpServer, HttpServerRequest, HttpServerResponse, Layer, } from '@livestore/utils/effect';
5
5
  import { PlatformNode } from '@livestore/utils/node';
6
6
  import { makeMeshNode, makeWebSocketEdge } from '@livestore/webmesh';
7
7
  import { makeViteMiddleware } from "./vite-dev-server.js";
8
+ /**
9
+ * Determines if a request URL should be routed to the Vite middleware.
10
+ * Includes LiveStore devtools paths and Vite internal paths like `/@fs/`, `/@vite/`, etc.
11
+ */
12
+ const shouldRouteToVite = (url) => url.startsWith('/_livestore') ||
13
+ url.startsWith('/@fs') ||
14
+ url.startsWith('/@vite') ||
15
+ url.startsWith('/@react-refresh');
8
16
  /**
9
17
  * Starts a devtools HTTP/WS server which serves ...
10
18
  * - the Devtools UI via Vite
11
19
  * - the Devtools Protocol via WebSocket Webmesh
12
20
  */
13
21
  export const startDevtoolsServer = ({ schemaPath, clientSessionInfo, port, host, }) => Effect.gen(function* () {
14
- const viteMiddleware = yield* makeViteMiddleware({
22
+ const viteMiddleware = yield* Effect.acquireRelease(makeViteMiddleware({
15
23
  mode: { _tag: 'node', url: `http://${host}:${port}` },
16
- schemaPath: isReadonlyArray(schemaPath)
17
- ? schemaPath.map((schemaPath) => path.resolve(process.cwd(), schemaPath))
18
- : path.resolve(process.cwd(), schemaPath),
24
+ schemaPath: typeof schemaPath === 'string'
25
+ ? path.resolve(process.cwd(), schemaPath)
26
+ : schemaPath.map((schemaPath) => path.resolve(process.cwd(), schemaPath)),
19
27
  viteConfig: (viteConfig) => {
20
- if (LS_DEV) {
28
+ if (LS_DEV === true) {
21
29
  viteConfig.server ??= {};
22
30
  viteConfig.server.fs ??= {};
23
31
  viteConfig.server.fs.strict = false;
@@ -26,12 +34,12 @@ export const startDevtoolsServer = ({ schemaPath, clientSessionInfo, port, host,
26
34
  }
27
35
  return viteConfig;
28
36
  },
29
- }).pipe(Effect.acquireRelease((viteMiddleware) => Effect.promise(() => viteMiddleware.close())));
37
+ }), (viteMiddleware) => Effect.promise(() => viteMiddleware.close()));
30
38
  const relayNodeName = 'ws';
31
39
  const node = yield* makeMeshNode(relayNodeName);
32
40
  const handler = Effect.gen(function* () {
33
41
  const req = yield* HttpServerRequest.HttpServerRequest;
34
- if (Headers.has(req.headers, 'upgrade')) {
42
+ if (Headers.has(req.headers, 'upgrade') === true) {
35
43
  // yield* Effect.logDebug(`WS Relay ${relayNodeName}: WS upgrade request ${req.url}`)
36
44
  const socket = yield* req.upgrade;
37
45
  const { webChannel, from } = yield* makeWebSocketEdge({
@@ -41,37 +49,35 @@ export const startDevtoolsServer = ({ schemaPath, clientSessionInfo, port, host,
41
49
  });
42
50
  // To handle websocket closing, we need to race the `webChannel.closedDeferred` to properly interrupt the handler
43
51
  yield* Effect.raceFirst(Effect.gen(function* () {
44
- yield* node
45
- .addEdge({ target: from, edgeChannel: webChannel, replaceIfExists: true })
46
- .pipe(Effect.acquireRelease(() => node.removeEdge(from).pipe(Effect.orDie)));
47
- if (LS_DEV) {
52
+ yield* Effect.acquireRelease(node.addEdge({ target: from, edgeChannel: webChannel, replaceIfExists: true }), () => node.removeEdge(from).pipe(Effect.orDie));
53
+ if (LS_DEV === true) {
48
54
  yield* Effect.log(`WS Relay ${relayNodeName}: added edge from '${from}'`);
49
55
  yield* Effect.addFinalizerLog(`WS Relay ${relayNodeName}: removed edge from '${from}'`);
50
56
  }
51
57
  // We want to keep the websocket open until the client disconnects or the server shuts down
52
58
  return yield* Effect.never;
53
- }), webChannel.closedDeferred);
59
+ }), Deferred.await(webChannel.closedDeferred));
54
60
  return HttpServerResponse.empty({ status: 101 });
55
61
  }
56
62
  else {
57
63
  if (req.url === '/' || req.url === '') {
58
64
  return HttpServerResponse.redirect('/_livestore/node');
59
65
  }
60
- else if (req.url.startsWith('/_livestore')) {
66
+ else if (shouldRouteToVite(req.url) === true) {
61
67
  // Here we're delegating to the Vite middleware
62
68
  // TODO replace this once @effect/platform-node supports Node HTTP middlewares
63
69
  const nodeReq = PlatformNode.NodeHttpServerRequest.toIncomingMessage(req);
64
70
  const nodeRes = PlatformNode.NodeHttpServerRequest.toServerResponse(req);
65
71
  const deferred = yield* Deferred.make();
66
- viteMiddleware.middlewares(nodeReq, nodeRes, () => Deferred.unsafeDone(deferred, Exit.void));
67
- yield* deferred;
72
+ viteMiddleware.middlewares(nodeReq, nodeRes, () => Deferred.doneUnsafe(deferred, Exit.void));
73
+ yield* Deferred.await(deferred);
68
74
  // The response is already sent, so we need to return an empty response (which won't be sent)
69
75
  return HttpServerResponse.empty();
70
76
  }
71
77
  }
72
78
  return HttpServerResponse.text('Not found');
73
- }).pipe(Effect.tapCauseLogPretty, Effect.interruptible);
74
- const sessionSuffix = clientSessionInfo
79
+ }).pipe(Effect.tapCauseLogPretty, Effect.interruptible, HttpMiddleware.withLoggerDisabled);
80
+ const sessionSuffix = clientSessionInfo !== undefined
75
81
  ? `/${clientSessionInfo.storeId}/${clientSessionInfo.clientId}/${clientSessionInfo.sessionId}/${clientSessionInfo.schemaAlias}`
76
82
  : '?autoconnect';
77
83
  // Use `localhost` instead of `0.0.0.0` as it doesn't have the `navigator.locks` web adapter limitation (https://share.cleanshot.com/nHBnmk6S)
@@ -80,5 +86,5 @@ export const startDevtoolsServer = ({ schemaPath, clientSessionInfo, port, host,
80
86
  return HttpServer.serve(handler, HttpMiddleware.logger);
81
87
  }).pipe(Effect.withSpan('@livestore/adapter-node:startDevtoolsServer', {
82
88
  attributes: { clientSessionInfo, port, host, schemaPath },
83
- }), HttpMiddleware.withLoggerDisabled, Layer.unwrapScoped, Layer.provide(PlatformNode.NodeHttpServer.layer(() => http.createServer(), { port, host })), Layer.launch, Effect.orDie);
89
+ }), Layer.unwrap, Layer.provide(PlatformNode.NodeHttpServer.layer(() => http.createServer(), { port, host })), Layer.launch, Effect.orDie);
84
90
  //# sourceMappingURL=devtools-server.js.map