@backland/schema
Version:
TypeScript schema declaration and validation library with static type inference
19 lines • 497 B
JavaScript
import { RuntimeError } from '@backland/utils';
export function withCache(parent) {
var cache = new Map();
function getOrSet(key, onCreate) {
if (!cache.has(key)) {
if (typeof onCreate !== 'function') {
throw new RuntimeError("missing cache ".concat(String(key)), {
cache,
parent
});
}
cache.set(key, onCreate());
}
return cache.get(key);
}
getOrSet.cache = cache;
return getOrSet;
}
//# sourceMappingURL=withCache.js.map