24 lines
699 B
TypeScript
24 lines
699 B
TypeScript
|
import CryptoContext from './crypto.js';
|
||
|
import * as errors from './errors.js';
|
||
|
declare type ErrorSuppressor = errors.CODES | Function;
|
||
|
declare type TryLoadOptions<T> = {
|
||
|
suppress?: ErrorSuppressor[];
|
||
|
default?: T;
|
||
|
};
|
||
|
interface Validator<T> {
|
||
|
(a: unknown): a is T;
|
||
|
}
|
||
|
export declare class SafeStorage<T> {
|
||
|
private validator;
|
||
|
private cryptoContext;
|
||
|
constructor(validator?: Validator<T>, cryptoContext?: CryptoContext);
|
||
|
private _encrypt;
|
||
|
private _decrypt;
|
||
|
_safeLoad(): Promise<unknown>;
|
||
|
load(): Promise<T>;
|
||
|
tryLoad<D>(options?: TryLoadOptions<D>): Promise<T | D | undefined>;
|
||
|
save(data: T): Promise<void>;
|
||
|
}
|
||
|
export { errors };
|
||
|
export default SafeStorage;
|