'-'
zhangwei
4 天以前 ddbf9504fc5faf6764fffa4e9263a3ad927331d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// https://github.com/localForage/localForage/blob/master/typings/localforage.d.ts
 
interface LocalForageDbInstanceOptions {
  name?: string;
 
  storeName?: string;
}
 
interface LocalForageOptions extends LocalForageDbInstanceOptions {
  driver?: string | string[];
 
  size?: number;
 
  version?: number;
 
  description?: string;
}
 
interface LocalForageDbMethodsCore {
  getItem<T>(
    key: string,
    callback?: (err: any, value: T | null) => void
  ): Promise<T | null>;
 
  setItem<T>(
    key: string,
    value: T,
    callback?: (err: any, value: T) => void
  ): Promise<T>;
 
  removeItem(key: string, callback?: (err: any) => void): Promise<void>;
 
  clear(callback?: (err: any) => void): Promise<void>;
 
  length(callback?: (err: any, numberOfKeys: number) => void): Promise<number>;
 
  key(
    keyIndex: number,
    callback?: (err: any, key: string) => void
  ): Promise<string>;
 
  keys(callback?: (err: any, keys: string[]) => void): Promise<string[]>;
 
  iterate<T, U>(
    iteratee: (value: T, key: string, iterationNumber: number) => U,
    callback?: (err: any, result: U) => void
  ): Promise<U>;
}
 
interface LocalForageDropInstanceFn {
  (
    dbInstanceOptions?: LocalForageDbInstanceOptions,
    callback?: (err: any) => void
  ): Promise<void>;
}
 
interface LocalForageDriverMethodsOptional {
  dropInstance?: LocalForageDropInstanceFn;
}
 
// duplicating LocalForageDriverMethodsOptional to preserve TS v2.0 support,
// since Partial<> isn't supported there
interface LocalForageDbMethodsOptional {
  dropInstance: LocalForageDropInstanceFn;
}
 
interface LocalForageDriverDbMethods
  extends LocalForageDbMethodsCore,
    LocalForageDriverMethodsOptional {}
 
interface LocalForageDriverSupportFunc {
  (): Promise<boolean>;
}
 
interface LocalForageDriver extends LocalForageDriverDbMethods {
  _driver: string;
 
  _initStorage(options: LocalForageOptions): void;
 
  _support?: boolean | LocalForageDriverSupportFunc;
}
 
interface LocalForageSerializer {
  serialize<T>(
    value: T | ArrayBuffer | Blob,
    callback: (value: string, error: any) => void
  ): void;
 
  deserialize<T>(value: string): T | ArrayBuffer | Blob;
 
  stringToBuffer(serializedString: string): ArrayBuffer;
 
  bufferToString(buffer: ArrayBuffer): string;
}
 
interface LocalForageDbMethods
  extends LocalForageDbMethodsCore,
    LocalForageDbMethodsOptional {}
 
export interface LocalForage extends LocalForageDbMethods {
  LOCALSTORAGE: string;
  WEBSQL: string;
  INDEXEDDB: string;
 
  /**
   * Set and persist localForage options. This must be called before any other calls to localForage are made, but can be called after localForage is loaded.
   * If you set any config values with this method they will persist after driver changes, so you can call config() then setDriver()
   * @param {LocalForageOptions} options?
   */
  config(options: LocalForageOptions): boolean;
  config(options: string): any;
  config(): LocalForageOptions;
 
  /**
   * Create a new instance of localForage to point to a different store.
   * All the configuration options used by config are supported.
   * @param {LocalForageOptions} options
   */
  createInstance(options: LocalForageOptions): LocalForage;
 
  driver(): string;
 
  /**
   * Force usage of a particular driver or drivers, if available.
   * @param {string} driver
   */
  setDriver(
    driver: string | string[],
    callback?: () => void,
    errorCallback?: (error: any) => void
  ): Promise<void>;
 
  defineDriver(
    driver: LocalForageDriver,
    callback?: () => void,
    errorCallback?: (error: any) => void
  ): Promise<void>;
 
  /**
   * Return a particular driver
   * @param {string} driver
   */
  getDriver(driver: string): Promise<LocalForageDriver>;
 
  getSerializer(
    callback?: (serializer: LocalForageSerializer) => void
  ): Promise<LocalForageSerializer>;
 
  supports(driverName: string): boolean;
 
  ready(callback?: (error: any) => void): Promise<void>;
}
 
// Customize
 
export interface ProxyStorage {
  setItem<T>(k: string, v: T, m: number): Promise<T>;
  getItem<T>(k: string): Promise<T>;
  removeItem(k: string): Promise<void>;
  clear(): Promise<void>;
}
 
export interface ExpiresData<T> {
  data: T;
  expires: number;
}