@livestore/devtools-web-common 0.3.0-dev.4 → 0.3.0-dev.40
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/web-channel/index.d.ts +44 -19
- package/dist/web-channel/index.d.ts.map +1 -1
- package/dist/web-channel/index.js +50 -20
- package/dist/web-channel/index.js.map +1 -1
- package/dist/worker/mod.d.ts.map +1 -1
- package/dist/worker/mod.js +7 -5
- package/dist/worker/mod.js.map +1 -1
- package/package.json +10 -8
- package/src/web-channel/index.ts +72 -61
- package/src/worker/mod.ts +8 -5
- package/dist/devtools-bridge/index.d.ts +0 -12
- package/dist/devtools-bridge/index.d.ts.map +0 -1
- package/dist/devtools-bridge/index.js +0 -65
- package/dist/devtools-bridge/index.js.map +0 -1
- package/src/devtools-bridge/index.ts +0 -124
- package/tsconfig.json +0 -10
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { Devtools, liveStoreVersion } from '@livestore/common'
|
|
2
|
-
import type { Scope, Worker } from '@livestore/utils/effect'
|
|
3
|
-
import { Deferred, Effect, PubSub, Schema, Stream } from '@livestore/utils/effect'
|
|
4
|
-
|
|
5
|
-
import { makeChannelForConnectedMeshNode, makeWebDevtoolsConnectedMeshNode } from '../web-channel/index.js'
|
|
6
|
-
import type * as WorkerSchema from '../worker/schema.js'
|
|
7
|
-
|
|
8
|
-
// TODO use a unique bridgeId for each connection (similar to web bridge)
|
|
9
|
-
// TODO refactor the bridge creation code to be re-used for both web and node and possibly expo
|
|
10
|
-
export const prepareWebDevtoolsBridge = ({
|
|
11
|
-
worker,
|
|
12
|
-
workerTargetName,
|
|
13
|
-
storeId,
|
|
14
|
-
appHostId,
|
|
15
|
-
}: {
|
|
16
|
-
worker: Worker.SerializedWorkerPool<typeof WorkerSchema.Request.Type>
|
|
17
|
-
/** Usually `shared-worker` */
|
|
18
|
-
workerTargetName: string
|
|
19
|
-
storeId: string
|
|
20
|
-
appHostId: string
|
|
21
|
-
}): Effect.Effect<Devtools.PrepareDevtoolsBridge, never, Scope.Scope> =>
|
|
22
|
-
Effect.gen(function* () {
|
|
23
|
-
const meshNode = yield* makeWebDevtoolsConnectedMeshNode({
|
|
24
|
-
nodeName: `devtools`,
|
|
25
|
-
target: workerTargetName,
|
|
26
|
-
worker,
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
// @ts-expect-error typing
|
|
30
|
-
globalThis.__debugWebMeshNode = meshNode
|
|
31
|
-
|
|
32
|
-
// const appHostId = `${storeId}-${sessionId}`
|
|
33
|
-
const isLeader = true // For now we only support a single node instance, which always is the leader
|
|
34
|
-
|
|
35
|
-
// TODO maybe we need a temporary channel to create a unique bridge channel e..g see appHostInfoDeferred below
|
|
36
|
-
const webDevtoolsChannelStore = yield* makeChannelForConnectedMeshNode({
|
|
37
|
-
node: meshNode,
|
|
38
|
-
target: `app-store-${storeId}-${appHostId}`,
|
|
39
|
-
schema: { listen: Devtools.MessageFromAppClientSession, send: Devtools.MessageToAppClientSession },
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const webDevtoolsChannelCoordinator = yield* makeChannelForConnectedMeshNode({
|
|
43
|
-
node: meshNode,
|
|
44
|
-
target: 'leader-worker',
|
|
45
|
-
schema: { listen: Devtools.MessageFromAppLeader, send: Devtools.MessageToAppLeader },
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const responsePubSub = yield* PubSub.unbounded<
|
|
49
|
-
Devtools.MessageFromAppLeader | Devtools.MessageFromAppClientSession
|
|
50
|
-
>().pipe(Effect.acquireRelease(PubSub.shutdown))
|
|
51
|
-
|
|
52
|
-
// const appHostInfoDeferred = yield* Deferred.make<{ appHostId: string; isLeader: boolean }>()
|
|
53
|
-
|
|
54
|
-
yield* webDevtoolsChannelCoordinator.listen.pipe(
|
|
55
|
-
Stream.flatten(),
|
|
56
|
-
// Stream.tapLogWithLabel('fromCoordinator.listen'),
|
|
57
|
-
Stream.tap((msg) =>
|
|
58
|
-
Effect.gen(function* () {
|
|
59
|
-
yield* PubSub.publish(responsePubSub, msg)
|
|
60
|
-
}),
|
|
61
|
-
),
|
|
62
|
-
Stream.runDrain,
|
|
63
|
-
Effect.withSpan('portForDevtoolsChannelCoordinator.listen'),
|
|
64
|
-
Effect.tapCauseLogPretty,
|
|
65
|
-
Effect.forkScoped,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
yield* webDevtoolsChannelStore.listen.pipe(
|
|
69
|
-
Stream.flatten(),
|
|
70
|
-
// Stream.tapLogWithLabel('fromStore.listen'),
|
|
71
|
-
Stream.tap((msg) =>
|
|
72
|
-
Effect.gen(function* () {
|
|
73
|
-
yield* PubSub.publish(responsePubSub, msg)
|
|
74
|
-
}),
|
|
75
|
-
),
|
|
76
|
-
Stream.runDrain,
|
|
77
|
-
Effect.withSpan('portForDevtoolsChannelStore.listen'),
|
|
78
|
-
Effect.tapCauseLogPretty,
|
|
79
|
-
Effect.forkScoped,
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
// yield* webDevtoolsChannelCoordinator.send(Devtools.DevtoolsReady.make({ liveStoreVersion }))
|
|
83
|
-
|
|
84
|
-
// const { appHostId, isLeader } = yield* Deferred.await(appHostInfoDeferred)
|
|
85
|
-
|
|
86
|
-
// TODO improve disconnect handling
|
|
87
|
-
yield* Deferred.await(webDevtoolsChannelCoordinator.closedDeferred).pipe(
|
|
88
|
-
Effect.tap(() => PubSub.publish(responsePubSub, Devtools.Disconnect.make({ liveStoreVersion, appHostId }))),
|
|
89
|
-
Effect.tapCauseLogPretty,
|
|
90
|
-
Effect.forkScoped,
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
// TODO improve disconnect handling
|
|
94
|
-
yield* Deferred.await(webDevtoolsChannelStore.closedDeferred).pipe(
|
|
95
|
-
Effect.tap(() => PubSub.publish(responsePubSub, Devtools.Disconnect.make({ liveStoreVersion, appHostId }))),
|
|
96
|
-
Effect.tapCauseLogPretty,
|
|
97
|
-
Effect.forkScoped,
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
const sendToAppHost: Devtools.PrepareDevtoolsBridge['sendToAppHost'] = (msg) =>
|
|
101
|
-
Effect.gen(function* () {
|
|
102
|
-
// NOTE it's possible that a message is for both the coordinator and the store (e.g. Disconnect)
|
|
103
|
-
if (Schema.is(Devtools.MessageToAppLeader)(msg)) {
|
|
104
|
-
yield* webDevtoolsChannelCoordinator.send(msg)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (Schema.is(Devtools.MessageToAppClientSession)(msg)) {
|
|
108
|
-
yield* webDevtoolsChannelStore.send(msg)
|
|
109
|
-
}
|
|
110
|
-
}).pipe(Effect.withSpan('sendToAppHost'), Effect.orDie)
|
|
111
|
-
|
|
112
|
-
const copyToClipboard = (text: string) =>
|
|
113
|
-
Effect.sync(() => {
|
|
114
|
-
navigator.clipboard.writeText(text)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
responsePubSub,
|
|
119
|
-
sendToAppHost,
|
|
120
|
-
appHostId,
|
|
121
|
-
copyToClipboard,
|
|
122
|
-
isLeader,
|
|
123
|
-
} satisfies Devtools.PrepareDevtoolsBridge
|
|
124
|
-
}).pipe(Effect.orDie)
|
package/tsconfig.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"tsBuildInfoFile": "./dist/.tsbuildinfo"
|
|
7
|
-
},
|
|
8
|
-
"include": ["./src"],
|
|
9
|
-
"references": [{ "path": "../common" }, { "path": "../utils" }, { "path": "../webmesh" }]
|
|
10
|
-
}
|