@livestore/webmesh 0.4.0 → 0.5.0-dev.0
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/direct-channel-internal.d.ts +2 -3
- package/dist/channel/direct-channel-internal.d.ts.map +1 -1
- package/dist/channel/direct-channel-internal.js +23 -18
- package/dist/channel/direct-channel-internal.js.map +1 -1
- package/dist/channel/direct-channel.d.ts.map +1 -1
- package/dist/channel/direct-channel.js +20 -21
- package/dist/channel/direct-channel.js.map +1 -1
- package/dist/channel/proxy-channel.d.ts +7 -8
- package/dist/channel/proxy-channel.d.ts.map +1 -1
- package/dist/channel/proxy-channel.js +26 -22
- package/dist/channel/proxy-channel.js.map +1 -1
- package/dist/common.d.ts +33 -35
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +3 -2
- package/dist/common.js.map +1 -1
- package/dist/mesh-schema.d.ts +262 -136
- package/dist/mesh-schema.d.ts.map +1 -1
- package/dist/mesh-schema.js +45 -44
- package/dist/mesh-schema.js.map +1 -1
- package/dist/node.d.ts +6 -6
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +22 -21
- package/dist/node.js.map +1 -1
- package/dist/node.test.js +74 -71
- package/dist/node.test.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/dist/websocket-edge.d.ts +18 -16
- package/dist/websocket-edge.d.ts.map +1 -1
- package/dist/websocket-edge.js +30 -36
- package/dist/websocket-edge.js.map +1 -1
- package/dist/websocket-edge.test.js +14 -14
- package/dist/websocket-edge.test.js.map +1 -1
- package/dist/worker/mod.d.ts +24 -0
- package/dist/worker/mod.d.ts.map +1 -0
- package/dist/worker/mod.js +44 -0
- package/dist/worker/mod.js.map +1 -0
- package/dist/worker/schema.d.ts +10 -0
- package/dist/worker/schema.d.ts.map +1 -0
- package/dist/worker/schema.js +7 -0
- package/dist/worker/schema.js.map +1 -0
- package/package.json +20 -37
- package/src/channel/direct-channel-internal.ts +30 -22
- package/src/channel/direct-channel.ts +26 -23
- package/src/channel/proxy-channel.ts +39 -36
- package/src/common.ts +6 -3
- package/src/mesh-schema.ts +34 -33
- package/src/node.test.ts +99 -86
- package/src/node.ts +32 -32
- package/src/utils.ts +3 -3
- package/src/websocket-edge.test.ts +14 -14
- package/src/websocket-edge.ts +47 -41
- package/src/worker/mod.ts +89 -0
- package/src/worker/schema.ts +8 -0
package/src/common.ts
CHANGED
|
@@ -23,14 +23,17 @@ export type ChannelKey = `target:${MeshNodeName}, channelName:${ChannelName}`
|
|
|
23
23
|
// '~@livestore/webmesh/NoConnectionRouteSignal',
|
|
24
24
|
// )('NoConnectionRouteSignal', {}) {}
|
|
25
25
|
|
|
26
|
-
export class EdgeAlreadyExistsError extends Schema.TaggedError<EdgeAlreadyExistsError>(
|
|
26
|
+
export class EdgeAlreadyExistsError extends Schema.TaggedError<EdgeAlreadyExistsError>(
|
|
27
|
+
'~@livestore/webmesh/EdgeAlreadyExistsError',
|
|
28
|
+
)('EdgeAlreadyExistsError', {
|
|
27
29
|
target: Schema.String,
|
|
28
30
|
}) {}
|
|
29
31
|
|
|
30
32
|
export const packetAsOtelAttributes = (packet: typeof Packet.Type) => ({
|
|
31
33
|
packetId: packet.id,
|
|
32
34
|
'span.label':
|
|
33
|
-
packet.id +
|
|
35
|
+
packet.id +
|
|
36
|
+
(Predicate.hasProperty(packet, 'reqId') === true && packet.reqId !== undefined ? ` for ${packet.reqId}` : ''),
|
|
34
37
|
...omitUndefineds({
|
|
35
38
|
packet:
|
|
36
39
|
packet._tag !== 'DirectChannelResponseSuccess' && packet._tag !== 'ProxyChannelPayload' ? packet : undefined,
|
|
@@ -40,7 +43,7 @@ export const packetAsOtelAttributes = (packet: typeof Packet.Type) => ({
|
|
|
40
43
|
export const ListenForChannelResult = Schema.Struct({
|
|
41
44
|
channelName: Schema.String,
|
|
42
45
|
source: Schema.String,
|
|
43
|
-
mode: Schema.
|
|
46
|
+
mode: Schema.Literals(['proxy', 'direct']),
|
|
44
47
|
})
|
|
45
48
|
|
|
46
49
|
export type ListenForChannelResult = typeof ListenForChannelResult.Type
|
package/src/mesh-schema.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Schema, Transferable } from '@livestore/utils/effect'
|
|
1
|
+
import { Effect, Schema, Transferable } from '@livestore/utils/effect'
|
|
2
2
|
import { nanoid } from '@livestore/utils/nanoid'
|
|
3
3
|
|
|
4
4
|
const id = Schema.String.pipe(
|
|
5
|
-
Schema.
|
|
6
|
-
Schema.
|
|
5
|
+
Schema.withDecodingDefaultType(Effect.sync(() => nanoid(10))),
|
|
6
|
+
Schema.withConstructorDefault(Effect.sync(() => nanoid(10))),
|
|
7
7
|
)
|
|
8
8
|
|
|
9
9
|
const defaultPacketFields = {
|
|
@@ -23,10 +23,10 @@ const remainingHopsUndefined = Schema.Undefined.pipe(Schema.optional)
|
|
|
23
23
|
* We need a clear path back to the sender to avoid this, thus we respond with a separate
|
|
24
24
|
* `DirectChannelResponseSuccess` which contains the `port`.
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
26
|
+
export const DirectChannelRequest = Schema.TaggedStruct('DirectChannelRequest', {
|
|
27
27
|
...defaultPacketFields,
|
|
28
28
|
remainingHops: Schema.Array(Schema.String).pipe(Schema.optional),
|
|
29
|
-
channelVersion: Schema.
|
|
29
|
+
channelVersion: Schema.Finite,
|
|
30
30
|
/** Only set if the request is in response to an incoming request */
|
|
31
31
|
reqId: Schema.UndefinedOr(Schema.String),
|
|
32
32
|
/**
|
|
@@ -34,70 +34,70 @@ export class DirectChannelRequest extends Schema.TaggedStruct('DirectChannelRequ
|
|
|
34
34
|
* source has changed.
|
|
35
35
|
*/
|
|
36
36
|
sourceId: Schema.String,
|
|
37
|
-
})
|
|
37
|
+
})
|
|
38
38
|
|
|
39
|
-
export
|
|
39
|
+
export const DirectChannelResponseSuccess = Schema.TaggedStruct('DirectChannelResponseSuccess', {
|
|
40
40
|
...defaultPacketFields,
|
|
41
41
|
reqId: Schema.String,
|
|
42
42
|
port: Transferable.MessagePort,
|
|
43
43
|
// Since we can't copy this message, we need to follow the exact route back to the sender
|
|
44
44
|
remainingHops: Schema.Array(Schema.String),
|
|
45
|
-
channelVersion: Schema.
|
|
46
|
-
})
|
|
45
|
+
channelVersion: Schema.Finite,
|
|
46
|
+
})
|
|
47
47
|
|
|
48
|
-
export
|
|
48
|
+
export const DirectChannelResponseNoTransferables = Schema.TaggedStruct('DirectChannelResponseNoTransferables', {
|
|
49
49
|
...defaultPacketFields,
|
|
50
50
|
reqId: Schema.String,
|
|
51
51
|
remainingHops: Schema.Array(Schema.String),
|
|
52
|
-
})
|
|
52
|
+
})
|
|
53
53
|
|
|
54
|
-
export
|
|
54
|
+
export const ProxyChannelRequest = Schema.TaggedStruct('ProxyChannelRequest', {
|
|
55
55
|
...defaultPacketFields,
|
|
56
56
|
remainingHops: remainingHopsUndefined,
|
|
57
57
|
channelIdCandidate: Schema.String,
|
|
58
|
-
})
|
|
58
|
+
})
|
|
59
59
|
|
|
60
|
-
export
|
|
60
|
+
export const ProxyChannelResponseSuccess = Schema.TaggedStruct('ProxyChannelResponseSuccess', {
|
|
61
61
|
...defaultPacketFields,
|
|
62
62
|
reqId: Schema.String,
|
|
63
63
|
remainingHops: Schema.Array(Schema.String),
|
|
64
64
|
combinedChannelId: Schema.String,
|
|
65
65
|
channelIdCandidate: Schema.String,
|
|
66
|
-
})
|
|
66
|
+
})
|
|
67
67
|
|
|
68
|
-
export
|
|
68
|
+
export const ProxyChannelPayload = Schema.TaggedStruct('ProxyChannelPayload', {
|
|
69
69
|
...defaultPacketFields,
|
|
70
70
|
remainingHops: remainingHopsUndefined,
|
|
71
71
|
payload: Schema.Any,
|
|
72
72
|
combinedChannelId: Schema.String,
|
|
73
|
-
})
|
|
73
|
+
})
|
|
74
74
|
|
|
75
|
-
export
|
|
75
|
+
export const ProxyChannelPayloadAck = Schema.TaggedStruct('ProxyChannelPayloadAck', {
|
|
76
76
|
...defaultPacketFields,
|
|
77
77
|
reqId: Schema.String,
|
|
78
78
|
remainingHops: Schema.Array(Schema.String),
|
|
79
79
|
combinedChannelId: Schema.String,
|
|
80
|
-
})
|
|
80
|
+
})
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* Broadcast to all nodes when a new edge is added.
|
|
84
84
|
* Mostly used for auto-reconnect purposes.
|
|
85
85
|
*/
|
|
86
|
-
export
|
|
86
|
+
export const NetworkEdgeAdded = Schema.TaggedStruct('NetworkEdgeAdded', {
|
|
87
87
|
id,
|
|
88
88
|
source: Schema.String,
|
|
89
89
|
target: Schema.String,
|
|
90
|
-
})
|
|
90
|
+
})
|
|
91
91
|
|
|
92
|
-
export
|
|
92
|
+
export const NetworkTopologyRequest = Schema.TaggedStruct('NetworkTopologyRequest', {
|
|
93
93
|
id,
|
|
94
94
|
hops: Schema.Array(Schema.String),
|
|
95
95
|
/** Always fixed to who requested the topology */
|
|
96
96
|
source: Schema.String,
|
|
97
97
|
target: Schema.Literal('-'),
|
|
98
|
-
})
|
|
98
|
+
})
|
|
99
99
|
|
|
100
|
-
export
|
|
100
|
+
export const NetworkTopologyResponse = Schema.TaggedStruct('NetworkTopologyResponse', {
|
|
101
101
|
id,
|
|
102
102
|
reqId: Schema.String,
|
|
103
103
|
remainingHops: Schema.Array(Schema.String),
|
|
@@ -106,7 +106,7 @@ export class NetworkTopologyResponse extends Schema.TaggedStruct('NetworkTopolog
|
|
|
106
106
|
/** Always fixed to who requested the topology */
|
|
107
107
|
source: Schema.String,
|
|
108
108
|
target: Schema.Literal('-'),
|
|
109
|
-
})
|
|
109
|
+
})
|
|
110
110
|
|
|
111
111
|
export const BroadcastChannelPacket = Schema.TaggedStruct('BroadcastChannelPacket', {
|
|
112
112
|
id,
|
|
@@ -121,27 +121,28 @@ export const BroadcastChannelPacket = Schema.TaggedStruct('BroadcastChannelPacke
|
|
|
121
121
|
target: Schema.Literal('-'),
|
|
122
122
|
})
|
|
123
123
|
|
|
124
|
-
export
|
|
124
|
+
export const DirectChannelPacket = Schema.Union([
|
|
125
125
|
DirectChannelRequest,
|
|
126
126
|
DirectChannelResponseSuccess,
|
|
127
127
|
DirectChannelResponseNoTransferables,
|
|
128
|
-
)
|
|
128
|
+
])
|
|
129
129
|
|
|
130
|
-
export
|
|
130
|
+
export const ProxyChannelPacket = Schema.Union([
|
|
131
131
|
ProxyChannelRequest,
|
|
132
132
|
ProxyChannelResponseSuccess,
|
|
133
133
|
ProxyChannelPayload,
|
|
134
134
|
ProxyChannelPayloadAck,
|
|
135
|
-
)
|
|
135
|
+
])
|
|
136
136
|
|
|
137
|
-
export
|
|
137
|
+
export const Packet = Schema.Union([
|
|
138
138
|
DirectChannelPacket,
|
|
139
139
|
ProxyChannelPacket,
|
|
140
140
|
NetworkEdgeAdded,
|
|
141
141
|
NetworkTopologyRequest,
|
|
142
142
|
NetworkTopologyResponse,
|
|
143
143
|
BroadcastChannelPacket,
|
|
144
|
-
)
|
|
144
|
+
])
|
|
145
|
+
|
|
146
|
+
export const DirectChannelPing = Schema.TaggedStruct('DirectChannelPing', {})
|
|
145
147
|
|
|
146
|
-
export
|
|
147
|
-
export class DirectChannelPong extends Schema.TaggedStruct('DirectChannelPong', {}) {}
|
|
148
|
+
export const DirectChannelPong = Schema.TaggedStruct('DirectChannelPong', {})
|