UNPKG

@lucidcms/core

Version:

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

2 lines 5.34 kB
import e from"./media.mjs";import t,{registeredFieldTypes as n}from"../collection/custom-fields/registered-fields.mjs";import r from"./document-bricks.mjs";import i from"./document-fields.mjs";import a from"./document-workflows.mjs";import o from"./index.mjs";const s=e=>{let t=e.workflows===void 0?void 0:new Map(e.workflows.map(e=>[e.document_id,e]));return e.documents.map(n=>{let i=null,o=null;e.hasFields&&(i=r.formatDocumentFields({bricksQuery:n,bricksSchema:e.bricksTableSchema,refData:e.refData||{data:{}},collection:e.collection,config:e.config,host:e.host})),e.hasBricks&&(o=r.formatMultiple({bricksQuery:n,bricksSchema:e.bricksTableSchema,refData:e.refData||{data:{}},collection:e.collection,config:e.config,host:e.host}));let s=h({data:e.refData,collection:e.collection,config:e.config,host:e.host,bricksTableSchema:e.bricksTableSchema,fieldTypes:e.refTypes});return l({document:n,collection:e.collection,config:e.config,fields:i,bricks:o||void 0,refs:s,workflow:t===void 0?void 0:a.formatSingle({collection:e.collection,workflow:t.get(n.id),host:e.host}),host:e.host})})},c=t=>t.id?{id:t.id,email:t.email??null,firstName:t.firstName??null,lastName:t.lastName??null,username:t.username??null,profilePicture:e.formatProfilePicture({poster:t.profilePicture?.[0],host:t.host})}:null,l=e=>{let t=e.document.workflow_assignees===void 0?void 0:a.formatSingle({collection:e.collection,workflow:{id:e.document.workflow_id,collection_key:e.document.collection_key,document_id:e.document.id,stage_key:e.document.workflow_stage_key,created_by:e.document.workflow_created_by,created_at:e.document.workflow_created_at,updated_by:e.document.workflow_updated_by,updated_at:e.document.workflow_updated_at,assignees:e.document.workflow_assignees},host:e.host});return{id:e.document.id,collectionKey:e.document.collection_key,version:e.document.version_type??null,versionId:e.document.version_id??null,versions:u({document:e.document,collection:e.collection}),bricks:e.bricks??null,fields:e.fields??null,refs:e.refs??null,workflow:e.workflow===void 0?t??a.formatSummary({collection:e.collection,stageKey:e.document.workflow_stage_key}):e.workflow,isDeleted:o.formatBoolean(e.document.is_deleted),createdBy:c({id:e.document.cb_user_id,email:e.document.cb_user_email,firstName:e.document.cb_user_first_name,lastName:e.document.cb_user_last_name,username:e.document.cb_user_username,profilePicture:e.document.cb_user_profile_picture,host:e.host}),updatedBy:c({id:e.document.ub_user_id,email:e.document.ub_user_email,firstName:e.document.ub_user_first_name,lastName:e.document.ub_user_last_name,username:e.document.ub_user_username,profilePicture:e.document.ub_user_profile_picture,host:e.host}),createdAt:o.formatDate(e.document.created_at),updatedAt:o.formatDate(e.document.updated_at)}},u=e=>{let t={latest:null};if(e.collection.getData.environments)for(let n of e.collection.getData.environments)t[n.key]=null;if(e.document.versions)for(let n of e.document.versions)t[n.type]={id:n.id,promotedFrom:n.promoted_from,contentId:n.content_id,createdAt:o.formatDate(n.created_at),updatedAt:o.formatDate(n.updated_at),createdBy:n.created_by};return t},d=e=>e.documents.map(t=>{let n=null,i=null;e.hasFields&&(n=r.formatDocumentFields({bricksQuery:t,bricksSchema:e.bricksTableSchema,refData:e.refData||{data:{}},collection:e.collection,config:e.config,host:e.host})),e.hasBricks&&(i=r.formatMultiple({bricksQuery:t,bricksSchema:e.bricksTableSchema,refData:e.refData||{data:{}},collection:e.collection,config:e.config,host:e.host}));let a=e.include.refs?h({data:e.refData,collection:e.collection,config:e.config,host:e.host,bricksTableSchema:e.bricksTableSchema,fieldTypes:e.refTypes,flattenRelationRefFields:!0}):null;return m({document:t,collection:e.collection,config:e.config,fields:n,bricks:i||void 0,refs:a,host:e.host,include:e.include})}),f=e=>({versionId:e.document.version_id??null,versions:u({document:e.document,collection:e.collection}),createdAt:o.formatDate(e.document.created_at),updatedAt:o.formatDate(e.document.updated_at),createdBy:e.document.created_by??null,updatedBy:e.document.updated_by??null}),p=(e,t)=>(e??[]).map(e=>{let n=t.brickInstances.find(t=>t.key===e.key);return{id:e.id,ref:e.ref,key:e.key,type:e.type,order:e.order,fields:i.flattenFields(e.fields,n?.clientFieldTree)}}),m=e=>{let t={id:e.document.id,collectionKey:e.document.collection_key,version:e.document.version_type??null,fields:i.flattenFields(e.fields??[],e.collection.clientFieldTree)};return e.include.bricks&&(t.bricks=p(e.bricks,e.collection)),e.include.refs&&(t.refs=e.refs??{}),e.include.meta&&(t.meta=f({document:e.document,collection:e.collection})),t},h=e=>{let r={};if(!e.data)return null;let i={locales:e.config.localization.locales.map(e=>e.code),default:e.config.localization.defaultLocale};for(let a of e.fieldTypes??n){let n=t[a].formatRef,o=e.data.data[a];if(!n||!o||!Array.isArray(o))continue;let s=[];for(let t of o){if(t==null)continue;let r=n(t,{collection:e.collection,config:e.config,host:e.host,bricksTableSchema:e.bricksTableSchema,relationRefMeta:e.data?.meta?.relation,flattenRelationRefFields:e.flattenRelationRefFields,localization:i});r!==null&&s.push(r)}r[a]=s}return r};var g={formatMultiple:s,formatSingle:l,formatClientMultiple:d,formatClientSingle:m,formatRefs:h};export{g as default}; //# sourceMappingURL=documents.mjs.map