braid-text 0.2.26 → 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 CHANGED
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.26",
3
+ "version": "0.2.27",
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
@@ -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 () => {