@picgo/store 1.0.1 → 2.0.0

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.
@@ -1,179 +1,300 @@
1
1
  TN:
2
2
  SF:/home/runner/work/store/store/src/DBStore.ts
3
- FN:10,(anonymous_0)
4
- FN:21,(anonymous_1)
5
- FN:28,(anonymous_2)
6
- FN:33,(anonymous_3)
7
- FN:50,(anonymous_4)
8
- FN:58,(anonymous_5)
9
- FN:70,(anonymous_6)
10
- FN:78,(anonymous_7)
11
- FNF:8
12
- FNH:8
13
- FNDA:10,(anonymous_0)
14
- FNDA:30,(anonymous_1)
15
- FNDA:3,(anonymous_2)
16
- FNDA:6,(anonymous_3)
17
- FNDA:1,(anonymous_4)
18
- FNDA:3,(anonymous_5)
19
- FNDA:3,(anonymous_6)
20
- FNDA:1,(anonymous_7)
21
- DA:1,1
22
- DA:2,1
23
- DA:3,1
3
+ FN:16,(anonymous_0)
4
+ FN:27,(anonymous_1)
5
+ FN:31,(anonymous_2)
6
+ FN:39,(anonymous_3)
7
+ FN:59,(anonymous_4)
8
+ FN:63,(anonymous_5)
9
+ FN:67,(anonymous_6)
10
+ FN:71,(anonymous_7)
11
+ FN:79,(anonymous_8)
12
+ FN:96,(anonymous_9)
13
+ FN:105,(anonymous_10)
14
+ FN:109,(anonymous_11)
15
+ FN:118,(anonymous_12)
16
+ FN:119,(anonymous_13)
17
+ FN:122,(anonymous_14)
18
+ FN:125,(anonymous_15)
19
+ FN:133,(anonymous_16)
20
+ FNF:17
21
+ FNH:17
22
+ FNDA:18,(anonymous_0)
23
+ FNDA:1,(anonymous_1)
24
+ FNDA:56,(anonymous_2)
25
+ FNDA:18,(anonymous_3)
26
+ FNDA:33,(anonymous_4)
27
+ FNDA:12,(anonymous_5)
28
+ FNDA:13,(anonymous_6)
29
+ FNDA:8,(anonymous_7)
30
+ FNDA:9,(anonymous_8)
31
+ FNDA:2,(anonymous_9)
32
+ FNDA:3,(anonymous_10)
33
+ FNDA:5,(anonymous_11)
34
+ FNDA:3,(anonymous_12)
35
+ FNDA:4,(anonymous_13)
36
+ FNDA:1,(anonymous_14)
37
+ FNDA:1,(anonymous_15)
38
+ FNDA:1,(anonymous_16)
24
39
  DA:4,1
25
- DA:9,10
26
- DA:12,10
27
- DA:13,2
28
- DA:15,8
29
- DA:16,8
30
- DA:17,8
31
- DA:18,8
32
- DA:22,30
33
- DA:23,8
34
- DA:25,30
35
- DA:29,3
36
- DA:33,1
37
- DA:34,6
38
- DA:36,6
39
- DA:38,6
40
- DA:39,1
41
- DA:40,1
42
- DA:42,5
43
- DA:44,5
44
- DA:45,5
45
- DA:46,5
40
+ DA:5,1
41
+ DA:6,1
42
+ DA:7,1
43
+ DA:13,18
44
+ DA:14,18
45
+ DA:18,18
46
+ DA:19,2
47
+ DA:21,16
48
+ DA:22,16
49
+ DA:23,16
50
+ DA:24,16
51
+ DA:28,1
52
+ DA:32,56
53
+ DA:33,16
54
+ DA:34,16
55
+ DA:36,56
56
+ DA:40,18
57
+ DA:41,18
58
+ DA:42,18
59
+ DA:43,6
60
+ DA:44,1
61
+ DA:46,6
62
+ DA:47,1
63
+ DA:49,6
46
64
  DA:50,1
