@picgo/store 2.0.1 → 2.0.4
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/CHANGELOG.md +32 -0
- package/coverage/clover.xml +78 -69
- package/coverage/coverage-final.json +3 -3
- package/coverage/lcov-report/index.html +17 -17
- package/coverage/lcov-report/src/DBStore.ts.html +11 -8
- package/coverage/lcov-report/src/JSONStore.ts.html +11 -11
- package/coverage/lcov-report/src/adapters/JSONAdapter.ts.html +69 -18
- package/coverage/lcov-report/src/adapters/ZlibAdapter.ts.html +2 -2
- package/coverage/lcov-report/src/adapters/index.html +15 -15
- package/coverage/lcov-report/src/index.html +5 -5
- package/coverage/lcov-report/src/types/index.html +1 -1
- package/coverage/lcov-report/src/types/index.ts.html +1 -1
- package/coverage/lcov-report/src/utils/index.html +1 -1
- package/coverage/lcov-report/src/utils/metaInfoHelper.ts.html +1 -1
- package/coverage/lcov.info +143 -133
- package/dist/adapters/JSONAdapter.d.ts +2 -1
- package/dist/index.js +2 -17
- package/package.json +15 -13
- package/rollup.config.js +8 -3
- package/dist/index.js.map +0 -1
package/coverage/lcov.info
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
TN:
|
|
2
2
|
SF:/home/runner/work/store/store/src/DBStore.ts
|
|
3
|
-
FN:
|
|
4
|
-
FN:
|
|
5
|
-
FN:
|
|
6
|
-
FN:
|
|
7
|
-
FN:
|
|
8
|
-
FN:
|
|
9
|
-
FN:
|
|
10
|
-
FN:
|
|
11
|
-
FN:
|
|
12
|
-
FN:
|
|
13
|
-
FN:
|
|
14
|
-
FN:
|
|
15
|
-
FN:
|
|
16
|
-
FN:
|
|
17
|
-
FN:
|
|
18
|
-
FN:
|
|
19
|
-
FN:
|
|
3
|
+
FN:17,(anonymous_0)
|
|
4
|
+
FN:28,(anonymous_1)
|
|
5
|
+
FN:32,(anonymous_2)
|
|
6
|
+
FN:40,(anonymous_3)
|
|
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)
|
|
20
20
|
FNF:17
|
|
21
21
|
FNH:17
|
|
22
22
|
FNDA:18,(anonymous_0)
|
|
@@ -36,120 +36,114 @@ FNDA:4,(anonymous_13)
|
|
|
36
36
|
FNDA:1,(anonymous_14)
|
|
37
37
|
FNDA:1,(anonymous_15)
|
|
38
38
|
FNDA:1,(anonymous_16)
|
|
39
|
-
DA:4,1
|
|
40
39
|
DA:5,1
|
|
41
40
|
DA:6,1
|
|
42
41
|
DA:7,1
|
|
43
|
-
DA:
|
|
42
|
+
DA:8,1
|
|
44
43
|
DA:14,18
|
|
45
|
-
DA:
|
|
46
|
-
DA:19,
|
|
47
|
-
DA:
|
|
44
|
+
DA:15,18
|
|
45
|
+
DA:19,18
|
|
46
|
+
DA:20,2
|
|
48
47
|
DA:22,16
|
|
49
48
|
DA:23,16
|
|
50
49
|
DA:24,16
|
|
51
|
-
DA:
|
|
52
|
-
DA:
|
|
53
|
-
DA:33,
|
|
50
|
+
DA:25,16
|
|
51
|
+
DA:29,1
|
|
52
|
+
DA:33,56
|
|
54
53
|
DA:34,16
|
|
55
|
-
DA:
|
|
56
|
-
DA:
|
|
54
|
+
DA:35,16
|
|
55
|
+
DA:37,56
|
|
57
56
|
DA:41,18
|
|
58
57
|
DA:42,18
|
|
59
|
-
DA:43,
|
|
60
|
-
DA:44,
|
|
61
|
-
DA:
|
|
62
|
-
DA:47,
|
|
63
|
-
DA:
|
|
64
|
-
DA:50,
|
|
65
|
-
DA:
|
|
66
|
-
DA:
|
|
67
|
-
DA:
|
|
68
|
-
DA:
|
|
69
|
-
DA:
|
|
58
|
+
DA:43,18
|
|
59
|
+
DA:44,6
|
|
60
|
+
DA:45,1
|
|
61
|
+
DA:47,6
|
|
62
|
+
DA:48,1
|
|
63
|
+
DA:50,6
|
|
64
|
+
DA:51,1
|
|
65
|
+
DA:54,18
|
|
66
|
+
DA:61,33
|
|
67
|
+
DA:65,12
|
|
68
|
+
DA:69,13
|
|
70
69
|
DA:73,8
|
|
71
70
|
DA:74,8
|
|
72
71
|
DA:75,8
|
|
73
|
-
DA:
|
|
74
|
-
DA:80,
|
|
72
|
+
DA:76,8
|
|
73
|
+
DA:80,1
|
|
75
74
|
DA:81,9
|
|
76
|
-
DA:
|
|
77
|
-
DA:84,
|
|
75
|
+
DA:82,9
|
|
76
|
+
DA:84,9
|
|
78
77
|
DA:85,1
|
|
79
|
-
DA:
|
|
78
|
+
DA:86,1
|
|
80
79
|
DA:88,8
|
|
81
80
|
DA:89,8
|
|
82
|
-
DA:90,
|
|
83
|
-
DA:
|
|
84
|
-
DA:
|
|
85
|
-
DA:97,
|
|
86
|
-
DA:98,
|
|
87
|
-
DA:
|
|
81
|
+
DA:90,8
|
|
82
|
+
DA:91,3
|
|
83
|
+
DA:93,8
|
|
84
|
+
DA:97,1
|
|
85
|
+
DA:98,2
|
|
86
|
+
DA:99,5
|
|
88
87
|
DA:101,2
|
|
89
|
-
DA:
|
|
90
|
-
DA:106,
|
|
88
|
+
DA:102,2
|
|
89
|
+
DA:106,1
|
|
91
90
|
DA:107,3
|
|
92
91
|
DA:108,3
|
|
93
|
-
DA:109,
|
|
94
|
-
DA:110,
|
|
92
|
+
DA:109,3
|
|
93
|
+
DA:110,5
|
|
95
94
|
DA:111,2
|
|
96
95
|
DA:112,2
|
|
97
|
-
DA:
|
|
98
|
-
DA:
|
|
99
|
-
DA:
|
|
96
|
+
DA:113,2
|
|
97
|
+
DA:115,1
|
|
98
|
+
DA:120,4
|
|
100
99
|
DA:124,1
|
|
101
100
|
DA:125,1
|
|
102
101
|
DA:126,1
|
|
103
102
|
DA:127,1
|
|
104
103
|
DA:128,1
|
|
105
104
|
DA:129,1
|
|
106
|
-
DA:
|
|
105
|
+
DA:130,1
|
|
107
106
|
DA:135,1
|
|
108
107
|
DA:136,1
|
|
109
108
|
DA:137,1
|
|
110
|
-
DA:
|
|
109
|
+
DA:138,1
|
|
110
|
+
DA:143,1
|
|
111
111
|
LF:72
|
|
112
112
|
LH:72
|
|
113
|
-
BRDA:
|
|
114
|
-
BRDA:
|
|
115
|
-
BRDA:
|
|
116
|
-
BRDA:
|
|
117
|
-
BRDA:
|
|
118
|
-
BRDA:
|
|
119
|
-
BRDA:
|
|
120
|
-
BRDA:
|
|
121
|
-
BRDA:
|
|
122
|
-
BRDA:
|
|
123
|
-
BRDA:
|
|
124
|
-
BRDA:
|
|
125
|
-
BRDA:
|
|
126
|
-
BRDA:
|
|
127
|
-
BRDA:
|
|
128
|
-
BRDA:
|
|
129
|
-
BRDA:
|
|
130
|
-
BRDA:
|
|
131
|
-
BRDA:
|
|
132
|
-
BRDA:
|
|
133
|
-
BRDA:
|
|
134
|
-
BRDA:
|
|
135
|
-
BRDA:
|
|
136
|
-
BRDA:
|
|
137
|
-
BRDA:
|
|
138
|
-
BRDA:
|
|
139
|
-
BRDA:
|
|
140
|
-
BRDA:
|
|
141
|
-
BRDA:
|
|
142
|
-
BRDA:
|
|
143
|
-
BRDA:
|
|
144
|
-
BRDA:
|
|
145
|
-
|
|
146
|
-
|
|
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
|
|
113
|
+
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:43,5,0,6
|
|
123
|
+
BRDA:43,5,1,12
|
|
124
|
+
BRDA:44,6,0,1
|
|
125
|
+
BRDA:44,6,1,5
|
|
126
|
+
BRDA:47,7,0,1
|
|
127
|
+
BRDA:47,7,1,5
|
|
128
|
+
BRDA:47,8,0,6
|
|
129
|
+
BRDA:47,8,1,2
|
|
130
|
+
BRDA:50,9,0,1
|
|
131
|
+
BRDA:50,9,1,5
|
|
132
|
+
BRDA:50,10,0,6
|
|
133
|
+
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
|
|
153
147
|
end_of_record
|
|
154
148
|
TN:
|
|
155
149
|
SF:/home/runner/work/store/store/src/JSONStore.ts
|
|
@@ -162,9 +156,9 @@ FN:39,(anonymous_5)
|
|
|
162
156
|
FN:43,(anonymous_6)
|
|
163
157
|
FNF:7
|
|
164
158
|
FNH:7
|
|
165
|
-
FNDA:
|
|
166
|
-
FNDA:
|
|
167
|
-
FNDA:
|
|
159
|
+
FNDA:7,(anonymous_0)
|
|
160
|
+
FNDA:8,(anonymous_1)
|
|
161
|
+
FNDA:10,(anonymous_2)
|
|
168
162
|
FNDA:4,(anonymous_3)
|
|
169
163
|
FNDA:2,(anonymous_4)
|
|
170
164
|
FNDA:1,(anonymous_5)
|
|
@@ -172,17 +166,17 @@ FNDA:1,(anonymous_6)
|
|
|
172
166
|
DA:1,1
|
|
173
167
|
DA:2,1
|
|
174
168
|
DA:3,1
|
|
175
|
-
DA:7,
|
|
176
|
-
DA:11,
|
|
177
|
-
DA:13,
|
|
169
|
+
DA:7,7
|
|
170
|
+
DA:11,8
|
|
171
|
+
DA:13,8
|
|
178
172
|
DA:14,1
|
|
179
|
-
DA:16,
|
|
180
|
-
DA:17,
|
|
181
|
-
DA:18,
|
|
182
|
-
DA:23,
|
|
183
|
-
DA:24,
|
|
184
|
-
DA:25,
|
|
185
|
-
DA:27,
|
|
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
|
|
186
180
|
DA:31,4
|
|
187
181
|
DA:35,2
|
|
188
182
|
DA:36,2
|
|
@@ -194,40 +188,56 @@ DA:51,1
|
|
|
194
188
|
LF:22
|
|
195
189
|
LH:22
|
|
196
190
|
BRDA:13,0,0,1
|
|
197
|
-
BRDA:13,0,1,
|
|
198
|
-
BRDA:21,1,0,
|
|
199
|
-
BRDA:23,2,0,
|
|
200
|
-
BRDA:23,3,0,
|
|
201
|
-
BRDA:23,3,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
|
|
202
196
|
BRDA:30,4,0,1
|
|
203
197
|
BRF:7
|
|
204
198
|
BRH:7
|
|
205
199
|
end_of_record
|
|
206
200
|
TN:
|
|
207
201
|
SF:/home/runner/work/store/store/src/adapters/JSONAdapter.ts
|
|
208
|
-
FN:
|
|
209
|
-
FN:
|
|
210
|
-
FN:
|
|
202
|
+
FN:8,(anonymous_0)
|
|
203
|
+
FN:13,(anonymous_1)
|
|
204
|
+
FN:37,(anonymous_2)
|
|
211
205
|
FNF:3
|
|
212
206
|
FNH:3
|
|
213
|
-
FNDA:
|
|
214
|
-
FNDA:
|
|
207
|
+
FNDA:7,(anonymous_0)
|
|
208
|
+
FNDA:10,(anonymous_1)
|
|
215
209
|
FNDA:3,(anonymous_2)
|
|
216
210
|
DA:1,1
|
|
217
211
|
DA:2,1
|
|
212
|
+
DA:4,1
|
|
218
213
|
DA:5,1
|
|
219
|
-
DA:
|
|
220
|
-
DA:
|
|
221
|
-
DA:
|
|
222
|
-
DA:
|
|
223
|
-
DA:
|
|
224
|
-
DA:21,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|
223
|
+
DA:27,4
|
|
224
|
+
DA:28,4
|
|
225
|
+
DA:30,4
|
|
226
|
+
DA:31,4
|
|
227
|
+
DA:38,3
|
|
228
|
+
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
|
|
231
241
|
end_of_record
|
|
232
242
|
TN:
|
|
233
243
|
SF:/home/runner/work/store/store/src/adapters/ZlibAdapter.ts
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
6
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
|
|
8
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
9
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
10
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
11
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
-
|
|
13
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
|
-
and limitations under the License.
|
|
15
|
-
***************************************************************************** */
|
|
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,null,2))}}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
|
-
//# sourceMappingURL=index.js.map
|
|
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}};
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picgo/store",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -45,29 +45,31 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@commitlint/cli": "^8.3.5",
|
|
47
47
|
"@picgo/bump-version": "^1.0.3",
|
|
48
|
+
"@rollup/plugin-commonjs": "^22.0.2",
|
|
48
49
|
"@types/jest": "^24.9.0",
|
|
49
50
|
"@types/node": "^13.1.7",
|
|
50
51
|
"@types/write-file-atomic": "^4.0.0",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "5.33.1",
|
|
52
53
|
"commitizen": "^4.2.4",
|
|
53
54
|
"conventional-changelog": "^3.1.18",
|
|
54
55
|
"coveralls": "^3.0.9",
|
|
55
56
|
"cz-customizable": "^6.2.0",
|
|
56
|
-
"eslint": "
|
|
57
|
-
"eslint-config-standard-with-typescript": "^
|
|
58
|
-
"eslint-plugin-import": "2",
|
|
59
|
-
"eslint-plugin-
|
|
60
|
-
"eslint-plugin-
|
|
61
|
-
"eslint-plugin-
|
|
57
|
+
"eslint": "8.22.0",
|
|
58
|
+
"eslint-config-standard-with-typescript": "^22.0.0",
|
|
59
|
+
"eslint-plugin-import": "2.26.0",
|
|
60
|
+
"eslint-plugin-n": "^15.2.4",
|
|
61
|
+
"eslint-plugin-node": "11.1.0",
|
|
62
|
+
"eslint-plugin-promise": "6.0.0",
|
|
63
|
+
"eslint-plugin-standard": "5.0.0",
|
|
62
64
|
"husky": "^4.0.10",
|
|
63
65
|
"jest": "^24.9.0",
|
|
64
66
|
"rimraf": "^3.0.2",
|
|
65
|
-
"rollup": "^
|
|
67
|
+
"rollup": "^2.78.1",
|
|
66
68
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
67
|
-
"rollup-plugin-terser": "^
|
|
68
|
-
"rollup-plugin-typescript2": "^0.
|
|
69
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
70
|
+
"rollup-plugin-typescript2": "^0.33.0",
|
|
69
71
|
"ts-jest": "^24.3.0",
|
|
70
|
-
"typescript": "^
|
|
72
|
+
"typescript": "^4.7.4"
|
|
71
73
|
},
|
|
72
74
|
"dependencies": {
|
|
73
75
|
"@commonify/lowdb": "^3.0.0",
|
|
@@ -75,7 +77,7 @@
|
|
|
75
77
|
"@types/bson": "^4.0.1",
|
|
76
78
|
"@types/graceful-fs": "^4.1.3",
|
|
77
79
|
"@types/lodash": "^4.14.182",
|
|
78
|
-
"comment-json": "^4.
|
|
80
|
+
"comment-json": "^4.2.3",
|
|
79
81
|
"fflate": "^0.7.3",
|
|
80
82
|
"lodash": "^4.17.21",
|
|
81
83
|
"lodash-id": "^0.14.0",
|
package/rollup.config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { terser } from 'rollup-plugin-terser'
|
|
2
2
|
import typescript from 'rollup-plugin-typescript2'
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs'
|
|
3
4
|
// import resolve from 'rollup-plugin-node-resolve'
|
|
4
5
|
export default {
|
|
5
6
|
input: './src/index.ts',
|
|
@@ -7,7 +8,8 @@ export default {
|
|
|
7
8
|
typescript({
|
|
8
9
|
tsconfigOverride: {
|
|
9
10
|
compilerOptions: {
|
|
10
|
-
|
|
11
|
+
target: 'ES2017',
|
|
12
|
+
module: 'ES2020'
|
|
11
13
|
},
|
|
12
14
|
exclude: [
|
|
13
15
|
'node_modules',
|
|
@@ -16,12 +18,13 @@ export default {
|
|
|
16
18
|
]
|
|
17
19
|
}
|
|
18
20
|
}),
|
|
21
|
+
commonjs(),
|
|
19
22
|
terser()
|
|
20
23
|
],
|
|
21
24
|
output: [{
|
|
22
25
|
format: 'cjs',
|
|
23
26
|
file: 'dist/index.js',
|
|
24
|
-
sourcemap:
|
|
27
|
+
sourcemap: 'inline'
|
|
25
28
|
}],
|
|
26
29
|
external: [
|
|
27
30
|
'write-file-atomic',
|
|
@@ -29,6 +32,8 @@ export default {
|
|
|
29
32
|
'@commonify/lowdb',
|
|
30
33
|
'fflate',
|
|
31
34
|
'util',
|
|
32
|
-
'fs'
|
|
35
|
+
'fs',
|
|
36
|
+
'lodash',
|
|
37
|
+
'comment-json'
|
|
33
38
|
]
|
|
34
39
|
}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|