@livestore/webmesh 0.0.0-snapshot-a52f85f365e9065fddfedc08697bcb11f090628c → 0.0.0-snapshot-97ca7eac46b6a583b22d40189126d06a377ec1b0
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/channel/message-channel-internal.d.ts.map +1 -1
- package/dist/channel/message-channel.d.ts.map +1 -1
- package/dist/channel/message-channel.js +1 -1
- package/dist/channel/message-channel.js.map +1 -1
- package/dist/channel/proxy-channel.d.ts.map +1 -1
- package/dist/channel/proxy-channel.js +13 -0
- package/dist/channel/proxy-channel.js.map +1 -1
- package/dist/common.d.ts.map +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +8 -8
- package/dist/node.js.map +1 -1
- package/dist/websocket-connection.d.ts +3 -3
- package/dist/websocket-connection.d.ts.map +1 -1
- package/dist/websocket-connection.js +5 -5
- package/dist/websocket-connection.js.map +1 -1
- package/dist/websocket-server.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/channel/message-channel.ts +1 -1
- package/src/channel/proxy-channel.ts +16 -0
- package/src/node.ts +12 -12
- package/src/websocket-connection.ts +9 -14
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from '@livestore/utils/effect'
|
|
14
14
|
import type * as NodeWebSocket from 'ws'
|
|
15
15
|
|
|
16
|
-
import * as
|
|
16
|
+
import * as WebmeshSchema from './mesh-schema.js'
|
|
17
17
|
import type { MeshNode } from './node.js'
|
|
18
18
|
|
|
19
19
|
export class WSConnectionInit extends Schema.TaggedStruct('WSConnectionInit', {
|
|
@@ -59,19 +59,14 @@ export const connectViaWebSocket = ({
|
|
|
59
59
|
yield* node.addConnection({ target: 'ws', connectionChannel: connection.webChannel, replaceIfExists: true })
|
|
60
60
|
|
|
61
61
|
yield* disconnected
|
|
62
|
-
}).pipe(
|
|
63
|
-
Effect.scoped,
|
|
64
|
-
Effect.forever,
|
|
65
|
-
Effect.catchTag('WebSocketError', Effect.orDie),
|
|
66
|
-
Effect.onInterrupt(() => Effect.log('connectViaWebSocket:interrupted')),
|
|
67
|
-
)
|
|
62
|
+
}).pipe(Effect.scoped, Effect.forever, Effect.catchTag('WebSocketError', Effect.orDie))
|
|
68
63
|
|
|
69
64
|
export const makeWebSocketConnection = (
|
|
70
65
|
socket: globalThis.WebSocket | NodeWebSocket.WebSocket,
|
|
71
66
|
socketType: SocketType,
|
|
72
67
|
): Effect.Effect<
|
|
73
68
|
{
|
|
74
|
-
webChannel: WebChannel.WebChannel<typeof
|
|
69
|
+
webChannel: WebChannel.WebChannel<typeof WebmeshSchema.Packet.Type, typeof WebmeshSchema.Packet.Type>
|
|
75
70
|
from: string
|
|
76
71
|
},
|
|
77
72
|
never,
|
|
@@ -83,7 +78,7 @@ export const makeWebSocketConnection = (
|
|
|
83
78
|
|
|
84
79
|
const fromDeferred = yield* Deferred.make<string>()
|
|
85
80
|
|
|
86
|
-
const listenQueue = yield* Queue.unbounded<typeof
|
|
81
|
+
const listenQueue = yield* Queue.unbounded<typeof WebmeshSchema.Packet.Type>().pipe(
|
|
87
82
|
Effect.acquireRelease(Queue.shutdown),
|
|
88
83
|
)
|
|
89
84
|
|
|
@@ -95,7 +90,7 @@ export const makeWebSocketConnection = (
|
|
|
95
90
|
if (msg._tag === 'WSConnectionInit') {
|
|
96
91
|
yield* Deferred.succeed(fromDeferred, msg.from)
|
|
97
92
|
} else {
|
|
98
|
-
const decodedPayload = yield* Schema.decode(
|
|
93
|
+
const decodedPayload = yield* Schema.decode(WebmeshSchema.Packet)(msg.payload)
|
|
99
94
|
yield* Queue.offer(listenQueue, decodedPayload)
|
|
100
95
|
}
|
|
101
96
|
}),
|
|
@@ -135,10 +130,10 @@ export const makeWebSocketConnection = (
|
|
|
135
130
|
{ once: true },
|
|
136
131
|
)
|
|
137
132
|
|
|
138
|
-
const send = (message: typeof
|
|
133
|
+
const send = (message: typeof WebmeshSchema.Packet.Type) =>
|
|
139
134
|
Effect.gen(function* () {
|
|
140
135
|
yield* isConnectedLatch.await
|
|
141
|
-
const payload = yield* Schema.encode(
|
|
136
|
+
const payload = yield* Schema.encode(WebmeshSchema.Packet)(message)
|
|
142
137
|
socket.send(Schema.encodeSync(MessageMsgPack)({ _tag: 'WSConnectionPayload', payload, from }))
|
|
143
138
|
})
|
|
144
139
|
|
|
@@ -149,10 +144,10 @@ export const makeWebSocketConnection = (
|
|
|
149
144
|
send,
|
|
150
145
|
listen,
|
|
151
146
|
closedDeferred,
|
|
152
|
-
schema: { listen:
|
|
147
|
+
schema: { listen: WebmeshSchema.Packet, send: WebmeshSchema.Packet },
|
|
153
148
|
supportsTransferables: false,
|
|
154
149
|
shutdown: Scope.close(scope, Exit.void),
|
|
155
|
-
} satisfies WebChannel.WebChannel<typeof
|
|
150
|
+
} satisfies WebChannel.WebChannel<typeof WebmeshSchema.Packet.Type, typeof WebmeshSchema.Packet.Type>
|
|
156
151
|
|
|
157
152
|
return { webChannel, from }
|
|
158
153
|
}).pipe(Effect.withSpanScoped('makeWebSocketConnection')),
|