mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 16:54:08 +00:00
Implement typescript strict mode and ESLint in ipld-eth-client and cache packages (#37)
* Set up typescript build. * Setup eslint in cache package. * Automatic lint fixes. * Fix typescript return types. * Fix typescript argument type warnings. * Set up typescript build and eslint. * Automatic lint fixes. * Fix typescript explicit any warnings. * Add argument types. * Fix return type warnings. * Fix typescript errors. * Implement declaration in types directory. Co-authored-by: nikugogoi <95nikass@gmail.com>
This commit is contained in:
co-authored by
nikugogoi
parent
47ce52c112
commit
4e0ef7c852
Vendored
+15
-10
@@ -8,12 +8,18 @@ import debug from 'debug';
|
||||
|
||||
const log = debug('vulcanize:cache');
|
||||
|
||||
export const getCache = async (config) => {
|
||||
interface Config {
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
deleteOnStart: boolean;
|
||||
}
|
||||
|
||||
export const getCache = async (config: Config): Promise<undefined | Cache> => {
|
||||
let cache;
|
||||
|
||||
// Cache is optional.
|
||||
if (config) {
|
||||
log("config", JSON.stringify(config, null, 2));
|
||||
log('config', JSON.stringify(config, null, 2));
|
||||
|
||||
const { name, enabled, deleteOnStart } = config;
|
||||
|
||||
@@ -37,23 +43,22 @@ export const getCache = async (config) => {
|
||||
};
|
||||
|
||||
export class Cache {
|
||||
|
||||
_db: any;
|
||||
_name: string;
|
||||
|
||||
constructor(name, dirPath) {
|
||||
constructor (name: string, dirPath: string) {
|
||||
assert(name);
|
||||
assert(dirPath);
|
||||
|
||||
this._name = name;
|
||||
this._db = level(dirPath, { valueEncoding: 'json' });;
|
||||
this._db = level(dirPath, { valueEncoding: 'json' });
|
||||
}
|
||||
|
||||
key(obj) {
|
||||
key (obj: any): string {
|
||||
return this._cacheKey(obj);
|
||||
}
|
||||
|
||||
async get(obj) {
|
||||
async get (obj: any): Promise<[any, boolean] | undefined> {
|
||||
const key = this._cacheKey(obj);
|
||||
|
||||
try {
|
||||
@@ -66,16 +71,16 @@ export class Cache {
|
||||
log(`${this._name}: cache miss ${key}`);
|
||||
|
||||
if (err.notFound) {
|
||||
return [undefined, false]
|
||||
return [undefined, false];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async put(obj, value) {
|
||||
async put (obj: any, value: any): Promise<void> {
|
||||
await this._db.put(this._cacheKey(obj), value);
|
||||
}
|
||||
|
||||
_cacheKey(obj) {
|
||||
_cacheKey (obj: any): string {
|
||||
return ethers.utils.keccak256(Buffer.from(canonicalStringify(obj)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user