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 IndexedDB Store implementation #120

Merged
merged 6 commits into from
Oct 26, 2022
Merged

Conversation

alanshaw
Copy link
Member

An IndexedDB store implementation that uses RSA keys for the browser.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 25, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: a628892
Status: ✅  Deploy successful!
Preview URL: https://bcc367ed.ucan-protocol.pages.dev
Branch Preview URL: https://feat-indexeddb-store.ucan-protocol.pages.dev

View logs

@alanshaw alanshaw temporarily deployed to dev October 25, 2022 16:21 Inactive
@alanshaw alanshaw temporarily deployed to dev October 25, 2022 18:07 Inactive
@alanshaw alanshaw temporarily deployed to dev October 25, 2022 18:10 Inactive
@alanshaw alanshaw marked this pull request as ready for review October 26, 2022 09:01
Copy link
Contributor

@Gozala Gozala left a comment

Choose a reason for hiding this comment

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

Looks ok to me, proposed some changes. I'm not super familiar with the code so might be worth getting some feedback from hugo as well.

* @param {number} [dbVersion]
*/
constructor(dbName, dbVersion) {
this.#dbName = dbName
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these widely enough available for us to use ? If I recall correctly they were considered in js-multiformats but then dropped because adoption was not there yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can put underscores...

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's fine!

Screenshot 2022-10-26 at 18 19 14

packages/access/src/stores/types.ts Outdated Show resolved Hide resolved
packages/access/src/stores/store-indexeddb.js Show resolved Hide resolved
/** @type {import('p-defer').DeferredPromise<boolean>} */
const { resolve, reject, promise } = defer()

const getReq = store.get(DATA_ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I find it handy to have this function around when working with IDB

/**
 * @template T
 * @param {IDBRequest<T>} request
 * @returns {Promise<T>}
 */
const request = (request) => new Promise((succeed, fail) => {
  request.onsuccess = () => succeed(request.result)
  request.onerror = () => fail(request.error)
})

With which you could simply change above line as follows

Suggested change
const getReq = store.get(DATA_ID)
const result = await request(store.get(DATA_ID))

Copy link
Contributor

@hugomrdias hugomrdias left a comment

Choose a reason for hiding this comment

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

LGTM

@alanshaw alanshaw temporarily deployed to dev October 26, 2022 16:06 Inactive
@alanshaw alanshaw temporarily deployed to dev October 26, 2022 17:25 Inactive
@alanshaw alanshaw merged commit 9d73a26 into main Oct 26, 2022
@alanshaw alanshaw deleted the feat/indexeddb-store branch October 26, 2022 17:27
@heyjay44 heyjay44 mentioned this pull request Dec 2, 2022
95 tasks
gobengo pushed a commit that referenced this pull request Apr 11, 2023
An IndexedDB store implementation that uses RSA keys for the browser.
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