@picgo/store 1.0.3 → 2.0.2
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 +41 -0
- package/README.md +33 -1
- package/coverage/clover.xml +164 -113
- package/coverage/coverage-final.json +6 -5
- package/coverage/lcov-report/index.html +20 -20
- package/coverage/lcov-report/src/DBStore.ts.html +183 -66
- package/coverage/lcov-report/src/JSONStore.ts.html +60 -30
- package/coverage/lcov-report/src/adapters/JSONAdapter.ts.html +157 -0
- package/coverage/lcov-report/src/adapters/ZlibAdapter.ts.html +94 -52
- package/coverage/lcov-report/src/adapters/index.html +24 -9
- package/coverage/lcov-report/src/index.html +14 -14
- package/coverage/lcov-report/src/types/index.html +5 -5
- package/coverage/lcov-report/src/types/index.ts.html +43 -4
- package/coverage/lcov-report/src/utils/index.html +7 -7
- package/coverage/lcov-report/src/utils/metaInfoHelper.ts.html +22 -34
- package/coverage/lcov.info +317 -218
- package/dist/DBStore.d.ts +14 -6
- package/dist/JSONStore.d.ts +3 -2
- package/dist/adapters/JSONAdapter.d.ts +8 -0
- package/dist/adapters/ZlibAdapter.d.ts +3 -1
- package/dist/index.js +2 -2
- package/dist/types/index.d.ts +12 -2
- package/package.json +12 -6
- package/rollup.config.js +7 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=
|
|
1
|
+
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@commonify/lowdb"),i=t(require("fs")),r=require("util"),a=require("fflate"),s=t(require("write-file-atomic")),n=t(require("comment-json")),o=t(require("lodash"));
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -13,5 +13,5 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
15
|
***************************************************************************** */
|
|
16
|
-
function
|
|
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.dbPath=t,this.adapter=new e.TextFileSync(t)}read(){const t=this.adapter.read();return null===t?{}:n.parse(t||"{}")}write(t){s.sync(this.dbPath,Buffer.from(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
17
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -19,11 +19,21 @@ export interface IObject {
|
|
|
19
19
|
}
|
|
20
20
|
export declare type IInsertData = IObject[] | [string, IObject] | [IObject[]];
|
|
21
21
|
export declare enum IMetaInfoMode {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
createMany = 0,
|
|
23
|
+
create = 1,
|
|
24
|
+
update = 2
|
|
24
25
|
}
|
|
25
26
|
export declare type IResult<T> = T & {
|
|
26
27
|
id: string;
|
|
27
28
|
createdAt: number;
|
|
28
29
|
updatedAt: number;
|
|
29
30
|
};
|
|
31
|
+
export interface ILowData {
|
|
32
|
+
[propName: string]: IObject[] | ILowDataKeyMap;
|
|
33
|
+
}
|
|
34
|
+
export interface ILowDataKeyMap {
|
|
35
|
+
[id: string]: 1;
|
|
36
|
+
}
|
|
37
|
+
export interface IJSON {
|
|
38
|
+
[propsName: string]: string | number | IJSON;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picgo/store",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"dev": "
|
|
9
|
-
"build": "
|
|
8
|
+
"dev": "rimraf ./dist/* && tsc -w -p .",
|
|
9
|
+
"build": "rimraf ./dist/* && rollup -c",
|
|
10
10
|
"lint": "eslint src/**",
|
|
11
11
|
"test": "jest --coverage --runInBand",
|
|
12
12
|
"cz": "git-cz",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@commitlint/cli": "^8.3.5",
|
|
47
47
|
"@picgo/bump-version": "^1.0.3",
|
|
48
48
|
"@types/jest": "^24.9.0",
|
|
49
|
-
"@types/lowdb": "^1.0.9",
|
|
50
49
|
"@types/node": "^13.1.7",
|
|
50
|
+
"@types/write-file-atomic": "^4.0.0",
|
|
51
51
|
"@typescript-eslint/eslint-plugin": "2",
|
|
52
52
|
"commitizen": "^4.2.4",
|
|
53
53
|
"conventional-changelog": "^3.1.18",
|
|
@@ -61,18 +61,24 @@
|
|
|
61
61
|
"eslint-plugin-standard": "4",
|
|
62
62
|
"husky": "^4.0.10",
|
|
63
63
|
"jest": "^24.9.0",
|
|
64
|
+
"rimraf": "^3.0.2",
|
|
64
65
|
"rollup": "^1.29.0",
|
|
66
|
+
"rollup-plugin-node-resolve": "^5.2.0",
|
|
65
67
|
"rollup-plugin-terser": "^5.2.0",
|
|
66
68
|
"rollup-plugin-typescript2": "^0.25.3",
|
|
67
69
|
"ts-jest": "^24.3.0",
|
|
68
70
|
"typescript": "^3.7.4"
|
|
69
71
|
},
|
|
70
72
|
"dependencies": {
|
|
73
|
+
"@commonify/lowdb": "^3.0.0",
|
|
74
|
+
"@commonify/steno": "^2.1.0",
|
|
71
75
|
"@types/bson": "^4.0.1",
|
|
72
76
|
"@types/graceful-fs": "^4.1.3",
|
|
73
|
-
"
|
|
77
|
+
"@types/lodash": "^4.14.182",
|
|
74
78
|
"comment-json": "^4.1.0",
|
|
79
|
+
"fflate": "^0.7.3",
|
|
80
|
+
"lodash": "^4.17.21",
|
|
75
81
|
"lodash-id": "^0.14.0",
|
|
76
|
-
"
|
|
82
|
+
"write-file-atomic": "^4.0.1"
|
|
77
83
|
}
|
|
78
84
|
}
|
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 resolve from 'rollup-plugin-node-resolve'
|
|
3
4
|
export default {
|
|
4
5
|
input: './src/index.ts',
|
|
5
6
|
plugins: [
|
|
@@ -23,8 +24,11 @@ export default {
|
|
|
23
24
|
sourcemap: true
|
|
24
25
|
}],
|
|
25
26
|
external: [
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
27
|
+
'write-file-atomic',
|
|
28
|
+
// '@commonify/steno',
|
|
29
|
+
'@commonify/lowdb',
|
|
30
|
+
'fflate',
|
|
31
|
+
'util',
|
|
32
|
+
'fs'
|
|
29
33
|
]
|
|
30
34
|
}
|