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: add storage interface + implement indexedDb #18

Merged
merged 8 commits into from
Oct 11, 2023

Conversation

AmeanAsad
Copy link
Contributor

Changes

  • implements a basic interface for injecting storage as a dependency for the saturn client.
  • adds indexedDb implementation for the storage interface.

@guanzo
Copy link
Collaborator

guanzo commented Oct 11, 2023

Can you add the logic to the Saturn constructor that adds this.storage to the class

@guanzo
Copy link
Collaborator

guanzo commented Oct 11, 2023

Can you implement a basic memory store with a plain object? If opts.storage doesn't exist, then the MemoryStore should be used.

this.storage = opts.storage ?? new MemoryStore()

that way storage is always available

src/utils/storage.js Outdated Show resolved Hide resolved
src/utils/storage.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
/**
* @typedef {object} Storage
* @property {function(string):Promise<any>} get - Retrieves the value associated with the key.
* @property {function(string,any):Promise<void>} set - Sets a new value for the key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can it be any value? Is it serialised automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its not serialised automatically. I guess it could be any value but we have to add some extra handling for some storage implementations. For example localStorage only accepts strings as keys and values so what ever gets passed has to be serialisable as a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gonna merge then, if we need to add support for non-string storage keys we can do that.

src/index.js Outdated Show resolved Hide resolved
@guanzo
Copy link
Collaborator

guanzo commented Oct 11, 2023

update branch then lgtm

@AmeanAsad AmeanAsad merged commit c93305f into main Oct 11, 2023
1 check passed
@AmeanAsad AmeanAsad deleted the feat/storage-interface branch October 11, 2023 19:43
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.

3 participants