47
- DA:51,1
48
- DA:52,2
49
- DA:54,1
50
- DA:58,1
51
- DA:59,3
52
- DA:60,3
53
- DA:61,3
54
- DA:63,2
55
- DA:64,2
56
- DA:66,1
57
- DA:71,3
65
+ DA:53,18
66
+ DA:60,33
67
+ DA:64,12
68
+ DA:68,13
69
+ DA:72,8
70
+ DA:73,8
71
+ DA:74,8
72
+ DA:75,8
58
73
  DA:79,1
59
- DA:81,1
60
- DA:82,1
61
- DA:87,1
62
- LF:41
63
- LH:41
64
- BRDA:12,0,0,2
65
- BRDA:12,0,1,8
66
- BRDA:12,1,0,10
67
- BRDA:12,1,1,9
68
- BRDA:21,2,0,30
69
- BRDA:22,3,0,8
70
- BRDA:22,3,1,22
71
- BRDA:22,4,0,30
72
- BRDA:22,4,1,30
73
- BRDA:38,5,0,1
74
- BRDA:38,5,1,5
75
- BRDA:61,6,0,2
76
- BRDA:61,6,1,1
77
- BRF:13
78
- BRH:13
74
+ DA:80,9
75
+ DA:81,9
76
+ DA:83,9
77
+ DA:84,1
78
+ DA:85,1
79
+ DA:87,8
80
+ DA:88,8
81
+ DA:89,8
82
+ DA:90,3
83
+ DA:92,8
84
+ DA:96,1
85
+ DA:97,2
86
+ DA:98,5
87
+ DA:100,2
88
+ DA:101,2
89
+ DA:105,1
90
+ DA:106,3
91
+ DA:107,3
92
+ DA:108,3
93
+ DA:109,5
94
+ DA:110,2
95
+ DA:111,2
96
+ DA:112,2
97
+ DA:114,1
98
+ DA:119,4
99
+ DA:123,1
100
+ DA:124,1
101
+ DA:125,1
102
+ DA:126,1
103
+ DA:127,1
104
+ DA:128,1
105
+ DA:129,1
106
+ DA:134,1
107
+ DA:135,1
108
+ DA:136,1
109
+ DA:137,1
110
+ DA:142,1
111
+ LF:72
112
+ LH:72
113
+ BRDA:18,0,0,2
114
+ BRDA:18,0,1,16
115
+ BRDA:18,1,0,18
116
+ BRDA:18,1,1,17
117
+ BRDA:31,2,0,56
118
+ BRDA:32,3,0,16
119
+ BRDA:32,3,1,40
120
+ BRDA:32,4,0,56
121
+ BRDA:32,4,1,56
122
+ BRDA:42,5,0,6
123
+ BRDA:42,5,1,12
124
+ BRDA:43,6,0,1
125
+ BRDA:43,6,1,5
126
+ BRDA:46,7,0,1
127
+ BRDA:46,7,1,5
128
+ BRDA:46,8,0,6
129
+ BRDA:46,8,1,2
130
+ BRDA:49,9,0,1
131
+ BRDA:49,9,1,5
132
+ BRDA:49,10,0,6
133
+ BRDA:49,10,1,2
134
+ BRDA:60,11,0,0
135
+ BRDA:60,11,1,33
136
+ BRDA:60,12,0,33
137
+ BRDA:60,12,1,33
138
+ BRDA:68,13,0,0
139
+ BRDA:68,13,1,13
140
+ BRDA:68,14,0,13
141
+ BRDA:68,14,1,13
142
+ BRDA:79,15,0,4
143
+ BRDA:83,16,0,1
144
+ BRDA:83,16,1,8
145
+ BRDA:89,17,0,3
146
+ BRDA:89,17,1,5
147
+ BRDA:108,18,0,2
148
+ BRDA:108,18,1,1
149
+ BRDA:126,19,0,1
150
+ BRDA:126,19,1,0
151
+ BRF:38
152
+ BRH:35
79
153
  end_of_record
80
154
  TN:
81
155
  SF:/home/runner/work/store/store/src/JSONStore.ts
82
156
  FN:6,(anonymous_0)
