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!: rename static indexeddb store method create to open #211

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/access-client/src/stores/store-indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,21 @@ export class StoreIndexedDB {
}

/**
* Creates a new, opened and initialized store.
* Opens (or creates) a store and initializes it if not already initialized.
*
* @param {string} dbName
* @param {object} [options]
* @param {number} [options.dbVersion]
* @param {string} [options.dbStoreName]
* @returns {Promise<Store>}
*/
static async create(dbName, options) {
static async open(dbName, options) {
const store = new StoreIndexedDB(dbName, options)
await store.open()
await store.init({})
const exists = await store.exists()
if (!exists) {
await store.init({})
}
return store
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StoreIndexedDB } from '../../src/stores/store-indexeddb.js'

describe('IndexedDB store', () => {
it('should create and load data', async () => {
const store = await StoreIndexedDB.create('test-access-db-' + Date.now())
const store = await StoreIndexedDB.open('test-access-db-' + Date.now())
const data = await store.load()
assert(data)

Expand All @@ -23,7 +23,7 @@ describe('IndexedDB store', () => {
})

it('should allow custom store name', async () => {
const store = await StoreIndexedDB.create('test-access-db-' + Date.now(), {
const store = await StoreIndexedDB.open('test-access-db-' + Date.now(), {
dbStoreName: `store-${Date.now()}`,
})
const data = await store.load()
Expand All @@ -44,7 +44,7 @@ describe('IndexedDB store', () => {
})

it('should close and disallow usage', async () => {
const store = await StoreIndexedDB.create('test-access-db-' + Date.now())
const store = await StoreIndexedDB.open('test-access-db-' + Date.now())
const data = await store.load()

await store.close()
Expand Down