Use tsconfig references (#4328)

* Use tsconfig references

* Move types-known (temp until lower-level split)

* Sources

* Adjust

* tesconfig.eslint.json

* Bumps

* AdjustAdjust

* Linting passing... a start...

* Adjust

* Merge derive

* Merge

* api-contract-support

* It builds?

* compare locations
This commit is contained in:
Jaco
2021-12-14 12:04:50 +02:00
committed by GitHub
parent cbb5a021a0
commit 736fd536f9
292 changed files with 1675 additions and 1273 deletions
-65
View File
@@ -1,65 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DeriveCache } from './types';
import { deriveNoopCache } from './cacheImpl';
interface CacheValue<T> {
v: T;
x: number;
}
const CHACHE_EXPIRY = 7 * (24 * 60) * (60 * 1000);
let deriveCache: DeriveCache;
function wrapCache (keyStart: string, cache: DeriveCache): DeriveCache {
return {
del: (partial: string): void => cache.del(`${keyStart}${partial}`),
forEach: cache.forEach,
get: <T> (partial: string): T | undefined => {
const key = `${keyStart}${partial}`;
const cached = cache.get<CacheValue<T>>(key);
if (cached) {
cached.x = Date.now();
cache.set(key, cached);
return cached.v;
}
return undefined;
},
set: (partial: string, v: unknown): void => {
cache.set(`${keyStart}${partial}`, { v, x: Date.now() });
}
};
}
function clearCache (cache: DeriveCache): void {
// clear all expired values
const now = Date.now();
const all: string[] = [];
cache.forEach((key: string, { x }: CacheValue<any>): void => {
((now - x) > CHACHE_EXPIRY) && all.push(key);
});
// don't do delete inside loop, just in-case
all.forEach((key) => cache.del(key));
}
export function setDeriveCache (prefix = '', cache?: DeriveCache): void {
deriveCache = cache
? wrapCache(`derive:${prefix}:`, cache)
: deriveNoopCache;
if (cache) {
clearCache(cache);
}
}
setDeriveCache();
export { deriveCache };