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