@picgo/store 2.2.1 → 2.2.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## :tada: 2.2.2 (2026-03-15)
2
+
3
+
4
+ ### :bug: Bug Fixes
5
+
6
+ * slice bug ([5564ed3](https://github.com/PicGo/store/commit/5564ed3))
7
+
8
+
9
+ ### :package: Chore
10
+
11
+ * update actions ([c14c92c](https://github.com/PicGo/store/commit/c14c92c))
12
+
13
+
14
+
1
15
  ## :tada: 2.2.1 (2026-01-05)
2
16
 
3
17
 
@@ -30,9 +30,9 @@
30
30
 
31
31
 
32
32
  <div class='fl pad1y space-right2'>
33
- <span class="strong">94.04% </span>
33
+ <span class="strong">92.04% </span>
34
34
  <span class="quiet">Branches</span>
35
- <span class='fraction'>79/84</span>
35
+ <span class='fraction'>81/88</span>
36
36
  </div>
37
37
 
38
38
 
@@ -85,8 +85,8 @@
85
85
  </td>
86
86
  <td data-value="100" class="pct high">100%</td>
87
87
  <td data-value="102" class="abs high">102/102</td>
88
- <td data-value="93.47" class="pct high">93.47%</td>
89
- <td data-value="46" class="abs high">43/46</td>
88
+ <td data-value="90" class="pct high">90%</td>
89
+ <td data-value="50" class="abs high">45/50</td>
90
90
  <td data-value="100" class="pct high">100%</td>
91
91
  <td data-value="26" class="abs high">26/26</td>
92
92
  <td data-value="100" class="pct high">100%</td>
@@ -146,7 +146,7 @@
146
146
  <div class='footer quiet pad2 space-top1 center small'>
147
147
  Code coverage generated by
148
148
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
149
- at 2026-01-05T10:05:12.274Z
149
+ at 2026-03-15T14:07:57.813Z
150
150
  </div>
151
151
  <script src="prettify.js"></script>
152
152
  <script>
@@ -30,9 +30,9 @@
30
30
 
31
31
 
32
32
  <div class='fl pad1y space-right2'>
33
- <span class="strong">94.04% </span>
33
+ <span class="strong">92.04% </span>
34
34
  <span class="quiet">Branches</span>
35
- <span class='fraction'>79/84</span>
35
+ <span class='fraction'>81/88</span>
36
36
  </div>
37
37
 
38
38
 
@@ -85,8 +85,8 @@
85
85
  </td>
86
86
  <td data-value="100" class="pct high">100%</td>
87
87
  <td data-value="102" class="abs high">102/102</td>
88
- <td data-value="93.47" class="pct high">93.47%</td>
89
- <td data-value="46" class="abs high">43/46</td>
88
+ <td data-value="90" class="pct high">90%</td>
89
+ <td data-value="50" class="abs high">45/50</td>
90
90
  <td data-value="100" class="pct high">100%</td>
91
91
  <td data-value="26" class="abs high">26/26</td>
92
92
  <td data-value="100" class="pct high">100%</td>
@@ -146,7 +146,7 @@
146
146
  <div class='footer quiet pad2 space-top1 center small'>
147
147
  Code coverage generated by
148
148
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
149
- at 2026-01-05T10:05:12.285Z
149
+ at 2026-03-15T14:07:57.823Z
150
150
  </div>
151
151
  <script src="prettify.js"></script>
152
152
  <script>
@@ -142,25 +142,29 @@ BRDA:50,9,0,1
142
142
  BRDA:50,9,1,5
143
143
  BRDA:50,10,0,6
144
144
  BRDA:50,10,1,2
145
- BRDA:82,11,0,12
146
- BRDA:85,12,0,1
147
- BRDA:85,12,1,11
148
- BRDA:91,13,0,3
149
- BRDA:91,13,1,8
150
- BRDA:110,14,0,2
151
- BRDA:110,14,1,1
152
- BRDA:112,15,0,2
153
- BRDA:112,15,1,0
154
- BRDA:126,16,0,3
155
- BRDA:126,16,1,1
156
- BRDA:128,17,0,2
157
- BRDA:128,17,1,1
158
- BRDA:131,18,0,2
159
- BRDA:131,18,1,0
160
- BRDA:151,19,0,1
161
- BRDA:151,19,1,1
162
- BRF:38
163
- BRH:36
145
+ BRDA:62,11,0,39
146
+ BRDA:62,11,1,0
147
+ BRDA:71,12,0,20
148
+ BRDA:71,12,1,0
149
+ BRDA:82,13,0,12
150
+ BRDA:85,14,0,1
151
+ BRDA:85,14,1,11
152
+ BRDA:91,15,0,3
153
+ BRDA:91,15,1,8
154
+ BRDA:110,16,0,2
155
+ BRDA:110,16,1,1
156
+ BRDA:112,17,0,2
157
+ BRDA:112,17,1,0
158
+ BRDA:126,18,0,3
159
+ BRDA:126,18,1,1
160
+ BRDA:128,19,0,2
161
+ BRDA:128,19,1,1
162
+ BRDA:131,20,0,2
163
+ BRDA:131,20,1,0
164
+ BRDA:151,21,0,1
165
+ BRDA:151,21,1,1
166
+ BRF:42
167
+ BRH:38
164
168
  end_of_record
165
169
  TN:
166
170
  SF:src/JSONStore.ts
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"),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}};
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,e;return null!==(e=null===(t=await this.read())||void 0===t?void 0:t[this.collectionName])&&void 0!==e?e:[]}async getCollectionKey(t){return(await this.getCollectionKeyMap())[t]}async getCollectionKeyMap(){var t,e;return null!==(e=null===(t=await this.read())||void 0===t?void 0:t[this.collectionKey])&&void 0!==e?e:{}}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/package.json CHANGED
@@ -1,17 +1,28 @@
1
1
  {
2
2
  "name": "@picgo/store",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
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": "vitest run --coverage",
12
+ "cz": "git-cz",
13
+ "release": "bump-version",
14
+ "cover": "cat ./coverage/lcov.info | coveralls",
15
+ "prepare": "husky",
16
+ "commitlint": "commitlint --edit"
17
+ },
7
18
  "repository": {
8
19
  "type": "git",
9
- "url": "git+https://github.com/Molunerfinn/typescript-node-template.git"
20
+ "url": "https://github.com/PicGo/store"
10
21
  },
11
22
  "author": "Molunerfinn",
12
23
  "license": "MIT",
13
24
  "bugs": {
14
- "url": "https://github.com/Molunerfinn/typescript-node-template/issues"
25
+ "url": "https://github.com/PicGo/store/issues"
15
26
  },
16
27
  "husky": {
17
28
  "hooks": {
@@ -73,15 +84,5 @@
73
84
  "lodash": "^4.17.21",
74
85
  "lodash-id": "^0.14.0",
75
86
  "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"
86
87
  }
87
- }
88
+ }