@livestore/adapter-node 0.0.0-snapshot-abe9ae4963ab9d3948906a6642c39bc33295e9f6 → 0.0.0-snapshot-1e670bae5105bde781e82aa2a8ee4f2dfc2446f0

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 (39) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/client-session/index.d.ts.map +1 -1
  3. package/dist/client-session/index.js +8 -15
  4. package/dist/client-session/index.js.map +1 -1
  5. package/dist/devtools/devtools-server.d.ts.map +1 -1
  6. package/dist/devtools/devtools-server.js +24 -14
  7. package/dist/devtools/devtools-server.js.map +1 -1
  8. package/dist/devtools/mod.d.ts +1 -1
  9. package/dist/devtools/mod.d.ts.map +1 -1
  10. package/dist/devtools/vite-dev-server.d.ts +22 -2
  11. package/dist/devtools/vite-dev-server.d.ts.map +1 -1
  12. package/dist/devtools/vite-dev-server.js +12 -58
  13. package/dist/devtools/vite-dev-server.js.map +1 -1
  14. package/dist/in-memory/index.d.ts.map +1 -1
  15. package/dist/in-memory/index.js +9 -5
  16. package/dist/in-memory/index.js.map +1 -1
  17. package/dist/make-leader-worker.d.ts +1 -1
  18. package/dist/make-leader-worker.d.ts.map +1 -1
  19. package/dist/make-leader-worker.js +7 -2
  20. package/dist/make-leader-worker.js.map +1 -1
  21. package/dist/shutdown-channel.d.ts +1 -5
  22. package/dist/shutdown-channel.d.ts.map +1 -1
  23. package/dist/webchannel.d.ts.map +1 -1
  24. package/dist/webchannel.js +3 -3
  25. package/dist/webchannel.js.map +1 -1
  26. package/dist/worker-schema.d.ts +2 -2
  27. package/dist/worker-schema.d.ts.map +1 -1
  28. package/dist/worker-schema.js +2 -4
  29. package/dist/worker-schema.js.map +1 -1
  30. package/package.json +8 -8
  31. package/src/client-session/index.ts +21 -22
  32. package/src/devtools/devtools-server.ts +28 -16
  33. package/src/devtools/mod.ts +1 -1
  34. package/src/devtools/vite-dev-server.ts +30 -60
  35. package/src/in-memory/index.ts +22 -4
  36. package/src/make-leader-worker.ts +10 -3
  37. package/src/webchannel.ts +11 -8
  38. package/src/worker-schema.ts +2 -4
  39. package/src/devtools/types.d.ts +0 -33
