braid-text 0.2.68 → 0.2.70
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/.claude/settings.local.json +10 -0
- package/index.js +500 -306
- package/package.json +1 -1
- package/test/fuzz-test.js +639 -0
- package/test/test.html +21 -1924
- package/test/tests.js +2107 -0
package/test/test.html
CHANGED
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
width: 25px;
|
|
29
29
|
height: 25px;
|
|
30
30
|
border: 1px solid #ddd;
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
32
|
</style>
|
|
33
33
|
<script src="https://unpkg.com/braid-http@~1.3/braid-http-client.js"></script>
|
|
34
|
+
<script src="./tests.js"></script>
|
|
34
35
|
<div id="summaryContainer"></div>
|
|
35
36
|
<div id="testContainer"></div>
|
|
36
37
|
<script type=module>
|
|
@@ -40,7 +41,17 @@ import {
|
|
|
40
41
|
Doc,
|
|
41
42
|
OpLog,
|
|
42
43
|
} from "https://unpkg.com/diamond-types-web";
|
|
43
|
-
|
|
44
|
+
|
|
45
|
+
// Make diamond-types available globally for tests.js
|
|
46
|
+
window.Doc = Doc
|
|
47
|
+
window.OpLog = OpLog
|
|
48
|
+
window.dt_p = init()
|
|
49
|
+
|
|
50
|
+
braid_fetch.enable_multiplex = false
|
|
51
|
+
|
|
52
|
+
// Parse URL parameters for filter
|
|
53
|
+
const urlParams = new URLSearchParams(window.location.search)
|
|
54
|
+
const filterArg = urlParams.get('filter') || urlParams.get('grep')
|
|
44
55
|
|
|
45
56
|
let delay = 0
|
|
46
57
|
|
|
@@ -54,7 +65,7 @@ function createTestDiv(testName) {
|
|
|
54
65
|
|
|
55
66
|
function updateTestResult(div, passed, message, got, expected) {
|
|
56
67
|
div.className = `test ${passed ? "passed" : "failed"}`
|
|
57
|
-
|
|
68
|
+
|
|
58
69
|
if (passed) {
|
|
59
70
|
div.querySelector(".result").textContent = message
|
|
60
71
|
div.querySelector(".result").style.fontSize = message.length > 400 ? 'xx-small' : message.length > 100 ? 'small' : ''
|
|
@@ -76,6 +87,11 @@ function updateSummaryBox(box, passed) {
|
|
|
76
87
|
}
|
|
77
88
|
|
|
78
89
|
async function runTest(testName, testFunction, expectedResult) {
|
|
90
|
+
// Apply filter if specified
|
|
91
|
+
if (filterArg && !testName.toLowerCase().includes(filterArg.toLowerCase())) {
|
|
92
|
+
return // Skip this test
|
|
93
|
+
}
|
|
94
|
+
|
|
79
95
|
delay += 70
|
|
80
96
|
|
|
81
97
|
await new Promise(done => setTimeout(done, delay))
|
|
@@ -96,1926 +112,7 @@ async function runTest(testName, testFunction, expectedResult) {
|
|
|
96
112
|
}
|
|
97
113
|
}
|
|
98
114
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
async () => {
|
|
102
|
-
var key = 'test' + Math.random().toString(36).slice(2)
|
|
103
|
-
|
|
104
|
-
var r = await braid_fetch(`/${key}`, {
|
|
105
|
-
method: 'PUT',
|
|
106
|
-
body: 'hi'
|
|
107
|
-
})
|
|
108
|
-
if (!r.ok) return 'got: ' + r.status
|
|
109
|
-
|
|
110
|
-
var r1p = braid_fetch(`/eval`, {
|
|
111
|
-
method: 'PUT',
|
|
112
|
-
body: `void (async () => {
|
|
113
|
-
var x = await new Promise(done => {
|
|
114
|
-
braid_text.get(new URL('http://localhost:8889/${key}'), {
|
|
115
|
-
subscribe: update => {
|
|
116
|
-
if (update.body_text) done(update.body_text)
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
res.end(x)
|
|
121
|
-
})()`
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
var r2 = await braid_fetch(`/${key}`, {
|
|
125
|
-
method: 'PUT',
|
|
126
|
-
body: 'yo'
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
var r1 = await r1p
|
|
130
|
-
if (!r1.ok) return 'got: ' + r.status
|
|
131
|
-
|
|
132
|
-
return await r1.text()
|
|
133
|
-
},
|
|
134
|
-
'yo'
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
runTest(
|
|
138
|
-
"test braid_text.sync, url to key",
|
|
139
|
-
async () => {
|
|
140
|
-
var key_a = 'test-a-' + Math.random().toString(36).slice(2)
|
|
141
|
-
var key_b = 'test-b-' + Math.random().toString(36).slice(2)
|
|
142
|
-
|
|
143
|
-
var r = await braid_fetch(`/${key_a}`, {
|
|
144
|
-
method: 'PUT',
|
|
145
|
-
body: 'hi'
|
|
146
|
-
})
|
|
147
|
-
if (!r.ok) return 'got: ' + r.status
|
|
148
|
-
|
|
149
|
-
var r = await braid_fetch(`/eval`, {
|
|
150
|
-
method: 'PUT',
|
|
151
|
-
body: `void (async () => {
|
|
152
|
-
braid_text.sync(new URL('http://localhost:8889/${key_a}'), '/${key_b}')
|
|
153
|
-
res.end('')
|
|
154
|
-
})()`
|
|
155
|
-
})
|
|
156
|
-
if (!r.ok) return 'got: ' + r.status
|
|
157
|
-
|
|
158
|
-
await new Promise(done => setTimeout(done, 100))
|
|
159
|
-
|
|
160
|
-
var r = await braid_fetch(`/${key_b}`)
|
|
161
|
-
return 'got: ' + (await r.text())
|
|
162
|
-
},
|
|
163
|
-
'got: hi'
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
runTest(
|
|
167
|
-
"test braid_text.sync, with two urls",
|
|
168
|
-
async () => {
|
|
169
|
-
var key_a = 'test-a-' + Math.random().toString(36).slice(2)
|
|
170
|
-
var key_b = 'test-b-' + Math.random().toString(36).slice(2)
|
|
171
|
-
|
|
172
|
-
var r = await braid_fetch(`/${key_a}`, {
|
|
173
|
-
method: 'PUT',
|
|
174
|
-
body: 'hi'
|
|
175
|
-
})
|
|
176
|
-
if (!r.ok) return 'got: ' + r.status
|
|
177
|
-
|
|
178
|
-
var r = await braid_fetch(`/eval`, {
|
|
179
|
-
method: 'PUT',
|
|
180
|
-
body: `void (async () => {
|
|
181
|
-
braid_text.sync(new URL('http://localhost:8889/${key_a}'),
|
|
182
|
-
new URL('http://localhost:8889/${key_b}'))
|
|
183
|
-
res.end('')
|
|
184
|
-
})()`
|
|
185
|
-
})
|
|
186
|
-
if (!r.ok) return 'got: ' + r.status
|
|
187
|
-
|
|
188
|
-
await new Promise(done => setTimeout(done, 100))
|
|
189
|
-
|
|
190
|
-
var r = await braid_fetch(`/${key_b}`)
|
|
191
|
-
return 'got: ' + (await r.text())
|
|
192
|
-
},
|
|
193
|
-
'got: hi'
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
runTest(
|
|
197
|
-
"test braid_text.sync, key to url",
|
|
198
|
-
async () => {
|
|
199
|
-
var key_a = 'test-a-' + Math.random().toString(36).slice(2)
|
|
200
|
-
var key_b = 'test-b-' + Math.random().toString(36).slice(2)
|
|
201
|
-
|
|
202
|
-
var r = await braid_fetch(`/${key_a}`, {
|
|
203
|
-
method: 'PUT',
|
|
204
|
-
body: 'hi'
|
|
205
|
-
})
|
|
206
|
-
if (!r.ok) return 'got: ' + r.status
|
|
207
|
-
|
|
208
|
-
var r = await braid_fetch(`/eval`, {
|
|
209
|
-
method: 'PUT',
|
|
210
|
-
body: `void (async () => {
|
|
211
|
-
braid_text.sync('/${key_a}', new URL('http://localhost:8889/${key_b}'))
|
|
212
|
-
res.end('')
|
|
213
|
-
})()`
|
|
214
|
-
})
|
|
215
|
-
if (!r.ok) return 'got: ' + r.status
|
|
216
|
-
|
|
217
|
-
await new Promise(done => setTimeout(done, 100))
|
|
218
|
-
|
|
219
|
-
var r = await braid_fetch(`/${key_b}`)
|
|
220
|
-
return 'got: ' + (await r.text())
|
|
221
|
-
},
|
|
222
|
-
'got: hi'
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
runTest(
|
|
226
|
-
"test braid_text.sync, with two keys",
|
|
227
|
-
async () => {
|
|
228
|
-
var key_a = 'test-a-' + Math.random().toString(36).slice(2)
|
|
229
|
-
var key_b = 'test-b-' + Math.random().toString(36).slice(2)
|
|
230
|
-
|
|
231
|
-
var r = await braid_fetch(`/${key_a}`, {
|
|
232
|
-
method: 'PUT',
|
|
233
|
-
body: 'hi'
|
|
234
|
-
})
|
|
235
|
-
if (!r.ok) return 'got: ' + r.status
|
|
236
|
-
|
|
237
|
-
var r = await braid_fetch(`/eval`, {
|
|
238
|
-
method: 'PUT',
|
|
239
|
-
body: `void (async () => {
|
|
240
|
-
braid_text.sync('/${key_a}', '/${key_b}')
|
|
241
|
-
res.end('')
|
|
242
|
-
})()`
|
|
243
|
-
})
|
|
244
|
-
if (!r.ok) return 'got: ' + r.status
|
|
245
|
-
|
|
246
|
-
await new Promise(done => setTimeout(done, 100))
|
|
247
|
-
|
|
248
|
-
var r = await braid_fetch(`/${key_b}`)
|
|
249
|
-
return 'got: ' + (await r.text())
|
|
250
|
-
},
|
|
251
|
-
'got: hi'
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
runTest(
|
|
255
|
-
"test putting version with multiple event ids, should have error",
|
|
256
|
-
async () => {
|
|
257
|
-
var key_a = 'test-a-' + Math.random().toString(36).slice(2)
|
|
258
|
-
|
|
259
|
-
var r = await braid_fetch(`/${key_a}`, {
|
|
260
|
-
method: 'PUT',
|
|
261
|
-
version: ['abc-1', 'xyz-2'],
|
|
262
|
-
body: 'hi'
|
|
263
|
-
})
|
|
264
|
-
return '' + (await r.text()).includes('cannot put a version with multiple ids')
|
|
265
|
-
},
|
|
266
|
-
'true'
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
runTest(
|
|
270
|
-
"test braid_text.get(url), with no options",
|
|
271
|
-
async () => {
|
|
272
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
273
|
-
let r = await braid_fetch(`/${key}`, {
|
|
274
|
-
method: 'PUT',
|
|
275
|
-
body: 'hi'
|
|
276
|
-
})
|
|
277
|
-
if (!r.ok) return 'got: ' + r.status
|
|
278
|
-
|
|
279
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
280
|
-
method: 'PUT',
|
|
281
|
-
body: `void (async () => {
|
|
282
|
-
res.end(await braid_text.get(new URL('http://localhost:8889/${key}')))
|
|
283
|
-
})()`
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
return 'got: ' + (await r1.text())
|
|
287
|
-
},
|
|
288
|
-
'got: hi'
|
|
289
|
-
)
|
|
290
|
-
|
|
291
|
-
runTest(
|
|
292
|
-
"test braid_text.get(url), with headers",
|
|
293
|
-
async () => {
|
|
294
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
295
|
-
let r = await braid_fetch(`/${key}`, {
|
|
296
|
-
method: 'PUT',
|
|
297
|
-
version: ['xyz-1'],
|
|
298
|
-
body: 'hi'
|
|
299
|
-
})
|
|
300
|
-
if (!r.ok) return 'got: ' + r.status
|
|
301
|
-
|
|
302
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
303
|
-
method: 'PUT',
|
|
304
|
-
body: `void (async () => {
|
|
305
|
-
res.end(await braid_text.get(new URL('http://localhost:8889/${key}'), {
|
|
306
|
-
headers: {
|
|
307
|
-
version: '"xyz-0"'
|
|
308
|
-
}
|
|
309
|
-
}))
|
|
310
|
-
})()`
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
return 'got: ' + (await r1.text())
|
|
314
|
-
},
|
|
315
|
-
'got: h'
|
|
316
|
-
)
|
|
317
|
-
|
|
318
|
-
runTest(
|
|
319
|
-
"test braid_text.get(url), with parents",
|
|
320
|
-
async () => {
|
|
321
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
322
|
-
let r = await braid_fetch(`/${key}`, {
|
|
323
|
-
method: 'PUT',
|
|
324
|
-
version: ['xyz-1'],
|
|
325
|
-
body: 'hi'
|
|
326
|
-
})
|
|
327
|
-
if (!r.ok) return 'got: ' + r.status
|
|
328
|
-
|
|
329
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
330
|
-
method: 'PUT',
|
|
331
|
-
body: `void (async () => {
|
|
332
|
-
res.end(await braid_text.get(new URL('http://localhost:8889/${key}'), {
|
|
333
|
-
parents: ['xyz-0']
|
|
334
|
-
}))
|
|
335
|
-
})()`
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
return 'got: ' + (await r1.text())
|
|
339
|
-
},
|
|
340
|
-
'got: h'
|
|
341
|
-
)
|
|
342
|
-
|
|
343
|
-
runTest(
|
|
344
|
-
"test braid_text.get(url), with version and peer",
|
|
345
|
-
async () => {
|
|
346
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
347
|
-
let r = await braid_fetch(`/${key}`, {
|
|
348
|
-
method: 'PUT',
|
|
349
|
-
version: ['xyz-1'],
|
|
350
|
-
body: 'hi'
|
|
351
|
-
})
|
|
352
|
-
if (!r.ok) return 'got: ' + r.status
|
|
353
|
-
|
|
354
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
355
|
-
method: 'PUT',
|
|
356
|
-
body: `void (async () => {
|
|
357
|
-
res.end(await braid_text.get(new URL('http://localhost:8889/${key}'), {
|
|
358
|
-
version: ['xyz-0'],
|
|
359
|
-
peer: 'xyz'
|
|
360
|
-
}))
|
|
361
|
-
})()`
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
return 'got: ' + (await r1.text())
|
|
365
|
-
},
|
|
366
|
-
'got: h'
|
|
367
|
-
)
|
|
368
|
-
|
|
369
|
-
runTest(
|
|
370
|
-
"test braid_text.get(url) with subscription",
|
|
371
|
-
async () => {
|
|
372
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
373
|
-
let r = await braid_fetch(`/${key}`, {
|
|
374
|
-
method: 'PUT',
|
|
375
|
-
version: ['xyz-1'],
|
|
376
|
-
body: 'hi'
|
|
377
|
-
})
|
|
378
|
-
if (!r.ok) return 'got: ' + r.status
|
|
379
|
-
|
|
380
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
381
|
-
method: 'PUT',
|
|
382
|
-
body: `void (async () => {
|
|
383
|
-
var url = new URL('http://localhost:8889/${key}')
|
|
384
|
-
var update = await new Promise(done => {
|
|
385
|
-
var o = {
|
|
386
|
-
subscribe: update => {
|
|
387
|
-
braid_text.forget(url, o)
|
|
388
|
-
done(update)
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
braid_text.get(url, o)
|
|
392
|
-
})
|
|
393
|
-
res.end(update.body)
|
|
394
|
-
})()`
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
return 'got: ' + (await r1.text())
|
|
398
|
-
},
|
|
399
|
-
'got: hi'
|
|
400
|
-
)
|
|
401
|
-
|
|
402
|
-
runTest(
|
|
403
|
-
"test braid_text.put(url), with body",
|
|
404
|
-
async () => {
|
|
405
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
406
|
-
|
|
407
|
-
var r = await braid_fetch(`/eval`, {
|
|
408
|
-
method: 'PUT',
|
|
409
|
-
body: `void (async () => {
|
|
410
|
-
var r = await braid_text.put(new URL('http://localhost:8889/${key}'),
|
|
411
|
-
{body: 'yo'})
|
|
412
|
-
res.end('')
|
|
413
|
-
})()`
|
|
414
|
-
})
|
|
415
|
-
if (!r.ok) return 'got: ' + r.status
|
|
416
|
-
|
|
417
|
-
let r1 = await braid_fetch(`/${key}`)
|
|
418
|
-
return 'got: ' + (await r1.text())
|
|
419
|
-
},
|
|
420
|
-
'got: yo'
|
|
421
|
-
)
|
|
422
|
-
|
|
423
|
-
runTest(
|
|
424
|
-
"test braid_text.put(url), with body and headers",
|
|
425
|
-
async () => {
|
|
426
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
427
|
-
|
|
428
|
-
var r = await braid_fetch(`/eval`, {
|
|
429
|
-
method: 'PUT',
|
|
430
|
-
body: `void (async () => {
|
|
431
|
-
var r = await braid_text.put(new URL('http://localhost:8889/${key}'),
|
|
432
|
-
{body: 'yo', headers: {version: '"abc123-1"'}})
|
|
433
|
-
res.end('')
|
|
434
|
-
})()`
|
|
435
|
-
})
|
|
436
|
-
if (!r.ok) return 'got: ' + r.status
|
|
437
|
-
|
|
438
|
-
let r2 = await braid_fetch(`/${key}`)
|
|
439
|
-
return 'got: ' + (await r2.text()) + ' -- version: ' + r2.headers.get('version')
|
|
440
|
-
},
|
|
441
|
-
'got: yo -- version: "abc123-1"'
|
|
442
|
-
)
|
|
443
|
-
|
|
444
|
-
runTest(
|
|
445
|
-
"test braid_text.put(url), with body and version and parents",
|
|
446
|
-
async () => {
|
|
447
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
448
|
-
let r = await braid_fetch(`/${key}`, {
|
|
449
|
-
method: 'PUT',
|
|
450
|
-
body: 'hi',
|
|
451
|
-
version: ['abc-1']
|
|
452
|
-
})
|
|
453
|
-
|
|
454
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
455
|
-
method: 'PUT',
|
|
456
|
-
body: `void (async () => {
|
|
457
|
-
var r = await braid_text.put(new URL('http://localhost:8889/${key}'),
|
|
458
|
-
{body: 'yo', version: ['xyz-3'], parents: ['abc-1']})
|
|
459
|
-
res.end('')
|
|
460
|
-
})()`
|
|
461
|
-
})
|
|
462
|
-
if (!r1.ok) return 'got: ' + r1.status
|
|
463
|
-
|
|
464
|
-
let r2 = await braid_fetch(`/${key}`)
|
|
465
|
-
return 'got: ' + (await r2.text()) + ' -- version: ' + r2.headers.get('version')
|
|
466
|
-
},
|
|
467
|
-
'got: yo -- version: "xyz-3"'
|
|
468
|
-
)
|
|
469
|
-
|
|
470
|
-
runTest(
|
|
471
|
-
"test braid_text.put(url), with peer",
|
|
472
|
-
async () => {
|
|
473
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
474
|
-
|
|
475
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
476
|
-
method: 'PUT',
|
|
477
|
-
body: `void (async () => {
|
|
478
|
-
var r = await braid_text.put(new URL('http://localhost:8889/${key}'),
|
|
479
|
-
{body: 'yo', peer: 'xyz', parents: []})
|
|
480
|
-
res.end('')
|
|
481
|
-
})()`
|
|
482
|
-
})
|
|
483
|
-
if (!r1.ok) return 'got: ' + r1.status
|
|
484
|
-
|
|
485
|
-
let r2 = await braid_fetch(`/${key}`)
|
|
486
|
-
return 'got: ' + (await r2.text()) + ' -- version: ' + r2.headers.get('version')
|
|
487
|
-
},
|
|
488
|
-
'got: yo -- version: "xyz-1"'
|
|
489
|
-
)
|
|
490
|
-
|
|
491
|
-
runTest(
|
|
492
|
-
"test updating meta data",
|
|
493
|
-
async () => {
|
|
494
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
495
|
-
|
|
496
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
497
|
-
method: 'PUT',
|
|
498
|
-
body: `void (async () => {
|
|
499
|
-
var resource = await braid_text.get_resource('/${key}')
|
|
500
|
-
resource.update_meta({ test_meta_info: 42 })
|
|
501
|
-
res.end(JSON.stringify(resource.meta))
|
|
502
|
-
})()`
|
|
503
|
-
})
|
|
504
|
-
|
|
505
|
-
return (await r1.text())
|
|
506
|
-
},
|
|
507
|
-
'{"test_meta_info":42}'
|
|
508
|
-
)
|
|
509
|
-
|
|
510
|
-
runTest(
|
|
511
|
-
"test updating meta data when do db_folder set",
|
|
512
|
-
async () => {
|
|
513
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
514
|
-
|
|
515
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
516
|
-
method: 'PUT',
|
|
517
|
-
body: `void (async () => {
|
|
518
|
-
var resource = await braid_text2.get_resource('/${key}')
|
|
519
|
-
resource.update_meta({ test_meta_info: 42 })
|
|
520
|
-
res.end(JSON.stringify(resource.meta))
|
|
521
|
-
})()`
|
|
522
|
-
})
|
|
523
|
-
|
|
524
|
-
return (await r1.text())
|
|
525
|
-
},
|
|
526
|
-
'{"test_meta_info":42}'
|
|
527
|
-
)
|
|
528
|
-
|
|
529
|
-
runTest(
|
|
530
|
-
"test loading a meta file from disk",
|
|
531
|
-
async () => {
|
|
532
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
533
|
-
|
|
534
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
535
|
-
method: 'PUT',
|
|
536
|
-
body: `void (async () => {
|
|
537
|
-
var resource = await braid_text.get_resource('/${key}')
|
|
538
|
-
resource.update_meta({ test_meta_info: 42 })
|
|
539
|
-
|
|
540
|
-
await new Promise(done => setTimeout(done, 200))
|
|
541
|
-
|
|
542
|
-
delete braid_text.cache['/${key}']
|
|
543
|
-
|
|
544
|
-
var resource = await braid_text.get_resource('/${key}')
|
|
545
|
-
res.end(JSON.stringify(resource.meta))
|
|
546
|
-
})()`
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
return (await r1.text())
|
|
550
|
-
},
|
|
551
|
-
'{"test_meta_info":42}'
|
|
552
|
-
)
|
|
553
|
-
|
|
554
|
-
runTest(
|
|
555
|
-
"test selection-sharing-prototype PUT and GET",
|
|
556
|
-
async () => {
|
|
557
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
558
|
-
|
|
559
|
-
let time = Date.now()
|
|
560
|
-
|
|
561
|
-
let r = await braid_fetch(`/${key}`, {
|
|
562
|
-
method: 'PUT',
|
|
563
|
-
body: JSON.stringify({
|
|
564
|
-
hello: {
|
|
565
|
-
yo: 'hi',
|
|
566
|
-
time
|
|
567
|
-
}
|
|
568
|
-
}),
|
|
569
|
-
headers: {
|
|
570
|
-
'selection-sharing-prototype': 'true'
|
|
571
|
-
}
|
|
572
|
-
})
|
|
573
|
-
if (!r.ok) return 'got: ' + r.status
|
|
574
|
-
|
|
575
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
576
|
-
method: 'GET',
|
|
577
|
-
headers: {
|
|
578
|
-
'selection-sharing-prototype': 'true'
|
|
579
|
-
}
|
|
580
|
-
})
|
|
581
|
-
if (!r2.ok) return 'got: ' + r2.status
|
|
582
|
-
|
|
583
|
-
let o = await r2.json()
|
|
584
|
-
return o.hello.time === time ? 'times match' : 'bad'
|
|
585
|
-
},
|
|
586
|
-
'times match'
|
|
587
|
-
)
|
|
588
|
-
|
|
589
|
-
runTest(
|
|
590
|
-
"test selection-sharing-prototype GET/subscribe",
|
|
591
|
-
async () => {
|
|
592
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
593
|
-
|
|
594
|
-
var a = new AbortController()
|
|
595
|
-
let r = await braid_fetch(`/${key}`, {
|
|
596
|
-
method: 'GET',
|
|
597
|
-
signal: a.signal,
|
|
598
|
-
subscribe: true,
|
|
599
|
-
peer: 'abc',
|
|
600
|
-
headers: {
|
|
601
|
-
'selection-sharing-prototype': 'true'
|
|
602
|
-
}
|
|
603
|
-
})
|
|
604
|
-
if (!r.ok) return 'got: ' + r.status
|
|
605
|
-
var p = new Promise(done => {
|
|
606
|
-
r.subscribe(update => {
|
|
607
|
-
var body = update.body_text
|
|
608
|
-
if (body.length > 2) done(body)
|
|
609
|
-
})
|
|
610
|
-
})
|
|
611
|
-
|
|
612
|
-
var time = Date.now()
|
|
613
|
-
|
|
614
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
615
|
-
method: 'PUT',
|
|
616
|
-
peer: 'xyz',
|
|
617
|
-
body: JSON.stringify({
|
|
618
|
-
hello: {
|
|
619
|
-
yo: 'hi',
|
|
620
|
-
time
|
|
621
|
-
}
|
|
622
|
-
}),
|
|
623
|
-
headers: {
|
|
624
|
-
'selection-sharing-prototype': 'true'
|
|
625
|
-
}
|
|
626
|
-
})
|
|
627
|
-
if (!r2.ok) return 'got: ' + r2.status
|
|
628
|
-
|
|
629
|
-
var ret_val = JSON.parse(await p).hello.time === time ? 'times match' : 'bad'
|
|
630
|
-
|
|
631
|
-
a.abort()
|
|
632
|
-
|
|
633
|
-
return ret_val
|
|
634
|
-
},
|
|
635
|
-
'times match'
|
|
636
|
-
)
|
|
637
|
-
|
|
638
|
-
runTest(
|
|
639
|
-
"test selection-sharing-prototype PUT old cursor",
|
|
640
|
-
async () => {
|
|
641
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
642
|
-
|
|
643
|
-
let time = Date.now()
|
|
644
|
-
|
|
645
|
-
let r = await braid_fetch(`/${key}`, {
|
|
646
|
-
method: 'PUT',
|
|
647
|
-
body: JSON.stringify({
|
|
648
|
-
hello: {
|
|
649
|
-
yo: 'hi',
|
|
650
|
-
time
|
|
651
|
-
}
|
|
652
|
-
}),
|
|
653
|
-
headers: {
|
|
654
|
-
'selection-sharing-prototype': 'true'
|
|
655
|
-
}
|
|
656
|
-
})
|
|
657
|
-
if (!r.ok) return 'got: ' + r.status
|
|
658
|
-
|
|
659
|
-
let r3 = await braid_fetch(`/${key}`, {
|
|
660
|
-
method: 'PUT',
|
|
661
|
-
body: JSON.stringify({
|
|
662
|
-
hello: {
|
|
663
|
-
yo: 'hoop',
|
|
664
|
-
time: time - 5
|
|
665
|
-
}
|
|
666
|
-
}),
|
|
667
|
-
headers: {
|
|
668
|
-
'selection-sharing-prototype': 'true'
|
|
669
|
-
}
|
|
670
|
-
})
|
|
671
|
-
if (!r3.ok) return 'got: ' + r3.status
|
|
672
|
-
|
|
673
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
674
|
-
method: 'GET',
|
|
675
|
-
headers: {
|
|
676
|
-
'selection-sharing-prototype': 'true'
|
|
677
|
-
}
|
|
678
|
-
})
|
|
679
|
-
if (!r2.ok) return 'got: ' + r2.status
|
|
680
|
-
|
|
681
|
-
let o = await r2.json()
|
|
682
|
-
return o.hello.yo
|
|
683
|
-
},
|
|
684
|
-
'hi'
|
|
685
|
-
)
|
|
686
|
-
|
|
687
|
-
runTest(
|
|
688
|
-
"test selection-sharing-prototype PUT really old cursor",
|
|
689
|
-
async () => {
|
|
690
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
691
|
-
|
|
692
|
-
let time = Date.now() - 1000 * 60 * 60 * 24
|
|
693
|
-
|
|
694
|
-
let r = await braid_fetch(`/${key}`, {
|
|
695
|
-
method: 'PUT',
|
|
696
|
-
body: JSON.stringify({
|
|
697
|
-
hello: {
|
|
698
|
-
yo: 'hi',
|
|
699
|
-
time
|
|
700
|
-
}
|
|
701
|
-
}),
|
|
702
|
-
headers: {
|
|
703
|
-
'selection-sharing-prototype': 'true'
|
|
704
|
-
}
|
|
705
|
-
})
|
|
706
|
-
if (!r.ok) return 'got: ' + r.status
|
|
707
|
-
|
|
708
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
709
|
-
method: 'GET',
|
|
710
|
-
headers: {
|
|
711
|
-
'selection-sharing-prototype': 'true'
|
|
712
|
-
}
|
|
713
|
-
})
|
|
714
|
-
if (!r2.ok) return 'got: ' + r2.status
|
|
715
|
-
|
|
716
|
-
let o = await r2.json()
|
|
717
|
-
return JSON.stringify(o)
|
|
718
|
-
},
|
|
719
|
-
'{}'
|
|
720
|
-
)
|
|
721
|
-
|
|
722
|
-
runTest(
|
|
723
|
-
"test PUT digest (good)",
|
|
724
|
-
async () => {
|
|
725
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
726
|
-
|
|
727
|
-
async function get_digest(s) {
|
|
728
|
-
var bytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s))
|
|
729
|
-
return `sha-256=:${btoa(String.fromCharCode(...new Uint8Array(bytes)))}:`
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
let r = await braid_fetch(`/${key}`, {
|
|
733
|
-
method: 'PUT',
|
|
734
|
-
version: ['hi-1'],
|
|
735
|
-
parents: [],
|
|
736
|
-
body: 'xx',
|
|
737
|
-
headers: {
|
|
738
|
-
'Repr-Digest': await get_digest('xx')
|
|
739
|
-
}
|
|
740
|
-
})
|
|
741
|
-
if (!r.ok) return 'got: ' + r.status
|
|
742
|
-
return 'ok'
|
|
743
|
-
},
|
|
744
|
-
'ok'
|
|
745
|
-
)
|
|
746
|
-
|
|
747
|
-
runTest(
|
|
748
|
-
"test PUT digest (bad)",
|
|
749
|
-
async () => {
|
|
750
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
751
|
-
|
|
752
|
-
async function get_digest(s) {
|
|
753
|
-
var bytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s))
|
|
754
|
-
return `sha-256=:${btoa(String.fromCharCode(...new Uint8Array(bytes)))}:`
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
let r = await braid_fetch(`/${key}`, {
|
|
758
|
-
method: 'PUT',
|
|
759
|
-
version: ['hi-1'],
|
|
760
|
-
parents: [],
|
|
761
|
-
body: 'xx',
|
|
762
|
-
headers: {
|
|
763
|
-
'Repr-Digest': await get_digest('yy')
|
|
764
|
-
}
|
|
765
|
-
})
|
|
766
|
-
if (!r.ok) return 'got: ' + r.status
|
|
767
|
-
return 'ok'
|
|
768
|
-
},
|
|
769
|
-
'got: 550'
|
|
770
|
-
)
|
|
771
|
-
|
|
772
|
-
runTest(
|
|
773
|
-
"test subscribing and verifying digests [simpleton]",
|
|
774
|
-
async () => {
|
|
775
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
776
|
-
|
|
777
|
-
let r = await braid_fetch(`/${key}`, {
|
|
778
|
-
method: 'PUT',
|
|
779
|
-
version: ['hi-1'],
|
|
780
|
-
parents: [],
|
|
781
|
-
body: 'xx'
|
|
782
|
-
})
|
|
783
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
784
|
-
|
|
785
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
786
|
-
version: ['hi-0'],
|
|
787
|
-
subscribe: true
|
|
788
|
-
})
|
|
789
|
-
var parts = []
|
|
790
|
-
var p = new Promise(async (done, fail) => {
|
|
791
|
-
r2.subscribe(update => {
|
|
792
|
-
parts.push(update.extra_headers['repr-digest'])
|
|
793
|
-
if (parts.length > 1) done()
|
|
794
|
-
}, fail)
|
|
795
|
-
})
|
|
796
|
-
|
|
797
|
-
await new Promise(done => setTimeout(done, 300))
|
|
798
|
-
let rr = await braid_fetch(`/${key}`, {
|
|
799
|
-
method: 'PUT',
|
|
800
|
-
version: ['hi-2'],
|
|
801
|
-
parents: ['hi-1'],
|
|
802
|
-
patches: [{unit: "text", range: "[1:1]", content: "Y"}]
|
|
803
|
-
})
|
|
804
|
-
if (!rr.ok) throw 'got: ' + rr.statusCode
|
|
805
|
-
|
|
806
|
-
await p
|
|
807
|
-
return JSON.stringify(parts)
|
|
808
|
-
},
|
|
809
|
-
'["sha-256=:Xd6JaIf2dUybFb/jpEGuSAbfL96UABMR4IvxEGIuC74=:","sha-256=:77cl3INcGEtczN0zK3eOgW/YWYAOm8ub73LkVcF2/rA=:"]'
|
|
810
|
-
)
|
|
811
|
-
|
|
812
|
-
runTest(
|
|
813
|
-
"test subscribing and verifying digests [dt]",
|
|
814
|
-
async () => {
|
|
815
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
816
|
-
|
|
817
|
-
let r = await braid_fetch(`/${key}`, {
|
|
818
|
-
method: 'PUT',
|
|
819
|
-
version: ['hi-1'],
|
|
820
|
-
parents: [],
|
|
821
|
-
body: 'xx'
|
|
822
|
-
})
|
|
823
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
824
|
-
|
|
825
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
826
|
-
version: ['hi-0'],
|
|
827
|
-
headers: { 'merge-type': 'dt' },
|
|
828
|
-
subscribe: true
|
|
829
|
-
})
|
|
830
|
-
var parts = []
|
|
831
|
-
var p = new Promise(async (done, fail) => {
|
|
832
|
-
r2.subscribe(update => {
|
|
833
|
-
parts.push(update.extra_headers['repr-digest'])
|
|
834
|
-
if (parts.length > 1) done()
|
|
835
|
-
}, fail)
|
|
836
|
-
})
|
|
837
|
-
|
|
838
|
-
await new Promise(done => setTimeout(done, 300))
|
|
839
|
-
let rr = await braid_fetch(`/${key}`, {
|
|
840
|
-
method: 'PUT',
|
|
841
|
-
version: ['hi-2'],
|
|
842
|
-
parents: ['hi-1'],
|
|
843
|
-
patches: [{unit: "text", range: "[2:2]", content: "Y"}]
|
|
844
|
-
})
|
|
845
|
-
if (!rr.ok) throw 'got: ' + rr.statusCode
|
|
846
|
-
|
|
847
|
-
await p
|
|
848
|
-
return JSON.stringify(parts)
|
|
849
|
-
},
|
|
850
|
-
'["sha-256=:Xd6JaIf2dUybFb/jpEGuSAbfL96UABMR4IvxEGIuC74=:","sha-256=:QknHazou37wCCwv3JXnCoAvXcKszP6xBTxLIiUAETgI=:"]'
|
|
851
|
-
)
|
|
852
|
-
|
|
853
|
-
runTest(
|
|
854
|
-
"test PUTing a version that the server already has",
|
|
855
|
-
async () => {
|
|
856
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
857
|
-
|
|
858
|
-
var r1 = await braid_fetch(`/${key}`, {
|
|
859
|
-
method: 'PUT',
|
|
860
|
-
version: ['hi-0'],
|
|
861
|
-
parents: [],
|
|
862
|
-
body: 'x'
|
|
863
|
-
})
|
|
864
|
-
|
|
865
|
-
var r2 = await braid_fetch(`/${key}`, {
|
|
866
|
-
method: 'PUT',
|
|
867
|
-
version: ['hi-0'],
|
|
868
|
-
parents: [],
|
|
869
|
-
body: 'x'
|
|
870
|
-
})
|
|
871
|
-
|
|
872
|
-
return r1.status + " " + r2.status
|
|
873
|
-
},
|
|
874
|
-
'200 200'
|
|
875
|
-
)
|
|
876
|
-
|
|
877
|
-
runTest(
|
|
878
|
-
"test validate_already_seen_versions with same version",
|
|
879
|
-
async () => {
|
|
880
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
881
|
-
|
|
882
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
883
|
-
method: 'PUT',
|
|
884
|
-
body: `void (async () => {
|
|
885
|
-
var resource = await braid_text.get_resource('/${key}')
|
|
886
|
-
|
|
887
|
-
var {change_count} = await braid_text.put(resource, { peer: "abc", version: ["hi-2"], parents: [], patches: [{unit: "text", range: "[0:0]", content: "XYZ"}], merge_type: "dt" })
|
|
888
|
-
|
|
889
|
-
res.end('' + change_count)
|
|
890
|
-
})()`
|
|
891
|
-
})
|
|
892
|
-
|
|
893
|
-
var r2 = await braid_fetch(`/eval`, {
|
|
894
|
-
method: 'PUT',
|
|
895
|
-
body: `void (async () => {
|
|
896
|
-
var resource = await braid_text.get_resource('/${key}')
|
|
897
|
-
|
|
898
|
-
var {change_count} = await braid_text.put(resource, { peer: "abc", version: ["hi-2"], parents: [], patches: [{unit: "text", range: "[0:0]", content: "XYZ"}], merge_type: "dt", validate_already_seen_versions: true })
|
|
899
|
-
|
|
900
|
-
res.end('' + change_count)
|
|
901
|
-
})()`
|
|
902
|
-
})
|
|
903
|
-
|
|
904
|
-
return (await r1.text()) + " " + (await r2.text())
|
|
905
|
-
},
|
|
906
|
-
'3 3'
|
|
907
|
-
)
|
|
908
|
-
|
|
909
|
-
runTest(
|
|
910
|
-
"test validate_already_seen_versions with modified version",
|
|
911
|
-
async () => {
|
|
912
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
913
|
-
|
|
914
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
915
|
-
method: 'PUT',
|
|
916
|
-
body: `void (async () => {
|
|
917
|
-
var resource = await braid_text.get_resource('/${key}')
|
|
918
|
-
|
|
919
|
-
var {change_count} = await braid_text.put(resource, { peer: "abc", version: ["hi-2"], parents: [], patches: [{unit: "text", range: "[0:0]", content: "XYZ"}], merge_type: "dt" })
|
|
920
|
-
|
|
921
|
-
res.end('' + change_count)
|
|
922
|
-
})()`
|
|
923
|
-
})
|
|
924
|
-
|
|
925
|
-
var r2 = await braid_fetch(`/eval`, {
|
|
926
|
-
method: 'PUT',
|
|
927
|
-
body: `void (async () => {
|
|
928
|
-
var resource = await braid_text.get_resource('/${key}')
|
|
929
|
-
|
|
930
|
-
try {
|
|
931
|
-
var {change_count} = await braid_text.put(resource, { peer: "abc", version: ["hi-2"], parents: [], patches: [{unit: "text", range: "[0:0]", content: "ABC"}], merge_type: "dt", validate_already_seen_versions: true })
|
|
932
|
-
|
|
933
|
-
res.end('' + change_count)
|
|
934
|
-
} catch (e) {
|
|
935
|
-
res.end(e.message)
|
|
936
|
-
}
|
|
937
|
-
})()`
|
|
938
|
-
})
|
|
939
|
-
|
|
940
|
-
return await r2.text()
|
|
941
|
-
},
|
|
942
|
-
'invalid update: different from previous update with same version'
|
|
943
|
-
)
|
|
944
|
-
|
|
945
|
-
runTest(
|
|
946
|
-
"test loading a previously saved resource",
|
|
947
|
-
async () => {
|
|
948
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
949
|
-
|
|
950
|
-
var f1 = await braid_fetch(`/${key}`, {
|
|
951
|
-
method: 'PUT',
|
|
952
|
-
version: ['hi-2'],
|
|
953
|
-
parents: [],
|
|
954
|
-
body: 'abc'
|
|
955
|
-
})
|
|
956
|
-
|
|
957
|
-
var f1 = await braid_fetch(`/eval`, {
|
|
958
|
-
method: 'PUT',
|
|
959
|
-
body: `
|
|
960
|
-
delete braid_text.cache['/${key}']
|
|
961
|
-
res.end()
|
|
962
|
-
`
|
|
963
|
-
})
|
|
964
|
-
|
|
965
|
-
var r = await braid_fetch(`/${key}`)
|
|
966
|
-
return await r.text()
|
|
967
|
-
},
|
|
968
|
-
'abc'
|
|
969
|
-
)
|
|
970
|
-
|
|
971
|
-
runTest(
|
|
972
|
-
"test non-contigous ids",
|
|
973
|
-
async () => {
|
|
974
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
975
|
-
|
|
976
|
-
var r = await braid_fetch(`/${key}`, {
|
|
977
|
-
method: 'PUT',
|
|
978
|
-
version: ['hi-10'],
|
|
979
|
-
parents: [],
|
|
980
|
-
body: 'abc'
|
|
981
|
-
})
|
|
982
|
-
|
|
983
|
-
var r = await braid_fetch(`/${key}`, {
|
|
984
|
-
method: 'PUT',
|
|
985
|
-
version: ['hi-20'],
|
|
986
|
-
parents: ['hi-10'],
|
|
987
|
-
body: 'ABC'
|
|
988
|
-
})
|
|
989
|
-
|
|
990
|
-
var f1 = await braid_fetch(`/eval`, {
|
|
991
|
-
method: 'PUT',
|
|
992
|
-
body: `
|
|
993
|
-
delete braid_text.cache['/${key}']
|
|
994
|
-
res.end()
|
|
995
|
-
`
|
|
996
|
-
})
|
|
997
|
-
|
|
998
|
-
var r = await braid_fetch(`/${key}`)
|
|
999
|
-
return await r.text()
|
|
1000
|
-
},
|
|
1001
|
-
'ABC'
|
|
1002
|
-
)
|
|
1003
|
-
|
|
1004
|
-
runTest(
|
|
1005
|
-
"test when PUT cache/buffer size fails",
|
|
1006
|
-
async () => {
|
|
1007
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1008
|
-
|
|
1009
|
-
var f1 = braid_fetch(`/${key}`, {
|
|
1010
|
-
method: 'PUT',
|
|
1011
|
-
version: ['hi-3000000'],
|
|
1012
|
-
parents: ['yo-0'],
|
|
1013
|
-
body: 'A'.repeat(3000000)
|
|
1014
|
-
})
|
|
1015
|
-
|
|
1016
|
-
await new Promise(done => setTimeout(done, 300))
|
|
1017
|
-
|
|
1018
|
-
var f2 = braid_fetch(`/${key}`, {
|
|
1019
|
-
method: 'PUT',
|
|
1020
|
-
version: ['ih-3000000'],
|
|
1021
|
-
parents: ['yo-0'],
|
|
1022
|
-
body: 'B'.repeat(3000000)
|
|
1023
|
-
})
|
|
1024
|
-
|
|
1025
|
-
await new Promise(done => setTimeout(done, 300))
|
|
1026
|
-
|
|
1027
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1028
|
-
method: 'PUT',
|
|
1029
|
-
version: ['yo-0'],
|
|
1030
|
-
parents: [],
|
|
1031
|
-
body: 'x'
|
|
1032
|
-
})
|
|
1033
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1034
|
-
|
|
1035
|
-
return `f1: ${(await f1).status}, f2: ${(await f2).status}`
|
|
1036
|
-
},
|
|
1037
|
-
'f1: 200, f2: 309'
|
|
1038
|
-
)
|
|
1039
|
-
|
|
1040
|
-
runTest(
|
|
1041
|
-
"test multiple patches",
|
|
1042
|
-
async () => {
|
|
1043
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1044
|
-
|
|
1045
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1046
|
-
method: 'PUT',
|
|
1047
|
-
version: ['hi-0'],
|
|
1048
|
-
parents: [],
|
|
1049
|
-
body: 'A'
|
|
1050
|
-
})
|
|
1051
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1052
|
-
|
|
1053
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1054
|
-
method: 'PUT',
|
|
1055
|
-
version: ['yo-1'],
|
|
1056
|
-
parents: ['hi-0'],
|
|
1057
|
-
patches: [
|
|
1058
|
-
{unit: 'text', range: '[0:0]', content: 'C'},
|
|
1059
|
-
{unit: 'text', range: '[1:1]', content: 'T'}
|
|
1060
|
-
]
|
|
1061
|
-
})
|
|
1062
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1063
|
-
|
|
1064
|
-
var r2 = await braid_fetch(`/${key}`)
|
|
1065
|
-
return await r2.text()
|
|
1066
|
-
},
|
|
1067
|
-
'CAT'
|
|
1068
|
-
)
|
|
1069
|
-
|
|
1070
|
-
runTest(
|
|
1071
|
-
"test PUT after subscribing",
|
|
1072
|
-
async () => {
|
|
1073
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1074
|
-
|
|
1075
|
-
var p_done
|
|
1076
|
-
var p = new Promise(done => p_done = done)
|
|
1077
|
-
|
|
1078
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1079
|
-
subscribe: true
|
|
1080
|
-
})
|
|
1081
|
-
r.subscribe(update => {
|
|
1082
|
-
if (update.version[0] === 'hi-0')
|
|
1083
|
-
p_done(update.patches[0].content_text)
|
|
1084
|
-
})
|
|
1085
|
-
|
|
1086
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1087
|
-
method: 'PUT',
|
|
1088
|
-
version: ['hi-0'],
|
|
1089
|
-
parents: [],
|
|
1090
|
-
body: 'x'
|
|
1091
|
-
})
|
|
1092
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1093
|
-
|
|
1094
|
-
return await p
|
|
1095
|
-
},
|
|
1096
|
-
'x'
|
|
1097
|
-
)
|
|
1098
|
-
|
|
1099
|
-
runTest(
|
|
1100
|
-
"test out-of-order PUTs",
|
|
1101
|
-
async () => {
|
|
1102
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1103
|
-
|
|
1104
|
-
var f = braid_fetch(`/${key}`, {
|
|
1105
|
-
method: 'PUT',
|
|
1106
|
-
version: ['hi-1'],
|
|
1107
|
-
parents: ['hi-0'],
|
|
1108
|
-
patches: [{unit: 'text', range: '[1:1]', content: 'y'}]
|
|
1109
|
-
})
|
|
1110
|
-
|
|
1111
|
-
await new Promise(done => setTimeout(done, 500))
|
|
1112
|
-
|
|
1113
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1114
|
-
method: 'PUT',
|
|
1115
|
-
version: ['hi-0'],
|
|
1116
|
-
parents: [],
|
|
1117
|
-
body: 'x'
|
|
1118
|
-
})
|
|
1119
|
-
|
|
1120
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1121
|
-
|
|
1122
|
-
r = await f
|
|
1123
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1124
|
-
|
|
1125
|
-
var r2 = await braid_fetch(`/${key}`)
|
|
1126
|
-
return await r2.text()
|
|
1127
|
-
},
|
|
1128
|
-
'xy'
|
|
1129
|
-
)
|
|
1130
|
-
|
|
1131
|
-
runTest(
|
|
1132
|
-
"test out-of-order PUTs (trial two)",
|
|
1133
|
-
async () => {
|
|
1134
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1135
|
-
|
|
1136
|
-
var f = braid_fetch(`/${key}`, {
|
|
1137
|
-
method: 'PUT',
|
|
1138
|
-
version: ['ab-1'],
|
|
1139
|
-
parents: ['hi-0'],
|
|
1140
|
-
patches: [{unit: 'text', range: '[1:1]', content: 'y'}]
|
|
1141
|
-
})
|
|
1142
|
-
|
|
1143
|
-
await new Promise(done => setTimeout(done, 500))
|
|
1144
|
-
|
|
1145
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1146
|
-
method: 'PUT',
|
|
1147
|
-
version: ['hi-1'],
|
|
1148
|
-
parents: [],
|
|
1149
|
-
body: 'xz'
|
|
1150
|
-
})
|
|
1151
|
-
|
|
1152
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1153
|
-
|
|
1154
|
-
r = await f
|
|
1155
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1156
|
-
|
|
1157
|
-
var r2 = await braid_fetch(`/${key}`)
|
|
1158
|
-
return await r2.text()
|
|
1159
|
-
},
|
|
1160
|
-
'xyz'
|
|
1161
|
-
)
|
|
1162
|
-
|
|
1163
|
-
runTest(
|
|
1164
|
-
"test in-order PUTs",
|
|
1165
|
-
async () => {
|
|
1166
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1167
|
-
|
|
1168
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1169
|
-
method: 'PUT',
|
|
1170
|
-
version: ['hi-0'],
|
|
1171
|
-
parents: [],
|
|
1172
|
-
body: 'x'
|
|
1173
|
-
})
|
|
1174
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1175
|
-
|
|
1176
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1177
|
-
method: 'PUT',
|
|
1178
|
-
version: ['hi-1'],
|
|
1179
|
-
parents: ['hi-0'],
|
|
1180
|
-
patches: [{unit: 'text', range: '[1:1]', content: 'y'}]
|
|
1181
|
-
})
|
|
1182
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1183
|
-
|
|
1184
|
-
var r2 = await braid_fetch(`/${key}`)
|
|
1185
|
-
return await r2.text()
|
|
1186
|
-
},
|
|
1187
|
-
'xy'
|
|
1188
|
-
)
|
|
1189
|
-
|
|
1190
|
-
runTest(
|
|
1191
|
-
"test put with transfer-encoding: dt",
|
|
1192
|
-
async () => {
|
|
1193
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1194
|
-
var doc = new Doc('hi')
|
|
1195
|
-
doc.ins(0, 'xy')
|
|
1196
|
-
|
|
1197
|
-
var bytes = doc.toBytes()
|
|
1198
|
-
|
|
1199
|
-
var r1 = await braid_fetch(`/eval`, {
|
|
1200
|
-
method: 'PUT',
|
|
1201
|
-
body: `void (async () => {
|
|
1202
|
-
var key = '/${key}'
|
|
1203
|
-
|
|
1204
|
-
var {change_count} = await braid_text.put(key, {
|
|
1205
|
-
body: new Uint8Array([${'' + bytes}]),
|
|
1206
|
-
transfer_encoding: "dt"
|
|
1207
|
-
})
|
|
1208
|
-
var {body, version} = await braid_text.get(key, {})
|
|
1209
|
-
|
|
1210
|
-
res.end('' + change_count + " " + body + " " + version)
|
|
1211
|
-
})()`
|
|
1212
|
-
})
|
|
1213
|
-
|
|
1214
|
-
return await r1.text()
|
|
1215
|
-
},
|
|
1216
|
-
'2 xy hi-1'
|
|
1217
|
-
)
|
|
1218
|
-
|
|
1219
|
-
runTest(
|
|
1220
|
-
"test transfer-encoding dt (with parents)",
|
|
1221
|
-
async () => {
|
|
1222
|
-
await dt_p
|
|
1223
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1224
|
-
var doc = new Doc('hi')
|
|
1225
|
-
doc.ins(0, 'x')
|
|
1226
|
-
|
|
1227
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1228
|
-
method: 'PUT',
|
|
1229
|
-
version: ['hi-1'],
|
|
1230
|
-
parents: [],
|
|
1231
|
-
body: 'xy'
|
|
1232
|
-
})
|
|
1233
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1234
|
-
|
|
1235
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1236
|
-
parents: ['hi-0'],
|
|
1237
|
-
headers: {
|
|
1238
|
-
'Accept-Transfer-Encoding': 'dt'
|
|
1239
|
-
}
|
|
1240
|
-
})
|
|
1241
|
-
|
|
1242
|
-
doc.mergeBytes([...new Uint8Array(await r2.arrayBuffer())])
|
|
1243
|
-
var text = doc.get()
|
|
1244
|
-
doc.free()
|
|
1245
|
-
|
|
1246
|
-
return r2.headers.get('current-version') + ' ' + r2.headers.get('x-transfer-encoding') + ' ' + text + ' ' + r2.statusText
|
|
1247
|
-
},
|
|
1248
|
-
'"hi-1" dt xy Multiresponse'
|
|
1249
|
-
)
|
|
1250
|
-
|
|
1251
|
-
runTest(
|
|
1252
|
-
"test transfer-encoding dt",
|
|
1253
|
-
async () => {
|
|
1254
|
-
await dt_p
|
|
1255
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1256
|
-
|
|
1257
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1258
|
-
method: 'PUT',
|
|
1259
|
-
version: ['hi-1'],
|
|
1260
|
-
parents: [],
|
|
1261
|
-
body: 'xy'
|
|
1262
|
-
})
|
|
1263
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1264
|
-
|
|
1265
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1266
|
-
headers: {
|
|
1267
|
-
'Accept-Transfer-Encoding': 'dt'
|
|
1268
|
-
}
|
|
1269
|
-
})
|
|
1270
|
-
|
|
1271
|
-
var doc = new Doc('yo')
|
|
1272
|
-
doc.mergeBytes([...new Uint8Array(await r2.arrayBuffer())])
|
|
1273
|
-
var text = doc.get()
|
|
1274
|
-
doc.free()
|
|
1275
|
-
|
|
1276
|
-
return r2.headers.get('current-version') + ' ' + r2.headers.get('x-transfer-encoding') + ' ' + text
|
|
1277
|
-
},
|
|
1278
|
-
'"hi-1" dt xy'
|
|
1279
|
-
)
|
|
1280
|
-
|
|
1281
|
-
runTest(
|
|
1282
|
-
"test GETing old version explicitly with transfer-encoding dt",
|
|
1283
|
-
async () => {
|
|
1284
|
-
await dt_p
|
|
1285
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1286
|
-
|
|
1287
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1288
|
-
method: 'PUT',
|
|
1289
|
-
version: ['hi∑-1'],
|
|
1290
|
-
parents: [],
|
|
1291
|
-
body: 'xy'
|
|
1292
|
-
})
|
|
1293
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1294
|
-
|
|
1295
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1296
|
-
version: ['hi∑-0'],
|
|
1297
|
-
headers: {
|
|
1298
|
-
'Accept-Transfer-Encoding': 'dt'
|
|
1299
|
-
}
|
|
1300
|
-
})
|
|
1301
|
-
|
|
1302
|
-
var doc = new Doc('yo')
|
|
1303
|
-
doc.mergeBytes([...new Uint8Array(await r2.arrayBuffer())])
|
|
1304
|
-
var text = doc.get()
|
|
1305
|
-
doc.free()
|
|
1306
|
-
|
|
1307
|
-
return r2.headers.get('current-version') + ' ' + text + ' ' + JSON.parse(r2.headers.get('current-version'))
|
|
1308
|
-
},
|
|
1309
|
-
'"hi\\u2211-1" x hi∑-1'
|
|
1310
|
-
)
|
|
1311
|
-
|
|
1312
|
-
runTest(
|
|
1313
|
-
"test GETing current version explicitly with transfer-encoding dt",
|
|
1314
|
-
async () => {
|
|
1315
|
-
await dt_p
|
|
1316
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1317
|
-
|
|
1318
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1319
|
-
method: 'PUT',
|
|
1320
|
-
version: ['hi∑-1'],
|
|
1321
|
-
parents: [],
|
|
1322
|
-
body: 'xy'
|
|
1323
|
-
})
|
|
1324
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1325
|
-
|
|
1326
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1327
|
-
version: ['hi∑-1'],
|
|
1328
|
-
headers: {
|
|
1329
|
-
'Accept-Transfer-Encoding': 'dt'
|
|
1330
|
-
}
|
|
1331
|
-
})
|
|
1332
|
-
|
|
1333
|
-
var doc = new Doc('yo')
|
|
1334
|
-
doc.mergeBytes([...new Uint8Array(await r2.arrayBuffer())])
|
|
1335
|
-
var text = doc.get()
|
|
1336
|
-
doc.free()
|
|
1337
|
-
|
|
1338
|
-
return r2.headers.get('current-version') + ' ' + text + ' ' + JSON.parse(r2.headers.get('current-version'))
|
|
1339
|
-
},
|
|
1340
|
-
'"hi\\u2211-1" xy hi∑-1'
|
|
1341
|
-
)
|
|
1342
|
-
|
|
1343
|
-
runTest(
|
|
1344
|
-
"test for Current-Version when GETing old version",
|
|
1345
|
-
async () => {
|
|
1346
|
-
await dt_p
|
|
1347
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1348
|
-
|
|
1349
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1350
|
-
method: 'PUT',
|
|
1351
|
-
version: ['hi∑-1'],
|
|
1352
|
-
parents: [],
|
|
1353
|
-
body: 'xy'
|
|
1354
|
-
})
|
|
1355
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1356
|
-
|
|
1357
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1358
|
-
version: ['hi∑-0']
|
|
1359
|
-
})
|
|
1360
|
-
|
|
1361
|
-
var text = await r2.text()
|
|
1362
|
-
|
|
1363
|
-
return r2.headers.get('current-version') + ' ' + r2.headers.get('version') + ' ' + text + ' ' + JSON.parse(r2.headers.get('current-version'))
|
|
1364
|
-
},
|
|
1365
|
-
'"hi\\u2211-1" "hi\\u2211-0" x hi∑-1'
|
|
1366
|
-
)
|
|
1367
|
-
|
|
1368
|
-
runTest(
|
|
1369
|
-
"test HEAD for GET without subscribe",
|
|
1370
|
-
async () => {
|
|
1371
|
-
await dt_p
|
|
1372
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1373
|
-
|
|
1374
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1375
|
-
method: 'PUT',
|
|
1376
|
-
version: ['hi∑-1'],
|
|
1377
|
-
parents: [],
|
|
1378
|
-
body: 'xy'
|
|
1379
|
-
})
|
|
1380
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1381
|
-
|
|
1382
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1383
|
-
method: 'HEAD'
|
|
1384
|
-
})
|
|
1385
|
-
|
|
1386
|
-
var text = await r2.text()
|
|
1387
|
-
|
|
1388
|
-
return r2.headers.get('version') + ' ' + JSON.parse(r2.headers.get('version')) + ` text:[${text}]`
|
|
1389
|
-
},
|
|
1390
|
-
'"hi\\u2211-1" hi∑-1 text:[]'
|
|
1391
|
-
)
|
|
1392
|
-
|
|
1393
|
-
runTest(
|
|
1394
|
-
"test HEAD for GET without subscribe (with transfer-encoding)",
|
|
1395
|
-
async () => {
|
|
1396
|
-
await dt_p
|
|
1397
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1398
|
-
|
|
1399
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1400
|
-
method: 'PUT',
|
|
1401
|
-
version: ['hi∑-1'],
|
|
1402
|
-
parents: [],
|
|
1403
|
-
body: 'xy'
|
|
1404
|
-
})
|
|
1405
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1406
|
-
|
|
1407
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1408
|
-
method: 'HEAD',
|
|
1409
|
-
headers: {
|
|
1410
|
-
'accept-transfer-encoding': 'dt'
|
|
1411
|
-
}
|
|
1412
|
-
})
|
|
1413
|
-
|
|
1414
|
-
var buf = await r2.arrayBuffer()
|
|
1415
|
-
|
|
1416
|
-
return r2.headers.get('current-version') + ' ' + JSON.parse(r2.headers.get('current-version')) + ` buf.byteLength:${buf.byteLength}`
|
|
1417
|
-
},
|
|
1418
|
-
'"hi\\u2211-1" hi∑-1 buf.byteLength:0'
|
|
1419
|
-
)
|
|
1420
|
-
|
|
1421
|
-
runTest(
|
|
1422
|
-
"test accept-encoding updates(dt) (with parents)",
|
|
1423
|
-
async () => {
|
|
1424
|
-
await dt_p
|
|
1425
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1426
|
-
var doc = new Doc('hi')
|
|
1427
|
-
doc.ins(0, 'x')
|
|
1428
|
-
|
|
1429
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1430
|
-
method: 'PUT',
|
|
1431
|
-
version: ['hi-1'],
|
|
1432
|
-
parents: [],
|
|
1433
|
-
body: 'xy'
|
|
1434
|
-
})
|
|
1435
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1436
|
-
|
|
1437
|
-
var a = new AbortController()
|
|
1438
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1439
|
-
signal: a.signal,
|
|
1440
|
-
parents: ['hi-0'],
|
|
1441
|
-
subscribe: true,
|
|
1442
|
-
headers: {
|
|
1443
|
-
'merge-type': 'dt',
|
|
1444
|
-
'X-Accept-Encoding': 'updates(dt)'
|
|
1445
|
-
}
|
|
1446
|
-
})
|
|
1447
|
-
|
|
1448
|
-
return await new Promise(done => {
|
|
1449
|
-
r2.subscribe(u => {
|
|
1450
|
-
doc.mergeBytes(u.body)
|
|
1451
|
-
done(doc.get())
|
|
1452
|
-
doc.free()
|
|
1453
|
-
a.abort()
|
|
1454
|
-
})
|
|
1455
|
-
})
|
|
1456
|
-
},
|
|
1457
|
-
'xy'
|
|
1458
|
-
)
|
|
1459
|
-
|
|
1460
|
-
runTest(
|
|
1461
|
-
"test accept-encoding updates(dt) (with parents which are current version)",
|
|
1462
|
-
async () => {
|
|
1463
|
-
await dt_p
|
|
1464
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1465
|
-
var doc = new Doc('hi')
|
|
1466
|
-
doc.ins(0, 'xy')
|
|
1467
|
-
|
|
1468
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1469
|
-
method: 'PUT',
|
|
1470
|
-
version: ['hi-1'],
|
|
1471
|
-
parents: [],
|
|
1472
|
-
body: 'xy'
|
|
1473
|
-
})
|
|
1474
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1475
|
-
|
|
1476
|
-
var a = new AbortController()
|
|
1477
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1478
|
-
signal: a.signal,
|
|
1479
|
-
parents: ['hi-1'],
|
|
1480
|
-
subscribe: true,
|
|
1481
|
-
headers: {
|
|
1482
|
-
'merge-type': 'dt',
|
|
1483
|
-
'X-Accept-Encoding': 'updates(dt)'
|
|
1484
|
-
}
|
|
1485
|
-
})
|
|
1486
|
-
|
|
1487
|
-
return await new Promise(done => {
|
|
1488
|
-
r2.subscribe(u => {
|
|
1489
|
-
doc.mergeBytes(u.body)
|
|
1490
|
-
done(doc.get())
|
|
1491
|
-
doc.free()
|
|
1492
|
-
a.abort()
|
|
1493
|
-
})
|
|
1494
|
-
})
|
|
1495
|
-
},
|
|
1496
|
-
'xy'
|
|
1497
|
-
)
|
|
1498
|
-
|
|
1499
|
-
runTest(
|
|
1500
|
-
"test accept-encoding updates(dt)",
|
|
1501
|
-
async () => {
|
|
1502
|
-
await dt_p
|
|
1503
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1504
|
-
|
|
1505
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1506
|
-
method: 'PUT',
|
|
1507
|
-
version: ['hi-1'],
|
|
1508
|
-
parents: [],
|
|
1509
|
-
body: 'xy'
|
|
1510
|
-
})
|
|
1511
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1512
|
-
|
|
1513
|
-
var a = new AbortController()
|
|
1514
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1515
|
-
signal: a.signal,
|
|
1516
|
-
subscribe: true,
|
|
1517
|
-
headers: {
|
|
1518
|
-
'merge-type': 'dt',
|
|
1519
|
-
'X-Accept-Encoding': 'updates(dt)'
|
|
1520
|
-
}
|
|
1521
|
-
})
|
|
1522
|
-
|
|
1523
|
-
var doc = new Doc('yo')
|
|
1524
|
-
return await new Promise(done => {
|
|
1525
|
-
r2.subscribe(u => {
|
|
1526
|
-
doc.mergeBytes(u.body)
|
|
1527
|
-
done(doc.get())
|
|
1528
|
-
doc.free()
|
|
1529
|
-
a.abort()
|
|
1530
|
-
})
|
|
1531
|
-
})
|
|
1532
|
-
},
|
|
1533
|
-
'xy'
|
|
1534
|
-
)
|
|
1535
|
-
|
|
1536
|
-
runTest(
|
|
1537
|
-
"test accept-encoding updates(dt), getting non-encoded update",
|
|
1538
|
-
async () => {
|
|
1539
|
-
await dt_p
|
|
1540
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1541
|
-
|
|
1542
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1543
|
-
method: 'PUT',
|
|
1544
|
-
version: ['hi-1'],
|
|
1545
|
-
parents: [],
|
|
1546
|
-
body: 'xy'
|
|
1547
|
-
})
|
|
1548
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1549
|
-
|
|
1550
|
-
var a = new AbortController()
|
|
1551
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1552
|
-
signal: a.signal,
|
|
1553
|
-
subscribe: true,
|
|
1554
|
-
headers: {
|
|
1555
|
-
'merge-type': 'dt',
|
|
1556
|
-
'X-Accept-Encoding': 'updates(dt)'
|
|
1557
|
-
}
|
|
1558
|
-
})
|
|
1559
|
-
|
|
1560
|
-
setTimeout(async () => {
|
|
1561
|
-
await braid_fetch(`/${key}`, {
|
|
1562
|
-
method: 'PUT',
|
|
1563
|
-
version: ['yo-0'],
|
|
1564
|
-
parents: ['hi-1'],
|
|
1565
|
-
patches: [{unit: 'text', range: '[2:2]', content: 'z'}]
|
|
1566
|
-
})
|
|
1567
|
-
}, 200)
|
|
1568
|
-
|
|
1569
|
-
var results = []
|
|
1570
|
-
|
|
1571
|
-
var doc = new Doc('yo')
|
|
1572
|
-
return await new Promise(done => {
|
|
1573
|
-
r2.subscribe(u => {
|
|
1574
|
-
if (!u.status) {
|
|
1575
|
-
doc.mergeBytes(u.body)
|
|
1576
|
-
results.push(doc.get())
|
|
1577
|
-
doc.free()
|
|
1578
|
-
} else {
|
|
1579
|
-
results.push(u.patches[0].content_text)
|
|
1580
|
-
done(results.join(''))
|
|
1581
|
-
a.abort()
|
|
1582
|
-
}
|
|
1583
|
-
})
|
|
1584
|
-
})
|
|
1585
|
-
},
|
|
1586
|
-
'xyz'
|
|
1587
|
-
)
|
|
1588
|
-
|
|
1589
|
-
runTest(
|
|
1590
|
-
"test Version we get from PUTing",
|
|
1591
|
-
async () => {
|
|
1592
|
-
await dt_p
|
|
1593
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1594
|
-
|
|
1595
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1596
|
-
method: 'PUT',
|
|
1597
|
-
version: ['hi∑-1'],
|
|
1598
|
-
parents: [],
|
|
1599
|
-
body: 'xy'
|
|
1600
|
-
})
|
|
1601
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1602
|
-
|
|
1603
|
-
return r.headers.get('version')
|
|
1604
|
-
},
|
|
1605
|
-
'"hi\\u2211-1"'
|
|
1606
|
-
)
|
|
1607
|
-
|
|
1608
|
-
runTest(
|
|
1609
|
-
"test error code when missing parents",
|
|
1610
|
-
async () => {
|
|
1611
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1612
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1613
|
-
method: 'PUT',
|
|
1614
|
-
version: ['hi-1'],
|
|
1615
|
-
parents: ['missing-0', 'y😀-0'],
|
|
1616
|
-
body: 'xx'
|
|
1617
|
-
})
|
|
1618
|
-
return r.status + ' ' + r.ok + ' ' + r.statusText + ' ' + r.headers.get('Version')
|
|
1619
|
-
},
|
|
1620
|
-
'309 false Version Unknown Here "missing-0", "y\\ud83d\\ude00-0"'
|
|
1621
|
-
)
|
|
1622
|
-
|
|
1623
|
-
runTest(
|
|
1624
|
-
"test subscribing starting at a version using simpleton",
|
|
1625
|
-
async () => {
|
|
1626
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1627
|
-
|
|
1628
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1629
|
-
method: 'PUT',
|
|
1630
|
-
version: ['hi-1'],
|
|
1631
|
-
parents: [],
|
|
1632
|
-
body: 'xx'
|
|
1633
|
-
})
|
|
1634
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1635
|
-
|
|
1636
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1637
|
-
version: ['hi-0'],
|
|
1638
|
-
subscribe: true
|
|
1639
|
-
})
|
|
1640
|
-
return await new Promise(async (done, fail) => {
|
|
1641
|
-
r2.subscribe(update => {
|
|
1642
|
-
done(JSON.stringify(update.parents))
|
|
1643
|
-
}, fail)
|
|
1644
|
-
})
|
|
1645
|
-
},
|
|
1646
|
-
JSON.stringify([ "hi-0" ])
|
|
1647
|
-
)
|
|
1648
|
-
|
|
1649
|
-
runTest(
|
|
1650
|
-
"test subscribing starting at a version using dt",
|
|
1651
|
-
async () => {
|
|
1652
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1653
|
-
|
|
1654
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1655
|
-
method: 'PUT',
|
|
1656
|
-
version: ['hi-1'],
|
|
1657
|
-
parents: [],
|
|
1658
|
-
body: 'xx'
|
|
1659
|
-
})
|
|
1660
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1661
|
-
|
|
1662
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1663
|
-
version: ['hi-0'],
|
|
1664
|
-
subscribe: true,
|
|
1665
|
-
headers: {
|
|
1666
|
-
'Merge-Type': 'dt'
|
|
1667
|
-
}
|
|
1668
|
-
})
|
|
1669
|
-
return r2.headers.get('merge-type') + ':' + await new Promise(async (done, fail) => {
|
|
1670
|
-
r2.subscribe(update => {
|
|
1671
|
-
done(JSON.stringify(update.parents))
|
|
1672
|
-
}, fail)
|
|
1673
|
-
})
|
|
1674
|
-
},
|
|
1675
|
-
'dt:' + JSON.stringify([ "hi-0" ])
|
|
1676
|
-
)
|
|
1677
|
-
|
|
1678
|
-
runTest(
|
|
1679
|
-
"test subscribing starting at the latest version using dt",
|
|
1680
|
-
async () => {
|
|
1681
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1682
|
-
|
|
1683
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1684
|
-
method: 'PUT',
|
|
1685
|
-
version: ['hi-1'],
|
|
1686
|
-
parents: [],
|
|
1687
|
-
body: 'xx'
|
|
1688
|
-
})
|
|
1689
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1690
|
-
|
|
1691
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1692
|
-
version: ['hi-1'],
|
|
1693
|
-
subscribe: true,
|
|
1694
|
-
headers: {
|
|
1695
|
-
'Merge-Type': 'dt'
|
|
1696
|
-
}
|
|
1697
|
-
})
|
|
1698
|
-
return await new Promise(async (done, fail) => {
|
|
1699
|
-
r2.subscribe(update => done('got something'), fail)
|
|
1700
|
-
setTimeout(() => done('got nothing'), 1500)
|
|
1701
|
-
})
|
|
1702
|
-
},
|
|
1703
|
-
'got nothing'
|
|
1704
|
-
)
|
|
1705
|
-
|
|
1706
|
-
runTest(
|
|
1707
|
-
"test subscribing starting at beginning using dt",
|
|
1708
|
-
async () => {
|
|
1709
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1710
|
-
|
|
1711
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1712
|
-
method: 'PUT',
|
|
1713
|
-
version: ['hi-1'],
|
|
1714
|
-
parents: [],
|
|
1715
|
-
body: 'xx'
|
|
1716
|
-
})
|
|
1717
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1718
|
-
|
|
1719
|
-
let r2 = await braid_fetch(`/${key}`, {
|
|
1720
|
-
subscribe: true,
|
|
1721
|
-
headers: {
|
|
1722
|
-
'Merge-Type': 'dt'
|
|
1723
|
-
}
|
|
1724
|
-
})
|
|
1725
|
-
return r2.headers.get('merge-type') + ':' + await new Promise(async (done, fail) => {
|
|
1726
|
-
r2.subscribe(update => {
|
|
1727
|
-
if (update.version[0] === 'hi-1') done('got it!')
|
|
1728
|
-
}, fail)
|
|
1729
|
-
})
|
|
1730
|
-
},
|
|
1731
|
-
'dt:got it!'
|
|
1732
|
-
)
|
|
1733
|
-
|
|
1734
|
-
runTest(
|
|
1735
|
-
"test dt_create_bytes with big agent name",
|
|
1736
|
-
async () => {
|
|
1737
|
-
let x = await (await fetch(`/test.html?dt_create_bytes_big_name`)).json()
|
|
1738
|
-
return JSON.stringify(x)
|
|
1739
|
-
},
|
|
1740
|
-
JSON.stringify({ok: true})
|
|
1741
|
-
)
|
|
1742
|
-
|
|
1743
|
-
runTest(
|
|
1744
|
-
"test dt_create_bytes with many agent names",
|
|
1745
|
-
async () => {
|
|
1746
|
-
let x = await (await fetch(`/test.html?dt_create_bytes_many_names`)).json()
|
|
1747
|
-
return JSON.stringify(x)
|
|
1748
|
-
},
|
|
1749
|
-
JSON.stringify({ok: true})
|
|
1750
|
-
)
|
|
1751
|
-
|
|
1752
|
-
runTest(
|
|
1753
|
-
"test deleting a resource",
|
|
1754
|
-
async () => {
|
|
1755
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1756
|
-
|
|
1757
|
-
await fetch(`/${key}`, {
|
|
1758
|
-
method: 'PUT',
|
|
1759
|
-
body: 'hi'
|
|
1760
|
-
})
|
|
1761
|
-
|
|
1762
|
-
await fetch(`/${key}`, {method: 'DELETE'})
|
|
1763
|
-
|
|
1764
|
-
let r = await fetch(`/${key}`)
|
|
1765
|
-
|
|
1766
|
-
return await r.text()
|
|
1767
|
-
},
|
|
1768
|
-
''
|
|
1769
|
-
)
|
|
1770
|
-
|
|
1771
|
-
runTest(
|
|
1772
|
-
"test getting a binary update from a subscription",
|
|
1773
|
-
async () => {
|
|
1774
|
-
return await new Promise(async (done, fail) => {
|
|
1775
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1776
|
-
|
|
1777
|
-
await fetch(`/${key}`, {
|
|
1778
|
-
method: 'PUT',
|
|
1779
|
-
body: JSON.stringify({a: 5, b: 6}, null, 4)
|
|
1780
|
-
})
|
|
1781
|
-
|
|
1782
|
-
let r = await braid_fetch(`/${key}`, {
|
|
1783
|
-
subscribe: true
|
|
1784
|
-
})
|
|
1785
|
-
|
|
1786
|
-
r.subscribe(update => done(update.body_text), fail)
|
|
1787
|
-
})
|
|
1788
|
-
},
|
|
1789
|
-
JSON.stringify({a: 5, b: 6}, null, 4)
|
|
1790
|
-
)
|
|
1791
|
-
|
|
1792
|
-
runTest(
|
|
1793
|
-
"test sending a json patch to some json-text",
|
|
1794
|
-
async () => {
|
|
1795
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1796
|
-
|
|
1797
|
-
await fetch(`/${key}`, {
|
|
1798
|
-
method: 'PUT',
|
|
1799
|
-
body: JSON.stringify({a: 5, b: 6})
|
|
1800
|
-
})
|
|
1801
|
-
|
|
1802
|
-
await fetch(`/${key}`, {
|
|
1803
|
-
method: 'PUT',
|
|
1804
|
-
headers: { 'Content-Range': 'json a' },
|
|
1805
|
-
body: '67'
|
|
1806
|
-
})
|
|
1807
|
-
|
|
1808
|
-
let r = await fetch(`/${key}`)
|
|
1809
|
-
|
|
1810
|
-
return await r.text()
|
|
1811
|
-
},
|
|
1812
|
-
JSON.stringify({a: 67, b: 6}, null, 4)
|
|
1813
|
-
)
|
|
1814
|
-
|
|
1815
|
-
runTest(
|
|
1816
|
-
"test sending multiple json patches to some json-text",
|
|
1817
|
-
async () => {
|
|
1818
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1819
|
-
|
|
1820
|
-
await fetch(`/${key}`, {
|
|
1821
|
-
method: 'PUT',
|
|
1822
|
-
body: JSON.stringify({a: 5, b: 6, c: 7})
|
|
1823
|
-
})
|
|
1824
|
-
|
|
1825
|
-
await braid_fetch(`/${key}`, {
|
|
1826
|
-
method: 'PUT',
|
|
1827
|
-
headers: { 'Content-Range': 'json a' },
|
|
1828
|
-
patches: [{
|
|
1829
|
-
unit: 'json',
|
|
1830
|
-
range: 'a',
|
|
1831
|
-
content: '55',
|
|
1832
|
-
}, {
|
|
1833
|
-
unit: 'json',
|
|
1834
|
-
range: 'b',
|
|
1835
|
-
content: '66',
|
|
1836
|
-
}]
|
|
1837
|
-
})
|
|
1838
|
-
|
|
1839
|
-
let r = await fetch(`/${key}`)
|
|
1840
|
-
|
|
1841
|
-
return await r.text()
|
|
1842
|
-
},
|
|
1843
|
-
JSON.stringify({a: 55, b: 66, c: 7}, null, 4)
|
|
1844
|
-
)
|
|
1845
|
-
|
|
1846
|
-
runTest(
|
|
1847
|
-
"test deleting something using a json patch",
|
|
1848
|
-
async () => {
|
|
1849
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1850
|
-
|
|
1851
|
-
await fetch(`/${key}`, {
|
|
1852
|
-
method: 'PUT',
|
|
1853
|
-
body: JSON.stringify({a: 5, b: 6}, null, 4)
|
|
1854
|
-
})
|
|
1855
|
-
|
|
1856
|
-
await fetch(`/${key}`, {
|
|
1857
|
-
method: 'PUT',
|
|
1858
|
-
headers: { 'Content-Range': 'json a' },
|
|
1859
|
-
body: ''
|
|
1860
|
-
})
|
|
1861
|
-
|
|
1862
|
-
let r = await fetch(`/${key}`)
|
|
1863
|
-
|
|
1864
|
-
return await r.text()
|
|
1865
|
-
},
|
|
1866
|
-
JSON.stringify({b: 6}, null, 4)
|
|
1867
|
-
)
|
|
1868
|
-
|
|
1869
|
-
runTest(
|
|
1870
|
-
"test length updating",
|
|
1871
|
-
async () => {
|
|
1872
|
-
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
1873
|
-
|
|
1874
|
-
await fetch(`/${key}`, { method: 'PUT', body: '' })
|
|
1875
|
-
await fetch(`/${key}`, { method: 'PUT', body: '0123456789' })
|
|
1876
|
-
await fetch(`/${key}`, { method: 'PUT', body: '0123456789' })
|
|
1877
|
-
await fetch(`/${key}`, { method: 'PUT', body: '0123456789' })
|
|
1878
|
-
|
|
1879
|
-
let r = await fetch(`/${key}`, { method: 'HEAD' })
|
|
1880
|
-
return '' + parseInt(r.headers.get('version').split('-')[1])
|
|
1881
|
-
},
|
|
1882
|
-
'19'
|
|
1883
|
-
)
|
|
1884
|
-
|
|
1885
|
-
runTest(
|
|
1886
|
-
"test retry when parents not there..",
|
|
1887
|
-
async () => {
|
|
1888
|
-
return await new Promise(done => {
|
|
1889
|
-
var count = 0
|
|
1890
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1891
|
-
var a = new AbortController()
|
|
1892
|
-
braid_fetch(`/${key}`, {
|
|
1893
|
-
signal: a.signal,
|
|
1894
|
-
multiplex: false,
|
|
1895
|
-
method: 'PUT',
|
|
1896
|
-
version: ['hi-3'],
|
|
1897
|
-
parents: ['hi-1'],
|
|
1898
|
-
body: 'xx',
|
|
1899
|
-
onFetch: () => {
|
|
1900
|
-
count++
|
|
1901
|
-
if (count === 2) {
|
|
1902
|
-
done('retried!')
|
|
1903
|
-
a.abort()
|
|
1904
|
-
}
|
|
1905
|
-
},
|
|
1906
|
-
retry: true
|
|
1907
|
-
})
|
|
1908
|
-
})
|
|
1909
|
-
},
|
|
1910
|
-
'retried!'
|
|
1911
|
-
)
|
|
1912
|
-
|
|
1913
|
-
runTest(
|
|
1914
|
-
"test asking for a version that should and shouldn't be there",
|
|
1915
|
-
async () => {
|
|
1916
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1917
|
-
|
|
1918
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1919
|
-
method: 'PUT',
|
|
1920
|
-
version: ['hi-10'],
|
|
1921
|
-
parents: [],
|
|
1922
|
-
body: 'x'
|
|
1923
|
-
})
|
|
1924
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1925
|
-
|
|
1926
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1927
|
-
method: 'HEAD',
|
|
1928
|
-
version: ['hi-5']
|
|
1929
|
-
})
|
|
1930
|
-
if (r.status !== 309) throw 'expected 309, got: ' + r.status
|
|
1931
|
-
if (r.statusText !== 'Version Unknown Here') throw 'unexpected status text: ' + r.statusText
|
|
1932
|
-
if (r.ok) throw 'found version we should not have found'
|
|
1933
|
-
|
|
1934
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1935
|
-
method: 'HEAD',
|
|
1936
|
-
version: ['hi-10']
|
|
1937
|
-
})
|
|
1938
|
-
if (!r.ok) throw 'could not find version we should have found'
|
|
1939
|
-
|
|
1940
|
-
return 'worked out!'
|
|
1941
|
-
},
|
|
1942
|
-
'worked out!'
|
|
1943
|
-
)
|
|
1944
|
-
|
|
1945
|
-
runTest(
|
|
1946
|
-
"test asking for parents that should and shouldn't be there",
|
|
1947
|
-
async () => {
|
|
1948
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1949
|
-
|
|
1950
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1951
|
-
method: 'PUT',
|
|
1952
|
-
version: ['hi-10'],
|
|
1953
|
-
parents: [],
|
|
1954
|
-
body: 'x'
|
|
1955
|
-
})
|
|
1956
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1957
|
-
|
|
1958
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1959
|
-
method: 'HEAD',
|
|
1960
|
-
parents: ['hi-5']
|
|
1961
|
-
})
|
|
1962
|
-
if (r.status !== 309) throw 'expected 309, got: ' + r.status
|
|
1963
|
-
if (r.ok) throw 'found parents we should not have found'
|
|
1964
|
-
|
|
1965
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1966
|
-
method: 'HEAD',
|
|
1967
|
-
parents: ['hi-10']
|
|
1968
|
-
})
|
|
1969
|
-
if (!r.ok) throw 'could not find parents we should have found'
|
|
1970
|
-
|
|
1971
|
-
return 'worked out!'
|
|
1972
|
-
},
|
|
1973
|
-
'worked out!'
|
|
1974
|
-
)
|
|
1975
|
-
|
|
1976
|
-
runTest(
|
|
1977
|
-
"test that 309 returns all missing events",
|
|
1978
|
-
async () => {
|
|
1979
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
1980
|
-
|
|
1981
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1982
|
-
method: 'PUT',
|
|
1983
|
-
version: ['hi-11'],
|
|
1984
|
-
parents: [],
|
|
1985
|
-
body: 'xyz'
|
|
1986
|
-
})
|
|
1987
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
1988
|
-
|
|
1989
|
-
var r = await braid_fetch(`/${key}`, {
|
|
1990
|
-
method: 'HEAD',
|
|
1991
|
-
version: ['yo-1', 'hi-11'],
|
|
1992
|
-
parents: ['hi-5', 'hi-8', 'hi-9', 'hi-10']
|
|
1993
|
-
})
|
|
1994
|
-
if (r.status !== 309) throw 'expected 309, got: ' + r.status
|
|
1995
|
-
return r.headers.get('version')
|
|
1996
|
-
},
|
|
1997
|
-
'"yo-1", "hi-5", "hi-8"'
|
|
1998
|
-
)
|
|
1999
|
-
|
|
2000
|
-
runTest(
|
|
2001
|
-
"test that subscribe returns current-version header",
|
|
2002
|
-
async () => {
|
|
2003
|
-
var key = 'test-' + Math.random().toString(36).slice(2)
|
|
2004
|
-
|
|
2005
|
-
var r = await braid_fetch(`/${key}`, {
|
|
2006
|
-
method: 'PUT',
|
|
2007
|
-
version: ['hi-11'],
|
|
2008
|
-
parents: [],
|
|
2009
|
-
body: 'xyz'
|
|
2010
|
-
})
|
|
2011
|
-
if (!r.ok) throw 'got: ' + r.statusCode
|
|
2012
|
-
|
|
2013
|
-
var r = await braid_fetch(`/${key}`, {
|
|
2014
|
-
subscribe: true
|
|
2015
|
-
})
|
|
2016
|
-
return r.headers.get('current-version')
|
|
2017
|
-
},
|
|
2018
|
-
'"hi-11"'
|
|
2019
|
-
)
|
|
115
|
+
// Load and run all tests from the shared tests.js file
|
|
116
|
+
defineTests(runTest, braid_fetch)
|
|
2020
117
|
|
|
2021
118
|
</script>
|