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.58 kB
import{isStorageMode as e}from"../../../libs/collection/custom-fields/storage/index.mjs";import t,{registeredFieldTypes as n}from"../../../libs/collection/custom-fields/registered-fields.mjs";const r=(e,t,n)=>{let r=n[e]??{};for(let e in t){let n=t[e];if(!n)continue;let i=r[e]??new Set;for(let e of n)i.add(e);r[e]=i}n[e]=r},i=(e,t)=>{let n=t.fields.get(e.key);if(!n)return null;let r={},i=e=>{let t=n.getRelationFieldValidationInput(e);for(let e in t){let n=t[e];if(!n)continue;let i=r[e]??[];i.push(...n),r[e]=i}};if(e.value!==void 0&&e.value!==null&&i(e.value),e.translations)for(let t in e.translations){let n=e.translations[t];n!=null&&i(n)}return r},a=async(e,t)=>{let n=o(t.bricks,t.fields,t.collection);return{data:await l(e,n),error:void 0}},o=(e,t,n)=>{let r={};for(let t of e){let e=s(t,n);!e||!t.fields||c(t.fields,e,r)}return c(t,n,r),r},s=(e,t)=>{switch(e.type){case`builder`:return t.config.bricks?.builder?.find(t=>t.key===e.key);case`fixed`:return t.config.bricks?.fixed?.find(t=>t.key===e.key);default:return}},c=(n,a,o)=>{for(let s of n){let n=a.fields.get(s.key);if(!n)continue;let l=t[n.type],u=l.config.database;if(l.validateInput!==null){let e=i(s,a);e&&r(s.type,e,o)}if(e(u,`tree-table`)&&s.groups)for(let e of s.groups)c(e.fields,a,o)}},l=async(e,r)=>{let i={},a=[];for(let o of n){let n=t[o];if(n.validateInput===null)continue;let s=Object.entries(r[o]??{}).reduce((e,[t,n])=>(e[t]=Array.from(n),e),{});a.push(n.validateInput(e,s).then(e=>{i[o]=e}))}return await Promise.all(a),i};export{a as default}; //# sourceMappingURL=fetch-validation-data.mjs.map