braid-blob 0.0.35 → 0.0.36

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/index.js CHANGED
@@ -201,7 +201,7 @@ function create_braid_blob() {
201
201
  throw new Error('unkown version: ' + options.version)
202
202
  if (options.parents && options.parents.length && compare_events(options.parents[0], meta.event) > 0)
203
203
  throw new Error('unkown version: ' + options.parents)
204
- if (options.head) return
204
+ if (options.head) return result
205
205
 
206
206
  if (options.subscribe) {
207
207
  var subscribe_chain = Promise.resolve()
@@ -432,7 +432,8 @@ function create_braid_blob() {
432
432
  try {
433
433
  // Check if remote has our current version (simple fork-point check)
434
434
  var local_result = await braid_blob.get(a, {
435
- signal: ac.signal
435
+ signal: ac.signal,
436
+ head: true
436
437
  })
437
438
  var local_version = local_result ? local_result.version : null
438
439
  var server_has_our_version = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-blob",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "Library for collaborative blobs over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-blob",
package/test/tests.js CHANGED
@@ -1199,6 +1199,68 @@ runTest(
1199
1199
  'no disconnects'
1200
1200
  )
1201
1201
 
1202
+ runTest(
1203
+ "test sync connect does not read file body for version check",
1204
+ async () => {
1205
+ var local_key = '/test-sync-no-read-' + Math.random().toString(36).slice(2)
1206
+ var remote_key = 'test-sync-no-read-remote-' + Math.random().toString(36).slice(2)
1207
+
1208
+ // Put something on remote with SAME version as local, so no data needs to flow
1209
+ var put_result = await braid_fetch(`/${remote_key}`, {
1210
+ method: 'PUT',
1211
+ version: ['same-version-123'],
1212
+ body: 'same content'
1213
+ })
1214
+ if (!put_result.ok) return 'PUT status: ' + put_result.status
1215
+
1216
+ var r1 = await braid_fetch(`/eval`, {
1217
+ method: 'POST',
1218
+ body: `void (async () => {
1219
+ try {
1220
+ var braid_blob = require(\`\${__dirname}/../index.js\`)
1221
+
1222
+ // Put locally with SAME version - so when sync connects, no updates need to flow
1223
+ await braid_blob.put('${local_key}', Buffer.from('same content'), { version: ['same-version-123'] })
1224
+
1225
+ // Wrap db.read to count calls for our specific key
1226
+ var read_count = 0
1227
+ var original_read = braid_blob.db.read
1228
+ braid_blob.db.read = async function(key) {
1229
+ if (key === '${local_key}') read_count++
1230
+ return original_read.call(this, key)
1231
+ }
1232
+
1233
+ var remote_url = new URL('http://localhost:' + req.socket.localPort + '/${remote_key}')
1234
+
1235
+ // Create an AbortController to stop the sync
1236
+ var ac = new AbortController()
1237
+
1238
+ // Start sync - since both have same version, no updates should flow
1239
+ braid_blob.sync('${local_key}', remote_url, { signal: ac.signal })
1240
+
1241
+ // Wait for sync to establish connection
1242
+ await new Promise(done => setTimeout(done, 300))
1243
+
1244
+ // Stop sync
1245
+ ac.abort()
1246
+
1247
+ // Restore original read
1248
+ braid_blob.db.read = original_read
1249
+
1250
+ // db.read should not have been called since:
1251
+ // 1. Initial version check uses head:true (no body read)
1252
+ // 2. Both have same version so no updates flow
1253
+ res.end(read_count === 0 ? 'no reads' : 'reads: ' + read_count)
1254
+ } catch (e) {
1255
+ res.end('error: ' + e.message + ' ' + e.stack)
1256
+ }
1257
+ })()`
1258
+ })
1259
+ return await r1.text()
1260
+ },
1261
+ 'no reads'
1262
+ )
1263
+
1202
1264
  runTest(
1203
1265
  "test sync closed during error",
1204
1266
  async () => {