braid-blob 0.0.82 → 0.0.84

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.
Files changed (2) hide show
  1. package/index.js +15 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -443,9 +443,22 @@ function create_braid_blob() {
443
443
  })
444
444
  }
445
445
 
446
- braid_blob.list = async () => {
446
+ // list() accepts an optional callback to process keys atomically,
447
+ // avoiding races where the set of keys changes between await and processing
448
+ braid_blob.list = async (cb) => {
447
449
  await braid_blob.init()
448
- return braid_blob.meta_db.prepare(`SELECT key FROM meta`).all().map(row => row.key)
450
+ var keys = braid_blob.meta_db.prepare(`SELECT key FROM meta`).all().map(row => row.key)
451
+ if (cb) cb(keys)
452
+ return keys
453
+ }
454
+
455
+ // exists() checks whether a key is present, with an optional callback
456
+ // to process the result atomically (same pattern as list())
457
+ braid_blob.exists = async (key, cb) => {
458
+ await braid_blob.init()
459
+ var exists = !!braid_blob.meta_db.prepare(`SELECT 1 FROM meta WHERE key = ?`).get(key)
460
+ if (cb) cb(exists)
461
+ return exists
449
462
  }
450
463
 
451
464
  braid_blob.init = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-blob",
3
- "version": "0.0.82",
3
+ "version": "0.0.84",
4
4
  "description": "Library for collaborative blobs over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-blob",