Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
34e898e0cf | |||
3530e376d6 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/webstore",
|
"name": "@pushrocks/webstore",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/webstore",
|
"name": "@pushrocks/webstore",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "high performance storage in the browser using indexed db",
|
"description": "high performance storage in the browser using indexed db",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -5,8 +5,8 @@ let testWebstore: webstore.WebStore;
|
|||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
testWebstore = new webstore.WebStore({
|
testWebstore = new webstore.WebStore({
|
||||||
dbName: 'mytestdb',
|
dbName: 'mytest-db',
|
||||||
storeName: 'myteststore'
|
storeName: 'mytest-store'
|
||||||
});
|
});
|
||||||
expect(testWebstore).to.be.instanceOf(webstore.WebStore);
|
expect(testWebstore).to.be.instanceOf(webstore.WebStore);
|
||||||
});
|
});
|
||||||
@ -22,4 +22,18 @@ tap.test('should store a value', async () => {
|
|||||||
console.log(JSON.stringify(await testWebstore.get('testProp1')));
|
console.log(JSON.stringify(await testWebstore.get('testProp1')));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should overwrite a value', async () => {
|
||||||
|
await testWebstore.set('testProp1', {
|
||||||
|
wow: 'wowVal2'
|
||||||
|
});
|
||||||
|
console.log(JSON.stringify(await testWebstore.get('testProp1')));
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should correctly check the existence of keys', async () => {
|
||||||
|
const resultNotThere = await testWebstore.check('notThere');
|
||||||
|
const resultThere = await testWebstore.check('testProp1');
|
||||||
|
expect(resultNotThere).to.be.false;
|
||||||
|
expect(resultThere).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -23,15 +23,20 @@ export class WebStore<T = any> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(key) {
|
async get(key: string) {
|
||||||
return this.db.get(this.options.storeName, key);
|
return this.db.get(this.options.storeName, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
async set(key, val) {
|
async check(keyArg: string): Promise<boolean> {
|
||||||
|
const result = await this.get(keyArg);
|
||||||
|
return !!result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async set(key: string, val: T) {
|
||||||
return this.db.put(this.options.storeName, val, key);
|
return this.db.put(this.options.storeName, val, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(key) {
|
async delete(key: string) {
|
||||||
return this.db.delete(this.options.storeName, key);
|
return this.db.delete(this.options.storeName, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user