@picgo/store
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -0,1 +1,15 @@ | ||
## :tada: 2.0.1 (2022-06-12) | ||
### :sparkles: Features | ||
* not compress json data ([ef8adb6](https://github.com/Molunerfinn/typescript-node-template/commit/ef8adb6)) | ||
### :bug: Bug Fixes | ||
* github action build error ([b4fe0ac](https://github.com/Molunerfinn/typescript-node-template/commit/b4fe0ac)) | ||
# :tada: 2.0.0 (2022-06-11) | ||
@@ -2,0 +16,0 @@ |
@@ -16,3 +16,3 @@ "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")); | ||
***************************************************************************** */ | ||
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))}}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}}; | ||
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}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@picgo/store", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
186988