Compare commits

..

22 Commits

Author SHA1 Message Date
995ae20502 1.0.13 2020-09-19 14:58:07 +00:00
5c805e57a2 fix(core): update 2020-09-19 14:58:06 +00:00
938207f1c5 1.0.12 2020-09-19 14:38:29 +00:00
e810bd9473 fix(core): update 2020-09-19 14:38:29 +00:00
10d1bb35ce 1.0.11 2020-09-19 14:35:55 +00:00
8e97b51f1f fix(core): update 2020-09-19 14:35:54 +00:00
7159b33425 1.0.10 2020-09-19 14:02:15 +00:00
5860066621 fix(core): update 2020-09-19 14:02:15 +00:00
fca8c434f6 1.0.9 2020-09-18 10:12:03 +00:00
6bd3bd4f37 fix(core): update 2020-09-18 10:12:02 +00:00
068199b5e9 1.0.8 2020-07-11 17:19:29 +00:00
0eb8193e4a fix(core): update 2020-07-11 17:19:29 +00:00
34e898e0cf 1.0.7 2020-07-11 17:15:25 +00:00
3530e376d6 fix(core): update 2020-07-11 17:15:24 +00:00
ef141659e2 1.0.6 2020-07-11 16:26:36 +00:00
0b3dec53dd fix(core): update 2020-07-11 16:26:35 +00:00
1d5cb914ac 1.0.5 2020-07-09 23:03:47 +00:00
ce7a457509 fix(core): update 2020-07-09 23:03:46 +00:00
89875393ef 1.0.4 2020-07-09 23:03:02 +00:00
fe2c6f312b fix(core): update 2020-07-09 23:03:01 +00:00
905238a962 1.0.3 2020-07-09 22:39:36 +00:00
e7cd65fbae fix(core): update 2020-07-09 22:39:35 +00:00
7 changed files with 1309 additions and 1023 deletions

2165
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/webstore", "name": "@pushrocks/webstore",
"version": "1.0.2", "version": "1.0.13",
"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",
@ -8,20 +8,20 @@
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/ --web)",
"build": "(tsbuild)", "build": "(tsbuild --web)"
"format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.39", "@gitzone/tstest": "^1.0.44",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.20", "@types/node": "^14.11.1",
"tslint": "^6.1.2", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"idb": "^5.0.4" "@pushrocks/smartpromise": "^3.0.6",
"idb": "^5.0.6"
}, },
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"

View File

@ -1,11 +1,44 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as webstore from '../ts/index'; import * as webstore from '../ts/index';
let testWebstore = new webstore.WebStore(); let testWebstore: webstore.WebStore;
tap.test('first test', async () => { tap.test('first test', async () => {
testWebstore = new webstore.WebStore(); testWebstore = new webstore.WebStore({
dbName: 'mytest-db',
storeName: 'mytest-store',
});
expect(testWebstore).to.be.instanceOf(webstore.WebStore); expect(testWebstore).to.be.instanceOf(webstore.WebStore);
}); });
tap.test('should init the database', async () => {
await testWebstore.init();
});
tap.test('should allow storing a string', async () => {
await testWebstore.set('mystring', 'heythere');
expect(await testWebstore.get('mystring')).to.equal('heythere');
});
tap.test('should allow storing an object', async () => {
await testWebstore.set('testProp1', {
wow: 'wowVal',
});
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();

View File

@ -1 +1 @@
export * from './webstiore.classes.webstore'; export * from './webstore.classes.webstore';

View File

@ -1,5 +0,0 @@
import * as plugins from './webstore.plugins';
export class WebStore {
}

View File

@ -0,0 +1,61 @@
import * as plugins from './webstore.plugins';
export interface IWebStoreOptions {
dbName: string;
storeName: string;
}
export class WebStore<T = any> {
public db: plugins.idb.IDBPDatabase;
public objectStore: plugins.idb.IDBPObjectStore;
public options: IWebStoreOptions;
private initCalled: boolean = false;
private readyDeferred = plugins.smartpromise.defer();
constructor(optionsArg: IWebStoreOptions) {
this.options = optionsArg;
}
public async init() {
if (this.initCalled) {
return this.readyDeferred.promise;
}
this.initCalled = true;
this.db = await plugins.idb.openDB(this.options.dbName, 1, {
upgrade: (db) => {
db.createObjectStore(this.options.storeName);
},
});
this.readyDeferred.resolve();
}
async get(key: string): Promise<T> {
await this.init();
return this.db.get(this.options.storeName, key);
}
async check(keyArg: string): Promise<boolean> {
await this.init();
const result = await this.get(keyArg);
return !!result;
}
async set(key: string, val: T) {
return this.db.put(this.options.storeName, val, key);
}
async delete(key: string) {
await this.init();
return this.db.delete(this.options.storeName, key);
}
async clear() {
await this.init();
return this.db.clear(this.options.storeName);
}
async keys() {
await this.init();
return this.db.getAllKeys(this.options.storeName);
}
}

View File

@ -1,5 +1,11 @@
import * as idb from 'idb'; // pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
export { export {
idb smartpromise
} };
// thirdparty scope
import * as idb from 'idb';
export { idb };