Skip to content

feat: stash util / stashable#35

Draft
fratzinger wants to merge 1 commit into
mainfrom
feat/stash-util-stashable
Draft

feat: stash util / stashable#35
fratzinger wants to merge 1 commit into
mainfrom
feat/stash-util-stashable

Conversation

@fratzinger

Copy link
Copy Markdown
Member

This pull request introduces significant improvements and changes to the stashable hook and related utilities in the FeathersJS ecosystem. The stashable hook 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 new stableStringify utility 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 stashable hook is now built to stash all affected records by their id for create, update, patch, or remove calls, supporting before, after, and around phases, and optionally passing the changes to a callback. The result is stored at context.params.stash as a Record<Id, { before, item }>; the API is unified and supports new options like fetchBefore, params, skipHooks, deleteParams, and name. The implementation is now based on the new stash utility. [1] [2]

  • The documentation for stashable is updated with new usage examples, option descriptions, and migration guidance, including how to use the low-level stash util directly for imperative use cases. [1] [2] [3] [4] [5]

  • The old stashBefore and changesById hooks from feathers-hooks-common are now merged into stashable, 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 stableStringify utility 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, and getOrFindByIdParams utilities 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 stableStringify in cache-utils.ts is removed in favor of the new shared utility.

  • The utils/index.ts export 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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant