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.55 kB
import e from"../../../helpers/prefix-generated-column-name.mjs";import{relationFieldConfig as t}from"./config.mjs";import{normalizeRelationCollections as n}from"./utils/normalize-relation-collections.mjs";import{getBricksTableSchema as r}from"../../../schema/runtime/runtime-schema-selectors.mjs";const i=(e,t)=>e.type===`relation`&&n(e.collection).includes(t),a=e=>e.schemas.find(n=>{if(n.key.collection!==e.collectionKey||n.type!==t.database.tableType||n.key.brick!==e.brickKey)return!1;let r=n.key.fieldPath;return r?.length===1&&r[0]===e.fieldKey})?.name??null,o=e=>{for(let t of e.fields){if(i(t,e.targetCollectionKey)){let n=a({schemas:e.schemas,collectionKey:e.collectionKey,brickKey:e.brickKey,fieldKey:t.key});n&&e.targets.add(n)}t.type===`repeater`&&o({fields:t.fields,schemas:e.schemas,collectionKey:e.collectionKey,targetCollectionKey:e.targetCollectionKey,brickKey:e.brickKey,targets:e.targets})}},s=async(t,n)=>{let i=new Set;for(let e of t.config.collections){let a=await r(t,e.key);if(a.error)return a;o({fields:e.persistedFieldTree,schemas:a.data,collectionKey:e.key,targetCollectionKey:n.collectionKey,targets:i});for(let t of e.brickInstances)o({fields:t.persistedFieldTree,schemas:a.data,collectionKey:e.key,targetCollectionKey:n.collectionKey,brickKey:t.key,targets:i})}let a=e(`document_id`),s=e(`collection_key`);for(let e of i)await t.db.client.deleteFrom(e).where(a,`=`,n.documentId).where(s,`=`,n.collectionKey).execute();return{error:void 0,data:void 0}};export{s as default}; //# sourceMappingURL=nullify-references.mjs.map