@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 2.97 kB
JavaScript
import e from"../db/query-builder/index.mjs";import t from"./parents/static-repository.mjs";import n from"zod";import{sql as r}from"kysely";var i=class extends t{constructor(e,t){super(e,t,`lucid_processed_images`)}tableSchema=n.object({key:n.string(),media_key:n.string(),file_size:n.number()});columnFormats={key:this.dbAdapter.getDataType(`text`),media_key:this.dbAdapter.getDataType(`text`),file_size:this.dbAdapter.getDataType(`integer`)};queryConfig=void 0;async sumFileSize(){let e=this.db.selectFrom(`lucid_processed_images`).select(r`COALESCE(SUM(file_size), 0)`.as(`total`)),t=await this.executeQuery(()=>e.executeTakeFirst(),{method:`sumFileSize`});return t.response.error?t.response:{error:void 0,data:Number(t.response.data?.total??0)}}async sumFileSizeByMediaTenant(e){let t=this.db.selectFrom(`lucid_processed_images`).leftJoin(`lucid_media`,`lucid_media.key`,`lucid_processed_images.media_key`).select(r`COALESCE(SUM(lucid_processed_images.file_size), 0)`.as(`total`));t=e.tenantKey===null?t.where(`lucid_media.tenant_key`,`is`,null):t.where(`lucid_media.tenant_key`,`=`,e.tenantKey);let n=await this.executeQuery(()=>t.executeTakeFirst(),{method:`sumFileSizeByMediaTenant`});return n.response.error?n.response:{error:void 0,data:Number(n.response.data?.total??0)}}async sumFileSizeGroupedByMediaTenant(){let e=this.db.selectFrom(`lucid_processed_images`).leftJoin(`lucid_media`,`lucid_media.key`,`lucid_processed_images.media_key`).select([`lucid_media.tenant_key as tenant_key`,r`COALESCE(SUM(lucid_processed_images.file_size), 0)`.as(`total`)]).groupBy(`lucid_media.tenant_key`),t=await this.executeQuery(()=>e.execute(),{method:`sumFileSizeGroupedByMediaTenant`});return t.response.error?t.response:{error:void 0,data:t.response.data.map(e=>({tenant_key:e.tenant_key,total:Number(e.total??0)}))}}async selectMultipleByMediaTenant(t){let n=this.db.selectFrom(`lucid_processed_images`).innerJoin(`lucid_media`,`lucid_media.key`,`lucid_processed_images.media_key`).select([`lucid_processed_images.key`,`lucid_processed_images.file_size`]).$call(n=>e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_media.tenant_key`})),r=await this.executeQuery(()=>n.execute(),{method:`selectMultipleByMediaTenant`});return r.response.error?r.response:this.validateResponse(r,{enabled:!0,mode:`multiple`,select:[`key`,`file_size`]})}async selectMultipleWithMediaTenant(t){let n=this.db.selectFrom(`lucid_processed_images`).leftJoin(`lucid_media`,`lucid_media.key`,`lucid_processed_images.media_key`).select([`lucid_processed_images.key`,`lucid_processed_images.media_key`,`lucid_processed_images.file_size`,`lucid_media.tenant_key as tenant_key`]).$call(n=>t?.tenantKey?e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_media.tenant_key`}):n),r=await this.executeQuery(()=>n.execute(),{method:`selectMultipleWithMediaTenant`});return r.response.error?r.response:{error:void 0,data:r.response.data}}};export{i as default};
//# sourceMappingURL=processed-images.mjs.map