feat: stash util / stashable#35
Draft
fratzinger wants to merge 1 commit into
Draft
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.
This pull request introduces significant improvements and changes to the
stashablehook and related utilities in the FeathersJS ecosystem. Thestashablehook has been redesigned to provide a more robust and flexible way of tracking changes to records during service mutations, supporting more methods and phases, and offering a unified API for stashing both before and after states of affected records. Additionally, a newstableStringifyutility is added for deterministic object serialization, and documentation is updated to reflect the new APIs and migration paths.Key changes include:
Stashable Hook Redesign and Enhancements
The
stashablehook is now built to stash all affected records by their id forcreate,update,patch, orremovecalls, supportingbefore,after, andaroundphases, and optionally passing the changes to a callback. The result is stored atcontext.params.stashas aRecord<Id, { before, item }>; the API is unified and supports new options likefetchBefore,params,skipHooks,deleteParams, andname. The implementation is now based on the newstashutility. [1] [2]The documentation for
stashableis updated with new usage examples, option descriptions, and migration guidance, including how to use the low-levelstashutil directly for imperative use cases. [1] [2] [3] [4] [5]The old
stashBeforeandchangesByIdhooks fromfeathers-hooks-commonare now merged intostashable, with clear migration instructions provided. The new approach captures all affected records and stores them in a consistent structure. [1] [2] [3] [4]Utilities and Exports
A new
stableStringifyutility is added for deterministic, order-independent serialization of objects, useful for cache keys. This utility is now exported and replaces the previous inline implementation. [1] [2]The new
stash,stashBefore,stashAfter, andgetOrFindByIdParamsutilities are implemented, exported, and covered by comprehensive tests to ensure correct behavior across various hook phases and service methods. [1] [2] [3]Refactoring and Cleanup
The previous in-file implementation of
stableStringifyincache-utils.tsis removed in favor of the new shared utility.The
utils/index.tsexport barrel is updated to include the new utilities for stable stringification and stashing.References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]