83
- FN:11,(anonymous_1)
84
- FN:19,(anonymous_2)
85
- FN:23,(anonymous_3)
86
- FN:27,(anonymous_4)
87
- FN:31,(anonymous_5)
88
- FN:35,(anonymous_6)
157
+ FN:12,(anonymous_1)
158
+ FN:21,(anonymous_2)
159
+ FN:30,(anonymous_3)
160
+ FN:34,(anonymous_4)
161
+ FN:39,(anonymous_5)
162
+ FN:43,(anonymous_6)
89
163
  FNF:7
90
164
  FNH:7
91
165
  FNDA:5,(anonymous_0)
92
- FNDA:3,(anonymous_1)
166
+ FNDA:6,(anonymous_1)
93
167
  FNDA:6,(anonymous_2)
94
- FNDA:3,(anonymous_3)
95
- FNDA:1,(anonymous_4)
168
+ FNDA:4,(anonymous_3)
169
+ FNDA:2,(anonymous_4)
96
170
  FNDA:1,(anonymous_5)
97
171
  FNDA:1,(anonymous_6)
98
172
  DA:1,1
99
173
  DA:2,1
100
174
  DA:3,1
101
175
  DA:7,5
102
- DA:8,1
103
- DA:10,4
104
- DA:12,3
105
- DA:16,4
106
- DA:20,6
107
- DA:24,3
108
- DA:28,1
109
- DA:32,1
110
- DA:36,1
111
- DA:41,1
112
- LF:14
113
- LH:14
114
- BRDA:7,0,0,1
115
- BRDA:7,0,1,4
116
- BRDA:23,1,0,1
117
- BRF:3
118
- BRH:3
176
+ DA:11,6
177
+ DA:13,6
178
+ DA:14,1
179
+ DA:16,5
180
+ DA:17,5
181
+ DA:18,5
182
+ DA:23,6
183
+ DA:24,6
184
+ DA:25,6
185
+ DA:27,6
186
+ DA:31,4
187
+ DA:35,2
188
+ DA:36,2
189
+ DA:40,1
190
+ DA:44,1
191
+ DA:45,1
192
+ DA:46,1
193
+ DA:51,1
194
+ LF:22
195
+ LH:22
196
+ BRDA:13,0,0,1
197
+ BRDA:13,0,1,5
198
+ BRDA:21,1,0,5
199
+ BRDA:23,2,0,6
200
+ BRDA:23,3,0,6
201
+ BRDA:23,3,1,5
202
+ BRDA:30,4,0,1
203
+ BRF:7
204
+ BRH:7
205
+ end_of_record
206
+ TN:
207
+ SF:/home/runner/work/store/store/src/adapters/JSONAdapter.ts
208
+ FN:7,(anonymous_0)
209
+ FN:11,(anonymous_1)
210
+ FN:20,(anonymous_2)
211
+ FNF:3
212
+ FNH:3
213
+ FNDA:5,(anonymous_0)
214
+ FNDA:6,(anonymous_1)
215
+ FNDA:3,(anonymous_2)
216
+ DA:1,1
217
+ DA:2,1
218
+ DA:5,1
219
+ DA:8,5
220
+ DA:12,6
221
+ DA:13,6
222
+ DA:14,1
223
+ DA:16,5
224
+ DA:21,3
225
+ LF:9
226
+ LH:9
227
+ BRDA:13,0,0,1
228
+ BRDA:13,0,1,5
229
+ BRF:2
230
+ BRH:2
119
231
  end_of_record
120
232
  TN:
121
233
  SF:/home/runner/work/store/store/src/adapters/ZlibAdapter.ts
122
- FN:13,(anonymous_0)
123
- FN:18,(anonymous_1)
124
- FN:19,(anonymous_2)
125
- FN:26,(anonymous_3)
126
- FN:28,(anonymous_4)
127
- FN:36,(anonymous_5)
128
- FN:49,(anonymous_6)
129
- FN:50,(anonymous_7)
130
- FN:52,(anonymous_8)
131
- FNF:9
132
- FNH:9
133
- FNDA:8,(anonymous_0)
234
+ FN:17,(anonymous_0)
235
+ FN:23,(anonymous_1)
236
+ FN:29,(anonymous_2)
237
+ FN:32,(anonymous_3)
238
+ FN:53,(anonymous_4)
239
+ FN:63,(anonymous_5)
240
+ FN:64,(anonymous_6)
241
+ FN:66,(anonymous_7)
242
+ FNF:8
243
+ FNH:8
244
+ FNDA:16,(anonymous_0)
134
245
  FNDA:16,(anonymous_1)
135
246
  FNDA:16,(anonymous_2)
136
247
  FNDA:15,(anonymous_3)
137
- FNDA:15,(anonymous_4)
138
- FNDA:1,(anonymous_5)
139
- FNDA:14,(anonymous_6)
140
- FNDA:14,(anonymous_7)
141
- FNDA:14,(anonymous_8)
142
- DA:3,1
248
+ FNDA:1,(anonymous_4)
249
+ FNDA:8,(anonymous_5)
250
+ FNDA:8,(anonymous_6)
251
+ FNDA:8,(anonymous_7)
143
252
  DA:4,1
144
253
  DA:5,1
254
+ DA:6,1
145
255
  DA:7,1
146
- DA:14,8
147
- DA:15,8
256
+ DA:9,1
257
+ DA:15,16
258
+ DA:18,16
148
259
  DA:19,16
149
260
  DA:20,16
150
- DA:22,15
151
- DA:23,15
152
- DA:24,15
153
- DA:26,15
154
- DA:27,15
155
- DA:29,15
156
- DA:32,1
261
+ DA:24,16
262
+ DA:25,16
263
+ DA:29,16
264
+ DA:30,16
265
+ DA:31,15
266
+ DA:32,15
267
+ DA:33,15
268
+ DA:34,1
269
+ DA:35,1
157
270
  DA:36,1
158
- DA:39,1
159
- DA:40,1
160
- DA:50,14
161
- DA:51,14
162
- DA:52,14
163
- DA:55,14
164
- DA:56,14
165
- DA:63,1
166
- LF:24
167
- LH:24
168
- BRDA:20,0,0,15
169
- BRDA:20,0,1,1
170
- BRF:2
171
- BRH:2
271
+ DA:38,14
272
+ DA:39,14
273
+ DA:40,14
274
+ DA:41,14
275
+ DA:52,1
276
+ DA:53,1
277
+ DA:56,1
278
+ DA:57,1
279
+ DA:64,8
280
+ DA:65,8
281
+ DA:66,8
282
+ DA:69,8
283
+ DA:70,8
284
+ DA:77,1
285
+ LF:33
286
+ LH:33
287
+ BRDA:30,0,0,15
288
+ BRDA:30,0,1,1
289
+ BRDA:33,1,0,1
290
+ BRDA:33,1,1,14
291
+ BRF:4
292
+ BRH:4
172
293
  end_of_record
173
294
  TN:
174
295
  SF:/home/runner/work/store/store/src/types/index.ts
175
296
  FN:1,(anonymous_0)
176
- FN:15,(anonymous_1)
297
+ FN:25,(anonymous_1)
177
298
  FNF:2
178
299
  FNH:2
179
300
  FNDA:1,(anonymous_0)
@@ -183,15 +304,16 @@ DA:2,1
183
304
  DA:3,1
184
305
  DA:4,1
185
306
  DA:5,1
186
- DA:15,1
187
- DA:16,1
188
- DA:17,1
189
- LF:8
190
- LH:8
307
+ DA:25,1
308
+ DA:26,1
309
+ DA:27,1
310
+ DA:28,1
311
+ LF:9
312
+ LH:9
191
313
  BRDA:1,0,0,1
192
314
  BRDA:1,0,1,1
193
- BRDA:15,1,0,1
194
- BRDA:15,1,1,1
315
+ BRDA:25,1,0,1
316
+ BRDA:25,1,1,1
195
317
  BRF:4
196
318
  BRH:4
197
319
  end_of_record
@@ -200,64 +322,60 @@ SF:/home/runner/work/store/store/src/utils/metaInfoHelper.ts
200
322
  FN:3,metaInfoHelper
201
323
  FN:4,(anonymous_1)
202
324
  FN:6,(anonymous_2)
203
- FN:13,(anonymous_3)
204
- FN:27,uuid
205
- FN:29,metaInfoGenerator
206
- FN:40,metaInfoUpdater
325
+ FN:9,(anonymous_3)
326
+ FN:23,uuid
327
+ FN:25,metaInfoGenerator
328
+ FN:36,metaInfoUpdater
207
329
  FNF:7
208
330
  FNH:7
209
331
  FNDA:3,metaInfoHelper
210
332
  FNDA:3,(anonymous_1)
211
- FNDA:10,(anonymous_2)
212
- FNDA:8,(anonymous_3)
333
+ FNDA:14,(anonymous_2)
334
+ FNDA:5,(anonymous_3)
213
335
  FNDA:1,uuid
214
- FNDA:8,metaInfoGenerator
336
+ FNDA:14,metaInfoGenerator
215
337
  FNDA:3,metaInfoUpdater
216
338
  DA:1,1
217
339
  DA:4,3
218
340
  DA:5,3
219
341
  DA:6,3
220
- DA:7,10
221
- DA:8,10
222
- DA:9,7
223
- DA:10,1
224
- DA:11,1
225
- DA:13,8
226
- DA:14,7
227
- DA:15,1
228
- DA:18,3
229
- DA:20,10
230
- DA:21,10
342
+ DA:7,14
343
+ DA:8,2
344
+ DA:9,5
345
+ DA:10,2
346
+ DA:11,12
347
+ DA:12,9
348
+ DA:14,3
349
+ DA:16,14
350
+ DA:17,14
351
+ DA:23,1
352
+ DA:26,14
231
353
  DA:27,1
354
+ DA:29,14
232
355
  DA:30,8
233
- DA:31,1
234
- DA:33,8
235
- DA:34,5
236
- DA:35,5
237
- DA:37,8
238
- DA:41,3
239
- DA:42,3
240
- DA:46,1
241
- LF:25
242
- LH:25
243
- BRDA:8,0,0,7
244
- BRDA:8,0,1,3
245
- BRDA:9,1,0,1
246
- BRDA:9,1,1,6
247
- BRDA:14,2,0,1
248
- BRDA:14,2,1,6
249
- BRDA:27,3,0,1
250
- BRDA:27,4,0,1
251
- BRDA:27,5,0,32
252
- BRDA:27,5,1,4
253
- BRDA:27,6,0,31
254
- BRDA:27,6,1,1
255
- BRDA:27,7,0,30
256
- BRDA:27,7,1,1
257
- BRDA:30,8,0,1
258
- BRDA:30,8,1,7
259
- BRDA:33,9,0,5
260
- BRDA:33,9,1,3
261
- BRF:18
262
- BRH:18
356
+ DA:31,8
357
+ DA:33,14
358
+ DA:37,3
359
+ DA:38,3
360
+ DA:42,1
361
+ LF:23
362
+ LH:23
363
+ BRDA:7,0,0,2
364
+ BRDA:7,0,1,12
365
+ BRDA:11,1,0,9
366
+ BRDA:11,1,1,3
367
+ BRDA:23,2,0,1
368
+ BRDA:23,3,0,1
369
+ BRDA:23,4,0,32
370
+ BRDA:23,4,1,4
371
+ BRDA:23,5,0,31
372
+ BRDA:23,5,1,1
373
+ BRDA:23,6,0,30
374
+ BRDA:23,6,1,1
375
+ BRDA:26,7,0,1
376
+ BRDA:26,7,1,13
377
+ BRDA:29,8,0,8
378
+ BRDA:29,8,1,6
379
+ BRF:16
380
+ BRH:16
263
381
  end_of_record
