feat: JSON:API Atomic Operations extension support (v2.2.0)#2
Open
treere wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements support for the JSON:API Atomic Operations extension, allowing clients to submit a batch of
add,update, andremoveoperations in a single request. Atomicity at the database level remains the responsibility of the calling application.This PR targets the
jsonapi1.1branch and builds on top of the JSON:API 1.1 changes introduced in #1.New Modules
JSONAPIPlug.AtomicPlugA
Plug.Builder-based pipeline for Atomic Operations endpoints. It:POSTmethod (returns405otherwise).atomic:operationsrequest body viaAtomicParams.api:andresources:options; resolves JSON:API type strings to resource modules at init time.JSONAPIPlug.Document.AtomicOperationStruct representing a single operation object within an
atomic:operationsdocument. Deserializesop,ref,href,data, andmetamembers; validates thatopis one ofadd,update, orremove; enforces mutual exclusion ofrefandhref.JSONAPIPlug.Document.OperationRefStruct representing the
refmember of an operation object. Requires a non-emptytypeand eitheridorlid; optionally carries arelationshipmember.Changes to Existing Modules
JSONAPIPlug(main module)operationsandresource_typesfields to the%JSONAPIPlug{}struct.render_atomic/3: renders anatomic:resultsdocument from a list of{resource_or_nil, meta_or_nil}tuples. Returnsnilwhen all results are empty, signalling a204 No Contentresponse.JSONAPIPlug.Documentoperationsandresultsfields to%Document{}.deserialize/1now handlesatomic:operationsdocuments; raisesInvalidDocumenton mutual exclusion violations (e.g.atomic:operations+data) or an empty operations array.serialize/1handlesatomic:resultsdocuments, encoding results under theatomic:resultskey.JSONAPIPlug.Normalizerdenormalize/3updated to handle atomic operation lists: returns a list ofConn.params()(one per operation) instead of a single params map.