@esportsplus/web-storage 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -6,24 +6,22 @@ declare const _default: {
6
6
  iterate: <T, U>(iteratee: (value: T, key: string, iterationNumber: number) => U, callback?: ((err: any, result: U) => void) | undefined) => Promise<U>;
7
7
  keys: (callback?: ((err: any, keys: string[]) => void) | undefined) => Promise<string[]>;
8
8
  length: (callback?: ((err: any, numberOfKeys: number) => void) | undefined) => Promise<number>;
9
- promises: (Promise<any> | (() => void))[];
10
- assign(key: string, value: import("./local/types").Object): void;
9
+ assign(key: string, value: import("./local/types").Object): Promise<void>;
11
10
  clear(): Promise<void>;
12
- delete(...keys: string[]): void;
11
+ delete(...keys: string[]): Promise<void>;
13
12
  entries(): Promise<import("./local/types").Object>;
14
13
  filter(fn: Function): Promise<import("./local/types").Object>;
15
14
  get(key: string, value?: any): Promise<any>;
16
15
  has(...keys: string[]): Promise<boolean>;
17
16
  only(...keys: string[]): Promise<import("./local/types").Object>;
18
17
  pop(key: string): Promise<any>;
19
- push(key: string, ...values: any[]): void;
18
+ push(key: string, ...values: any[]): Promise<void>;
20
19
  replace(values: {
21
20
  [key: string]: any;
22
- }): void;
21
+ }): Promise<void>;
23
22
  shift(key: string): Promise<any>;
24
- set(key: string, value: any): void;
25
- sync(): Promise<void>;
26
- unshift(key: string, ...values: any[]): void;
23
+ set(key: string, value: any): Promise<void>;
24
+ unshift(key: string, ...values: any[]): Promise<void>;
27
25
  };
28
26
  };
29
27
  };
@@ -4,25 +4,23 @@ declare class Store {
4
4
  iterate: LocalForage['iterate'];
5
5
  keys: LocalForage['keys'];
6
6
  length: LocalForage['length'];
7
- promises: (Promise<any> | (() => void))[];
8
7
  constructor(options?: LocalForageOptions);
9
- assign(key: string, value: Object): void;
8
+ assign(key: string, value: Object): Promise<void>;
10
9
  clear(): Promise<void>;
11
- delete(...keys: string[]): void;
10
+ delete(...keys: string[]): Promise<void>;
12
11
  entries(): Promise<Object>;
13
12
  filter(fn: Function): Promise<Object>;
14
13
  get(key: string, value?: any): Promise<any>;
15
14
  has(...keys: string[]): Promise<boolean>;
16
15
  only(...keys: string[]): Promise<Object>;
17
16
  pop(key: string): Promise<any>;
18
- push(key: string, ...values: any[]): void;
17
+ push(key: string, ...values: any[]): Promise<void>;
19
18
  replace(values: {
20
19
  [key: string]: any;
21
- }): void;
20
+ }): Promise<void>;
22
21
  shift(key: string): Promise<any>;
23
- set(key: string, value: any): void;
24
- sync(): Promise<void>;
25
- unshift(key: string, ...values: any[]): void;
22
+ set(key: string, value: any): Promise<void>;
23
+ unshift(key: string, ...values: any[]): Promise<void>;
26
24
  }
