braid-text 0.2.26 → 0.2.28
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 +9 -1
- package/package.json +1 -1
- package/test/test.html +85 -0
package/index.js
CHANGED
|
@@ -808,6 +808,11 @@ function dt_len(doc, version) {
|
|
|
808
808
|
}
|
|
809
809
|
|
|
810
810
|
function dt_get_string(doc, version) {
|
|
811
|
+
// optimization: if version is the latest,
|
|
812
|
+
// then return the current text..
|
|
813
|
+
if (v_eq(version, doc.getRemoteVersion().map((x) => x.join("-")).sort()))
|
|
814
|
+
return doc.get()
|
|
815
|
+
|
|
811
816
|
var bytes = doc.toBytes()
|
|
812
817
|
var oplog = OpLog.fromBytes(bytes)
|
|
813
818
|
|
|
@@ -923,7 +928,10 @@ function dt_get_patches(doc, version = null) {
|
|
|
923
928
|
let [_agents, versions, parentss] = dt_parse([...bytes])
|
|
924
929
|
|
|
925
930
|
let op_runs = []
|
|
926
|
-
if (version
|
|
931
|
+
if (version && v_eq(version,
|
|
932
|
+
doc.getRemoteVersion().map((x) => x.join("-")).sort())) {
|
|
933
|
+
// they want everything past the end, which is nothing
|
|
934
|
+
} else if (version) {
|
|
927
935
|
let frontier = {}
|
|
928
936
|
version.forEach((x) => frontier[x] = true)
|
|
929
937
|
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 () => {
|