cujojs / jiff

JSON Patch and diff based on rfc6902
Other
627 stars 41 forks source link

Which operations are generated using `jiff.diff` #24

Closed emilbayes closed 9 years ago

emilbayes commented 9 years ago

I'm developing a MongoDB adapter for JSON Patches and am using jiff to do diffs. Because some operations are not possible with the underlying query language I was wondering if I might make do with just a subset of the operations defined in the RFC.

So I have a couple of questions, that I think I've got the answers to from reading the source, but I'd love if you could confirm:

briancavalier commented 9 years ago

Hey @emilbayes, that sounds like a cool project!

Is /arr/- reference used?

jiff.diff will not generate patches containing the /arr/- syntax. However, jiff.patch will handle patches containing that syntax.

Are only add, remove, replace and test used?

Yes, that is correct. jiff.diff will not generate move or copy.

Another thing that you may need to know if that jiff.diff currently produces "safe" patches. Each operation is preceded by a test that verifies its precondition. That's not a requirement of the RFC, but it is the only way to produce patches that are invertible. In general, I think it's a good thing, but it does mean that patches are larger. If that's a problem for your use case, let me know. I think we could consider adding an option to disable the extra test ops.

emilbayes commented 9 years ago

I see the extra test ops as a strength (at least in theory). My intention is to use these to do the "select" part of the query, and do "update" using the modifying operations. Thanks for the feedback!

briancavalier commented 9 years ago

Cool. happy to help.