Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
dac5342a19 | |||
1829db1d82 | |||
3c4cba97c2 | |||
b86bd61cbf | |||
ad95154284 | |||
7fb47d224e | |||
40175dc4de | |||
115d461d29 | |||
00964a7db1 | |||
b00db37bf4 |
@ -19,23 +19,36 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
audit:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -50,9 +63,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@ -63,9 +74,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -85,6 +94,8 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23626
package-lock.json
generated
23626
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/webstore",
|
"name": "@pushrocks/webstore",
|
||||||
"version": "1.0.13",
|
"version": "1.0.18",
|
||||||
"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",
|
||||||
@ -12,16 +12,20 @@
|
|||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.29",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.60",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^4.0.0",
|
||||||
"@types/node": "^14.11.1",
|
"@types/node": "^17.0.10",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||||
"idb": "^5.0.6"
|
"@pushrocks/lik": "^5.0.0",
|
||||||
|
"@pushrocks/smartjson": "^4.0.6",
|
||||||
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
|
"@pushrocks/smartrx": "^2.0.20",
|
||||||
|
"idb": "^7.0.0"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
11
test/test.typedrequestcache.browser.ts
Normal file
11
test/test.typedrequestcache.browser.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as webstore from '../ts/index';
|
||||||
|
|
||||||
|
let testTypedrequestcache: webstore.TypedrequestCache;
|
||||||
|
|
||||||
|
tap.test('first test', async () => {
|
||||||
|
testTypedrequestcache = new webstore.TypedrequestCache('https://test.lossless.com/typedrequest')
|
||||||
|
expect(testTypedrequestcache).toBeInstanceOf(webstore.TypedrequestCache);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -8,16 +8,12 @@ tap.test('first test', async () => {
|
|||||||
dbName: 'mytest-db',
|
dbName: 'mytest-db',
|
||||||
storeName: 'mytest-store',
|
storeName: 'mytest-store',
|
||||||
});
|
});
|
||||||
expect(testWebstore).to.be.instanceOf(webstore.WebStore);
|
expect(testWebstore).toBeInstanceOf(webstore.WebStore);
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should init the database', async () => {
|
|
||||||
await testWebstore.init();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should allow storing a string', async () => {
|
tap.test('should allow storing a string', async () => {
|
||||||
await testWebstore.set('mystring', 'heythere');
|
await testWebstore.set('mystring', 'heythere');
|
||||||
expect(await testWebstore.get('mystring')).to.equal('heythere');
|
expect(await testWebstore.get('mystring')).toEqual('heythere');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should allow storing an object', async () => {
|
tap.test('should allow storing an object', async () => {
|
||||||
@ -37,8 +33,8 @@ tap.test('should overwrite a value', async () => {
|
|||||||
tap.test('should correctly check the existence of keys', async () => {
|
tap.test('should correctly check the existence of keys', async () => {
|
||||||
const resultNotThere = await testWebstore.check('notThere');
|
const resultNotThere = await testWebstore.check('notThere');
|
||||||
const resultThere = await testWebstore.check('testProp1');
|
const resultThere = await testWebstore.check('testProp1');
|
||||||
expect(resultNotThere).to.be.false;
|
expect(resultNotThere).toBeFalse();
|
||||||
expect(resultThere).to.be.true;
|
expect(resultThere).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
@ -1 +1,2 @@
|
|||||||
|
export * from './webstore.classes.typedrequestcache';
|
||||||
export * from './webstore.classes.webstore';
|
export * from './webstore.classes.webstore';
|
||||||
|
47
ts/webstore.classes.typedrequestcache.ts
Normal file
47
ts/webstore.classes.typedrequestcache.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { WebStore } from './webstore.classes.webstore';
|
||||||
|
import * as plugins from './webstore.plugins';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a cache that can be used to store and retrieve typedrequests
|
||||||
|
*/
|
||||||
|
export class TypedrequestCache {
|
||||||
|
private webstore: WebStore;
|
||||||
|
|
||||||
|
constructor(domainArg = 'default') {
|
||||||
|
this.webstore = new WebStore<plugins.typedrequestInterfaces.ITypedRequest>({
|
||||||
|
dbName: 'trStore',
|
||||||
|
storeName: `trStore-${domainArg}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildKey(requestArg: plugins.typedrequestInterfaces.ITypedRequest) {
|
||||||
|
return plugins.smartjson.stringify({
|
||||||
|
method: requestArg.method,
|
||||||
|
request: requestArg.request,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stores by request
|
||||||
|
* @param typedrequestarg
|
||||||
|
*/
|
||||||
|
public async setByRequest(
|
||||||
|
typedrequestArg: plugins.typedrequestInterfaces.ITypedRequest
|
||||||
|
): Promise<void> {
|
||||||
|
if (!typedrequestArg.response) {
|
||||||
|
throw new Error('You cannot store requests without a response present');
|
||||||
|
}
|
||||||
|
await this.webstore.set(this.buildKey(typedrequestArg), typedrequestArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get by full tyoedrequest by partial typedrequest
|
||||||
|
* @param typedrequestarg
|
||||||
|
*/
|
||||||
|
public async getByRequest(
|
||||||
|
typedrequestArg: plugins.typedrequestInterfaces.ITypedRequest
|
||||||
|
): Promise<plugins.typedrequestInterfaces.ITypedRequest> {
|
||||||
|
const result = await this.webstore.get(this.buildKey(typedrequestArg));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,8 @@ export class WebStore<T = any> {
|
|||||||
|
|
||||||
public async init() {
|
public async init() {
|
||||||
if (this.initCalled) {
|
if (this.initCalled) {
|
||||||
return this.readyDeferred.promise;
|
await this.readyDeferred.promise;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.initCalled = true;
|
this.initCalled = true;
|
||||||
this.db = await plugins.idb.openDB(this.options.dbName, 1, {
|
this.db = await plugins.idb.openDB(this.options.dbName, 1, {
|
||||||
@ -27,6 +28,7 @@ export class WebStore<T = any> {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.readyDeferred.resolve();
|
this.readyDeferred.resolve();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(key: string): Promise<T> {
|
async get(key: string): Promise<T> {
|
||||||
@ -41,6 +43,7 @@ export class WebStore<T = any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async set(key: string, val: T) {
|
async set(key: string, val: T) {
|
||||||
|
await this.init();
|
||||||
return this.db.put(this.options.storeName, val, key);
|
return this.db.put(this.options.storeName, val, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
|
import * as lik from '@pushrocks/lik';
|
||||||
|
import * as smartjson from '@pushrocks/smartjson';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
export {
|
export { lik, smartjson, smartpromise, smartrx };
|
||||||
smartpromise
|
|
||||||
};
|
// apiglobal scope
|
||||||
|
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||||
|
|
||||||
|
export { typedrequestInterfaces };
|
||||||
|
|
||||||
// thirdparty scope
|
// thirdparty scope
|
||||||
import * as idb from 'idb';
|
import * as idb from 'idb';
|
||||||
|
Reference in New Issue
Block a user