@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.
@@ -13,7 +13,7 @@ import {
13
13
  } from '@livestore/utils/effect'
14
14
  import type * as NodeWebSocket from 'ws'
15
15
 
16
- import * as MeshSchema from './mesh-schema.js'
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 MeshSchema.Packet.Type, typeof MeshSchema.Packet.Type>
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 MeshSchema.Packet.Type>().pipe(
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(MeshSchema.Packet)(msg.payload)
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 MeshSchema.Packet.Type) =>
133
+ const send = (message: typeof WebmeshSchema.Packet.Type) =>
139
134
  Effect.gen(function* () {
140
135
  yield* isConnectedLatch.await
141
- const payload = yield* Schema.encode(MeshSchema.Packet)(message)
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: MeshSchema.Packet, send: MeshSchema.Packet },
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 MeshSchema.Packet.Type, typeof MeshSchema.Packet.Type>
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')),