braid-text 0.2.20 → 0.2.21

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
@@ -26,8 +26,8 @@ braid_text.serve = async (req, res, options = {}) => {
26
26
 
27
27
  braid_text.free_cors(res)
28
28
 
29
- function my_end(statusCode, x) {
30
- res.statusCode = statusCode
29
+ function my_end(statusCode, x, statusText, headers) {
30
+ res.writeHead(statusCode, statusText, headers)
31
31
  res.end(x ?? '')
32
32
  }
33
33
 
@@ -134,10 +134,10 @@ braid_text.serve = async (req, res, options = {}) => {
134
134
  let done_my_turn = null
135
135
  prev_put_p = new Promise(
136
136
  (done) =>
137
- (done_my_turn = (statusCode, x) => {
137
+ (done_my_turn = (statusCode, x, statusText, headers) => {
138
138
  waiting_puts--
139
139
  if (braid_text.verbose) console.log(`waiting_puts(after--) = ${waiting_puts}`)
140
- my_end(statusCode, x)
140
+ my_end(statusCode, x, statusText, headers)
141
141
  done()
142
142
  })
143
143
  )
@@ -190,7 +190,7 @@ braid_text.serve = async (req, res, options = {}) => {
190
190
  // - 428 Precondition Required
191
191
  // - pros: the name sounds right
192
192
  // - cons: typically implies that the request was missing an http conditional field like If-Match. that is to say, it implies that the request is missing a precondition, not that the server is missing a precondition
193
- return done_my_turn(425, e.message)
193
+ return done_my_turn(400, e.message, 'Missing Parents', { 'Retry-After': '1' })
194
194
  } else {
195
195
  return done_my_turn(500, "The server failed to apply this version. The error generated was: " + e)
196
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",
package/test/test.html CHANGED
@@ -238,4 +238,32 @@ runTest(
238
238
  '19'
239
239
  )
240
240
 
241
+ runTest(
242
+ "test retry when parents not there..",
243
+ async () => {
244
+ return await new Promise(done => {
245
+ var count = 0
246
+ var key = 'test-' + Math.random().toString(36).slice(2)
247
+ var a = new AbortController()
248
+ braid_fetch(`/${key}`, {
249
+ signal: a.signal,
250
+ multiplex: false,
251
+ method: 'PUT',
252
+ version: ['hi-3'],
253
+ parents: ['hi-1'],
254
+ body: 'xx',
255
+ onFetch: () => {
256
+ count++
257
+ if (count === 2) {
258
+ done('retried!')
259
+ a.abort()
260
+ }
261
+ },
262
+ retry: true
263
+ })
264
+ })
265
+ },
266
+ 'retried!'
267
+ )
268
+
241
269
  </script>