Extended operations a.k.a. user-defined operations #284
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello there! I've been using this library in a number of projects and have found it very useful.
Recently, at my company I needed the ability to perform simple mutations of JSON documents beyond those defined in the RFC-6902 specification. I really love the way the RFC defined its patch operation objects and wondered if there would be a way to extend that schema into user-defined operations. ("smart patches", if you will...)
I wound up implementing the specific changes I needed in our product, but quickly realized that it could be generalized to "reasonably arbitrary" operations and also work along side of the standard patch operations, and that we would have need to utilize such functionality immediately.
Using the JSON-Patch library as a starting point, I added "hooks" to allow processing of user-defined operation logic. It worked very well with almost no impact to the existing behavior and API.
I wasn't really planning on publishing this fork myself, (though I am using this code in production), but It seems like this functionality could be helpful to others, so I did some refactoring and added a full suite of tests and documentation and am submitting this pull request in case you'd like to incorporate this functionality into the public library as a major version release.
Please check out the docs in 'EXTENDED.md' for a much better overview of what this branch is all about.
The tests are at 'test/spec/extendedSpec.mjs'
I tried my best to not disturb any existing core functionality (core API is the same, all core tests pass w/o modifications) and match existing coding style.
Thanks for the hard work so far. JSON-Patch has been very helpful in several of my projects.
I hope you'll find this pull useful as well.
Cheers!