package/dist/DBStore.d.ts CHANGED
@@ -1,17 +1,25 @@
1
- import Lowdb from 'lowdb';
2
- import { IObject, IResult } from './types';
1
+ import { ZlibAdapter } from './adapters/ZlibAdapter';
2
+ import { IObject, IResult, IGetResult, IFilter, ILowData } from './types';
3
3
  declare class DBStore {
4
4
  private readonly db;
5
5
  private readonly collectionName;
6
6
  private readonly collectionKey;
7
- private reading;
7
+ private hasRead;
8
+ errorList: Array<Error | string>;
9
+ private readonly adapter;
8
10
  constructor(dbPath: string, collectionName: string);
9
- read(flush?: boolean): Promise<Lowdb.LowdbAsync<any>>;
10
- get(): Promise<IObject[]>;
11
- insert<T>(value: T): Promise<IResult<T>>;
11
+ getAdapter(): ZlibAdapter;
12
+ read(flush?: boolean): Promise<ILowData | null>;
13
+ get(filter?: IFilter): Promise<IGetResult<IObject>>;
14
+ private getCollection;
15
+ private getCollectionKey;
16
+ private getCollectionKeyMap;
17
+ private setCollectionKey;
18
+ insert<T>(value: T, writable?: boolean): Promise<IResult<T>>;
12
19
  insertMany<T>(value: T[]): Promise<Array<IResult<T>>>;
13
20
  updateById(id: string, value: IObject): Promise<boolean>;
14
- getById<T>(id: string): Promise<T | undefined>;
21
+ getById<T>(id: string): Promise<IResult<T> | undefined>;
15
22
  removeById(id: string): Promise<void>;
23
+ overwrite<T>(value: T[]): Promise<Array<IResult<T>>>;
16
24
  }
17
25
  export { DBStore };
@@ -1,8 +1,9 @@
1
- import Lowdb from 'lowdb';
1
+ import { IJSON } from './types';
2
2
  declare class JSONStore {
3
3
  private readonly db;
4
+ private hasRead;
4
5
  constructor(dbPath: string);
5
- read(): Lowdb.LowdbSync<Lowdb.AdapterSync<any>>;
6
+ read(flush?: boolean): IJSON;
6
7
  get(key?: string): any;
7
8
  set(key: string, value: any): void;
8
9
  has(key: string): boolean;
@@ -0,0 +1,7 @@
1
+ import { IJSON } from 'src/types';
2
+ export declare class JSONAdapter {
3
+ private readonly adapter;
4
+ constructor(dbName: string);
5
+ read(): IJSON;
6
+ write(obj: any): void;
7
+ }
@@ -1,7 +1,9 @@
1
1
  declare class ZlibAdapter {
2
2
  private readonly dbPath;
3
3
  private readonly collectionName;
4
- constructor(dbPath: string, collectionName: string);
4
+ errorList: Array<Error | string>;
5
+ readCount: number;
6
+ constructor(dbPath: string, collectionName: string, errorList: Array<Error | string>);
5
7
  read(): Promise<any>;
6
8
  write(data: any): Promise<void>;
7
9
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("lowdb")),i=t(require("graceful-fs")),r=require("util"),a=t(require("zlib")),n=t(require("lowdb/adapters/FileSync")),s=t(require("comment-json"));
1
+ "use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@commonify/lowdb"),i=t(require("fs")),r=require("util"),a=require("fflate"),s=t(require("write-file-atomic")),n=t(require("comment-json")),o=t(require("lodash"));
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -13,5 +13,5 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
15
  ***************************************************************************** */
