braid-text 0.2.24 → 0.2.25
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 +10 -0
- package/package.json +1 -1
- package/test/test.html +30 -0
package/index.js
CHANGED
|
@@ -76,6 +76,16 @@ braid_text.serve = async (req, res, options = {}) => {
|
|
|
76
76
|
if (!req.subscribe) {
|
|
77
77
|
res.setHeader("Accept-Subscribe", "true")
|
|
78
78
|
|
|
79
|
+
// special case for HEAD asking for version/parents,
|
|
80
|
+
// to be faster by not reconstructing body
|
|
81
|
+
if (req.method === "HEAD" && (req.version || req.parents)) {
|
|
82
|
+
if ((req.version || req.parents).every(event => {
|
|
83
|
+
var [actor, seq] = decode_version(event)
|
|
84
|
+
return resource.actor_seqs[actor]?.has(seq)
|
|
85
|
+
})) return my_end(200)
|
|
86
|
+
else return my_end(500, "Unknown Version")
|
|
87
|
+
}
|
|
88
|
+
|
|
79
89
|
let x = null
|
|
80
90
|
try {
|
|
81
91
|
x = await braid_text.get(resource, { version: req.version, parents: req.parents })
|
package/package.json
CHANGED
package/test/test.html
CHANGED
|
@@ -266,4 +266,34 @@ runTest(
|
|
|
266
266
|
'retried!'
|
|
267
267
|
)
|
|
268
268
|
|
|
269
|
+
runTest(
|
|
270
|
+
"test asking for a version that should and shouldn't be there",
|
|
271
|
+
async () => {
|
|
272
|
+
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
273
|
+
|
|
274
|
+
var r = await braid_fetch(`/${key}`, {
|
|
275
|
+
method: 'PUT',
|
|
276
|
+
version: ['hi-10'],
|
|
277
|
+
parents: [],
|
|
278
|
+
body: 'x'
|
|
279
|
+
})
|
|
280
|
+
if (!r.ok) throw 'got: ' + r.statusCode
|
|
281
|
+
|
|
282
|
+
var r = await braid_fetch(`/${key}`, {
|
|
283
|
+
method: 'HEAD',
|
|
284
|
+
version: ['hi-5']
|
|
285
|
+
})
|
|
286
|
+
if (r.ok) throw 'found version we should not have found'
|
|
287
|
+
|
|
288
|
+
var r = await braid_fetch(`/${key}`, {
|
|
289
|
+
method: 'HEAD',
|
|
290
|
+
version: ['hi-10']
|
|
291
|
+
})
|
|
292
|
+
if (!r.ok) throw 'could not find version we should have found'
|
|
293
|
+
|
|
294
|
+
return 'worked out!'
|
|
295
|
+
},
|
|
296
|
+
'worked out!'
|
|
297
|
+
)
|
|
298
|
+
|
|
269
299
|
</script>
|