@picgo/store 2.0.4 → 2.2.1
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/.eslintrc.json +6 -2
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.node-version +1 -0
- package/CHANGELOG.md +28 -0
- package/README.md +28 -1
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +161 -0
- package/coverage/lcov-report/block-navigation.js +9 -1
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +36 -30
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +40 -0
- package/coverage/lcov-report/src/DBStore.ts.html +140 -59
- package/coverage/lcov-report/src/JSONStore.ts.html +29 -23
- package/coverage/lcov-report/src/adapters/JSONAdapter.ts.html +33 -27
- package/coverage/lcov-report/src/adapters/ZlibAdapter.ts.html +52 -49
- package/coverage/lcov-report/src/adapters/index.html +32 -26
- package/coverage/lcov-report/src/index.html +24 -18
- package/coverage/lcov-report/src/types/index.html +14 -8
- package/coverage/lcov-report/src/types/index.ts.html +17 -8
- package/coverage/lcov-report/src/utils/index.html +18 -12
- package/coverage/lcov-report/src/utils/metaInfoHelper.ts.html +49 -28
- package/coverage/lcov.info +295 -273
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/coverage/src/DBStore.ts.html +592 -0
- package/coverage/src/JSONStore.ts.html +241 -0
- package/coverage/src/adapters/JSONAdapter.ts.html +205 -0
- package/coverage/src/adapters/ZlibAdapter.ts.html +316 -0
- package/coverage/src/adapters/index.html +131 -0
- package/coverage/src/index.html +131 -0
- package/coverage/src/types/index.html +116 -0
- package/coverage/src/types/index.ts.html +229 -0
- package/coverage/src/utils/index.html +116 -0
- package/coverage/src/utils/metaInfoHelper.ts.html +229 -0
- package/dist/DBStore.d.ts +29 -25
- package/dist/JSONStore.d.ts +12 -12
- package/dist/adapters/JSONAdapter.d.ts +8 -8
- package/dist/adapters/ZlibAdapter.d.ts +10 -10
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +40 -39
- package/dist/utils/metaInfoHelper.d.ts +3 -3
- package/package.json +28 -27
- package/rollup.config.js +1 -1
- package/vitest.config.ts +14 -0
- package/coverage/clover.xml +0 -213
- package/coverage/coverage-final.json +0 -7
- package/jest.config.js +0 -6
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Code coverage report for src/utils/metaInfoHelper.ts</title>
|
|
7
|
+
<meta charset="utf-8" />
|
|
8
|
+
<link rel="stylesheet" href="../../prettify.css" />
|
|
9
|
+
<link rel="stylesheet" href="../../base.css" />
|
|
10
|
+
<link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
+
<style type='text/css'>
|
|
13
|
+
.coverage-summary .sorter {
|
|
14
|
+
background-image: url(../../sort-arrow-sprite.png);
|
|
15
|
+
}
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<div class='wrapper'>
|
|
21
|
+
<div class='pad1'>
|
|
22
|
+
<h1><a href="../../index.html">All files</a> / <a href="index.html">src/utils</a> metaInfoHelper.ts</h1>
|
|
23
|
+
<div class='clearfix'>
|
|
24
|
+
|
|
25
|
+
<div class='fl pad1y space-right2'>
|
|
26
|
+
<span class="strong">100% </span>
|
|
27
|
+
<span class="quiet">Statements</span>
|
|
28
|
+
<span class='fraction'>28/28</span>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<div class='fl pad1y space-right2'>
|
|
33
|
+
<span class="strong">100% </span>
|
|
34
|
+
<span class="quiet">Branches</span>
|
|
35
|
+
<span class='fraction'>18/18</span>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<div class='fl pad1y space-right2'>
|
|
40
|
+
<span class="strong">100% </span>
|
|
41
|
+
<span class="quiet">Functions</span>
|
|
42
|
+
<span class='fraction'>8/8</span>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<div class='fl pad1y space-right2'>
|
|
47
|
+
<span class="strong">100% </span>
|
|
48
|
+
<span class="quiet">Lines</span>
|
|
49
|
+
<span class='fraction'>25/25</span>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
<p class="quiet">
|
|
55
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
56
|
+
</p>
|
|
57
|
+
<template id="filterTemplate">
|
|
58
|
+
<div class="quiet">
|
|
59
|
+
Filter:
|
|
60
|
+
<input type="search" id="fileSearch">
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
</div>
|
|
64
|
+
<div class='status-line high'></div>
|
|
65
|
+
<pre><table class="coverage">
|
|
66
|
+
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
67
|
+
<a name='L2'></a><a href='#L2'>2</a>
|
|
68
|
+
<a name='L3'></a><a href='#L3'>3</a>
|
|
69
|
+
<a name='L4'></a><a href='#L4'>4</a>
|
|
70
|
+
<a name='L5'></a><a href='#L5'>5</a>
|
|
71
|
+
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
|
+
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
|
+
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
+
<a name='L9'></a><a href='#L9'>9</a>
|
|
75
|
+
<a name='L10'></a><a href='#L10'>10</a>
|
|
76
|
+
<a name='L11'></a><a href='#L11'>11</a>
|
|
77
|
+
<a name='L12'></a><a href='#L12'>12</a>
|
|
78
|
+
<a name='L13'></a><a href='#L13'>13</a>
|
|
79
|
+
<a name='L14'></a><a href='#L14'>14</a>
|
|
80
|
+
<a name='L15'></a><a href='#L15'>15</a>
|
|
81
|
+
<a name='L16'></a><a href='#L16'>16</a>
|
|
82
|
+
<a name='L17'></a><a href='#L17'>17</a>
|
|
83
|
+
<a name='L18'></a><a href='#L18'>18</a>
|
|
84
|
+
<a name='L19'></a><a href='#L19'>19</a>
|
|
85
|
+
<a name='L20'></a><a href='#L20'>20</a>
|
|
86
|
+
<a name='L21'></a><a href='#L21'>21</a>
|
|
87
|
+
<a name='L22'></a><a href='#L22'>22</a>
|
|
88
|
+
<a name='L23'></a><a href='#L23'>23</a>
|
|
89
|
+
<a name='L24'></a><a href='#L24'>24</a>
|
|
90
|
+
<a name='L25'></a><a href='#L25'>25</a>
|
|
91
|
+
<a name='L26'></a><a href='#L26'>26</a>
|
|
92
|
+
<a name='L27'></a><a href='#L27'>27</a>
|
|
93
|
+
<a name='L28'></a><a href='#L28'>28</a>
|
|
94
|
+
<a name='L29'></a><a href='#L29'>29</a>
|
|
95
|
+
<a name='L30'></a><a href='#L30'>30</a>
|
|
96
|
+
<a name='L31'></a><a href='#L31'>31</a>
|
|
97
|
+
<a name='L32'></a><a href='#L32'>32</a>
|
|
98
|
+
<a name='L33'></a><a href='#L33'>33</a>
|
|
99
|
+
<a name='L34'></a><a href='#L34'>34</a>
|
|
100
|
+
<a name='L35'></a><a href='#L35'>35</a>
|
|
101
|
+
<a name='L36'></a><a href='#L36'>36</a>
|
|
102
|
+
<a name='L37'></a><a href='#L37'>37</a>
|
|
103
|
+
<a name='L38'></a><a href='#L38'>38</a>
|
|
104
|
+
<a name='L39'></a><a href='#L39'>39</a>
|
|
105
|
+
<a name='L40'></a><a href='#L40'>40</a>
|
|
106
|
+
<a name='L41'></a><a href='#L41'>41</a>
|
|
107
|
+
<a name='L42'></a><a href='#L42'>42</a>
|
|
108
|
+
<a name='L43'></a><a href='#L43'>43</a>
|
|
109
|
+
<a name='L44'></a><a href='#L44'>44</a>
|
|
110
|
+
<a name='L45'></a><a href='#L45'>45</a>
|
|
111
|
+
<a name='L46'></a><a href='#L46'>46</a>
|
|
112
|
+
<a name='L47'></a><a href='#L47'>47</a>
|
|
113
|
+
<a name='L48'></a><a href='#L48'>48</a>
|
|
114
|
+
<a name='L49'></a><a href='#L49'>49</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
|
115
|
+
<span class="cline-any cline-neutral"> </span>
|
|
116
|
+
<span class="cline-any cline-neutral"> </span>
|
|
117
|
+
<span class="cline-any cline-yes">4x</span>
|
|
118
|
+
<span class="cline-any cline-yes">4x</span>
|
|
119
|
+
<span class="cline-any cline-yes">4x</span>
|
|
120
|
+
<span class="cline-any cline-yes">19x</span>
|
|
121
|
+
<span class="cline-any cline-yes">3x</span>
|
|
122
|
+
<span class="cline-any cline-yes">8x</span>
|
|
123
|
+
<span class="cline-any cline-yes">3x</span>
|
|
124
|
+
<span class="cline-any cline-yes">16x</span>
|
|
125
|
+
<span class="cline-any cline-yes">12x</span>
|
|
126
|
+
<span class="cline-any cline-yes">4x</span>
|
|
127
|
+
<span class="cline-any cline-yes">1x</span>
|
|
128
|
+
<span class="cline-any cline-yes">4x</span>
|
|
129
|
+
<span class="cline-any cline-yes">1x</span>
|
|
130
|
+
<span class="cline-any cline-neutral"> </span>
|
|
131
|
+
<span class="cline-any cline-yes">3x</span>
|
|
132
|
+
<span class="cline-any cline-neutral"> </span>
|
|
133
|
+
<span class="cline-any cline-yes">19x</span>
|
|
134
|
+
<span class="cline-any cline-yes">19x</span>
|
|
135
|
+
<span class="cline-any cline-neutral"> </span>
|
|
136
|
+
<span class="cline-any cline-neutral"> </span>
|
|
137
|
+
<span class="cline-any cline-neutral"> </span>
|
|
138
|
+
<span class="cline-any cline-neutral"> </span>
|
|
139
|
+
<span class="cline-any cline-neutral"> </span>
|
|
140
|
+
<span class="cline-any cline-neutral"> </span>
|
|
141
|
+
<span class="cline-any cline-yes">1x</span>
|
|
142
|
+
<span class="cline-any cline-neutral"> </span>
|
|
143
|
+
<span class="cline-any cline-neutral"> </span>
|
|
144
|
+
<span class="cline-any cline-yes">20x</span>
|
|
145
|
+
<span class="cline-any cline-yes">1x</span>
|
|
146
|
+
<span class="cline-any cline-neutral"> </span>
|
|
147
|
+
<span class="cline-any cline-yes">20x</span>
|
|
148
|
+
<span class="cline-any cline-yes">11x</span>
|
|
149
|
+
<span class="cline-any cline-yes">11x</span>
|
|
150
|
+
<span class="cline-any cline-neutral"> </span>
|
|
151
|
+
<span class="cline-any cline-yes">20x</span>
|
|
152
|
+
<span class="cline-any cline-neutral"> </span>
|
|
153
|
+
<span class="cline-any cline-neutral"> </span>
|
|
154
|
+
<span class="cline-any cline-neutral"> </span>
|
|
155
|
+
<span class="cline-any cline-yes">7x</span>
|
|
156
|
+
<span class="cline-any cline-yes">7x</span>
|
|
157
|
+
<span class="cline-any cline-neutral"> </span>
|
|
158
|
+
<span class="cline-any cline-neutral"> </span>
|
|
159
|
+
<span class="cline-any cline-neutral"> </span>
|
|
160
|
+
<span class="cline-any cline-neutral"> </span>
|
|
161
|
+
<span class="cline-any cline-neutral"> </span>
|
|
162
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import { IInsertData, IMetaInfoMode, IObject } from '../types'
|
|
163
|
+
|
|
164
|
+
function metaInfoHelper (mode: IMetaInfoMode) {
|
|
165
|
+
return function (_target: any, _propertyKey: any, descriptor: PropertyDescriptor) {
|
|
166
|
+
const method = descriptor.value
|
|
167
|
+
descriptor.value = async function (...args: IInsertData) {
|
|
168
|
+
if (mode === IMetaInfoMode.createMany) {
|
|
169
|
+
args = args[0] as IObject[]
|
|
170
|
+
args = args.map(item => metaInfoGenerator(item))
|
|
171
|
+
args = [args]
|
|
172
|
+
} else if (mode === IMetaInfoMode.create) {
|
|
173
|
+
args[0] = metaInfoGenerator(args[0] as IObject)
|
|
174
|
+
} else if (mode === IMetaInfoMode.updateMany) {
|
|
175
|
+
args = args[0] as IObject[]
|
|
176
|
+
args = args.map(item => metaInfoUpdater(item))
|
|
177
|
+
args = [args]
|
|
178
|
+
} else {
|
|
179
|
+
metaInfoUpdater((args as [string, IObject])[1])
|
|
180
|
+
}
|
|
181
|
+
const result = await method.call(this, ...args)
|
|
182
|
+
return result
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// https://gist.github.com/LeverOne/1308368
|
|
188
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
189
|
+
function uuid (a: any = '', b: any = ''): string { for (b = a = ''; a++ < 36; b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-');return b }
|
|
190
|
+
|
|
191
|
+
function metaInfoGenerator (value: IObject): IObject {
|
|
192
|
+
if (!value.id) {
|
|
193
|
+
value.id = uuid()
|
|
194
|
+
}
|
|
195
|
+
if (!value.createdAt) {
|
|
196
|
+
value.createdAt = Date.now()
|
|
197
|
+
value.updatedAt = Date.now()
|
|
198
|
+
}
|
|
199
|
+
return value
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function metaInfoUpdater (value: IObject): IObject {
|
|
203
|
+
value.updatedAt = Date.now()
|
|
204
|
+
return value
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export {
|
|
208
|
+
metaInfoHelper
|
|
209
|
+
}
|
|
210
|
+
</pre></td></tr></table></pre>
|
|
211
|
+
|
|
212
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
213
|
+
</div><!-- /wrapper -->
|
|
214
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
215
|
+
Code coverage generated by
|
|
216
|
+
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
217
|
+
at 2026-01-05T10:05:12.274Z
|
|
218
|
+
</div>
|
|
219
|
+
<script src="../../prettify.js"></script>
|
|
220
|
+
<script>
|
|
221
|
+
window.onload = function () {
|
|
222
|
+
prettyPrint();
|
|
223
|
+
};
|
|
224
|
+
</script>
|
|
225
|
+
<script src="../../sorter.js"></script>
|
|
226
|
+
<script src="../../block-navigation.js"></script>
|
|
227
|
+
</body>
|
|
228
|
+
</html>
|
|
229
|
+
|
package/dist/DBStore.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { ZlibAdapter } from './adapters/ZlibAdapter';
|
|
2
|
-
import { IObject, IResult, IGetResult, IFilter, ILowData } from './types';
|
|
3
|
-
declare class DBStore {
|
|
4
|
-
private readonly db;
|
|
5
|
-
private readonly collectionName;
|
|
6
|
-
private readonly collectionKey;
|
|
7
|
-
private hasRead;
|
|
8
|
-
errorList: Array<Error | string>;
|
|
9
|
-
private readonly adapter;
|
|
10
|
-
constructor(dbPath: string, collectionName: string);
|
|
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>>;
|
|
19
|
-
insertMany<T>(value: T[]): Promise<Array<IResult<T>>>;
|
|
20
|
-
updateById(id: string, value: IObject): Promise<boolean>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
1
|
+
import { ZlibAdapter } from './adapters/ZlibAdapter';
|
|
2
|
+
import { IObject, IResult, IGetResult, IFilter, ILowData } from './types';
|
|
3
|
+
declare class DBStore {
|
|
4
|
+
private readonly db;
|
|
5
|
+
private readonly collectionName;
|
|
6
|
+
private readonly collectionKey;
|
|
7
|
+
private hasRead;
|
|
8
|
+
errorList: Array<Error | string>;
|
|
9
|
+
private readonly adapter;
|
|
10
|
+
constructor(dbPath: string, collectionName: string);
|
|
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>>;
|
|
19
|
+
insertMany<T>(value: T[]): Promise<Array<IResult<T>>>;
|
|
20
|
+
updateById(id: string, value: IObject): Promise<boolean>;
|
|
21
|
+
updateMany(list: IObject[]): Promise<{
|
|
22
|
+
total: number;
|
|
23
|
+
success: number;
|
|
24
|
+
}>;
|
|
25
|
+
getById<T>(id: string): Promise<IResult<T> | undefined>;
|
|
26
|
+
removeById(id: string): Promise<void>;
|
|
27
|
+
overwrite<T>(value: T[]): Promise<Array<IResult<T>>>;
|
|
28
|
+
}
|
|
29
|
+
export { DBStore };
|
package/dist/JSONStore.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { IJSON } from './types';
|
|
2
|
-
declare class JSONStore {
|
|
3
|
-
private readonly db;
|
|
4
|
-
private hasRead;
|
|
5
|
-
constructor(dbPath: string);
|
|
6
|
-
read(flush?: boolean): IJSON;
|
|
7
|
-
get(key?: string): any;
|
|
8
|
-
set(key: string, value: any): void;
|
|
9
|
-
has(key: string): boolean;
|
|
10
|
-
unset(key: string, value: any): boolean;
|
|
11
|
-
}
|
|
12
|
-
export { JSONStore };
|
|
1
|
+
import { IJSON } from './types';
|
|
2
|
+
declare class JSONStore {
|
|
3
|
+
private readonly db;
|
|
4
|
+
private hasRead;
|
|
5
|
+
constructor(dbPath: string);
|
|
6
|
+
read(flush?: boolean): IJSON;
|
|
7
|
+
get(key?: string): any;
|
|
8
|
+
set(key: string, value: any): void;
|
|
9
|
+
has(key: string): boolean;
|
|
10
|
+
unset(key: string, value: any): boolean;
|
|
11
|
+
}
|
|
12
|
+
export { JSONStore };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IJSON } from 'src/types';
|
|
2
|
-
export declare class JSONAdapter {
|
|
3
|
-
private readonly adapter;
|
|
4
|
-
private readonly dbPath;
|
|
5
|
-
constructor(dbPath: string);
|
|
6
|
-
read(): IJSON;
|
|
7
|
-
write(obj: any): void;
|
|
8
|
-
}
|
|
1
|
+
import { IJSON } from 'src/types';
|
|
2
|
+
export declare class JSONAdapter {
|
|
3
|
+
private readonly adapter;
|
|
4
|
+
private readonly dbPath;
|
|
5
|
+
constructor(dbPath: string);
|
|
6
|
+
read(): IJSON;
|
|
7
|
+
write(obj: any): void;
|
|
8
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
declare class ZlibAdapter {
|
|
2
|
-
private readonly dbPath;
|
|
3
|
-
private readonly collectionName;
|
|
4
|
-
errorList: Array<Error | string>;
|
|
5
|
-
readCount: number;
|
|
6
|
-
constructor(dbPath: string, collectionName: string, errorList: Array<Error | string>);
|
|
7
|
-
read(): Promise<any>;
|
|
8
|
-
write(data: any): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
export { ZlibAdapter };
|
|
1
|
+
declare class ZlibAdapter {
|
|
2
|
+
private readonly dbPath;
|
|
3
|
+
private readonly collectionName;
|
|
4
|
+
errorList: Array<Error | string>;
|
|
5
|
+
readCount: number;
|
|
6
|
+
constructor(dbPath: string, collectionName: string, errorList: Array<Error | string>);
|
|
7
|
+
read(): Promise<any>;
|
|
8
|
+
write(data: any): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export { ZlibAdapter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DBStore } from './DBStore';
|
|
2
|
-
import { JSONStore } from './JSONStore';
|
|
3
|
-
export { DBStore, JSONStore };
|
|
1
|
+
import { DBStore } from './DBStore';
|
|
2
|
+
import { JSONStore } from './JSONStore';
|
|
3
|
+
export { DBStore, JSONStore };
|
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"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@commonify/lowdb"),e=require("fs"),i=require("node:util"),r=require("fflate"),a=require("write-file-atomic"),n=require("comment-json"),s=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(n),u=o(s);function h(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}"function"==typeof SuppressedError&&SuppressedError;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);r.gunzip(i,(i,a)=>{if(i)return console.error(i),this.errorList.push(i),e(t);const n=r.strFromU8(a);try{const t=JSON.parse(n);return e(t)}catch(i){return console.error(i),this.errorList.push(i),e(t)}})}else{const a=Buffer.from(JSON.stringify(t));r.gzip(a,async(r,a)=>{if(r)return i(r);await d.default(this.dbPath,Buffer.from(a)),e(t)})}})}async write(t){return new Promise((e,i)=>{t=Buffer.from(JSON.stringify(t)),r.gzip(t,async(t,r)=>{if(t)return i(t);await d.default(this.dbPath,Buffer.from(r)),e()})})}}var p,w;function b(t){return function(e,i,r){const a=r.value;r.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=>v(t))]:v(e[1]);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 v(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 m{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){var i;const r=await this.getCollection();if(await this.getCollectionKey(t)){const a=null!==(i=r.find(e=>e.id===t))&&void 0!==i?i:{};return Object.assign(a,e),await this.db.write(),!0}return!1}async updateMany(t){var e;const i=await this.getCollection();let r=0;for(const a of t)if(a.id){if(await this.getCollectionKey(a.id)){r++;const t=null!==(e=i.find(t=>t.id===a.id))&&void 0!==e?e:{};Object.assign(t,a)}}return await this.db.write(),{success:r,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(),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)}}h([b(w.create)],m.prototype,"insert",null),h([b(w.createMany)],m.prototype,"insertMany",null),h([b(w.update)],m.prototype,"updateById",null),h([b(w.updateMany)],m.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=m,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=
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
export declare enum IDBStatus {
|
|
2
|
-
inited = "inited",
|
|
3
|
-
loaded = "loaded",
|
|
4
|
-
started = "started",
|
|
5
|
-
stopped = "stopped"
|
|
6
|
-
}
|
|
7
|
-
export interface IFilter {
|
|
8
|
-
orderBy?: 'asc' | 'desc';
|
|
9
|
-
limit?: number;
|
|
10
|
-
offset?: number;
|
|
11
|
-
}
|
|
12
|
-
export interface IGetResult<T> {
|
|
13
|
-
total: number;
|
|
14
|
-
data: Array<IResult<T>>;
|
|
15
|
-
}
|
|
16
|
-
export interface IObject {
|
|
17
|
-
id?: string;
|
|
18
|
-
[propName: string]: any;
|
|
19
|
-
}
|
|
20
|
-
export
|
|
21
|
-
export declare enum IMetaInfoMode {
|
|
22
|
-
createMany = 0,
|
|
23
|
-
create = 1,
|
|
24
|
-
update = 2
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
export declare enum IDBStatus {
|
|
2
|
+
inited = "inited",
|
|
3
|
+
loaded = "loaded",
|
|
4
|
+
started = "started",
|
|
5
|
+
stopped = "stopped"
|
|
6
|
+
}
|
|
7
|
+
export interface IFilter {
|
|
8
|
+
orderBy?: 'asc' | 'desc';
|
|
9
|
+
limit?: number;
|
|
10
|
+
offset?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface IGetResult<T> {
|
|
13
|
+
total: number;
|
|
14
|
+
data: Array<IResult<T>>;
|
|
15
|
+
}
|
|
16
|
+
export interface IObject {
|
|
17
|
+
id?: string;
|
|
18
|
+
[propName: string]: any;
|
|
19
|
+
}
|
|
20
|
+
export type IInsertData = IObject[] | [string, IObject] | [IObject[]];
|
|
21
|
+
export declare enum IMetaInfoMode {
|
|
22
|
+
createMany = 0,
|
|
23
|
+
create = 1,
|
|
24
|
+
update = 2,
|
|
25
|
+
updateMany = 3
|
|
26
|
+
}
|
|
27
|
+
export type IResult<T> = T & {
|
|
28
|
+
id: string;
|
|
29
|
+
createdAt: number;
|
|
30
|
+
updatedAt: number;
|
|
31
|
+
};
|
|
32
|
+
export interface ILowData {
|
|
33
|
+
[propName: string]: IObject[] | ILowDataKeyMap;
|
|
34
|
+
}
|
|
35
|
+
export interface ILowDataKeyMap {
|
|
36
|
+
[id: string]: 1;
|
|
37
|
+
}
|
|
38
|
+
export interface IJSON {
|
|
39
|
+
[propsName: string]: string | number | IJSON;
|
|
40
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IMetaInfoMode } from '../types';
|
|
2
|
-
declare function metaInfoHelper(mode: IMetaInfoMode): (_target: any, _propertyKey: any, descriptor: PropertyDescriptor) => void;
|
|
3
|
-
export { metaInfoHelper };
|
|
1
|
+
import { IMetaInfoMode } from '../types';
|
|
2
|
+
declare function metaInfoHelper(mode: IMetaInfoMode): (_target: any, _propertyKey: any, descriptor: PropertyDescriptor) => void;
|
|
3
|
+
export { metaInfoHelper };
|
package/package.json
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picgo/store",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"dev": "rimraf ./dist/* && tsc -w -p .",
|
|
9
|
-
"build": "rimraf ./dist/* && rollup -c",
|
|
10
|
-
"lint": "eslint src/**",
|
|
11
|
-
"test": "jest --coverage --runInBand",
|
|
12
|
-
"cz": "git-cz",
|
|
13
|
-
"release": "bump-version",
|
|
14
|
-
"cover": "cat ./coverage/lcov.info | coveralls"
|
|
15
|
-
},
|
|
16
7
|
"repository": {
|
|
17
8
|
"type": "git",
|
|
18
9
|
"url": "git+https://github.com/Molunerfinn/typescript-node-template.git"
|
|
@@ -43,17 +34,21 @@
|
|
|
43
34
|
},
|
|
44
35
|
"homepage": "https://github.com/Molunerfinn/typescript-node-template#readme",
|
|
45
36
|
"devDependencies": {
|
|
46
|
-
"@commitlint/cli": "^
|
|
47
|
-
"@picgo/bump-version": "^
|
|
37
|
+
"@commitlint/cli": "^20.3.0",
|
|
38
|
+
"@picgo/bump-version": "^2.0.0",
|
|
48
39
|
"@rollup/plugin-commonjs": "^22.0.2",
|
|
49
|
-
"@
|
|
50
|
-
"@types/
|
|
40
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
41
|
+
"@types/bson": "^4.0.1",
|
|
42
|
+
"@types/graceful-fs": "^4.1.3",
|
|
43
|
+
"@types/lodash": "^4.14.182",
|
|
44
|
+
"@types/node": "^22.19.3",
|
|
51
45
|
"@types/write-file-atomic": "^4.0.0",
|
|
52
46
|
"@typescript-eslint/eslint-plugin": "5.33.1",
|
|
53
|
-
"
|
|
47
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
48
|
+
"commitizen": "^4.3.1",
|
|
54
49
|
"conventional-changelog": "^3.1.18",
|
|
55
50
|
"coveralls": "^3.0.9",
|
|
56
|
-
"cz-customizable": "^
|
|
51
|
+
"cz-customizable": "^7.5.1",
|
|
57
52
|
"eslint": "8.22.0",
|
|
58
53
|
"eslint-config-standard-with-typescript": "^22.0.0",
|
|
59
54
|
"eslint-plugin-import": "2.26.0",
|
|
@@ -61,26 +56,32 @@
|
|
|
61
56
|
"eslint-plugin-node": "11.1.0",
|
|
62
57
|
"eslint-plugin-promise": "6.0.0",
|
|
63
58
|
"eslint-plugin-standard": "5.0.0",
|
|
64
|
-
"husky": "^
|
|
65
|
-
"jest": "^24.9.0",
|
|
59
|
+
"husky": "^9.1.7",
|
|
66
60
|
"rimraf": "^3.0.2",
|
|
67
61
|
"rollup": "^2.78.1",
|
|
68
62
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
69
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
70
63
|
"rollup-plugin-typescript2": "^0.33.0",
|
|
71
|
-
"
|
|
72
|
-
"typescript": "^
|
|
64
|
+
"tslib": "^2.8.1",
|
|
65
|
+
"typescript": "^5.9.3",
|
|
66
|
+
"vitest": "^4.0.16"
|
|
73
67
|
},
|
|
74
68
|
"dependencies": {
|
|
75
69
|
"@commonify/lowdb": "^3.0.0",
|
|
76
70
|
"@commonify/steno": "^2.1.0",
|
|
77
|
-
"@types/bson": "^4.0.1",
|
|
78
|
-
"@types/graceful-fs": "^4.1.3",
|
|
79
|
-
"@types/lodash": "^4.14.182",
|
|
80
71
|
"comment-json": "^4.2.3",
|
|
81
|
-
"fflate": "^0.
|
|
72
|
+
"fflate": "^0.8.2",
|
|
82
73
|
"lodash": "^4.17.21",
|
|
83
74
|
"lodash-id": "^0.14.0",
|
|
84
|
-
"write-file-atomic": "^
|
|
75
|
+
"write-file-atomic": "^7.0.0"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"dev": "rimraf ./dist/* && tsc -w -p .",
|
|
79
|
+
"build": "rimraf ./dist/* && rollup -c",
|
|
80
|
+
"lint": "eslint src/**",
|
|
81
|
+
"test": "vitest run --coverage",
|
|
82
|
+
"cz": "git-cz",
|
|
83
|
+
"release": "bump-version",
|
|
84
|
+
"cover": "cat ./coverage/lcov.info | coveralls",
|
|
85
|
+
"commitlint": "commitlint --edit"
|
|
85
86
|
}
|
|
86
|
-
}
|
|
87
|
+
}
|
package/rollup.config.js
CHANGED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
environment: 'node',
|
|
6
|
+
globals: true,
|
|
7
|
+
include: ['src/**/*.{test,spec}.ts'],
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: 'v8',
|
|
10
|
+
reportsDirectory: 'coverage',
|
|
11
|
+
reporter: ['text', 'html', 'lcov']
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
})
|