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