braid-text 0.2.25 → 0.2.27
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 +6 -3
- package/package.json +1 -1
- package/test/test.html +85 -0
- package/test/server.js +0 -50
package/index.js
CHANGED
|
@@ -488,6 +488,8 @@ braid_text.put = async (key, options) => {
|
|
|
488
488
|
|
|
489
489
|
resource.need_defrag = true
|
|
490
490
|
|
|
491
|
+
await resource.db_delta(resource.doc.getPatchSince(v_before))
|
|
492
|
+
|
|
491
493
|
if (options.merge_type != "dt") {
|
|
492
494
|
patches = get_xf_patches(resource.doc, v_before)
|
|
493
495
|
if (braid_text.verbose) console.log(JSON.stringify({ patches }))
|
|
@@ -588,8 +590,6 @@ braid_text.put = async (key, options) => {
|
|
|
588
590
|
for (let client of resource.clients) {
|
|
589
591
|
if (!peer || client.peer !== peer) client.subscribe(x)
|
|
590
592
|
}
|
|
591
|
-
|
|
592
|
-
await resource.db_delta(resource.doc.getPatchSince(v_before))
|
|
593
593
|
}
|
|
594
594
|
|
|
595
595
|
braid_text.list = async () => {
|
|
@@ -923,7 +923,10 @@ function dt_get_patches(doc, version = null) {
|
|
|
923
923
|
let [_agents, versions, parentss] = dt_parse([...bytes])
|
|
924
924
|
|
|
925
925
|
let op_runs = []
|
|
926
|
-
if (version
|
|
926
|
+
if (version && v_eq(version,
|
|
927
|
+
doc.getRemoteVersion().map((x) => x.join("-")).sort())) {
|
|
928
|
+
// they want everything past the end, which is nothing
|
|
929
|
+
} else if (version) {
|
|
927
930
|
let frontier = {}
|
|
928
931
|
version.forEach((x) => frontier[x] = true)
|
|
929
932
|
let local_version = []
|
package/package.json
CHANGED
package/test/test.html
CHANGED
|
@@ -87,6 +87,91 @@ runTest(
|
|
|
87
87
|
JSON.stringify([ "hi-0" ])
|
|
88
88
|
)
|
|
89
89
|
|
|
90
|
+
runTest(
|
|
91
|
+
"test subscribing starting at a version using dt",
|
|
92
|
+
async () => {
|
|
93
|
+
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
94
|
+
|
|
95
|
+
let r = await braid_fetch(`/${key}`, {
|
|
96
|
+
method: 'PUT',
|
|
97
|
+
version: ['hi-1'],
|
|
98
|
+
parents: [],
|
|
99
|
+
body: 'xx'
|
|
100
|
+
})
|
|
101
|
+
if (!r.ok) throw 'got: ' + r.statusCode
|
|
102
|
+
|
|
103
|
+
let r2 = await braid_fetch(`/${key}`, {
|
|
104
|
+
version: ['hi-0'],
|
|
105
|
+
subscribe: true,
|
|
106
|
+
headers: {
|
|
107
|
+
'Merge-Type': 'dt'
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
return r2.headers.get('merge-type') + ':' + await new Promise(async (done, fail) => {
|
|
111
|
+
r2.subscribe(update => {
|
|
112
|
+
done(JSON.stringify(update.parents))
|
|
113
|
+
}, fail)
|
|
114
|
+
})
|
|
115
|
+
},
|
|
116
|
+
'dt:' + JSON.stringify([ "hi-0" ])
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
runTest(
|
|
120
|
+
"test subscribing starting at the latest version using dt",
|
|
121
|
+
async () => {
|
|
122
|
+
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
123
|
+
|
|
124
|
+
let r = await braid_fetch(`/${key}`, {
|
|
125
|
+
method: 'PUT',
|
|
126
|
+
version: ['hi-1'],
|
|
127
|
+
parents: [],
|
|
128
|
+
body: 'xx'
|
|
129
|
+
})
|
|
130
|
+
if (!r.ok) throw 'got: ' + r.statusCode
|
|
131
|
+
|
|
132
|
+
let r2 = await braid_fetch(`/${key}`, {
|
|
133
|
+
version: ['hi-1'],
|
|
134
|
+
subscribe: true,
|
|
135
|
+
headers: {
|
|
136
|
+
'Merge-Type': 'dt'
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
return await new Promise(async (done, fail) => {
|
|
140
|
+
r2.subscribe(update => done('got something'), fail)
|
|
141
|
+
setTimeout(() => done('got nothing'), 1500)
|
|
142
|
+
})
|
|
143
|
+
},
|
|
144
|
+
'got nothing'
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
runTest(
|
|
148
|
+
"test subscribing starting at beginning using dt",
|
|
149
|
+
async () => {
|
|
150
|
+
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
151
|
+
|
|
152
|
+
let r = await braid_fetch(`/${key}`, {
|
|
153
|
+
method: 'PUT',
|
|
154
|
+
version: ['hi-1'],
|
|
155
|
+
parents: [],
|
|
156
|
+
body: 'xx'
|
|
157
|
+
})
|
|
158
|
+
if (!r.ok) throw 'got: ' + r.statusCode
|
|
159
|
+
|
|
160
|
+
let r2 = await braid_fetch(`/${key}`, {
|
|
161
|
+
subscribe: true,
|
|
162
|
+
headers: {
|
|
163
|
+
'Merge-Type': 'dt'
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
return r2.headers.get('merge-type') + ':' + await new Promise(async (done, fail) => {
|
|
167
|
+
r2.subscribe(update => {
|
|
168
|
+
if (update.version[0] === 'hi-1') done('got it!')
|
|
169
|
+
}, fail)
|
|
170
|
+
})
|
|
171
|
+
},
|
|
172
|
+
'dt:got it!'
|
|
173
|
+
)
|
|
174
|
+
|
|
90
175
|
runTest(
|
|
91
176
|
"test dt_create_bytes with big agent name",
|
|
92
177
|
async () => {
|
package/test/server.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var port = process.argv[2] || 8889
|
|
3
|
-
|
|
4
|
-
var braid_text = require("../index.js")
|
|
5
|
-
braid_text.db_folder = null
|
|
6
|
-
|
|
7
|
-
var server = require("http").createServer(async (req, res) => {
|
|
8
|
-
console.log(`${req.method} ${req.url}`)
|
|
9
|
-
|
|
10
|
-
// Free the CORS
|
|
11
|
-
braid_text.free_cors(res)
|
|
12
|
-
if (req.method === 'OPTIONS') return
|
|
13
|
-
|
|
14
|
-
if (req.url.startsWith('/test.html')) {
|
|
15
|
-
let parts = req.url.split(/[\?&=]/g)
|
|
16
|
-
|
|
17
|
-
if (parts[1] === 'check') {
|
|
18
|
-
res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-cache" })
|
|
19
|
-
return res.end(JSON.stringify({
|
|
20
|
-
checking: parts[2],
|
|
21
|
-
result: (await braid_text.get(parts[2])) != null
|
|
22
|
-
}))
|
|
23
|
-
} else if (parts[1] === 'dt_create_bytes_big_name') {
|
|
24
|
-
try {
|
|
25
|
-
braid_text.dt_create_bytes('x'.repeat(1000000) + '-0', [], 0, 0, 'hi')
|
|
26
|
-
return res.end(JSON.stringify({ ok: true }))
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return res.end(JSON.stringify({ ok: false, error: '' + e }))
|
|
29
|
-
}
|
|
30
|
-
} else if (parts[1] === 'dt_create_bytes_many_names') {
|
|
31
|
-
try {
|
|
32
|
-
braid_text.dt_create_bytes('hi-0', new Array(1000000).fill(0).map((x, i) => `x${i}-0`), 0, 0, 'hi')
|
|
33
|
-
return res.end(JSON.stringify({ ok: true }))
|
|
34
|
-
} catch (e) {
|
|
35
|
-
return res.end(JSON.stringify({ ok: false, error: '' + e }))
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-cache" })
|
|
40
|
-
require("fs").createReadStream(`${__dirname}/test.html`).pipe(res)
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Now serve the collaborative text!
|
|
45
|
-
braid_text.serve(req, res)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
server.listen(port, () => {
|
|
49
|
-
console.log(`serving: http://localhost:${port}/test.html`)
|
|
50
|
-
})
|