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