braid-text 0.3.8 → 0.3.9

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.
@@ -45,15 +45,6 @@
45
45
  // get_state: () => current_state
46
46
  // returns the current state (e.g., textarea.value)
47
47
  //
48
- // [DEPRECATED] apply_remote_update: ({patches, state}) => {...}
49
- // this is for incoming changes;
50
- // one of these will be non-null,
51
- // and can be applied to the current state.
52
- //
53
- // [DEPRECATED] generate_local_diff_update: (client_state) => {...}
54
- // this is to generate outgoing changes,
55
- // and if there are changes, returns { patches, new_state }
56
- //
57
48
  // content_type: used for Accept and Content-Type headers
58
49
  //
59
50
  // returns { changed, abort }
@@ -75,18 +66,12 @@
75
66
  //
76
67
  // PUT requests:
77
68
  // retry: (res) => res.status !== 550 — retry all errors EXCEPT
78
- // HTTP 550 (permanent rejection by the server). This means:
69
+ // HTTP 550 (Repr-Digest mismatch, meaning client is out of sync).
70
+ // This means:
79
71
  // - Connection failure: retried with backoff
80
- // - HTTP 408, 429, 500, 502, 503, 504, etc.: retried
81
- // - HTTP 550: give up, throw error, outstanding_changes stays
82
- // incremented (potential throttle leak see note below)
83
- // - HTTP 401, 403: retried by braid_fetch, but the !r.ok check
84
- // throws, which calls on_error and exits the async loop
85
- //
86
- // NOTE: When a PUT permanently fails (550 or !r.ok), outstanding_changes
87
- // is incremented but never decremented. If this happens repeatedly, the
88
- // client will eventually hit max_outstanding_changes and stop sending.
89
- // This is arguably a bug in the JS implementation too.
72
+ // - HTTP 401, 403, 408, 429, 500, 502, 503, 504, etc.: retried
73
+ // - HTTP 550: out of sync — stop retrying, throw error. The
74
+ // client must be torn down and restarted from scratch.
90
75
  //
91
76
  // --- Local Edit Absorption ---
92
77
  //
@@ -107,8 +92,6 @@ function simpleton_client(url, {
107
92
  on_state,
108
93
  get_patches,
109
94
  get_state,
110
- apply_remote_update, // DEPRECATED
111
- generate_local_diff_update, // DEPRECATED
112
95
  content_type,
113
96
 
114
97
  on_error,
@@ -127,10 +110,6 @@ function simpleton_client(url, {
127
110
  var throttled_update = null
128
111
  var ac = new AbortController()
129
112
 
130
- // temporary: our old code uses this deprecated api,
131
- // and our old code wants to send digests..
132
- if (apply_remote_update) send_digests = true
133
-
134
113
  // ── Subscription (GET) ──────────────────────────────────────────────
135
114
  //
136
115
  // Opens a long-lived GET subscription with retry: () => true, meaning
@@ -211,28 +190,23 @@ function simpleton_client(url, {
211
190
  }
212
191
 
213
192
  // ── Apply the update ────────────────────────────────
214
- if (apply_remote_update) {
215
- // DEPRECATED path
216
- client_state = apply_remote_update(update)
193
+ // Convert initial snapshot body to a patch replacing
194
+ // [0,0] — so initial load follows the same code path
195
+ // as incremental patches.
196
+ var patches = update.patches ||
197
+ [{range: [0, 0], content: update.state}]
198
+ if (on_patches) {
199
+ // EXTERNAL MODE: Apply patches to the UI, then
200
+ // read back the full state. Note: this absorbs
201
+ // any un-flushed local edits into client_state.
202
+ on_patches(patches)
203
+ client_state = get_state()
217
204
  } else {
218
- // Convert initial snapshot body to a patch replacing
219
- // [0,0] so initial load follows the same code path
220
- // as incremental patches.
221
- var patches = update.patches ||
222
- [{range: [0, 0], content: update.state}]
223
- if (on_patches) {
224
- // EXTERNAL MODE: Apply patches to the UI, then
225
- // read back the full state. Note: this absorbs
226
- // any un-flushed local edits into client_state.
227
- on_patches(patches)
228
- client_state = get_state()
229
- } else {
230
- // INTERNAL MODE: Apply patches to our internal
231
- // state only. Local edits in the UI are NOT
232
- // absorbed — they will be captured by the next
233
- // changed() diff.
234
- client_state = apply_patches(client_state, patches)
235
- }
205
+ // INTERNAL MODE: Apply patches to our internal
206
+ // state only. Local edits in the UI are NOT
207
+ // absorbed they will be captured by the next
208
+ // changed() diff.
209
+ client_state = apply_patches(client_state, patches)
236
210
  }
237
211
 
238
212
  // ── Digest verification ─────────────────────────────
@@ -278,18 +252,11 @@ function simpleton_client(url, {
278
252
  // during a PUT round-trip are eventually sent.
279
253
  changed: () => {
280
254
  function get_change() {
281
- if (generate_local_diff_update) {
282
- // DEPRECATED
283
- var update = generate_local_diff_update(client_state)
284
- if (!update) return null
285
- return update
286
- } else {
287
- var new_state = get_state()
288
- if (new_state === client_state) return null
289
- var patches = get_patches ? get_patches(client_state) :
290
- [simple_diff(client_state, new_state)]
291
- return {patches, new_state}
292
- }
255
+ var new_state = get_state()
256
+ if (new_state === client_state) return null
257
+ var patches = get_patches ? get_patches(client_state) :
258
+ [simple_diff(client_state, new_state)]
259
+ return {patches, new_state}
293
260
  }
294
261
 
295
262
  var change = get_change()
@@ -357,9 +324,9 @@ function simpleton_client(url, {
357
324
  // Uses braid_fetch with retry: (res) => res.status !== 550
358
325
  // This means:
359
326
  // - Network failures: retried with backoff
360
- // - HTTP 408, 429, 500, 502, 503, 504: retried
361
- // - HTTP 550 (permanent rejection): give up, throw
362
- // - Other non-ok: throws via !r.ok check below
327
+ // - HTTP 401, 403, 408, 429, 500, 502, 503, 504: retried
328
+ // - HTTP 550 (Repr-Digest mismatch / out of sync):
329
+ // give up, throw client must be re-created
363
330
  outstanding_changes++
364
331
  try {
365
332
  var r = await braid_fetch(url, {
@@ -373,13 +340,11 @@ function simpleton_client(url, {
373
340
  version, parents, patches,
374
341
  peer
375
342
  })
376
- if (!r.ok) throw new Error(`bad http status: ${r.status}${(r.status === 401 || r.status === 403) ? ` (access denied)` : ''}`)
343
+ if (!r.ok) throw new Error(`bad http status: ${r.status}`)
377
344
  } catch (e) {
378
- // On error, notify and exit the loop.
379
- // NOTE: outstanding_changes is NOT decremented here.
380
- // This is arguably a bug — repeated failures will
381
- // eventually hit max_outstanding_changes and stop
382
- // the client from sending any more edits.
345
+ // A 550 means Repr-Digest check failed — we're out
346
+ // of sync. The client must be torn down and
347
+ // re-created from scratch.
383
348
  on_error(e)
384
349
  throw e
385
350
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",