@livestore/webmesh 0.4.0-dev.1 → 0.4.0-dev.11

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/src/node.test.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IS_CI } from '@livestore/utils'
1
+ import { IS_CI, omitUndefineds } from '@livestore/utils'
2
2
  import { Chunk, Deferred, Effect, Exit, Schema, Scope, Stream, WebChannel } from '@livestore/utils/effect'
3
3
  import { Vitest } from '@livestore/utils-dev/node-vitest'
4
4
  import { expect } from 'vitest'
@@ -25,12 +25,12 @@ const connectNodesViaMessageChannel = (nodeA: MeshNode, nodeB: MeshNode, options
25
25
  yield* nodeA.addEdge({
26
26
  target: nodeB.nodeName,
27
27
  edgeChannel: meshChannelAToB,
28
- replaceIfExists: options?.replaceIfExists,
28
+ ...omitUndefineds({ replaceIfExists: options?.replaceIfExists }),
29
29
  })
30
30
  yield* nodeB.addEdge({
31
31
  target: nodeA.nodeName,
32
32
  edgeChannel: meshChannelBToA,
33
- replaceIfExists: options?.replaceIfExists,
33
+ ...omitUndefineds({ replaceIfExists: options?.replaceIfExists }),
34
34
  })
35
35
  }).pipe(Effect.withSpan(`connectNodesViaMessageChannel:${nodeA.nodeName}↔${nodeB.nodeName}`))
36
36
 
@@ -50,12 +50,12 @@ const connectNodesViaBroadcastChannel = (nodeA: MeshNode, nodeB: MeshNode, optio
50
50
  yield* nodeA.addEdge({
51
51
  target: nodeB.nodeName,
52
52
  edgeChannel: broadcastWebChannelA,
53
- replaceIfExists: options?.replaceIfExists,
53
+ ...omitUndefineds({ replaceIfExists: options?.replaceIfExists }),
54
54
  })
55
55
  yield* nodeB.addEdge({
56
56
  target: nodeA.nodeName,
57
57
  edgeChannel: broadcastWebChannelB,
58
- replaceIfExists: options?.replaceIfExists,
58
+ ...omitUndefineds({ replaceIfExists: options?.replaceIfExists }),
59
59
  })
60
60
  }).pipe(Effect.withSpan(`connectNodesViaBroadcastChannel:${nodeA.nodeName}↔${nodeB.nodeName}`))
61
61
 
@@ -188,7 +188,13 @@ Vitest.describe('webmesh node', { timeout: testTimeout }, () => {
188
188
  nodeX,
189
189
  nodeY,
190
190
  channelType,
191
- delays: { x: delayX, y: delayY, connect: connectDelay },
191
+ delays: {
192
+ ...omitUndefineds({
193
+ x: delayX,
194
+ y: delayY,
195
+ connect: connectDelay,
196
+ }),
197
+ },
192
198
  })
193
199
 
194
200
  yield* Effect.promise(() => nodeX.debug.requestTopology(100))
package/src/node.ts CHANGED
@@ -171,10 +171,8 @@ export const makeMeshNode = <TName extends MeshNodeName>(
171
171
  const checkTransferableEdges = (packet: typeof WebmeshSchema.DirectChannelPacket.Type) => {
172
172
  if (
173
173
  (packet._tag === 'DirectChannelRequest' &&
174
- (edgeChannels.size === 0 ||
175
- // Either if direct edge does not support transferables ...
176
- edgeChannels.get(packet.target)?.channel.supportsTransferables === false)) ||
177
- // ... or if no forward-edges support transferables
174
+ (edgeChannels.size === 0 || // Either if direct edge does not support transferables ...
175
+ edgeChannels.get(packet.target)?.channel.supportsTransferables === false)) || // ... or if no forward-edges support transferables
178
176
  ![...edgeChannels.values()].some((c) => c.channel.supportsTransferables === true)
179
177
  ) {
180
178
  return WebmeshSchema.DirectChannelResponseNoTransferables.make({
@@ -458,7 +456,7 @@ export const makeMeshNode = <TName extends MeshNodeName>(
458
456
  const removeEdge: MeshNode['removeEdge'] = (targetNodeName) =>
459
457
  Effect.gen(function* () {
460
458
  if (!edgeChannels.has(targetNodeName)) {
461
- yield* new Cause.NoSuchElementException(`No edge found for ${targetNodeName}`)
459
+ return yield* new Cause.NoSuchElementException(`No edge found for ${targetNodeName}`)
462
460
  }
463
461
 
464
462
  yield* Fiber.interrupt(edgeChannels.get(targetNodeName)!.listenFiber)
@@ -5,6 +5,7 @@ import {
5
5
  Either,
6
6
  Exit,
7
7
  Layer,
8
+ MsgPack,
8
9
  Queue,
9
10
  Schedule,
10
11
  Schema,
@@ -28,7 +29,7 @@ export class WSEdgePayload extends Schema.TaggedStruct('WSEdgePayload', {
28
29
 
29
30
  export class WSEdgeMessage extends Schema.Union(WSEdgeInit, WSEdgePayload) {}
30
31
 
31
- export const MessageMsgPack = Schema.MsgPack(WSEdgeMessage)
32
+ export const MessageMsgPack = MsgPack.schema(WSEdgeMessage)
32
33
 
33
34
  export type SocketType =
34
35
  | {
@@ -77,7 +78,7 @@ export const makeWebSocketEdge = ({
77
78
  }: {
78
79
  socket: Socket.Socket
79
80
  socketType: SocketType
80
- debug?: { id?: string }
81
+ debug?: { id?: string } | undefined
81
82
  }): Effect.Effect<
82
83
  {
83
84
  webChannel: WebChannel.WebChannel<typeof WebmeshSchema.Packet.Type, typeof WebmeshSchema.Packet.Type>