@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/package.json CHANGED
@@ -1,27 +1,25 @@
1
1
  {
2
2
  "name": "@livestore/webmesh",
3
- "version": "0.0.0-snapshot-057a9e3a18ca69a310d4eb8cf35a34e94fa1841e",
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-057a9e3a18ca69a310d4eb8cf35a34e94fa1841e"
18
+ "@livestore/utils": "0.0.0-snapshot-8fd59846e2580d37bdd37ae607e9db2a458a8b63"
21
19
  },
22
20
  "devDependencies": {
23
- "vitest": "3.2.4",
24
- "@livestore/utils-dev": "0.0.0-snapshot-057a9e3a18ca69a310d4eb8cf35a34e94fa1841e"
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
- if (waitForOfflineDelay === undefined) {
233
- // TODO we still need to fix this scenario but it shouldn't really be common in practice
234
- return
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
- const nodeA = yield* makeMeshNode('A')
238
- const nodeB = yield* makeMeshNode('B')
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
- const { mode, connectNodes } = fromChannelType(channelType)
239
+ const nodeA = yield* makeMeshNode('A')
240
+ const nodeB = yield* makeMeshNode('B')
241
241
 
242
- // TODO also optionally delay the edge
243
- yield* connectNodes(nodeA, nodeB)
242
+ const { mode, connectNodes } = fromChannelType(channelType)
244
243
 
245
- const waitForBToBeOffline =
246
- waitForOfflineDelay === undefined ? undefined : yield* Deferred.make<void, never>()
244
+ // TODO also optionally delay the edge
245
+ yield* connectNodes(nodeA, nodeB)
247
246
 
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' })
247
+ const waitForBToBeOffline =
248
+ waitForOfflineDelay === undefined ? undefined : yield* Deferred.make<void, never>()
252
249
 
253
- console.log('nodeACode:waiting for B to be offline')
254
- if (waitForBToBeOffline !== undefined) {
255
- yield* waitForBToBeOffline
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
- yield* channelAToB.send({ message: 'A2' })
259
- expect(yield* getFirstMessage(channelAToB)).toEqual({ message: 'B2' })
260
- })
255
+ console.log('nodeACode:waiting for B to be offline')
256
+ if (waitForBToBeOffline !== undefined) {
257
+ yield* waitForBToBeOffline
258
+ }
261
259
 
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 })
260
+ yield* channelAToB.send({ message: 'A2' })
261
+ expect(yield* getFirstMessage(channelAToB)).toEqual({ message: 'B2' })
262
+ })
268
263
 
269
- yield* channelBToA.send({ message: 'B1' })
270
- expect(yield* getFirstMessage(channelBToA)).toEqual({ message: 'A1' })
271
- }).pipe(Effect.scoped, Effect.withSpan('nodeBCode:part1'))
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
- console.log('nodeBCode:B node going offline')
274
- if (waitForBToBeOffline !== undefined) {
275
- yield* Deferred.succeed(waitForBToBeOffline, void 0)
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
- if (sleepDelay !== undefined) {
279
- yield* Effect.sleep(sleepDelay).pipe(Effect.withSpan(`B:sleep(${sleepDelay})`))
280
- }
275
+ console.log('nodeBCode:B node going offline')
276
+ if (waitForBToBeOffline !== undefined) {
277
+ yield* Deferred.succeed(waitForBToBeOffline, void 0)
278
+ }
281
279
 
282
- // Recreating the channel
283
- yield* Effect.gen(function* () {
284
- const channelBToA = yield* createChannel(nodeB, 'A', { mode })
280
+ if (sleepDelay !== undefined) {
281
+ yield* Effect.sleep(sleepDelay).pipe(Effect.withSpan(`B:sleep(${sleepDelay})`))
282
+ }
285
283
 
286
- yield* channelBToA.send({ message: 'B2' })
287
- expect(yield* getFirstMessage(channelBToA)).toEqual({ message: 'A2' })
288
- }).pipe(Effect.scoped, Effect.withSpan('nodeBCode:part2'))
289
- })
284
+ // Recreating the channel
285
+ yield* Effect.gen(function* () {
286
+ const channelBToA = yield* createChannel(nodeB, 'A', { mode })
290
287
 
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
- )
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
@@ -1,3 +1,4 @@
1
+ /* eslint-disable prefer-arrow/prefer-arrow-functions */
1
2
  import { Duration, Effect } from '@livestore/utils/effect'
2
3
 
3
4
  /**