@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.51 kB
JavaScript
import e from"../../constants/constants.mjs";import t from"../../libs/logger/index.mjs";import n from"../../libs/repositories/collections.mjs";import r from"../../libs/formatters/index.mjs";const i=async i=>{let a=new n(i.db.client,i.config.db),o=i.config.collections.map(e=>e.key),s=await a.selectMultiple({select:[`key`,`is_deleted`],validation:{enabled:!0}});if(s.error)return s;let c=s.data.map(e=>e.key),l=o.filter(e=>!c.includes(e));l.length>0&&t.debug({message:`Syncing new collections to the DB: ${l.join(`, `)}`,scope:e.logScopes.sync});let u=s.data.filter(e=>!o.includes(e.key)&&r.formatBoolean(e.is_deleted)===!1).map(e=>e.key);u.length>0&&t.debug({message:`Marking the following collections as deleted: ${u.join(`, `)}`,scope:e.logScopes.sync});let d=s.data.filter(e=>r.formatBoolean(e.is_deleted)&&o.includes(e.key)).map(e=>e.key);d.length>0&&t.debug({message:`Restoring previously deleted collections: ${d.join(`, `)}`,scope:e.logScopes.sync});let[f,p,m]=await Promise.all([l.length>0&&a.createMultiple({data:l.map(e=>({key:e})).filter(e=>e!==null)}),u.length>0&&a.updateSingle({data:{is_deleted:!0,is_deleted_at:new Date().toISOString()},where:[{key:`key`,operator:`in`,value:u}]}),d.length>0&&a.updateSingle({data:{is_deleted:!1,is_deleted_at:null},where:[{key:`key`,operator:`in`,value:d}]})]);return typeof f!=`boolean`&&f.error?f:typeof p!=`boolean`&&p.error?p:typeof m!=`boolean`&&m.error?m:{error:void 0,data:void 0}};export{i as default};
//# sourceMappingURL=sync-collections.mjs.map