braid-text 0.2.15 → 0.2.16

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
@@ -80,7 +80,7 @@ braid_text.serve = async (req, res, options = {}) => {
80
80
  try {
81
81
  x = await braid_text.get(resource, { version: req.version, parents: req.parents })
82
82
  } catch (e) {
83
- return my_end(400, "The server failed to get something. The error generated was: " + e)
83
+ return my_end(500, "The server failed to get something. The error generated was: " + e)
84
84
  }
85
85
 
86
86
  res.setHeader("Version", x.version.map((x) => JSON.stringify(x)).join(", "))
@@ -116,7 +116,7 @@ braid_text.serve = async (req, res, options = {}) => {
116
116
  try {
117
117
  return await braid_text.get(resource, options)
118
118
  } catch (e) {
119
- return my_end(400, "The server failed to get something. The error generated was: " + e)
119
+ return my_end(500, "The server failed to get something. The error generated was: " + e)
120
120
  }
121
121
  }
122
122
  }
@@ -192,7 +192,7 @@ braid_text.serve = async (req, res, options = {}) => {
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
193
  return done_my_turn(425, e.message)
194
194
  } else {
195
- return done_my_turn(400, "The server failed to apply this version. The error generated was: " + e)
195
+ return done_my_turn(500, "The server failed to apply this version. The error generated was: " + e)
196
196
  }
197
197
  }
198
198
 
@@ -219,17 +219,14 @@ braid_text.get = async (key, options) => {
219
219
  let resource = (typeof key == 'string') ? await get_resource(key) : key
220
220
 
221
221
  if (!options.subscribe) {
222
- let doc = resource.doc
223
- if (options.version || options.parents) doc = dt_get(doc, options.version || options.parents)
224
-
225
- let ret = {
226
- version: doc.getRemoteVersion().map((x) => x.join("-")).sort(),
227
- body: doc.get()
228
- }
229
-
230
- if (options.version || options.parents) doc.free()
231
-
232
- return ret
222
+ return options.version || options.parents ?
223
+ {
224
+ version: options.version || options.parents,
225
+ body: dt_get_string(resource.doc, options.version || options.parents)
226
+ } : {
227
+ version: resource.doc.getRemoteVersion().map((x) => x.join("-")).sort(),
228
+ body: resource.doc.get()
229
+ }
233
230
  } else {
234
231
  if (options.merge_type != "dt") {
235
232
  let version = resource.doc.getRemoteVersion().map((x) => x.join("-")).sort()
@@ -790,14 +787,18 @@ async function file_sync(key, process_delta, get_init) {
790
787
  //////////////////////////////////////////////////////////////////
791
788
 
792
789
  function dt_len(doc, version) {
793
- let bytes = doc.toBytes()
794
- let oplog = OpLog.fromBytes(bytes)
795
- let [_agents, versions, _parentss] = dt_parse([...bytes])
790
+ return count_code_points(dt_get_string(doc, version))
791
+ }
796
792
 
797
- let frontier = new Set(version)
793
+ function dt_get_string(doc, version) {
794
+ var bytes = doc.toBytes()
795
+ var oplog = OpLog.fromBytes(bytes)
796
+ var [_agents, versions, _parentss] = dt_parse([...bytes])
798
797
 
799
- let local_version = []
800
- for (let i = 0; i < versions.length; i++) {
798
+ var frontier = new Set(version)
799
+
800
+ var local_version = []
801
+ for (var i = 0; i < versions.length; i++) {
801
802
  var v = versions[i].join("-")
802
803
  if (frontier.has(v)) {
803
804
  local_version.push(i)
@@ -807,13 +808,13 @@ function dt_len(doc, version) {
807
808
 
808
809
  if (frontier.size) throw new Error(`version not found: ${version}`)
809
810
 
810
- let b = new Branch()
811
+ var b = new Branch()
811
812
  b.merge(oplog, new Uint32Array(local_version))
812
- let len = count_code_points(b.get())
813
+ var s = b.get()
813
814
  b.free()
814
815
 
815
816
  oplog.free()
816
- return len
817
+ return s
817
818
  }
818
819
 
819
820
  function dt_get(doc, version, agent = null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
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/server.js CHANGED
@@ -46,5 +46,5 @@ var server = require("http").createServer(async (req, res) => {
46
46
  })
47
47
 
48
48
  server.listen(port, () => {
49
- console.log(`server started on port ${port}`)
49
+ console.log(`serving: http://localhost:${port}/test.html`)
50
50
  })
package/test/test.js CHANGED
@@ -23,7 +23,7 @@ async function main() {
23
23
  for (let t = 0; t < 10000; t++) {
24
24
  let seed = base + t
25
25
  // for (let t = 0; t < 1; t++) {
26
- // let seed = 7572861
26
+ // let seed = 7630348
27
27
 
28
28
  og_log(`t = ${t}, seed = ${seed}, best_n = ${best_n} @ ${best_seed}`)
29
29
  Math.randomSeed(seed)