@mblaney/holster 1.0.19 → 1.0.20

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mblaney/holster",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "Holster is a service that allows synchronising data between devices using Node, Deno, Bun or the browser.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/wire.js CHANGED
@@ -264,32 +264,27 @@ const Wire = opt => {
264
264
  const put = async (msg, send) => {
265
265
  // Store updates returned from Ham.mix and defer updates if required.
266
266
  const update = await Ham.mix(msg.put, graph, opt.secure, listen)
267
- if (Object.keys(update.now).length) {
268
- if (!(await check(update.now, send))) return
269
-
270
- store.put(update.now, err => {
271
- send(
272
- JSON.stringify({
273
- "#": dup.track(utils.text.random(9)),
274
- "@": msg["#"],
275
- err: err,
276
- }),
277
- )
278
- })
267
+ if (Object.keys(update.now).length === 0) {
268
+ // No updates to store, check deferred.
269
+ if (Object.keys(update.defer).length !== 0) {
270
+ setTimeout(() => put({put: update.defer}, send), update.wait)
271
+ }
272
+ return
279
273
  }
280
274
 
281
- // Always broadcast original data to other peers even if no local update
282
- const sendResult = send(
283
- JSON.stringify({
284
- "#": dup.track(utils.text.random(9)),
285
- put: msg.put,
286
- }),
287
- )
288
- if (sendResult && sendResult.err) {
289
- console.log(`Error broadcasting put: ${sendResult.err}`)
290
- }
275
+ if (!(await check(update.now, send))) return
291
276
 
292
- if (Object.keys(update.defer).length) {
277
+ store.put(update.now, err => {
278
+ send(
279
+ JSON.stringify({
280
+ "#": dup.track(utils.text.random(9)),
281
+ "@": msg["#"],
282
+ err: err,
283
+ }),
284
+ )
285
+ })
286
+
287
+ if (Object.keys(update.defer).length !== 0) {
293
288
  setTimeout(() => put({put: update.defer}, send), update.wait)
294
289
  }
295
290
  }
@@ -365,29 +360,29 @@ const Wire = opt => {
365
360
  // used whereas wire spec needs to handle clock skew for updates
366
361
  // across the network.
367
362
  const update = await Ham.mix(data, graph, opt.secure, listen)
363
+ if (Object.keys(update.now).length === 0) {
364
+ // No updates, still respond to callback.
365
+ if (cb) cb(null)
366
+ return
367
+ }
368
368
 
369
- if (Object.keys(update.now).length !== 0) {
370
- if (!(await check(update.now, send, cb))) return
371
-
372
- // Seed pendingReferences with any new references from API calls
373
- for (const [soul, node] of Object.entries(update.now)) {
374
- if (node && typeof node === "object") {
375
- for (const [key, value] of Object.entries(node)) {
376
- const soulId = utils.rel.is(value)
377
- if (soulId) {
378
- // Add referenced soul to pending list
379
- pendingReferences.add(soulId)
380
- }
369
+ if (!(await check(update.now, send, cb))) return
370
+
371
+ // Seed pendingReferences with any new references from API calls
372
+ for (const [soul, node] of Object.entries(update.now)) {
373
+ if (node && typeof node === "object") {
374
+ for (const [key, value] of Object.entries(node)) {
375
+ const soulId = utils.rel.is(value)
376
+ if (soulId) {
377
+ // Add referenced soul to pending list
378
+ pendingReferences.add(soulId)
381
379
  }
382
380
  }
383
381
  }
384
-
385
- store.put(update.now, cb)
386
- } else {
387
- // No local update needed, but still callback
388
- if (cb) cb(null)
389
382
  }
390
383
 
384
+ store.put(update.now, cb)
385
+
391
386
  // Always put data on the wire spec even if no local update needed
392
387
  const sendResult = send(
393
388
  JSON.stringify({