Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NOTIFY-1146): use better type system for user storage #4907

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mathieuartu
Copy link
Contributor

Explanation

This PR adds an enum for feature names so we stop relying on string values for user storage operations.
This enum is also now exported from the packages, in both SDK and UserStorage paths.

References

https://consensyssoftware.atlassian.net/browse/NOTIFY-1146

Changelog

@metamask/profile-sync-controller

  • CHANGED: Better type system for user storage, using a new UserStorageFeatureNames enum

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mathieuartu mathieuartu added the team-notifications Notification Team changes. https://github.com/orgs/MetaMask/teams/notifications label Nov 8, 2024
@mathieuartu mathieuartu marked this pull request as ready for review November 8, 2024 13:43
@mathieuartu mathieuartu requested a review from a team as a code owner November 8, 2024 13:43
Comment on lines +12 to +15
export enum UserStorageFeatureNames {
Notifications = 'notifications',
Accounts = 'accounts_v2',
Networks = 'networks',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to make 100% sure these names are identical to what they were before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I see that account_v2 change lol.

We might not need this as we are resolving the issue through a delete endpoint.

But not against it if we want a fresh clean slate

UserStorageSchema[Feature][0] extends typeof ALLOW_ARBITRARY_KEYS
? string
: UserStorageSchema[Feature][number];

type UserStorageFeatureAndKey = {
feature: UserStorageFeatures;
key: UserStorageFeatureKeys<UserStorageFeatures>;
feature: UserStorageFeatureNames;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice if some outside interfaces are backwards compatible. Supporting string unions or enums.

E.g. if I'm an SDK user, I now have to add an additional import for using user storage. That's not great.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you make sure that we have the correct exports for the subpaths?

E.g. If I'm importing the SDK through /SDK, can I also access the enum from here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-notifications Notification Team changes. https://github.com/orgs/MetaMask/teams/notifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants