@livestore/webmesh 0.0.0-snapshot-057a9e3a18ca69a310d4eb8cf35a34e94fa1841e → 0.0.0-snapshot-8fd59846e2580d37bdd37ae607e9db2a458a8b63
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/README.md +0 -52
- package/dist/.tsbuildinfo +1 -1
- package/dist/channel/proxy-channel.d.ts.map +1 -1
- package/dist/channel/proxy-channel.js.map +1 -1
- package/dist/mod.d.ts +3 -3
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +3 -3
- package/dist/mod.js.map +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1 -0
- package/dist/node.js.map +1 -1
- package/dist/node.test.js +58 -56
- package/dist/node.test.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -1
- package/package.json +4 -6
- package/src/channel/proxy-channel.ts +2 -2
- package/src/mod.ts +3 -3
- package/src/node.test.ts +69 -66
- package/src/node.ts +1 -0
- package/src/utils.ts +1 -0
package/package.json
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/webmesh",
|
|
3
|
-
"version": "0.0.0-snapshot-
|
|
3
|
+
"version": "0.0.0-snapshot-8fd59846e2580d37bdd37ae607e9db2a458a8b63",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/mod.d.ts",
|
|
9
|
-
"bun": "./src/mod.ts",
|
|
10
9
|
"default": "./dist/mod.js"
|
|
11
10
|
},
|
|
12
11
|
"./websocket-server": {
|
|
13
12
|
"types": "./dist/websocket-server.d.ts",
|
|
14
|
-
"bun": "./src/websocket-server.ts",
|
|
15
13
|
"default": "./dist/websocket-server.js"
|
|
16
14
|
}
|
|
17
15
|
},
|
|
18
16
|
"types": "./dist/mod.d.ts",
|
|
19
17
|
"dependencies": {
|
|
20
|
-
"@livestore/utils": "0.0.0-snapshot-
|
|
18
|
+
"@livestore/utils": "0.0.0-snapshot-8fd59846e2580d37bdd37ae607e9db2a458a8b63"
|
|
21
19
|
},
|
|
22
20
|
"devDependencies": {
|
|
23
|
-
"vitest": "3.2
|
|
24
|
-
"@livestore/utils-dev": "0.0.0-snapshot-
|
|
21
|
+
"vitest": "^3.1.2",
|
|
22
|
+
"@livestore/utils-dev": "0.0.0-snapshot-8fd59846e2580d37bdd37ae607e9db2a458a8b63"
|
|
25
23
|
},
|
|
26
24
|
"files": [
|
|
27
25
|
"package.json",
|
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
type ChannelKey,
|
|
22
22
|
type ChannelName,
|
|
23
23
|
type MeshNodeName,
|
|
24
|
-
type ProxyQueueItem,
|
|
25
24
|
packetAsOtelAttributes,
|
|
25
|
+
type ProxyQueueItem,
|
|
26
26
|
} from '../common.js'
|
|
27
27
|
import * as MeshSchema from '../mesh-schema.js'
|
|
28
28
|
|
|
@@ -427,7 +427,7 @@ export const makeProxyChannel = ({
|
|
|
427
427
|
debugInfo,
|
|
428
428
|
...({
|
|
429
429
|
debug: {
|
|
430
|
-
ping: (message = 'ping') =>
|
|
430
|
+
ping: (message: string = 'ping') =>
|
|
431
431
|
send(WebChannel.DebugPingMessage.make({ message })).pipe(
|
|
432
432
|
Effect.provide(runtime),
|
|
433
433
|
Effect.tapCauseLogPretty,
|
package/src/mod.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { EdgeAlreadyExistsError } from './common.js'
|
|
2
|
-
export * as WebmeshSchema from './mesh-schema.js'
|
|
3
|
-
export * from './node.js'
|
|
4
1
|
export * from './websocket-edge.js'
|
|
2
|
+
export * from './node.js'
|
|
3
|
+
export * as WebmeshSchema from './mesh-schema.js'
|
|
4
|
+
export { EdgeAlreadyExistsError } from './common.js'
|
package/src/node.test.ts
CHANGED
|
@@ -216,87 +216,90 @@ Vitest.describe('webmesh node', { timeout: testTimeout }, () => {
|
|
|
216
216
|
),
|
|
217
217
|
// { fastCheck: { numRuns: 20 } },
|
|
218
218
|
)
|
|
219
|
-
// const waitForOfflineDelay = undefined
|
|
220
|
-
// const sleepDelay = 0
|
|
221
|
-
// const channelType = 'direct'
|
|
222
|
-
// Vitest.scopedLive(
|
|
223
|
-
// 'b reconnects',
|
|
224
|
-
// (test) =>
|
|
225
|
-
Vitest.scopedLive.prop(
|
|
226
|
-
'b reconnects',
|
|
227
|
-
[Delay, Delay, ChannelType],
|
|
228
|
-
([waitForOfflineDelay, sleepDelay, channelType], test) =>
|
|
229
|
-
Effect.gen(function* () {
|
|
230
|
-
// console.log({ waitForOfflineDelay, sleepDelay, channelType })
|
|
231
219
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
220
|
+
{
|
|
221
|
+
// const waitForOfflineDelay = undefined
|
|
222
|
+
// const sleepDelay = 0
|
|
223
|
+
// const channelType = 'direct'
|
|
224
|
+
// Vitest.scopedLive(
|
|
225
|
+
// 'b reconnects',
|
|
226
|
+
// (test) =>
|
|
227
|
+
Vitest.scopedLive.prop(
|
|
228
|
+
'b reconnects',
|
|
229
|
+
[Delay, Delay, ChannelType],
|
|
230
|
+
([waitForOfflineDelay, sleepDelay, channelType], test) =>
|
|
231
|
+
Effect.gen(function* () {
|
|
232
|
+
// console.log({ waitForOfflineDelay, sleepDelay, channelType })
|
|
236
233
|
|
|
237
|
-
|
|
238
|
-
|
|
234
|
+
if (waitForOfflineDelay === undefined) {
|
|
235
|
+
// TODO we still need to fix this scenario but it shouldn't really be common in practice
|
|
236
|
+
return
|
|
237
|
+
}
|
|
239
238
|
|
|
240
|
-
|
|
239
|
+
const nodeA = yield* makeMeshNode('A')
|
|
240
|
+
const nodeB = yield* makeMeshNode('B')
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
yield* connectNodes(nodeA, nodeB)
|
|
242
|
+
const { mode, connectNodes } = fromChannelType(channelType)
|
|
244
243
|
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
// TODO also optionally delay the edge
|
|
245
|
+
yield* connectNodes(nodeA, nodeB)
|
|
247
246
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
yield* channelAToB.send({ message: 'A1' })
|
|
251
|
-
expect(yield* getFirstMessage(channelAToB)).toEqual({ message: 'B1' })
|
|
247
|
+
const waitForBToBeOffline =
|
|
248
|
+
waitForOfflineDelay === undefined ? undefined : yield* Deferred.make<void, never>()
|
|
252
249
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
yield*
|
|
256
|
-
|
|
250
|
+
const nodeACode = Effect.gen(function* () {
|
|
251
|
+
const channelAToB = yield* createChannel(nodeA, 'B', { mode })
|
|
252
|
+
yield* channelAToB.send({ message: 'A1' })
|
|
253
|
+
expect(yield* getFirstMessage(channelAToB)).toEqual({ message: 'B1' })
|
|
257
254
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
255
|
+
console.log('nodeACode:waiting for B to be offline')
|
|
256
|
+
if (waitForBToBeOffline !== undefined) {
|
|
257
|
+
yield* waitForBToBeOffline
|
|
258
|
+
}
|
|
261
259
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const nodeBCode = Effect.gen(function* () {
|
|
266
|
-
yield* Effect.gen(function* () {
|
|
267
|
-
const channelBToA = yield* createChannel(nodeB, 'A', { mode })
|
|
260
|
+
yield* channelAToB.send({ message: 'A2' })
|
|
261
|
+
expect(yield* getFirstMessage(channelAToB)).toEqual({ message: 'B2' })
|
|
262
|
+
})
|
|
268
263
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
264
|
+
// Simulating node b going offline and then coming back online
|
|
265
|
+
// This test also illustrates why we need a ack-message channel since otherwise
|
|
266
|
+
// sent messages might get lost
|
|
267
|
+
const nodeBCode = Effect.gen(function* () {
|
|
268
|
+
yield* Effect.gen(function* () {
|
|
269
|
+
const channelBToA = yield* createChannel(nodeB, 'A', { mode })
|
|
272
270
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
271
|
+
yield* channelBToA.send({ message: 'B1' })
|
|
272
|
+
expect(yield* getFirstMessage(channelBToA)).toEqual({ message: 'A1' })
|
|
273
|
+
}).pipe(Effect.scoped, Effect.withSpan('nodeBCode:part1'))
|
|
277
274
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
275
|
+
console.log('nodeBCode:B node going offline')
|
|
276
|
+
if (waitForBToBeOffline !== undefined) {
|
|
277
|
+
yield* Deferred.succeed(waitForBToBeOffline, void 0)
|
|
278
|
+
}
|
|
281
279
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
280
|
+
if (sleepDelay !== undefined) {
|
|
281
|
+
yield* Effect.sleep(sleepDelay).pipe(Effect.withSpan(`B:sleep(${sleepDelay})`))
|
|
282
|
+
}
|
|
285
283
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
})
|
|
284
|
+
// Recreating the channel
|
|
285
|
+
yield* Effect.gen(function* () {
|
|
286
|
+
const channelBToA = yield* createChannel(nodeB, 'A', { mode })
|
|
290
287
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
288
|
+
yield* channelBToA.send({ message: 'B2' })
|
|
289
|
+
expect(yield* getFirstMessage(channelBToA)).toEqual({ message: 'A2' })
|
|
290
|
+
}).pipe(Effect.scoped, Effect.withSpan('nodeBCode:part2'))
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
yield* Effect.all([nodeACode, nodeBCode], { concurrency: 'unbounded' }).pipe(Effect.withSpan('test'))
|
|
294
|
+
}).pipe(
|
|
295
|
+
withCtx(test, {
|
|
296
|
+
skipOtel: true,
|
|
297
|
+
suffix: `waitForOfflineDelay=${waitForOfflineDelay} sleepDelay=${sleepDelay} channelType=${channelType}`,
|
|
298
|
+
}),
|
|
299
|
+
),
|
|
300
|
+
{ fastCheck: { numRuns: 20 } },
|
|
301
|
+
)
|
|
302
|
+
}
|
|
300
303
|
|
|
301
304
|
Vitest.scopedLive('reconnect with re-created node', (test) =>
|
|
302
305
|
Effect.gen(function* () {
|
package/src/node.ts
CHANGED
|
@@ -298,6 +298,7 @@ export const makeMeshNode = <TName extends MeshNodeName>(
|
|
|
298
298
|
yield* edgeChannel.send({ ...packet, hops })
|
|
299
299
|
}
|
|
300
300
|
// In this case we have an expected route back we should follow
|
|
301
|
+
// eslint-disable-next-line unicorn/no-negated-condition
|
|
301
302
|
else if (packet.remainingHops !== undefined) {
|
|
302
303
|
const hopTarget =
|
|
303
304
|
packet.remainingHops.at(-1) ?? shouldNeverHappen(`${nodeName}: Expected remaining hops for packet`, packet)
|
package/src/utils.ts
CHANGED