feat: add serialize mutation option for queued (serialised) mutations - #149
Merged
Conversation
- New `serialize?: boolean | string` option on MutationOptions: true derives a TanStack mutation scope id from the operation's method + resolved path; a string is used verbatim for cross-operation grouping - Explicit `scope` wins over `serialize` (warning emitted once) - Deferred path params fall back to the path template scope id (documented) - Unit tests for sequential execution, concurrency guard, cross-operation grouping, scope precedence, order preservation, and error non-blocking - Typing tests for boolean | string acceptance - README 'Serialised mutations' section, CHANGELOG entry, version 0.23.0
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class support for serialised (queued) mutations via a new serialize?: boolean | string option on mutation options, mapping to TanStack Query v5 mutation scope and documenting/testing the behavior.
Changes:
- Introduces
serializeonMutationOptionsand derives a TanStackscope.idautomatically from method + resolved path (or uses a caller-provided string scope). - Implements serialization scope handling in
useEndpointMutation, including “explicit scope wins” warning behavior and ensuringserializedoesn’t leak to axios. - Adds unit + typing tests, plus README/CHANGELOG updates and a version bump.
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/mutation-serialize.test.ts | New unit tests covering queued execution, precedence rules, and non-leakage. |
| tests/typing/mutation-serialize.ts | New compile-time checks for serialize’s accepted/rejected types. |
| src/types.ts | Adds serialize?: boolean | string to MutationOptions with detailed docs. |
| src/openapi-mutation.ts | Derives/passes TanStack mutation scope from serialize and handles precedence + warning. |
| README.md | Documents “Serialised mutations” usage and caveats. |
| package.json | Bumps version to 0.23.0. |
| package-lock.json | Updates lockfile version metadata to 0.23.0. |
| CHANGELOG.md | Adds 0.23.0 entry documenting the new feature. |
| .prettierignore | Ignores subagent artifact directory. |
| .gitignore | Ignores subagent artifact directory. |
Address Copilot review: serialize was checked with truthiness, so serialize: '' was silently ignored. Enable serialization whenever serialize !== undefined && serialize !== false, matching the documented 'string used verbatim' contract. Add empty-string serialization test.
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
Adds first-class support for serialised (queued) mutations via a new
serializeoption onMutationOptions, wrapping TanStack Query v5 mutationscopewith an ergonomic, typed, auto-keyed API. Replaces consumer-side hacks (e.g. manual save queues) for auto-save / last-write-wins flows.Changes
serialize?: boolean | stringonMutationOptions:truederives the scope id from the operation's method + resolved path (e.g.serialize:PATCH:/api/contract/123), so mutations of the same resource queue automatically while different resources stay concurrentscopepassed by the caller wins overserialize(warning emitted once)mutateAsync) fall back to the path-template scope id: coarser but correct, documented in typedoc and READMEserializeis stripped before options reachuseMutation(does not leak)serializeon mutation vars deliberately omitted: TanStackscopeis static per observer, so a per-call override would be a silent no-opTests
tests/unit/mutation-serialize.test.ts(7 tests): sequential execution with deferred-promise mocks, concurrency guard withoutserialize, cross-operation string scope, explicit-scope-wins + single warning, order preservation, error in first does not block queued second, no leak into axios configtests/typing/mutation-serialize.ts:boolean | stringaccepted, number rejectedRelease
Validation
npm run check(types, types:test, lint, format:check) ✅npx vitest run tests/unit/mutation-serialize.test.ts→ 7/7 ✅Implements the plan in OPENAPI_SERIAL.md via a reviewed subagent chain (implement → test → review → finalize → quality gate).