braid-text 0.1.4 → 0.2.0

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/editor.html CHANGED
@@ -5,7 +5,7 @@
5
5
  ></textarea>
6
6
  </body>
7
7
  <script src="https://braid.org/code/myers-diff1.js"></script>
8
- <script src="https://unpkg.com/braid-http@~1.0/braid-http-client.js"></script>
8
+ <script src="https://unpkg.com/braid-http@~1.3/braid-http-client.js"></script>
9
9
  <script src="/simpleton-client.js"></script>
10
10
  <script>
11
11
  let simpleton = simpleton_client(location.pathname, {
package/index.js CHANGED
@@ -148,6 +148,7 @@ braid_text.serve = async (req, res, options = {}) => {
148
148
  let ee = null
149
149
  try {
150
150
  patches = await req.patches()
151
+ for (let p of patches) p.content = p.content_text
151
152
  } catch (e) { ee = e }
152
153
  await my_prev_put_p
153
154
 
@@ -12,7 +12,7 @@ dom.BODY = -> DIV(WIKI())
12
12
  window.statebus_fetch = window.fetch
13
13
  window.fetch = window.og_fetch
14
14
  </script>
15
- <script src="https://unpkg.com/braid-http@~1.0/braid-http-client.js"></script>
15
+ <script src="https://unpkg.com/braid-http@~1.3/braid-http-client.js"></script>
16
16
  <script>
17
17
  window.fetch = window.statebus_fetch
18
18
  </script>
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidjs",
7
7
  "homepage": "https://braid.org",
8
8
  "dependencies": {
9
9
  "diamond-types-node": "^1.0.2",
10
- "braid-http": "^1.0.7"
10
+ "braid-http": "^1.3.4"
11
11
  }
12
12
  }
@@ -1,4 +1,4 @@
1
- // requires braid-http@~1.0/braid-http-client.js
1
+ // requires braid-http@~1.3/braid-http-client.js
2
2
  //
3
3
  // url: resource endpoint
4
4
  //
@@ -41,10 +41,13 @@ function simpleton_client(url, { apply_remote_update, generate_local_diff_update
41
41
  if (current_version.length === update.parents.length
42
42
  && current_version.every((v, i) => v === update.parents[i])) {
43
43
  current_version = update.version.sort()
44
- update.state = update.body
44
+ update.state = update.body_text
45
45
 
46
46
  if (update.patches) {
47
- for (let p of update.patches) p.range = p.range.match(/\d+/g).map((x) => 1 * x)
47
+ for (let p of update.patches) {
48
+ p.range = p.range.match(/\d+/g).map((x) => 1 * x)
49
+ p.content = p.content_text
50
+ }
48
51
  update.patches.sort((a, b) => a.range[0] - b.range[0])
49
52
 
50
53
  // convert from code-points to js-indicies
package/test.html CHANGED
@@ -19,7 +19,7 @@
19
19
  background-color: #ffebee;
20
20
  }
21
21
  </style>
22
- <script src="https://unpkg.com/braid-http@~1.1/braid-http-client.js"></script>
22
+ <script src="https://unpkg.com/braid-http@~1.3/braid-http-client.js"></script>
23
23
  <div id="testContainer"></div>
24
24
  <script type=module>
25
25
 
@@ -61,6 +61,27 @@ async function runTest(testName, testFunction, expectedResult) {
61
61
  }
62
62
  }
63
63
 
64
+ runTest(
65
+ "test getting a binary update from a subscription",
66
+ async () => {
67
+ return await new Promise(async (done, fail) => {
68
+ let key = 'test-' + Math.random().toString(36).slice(2)
69
+
70
+ await fetch(`/${key}`, {
71
+ method: 'PUT',
72
+ body: JSON.stringify({a: 5, b: 6}, null, 4)
73
+ })
74
+
75
+ let r = await braid_fetch(`/${key}`, {
76
+ subscribe: true
77
+ })
78
+
79
+ r.subscribe(update => done(update.body_text), fail)
80
+ })
81
+ },
82
+ JSON.stringify({a: 5, b: 6}, null, 4)
83
+ )
84
+
64
85
  runTest(
65
86
  "test sending a json patch to some json-text",
66
87
  async () => {
package/test.js CHANGED
@@ -27,7 +27,7 @@ async function main() {
27
27
  og_log(`t = ${t}, seed = ${seed}, best_n = ${best_n} @ ${best_seed}`)
28
28
  Math.randomSeed(seed)
29
29
 
30
- let n = Math.floor(Math.random() * 15) + 5
30
+ let n = Math.floor(Math.random() * 15)
31
31
  console.log(`n = ${n}`)
32
32
 
33
33
  try {