Commit 99885c3
Throw when array and object deletion values do not match current version
This change adds validation to array and object deletion. If the values
provided in either `ld` or `od` do not match the current value, then
`apply` will `throw`. It will also throw if `oi` overwrites an existing
value without providing `od`.
The primary motivation of this change is to ensure that all submitted
ops remain reversible. At the moment, the following series of ops is
possible:
- start with `{ foo: 'bar' }`
- `apply` this op: `{ p: ['foo'], oi: 'baz' }`
- ...resulting in `{ foo: 'baz' }`
- `invert` the previous op: `{ p: ['foo'], od: 'baz' }`
- and `apply` the inverted op: `{}`
When I apply, invert and apply, I should always wind up where I started,
but in this case I clearly do not.
By ensuring that the `od` matches the current value, we make sure that
all ops remain reversible.
Deep equality adds a dependency on [`fast-deep-equal`][1].
[1]: https://github.com/epoberezkin/fast-deep-equal1 parent b89153c commit 99885c3
3 files changed
+30
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
200 | 202 | | |
201 | 203 | | |
202 | 204 | | |
203 | | - | |
| 205 | + | |
| 206 | + | |
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
| |||
213 | 216 | | |
214 | 217 | | |
215 | 218 | | |
216 | | - | |
| 219 | + | |
| 220 | + | |
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
| |||
236 | 240 | | |
237 | 241 | | |
238 | 242 | | |
239 | | - | |
| 243 | + | |
| 244 | + | |
240 | 245 | | |
241 | 246 | | |
242 | 247 | | |
243 | 248 | | |
244 | 249 | | |
245 | 250 | | |
246 | 251 | | |
247 | | - | |
| 252 | + | |
| 253 | + | |
248 | 254 | | |
249 | 255 | | |
250 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
141 | 149 | | |
142 | 150 | | |
143 | 151 | | |
| |||
418 | 426 | | |
419 | 427 | | |
420 | 428 | | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
421 | 434 | | |
422 | 435 | | |
423 | 436 | | |
| |||
0 commit comments