Add query history persistence (#20700)

* initial

* Fix and revert secret storage changes

* persist to file

* Add debounce and write on dispose

* Fix run

* No ext dependencies and show warning message

* Remove test stuff

* comments

* Fix tests and console logs
This commit is contained in:
Charles Gagnon
2022-09-30 16:48:55 -07:00
committed by GitHub
parent 3aa416df6d
commit d6d75d8817
10 changed files with 255 additions and 38 deletions

View File

@@ -11,3 +11,35 @@
export function removeNewLines(str: string): string {
return str.replace(/\r\n/g, ' ').replace(/\n/g, ' ');
}
function decorate(decorator: (fn: Function, key: string) => Function): Function {
return (_target: any, key: string, descriptor: any): void => {
let fnKey: string | null = null;
let fn: Function | null = null;
if (typeof descriptor.value === 'function') {
fnKey = 'value';
fn = descriptor.value;
} else if (typeof descriptor.get === 'function') {
fnKey = 'get';
fn = descriptor.get;
}
if (!fn || !fnKey) {
throw new Error('not supported');
}
descriptor[fnKey] = decorator(fn, key);
};
}
export function debounce(delay: number): Function {
return decorate((fn, key) => {
const timerKey = `$debounce$${key}`;
return function (this: any, ...args: any[]): void {
clearTimeout(this[timerKey]);
this[timerKey] = setTimeout(() => fn.apply(this, args), delay);
};
});
}