braid-text 0.2.37 → 0.2.39
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/package.json +1 -1
- package/simpleton-client.js +6 -4
package/package.json
CHANGED
package/simpleton-client.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// this is for outgoing changes;
|
|
18
18
|
// diff_function = () => ({patches, new_version}).
|
|
19
19
|
//
|
|
20
|
-
function simpleton_client(url, { apply_remote_update, generate_local_diff_update, content_type, on_error }) {
|
|
20
|
+
function simpleton_client(url, { apply_remote_update, generate_local_diff_update, content_type, on_error, on_res }) {
|
|
21
21
|
var peer = Math.random().toString(36).substr(2)
|
|
22
22
|
var current_version = []
|
|
23
23
|
var prev_state = ""
|
|
@@ -34,7 +34,8 @@ function simpleton_client(url, { apply_remote_update, generate_local_diff_update
|
|
|
34
34
|
parents: () => current_version.length ? current_version : null,
|
|
35
35
|
peer,
|
|
36
36
|
signal: ac.signal
|
|
37
|
-
}).then(res =>
|
|
37
|
+
}).then(res => {
|
|
38
|
+
if (on_res) on_res(res)
|
|
38
39
|
res.subscribe(update => {
|
|
39
40
|
// Only accept the update if its parents == our current version
|
|
40
41
|
update.parents.sort()
|
|
@@ -71,7 +72,7 @@ function simpleton_client(url, { apply_remote_update, generate_local_diff_update
|
|
|
71
72
|
prev_state = apply_remote_update(update)
|
|
72
73
|
}
|
|
73
74
|
}, on_error)
|
|
74
|
-
).catch(on_error)
|
|
75
|
+
}).catch(on_error)
|
|
75
76
|
|
|
76
77
|
return {
|
|
77
78
|
stop: async () => {
|
|
@@ -115,7 +116,7 @@ function simpleton_client(url, { apply_remote_update, generate_local_diff_update
|
|
|
115
116
|
|
|
116
117
|
outstanding_changes++
|
|
117
118
|
try {
|
|
118
|
-
await braid_fetch(url, {
|
|
119
|
+
var r = await braid_fetch(url, {
|
|
119
120
|
headers: { "Merge-Type": "simpleton",
|
|
120
121
|
...(content_type ? {"Content-Type": content_type} : {}) },
|
|
121
122
|
method: "PUT",
|
|
@@ -123,6 +124,7 @@ function simpleton_client(url, { apply_remote_update, generate_local_diff_update
|
|
|
123
124
|
version, parents, patches,
|
|
124
125
|
peer
|
|
125
126
|
})
|
|
127
|
+
if (!r.ok) throw new Error(`bad http status: ${r.status}${(r.status === 401 || r.status === 403) ? ` (access denied)` : ''}`)
|
|
126
128
|
} catch (e) {
|
|
127
129
|
on_error(e)
|
|
128
130
|
throw e
|