fix(core): update
This commit is contained in:
43
ts/webstore.classes.typedrequestcache.ts
Normal file
43
ts/webstore.classes.typedrequestcache.ts
Normal file
@ -0,0 +1,43 @@
|
||||
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 = new WebStore<plugins.typedrequestInterfaces.ITypedRequest>({
|
||||
dbName: 'trStore',
|
||||
storeName: 'trStore',
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,9 +1,15 @@
|
||||
// pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartjson from '@pushrocks/smartjson';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartrx from '@pushrocks/smartrx';
|
||||
|
||||
export {
|
||||
smartpromise
|
||||
};
|
||||
export { lik, smartjson, smartpromise, smartrx };
|
||||
|
||||
// apiglobal scope
|
||||
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||
|
||||
export { typedrequestInterfaces };
|
||||
|
||||
// thirdparty scope
|
||||
import * as idb from 'idb';
|
||||
|
Reference in New Issue
Block a user