@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
4 lines • 1.19 kB
JavaScript
import{copy as e}from"../../libs/i18n/copy.mjs";import t from"../../libs/logger/index.mjs";import n from"./utils/merge-errors.mjs";import r from"./utils/transaction-error.mjs";const i=(i,a)=>async(o,...s)=>{try{if(a.schema){let e=await a.schema.safeParseAsync(s[a.schemaArgIndex??0]);if(e.success===!1)return{error:n({type:`validation`,zod:e.error},a.defaultError),data:void 0}}if(!a.transaction||!o.config.db.supports(`transaction`)||o.db.client.isTransaction){let e=await i(o,...s);return e.error?{error:n(e.error,a.defaultError),data:void 0}:e}return await o.db.client.transaction().execute(async e=>{let t=await i({...o,db:{client:e}},...s);if(t.error)
//! Kysely needs function to throw for transaction to rollback !\\
throw new r(t.error);return t})}catch(i){return a.logError&&t.error({error:i,event:`service.execution.failed`,message:`Service execution failed`,data:{errorMessage:i instanceof Error?i.message:`An unknown error occurred`}}),i instanceof r?{error:n(i.error,a.defaultError),data:void 0}:(i instanceof Error,{error:n({message:e(`server:core.errors.default.message`),cause:i},a.defaultError),data:void 0})}};export{i as default};
//# sourceMappingURL=service-wrapper.mjs.map