UNPKG

@lucidcms/core

Version:

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

2 lines 2.87 kB
import{getFieldDatabaseConfig as e,isStorageMode as t,isTreeTableType as n}from"../collection/custom-fields/storage/index.mjs";import r from"./document-fields.mjs";import i from"./index.mjs";import a from"node:crypto";const o=e=>{let t=e.bricksSchema.filter(e=>e.type===`brick`);if(t.length===0)return[];let n=[];for(let a of t){let t=e.bricksQuery[a.name];if(!t||t.length===0)continue;let o=Map.groupBy(t,e=>e.brick_instance_id);for(let[t,s]of o.entries()){if(t===void 0||!s||s.length===0)continue;let o=s[0];if(!o||!o.brick_type)continue;let c=a.key.brick;if(!c)continue;let l=e.collection.brickInstances.find(e=>e.key===c);l&&n.push({ref:u(e.collection.key,c,o.id),key:c,order:o.position,open:i.formatBoolean(o.is_open),type:o.brick_type,id:o.id,fields:r.formatMultiple({brickRows:s,bricksQuery:e.bricksQuery,bricksSchema:e.bricksSchema,refData:e.refData},{host:e.host,builder:l,collection:e.collection,localization:{locales:e.config.localization.locales.map(e=>e.code),default:e.config.localization.defaultLocale},brickKey:c,config:e.config,bricksTableSchema:e.bricksSchema})})}}return n.sort((e,t)=>e.order-t.order)},s=e=>{let t=e.bricksSchema.find(e=>e.type===`document-fields`);if(!t)return[];let n=e.bricksQuery[t.name];if(!n)return[];let i=Map.groupBy(n,e=>e.position).get(0);return i?r.formatMultiple({brickRows:i,bricksQuery:e.bricksQuery,bricksSchema:e.bricksSchema,refData:e.refData},{host:e.host,builder:e.collection,collection:e.collection,localization:{locales:e.config.localization.locales.map(e=>e.code),default:e.config.localization.defaultLocale},brickKey:void 0,config:e.config,bricksTableSchema:e.bricksSchema}):[]},c=e=>{let t=e.bricksSchema.find(t=>{if(t.key.collection!==e.collectionKey||e.brickKey!==void 0&&t.key.brick!==e.brickKey||!n(t.type)||e.brickKey===void 0&&t.key.brick!==void 0)return!1;let r=t.key.fieldPath;return!(!r||r.length===0||r.length!==e.treeLevel+1||r[r.length-1]!==e.treeFieldKey)});if(t&&t.name in e.bricksQuery){let n=e.bricksQuery[t.name];return n?e.treeLevel===0?n.filter(t=>t.brick_id&&e.relationIds.includes(t.brick_id)):n.filter(t=>t.parent_id&&e.relationIds.includes(t.parent_id)):[]}return[]},l=n=>{let r=e(n.tableType);if(!r||!t(r,`relation-table`))return[];let i=n.bricksSchema.find(e=>{if(e.key.collection!==n.collectionKey||e.type!==n.tableType||n.brickKey!==void 0&&e.key.brick!==n.brickKey||n.brickKey===void 0&&e.key.brick!==void 0)return!1;let t=e.key.fieldPath;return t?.length===1&&t[0]===n.fieldKey});if(!i||!(i.name in n.bricksQuery))return[];let a=n.bricksQuery[i.name];return a?a.filter(e=>typeof e.parent_id==`number`&&n.relationIds.includes(e.parent_id)):[]},u=(e,t,n)=>a.createHash(`sha256`).update(`${e}-${t}-${n}`).digest(`hex`).substring(0,36);var d={formatMultiple:o,formatDocumentFields:s,getBrickTreeRows:c,getRelationRows:l};export{d as default}; //# sourceMappingURL=document-bricks.mjs.map