@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 6.33 kB
JavaScript
import e from"../db/query-builder/index.mjs";import t from"./parents/static-repository.mjs";import{emailDeliveryStatusSchema as n,emailPrioritySchema as r}from"../../schemas/email.mjs";import i from"zod";var a=class extends t{constructor(e,t){super(e,t,`lucid_emails`)}tableSchema=i.object({id:i.number(),from_address:i.string(),from_name:i.string(),to_address:i.string(),subject:i.string(),cc:i.string().nullable(),bcc:i.string().nullable(),template:i.string(),priority:r,headers:i.record(i.string(),i.string()).nullable(),data:i.record(i.string(),i.unknown()).nullable(),storage_strategy:i.record(i.string(),i.unknown()).nullable(),type:i.string(),is_system:i.union([i.literal(this.dbAdapter.config.defaults.boolean.true),i.literal(this.dbAdapter.config.defaults.boolean.false)]),current_status:n,attempt_count:i.number(),last_attempted_at:i.union([i.string(),i.date()]).nullable(),created_at:i.union([i.string(),i.date()]).nullable(),updated_at:i.union([i.string(),i.date()]).nullable(),attachments:i.array(i.object({type:i.literal(`url`),url:i.string(),filename:i.string(),content_type:i.string().nullable(),disposition:i.union([i.literal(`attachment`),i.literal(`inline`)]),content_id:i.string().nullable(),order:i.number()})).optional(),transactions:i.array(i.object({delivery_status:n,message:i.string().nullable(),strategy_identifier:i.string(),strategy_data:i.record(i.string(),i.unknown()).nullable(),simulate:i.union([i.literal(this.dbAdapter.config.defaults.boolean.true),i.literal(this.dbAdapter.config.defaults.boolean.false)]),external_message_id:i.string().nullable(),created_at:i.union([i.string(),i.date()]).nullable(),updated_at:i.union([i.string(),i.date()]).nullable()})).optional(),tenants:i.array(i.object({tenant_key:i.string()})).optional()});columnFormats={id:this.dbAdapter.getDataType(`primary`),from_address:this.dbAdapter.getDataType(`text`),from_name:this.dbAdapter.getDataType(`text`),to_address:this.dbAdapter.getDataType(`text`),subject:this.dbAdapter.getDataType(`text`),cc:this.dbAdapter.getDataType(`text`),bcc:this.dbAdapter.getDataType(`text`),template:this.dbAdapter.getDataType(`text`),priority:this.dbAdapter.getDataType(`text`),headers:this.dbAdapter.getDataType(`json`),data:this.dbAdapter.getDataType(`json`),storage_strategy:this.dbAdapter.getDataType(`json`),type:this.dbAdapter.getDataType(`text`),is_system:this.dbAdapter.getDataType(`boolean`),current_status:this.dbAdapter.getDataType(`text`),attempt_count:this.dbAdapter.getDataType(`integer`),last_attempted_at:this.dbAdapter.getDataType(`timestamp`),created_at:this.dbAdapter.getDataType(`timestamp`),updated_at:this.dbAdapter.getDataType(`timestamp`)};queryConfig={tableKeys:{filters:{fromAddress:`from_address`,toAddress:`to_address`,subject:`subject`,type:`type`,template:`template`,priority:`priority`,currentStatus:`current_status`,attemptCount:`attempt_count`,lastAttemptedAt:`last_attempted_at`,createdAt:`created_at`,updatedAt:`updated_at`},sorts:{attemptCount:`attempt_count`,lastAttemptedAt:`last_attempted_at`,createdAt:`created_at`,updatedAt:`updated_at`}},operators:{subject:`contains`,template:`contains`}};async selectSingleById(e){let t=this.db.selectFrom(`lucid_emails`).select(e=>[`id`,`from_address`,`from_name`,`to_address`,`subject`,`cc`,`bcc`,`template`,`priority`,`headers`,`data`,`storage_strategy`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_email_attachments`).select([`lucid_email_attachments.type`,`lucid_email_attachments.url`,`lucid_email_attachments.filename`,`lucid_email_attachments.content_type`,`lucid_email_attachments.disposition`,`lucid_email_attachments.content_id`,`lucid_email_attachments.order`]).whereRef(`lucid_email_attachments.email_id`,`=`,`lucid_emails.id`).orderBy(`lucid_email_attachments.order`,`asc`)).as(`attachments`),`type`,`current_status`,`attempt_count`,`last_attempted_at`,`created_at`,`updated_at`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_email_transactions`).select([`lucid_email_transactions.delivery_status`,`lucid_email_transactions.message`,`lucid_email_transactions.strategy_identifier`,`lucid_email_transactions.strategy_data`,`lucid_email_transactions.simulate`,`lucid_email_transactions.external_message_id`,`lucid_email_transactions.created_at`,`lucid_email_transactions.updated_at`]).whereRef(`lucid_email_transactions.email_id`,`=`,`lucid_emails.id`).orderBy(`lucid_email_transactions.created_at`,`desc`)).as(`transactions`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_email_tenants`).select([`lucid_email_tenants.tenant_key`]).whereRef(`lucid_email_tenants.email_id`,`=`,`lucid_emails.id`)).as(`tenants`)]).where(`id`,`=`,e.id);t=this.applyTenantScope(t,e.tenantKey);let n=await this.executeQuery(()=>t.executeTakeFirst(),{method:`selectSingleById`});return n.response.error?n.response:this.validateResponse(n,{...e.validation,mode:`single`,select:[`id`,`from_address`,`from_name`,`to_address`,`subject`,`cc`,`bcc`,`template`,`priority`,`headers`,`data`,`storage_strategy`,`attachments`,`type`,`current_status`,`attempt_count`,`last_attempted_at`,`created_at`,`updated_at`,`transactions`,`tenants`]})}async selectMultipleFilteredFixed(t){let n=await this.executeQuery(async()=>{let n=this.db.selectFrom(`lucid_emails`).select(t.select),r=this.db.selectFrom(`lucid_emails`).select(e=>e.fn.countAll().as(`count`));if(n=this.applyTenantScope(n,t.tenantKey),r=this.applyTenantScope(r,t.tenantKey),t.includeSystem!==!0){let e=this.dbAdapter.getDefault(`boolean`,`false`);n=n.where(`is_system`,`=`,e),r=r.where(`is_system`,`=`,e)}let{main:i,count:a}=e.main({main:n,count:r},{queryParams:t.queryParams,database:this.dbAdapter.config,meta:this.queryConfig}),[o,s]=await Promise.all([i.execute(),a?.executeTakeFirst()]);return[o,s]},{method:`selectMultipleFilteredFixed`});return n.response.error?n.response:this.validateResponse(n,{...t.validation,mode:`multiple-count`,select:t.select})}applyTenantScope(e,t){return t==null?e:e.where(e=>e.or([e.exists(e.selectFrom(`lucid_email_tenants`).select(`lucid_email_tenants.id`).whereRef(`lucid_email_tenants.email_id`,`=`,`lucid_emails.id`).where(`lucid_email_tenants.tenant_key`,`=`,t)),e.not(e.exists(e.selectFrom(`lucid_email_tenants`).select(`lucid_email_tenants.id`).whereRef(`lucid_email_tenants.email_id`,`=`,`lucid_emails.id`)))]))}};export{a as default};
//# sourceMappingURL=emails.mjs.map