braid-text 0.2.30 → 0.2.31
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/README.md +7 -3
- package/index.js +4 -24
- package/package.json +1 -1
- package/test/test.html +15 -0
package/README.md
CHANGED
|
@@ -105,7 +105,11 @@ http_server.on("request", (req, res) => {
|
|
|
105
105
|
apply_remote_update: ({ state, patches }) => {
|
|
106
106
|
|
|
107
107
|
// Apply the incoming state or patches to local text here.
|
|
108
|
-
|
|
108
|
+
//
|
|
109
|
+
// Example data:
|
|
110
|
+
// state: "Hello World" // The new text
|
|
111
|
+
// patches: [{ range: [5, 5], content: " World" }] // Patches that create the new text
|
|
112
|
+
//
|
|
109
113
|
// Then return the new state of textarea as a string:
|
|
110
114
|
return new_state
|
|
111
115
|
},
|
|
@@ -114,8 +118,8 @@ http_server.on("request", (req, res) => {
|
|
|
114
118
|
// Compute diff between prev_state ^ and the current textarea string, such as:
|
|
115
119
|
//
|
|
116
120
|
// var patches = [{
|
|
117
|
-
// range: [5
|
|
118
|
-
// content: " World"
|
|
121
|
+
// range: [5, 5], // The range from position 5 to position 5
|
|
122
|
+
// content: " World" // is replaced with the string " World"
|
|
119
123
|
// }]
|
|
120
124
|
//
|
|
121
125
|
// ...to insert something after a prev_state of "Hello".
|
package/index.js
CHANGED
|
@@ -176,31 +176,11 @@ braid_text.serve = async (req, res, options = {}) => {
|
|
|
176
176
|
} catch (e) {
|
|
177
177
|
console.log(`${req.method} ERROR: ${e.stack}`)
|
|
178
178
|
if (e.message?.startsWith(MISSING_PARENT_VERSION)) {
|
|
179
|
-
// we couldn't apply the version, because we're missing its parents
|
|
180
|
-
// we want to send
|
|
179
|
+
// we couldn't apply the version, because we're missing its parents;
|
|
180
|
+
// we want to send some kind of error that gives the client faith,
|
|
181
|
+
// that resending this request later may work,
|
|
181
182
|
// hopefully after we've received the necessary parents.
|
|
182
|
-
|
|
183
|
-
// here are some 4XX error code options..
|
|
184
|
-
//
|
|
185
|
-
// - 425 Too Early
|
|
186
|
-
// - pros: our message is too early
|
|
187
|
-
// - cons: associated with some "Early-Data" http thing, which we're not using
|
|
188
|
-
// - 400 Bad Request
|
|
189
|
-
// - pros: pretty generic
|
|
190
|
-
// - cons: implies client shouldn't resend as-is
|
|
191
|
-
// - 409 Conflict
|
|
192
|
-
// - pros: doesn't imply modifications needed
|
|
193
|
-
// - cons: the message is not conflicting with anything
|
|
194
|
-
// - 412 Precondition Failed
|
|
195
|
-
// - pros: kindof true.. the precondition of having another version has failed..
|
|
196
|
-
// - cons: not strictly true, as this code is associated with http's If-Unmodified-Since stuff
|
|
197
|
-
// - 422 Unprocessable Content
|
|
198
|
-
// - pros: it's true
|
|
199
|
-
// - cons: implies client shouldn't resend as-is (at least, it says that here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422)
|
|
200
|
-
// - 428 Precondition Required
|
|
201
|
-
// - pros: the name sounds right
|
|
202
|
-
// - 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
|
|
203
|
-
return done_my_turn(400, e.message, 'Missing Parents', { 'Retry-After': '1' })
|
|
183
|
+
return done_my_turn(309, e.message, 'Missing Parents', { 'Retry-After': '1' })
|
|
204
184
|
} else {
|
|
205
185
|
return done_my_turn(500, "The server failed to apply this version. The error generated was: " + e)
|
|
206
186
|
}
|
package/package.json
CHANGED
package/test/test.html
CHANGED
|
@@ -61,6 +61,21 @@ async function runTest(testName, testFunction, expectedResult) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
runTest(
|
|
65
|
+
"test error code when missing parents",
|
|
66
|
+
async () => {
|
|
67
|
+
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
68
|
+
let r = await braid_fetch(`/${key}`, {
|
|
69
|
+
method: 'PUT',
|
|
70
|
+
version: ['hi-1'],
|
|
71
|
+
parents: ['missing-0'],
|
|
72
|
+
body: 'xx'
|
|
73
|
+
})
|
|
74
|
+
return r.status + ' ' + r.ok
|
|
75
|
+
},
|
|
76
|
+
'309 false'
|
|
77
|
+
)
|
|
78
|
+
|
|
64
79
|
runTest(
|
|
65
80
|
"test subscribing starting at a version using simpleton",
|
|
66
81
|
async () => {
|