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.99 kB
import{copy as e}from"../../../libs/i18n/copy.mjs";import t from"../../../libs/repositories/document-versions.mjs";import{getTableNames as n}from"../../../libs/collection/schema/runtime/runtime-schema-selectors.mjs";import r from"../../../libs/collection/get-collection-migration-status.mjs";import i from"../../documents/checks/check-collection.mjs";import a from"../../documents/checks/check-document-access.mjs";import o from"../../../libs/collection/migration/get-current-collection-migration-id.mjs";const s=async(s,c)=>{let l=new t(s.db.client,s.config.db),u=await i(s,{key:c.collectionKey});if(u.error)return u;let d=await n(s,c.collectionKey);if(d.error)return d;let f=await a(s,{collectionKey:c.collectionKey,id:c.documentId});if(f.error)return f;if(u.data.getData.locked)return{error:{type:`basic`,name:e(`server:core.error.locked.collection.name`),message:e(`server:core.error.locked.collection.message`),status:400},data:void 0};let p=await r(s,{collection:u.data});if(p.error)return p;if(p.data.requiresMigration)return{error:{type:`basic`,name:e(`server:core.error.schema.migration.required.name`),message:e(`server:core.error.schema.migration.required.message`),status:400},data:void 0};let m=await o(s,c.collectionKey);if(m.error)return m;let h=await l.selectSingle({select:[`id`,`type`],where:[{key:`id`,operator:`=`,value:c.versionId},{key:`collection_key`,operator:`=`,value:c.collectionKey},{key:`document_id`,operator:`=`,value:c.documentId}],validation:{enabled:!0,defaultError:{message:e(`server:core.documents.versions.not.found.message`),status:404}}},{tableName:d.data.version});return h.error?h:h.data.type===`latest`?{error:void 0,data:{collection:u.data,tableNames:d.data,migrationId:m.data,versionType:h.data.type}}:{error:{type:`basic`,name:e(`server:core.error.update.non.latest.version.name`),message:e(`server:core.error.update.non.latest.version.message`),status:400},data:void 0}};export{s as default}; //# sourceMappingURL=get-update-context.mjs.map