@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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,39 @@
1
+ # :tada: 2.0.0 (2022-06-11)
2
+
3
+
4
+ ### :sparkles: Features
5
+
6
+ * add overwrite for DBStore && update lowdb version ([ebd28d9](https://github.com/Molunerfinn/typescript-node-template/commit/ebd28d9))
7
+
8
+
9
+
10
+ ## :tada: 1.0.4 (2022-06-11)
11
+
12
+
13
+ ### :bug: Bug Fixes
14
+
15
+ * gzip data read error will cause DBStore crash ([01df844](https://github.com/Molunerfinn/typescript-node-template/commit/01df844))
16
+
17
+
18
+
19
+ ## :tada: 1.0.3 (2021-08-01)
20
+
21
+
22
+ ### :bug: Bug Fixes
23
+
24
+ * reverse will change data self ([bcb32bd](https://github.com/Molunerfinn/typescript-node-template/commit/bcb32bd))
25
+
26
+
27
+
28
+ ## :tada: 1.0.2 (2021-08-01)
29
+
30
+
31
+ ### :sparkles: Features
32
+
33
+ * add filter support ([8cf57e8](https://github.com/Molunerfinn/typescript-node-template/commit/8cf57e8))
34
+
35
+
36
+
1
37
  ## :tada: 1.0.1 (2021-07-31)
2
38
 
3
39
 
package/README.md CHANGED
@@ -37,17 +37,30 @@ For now, `@picgo/store` has two export member: `DBStore` & `JSONStore`.
37
37
  const db = new DBStore('picgo.db', 'uploadImgs')
38
38
  ```
39
39
 
40
- #### Get `.get()`
40
+ #### Get `.get(filter?: IFilter)`
41
41
 
42
- - return: `Promise<IObject[]>`
43
- - interface: [IObject](/src/types/index.ts)
42
+ - return: `Promise<IGetResult<IObject>[]>`
43
+ - interface: [IGetResult](/src/types/index.ts)
44
44
 
45
45
  To get the whole collection value.
46
46
 
47
47
  ```js
48
48
  async () => {
49
49
  const collection = await db.get()
50
- console.log(collection) // []
50
+ console.log(collection) // { total: x, data: [{...}, {...}, ...] }
51
+ }
52
+ ```
53
+
54
+ To get filtered collection: (just like SQL `orderBy`, `limit` & `offset`)
55
+
56
+ ```js
57
+ async () => {
58
+ const collection = await db.get({
59
+ orderBy: 'desc', // ['desc' | 'asc'] -> order with created-time
60
+ limit: 1, // limit >= 1
61
+ offset: 0, // offset >= 0
62
+ })
63
+ console.log(collection) // { total: 1, data: [{...}] }
51
64
  }
52
65
  ```
53
66
 
@@ -136,7 +149,7 @@ async () => {
136
149
  }
137
150
  ```
138
151
 
139
- #### `.removeById(id: string)`: Promise<void>;
152
+ #### RemoveById `.removeById(id: string)`;
140
153
 
141
154
  - return: `Promise<void>`
142
155
 
@@ -149,6 +162,38 @@ async () => {
149
162
  }
150
163
  ```
151
164
 
165
+ #### Overwrite `.overwrite()<T>(value: T[])` (v2.0.0)
166
+
167
+ - return: `Promise<IResult<T>[]>`
168
+ - interface: [IResult](/src/types/index.ts)
169
+
170
+ To overwrite whole collection:
171
+
172
+ ```js
173
+ async () => {
174
+ const result = await db.overwrite([
175
+ {
176
+ imgUrl: 'https://xxxx.jpg'
177
+ },
178
+ {
179
+ imgUrl: 'https://yyyy.jpg'
180
+ }
181
+ ])
182
+ console.log(result)
183
+ // [{
184
+ // id: string,
185
+ // imgUrl: string,
186
+ // createdAt: number,
187
+ // updatedAt: number
188
+ // },{
189
+ // id: string,
190
+ // imgUrl: string,
191
+ // createdAt: number,
192
+ // updatedAt: number
193
+ // }]
194
+ }
195
+ ```
196
+
152
197
  ## License
153
198
 
154
199
  [MIT](http://opensource.org/licenses/MIT)
@@ -1,144 +1,203 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <coverage generated="1627736076431" clover="3.2.0">
3
- <project timestamp="1627736076431" name="All files">
4
- <metrics statements="112" coveredstatements="112" conditionals="40" coveredconditionals="40" methods="33" coveredmethods="33" elements="185" coveredelements="185" complexity="0" loc="112" ncloc="112" packages="4" files="5" classes="5"/>
2
+ <coverage generated="1654999899287" clover="3.2.0">
3
+ <project timestamp="1654999899287" name="All files">
4
+ <metrics statements="168" coveredstatements="168" conditionals="71" coveredconditionals="68" methods="44" coveredmethods="44" elements="283" coveredelements="280" complexity="0" loc="168" ncloc="168" packages="4" files="6" classes="6"/>
5
5
  <package name="src">
6
- <metrics statements="55" coveredstatements="55" conditionals="16" coveredconditionals="16" methods="15" coveredmethods="15"/>
6
+ <metrics statements="94" coveredstatements="94" conditionals="45" coveredconditionals="42" methods="24" coveredmethods="24"/>
7
7
  <file name="DBStore.ts" path="/home/runner/work/store/store/src/DBStore.ts">
8
- <metrics statements="41" coveredstatements="41" conditionals="13" coveredconditionals="13" methods="8" coveredmethods="8"/>
9
- <line num="1" count="1" type="stmt"/>
10
- <line num="2" count="1" type="stmt"/>
11
- <line num="3" count="1" type="stmt"/>
8
+ <metrics statements="72" coveredstatements="72" conditionals="38" coveredconditionals="35" methods="17" coveredmethods="17"/>
12
9
  <line num="4" count="1" type="stmt"/>
13
- <line num="9" count="10" type="stmt"/>
14
- <line num="12" count="10" type="cond" truecount="4" falsecount="0"/>
15
- <line num="13" count="2" type="stmt"/>
16
- <line num="15" count="8" type="stmt"/>
17
- <line num="16" count="8" type="stmt"/>
18
- <line num="17" count="8" type="stmt"/>
19
- <line num="18" count="8" type="stmt"/>
20
- <line num="22" count="30" type="cond" truecount="4" falsecount="0"/>
21
- <line num="23" count="8" type="stmt"/>
22
- <line num="25" count="30" type="stmt"/>
23
- <line num="29" count="3" type="stmt"/>
24
- <line num="33" count="1" type="stmt"/>
25
- <line num="34" count="6" type="stmt"/>
26
- <line num="36" count="6" type="stmt"/>
27
- <line num="38" count="6" type="cond" truecount="2" falsecount="0"/>
28
- <line num="39" count="1" type="stmt"/>
29
- <line num="40" count="1" type="stmt"/>
30
- <line num="42" count="5" type="stmt"/>
31
- <line num="44" count="5" type="stmt"/>
32
- <line num="45" count="5" type="stmt"/>
33
- <line num="46" count="5" type="stmt"/>
10
+ <line num="5" count="1" type="stmt"/>
11
+ <line num="6" count="1" type="stmt"/>
12
+ <line num="7" count="1" type="stmt"/>
13
+ <line num="13" count="18" type="stmt"/>
14
+ <line num="14" count="18" type="stmt"/>
15
+ <line num="18" count="18" type="cond" truecount="4" falsecount="0"/>
16
+ <line num="19" count="2" type="stmt"/>
17
+ <line num="21" count="16" type="stmt"/>
18
+ <line num="22" count="16" type="stmt"/>
19
+ <line num="23" count="16" type="stmt"/>
20
+ <line num="24" count="16" type="stmt"/>
21
+ <line num="28" count="1" type="stmt"/>
22
+ <line num="32" count="56" type="cond" truecount="4" falsecount="0"/>
23
+ <line num="33" count="16" type="stmt"/>
24
+ <line num="34" count="16" type="stmt"/>
25
+ <line num="36" count="56" type="stmt"/>
26
+ <line num="40" count="18" type="stmt"/>
27
+ <line num="41" count="18" type="stmt"/>
28
+ <line num="42" count="18" type="cond" truecount="2" falsecount="0"/>
29
+ <line num="43" count="6" type="cond" truecount="2" falsecount="0"/>
30
+ <line num="44" count="1" type="stmt"/>
31
+ <line num="46" count="6" type="cond" truecount="4" falsecount="0"/>
32
+ <line num="47" count="1" type="stmt"/>
33
+ <line num="49" count="6" type="cond" truecount="4" falsecount="0"/>
34
34
  <line num="50" count="1" type="stmt"/>
35
- <line num="51" count="1" type="stmt"/>
36
- <line num="52" count="2" type="stmt"/>
37
- <line num="54" count="1" type="stmt"/>
38
- <line num="58" count="1" type="stmt"/>
39
- <line num="59" count="3" type="stmt"/>
40
- <line num="60" count="3" type="stmt"/>
41
- <line num="61" count="3" type="cond" truecount="2" falsecount="0"/>
42
- <line num="63" count="2" type="stmt"/>
43
- <line num="64" count="2" type="stmt"/>
44
- <line num="66" count="1" type="stmt"/>
45
- <line num="71" count="3" type="stmt"/>
46
- <line num="79" count="1" type="stmt"/>
47
- <line num="81" count="1" type="stmt"/>
48
- <line num="82" count="1" type="stmt"/>
49
- <line num="87" count="1" type="stmt"/>
35
+ <line num="53" count="18" type="stmt"/>
36
+ <line num="60" count="33" type="cond" truecount="3" falsecount="1"/>
37
+ <line num="64" count="12" type="stmt"/>
38
+ <line num="68" count="13" type="cond" truecount="3" falsecount="1"/>
39
+ <line num="72" count="8" type="stmt"/>
40
+ <line num="73" count="8" type="stmt"/>
41
+ <line num="74" count="8" type="stmt"/>
42
+ <line num="75" count="8" type="stmt"/>
43
+ <line num="79" count="1" type="cond" truecount="1" falsecount="0"/>
44
+ <line num="80" count="9" type="stmt"/>
45
+ <line num="81" count="9" type="stmt"/>
46
+ <line num="83" count="9" type="cond" truecount="2" falsecount="0"/>
47
+ <line num="84" count="1" type="stmt"/>
48
+ <line num="85" count="1" type="stmt"/>
49
+ <line num="87" count="8" type="stmt"/>
50
+ <line num="88" count="8" type="stmt"/>
51
+ <line num="89" count="8" type="cond" truecount="2" falsecount="0"/>
52
+ <line num="90" count="3" type="stmt"/>
53
+ <line num="92" count="8" type="stmt"/>
54
+ <line num="96" count="1" type="stmt"/>
55
+ <line num="97" count="2" type="stmt"/>
56
+ <line num="98" count="5" type="stmt"/>
57
+ <line num="100" count="2" type="stmt"/>
58
+ <line num="101" count="2" type="stmt"/>
59
+ <line num="105" count="1" type="stmt"/>
60
+ <line num="106" count="3" type="stmt"/>
61
+ <line num="107" count="3" type="stmt"/>
62
+ <line num="108" count="3" type="cond" truecount="2" falsecount="0"/>
63
+ <line num="109" count="5" type="stmt"/>
64
+ <line num="110" count="2" type="stmt"/>
65
+ <line num="111" count="2" type="stmt"/>
66
+ <line num="112" count="2" type="stmt"/>
67
+ <line num="114" count="1" type="stmt"/>
68
+ <line num="119" count="4" type="stmt"/>
69
+ <line num="123" count="1" type="stmt"/>
70
+ <line num="124" count="1" type="stmt"/>
71
+ <line num="125" count="1" type="stmt"/>
72
+ <line num="126" count="1" type="cond" truecount="1" falsecount="1"/>
73
+ <line num="127" count="1" type="stmt"/>
74
+ <line num="128" count="1" type="stmt"/>
75
+ <line num="129" count="1" type="stmt"/>
76
+ <line num="134" count="1" type="stmt"/>
77
+ <line num="135" count="1" type="stmt"/>
78
+ <line num="136" count="1" type="stmt"/>
79
+ <line num="137" count="1" type="stmt"/>
80
+ <line num="142" count="1" type="stmt"/>
50
81
  </file>
51
82
  <file name="JSONStore.ts" path="/home/runner/work/store/store/src/JSONStore.ts">
52
- <metrics statements="14" coveredstatements="14" conditionals="3" coveredconditionals="3" methods="7" coveredmethods="7"/>
83
+ <metrics statements="22" coveredstatements="22" conditionals="7" coveredconditionals="7" methods="7" coveredmethods="7"/>
53
84
  <line num="1" count="1" type="stmt"/>
54
85
  <line num="2" count="1" type="stmt"/>
55
86
  <line num="3" count="1" type="stmt"/>
56
- <line num="7" count="5" type="cond" truecount="2" falsecount="0"/>
57
- <line num="8" count="1" type="stmt"/>
58
- <line num="10" count="4" type="stmt"/>
59
- <line num="12" count="3" type="stmt"/>
60
- <line num="16" count="4" type="stmt"/>
61
- <line num="20" count="6" type="stmt"/>
62
- <line num="24" count="3" type="stmt"/>
63
- <line num="28" count="1" type="stmt"/>
64
- <line num="32" count="1" type="stmt"/>
65
- <line num="36" count="1" type="stmt"/>
66
- <line num="41" count="1" type="stmt"/>
87
+ <line num="7" count="5" type="stmt"/>
88
+ <line num="11" count="6" type="stmt"/>
89
+ <line num="13" count="6" type="cond" truecount="2" falsecount="0"/>
90
+ <line num="14" count="1" type="stmt"/>
91
+ <line num="16" count="5" type="stmt"/>
92
+ <line num="17" count="5" type="stmt"/>
93
+ <line num="18" count="5" type="stmt"/>
94
+ <line num="23" count="6" type="cond" truecount="3" falsecount="0"/>
95
+ <line num="24" count="6" type="stmt"/>
96
+ <line num="25" count="6" type="stmt"/>
97
+ <line num="27" count="6" type="stmt"/>
98
+ <line num="31" count="4" type="stmt"/>
99
+ <line num="35" count="2" type="stmt"/>
100
+ <line num="36" count="2" type="stmt"/>
101
+ <line num="40" count="1" type="stmt"/>
102
+ <line num="44" count="1" type="stmt"/>
103
+ <line num="45" count="1" type="stmt"/>
104
+ <line num="46" count="1" type="stmt"/>
105
+ <line num="51" count="1" type="stmt"/>
67
106
  </file>
68
107
  </package>
69
108
  <package name="src.adapters">
70
- <metrics statements="24" coveredstatements="24" conditionals="2" coveredconditionals="2" methods="9" coveredmethods="9"/>
109
+ <metrics statements="42" coveredstatements="42" conditionals="6" coveredconditionals="6" methods="11" coveredmethods="11"/>
110
+ <file name="JSONAdapter.ts" path="/home/runner/work/store/store/src/adapters/JSONAdapter.ts">
111
+ <metrics statements="9" coveredstatements="9" conditionals="2" coveredconditionals="2" methods="3" coveredmethods="3"/>
112
+ <line num="1" count="1" type="stmt"/>
113
+ <line num="2" count="1" type="stmt"/>
114
+ <line num="5" count="1" type="stmt"/>
115
+ <line num="8" count="5" type="stmt"/>
116
+ <line num="12" count="6" type="stmt"/>
117
+ <line num="13" count="6" type="cond" truecount="2" falsecount="0"/>
118
+ <line num="14" count="1" type="stmt"/>
119
+ <line num="16" count="5" type="stmt"/>
120
+ <line num="21" count="3" type="stmt"/>
121
+ </file>
71
122
  <file name="ZlibAdapter.ts" path="/home/runner/work/store/store/src/adapters/ZlibAdapter.ts">
72
- <metrics statements="24" coveredstatements="24" conditionals="2" coveredconditionals="2" methods="9" coveredmethods="9"/>
73
- <line num="3" count="1" type="stmt"/>
123
+ <metrics statements="33" coveredstatements="33" conditionals="4" coveredconditionals="4" methods="8" coveredmethods="8"/>
74
124
  <line num="4" count="1" type="stmt"/>
75
125
  <line num="5" count="1" type="stmt"/>
126
+ <line num="6" count="1" type="stmt"/>
76
127
  <line num="7" count="1" type="stmt"/>
77
- <line num="14" count="8" type="stmt"/>
78
- <line num="15" count="8" type="stmt"/>
128
+ <line num="9" count="1" type="stmt"/>
129
+ <line num="15" count="16" type="stmt"/>
130
+ <line num="18" count="16" type="stmt"/>
79
131
  <line num="19" count="16" type="stmt"/>
80
- <line num="20" count="16" type="cond" truecount="2" falsecount="0"/>
81
- <line num="22" count="15" type="stmt"/>
82
- <line num="23" count="15" type="stmt"/>
83
- <line num="24" count="15" type="stmt"/>
84
- <line num="26" count="15" type="stmt"/>
85
- <line num="27" count="15" type="stmt"/>
86
- <line num="29" count="15" type="stmt"/>
87
- <line num="32" count="1" type="stmt"/>
132
+ <line num="20" count="16" type="stmt"/>
133
+ <line num="24" count="16" type="stmt"/>
134
+ <line num="25" count="16" type="stmt"/>
135
+ <line num="29" count="16" type="stmt"/>
136
+ <line num="30" count="16" type="cond" truecount="2" falsecount="0"/>
137
+ <line num="31" count="15" type="stmt"/>
138
+ <line num="32" count="15" type="stmt"/>
139
+ <line num="33" count="15" type="cond" truecount="2" falsecount="0"/>
140
+ <line num="34" count="1" type="stmt"/>
141
+ <line num="35" count="1" type="stmt"/>
88
142
  <line num="36" count="1" type="stmt"/>
89
- <line num="39" count="1" type="stmt"/>
90
- <line num="40" count="1" type="stmt"/>
91
- <line num="50" count="14" type="stmt"/>
92
- <line num="51" count="14" type="stmt"/>
93
- <line num="52" count="14" type="stmt"/>
94
- <line num="55" count="14" type="stmt"/>
95
- <line num="56" count="14" type="stmt"/>
96
- <line num="63" count="1" type="stmt"/>
143
+ <line num="38" count="14" type="stmt"/>
144
+ <line num="39" count="14" type="stmt"/>
145
+ <line num="40" count="14" type="stmt"/>
146
+ <line num="41" count="14" type="stmt"/>
147
+ <line num="52" count="1" type="stmt"/>
148
+ <line num="53" count="1" type="stmt"/>
149
+ <line num="56" count="1" type="stmt"/>
150
+ <line num="57" count="1" type="stmt"/>
151
+ <line num="64" count="8" type="stmt"/>
152
+ <line num="65" count="8" type="stmt"/>
153
+ <line num="66" count="8" type="stmt"/>
154
+ <line num="69" count="8" type="stmt"/>
155
+ <line num="70" count="8" type="stmt"/>
156
+ <line num="77" count="1" type="stmt"/>
97
157
  </file>
98
158
  </package>
99
159
  <package name="src.types">
100
- <metrics statements="8" coveredstatements="8" conditionals="4" coveredconditionals="4" methods="2" coveredmethods="2"/>
160
+ <metrics statements="9" coveredstatements="9" conditionals="4" coveredconditionals="4" methods="2" coveredmethods="2"/>
101
161
  <file name="index.ts" path="/home/runner/work/store/store/src/types/index.ts">
102
- <metrics statements="8" coveredstatements="8" conditionals="4" coveredconditionals="4" methods="2" coveredmethods="2"/>
162
+ <metrics statements="9" coveredstatements="9" conditionals="4" coveredconditionals="4" methods="2" coveredmethods="2"/>
103
163
  <line num="1" count="1" type="cond" truecount="2" falsecount="0"/>
104
164
  <line num="2" count="1" type="stmt"/>
105
165
  <line num="3" count="1" type="stmt"/>
106
166
  <line num="4" count="1" type="stmt"/>
107
167
  <line num="5" count="1" type="stmt"/>
108
- <line num="15" count="1" type="cond" truecount="2" falsecount="0"/>
109
- <line num="16" count="1" type="stmt"/>
110
- <line num="17" count="1" type="stmt"/>
168
+ <line num="25" count="1" type="cond" truecount="2" falsecount="0"/>
169
+ <line num="26" count="1" type="stmt"/>
170
+ <line num="27" count="1" type="stmt"/>
171
+ <line num="28" count="1" type="stmt"/>
111
172
  </file>
112
173
  </package>
113
174
  <package name="src.utils">
114
- <metrics statements="25" coveredstatements="25" conditionals="18" coveredconditionals="18" methods="7" coveredmethods="7"/>
175
+ <metrics statements="23" coveredstatements="23" conditionals="16" coveredconditionals="16" methods="7" coveredmethods="7"/>
115
176
  <file name="metaInfoHelper.ts" path="/home/runner/work/store/store/src/utils/metaInfoHelper.ts">
116
- <metrics statements="25" coveredstatements="25" conditionals="18" coveredconditionals="18" methods="7" coveredmethods="7"/>
177
+ <metrics statements="23" coveredstatements="23" conditionals="16" coveredconditionals="16" methods="7" coveredmethods="7"/>
117
178
  <line num="1" count="1" type="stmt"/>
118
179
  <line num="4" count="3" type="stmt"/>
119
180
  <line num="5" count="3" type="stmt"/>
120
181
  <line num="6" count="3" type="stmt"/>
121
- <line num="7" count="10" type="stmt"/>
122
- <line num="8" count="10" type="cond" truecount="2" falsecount="0"/>
123
- <line num="9" count="7" type="cond" truecount="2" falsecount="0"/>
124
- <line num="10" count="1" type="stmt"/>
125
- <line num="11" count="1" type="stmt"/>
126
- <line num="13" count="8" type="stmt"/>
127
- <line num="14" count="7" type="cond" truecount="2" falsecount="0"/>
128
- <line num="15" count="1" type="stmt"/>
129
- <line num="18" count="3" type="stmt"/>
130
- <line num="20" count="10" type="stmt"/>
131
- <line num="21" count="10" type="stmt"/>
132
- <line num="27" count="1" type="cond" truecount="8" falsecount="0"/>
133
- <line num="30" count="8" type="cond" truecount="2" falsecount="0"/>
134
- <line num="31" count="1" type="stmt"/>
135
- <line num="33" count="8" type="cond" truecount="2" falsecount="0"/>
136
- <line num="34" count="5" type="stmt"/>
137
- <line num="35" count="5" type="stmt"/>
138
- <line num="37" count="8" type="stmt"/>
139
- <line num="41" count="3" type="stmt"/>
140
- <line num="42" count="3" type="stmt"/>
141
- <line num="46" count="1" type="stmt"/>
182
+ <line num="7" count="14" type="cond" truecount="2" falsecount="0"/>
183
+ <line num="8" count="2" type="stmt"/>
184
+ <line num="9" count="5" type="stmt"/>
185
+ <line num="10" count="2" type="stmt"/>
186
+ <line num="11" count="12" type="cond" truecount="2" falsecount="0"/>
187
+ <line num="12" count="9" type="stmt"/>
188
+ <line num="14" count="3" type="stmt"/>
189
+ <line num="16" count="14" type="stmt"/>
190
+ <line num="17" count="14" type="stmt"/>
191
+ <line num="23" count="1" type="cond" truecount="8" falsecount="0"/>
192
+ <line num="26" count="14" type="cond" truecount="2" falsecount="0"/>
193
+ <line num="27" count="1" type="stmt"/>
194
+ <line num="29" count="14" type="cond" truecount="2" falsecount="0"/>
195
+ <line num="30" count="8" type="stmt"/>
196
+ <line num="31" count="8" type="stmt"/>
197
+ <line num="33" count="14" type="stmt"/>
198
+ <line num="37" count="3" type="stmt"/>
199
+ <line num="38" count="3" type="stmt"/>
200
+ <line num="42" count="1" type="stmt"/>
142
201
  </file>
143
202
  </package>
144
203
  </project>