UNPKG

3.22 kBJavaScriptView Raw
1module.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var n=r[t]={i:t,l:false,exports:{}};e[t].call(n.exports,n,n.exports,__webpack_require__);n.l=true;return n.exports}return __webpack_require__(240)}({240:function(e,t,r){const{createStore:n}=r(601);e.exports=n},563:function(e){e.exports=((e,t={})=>{const{idLabel:r="uid"}=t;return{get(){return{sucess:true,data:this.collection}},post(t){try{t=this[e](t)}catch(e){return{sucess:false,error:e}}this.collection=[...this.collection,t];return{sucess:true,data:t}},put(e,t){e=String(e);if(!this.collection.find(t=>t[r]===e)){return{sucess:false,error:"couldnt match the uid"}}this.collection=this.collection.map(n=>{if(n[r]===e){n={...n,...t}}return n});return{sucess:true,data:this.collection.find(t=>t[r]===e)}},delete(e){e=String(e);if(!this.collection.find(t=>t[r]===e)){return{sucess:false,error:"couldnt match the uid"}}this.collection=this.collection.filter(t=>t[r]!==e);return{sucess:true}}}})},589:function(e){e.exports=require("path")},601:function(e,t,r){const n=r(772),o=r(563),s=r(865);e.exports={createStore:n,appendCrud:o,persistentData:s}},66:function(e){e.exports=require("fs")},772:function(e,t,r){const n=r(563);const o=r(865);e.exports=(e=>{if(!e&&typeof e!=="object"||Object.keys(e).length===0)throw new Error("No object found in 'createStore' parameter.");const t=(e=[],t,r)=>e.map((e,n)=>s(t,e,n,r));const r=(e,t)=>{if(e.length===0)throw new Error("Require at least one object inside the data key, with useSchema option at false.");const r={[t]:function(e){Object.entries(e).forEach(([e,t])=>{this[e]=t})}};return r[t]};const s=(e,t,r,n,o=[])=>{const{idLabel:s="uid"}=n;const c=e=>{e=String(e);let t=`${"0".repeat(6-e.length)}${e}`;if(e.length===6){return e}else{if(o.length>0){const e=o.map(e=>e[s]).sort((e,t)=>e-t);for(const r in e){const n=`${"0".repeat(6-String(r).length)}${r}`;if(e[r]!==n){t=n;break}}}return c(t)}};return{...new e({...t}),[s]:c(r)}};return Object.entries(e).reduce((e,c)=>{const i=c[0];const u=c[1];const l=u.options||{};const a=u.resolvers;if(l.useSchema&&!u.schema){throw new Error("A schema must be spcecified with useSchema option at true.")}const f=i.toLowerCase().replace(/^./,e=>e.toUpperCase());const h=l.useSchema?u.schema:r(u.data,f);const p=t(l.isDataDeletable?[]:u.data,h,l);return o({...e,[i]:{collection:p,[f]:function(e){return s(h,e,this.collection.length,l,this.collection)},...n(f,l),...a}},l.isPersistent)},{})})},865:function(e,t,r){const n=r(66),o=r(589);const s=o.join(__dirname,"../db/collection.json");const c=()=>{return n.readFileSync(s)};const i=e=>{if(!n.existsSync(o.join(__dirname,"../db"))){n.mkdirSync(o.join(__dirname,"../db"))}n.writeFileSync(s,JSON.stringify(e));return c()};const u=e=>{n.writeFileSync(s,JSON.stringify({...JSON.parse(c()),...e}))};const l=e=>{return{set:(t,r,n)=>{if(r==="collection"){u({[e]:n});t[r]=n}else return Reflect.set(...arguments)}}};const a=()=>n.existsSync(s);e.exports=((e,t)=>{return!t?e:Object.entries(e).reduce((e,t)=>{const r=t[0];const n=t[1].collection;const o=a()?c():i({[r]:n});if(!JSON.parse(o)[r]){u({[r]:n})}t[1].collection=JSON.parse(c())[r];return{...e,[r]:new Proxy(t[1],l(r))}},{})})}});
\No newline at end of file