16
- function o(t,e,i,r){var a,n=arguments.length,s=n<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,i,r);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(s=(n<3?a(s):n>3?a(e,i,s):a(e,i))||s);return n>3&&s&&Object.defineProperty(e,i,s),s}const c=r.promisify(i.writeFile);class d{constructor(t,e){this.dbPath=t,this.collectionName=e}async read(){return new Promise((t,e)=>{if(i.existsSync(this.dbPath)){const e=a.createGunzip();let r="";i.createReadStream(this.dbPath).pipe(e),e.on("data",t=>{r+=t.toString()}).on("end",()=>{t(JSON.parse(r))})}else{const i=JSON.stringify({[this.collectionName]:[],[`__${this.collectionName}_KEY__`]:{}});a.gzip(i,async(i,r)=>{if(i)return e(i);await c(this.dbPath,r),t({[this.collectionName]:[],[`__${this.collectionName}_KEY__`]:{}})})}})}async write(t){return new Promise((e,i)=>{t=JSON.stringify(t),a.gzip(t,async(t,r)=>{if(t)return i(t);await c(this.dbPath,r),e()})})}}var l,u;function h(t){return function(e,i,r){const a=r.value;r.value=async function(...e){let i=!1;t===u.create?(Array.isArray(e[0])&&(e=e[0],i=!0),e=e.map(t=>function(t){t.id||(t.id=function(t="",e=""){for(e=t="";t++<36;e+=51*t&52?(15^t?8^Math.random()*(20^t?16:4):4).toString(16):"-");return e}());t.createdAt||(t.createdAt=Date.now(),t.updatedAt=Date.now());return t}(t)),i&&(e=[e])):e[1].updatedAt=Date.now();return await a.call(this,...e)}}}!function(t){t.inited="inited",t.loaded="loaded",t.started="started",t.stopped="stopped"}(l||(l={})),function(t){t[t.create=0]="create",t[t.update=1]="update"}(u||(u={}));class p{constructor(t,i){if(this.reading=null,!t||!i)throw Error("Please provide valid dbPath or collectionName");this.collectionName=i,this.collectionKey=`__${i}_KEY__`;const r=new d(t,i);this.db=e(r)}async read(t=!1){return!t&&this.reading||(this.reading=(await this.db).read()),this.reading}async get(){return(await this.read()).get(this.collectionName).value()}async insert(t){const e=t.id;if((await this.read()).get(`${this.collectionKey}.${e}`).value())return await this.updateById(e,t),t;const i=(await this.read()).get(this.collectionName);return await i.push(t).write(),await(await this.read()).set(`${this.collectionKey}.${e}`,1).write(),t}async insertMany(t){for(const e of t)await this.insert(e);return t}async updateById(t,e){const i=(await this.read()).get(this.collectionName);return!!(await this.read()).get(`${this.collectionKey}.${t}`).value()&&(await i.find({id:t}).assign(e).write(),!0)}async getById(t){return(await this.read()).get(this.collectionName).find({id:t}).value()}async removeById(t){const e=(await this.read()).get(this.collectionName);await e.remove({id:t}).write(),await(await this.read()).get(this.collectionKey).unset(t).write()}}o([h(u.create)],p.prototype,"insert",null),o([h(u.create)],p.prototype,"insertMany",null),o([h(u.update)],p.prototype,"updateById",null);exports.DBStore=p,exports.JSONStore=class{constructor(t){if(!t)throw Error("Please provide valid dbPath");const i=new n(t,{serialize:t=>s.stringify(t,null,2),deserialize:s.parse});this.db=e(i)}read(){return this.db.read()}get(t=""){return this.read().get(t).value()}set(t,e){return this.read().set(t,e).write()}has(t){return this.read().has(t).value()}unset(t,e){return this.read().get(t).unset(e).write()}};
16
+ function c(t,e,i,r){var a,s=arguments.length,n=s<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,r);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(s<3?a(n):s>3?a(e,i,n):a(e,i))||n);return s>3&&n&&Object.defineProperty(e,i,n),n}const d=r.promisify(i.readFile);class l{constructor(t,e,i){this.readCount=0,this.dbPath=t,this.collectionName=e,this.errorList=i}async read(){this.readCount++;const t={[this.collectionName]:[],[`__${this.collectionName}_KEY__`]:{}};return new Promise(async(e,r)=>{if(i.existsSync(this.dbPath)){const i=await d(this.dbPath);a.gunzip(i,(i,r)=>{if(i)return console.error(i),this.errorList.push(i),e(t);const s=a.strFromU8(r);try{const t=JSON.parse(s);return e(t)}catch(i){return console.error(i),this.errorList.push(i),e(t)}})}else{const i=Buffer.from(JSON.stringify(t));a.gzip(i,async(i,a)=>{if(i)return r(i);await s(this.dbPath,Buffer.from(a)),e(t)})}})}async write(t){return new Promise((e,i)=>{t=Buffer.from(JSON.stringify(t)),a.gzip(t,async(t,r)=>{if(t)return i(t);await s(this.dbPath,Buffer.from(r)),e()})})}}var h,u;function f(t){return function(e,i,r){const a=r.value;r.value=async function(...e){t===u.createMany?e=[e=(e=e[0]).map(t=>y(t))]:t===u.create?e[0]=y(e[0]):e[1].updatedAt=Date.now();return await a.call(this,...e)}}}function y(t){return t.id||(t.id=function(t="",e=""){for(e=t="";t++<36;e+=51*t&52?(15^t?8^Math.random()*(20^t?16:4):4).toString(16):"-");return e}()),t.createdAt||(t.createdAt=Date.now(),t.updatedAt=Date.now()),t}!function(t){t.inited="inited",t.loaded="loaded",t.started="started",t.stopped="stopped"}(h||(h={})),function(t){t[t.createMany=0]="createMany",t[t.create=1]="create",t[t.update=2]="update"}(u||(u={}));class p{constructor(t,i){if(this.hasRead=!1,this.errorList=[],!t||!i)throw Error("Please provide valid dbPath or collectionName");this.collectionName=i,this.collectionKey=`__${i}_KEY__`,this.adapter=new l(t,i,this.errorList),this.db=new e.Low(this.adapter)}getAdapter(){return this.adapter}async read(t=!1){return!t&&this.hasRead||(this.hasRead=!0,await this.db.read()),this.db.data}async get(t){let e=(await this.getCollection()).slice();const i=e.length;return void 0!==t&&("desc"===t.orderBy&&(e=e.reverse()),"number"==typeof t.offset&&t.offset>=0&&(e=e.slice(t.offset)),"number"==typeof t.limit&&t.limit>0&&(e=e.slice(0,t.limit))),{total:i,data:e}}async getCollection(){var t;return null===(t=await this.read())||void 0===t?void 0:t[this.collectionName]}async getCollectionKey(t){return(await this.getCollectionKeyMap())[t]}async getCollectionKeyMap(){var t;return null===(t=await this.read())||void 0===t?void 0:t[this.collectionKey]}async setCollectionKey(t){await this.read();this.db.data[this.collectionKey][t]=1}async insert(t,e=!0){const i=t.id;return await this.getCollectionKey(i)?(await this.updateById(i,t),t):((await this.getCollection()).push(t),await this.setCollectionKey(i),e&&await this.db.write(),t)}async insertMany(t){for(const e of t)await this.insert(e,!1);return await this.db.write(),t}async updateById(t,e){const i=await this.getCollection();if(await this.getCollectionKey(t)){const r=i.find(e=>e.id===t);return Object.assign(r,e),await this.db.write(),!0}return!1}async getById(t){return(await this.getCollection()).find(e=>e.id===t)}async removeById(t){const e=await this.getCollection(),i=await this.getCollectionKeyMap(),r=e.findIndex(e=>e.id===t);-1!==r&&(e.splice(r,1),delete i[t],await this.db.write())}async overwrite(t){return await this.read(),this.db.data[this.collectionName]=[],this.db.data[this.collectionKey]={},await this.insertMany(t)}}c([f(u.create)],p.prototype,"insert",null),c([f(u.createMany)],p.prototype,"insertMany",null),c([f(u.update)],p.prototype,"updateById",null);class w{constructor(t){this.adapter=new e.TextFileSync(t)}read(){const t=this.adapter.read();return null===t?{}:n.parse(t)}write(t){this.adapter.write(n.stringify(t))}}class b extends e.LowSync{constructor(){super(...arguments),this.chain=o.chain(this).get("data")}}exports.DBStore=p,exports.JSONStore=class{constructor(t){if(this.hasRead=!1,!t)throw Error("Please provide valid dbPath");const e=new w(t);this.db=new b(e),this.read()}read(t=!1){return!t&&this.hasRead||(this.hasRead=!0,this.db.read()),this.db.data}get(t=""){return this.db.chain.get(t).value()}set(t,e){this.db.chain.set(t,e).value(),this.db.write()}has(t){return this.db.chain.has(t).value()}unset(t,e){const i=this.db.chain.get(t).unset(e).value();return this.db.write(),i}};
17
17
  //# sourceMappingURL=index.js.map