UNPKG

4.34 kBTypeScriptView Raw
1/**
2 * A wrapper class to provide a consistent interface to browser based storage
3 *
4 */
5export declare class PnPClientStorageWrapper implements IPnPClientStore {
6 private store;
7 defaultTimeoutMinutes: number;
8 /**
9 * True if the wrapped storage is available; otherwise, false
10 */
11 enabled: boolean;
12 /**
13 * Creates a new instance of the PnPClientStorageWrapper class
14 *
15 * @constructor
16 */
17 constructor(store: Storage, defaultTimeoutMinutes?: number);
18 static bind(store: Storage): IPnPClientStore;
19 /**
20 * Get a value from storage, or null if that value does not exist
21 *
22 * @param key The key whose value we want to retrieve
23 */
24 get<T>(key: string): T | null;
25 /**
26 * Adds a value to the underlying storage
27 *
28 * @param key The key to use when storing the provided value
29 * @param o The value to store
30 * @param expire Optional, if provided the expiration of the item, otherwise the default is used
31 */
32 put(key: string, o: any, expire?: Date): void;
33 /**
34 * Deletes a value from the underlying storage
35 *
36 * @param key The key of the pair we want to remove from storage
37 */
38 delete(key: string): void;
39 /**
40 * Gets an item from the underlying storage, or adds it if it does not exist using the supplied getter function
41 *
42 * @param key The key to use when storing the provided value
43 * @param getter A function which will upon execution provide the desired value
44 * @param expire Optional, if provided the expiration of the item, otherwise the default is used
45 */
46 getOrPut<T>(key: string, getter: () => Promise<T>, expire?: Date): Promise<T>;
47 /**
48 * Deletes any expired items placed in the store by the pnp library, leaves other items untouched
49 */
50 deleteExpired(): Promise<void>;
51 /**
52 * Used to determine if the wrapped storage is available currently
53 */
54 private test;
55 /**
56 * Creates the persistable to store
57 */
58 private createPersistable;
59 /**
60 * Deletes expired items added by this library in this.store and sets a timeout to call itself
61 */
62 private cacheExpirationHandler;
63}
64/**
65 * Interface which defines the operations provided by a client storage object
66 */
67export interface IPnPClientStore {
68 /**
69 * True if the wrapped storage is available; otherwise, false
70 */
71 enabled: boolean;
72 /**
73 * Get a value from storage, or null if that value does not exist
74 *
75 * @param key The key whose value we want to retrieve
76 */
77 get(key: string): any;
78 /**
79 * Adds a value to the underlying storage
80 *
81 * @param key The key to use when storing the provided value
82 * @param o The value to store
83 * @param expire Optional, if provided the expiration of the item, otherwise the default is used
84 */
85 put(key: string, o: any, expire?: Date): void;
86 /**
87 * Deletes a value from the underlying storage
88 *
89 * @param key The key of the pair we want to remove from storage
90 */
91 delete(key: string): void;
92 /**
93 * Gets an item from the underlying storage, or adds it if it does not exist using the supplied getter function
94 *
95 * @param key The key to use when storing the provided value
96 * @param getter A function which will upon execution provide the desired value
97 * @param expire Optional, if provided the expiration of the item, otherwise the default is used
98 */
99 getOrPut<T>(key: string, getter: () => Promise<T>, expire?: Date): Promise<T>;
100 /**
101 * Removes any expired items placed in the store by the pnp library, leaves other items untouched
102 */
103 deleteExpired(): Promise<void>;
104}
105/**
106 * A class that will establish wrappers for both local and session storage
107 */
108export declare class PnPClientStorage {
109 private _local;
110 private _session;
111 /**
112 * Creates a new instance of the PnPClientStorage class
113 *
114 * @constructor
115 */
116 constructor(_local?: IPnPClientStore | null, _session?: IPnPClientStore | null);
117 /**
118 * Provides access to the local storage of the browser
119 */
120 get local(): IPnPClientStore;
121 /**
122 * Provides access to the session storage of the browser
123 */
124 get session(): IPnPClientStore;
125}
126//# sourceMappingURL=storage.d.ts.map
\No newline at end of file