@@ -1 +1 @@
1
- {"version":3,"file":"worker-schema.d.ts","sourceRoot":"","sources":["../src/worker-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAAE,gBAAgB,EAAoB,SAAS,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExH,OAAO,EAAE,MAAM,EAAgB,MAAM,yBAAyB,CAAA;AAE9D,eAAO,MAAM,UAAU;;;;iBAMtB,CAAA;AAED,eAAO,MAAM,eAAe;;IAE1B;;;;;OAKG;;EAEH,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAA;AAUzD,eAAO,MAAM,WAAW;;IAnBtB;;;;;OAKG;;EAiBJ,CAAA;AACD,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA;AACjD,MAAM,MAAM,kBAAkB,GAAG,OAAO,WAAW,CAAC,OAAO,CAAA;AAS3D,eAAO,MAAM,kBAAkB,gGAAiE,CAAA;AAChG,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAA;AAEjE,yBAAiB,iBAAiB,CAAC;;;;;;IACjC,MAAM,OAAO,cAAe,SAAQ,mBAIlC;KAAG;;IAEL,MAAM,OAAO,OAAQ,SAAQ,YAA4B;KAAG;;CAC7D;AAED,yBAAiB,iBAAiB,CAAC;;;;;;;;;;;;;IACjC,MAAM,OAAO,cAAe,SAAQ,qBAalC;KAAG;;;;eAqFF,OAAQ,OAAO;;eAEd,OAAQ,OAAO;kBAER,OACT,MAAK;yBACW,OAChB,MAAK;0BACA,OAAQ,MACb;;;eACgB,OAChB,OAAM;kBAER,OACI,MAAM;yBAAuB,OACnC,MACG;0BAAuB,OAAQ,MAAM;;;eAAwC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SAAQ,aAI5B;KAAG;;;;;kBA0BmiQ,OAAQ,OAAO;;uCAAmE,OAAQ,MAAM;;sCAAuF,OAAQ,MAAM;;+BAAiX,OAAQ,OAAO;;uCAAsC,OAAQ,MAAM;;sCAAuF,OAAQ,MAAM;;;IAxBtwR,MAAM,OAAO,oBAAqB,SAAQ,yBAMxC;KAAG;IAEL,MAAM,CAAC,MAAM,OAAO,wSAanB,CAAA;IACD,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;;CAC1C"}
@@ -1,4 +1,4 @@
1
- import { BootStatus, Devtools, InvalidPushError, MigrationsReport, SyncState, UnexpectedError } from '@livestore/common';
1
+ import { BootStatus, Devtools, LeaderAheadError, MigrationsReport, SyncState, UnexpectedError } from '@livestore/common';
2
2
  import { EventId, MutationEvent } from '@livestore/common/schema';
3
3
  import { Schema, Transferable } from '@livestore/utils/effect';
4
4
  export const WorkerArgv = Schema.parseJson(Schema.Struct({
@@ -74,8 +74,6 @@ export var LeaderWorkerInner;
74
74
  cursor: EventId.EventId,
75
75
  },
76
76
  success: Schema.Struct({
77
- // mutationEvents: Schema.Array(EncodedAny),
78
- // backendHead: Schema.Number,
79
77
  payload: SyncState.PayloadUpstream,
80
78
  remaining: Schema.Number,
81
79
  }),
@@ -88,7 +86,7 @@ export var LeaderWorkerInner;
88
86
  batch: Schema.Array(MutationEvent.AnyEncoded),
89
87
  },
90
88
  success: Schema.Void,
91
- failure: Schema.Union(UnexpectedError, InvalidPushError),
89
+ failure: Schema.Union(UnexpectedError, LeaderAheadError),
92
90
  }) {
93
91
  }
94
92
  LeaderWorkerInner.PushToLeader = PushToLeader;
