@livestore/adapter-node 0.3.0-dev.14 → 0.3.0-dev.16
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/devtools/devtools-server.d.ts.map +1 -1
- package/dist/devtools/devtools-server.js +10 -10
- package/dist/devtools/devtools-server.js.map +1 -1
- package/dist/devtools/mod.d.ts +1 -1
- package/dist/devtools/mod.d.ts.map +1 -1
- package/dist/devtools/vite-dev-server.d.ts +22 -2
- package/dist/devtools/vite-dev-server.d.ts.map +1 -1
- package/dist/devtools/vite-dev-server.js +12 -58
- package/dist/devtools/vite-dev-server.js.map +1 -1
- package/package.json +8 -8
- package/src/devtools/devtools-server.ts +10 -11
- package/src/devtools/mod.ts +1 -1
- package/src/devtools/vite-dev-server.ts +30 -60
- package/dist/leader-thread.d.ts +0 -2
- package/dist/leader-thread.d.ts.map +0 -1
- package/dist/leader-thread.js +0 -140
- package/dist/leader-thread.js.map +0 -1
- package/src/devtools/types.d.ts +0 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-server.d.ts","sourceRoot":"","sources":["../../src/devtools/devtools-server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"devtools-server.d.ts","sourceRoot":"","sources":["../../src/devtools/devtools-server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAKhD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,wDAM7B;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;CACb,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,CAAC,KAAK,CA0D8B,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { UnexpectedError } from '@livestore/common';
|
|
4
|
+
import { LS_DEV } from '@livestore/utils';
|
|
4
5
|
import { Effect } from '@livestore/utils/effect';
|
|
5
6
|
import { makeWebSocketServer } from '@livestore/webmesh/websocket-server';
|
|
6
7
|
import { makeViteServer } from './vite-dev-server.js';
|
|
@@ -33,24 +34,23 @@ export const startDevtoolsServer = ({ schemaPath, storeId, clientId, sessionId,
|
|
|
33
34
|
mode: { _tag: 'node', storeId, clientId, sessionId, url: `ws://localhost:${port}` },
|
|
34
35
|
schemaPath: path.resolve(process.cwd(), schemaPath),
|
|
35
36
|
viteConfig: (viteConfig) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
viteConfig.optimizeDeps.force = true;
|
|
37
|
+
if (LS_DEV) {
|
|
38
|
+
viteConfig.server ??= {};
|
|
39
|
+
viteConfig.server.fs ??= {};
|
|
40
|
+
viteConfig.server.fs.strict = true;
|
|
41
|
+
viteConfig.optimizeDeps ??= {};
|
|
42
|
+
viteConfig.optimizeDeps.force = true;
|
|
43
|
+
}
|
|
44
44
|
return viteConfig;
|
|
45
45
|
},
|
|
46
46
|
});
|
|
47
47
|
yield* Effect.addFinalizer(() => Effect.promise(() => viteServer.close()));
|
|
48
48
|
httpServer.on('request', (req, res) => {
|
|
49
49
|
if (req.url === '/' || req.url === '') {
|
|
50
|
-
res.writeHead(302, { Location: '/
|
|
50
|
+
res.writeHead(302, { Location: '/_livestore' });
|
|
51
51
|
res.end();
|
|
52
52
|
}
|
|
53
|
-
else if (req.url?.startsWith('/
|
|
53
|
+
else if (req.url?.startsWith('/_livestore')) {
|
|
54
54
|
return viteServer.middlewares(req, res);
|
|
55
55
|
}
|
|
56
56
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-server.js","sourceRoot":"","sources":["../../src/devtools/devtools-server.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"devtools-server.js","sourceRoot":"","sources":["../../src/devtools/devtools-server.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,UAAU,EACV,OAAO,EACP,QAAQ,EACR,SAAS,EACT,IAAI,GAOL,EAAqD,EAAE,CACtD,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;IACtC,MAAM,eAAe,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;IAE3E,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAEvE,0BAA0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AACrD,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/devtools/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
+
import type { Devtools } from '@livestore/common';
|
|
1
2
|
import { UnexpectedError } from '@livestore/common';
|
|
2
3
|
import { Effect } from '@livestore/utils/effect';
|
|
3
4
|
import * as Vite from 'vite';
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
export type ViteDevtoolsOptions = {
|
|
6
|
+
viteConfig?: (config: Vite.UserConfig) => Vite.UserConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Path to the file exporting the LiveStore schema as `export const schema = ...`
|
|
9
|
+
* File path must be relative to the project root and will be imported via Vite.
|
|
10
|
+
*
|
|
11
|
+
* Example: `./src/schema.ts`
|
|
12
|
+
*/
|
|
13
|
+
schemaPath: string;
|
|
14
|
+
/**
|
|
15
|
+
* The mode of the devtools server.
|
|
16
|
+
*
|
|
17
|
+
* @default 'node'
|
|
18
|
+
*/
|
|
19
|
+
mode: Extract<Devtools.DevtoolsMode, {
|
|
20
|
+
_tag: 'node';
|
|
21
|
+
} | {
|
|
22
|
+
_tag: 'expo';
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
export declare const makeViteServer: (options: ViteDevtoolsOptions) => Effect.Effect<Vite.ViteDevServer, UnexpectedError>;
|
|
6
26
|
export declare const getFreePort: Effect.Effect<number, UnexpectedError, never>;
|
|
7
27
|
//# sourceMappingURL=vite-dev-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-dev-server.d.ts","sourceRoot":"","sources":["../../src/devtools/vite-dev-server.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"vite-dev-server.d.ts","sourceRoot":"","sources":["../../src/devtools/vite-dev-server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAA;IACzD;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC1E,CAAA;AAKD,eAAO,MAAM,cAAc,YAAa,mBAAmB,KAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,eAAe,CAwClC,CAAA;AAE7E,eAAO,MAAM,WAAW,+CAmBtB,CAAA"}
|
|
@@ -2,9 +2,11 @@ import * as http from 'node:http';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { UnexpectedError } from '@livestore/common';
|
|
5
|
+
import { livestoreDevtoolsPlugin } from '@livestore/devtools-vite';
|
|
5
6
|
import { Effect } from '@livestore/utils/effect';
|
|
6
7
|
import * as Vite from 'vite';
|
|
7
8
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
// NOTE this is currently also used in @livestore/devtools-expo
|
|
8
10
|
export const makeViteServer = (options) => Effect.gen(function* () {
|
|
9
11
|
const hmrPort = yield* getFreePort;
|
|
10
12
|
const cwd = process.cwd();
|
|
@@ -14,15 +16,8 @@ export const makeViteServer = (options) => Effect.gen(function* () {
|
|
|
14
16
|
hmr: {
|
|
15
17
|
port: hmrPort,
|
|
16
18
|
},
|
|
17
|
-
fs
|
|
18
|
-
|
|
19
|
-
allow: [path.resolve(__dirname, '..', '..')],
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
resolve: {
|
|
23
|
-
alias: {
|
|
24
|
-
'@schema': path.resolve(cwd, options.schemaPath),
|
|
25
|
-
},
|
|
19
|
+
// Relaxing fs access for monorepo setup
|
|
20
|
+
fs: { strict: process.env.LS_DEV ? false : true },
|
|
26
21
|
},
|
|
27
22
|
appType: 'spa',
|
|
28
23
|
optimizeDeps: {
|
|
@@ -30,8 +25,14 @@ export const makeViteServer = (options) => Effect.gen(function* () {
|
|
|
30
25
|
exclude: ['@livestore/wa-sqlite'],
|
|
31
26
|
},
|
|
32
27
|
root: __dirname,
|
|
33
|
-
base: '/
|
|
34
|
-
plugins: [
|
|
28
|
+
base: '/_livestore/',
|
|
29
|
+
plugins: [
|
|
30
|
+
livestoreDevtoolsPlugin({
|
|
31
|
+
schemaPath: path.resolve(cwd, options.schemaPath),
|
|
32
|
+
mode: options.mode,
|
|
33
|
+
path: '/',
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
35
36
|
clearScreen: false,
|
|
36
37
|
logLevel: 'silent',
|
|
37
38
|
});
|
|
@@ -39,53 +40,6 @@ export const makeViteServer = (options) => Effect.gen(function* () {
|
|
|
39
40
|
const viteServer = yield* Effect.promise(() => Vite.createServer(viteConfig)).pipe(UnexpectedError.mapToUnexpectedError);
|
|
40
41
|
return viteServer;
|
|
41
42
|
}).pipe(Effect.withSpan('@livestore/adapter-node:devtools:makeViteServer'));
|
|
42
|
-
// TODO unify this with `@livestore/devtools-vite/plugin.ts`
|
|
43
|
-
const virtualHtmlPlugin = (mode) => ({
|
|
44
|
-
name: 'virtual-html',
|
|
45
|
-
configureServer: (server) => {
|
|
46
|
-
return () => {
|
|
47
|
-
server.middlewares.use(async (req, res, next) => {
|
|
48
|
-
if (req.url === '/' || req.url === '' || req.url === '/index.html') {
|
|
49
|
-
const html = `
|
|
50
|
-
<!doctype html>
|
|
51
|
-
<html lang="en">
|
|
52
|
-
<head>
|
|
53
|
-
<meta charset="UTF-8" />
|
|
54
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
55
|
-
<meta name="livestore-devtools" content="true" />
|
|
56
|
-
<title>LiveStore Devtools</title>
|
|
57
|
-
</head>
|
|
58
|
-
<body>
|
|
59
|
-
<div id="root"></div>
|
|
60
|
-
<script type="module">
|
|
61
|
-
import '@livestore/devtools-react/index.css'
|
|
62
|
-
import { mountDevtools } from '@livestore/devtools-react'
|
|
63
|
-
import sharedWorker from '@livestore/adapter-web/shared-worker?sharedworker'
|
|
64
|
-
import { schema } from '@schema'
|
|
65
|
-
|
|
66
|
-
mountDevtools({
|
|
67
|
-
schema,
|
|
68
|
-
rootEl: document.getElementById('root'),
|
|
69
|
-
sharedWorker,
|
|
70
|
-
mode: ${JSON.stringify(mode)},
|
|
71
|
-
license: ${JSON.stringify(process.env.LSD_LICENSE)},
|
|
72
|
-
})
|
|
73
|
-
</script>
|
|
74
|
-
</body>
|
|
75
|
-
</html>
|
|
76
|
-
`;
|
|
77
|
-
const transformedHtml = await server.transformIndexHtml(req.url, html);
|
|
78
|
-
res.statusCode = 200;
|
|
79
|
-
res.setHeader('Content-Type', 'text/html');
|
|
80
|
-
res.end(transformedHtml);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
next();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
43
|
export const getFreePort = Effect.async((cb) => {
|
|
90
44
|
const server = http.createServer();
|
|
91
45
|
// Listen on port 0 to get an available port
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-dev-server.js","sourceRoot":"","sources":["../../src/devtools/vite-dev-server.ts"],"names":[],"mappings":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C;YACN,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,2BAA2B,EAAE,CAAC,CAAC,CAAC,CAAA;QACtF,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,wDAAwD;IACxD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/adapter-node",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.16",
|
|
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-
|
|
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.3.0-dev.
|
|
35
|
-
"@livestore/common": "0.3.0-dev.
|
|
36
|
-
"@livestore/
|
|
37
|
-
"@livestore/
|
|
38
|
-
"@livestore/
|
|
39
|
-
"@livestore/
|
|
34
|
+
"@livestore/adapter-web": "0.3.0-dev.16",
|
|
35
|
+
"@livestore/devtools-node-common": "0.3.0-dev.16",
|
|
36
|
+
"@livestore/common": "0.3.0-dev.16",
|
|
37
|
+
"@livestore/webmesh": "0.3.0-dev.16",
|
|
38
|
+
"@livestore/sqlite-wasm": "0.3.0-dev.16",
|
|
39
|
+
"@livestore/utils": "0.3.0-dev.16"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@rollup/plugin-commonjs": "^28.0.1",
|
|
@@ -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'
|
|
@@ -60,16 +61,14 @@ export const startDevtoolsServer = ({
|
|
|
60
61
|
mode: { _tag: 'node', storeId, clientId, sessionId, url: `ws://localhost:${port}` },
|
|
61
62
|
schemaPath: path.resolve(process.cwd(), schemaPath),
|
|
62
63
|
viteConfig: (viteConfig) => {
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
if (LS_DEV) {
|
|
65
|
+
viteConfig.server ??= {}
|
|
66
|
+
viteConfig.server.fs ??= {}
|
|
67
|
+
viteConfig.server.fs.strict = true
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
viteConfig.server.fs.allow.push(process.env.WORKSPACE_ROOT + '/../..')
|
|
70
|
-
|
|
71
|
-
viteConfig.optimizeDeps ??= {}
|
|
72
|
-
viteConfig.optimizeDeps.force = true
|
|
69
|
+
viteConfig.optimizeDeps ??= {}
|
|
70
|
+
viteConfig.optimizeDeps.force = true
|
|
71
|
+
}
|
|
73
72
|
|
|
74
73
|
return viteConfig
|
|
75
74
|
},
|
|
@@ -79,9 +78,9 @@ export const startDevtoolsServer = ({
|
|
|
79
78
|
|
|
80
79
|
httpServer.on('request', (req, res) => {
|
|
81
80
|
if (req.url === '/' || req.url === '') {
|
|
82
|
-
res.writeHead(302, { Location: '/
|
|
81
|
+
res.writeHead(302, { Location: '/_livestore' })
|
|
83
82
|
res.end()
|
|
84
|
-
} else if (req.url?.startsWith('/
|
|
83
|
+
} else if (req.url?.startsWith('/_livestore')) {
|
|
85
84
|
return viteServer.middlewares(req, res as any)
|
|
86
85
|
}
|
|
87
86
|
})
|
package/src/devtools/mod.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { makeViteServer } from './vite-dev-server.js'
|
|
2
|
-
export type {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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: '/
|
|
42
|
-
plugins: [
|
|
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
|
|
package/dist/leader-thread.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"leader-thread.d.ts","sourceRoot":"","sources":["../src/leader-thread.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAA"}
|
package/dist/leader-thread.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import './thread-polyfill.js';
|
|
2
|
-
import inspector from 'node:inspector';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
if (process.execArgv.includes('--inspect')) {
|
|
5
|
-
inspector.open();
|
|
6
|
-
inspector.waitForDebugger();
|
|
7
|
-
}
|
|
8
|
-
import { NodeFileSystem, NodeWorkerRunner } from '@effect/platform-node';
|
|
9
|
-
import { Devtools, liveStoreStorageFormatVersion, sql, UnexpectedError } from '@livestore/common';
|
|
10
|
-
import { configureConnection, LeaderThreadCtx, makeLeaderThreadLayer } from '@livestore/common/leader-thread';
|
|
11
|
-
import { EventId, MutationEvent } from '@livestore/common/schema';
|
|
12
|
-
import { makeNodeDevtoolsChannel } from '@livestore/devtools-node-common/web-channel';
|
|
13
|
-
import { loadSqlite3Wasm } from '@livestore/sqlite-wasm/load-wasm';
|
|
14
|
-
import { syncDbFactory } from '@livestore/sqlite-wasm/node';
|
|
15
|
-
import { Effect, FetchHttpClient, Layer, Logger, LogLevel, Schema, Stream, WorkerRunner } from '@livestore/utils/effect';
|
|
16
|
-
import { OtelLiveHttp } from '@livestore/utils/node';
|
|
17
|
-
import { startDevtoolsServer } from './devtools/devtools-server.js';
|
|
18
|
-
import { makeShutdownChannel } from './shutdown-channel.js';
|
|
19
|
-
import * as WorkerSchema from './worker-schema.js';
|
|
20
|
-
const argvOptions = Schema.decodeSync(WorkerSchema.WorkerArgv)(process.argv[2]);
|
|
21
|
-
WorkerRunner.layerSerialized(WorkerSchema.LeaderWorkerInner.Request, {
|
|
22
|
-
InitialMessage: (args) => makeLeaderThread(args),
|
|
23
|
-
PushToLeader: ({ batch }) => Effect.andThen(LeaderThreadCtx, (_) => _.syncProcessor.push(batch.map((item) => new MutationEvent.EncodedWithMeta(item)))).pipe(Effect.uninterruptible, Effect.withSpan('@livestore/node:worker:PushToLeader')),
|
|
24
|
-
BootStatusStream: () => Effect.andThen(LeaderThreadCtx, (_) => Stream.fromQueue(_.bootStatusQueue)).pipe(Stream.unwrap),
|
|
25
|
-
PullStream: ({ cursor }) => Effect.gen(function* () {
|
|
26
|
-
const { connectedClientSessionPullQueues } = yield* LeaderThreadCtx;
|
|
27
|
-
const pullQueue = yield* connectedClientSessionPullQueues.makeQueue(cursor);
|
|
28
|
-
return Stream.fromQueue(pullQueue);
|
|
29
|
-
}).pipe(Stream.unwrapScoped),
|
|
30
|
-
Export: () => Effect.andThen(LeaderThreadCtx, (_) => _.db.export()).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/node:worker:Export')),
|
|
31
|
-
ExportMutationlog: () => Effect.andThen(LeaderThreadCtx, (_) => _.dbLog.export()).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/node:worker:ExportMutationlog')),
|
|
32
|
-
GetCurrentMutationEventId: () => Effect.gen(function* () {
|
|
33
|
-
const workerCtx = yield* LeaderThreadCtx;
|
|
34
|
-
const result = workerCtx.dbLog.select(sql `SELECT idGlobal, idLocal FROM mutation_log ORDER BY idGlobal DESC, idLocal DESC LIMIT 1`)[0];
|
|
35
|
-
return result ? { global: result.idGlobal, local: result.idLocal } : EventId.ROOT;
|
|
36
|
-
}).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/node:worker:GetCurrentMutationEventId')),
|
|
37
|
-
NetworkStatusStream: () => Effect.gen(function* (_) {
|
|
38
|
-
const ctx = yield* LeaderThreadCtx;
|
|
39
|
-
if (ctx.syncBackend === undefined) {
|
|
40
|
-
return Stream.make({ isConnected: false, timestampMs: Date.now() });
|
|
41
|
-
}
|
|
42
|
-
return ctx.syncBackend.isConnected.changes.pipe(Stream.map((isConnected) => ({ isConnected, timestampMs: Date.now() })));
|
|
43
|
-
}).pipe(Stream.unwrap),
|
|
44
|
-
GetLeaderSyncState: () => Effect.gen(function* () {
|
|
45
|
-
const workerCtx = yield* LeaderThreadCtx;
|
|
46
|
-
return yield* workerCtx.syncProcessor.syncState;
|
|
47
|
-
}).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/node:worker:GetLeaderSyncState')),
|
|
48
|
-
// GetRecreateSnapshot: () =>
|
|
49
|
-
// Effect.gen(function* () {
|
|
50
|
-
// const workerCtx = yield* LeaderThreadCtx
|
|
51
|
-
// const result = yield* Deferred.await(workerCtx.initialSetupDeferred)
|
|
52
|
-
// // NOTE we can only return the cached snapshot once as it's transferred (i.e. disposed), so we need to set it to undefined
|
|
53
|
-
// const cachedSnapshot =
|
|
54
|
-
// result._tag === 'Recreate' ? yield* Ref.getAndSet(result.snapshotRef, undefined) : undefined
|
|
55
|
-
// return cachedSnapshot ?? workerCtx.db.export()
|
|
56
|
-
// }).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/node:worker:GetRecreateSnapshot')),
|
|
57
|
-
Shutdown: () => Effect.gen(function* () {
|
|
58
|
-
const { db, dbLog } = yield* LeaderThreadCtx;
|
|
59
|
-
yield* Effect.logDebug('[@livestore/node:worker] Shutdown');
|
|
60
|
-
// if (devtools.enabled) {
|
|
61
|
-
// yield* FiberSet.clear(devtools.connections)
|
|
62
|
-
// }
|
|
63
|
-
db.close();
|
|
64
|
-
dbLog.close();
|
|
65
|
-
// Buy some time for Otel to flush
|
|
66
|
-
// TODO find a cleaner way to do this
|
|
67
|
-
// yield* Effect.sleep(1000)
|
|
68
|
-
}).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/node:worker:Shutdown')),
|
|
69
|
-
ExtraDevtoolsMessage: ({ message }) => Effect.andThen(LeaderThreadCtx, (_) => _.extraIncomingMessagesQueue.offer(message)).pipe(UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/node:worker:ExtraDevtoolsMessage')),
|
|
70
|
-
}).pipe(Layer.provide(NodeWorkerRunner.layer), Layer.launch, Effect.scoped, Effect.tapCauseLogPretty, Effect.annotateLogs({ thread: argvOptions.otel?.workerServiceName ?? 'livestore-node-leader-thread' }), Effect.provide(Logger.prettyWithThread(argvOptions.otel?.workerServiceName ?? 'livestore-node-leader-thread')), Effect.provide(FetchHttpClient.layer), Effect.provide(NodeFileSystem.layer), Effect.provide(OtelLiveHttp({
|
|
71
|
-
serviceName: argvOptions.otel?.workerServiceName ?? 'livestore-node-leader-thread',
|
|
72
|
-
skipLogUrl: true,
|
|
73
|
-
})), Logger.withMinimumLogLevel(LogLevel.Debug), Effect.runFork);
|
|
74
|
-
const makeLeaderThread = ({ schemaPath, storeId, clientId, syncOptions, makeSyncBackendUrl, baseDirectory, devtoolsEnabled, devtoolsPort, initialSyncOptions, }) => Effect.gen(function* () {
|
|
75
|
-
const schema = yield* Effect.promise(() => import(schemaPath).then((m) => m.schema));
|
|
76
|
-
const makeSyncBackend = makeSyncBackendUrl
|
|
77
|
-
? yield* Effect.promise(() => import(makeSyncBackendUrl).then((m) => m.makeWsSync))
|
|
78
|
-
: undefined;
|
|
79
|
-
const sqlite3 = yield* Effect.promise(() => loadSqlite3Wasm()).pipe(Effect.withSpan('@livestore/node:leader-thread:loadSqlite3Wasm'));
|
|
80
|
-
const makeSyncDb = yield* syncDbFactory({ sqlite3 });
|
|
81
|
-
const schemaHashSuffix = schema.migrationOptions.strategy === 'manual' ? 'fixed' : schema.hash.toString();
|
|
82
|
-
const makeDb = (kind) => makeSyncDb({
|
|
83
|
-
_tag: 'fs',
|
|
84
|
-
directory: path.join(baseDirectory ?? '', storeId),
|
|
85
|
-
fileName: kind === 'app' ? getAppDbFileName(schemaHashSuffix) : `mutationlog@${liveStoreStorageFormatVersion}.db`,
|
|
86
|
-
// TODO enable WAL for nodejs
|
|
87
|
-
configureDb: (db) => configureConnection(db, { fkEnabled: true }),
|
|
88
|
-
}).pipe(Effect.acquireRelease((db) => Effect.sync(() => db.close())));
|
|
89
|
-
// Might involve some async work, so we're running them concurrently
|
|
90
|
-
const [db, dbLog] = yield* Effect.all([makeDb('app'), makeDb('mutationlog')], { concurrency: 2 });
|
|
91
|
-
const devtoolsOptions = yield* makeDevtoolsOptions({
|
|
92
|
-
devtoolsEnabled,
|
|
93
|
-
db,
|
|
94
|
-
dbLog,
|
|
95
|
-
storeId,
|
|
96
|
-
clientId,
|
|
97
|
-
devtoolsPort,
|
|
98
|
-
schemaPath,
|
|
99
|
-
});
|
|
100
|
-
const shutdownChannel = yield* makeShutdownChannel(storeId);
|
|
101
|
-
return makeLeaderThreadLayer({
|
|
102
|
-
schema,
|
|
103
|
-
storeId,
|
|
104
|
-
clientId,
|
|
105
|
-
makeSyncDb,
|
|
106
|
-
makeSyncBackend: makeSyncBackend === undefined || syncOptions === undefined ? undefined : makeSyncBackend(syncOptions),
|
|
107
|
-
db,
|
|
108
|
-
dbLog,
|
|
109
|
-
devtoolsOptions,
|
|
110
|
-
initialSyncOptions,
|
|
111
|
-
shutdownChannel,
|
|
112
|
-
});
|
|
113
|
-
}).pipe(Effect.tapCauseLogPretty, UnexpectedError.mapToUnexpectedError, Effect.withSpan('@livestore/node:worker:InitialMessage'), Layer.unwrapScoped);
|
|
114
|
-
const getAppDbFileName = (suffix) => `app${suffix}@${liveStoreStorageFormatVersion}.db`;
|
|
115
|
-
const makeDevtoolsOptions = ({ devtoolsEnabled, db, dbLog, storeId, clientId, devtoolsPort, schemaPath, }) => Effect.gen(function* () {
|
|
116
|
-
if (devtoolsEnabled === false) {
|
|
117
|
-
return {
|
|
118
|
-
enabled: false,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
enabled: true,
|
|
123
|
-
makeContext: Effect.gen(function* () {
|
|
124
|
-
yield* startDevtoolsServer({ schemaPath, storeId, port: devtoolsPort }).pipe(Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
125
|
-
return {
|
|
126
|
-
devtoolsWebChannel: yield* makeNodeDevtoolsChannel({
|
|
127
|
-
nodeName: `leader-${storeId}-${clientId}`,
|
|
128
|
-
target: `devtools`,
|
|
129
|
-
url: `ws://localhost:${devtoolsPort}`,
|
|
130
|
-
schema: { listen: Devtools.MessageToAppLeader, send: Devtools.MessageFromAppLeader },
|
|
131
|
-
}),
|
|
132
|
-
persistenceInfo: {
|
|
133
|
-
db: db.metadata.persistenceInfo,
|
|
134
|
-
mutationLog: dbLog.metadata.persistenceInfo,
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}),
|
|
138
|
-
};
|
|
139
|
-
});
|
|
140
|
-
//# sourceMappingURL=leader-thread.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"leader-thread.js","sourceRoot":"","sources":["../src/leader-thread.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAA;AAE7B,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;IAC3C,SAAS,CAAC,IAAI,EAAE,CAAA;IAChB,SAAS,CAAC,eAAe,EAAE,CAAA;AAC7B,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExE,OAAO,EAAE,QAAQ,EAAE,6BAA6B,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEjG,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AAE7G,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAA;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OA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QAAQ,CAAC,eAAe;oBAC/B,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,eAAe;iBAC5C;aACF,CAAA;QACH,CAAC,CAAC;KACH,CAAA;AACH,CAAC,CAAC,CAAA"}
|
package/src/devtools/types.d.ts
DELETED
|
@@ -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
|
-
}
|