UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.77 kB
import e from"../../constants/constants.mjs";import t from"../../libs/logger/index.mjs";import n from"../../libs/repositories/locales.mjs";import r from"../../libs/kv/cache-keys.mjs";import i from"../../libs/formatters/index.mjs";const a=async a=>{let o=new n(a.db.client,a.config.db),s=a.config.localization.locales.map(e=>e.code),c=await o.selectMultiple({select:[`code`,`is_deleted`],validation:{enabled:!0}});if(c.error)return c;let l=c.data.map(e=>e.code),u=s.filter(e=>!l.includes(e));u.length>0&&t.debug({message:`Syncing new locales to the DB: ${u.join(`, `)}`,scope:e.logScopes.sync});let d=c.data.filter(e=>!s.includes(e.code)&&i.formatBoolean(e.is_deleted)===!1).map(e=>e.code);d.length>0&&t.debug({message:`Marking the following locales as deleted: ${d.join(`, `)}`,scope:e.logScopes.sync});let f=c.data.filter(e=>i.formatBoolean(e.is_deleted)&&s.includes(e.code)),p=f.map(e=>e.code);p.length>0&&t.debug({message:`Restoring previously deleted locales: ${p.join(`, `)}`,scope:e.logScopes.sync});let[m,h,g]=await Promise.all([u.length>0&&o.createMultiple({data:u.map(e=>({code:e}))}),d.length>0&&o.updateSingle({data:{is_deleted:!0,is_deleted_at:new Date().toISOString(),updated_at:new Date().toISOString()},where:[{key:`code`,operator:`in`,value:d}],returning:[`code`],validation:{enabled:!0}}),p.length>0&&o.updateSingle({data:{is_deleted:!1,is_deleted_at:null,updated_at:new Date().toISOString()},where:[{key:`code`,operator:`in`,value:f.map(e=>e.code)}],returning:[`code`],validation:{enabled:!0}})]);return typeof m!=`boolean`&&m.error?m:typeof h!=`boolean`&&h.error?h:typeof g!=`boolean`&&g.error?g:(await a.kv.delete(a,{key:r.http.static.clientLocales,hash:!0}),{error:void 0,data:void 0})};export{a as default}; //# sourceMappingURL=sync-locales.mjs.map