@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.38 kB
JavaScript
import e from"../../libs/repositories/documents.mjs";import{getDocumentTableSchema as t}from"../../libs/collection/schema/runtime/runtime-schema-selectors.mjs";import n from"./helpers/get-retention-days.mjs";import r from"./helpers/group-queue-payloads-by-tenant.mjs";const i=async i=>{let a=new e(i.db.client,i.config.db),o=i.config.collections.map(e=>e.key),s=await Promise.all(o.map(e=>t(i,e)));for(let e of s)if(e.error)return e;let c=s.map(e=>e.data).filter(e=>e!==void 0),l=n(i.config.retention,`deletedDocuments`),u=await Promise.all(c.map(async e=>{let t=await a.selectMultiple({select:[`id`,`collection_key`,`deleted_by`,`created_by`,`tenant_key`],where:[{key:`is_deleted`,operator:`=`,value:i.config.db.getDefault(`boolean`,`true`)},{key:`is_deleted_at`,operator:`<`,value:l}],validation:{enabled:!0}},{tableName:e.name});if(t.error)return t;if(t.data.length===0)return;let n=r(t.data.map(e=>({payload:{id:e.id,collectionKey:e.collection_key,userId:e.deleted_by??e.created_by,tenantKey:e.tenant_key},tenantKeys:[e.tenant_key]})));for(let e of n){let t=await i.queue.addBatch(i,{event:`documents:delete`,payloads:e.payloads,options:e.tenantKeys.length>0?{tenantKeys:e.tenantKeys}:void 0});if(t.error)return t}}));for(let e of u)if(e?.error)return e;return{error:void 0,data:void 0}};export{i as default};
//# sourceMappingURL=delete-expired-deleted-documents.mjs.map