braid-text 0.0.12 → 0.0.13

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.
Files changed (2) hide show
  1. package/index.js +18 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -118,20 +118,28 @@ braid_text.serve = async (req, res, options = {}) => {
118
118
  done()
119
119
  })
120
120
  )
121
- let patches = await req.patches()
121
+ let patches = null
122
+ let ee = null
123
+ try {
124
+ patches = await req.patches()
125
+ } catch (e) { ee = e }
122
126
  await my_prev_put_p
123
127
 
124
- let body = null
125
- if (patches[0]?.unit === 'everything') {
126
- body = patches[0].content
127
- patches = null
128
- }
129
-
130
128
  try {
129
+ if (ee) throw ee
130
+
131
+ let body = null
132
+ if (patches[0]?.unit === 'everything') {
133
+ body = patches[0].content
134
+ patches = null
135
+ }
136
+
131
137
  await braid_text.put(resource, { peer, version: req.version, parents: req.parents, patches, body, merge_type: req.headers["merge-type"] })
138
+
139
+ options.put_cb(options.key, resource.doc.get())
132
140
  } catch (e) {
133
141
  console.log(`EEE= ${e}:${e.stack}`)
134
- // we couldn't apply the version, presumably because we're missing its parents.
142
+ // we couldn't apply the version, possibly because we're missing its parents,
135
143
  // we want to send a 4XX error, so the client will resend this request later,
136
144
  // hopefully after we've received the necessary parents.
137
145
 
@@ -155,11 +163,9 @@ braid_text.serve = async (req, res, options = {}) => {
155
163
  // - 428 Precondition Required
156
164
  // - pros: the name sounds right
157
165
  // - 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
158
- return done_my_turn(425, "The server is missing the parents of this version.")
166
+ return done_my_turn(425, "The server failed to apply this version.")
159
167
  }
160
168
 
161
- options.put_cb(options.key, resource.doc.get())
162
-
163
169
  return done_my_turn(200)
164
170
  }
165
171
 
@@ -544,11 +550,7 @@ async function file_sync(key, process_delta, get_init) {
544
550
  let threshold = 0
545
551
 
546
552
  // Ensure the existence of db_folder
547
- try {
548
- await fs.promises.access(braid_text.db_folder);
549
- } catch (err) {
550
- await fs.promises.mkdir(braid_text.db_folder, { recursive: true });
551
- }
553
+ await fs.promises.mkdir(braid_text.db_folder, { recursive: true });
552
554
 
553
555
  // Read existing files and sort by numbers.
554
556
  const files = (await get_files_for_key(key))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidjs",