Commit 61eb934
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 73db17e commit 61eb934
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 | | |
| |||
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
193 | | - | |
| 195 | + | |
| 196 | + | |
194 | 197 | | |
195 | 198 | | |
196 | 199 | | |
| |||
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
206 | | - | |
| 209 | + | |
| 210 | + | |
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
| |||
226 | 230 | | |
227 | 231 | | |
228 | 232 | | |
229 | | - | |
| 233 | + | |
| 234 | + | |
230 | 235 | | |
231 | 236 | | |
232 | 237 | | |
233 | 238 | | |
234 | 239 | | |
235 | 240 | | |
236 | 241 | | |
237 | | - | |
| 242 | + | |
| 243 | + | |
238 | 244 | | |
239 | 245 | | |
240 | 246 | | |
| |||
| 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