27
25
  declare const _default: {
28
26
  store: (options?: LocalForageOptions) => Store;
@@ -10,7 +10,6 @@ class Store {
10
10
  iterate;
11
11
  keys;
12
12
  length;
13
- promises;
14
13
  constructor(options = {}) {
15
14
  let driver, name = options.name || 'store';
16
15
  switch ((options.driver || types_1.Driver.IndexedDB)) {
@@ -25,32 +24,25 @@ class Store {
25
24
  this.iterate = this.instance.iterate;
26
25
  this.keys = this.instance.keys;
27
26
  this.length = this.instance.length;
28
- this.promises = [];
29
27
  }
30
- assign(key, value) {
31
- let transaction = async () => {
32
- let data = (await this.get(key)) || {};
33
- await this.instance.setItem(key, Object.assign(data, value));
34
- };
35
- this.promises.push(transaction());
28
+ async assign(key, value) {
29
+ let data = (await this.get(key)) || {};
30
+ await this.instance.setItem(key, Object.assign(data, value));
36
31
  }
37
- clear() {
38
- this.promises = [];
39
- return this.instance.clear();
32
+ async clear() {
33
+ await this.instance.clear();
40
34
  }
41
- delete(...keys) {
35
+ async delete(...keys) {
42
36
  if (!keys.length) {
43
37
  return;
44
38
  }
45
39
  for (let i = 0, n = keys.length; i < n; i++) {
46
- this.promises.push(this.instance.removeItem(keys[i]));
40
+ await this.instance.removeItem(keys[i]);
47
41
  }
48
42
  }
49
43
  async entries() {
50
44
  let values = {};
51
- await this.instance.iterate((value, key) => {
52
- values[key] = value;
53
- });
45
+ await this.instance.iterate((value, key) => (values[key] = value));
54
46
  return values;
55
47
  }
56
48
  async filter(fn) {
@@ -100,50 +92,41 @@ class Store {
100
92
  async pop(key) {
101
93
  let value, values = (await this.get(key)) || [];
102
94
  value = values.pop();
103
- this.promises.push(this.instance.setItem(key, values));
95
+ await this.instance.setItem(key, values);
104
96
  return value;
105
97
  }
106
- push(key, ...values) {
98
+ async push(key, ...values) {
107
99
  if (!values.length) {
108
100
  return;
109
101
  }
110
- let transaction = async () => {
111
- let data = (await this.get(key)) || [];
112
- data.push(...values);
113
- await this.instance.setItem(key, data);
114
- };
115
- this.promises.push(transaction());
102
+ let data = (await this.get(key)) || [];
103
+ data.push(...values);
104
+ await this.instance.setItem(key, data);
116
105
  }
117
- replace(values) {
106
+ async replace(values) {
118
107
  if (!Object.keys(values).length) {
119
108
  return;
120
109
  }
121
110
  for (let key in values) {
122
- this.promises.push(this.instance.setItem(key, values[key]));
111
+ await this.instance.setItem(key, values[key]);
123
112
  }
124
113
  }
125
114
  async shift(key) {
126
115
  let value, values = (await this.get(key)) || [];
127
116
  value = values.shift();
128
- this.promises.push(this.instance.setItem(key, values));
117
+ await this.instance.setItem(key, values);
129
118
  return value;
130
119
  }
131
- set(key, value) {
132
- this.promises.push(this.instance.setItem(key, value));
133
- }
134
- async sync() {
135
- await Promise.allSettled(this.promises.splice(0));
120
+ async set(key, value) {
121
+ await this.instance.setItem(key, value);
136
122
  }
137
- unshift(key, ...values) {
123
+ async unshift(key, ...values) {
138
124
  if (!values.length) {
139
125
  return;
140
126
  }
141
- let transaction = async () => {
142
- let data = (await this.get(key)) || [];
143
- data.unshift(...values);
144
- await this.instance.setItem(key, data);
145
- };
146
- this.promises.push(transaction());
127
+ let data = (await this.get(key)) || [];
128
+ data.unshift(...values);
129
+ await this.instance.setItem(key, data);
147
130
  }
148
131
  }
149
132
  exports.default = {
package/package.json CHANGED
@@ -23,5 +23,5 @@
23
23
  "prepublishOnly": "npm run build"
24
24
  },
25
25
  "types": "./build/index.d.ts",
26
- "version": "0.1.7"
26
+ "version": "0.1.8"
27
27
  }
@@ -7,7 +7,6 @@ class Store {
7
7
  iterate: LocalForage['iterate'];
8
8
  keys: LocalForage['keys'];
9
9
  length: LocalForage['length'];
10
- promises: (Promise<any> | (() => void))[];
11
10
 
12
11
 
13
12
  constructor(options: LocalForageOptions = {}) {
@@ -23,49 +22,42 @@ class Store {
23
22
  break;
24
23
  }
25
24
 
26
- this.instance = localforage.createInstance( Object.assign(options, { driver, name, storeName: name }) );
25
+ this.instance = localforage.createInstance(
26
+ Object.assign(options, { driver, name, storeName: name })
27
+ );
27
28
  this.iterate = this.instance.iterate;
28
29
  this.keys = this.instance.keys;
29
30
  this.length = this.instance.length;
30
- this.promises = [];
31
31
  }
32
32
 
33
33
 
34
- assign(key: string, value: Object): void {
35
- let transaction = async () => {
36
- let data = (await this.get(key)) || {};
37
-
38
- await this.instance.setItem(
39
- key,
40
- Object.assign(data, value)
41
- );
42
- };
43
-
44
- this.promises.push( transaction() );
34
+ async assign(key: string, value: Object): Promise<void> {
35
+ let data = (await this.get(key)) || {};
36
+
37
+ await this.instance.setItem(
38
+ key,
39
+ Object.assign(data, value)
40
+ );
45
41
  }
46
42
 
47
- clear(): Promise<void> {
48
- this.promises = [];
49
-
50
- return this.instance.clear();
43
+ async clear(): Promise<void> {
44
+ await this.instance.clear();
51
45
  }
52
46
 
53
- delete(...keys: string[]): void {
47
+ async delete(...keys: string[]): Promise<void> {
54
48
  if (!keys.length) {
55
49
  return;
56
50
  }
57
51
 
58
52
  for (let i = 0, n = keys.length; i < n; i++) {
59
- this.promises.push(this.instance.removeItem(keys[i]));
53
+ await this.instance.removeItem(keys[i]);
60
54
  }
61
55
  }
62
56
 
63
57
  async entries(): Promise<Object> {
64
58
  let values: Object = {};
65
59
 
66
- await this.instance.iterate((value: any, key: string) => {
67
- values[key] = value;
68
- });
60
+ await this.instance.iterate((value: any, key: string) => (values[key] = value));
69
61
 
70
62
  return values;
71
63
  }
@@ -136,34 +128,30 @@ class Store {
136
128
 
137
129
  value = values.pop();
138
130
 
139
- this.promises.push( this.instance.setItem(key, values) );
131
+ await this.instance.setItem(key, values);
140
132
 
141
133
  return value;
142
134
  }
143
135
 
144
- push(key: string, ...values: any[]): void {
136
+ async push(key: string, ...values: any[]): Promise<void> {
145
137
  if (!values.length) {
146
138
  return;
147
139
  }
148
140
 
149
- let transaction = async () => {
150
- let data = (await this.get(key)) || [];
141
+ let data = (await this.get(key)) || [];
151
142
 
152
- data.push(...values);
143
+ data.push(...values);
153
144
 
154
- await this.instance.setItem(key, data);
155
- };
156
-
157
- this.promises.push( transaction() );
145
+ await this.instance.setItem(key, data);
158
146
  }
159
147
 
160
- replace(values: { [key: string]: any }): void {
148
+ async replace(values: { [key: string]: any }): Promise<void> {
161
149
  if (!Object.keys(values).length) {
162
150
  return;
163
151
  }
164
152
 
165
153
  for (let key in values) {
166
- this.promises.push( this.instance.setItem(key, values[key]) );
154
+ await this.instance.setItem(key, values[key]);
167
155
  }
168
156
  }
169
157
 
@@ -173,33 +161,25 @@ class Store {
173
161
 
174
162
  value = values.shift();
175
163
 
176
- this.promises.push( this.instance.setItem(key, values) );
164
+ await this.instance.setItem(key, values);
177
165
 
178
166
  return value;
179
167
  }
180
168
 
181
- set(key: string, value: any): void {
182
- this.promises.push( this.instance.setItem(key, value) );
183
- }
184
-
185
- async sync(): Promise<void> {
186
- await Promise.allSettled(this.promises.splice(0));
169
+ async set(key: string, value: any): Promise<void> {
170
+ await this.instance.setItem(key, value);
187
171
  }
188
172
 
189
- unshift(key: string, ...values: any[]): void {
173
+ async unshift(key: string, ...values: any[]): Promise<void> {
190
174
  if (!values.length) {
191
175
  return;
192
176
  }
193
177
 
194
- let transaction = async () => {
195
- let data = (await this.get(key)) || [];
196
-
197
- data.unshift(...values);
178
+ let data = (await this.get(key)) || [];
198
179
 
199
- await this.instance.setItem(key, data);
200
- };
180
+ data.unshift(...values);
201
181
 
202
- this.promises.push( transaction() );
182
+ await this.instance.setItem(key, data);
203
183
  }
204
184
  }
205
185