@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.44 kB
JavaScript
import{copy as e}from"../../../i18n/copy.mjs";import t from"../../../repositories/collection-migrations.mjs";import n from"../infer-schema.mjs";import r from"./build-runtime-schema.mjs";import i from"./diff-snapshot-vs-config.mjs";import{hasRuntimeSchema as a,setRuntimeSchema as o}from"./runtime-schema-cache.mjs";const s=async(s,c)=>{let l=new t(s.db.client,s.config.db),u=c.collectionKeys??s.config.collections.map(e=>e.key),d=(await Promise.all(u.map(async e=>await a(s,e)?null:e))).filter(e=>e!==null);if(d.length===0)return{data:void 0,error:void 0};let f=await l.selectLatestByCollectionKeysMap({collectionKeys:d,validation:{enabled:!0}});if(f.error)return f;let p=new Map(f.data.map(e=>[e.collection_key,e]));for(let t of d){let a=s.config.collections.find(e=>e.key===t);if(!a)return{data:void 0,error:{message:e(`server:core.collections.not.found.message`)}};let c=n(a,s.config.db);if(c.error)return c;let l=p.get(t);if(!l)return{data:void 0,error:{type:`basic`,name:e(`server:core.error.schema.migration.required.name`),message:e(`server:core.error.schema.migration.required.message`),status:400}};let u=i(l.collection_schema,c.data),d=r(c.data,u);try{await o(s,t,d)}catch(t){return{data:void 0,error:{message:e(`server:core.errors.unknown`,{defaultMessage:t instanceof Error?t.message:`An unknown error occurred`})}}}}return{data:void 0,error:void 0}};export{s as default};
//# sourceMappingURL=prime-runtime-schemas.mjs.map