@@ -1 +1 @@
1
- {"version":3,"file":"worker-schema.js","sourceRoot":"","sources":["../src/worker-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxH,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,EACN,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,QAAQ,EACR,oBAAoB,CACrB,CAAA;AAEH,CAAC,EAhHgB,iBAAiB,KAAjB,iBAAiB,QAgHjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/adapter-node",
3
- "version": "0.0.0-snapshot-abe9ae4963ab9d3948906a6642c39bc33295e9f6",
3
+ "version": "0.0.0-snapshot-1e670bae5105bde781e82aa2a8ee4f2dfc2446f0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -26,17 +26,17 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@livestore/devtools-vite": "0.3.0-dev.15",
29
+ "@livestore/devtools-vite": "0.3.0-dev.16",
30
30
  "@opentelemetry/api": "1.9.0",
31
31
  "@opentelemetry/otlp-exporter-base": "0.57.2",
32
32
  "vite": "6.1.0",
33
33
  "ws": "8.18.0",
34
- "@livestore/adapter-web": "0.0.0-snapshot-abe9ae4963ab9d3948906a6642c39bc33295e9f6",
35
- "@livestore/common": "0.0.0-snapshot-abe9ae4963ab9d3948906a6642c39bc33295e9f6",
36
- "@livestore/devtools-node-common": "0.0.0-snapshot-abe9ae4963ab9d3948906a6642c39bc33295e9f6",
37
- "@livestore/sqlite-wasm": "0.0.0-snapshot-abe9ae4963ab9d3948906a6642c39bc33295e9f6",
38
- "@livestore/utils": "0.0.0-snapshot-abe9ae4963ab9d3948906a6642c39bc33295e9f6",
39
- "@livestore/webmesh": "0.0.0-snapshot-abe9ae4963ab9d3948906a6642c39bc33295e9f6"
34
+ "@livestore/adapter-web": "0.0.0-snapshot-1e670bae5105bde781e82aa2a8ee4f2dfc2446f0",
35
+ "@livestore/common": "0.0.0-snapshot-1e670bae5105bde781e82aa2a8ee4f2dfc2446f0",
36
+ "@livestore/devtools-node-common": "0.0.0-snapshot-1e670bae5105bde781e82aa2a8ee4f2dfc2446f0",
37
+ "@livestore/sqlite-wasm": "0.0.0-snapshot-1e670bae5105bde781e82aa2a8ee4f2dfc2446f0",
38
+ "@livestore/utils": "0.0.0-snapshot-1e670bae5105bde781e82aa2a8ee4f2dfc2446f0",
39
+ "@livestore/webmesh": "0.0.0-snapshot-1e670bae5105bde781e82aa2a8ee4f2dfc2446f0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@rollup/plugin-commonjs": "^28.0.1",
@@ -10,13 +10,11 @@ import type {
10
10
  NetworkStatus,
11
11
  } from '@livestore/common'
12
12
  import { Devtools, UnexpectedError } from '@livestore/common'
13
- import type { MutationEvent } from '@livestore/common/schema'
14
13
  import { makeNodeDevtoolsChannel } from '@livestore/devtools-node-common/web-channel'
15
14
  import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm'
16
15
  import { sqliteDbFactory } from '@livestore/sqlite-wasm/node'
17
- import type { Cause } from '@livestore/utils/effect'
18
16
  import {
19
- BucketQueue,
17
+ Cause,
20
18
  Effect,
21
19
  Fiber,
22
20
  ParseResult,
@@ -28,6 +26,7 @@ import {
28
26
  } from '@livestore/utils/effect'
29
27
  import { PlatformNode } from '@livestore/utils/node'
30
28
 
29
+ import { makeShutdownChannel } from '../shutdown-channel.js'
31
30
  import * as WorkerSchema from '../worker-schema.js'
32
31
 
33
32
  export interface NodeAdapterOptions {
@@ -74,6 +73,17 @@ export const makeNodeAdapter = ({
74
73
  // yield* Effect.logWarning('Failed to load database file', fileData.left)
75
74
  // }
76
75
 
76
+ const shutdownChannel = yield* makeShutdownChannel(storeId)
77
+
78
+ yield* shutdownChannel.listen.pipe(
79
+ Stream.flatten(),
80
+ Stream.tap((error) => Effect.sync(() => shutdown(Cause.fail(error)))),
81
+ Stream.runDrain,
82
+ Effect.interruptible,
83
+ Effect.tapCauseLogPretty,
84
+ Effect.forkScoped,
85
+ )
86
+
77
87
  const syncInMemoryDb = yield* makeSqliteDb({ _tag: 'in-memory' }).pipe(Effect.orDie)
78
88
 
79
89
  // TODO actually implement this multi-session support
@@ -141,7 +151,7 @@ const makeLeaderThread = ({
141
151
  devtoolsOptions,
142
152
  schemaPath,
143
153
  }: {
144
- shutdown: (cause: Cause.Cause<UnexpectedError | IntentionalShutdownCause>) => Effect.Effect<void>
154
+ shutdown: (cause: Cause.Cause<UnexpectedError | IntentionalShutdownCause>) => void
145
155
  storeId: string
146
156
  clientId: string
147
157
  sessionId: string
@@ -171,7 +181,7 @@ const makeLeaderThread = ({
171
181
  }).pipe(
172
182
  Effect.provide(PlatformNode.NodeWorker.layer(() => nodeWorker)),
173
183
  UnexpectedError.mapToUnexpectedError,
174
- Effect.tapErrorCause(shutdown),
184
+ Effect.tapErrorCause((cause) => Effect.sync(() => shutdown(cause))),
175
185
  Effect.withSpan('@livestore/adapter-node:adapter:setupLeaderThread'),
176
186
  Effect.tapCauseLogPretty,
177
187
  Effect.forkScoped,
@@ -240,19 +250,6 @@ const makeLeaderThread = ({
240
250
  latchClosed: false,
241
251
  })
242
252
 
243
- const pushQueue = yield* BucketQueue.make<MutationEvent.AnyEncoded>()
244
-
245
- yield* Effect.gen(function* () {
246
- const batch = yield* BucketQueue.takeBetween(pushQueue, 1, 100)
247
- yield* runInWorker(new WorkerSchema.LeaderWorkerInner.PushToLeader({ batch })).pipe(
248
- Effect.withSpan('@livestore/adapter-node:client-session:pushToLeader', {
249
- attributes: { batchSize: batch.length },
250
- }),
251
- // We can ignore the error here because the ClientSessionSyncProcessor will retry after rebasing
252
- Effect.ignoreLogged,
253
- )
254
- }).pipe(Effect.forever, Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped)
255
-
256
253
  const bootResult = yield* runInWorker(new WorkerSchema.LeaderWorkerInner.GetRecreateSnapshot()).pipe(
257
254
  Effect.timeout(10_000),
258
255
  UnexpectedError.mapToUnexpectedError,
@@ -265,10 +262,12 @@ const makeLeaderThread = ({
265
262
  pull: runInWorkerStream(new WorkerSchema.LeaderWorkerInner.PullStream({ cursor: initialLeaderHead })).pipe(
266
263
  Stream.orDie,
267
264
  ),
268
- // NOTE instead of sending the worker message right away, we're batching the events in order to
269
- // - maintain a consistent order of events
270
- // - improve efficiency by reducing the number of messages
271
- push: (batch) => BucketQueue.offerAll(pushQueue, batch),
265
+ push: (batch) =>
266
+ runInWorker(new WorkerSchema.LeaderWorkerInner.PushToLeader({ batch })).pipe(
267
+ Effect.withSpan('@livestore/adapter-node:client-session:pushToLeader', {
268
+ attributes: { batchSize: batch.length },
269
+ }),
270
+ ),
272
271
  },
273
272
  initialState: {
274
273
  leaderHead: initialLeaderHead,
@@ -2,6 +2,7 @@ import http from 'node:http'
2
2
  import path from 'node:path'
3
3
 
4
4
  import { UnexpectedError } from '@livestore/common'
5
+ import { LS_DEV } from '@livestore/utils'
5
6
  import type { Scope } from '@livestore/utils/effect'
6
7
  import { Effect } from '@livestore/utils/effect'
7
8
  import { makeWebSocketServer } from '@livestore/webmesh/websocket-server'
@@ -27,10 +28,23 @@ export const startDevtoolsServer = ({
27
28
  port: number
28
29
  }): Effect.Effect<void, UnexpectedError, Scope.Scope> =>
29
30
  Effect.gen(function* () {
30
- const httpServer = http.createServer()
31
- const webSocketServer = yield* makeWebSocketServer({ relayNodeName: 'ws' })
31
+ const httpServer = yield* Effect.sync(() => http.createServer()).pipe(
32
+ Effect.acquireRelease((httpServer) =>
33
+ Effect.async<void, UnexpectedError>((cb) => {
34
+ httpServer.removeAllListeners()
35
+ httpServer.closeAllConnections()
36
+ httpServer.close((err) => {
37
+ if (err) {
38
+ cb(Effect.fail(UnexpectedError.make({ cause: err })))
39
+ } else {
40
+ cb(Effect.succeed(undefined))
41
+ }
42
+ })
43
+ }).pipe(Effect.orDie),
44
+ ),
45
+ )
32
46
 
33
- yield* Effect.addFinalizer(() => Effect.sync(() => httpServer.close()))
47
+ const webSocketServer = yield* makeWebSocketServer({ relayNodeName: 'ws' })
34
48
 
35
49
  // Handle upgrade manually
36
50
  httpServer.on('upgrade', (request, socket, head) => {
@@ -45,7 +59,7 @@ export const startDevtoolsServer = ({
45
59
  cb(UnexpectedError.make({ cause: err }))
46
60
  })
47
61
 
48
- httpServer.listen(port, () => {
62
+ httpServer.listen(port, '0.0.0.0', () => {
49
63
  cb(Effect.succeed(undefined))
50
64
  })
51
65
  })
@@ -53,23 +67,21 @@ export const startDevtoolsServer = ({
53
67
  yield* startServer(port)
54
68
 
55
69
  yield* Effect.logDebug(
56
- `[@livestore/adapter-node:devtools] LiveStore devtools are available at http://localhost:${port}/livestore-devtools`,
70
+ `[@livestore/adapter-node:devtools] LiveStore devtools are available at http://localhost:${port}/_livestore`,
57
71
  )
58
72
 
59
73
  const viteServer = yield* makeViteServer({
60
74
  mode: { _tag: 'node', storeId, clientId, sessionId, url: `ws://localhost:${port}` },
61
75
  schemaPath: path.resolve(process.cwd(), schemaPath),
62
76
  viteConfig: (viteConfig) => {
63
- viteConfig.server ??= {}
64
- viteConfig.server.fs ??= {}
65
-
66
- // TODO move this into the example code
67
- // Point to Overtone monorepo root
68
- viteConfig.server.fs.allow ??= []
69
- viteConfig.server.fs.allow.push(process.env.WORKSPACE_ROOT + '/../..')
77
+ if (LS_DEV) {
78
+ viteConfig.server ??= {}
79
+ viteConfig.server.fs ??= {}
80
+ viteConfig.server.fs.strict = true
70
81
 
71
- viteConfig.optimizeDeps ??= {}
72
- viteConfig.optimizeDeps.force = true
82
+ viteConfig.optimizeDeps ??= {}
83
+ viteConfig.optimizeDeps.force = true
84
+ }
73
85
 
74
86
  return viteConfig
75
87
  },
@@ -79,9 +91,9 @@ export const startDevtoolsServer = ({
79
91
 
80
92
  httpServer.on('request', (req, res) => {
81
93
  if (req.url === '/' || req.url === '') {
82
- res.writeHead(302, { Location: '/livestore-devtools' })
94
+ res.writeHead(302, { Location: '/_livestore' })
83
95
  res.end()
84
- } else if (req.url?.startsWith('/livestore-devtools')) {
96
+ } else if (req.url?.startsWith('/_livestore')) {
85
97
  return viteServer.middlewares(req, res as any)
86
98
  }
87
99
  })
@@ -1,2 +1,2 @@
1
1
  export { makeViteServer } from './vite-dev-server.js'
2
- export type { Options } from './types.js'
2
+ export type { ViteDevtoolsOptions } from './vite-dev-server.js'
@@ -2,15 +2,33 @@ import * as http from 'node:http'
2
2
  import path from 'node:path'
3
3
  import { fileURLToPath } from 'node:url'
4
4
 
5
+ import type { Devtools } from '@livestore/common'
5
6
  import { UnexpectedError } from '@livestore/common'
7
+ import { livestoreDevtoolsPlugin } from '@livestore/devtools-vite'
6
8
  import { Effect } from '@livestore/utils/effect'
7
9
  import * as Vite from 'vite'
8
10
 
9
- import type { Options } from './types.js'
11
+ export type ViteDevtoolsOptions = {
12
+ viteConfig?: (config: Vite.UserConfig) => Vite.UserConfig
13
+ /**
14
+ * Path to the file exporting the LiveStore schema as `export const schema = ...`
15
+ * File path must be relative to the project root and will be imported via Vite.
16
+ *
17
+ * Example: `./src/schema.ts`
18
+ */
19
+ schemaPath: string
20
+ /**
21
+ * The mode of the devtools server.
22
+ *
23
+ * @default 'node'
24
+ */
25
+ mode: Extract<Devtools.DevtoolsMode, { _tag: 'node' } | { _tag: 'expo' }>
26
+ }
10
27
 
11
28
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
12
29
 
13
- export const makeViteServer = (options: Options): Effect.Effect<Vite.ViteDevServer, UnexpectedError> =>
30
+ // NOTE this is currently also used in @livestore/devtools-expo
31
+ export const makeViteServer = (options: ViteDevtoolsOptions): Effect.Effect<Vite.ViteDevServer, UnexpectedError> =>
14
32
  Effect.gen(function* () {
15
33
  const hmrPort = yield* getFreePort
16
34
 
@@ -22,15 +40,8 @@ export const makeViteServer = (options: Options): Effect.Effect<Vite.ViteDevServ
22
40
  hmr: {
23
41
  port: hmrPort,
24
42
  },
25
- fs: {
26
- // Adds `node_modules` so we can import `@livestore/wa-sqlite` for WASM to work
27
- allow: [path.resolve(__dirname, '..', '..')],
28
- },
29
- },
30
- resolve: {
31
- alias: {
32
- '@schema': path.resolve(cwd, options.schemaPath),
33
- },
43
+ // Relaxing fs access for monorepo setup
44
+ fs: { strict: process.env.LS_DEV ? false : true },
34
45
  },
35
46
  appType: 'spa',
36
47
  optimizeDeps: {
@@ -38,8 +49,14 @@ export const makeViteServer = (options: Options): Effect.Effect<Vite.ViteDevServ
38
49
  exclude: ['@livestore/wa-sqlite'],
39
50
  },
40
51
  root: __dirname,
41
- base: '/livestore-devtools/',
42
- plugins: [virtualHtmlPlugin(options.mode)],
52
+ base: '/_livestore/',
53
+ plugins: [
54
+ livestoreDevtoolsPlugin({
55
+ schemaPath: path.resolve(cwd, options.schemaPath),
56
+ mode: options.mode,
57
+ path: '/',
58
+ }),
59
+ ],
43
60
  clearScreen: false,
44
61
  logLevel: 'silent',
45
62
  })
@@ -53,53 +70,6 @@ export const makeViteServer = (options: Options): Effect.Effect<Vite.ViteDevServ
53
70
  return viteServer
54
71
  }).pipe(Effect.withSpan('@livestore/adapter-node:devtools:makeViteServer'))
55
72
 
56
- // TODO unify this with `@livestore/devtools-vite/plugin.ts`
57
- const virtualHtmlPlugin = (mode: Options['mode']): Vite.Plugin => ({
58
- name: 'virtual-html',
59
- configureServer: (server) => {
60
- return () => {
61
- server.middlewares.use(async (req, res, next) => {
62
- if (req.url === '/' || req.url === '' || req.url === '/index.html') {
63
- const html = `
64
- <!doctype html>
65
- <html lang="en">
66
- <head>
67
- <meta charset="UTF-8" />
68
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
69
- <meta name="livestore-devtools" content="true" />
70
- <title>LiveStore Devtools</title>
71
- </head>
72
- <body>
73
- <div id="root"></div>
74
- <script type="module">
75
- import '@livestore/devtools-react/index.css'
76
- import { mountDevtools } from '@livestore/devtools-react'
77
- import sharedWorker from '@livestore/adapter-web/shared-worker?sharedworker'
78
- import { schema } from '@schema'
79
-
80
- mountDevtools({
81
- schema,
82
- rootEl: document.getElementById('root'),
83
- sharedWorker,
84
- mode: ${JSON.stringify(mode)},
85
- license: ${JSON.stringify(process.env.LSD_LICENSE)},
86
- })
87
- </script>
88
- </body>
89
- </html>
90
- `
91
- const transformedHtml = await server.transformIndexHtml(req.url, html)
92
- res.statusCode = 200
93
- res.setHeader('Content-Type', 'text/html')
94
- res.end(transformedHtml)
95
- } else {
96
- next()
97
- }
98
- })
99
- }
100
- },
101
- })
102
-
103
73
  export const getFreePort = Effect.async<number, UnexpectedError>((cb) => {
104
74
  const server = http.createServer()
105
75
 
@@ -12,9 +12,11 @@ import type { LiveStoreSchema } from '@livestore/common/schema'
12
12
  import { MutationEvent } from '@livestore/common/schema'
13
13
  import { sqliteDbFactory } from '@livestore/sqlite-wasm/browser'
14
14
  import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm'
15
- import { Effect, FetchHttpClient, Layer, Stream, SubscriptionRef, WebChannel } from '@livestore/utils/effect'
15
+ import { Cause, Effect, FetchHttpClient, Layer, Stream, SubscriptionRef } from '@livestore/utils/effect'
16
16
  import { nanoid } from '@livestore/utils/nanoid'
17
17
 
18
+ import { makeShutdownChannel } from '../shutdown-channel.js'
19
+
18
20
  // TODO unify in-memory adapter with other in-memory adapter implementations
19
21
 
20
22
  export interface InMemoryAdapterOptions {
@@ -31,6 +33,7 @@ export const makeInMemoryAdapter =
31
33
  ({
32
34
  schema,
33
35
  storeId,
36
+ shutdown,
34
37
  // devtoolsEnabled, bootStatusQueue, shutdown, connectDevtoolsToStore
35
38
  }) =>
36
39
  Effect.gen(function* () {
@@ -43,6 +46,17 @@ export const makeInMemoryAdapter =
43
46
 
44
47
  const sessionId = nanoid(6)
45
48
 
49
+ const shutdownChannel = yield* makeShutdownChannel(storeId)
50
+
51
+ yield* shutdownChannel.listen.pipe(
52
+ Stream.flatten(),
53
+ Stream.tap((error) => Effect.sync(() => shutdown(Cause.fail(error)))),
54
+ Stream.runDrain,
55
+ Effect.interruptible,
56
+ Effect.tapCauseLogPretty,
57
+ Effect.forkScoped,
58
+ )
59
+
46
60
  const { leaderThread, initialSnapshot } = yield* makeLeaderThread({
47
61
  storeId,
48
62
  clientId,
@@ -60,7 +74,7 @@ export const makeInMemoryAdapter =
60
74
  sessionId,
61
75
  lockStatus,
62
76
  leaderThread,
63
- shutdown: () => Effect.dieMessage('TODO implement shutdown'),
77
+ shutdown,
64
78
  } satisfies ClientSession
65
79
 
66
80
  return clientSession
@@ -88,7 +102,8 @@ const makeLeaderThread = ({
88
102
  devtoolsOptions: { enabled: false },
89
103
  makeSqliteDb,
90
104
  schema,
91
- shutdownChannel: yield* WebChannel.noopChannel<any, any>(),
105
+ // NOTE we're creating a separate channel here since you can't listen to your own channel messages
106
+ shutdownChannel: yield* makeShutdownChannel(storeId),
92
107
  storeId,
93
108
  syncOptions,
94
109
  }).pipe(Layer.provideMerge(FetchHttpClient.layer)),
@@ -112,7 +127,10 @@ const makeLeaderThread = ({
112
127
  pull: Stream.fromQueue(pullQueue),
113
128
  push: (batch) =>
114
129
  syncProcessor
115
- .push(batch.map((item) => new MutationEvent.EncodedWithMeta(item)))
130
+ .push(
131
+ batch.map((item) => new MutationEvent.EncodedWithMeta(item)),
132
+ { waitForProcessing: true },
133
+ )
116
134
  .pipe(Effect.provide(layer), Effect.scoped),
117
135
  },
118
136
  initialState: { leaderHead: initialLeaderHead, migrationsReport: initialState.migrationsReport },
@@ -68,7 +68,11 @@ export const makeWorkerEffect = (options: WorkerOptions) => {
68
68
  InitialMessage: (args) => makeLeaderThread({ ...args, syncOptions: options.sync }),
69
69
  PushToLeader: ({ batch }) =>
70
70
  Effect.andThen(LeaderThreadCtx, (_) =>
71
- _.syncProcessor.push(batch.map((item) => new MutationEvent.EncodedWithMeta(item))),
71
+ _.syncProcessor.push(
72
+ batch.map((item) => new MutationEvent.EncodedWithMeta(item)),
73
+ // We'll wait in order to keep back pressure on the client session
74
+ { waitForProcessing: true },
75
+ ),
72
76
  ).pipe(Effect.uninterruptible, Effect.withSpan('@livestore/adapter-node:worker:PushToLeader')),
73
77
  BootStatusStream: () =>
74
78
  Effect.andThen(LeaderThreadCtx, (_) => Stream.fromQueue(_.bootStatusQueue)).pipe(Stream.unwrap),
@@ -149,10 +153,13 @@ export const makeWorkerEffect = (options: WorkerOptions) => {
149
153
  ),
150
154
  }).pipe(
151
155
  Layer.provide(PlatformNode.NodeWorkerRunner.layer),
152
- Layer.launch,
156
+ WorkerRunner.launch,
153
157
  Effect.scoped,
154
158
  Effect.tapCauseLogPretty,
155
- Effect.annotateLogs({ thread: options.otelOptions?.serviceName ?? 'livestore-node-leader-thread' }),
159
+ Effect.annotateLogs({
160
+ thread: options.otelOptions?.serviceName ?? 'livestore-node-leader-thread',
161
+ processId: process.pid,
162
+ }),
156
163
  Effect.provide(Logger.prettyWithThread(options.otelOptions?.serviceName ?? 'livestore-node-leader-thread')),
157
164
  Effect.provide(FetchHttpClient.layer),
158
165
  Effect.provide(PlatformNode.NodeFileSystem.layer),
package/src/webchannel.ts CHANGED
@@ -28,14 +28,17 @@ export const makeBroadcastChannel = <Msg, MsgEncoded>({
28
28
  // )
29
29
 
30
30
  const listen = Stream.asyncPush<Either.Either<Msg, ParseResult.ParseError>>((emit) =>
31
- Effect.gen(function* () {
32
- // eslint-disable-next-line unicorn/prefer-add-event-listener
33
- channel.onmessage = (event: any) => {
34
- return emit.single(Schema.decodeEither(schema)(event.data))
35
- }
36
-
37
- return () => channel.unref()
38
- }),
31
+ Effect.acquireRelease(
32
+ Effect.gen(function* () {
33
+ // eslint-disable-next-line unicorn/prefer-add-event-listener
34
+ channel.onmessage = (event: any) => {
35
+ return emit.single(Schema.decodeEither(schema)(event.data))
36
+ }
37
+
38
+ return channel
39
+ }),
40
+ (channel) => Effect.sync(() => channel.unref()),
41
+ ),
39
42
  )
40
43
 
41
44
  const closedDeferred = yield* Deferred.make<void>().pipe(Effect.acquireRelease(Deferred.done(Exit.void)))
@@ -1,4 +1,4 @@
1
- import { BootStatus, Devtools, InvalidPushError, MigrationsReport, SyncState, UnexpectedError } from '@livestore/common'
1
+ import { BootStatus, Devtools, LeaderAheadError, MigrationsReport, SyncState, UnexpectedError } from '@livestore/common'
2
2
  import { EventId, MutationEvent } from '@livestore/common/schema'
3
3
  import { Schema, Transferable } from '@livestore/utils/effect'
4
4
 
@@ -85,8 +85,6 @@ export namespace LeaderWorkerInner {
85
85
  cursor: EventId.EventId,
86
86
  },
87
87
  success: Schema.Struct({
88
- // mutationEvents: Schema.Array(EncodedAny),
89
- // backendHead: Schema.Number,
90
88
  payload: SyncState.PayloadUpstream,
91
89
  remaining: Schema.Number,
92
90
  }),
@@ -98,7 +96,7 @@ export namespace LeaderWorkerInner {
98
96
  batch: Schema.Array(MutationEvent.AnyEncoded),
99
97
  },
100
98
  success: Schema.Void,
101
- failure: Schema.Union(UnexpectedError, InvalidPushError),
99
+ failure: Schema.Union(UnexpectedError, LeaderAheadError),
102
100
  }) {}
103
101
 
104
102
  export class Export extends Schema.TaggedRequest<Export>()('Export', {
@@ -1,33 +0,0 @@
1
- import type * as http from 'node:http'
2
-
3
- import type * as Vite from 'vite'
4
-
5
- export type Middleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void
6
-
7
- export type Options = {
8
- viteConfig?: (config: Vite.UserConfig) => Vite.UserConfig
9
- /**
10
- * Path to the file exporting the LiveStore schema as `export const schema = ...`
11
- * File path must be relative to the project root and will be imported via Vite.
12
- *
13
- * Example: `./src/schema.ts`
14
- */
15
- schemaPath: string
16
- // TODO consolidate with `Mode` in `@livestore/devtools-react/devtools-api.ts`
17
- /**
18
- * The mode of the devtools server.
19
- *
20
- * @default 'node'
21
- */
22
- mode:
23
- | {
24
- _tag: 'node'
25
- storeId: string
26
- clientId: string
27
- sessionId: string
28
- url: string
29
- }
30
- | {
31
- _tag: 'expo'
32
- }
33
- }