multiple delete
DavidBiesack opened this issue · comments
I see some test cases for deleting multiple items from an array; the index is relative to
the input document, so
{
"operations": [
{ "op": "remove", "path": "/path/1" },
{ "op": "remove", "path": "/path/2" }
}
would remove the first and second item. It is the same as
not remove item 1, then shifting items and remove what is now the second item (effectively deleting item 3, then 1)
http://tools.ietf.org/html/rfc6902 is not clear about the semantics of the following
{
"operations": [
{ "op": "remove", "path": "/path/2" },
{ "op": "remove", "path": "/path/2" }
}
The paths refer to the items in the input document, so /path/2 exists . Is the above an error, or is
it equivalent to
{
"operations": [
{ "op": "remove", "path": "/path/2" }
}
From my understanding, order of operation does matter. From the spec:
If removing an element from an array, any elements above the specified index are shifted one position to the left.
To me, that implies that the shift would occur after each operation rather than each operation having the original scope of the document. This is certainly not convenient since the client would need to maintain the relative index of array elements for each remove operation that is applied, but if ordering didn't matter, adding or modifying elements relative to the base document would also be confusion to work with.
Although it could be more clear, my gut tells me operations are not commutative and therefore relative to the previous operation.
OK, I misread the test
{ "comment": "test repeated removes",
"doc": [1, 2, 3, 4],
"patch": [{ "op": "remove", "path": "/1" },
{ "op": "remove", "path": "/2" }],
"expected": [1, 3] },
because "remove" uses 0-based indexing, but the data is not 0 based. I think this might be a better example:
{ "comment": "test repeated removes",
"doc": [0, 1, 2, 3, 4],
"patch": [{ "op": "remove", "path": "/1" },
{ "op": "remove", "path": "/2" }],
"expected": [0, 2, 4] },