mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
Merge pull request #32 from bknd-io/feat/optimize-seeding
Feat: optimize seeding, adding api typing support
This commit is contained in:
@@ -9,10 +9,25 @@ export async function withDisabledConsole<R>(
|
||||
fn: () => Promise<R>,
|
||||
severities: ConsoleSeverity[] = ["log"]
|
||||
): Promise<R> {
|
||||
const enable = disableConsoleLog(severities);
|
||||
const result = await fn();
|
||||
enable();
|
||||
return result;
|
||||
const _oldConsoles = {
|
||||
log: console.log,
|
||||
warn: console.warn,
|
||||
error: console.error
|
||||
};
|
||||
disableConsoleLog(severities);
|
||||
const enable = () => {
|
||||
Object.entries(_oldConsoles).forEach(([severity, fn]) => {
|
||||
console[severity as ConsoleSeverity] = fn;
|
||||
});
|
||||
};
|
||||
try {
|
||||
const result = await fn();
|
||||
enable();
|
||||
return result;
|
||||
} catch (e) {
|
||||
enable();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export function disableConsoleLog(severities: ConsoleSeverity[] = ["log"]) {
|
||||
|
||||
Reference in New Issue
Block a user