UNPKG

2.99 kBTypeScriptView Raw
1/** @hidden */
2export declare const Drivers: {
3 SecureStorage: string;
4 IndexedDB: string;
5 LocalStorage: string;
6};
7export interface StorageConfig {
8 name?: string;
9 version?: number;
10 size?: number;
11 storeName?: string;
12 description?: string;
13 driverOrder?: Driver[];
14 dbKey?: string;
15}
16export declare type Database = any;
17declare type Driver = any;
18export declare class Storage {
19 private _config;
20 private _db;
21 private _secureStorageDriver;
22 /**
23 * Create a new Storage instance using the order of drivers and any additional config
24 * options to pass to LocalForage.
25 *
26 * Possible default driverOrder options are: ['indexeddb', 'localstorage'] and the
27 * default is that exact ordering.
28 *
29 * When using Ionic Secure Storage (enterprise only), use ['ionicSecureStorage', 'indexeddb', 'localstorage'] to ensure
30 * Secure Storage is used when available, or fall back to IndexedDB or LocalStorage on the web.
31 */
32 constructor(config?: StorageConfig);
33 create(): Promise<Storage>;
34 /**
35 * Define a new Driver. Must be called before
36 * initializing the database. Example:
37 *
38 * await storage.defineDriver(myDriver);
39 * await storage.create();
40 */
41 defineDriver(driver: Driver): Promise<void>;
42 /**
43 * Get the name of the driver being used.
44 * @returns Name of the driver
45 */
46 get driver(): string | null;
47 private assertDb;
48 /**
49 * Get the value associated with the given key.
50 * @param key the key to identify this value
51 * @returns Returns a promise with the value of the given key
52 */
53 get(key: string): Promise<any>;
54 /**
55 * Set the value for the given key.
56 * @param key the key to identify this value
57 * @param value the value for this key
58 * @returns Returns a promise that resolves when the key and value are set
59 */
60 set(key: string, value: any): Promise<any>;
61 /**
62 * Remove any value associated with this key.
63 * @param key the key to identify this value
64 * @returns Returns a promise that resolves when the value is removed
65 */
66 remove(key: string): Promise<any>;
67 /**
68 * Clear the entire key value store. WARNING: HOT!
69 * @returns Returns a promise that resolves when the store is cleared
70 */
71 clear(): Promise<void>;
72 /**
73 * @returns Returns a promise that resolves with the number of keys stored.
74 */
75 length(): Promise<number>;
76 /**
77 * @returns Returns a promise that resolves with the keys in the store.
78 */
79 keys(): Promise<string[]>;
80 /**
81 * Iterate through each key,value pair.
82 * @param iteratorCallback a callback of the form (value, key, iterationNumber)
83 * @returns Returns a promise that resolves when the iteration has finished.
84 */
85 forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): Promise<void>;
86 setEncryptionKey(key: string): void;
87}
88export {};