@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 2.19 kB
JavaScript
import e from"../i18n/prepare-translations.mjs";import t from"../../utils/services/create-service-context.mjs";import n from"../config/resolve-config-definition.mjs";import r from"../toolkit/create-toolkit.mjs";import i from"../http/app.mjs";const a=async a=>{let o=`config`in a?{config:a.config,env:a.env}:await n({definition:a.definition,envSchema:a.envSchema,env:a.env,meta:a.meta,processConfigOptions:{skipValidation:!0}}),s=`translationStore`in a?a.translationStore:(await e({config:o.config,bundles:a.translationBundles})).translationStore,c=await i({config:o.config,translationStore:s,env:o.env,runtimeContext:a.runtimeContext,http:a.http}),l,u=!1,d,f=new Set,p=e=>o.config.db.connect(e??{}),m=()=>(l||=Promise.resolve(p(o.env)).catch(e=>{throw l=void 0,e}),l);return{config:o.config,env:o.env,runtimeContext:a.runtimeContext,translationStore:s,issues:c.issues,createInvocation:e=>{if(u)throw Error(`Cannot use a Lucid host after it has been destroyed.`);let n=e?.env??o.env,i,l=!1,d,h=()=>{if(u)throw Error(`Cannot use a Lucid host after it has been destroyed.`);if(l)throw Error(`Cannot use a Lucid invocation after it has been destroyed.`);return a.databaseScope===`runtime`?m():(i||=Promise.resolve(p(n)).catch(e=>{throw i=void 0,e}),i)},g=async e=>{let r=await h();return t({config:o.config,database:r,translationStore:s,env:n,runtimeContext:a.runtimeContext,queue:c.queue,kv:c.kv,media:c.media,email:c.email,request:e})},_={getServiceContext:g,getToolkit:async e=>r(await g(e)),handle:async e=>{let t=await h();return c.handle({request:e.request,database:t,env:n,executionContext:e.executionContext,requestBindings:e.requestBindings})},destroy:async()=>(d??=(async()=>{l=!0;try{if(a.databaseScope===`invocation`&&i){let e=(await Promise.allSettled([i]))[0];e?.status===`fulfilled`&&await Promise.allSettled([e.value.destroy()])}}finally{f.delete(_)}})(),d)};return f.add(_),_},destroy:async()=>(d??=(async()=>{u=!0,await Promise.allSettled(Array.from(f,e=>e.destroy()));let[e]=await Promise.allSettled([l]),t=e.status===`fulfilled`?e.value:void 0;await Promise.allSettled([c.destroy(),t?.destroy()])})(),d)}};export{a as default};
//# sourceMappingURL=create-lucid-host.mjs.map