braid-text 0.5.9 → 0.5.10

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.
@@ -63,8 +63,8 @@ function simpleton_client(url, {
63
63
  get_patches,
64
64
 
65
65
  on_update,
66
- on_error,
67
- on_online,
66
+ on_error, // (error) =>
67
+ on_online, // (is_online) =>
68
68
  on_ack,
69
69
 
70
70
  headers, // The user can pass in custom headers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
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/server.js CHANGED
@@ -408,8 +408,8 @@ function create_braid_text() {
408
408
  Version: ascii_ify(unknowns.map(e => JSON.stringify(e)).join(', '))
409
409
  })
410
410
 
411
- var has_parents = req.parents && req.parents.length > 0
412
- var has_version = req.version && req.version.length > 0
411
+ var has_parents = Array.isArray(req.parents)
412
+ var has_version = Array.isArray(req.version)
413
413
 
414
414
  if (req.subscribe && has_version)
415
415
  return my_end(400, 'Version header is not allowed with Subscribe — use Parents instead')
@@ -685,8 +685,8 @@ function create_braid_text() {
685
685
  var version = resource.version
686
686
  var merge_type = options.range_unit === 'yjs-text' ? 'yjs'
687
687
  : (options.merge_type || 'simpleton')
688
- var has_parents = options.parents && options.parents.length > 0
689
- var has_version = options.version && options.version.length > 0
688
+ var has_parents = Array.isArray(options.parents)
689
+ var has_version = Array.isArray(options.version)
690
690
 
691
691
  if (options.subscribe && has_version)
692
692
  throw new Error('version is not allowed with subscribe — use parents instead')
@@ -704,21 +704,9 @@ function create_braid_text() {
704
704
  }
705
705
  getting.single_snapshot = !getting.subscribe && !getting.history
706
706
 
707
- // Single snapshot: return the text (optionally at a specific version)
708
- if (getting.single_snapshot) {
709
- if (has_version) {
710
- await ensure_dt_exists(resource)
711
- return options.full_response
712
- ? { version: options.version, body: dt_get_string(resource.dt.doc, options.version) }
713
- : dt_get_string(resource.dt.doc, options.version)
714
- }
715
- return options.full_response ? { version, body: resource.val } : resource.val
716
- }
717
-
718
707
  // DT binary encoding: a transport optimization usable by any merge type.
719
708
  // Returns raw DT bytes instead of text.
720
- if (getting.history && !getting.subscribe && getting.transfer_encoding === 'dt') {
721
- // TODO: move this into the dt/simpleton merge_type cases below
709
+ if (!getting.subscribe && getting.transfer_encoding === 'dt') {
722
710
  await ensure_dt_exists(resource)
723
711
  // If requesting the current version, skip the version lookup
724
712
  // (faster than asking DT about a version we already have)
@@ -742,6 +730,17 @@ function create_braid_text() {
742
730
  return { body: bytes }
743
731
  }
744
732
 
733
+ // Single snapshot: return the text (optionally at a specific version)
734
+ if (getting.single_snapshot) {
735
+ if (has_version) {
736
+ await ensure_dt_exists(resource)
737
+ return options.full_response
738
+ ? { version: options.version, body: dt_get_string(resource.dt.doc, options.version) }
739
+ : dt_get_string(resource.dt.doc, options.version)
740
+ }
741
+ return options.full_response ? { version, body: resource.val } : resource.val
742
+ }
743
+
745
744
  // Each merge-type has a different way of getting history
746
745
  switch (merge_type) {
747
746