@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 23.5 kB
JavaScript
import e from"../db/query-builder/index.mjs";import{activeMediaCropSelect as t}from"./helpers/media-selects.mjs";import n from"./parents/static-repository.mjs";import r from"zod";import{sql as i}from"kysely";var a=class extends n{constructor(e,t){super(e,t,`lucid_media`)}tableSchema=r.object({id:r.number(),key:r.string(),folder_id:r.number().nullable(),parent_media_id:r.number().nullable(),relation_type:r.enum([`crop`,`poster`]).nullable(),e_tag:r.string().nullable(),origin:r.enum([`human`,`ai_generated`,`ai_modified`]),ai_generation_id:r.number().nullable(),public:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]),type:r.string(),mime_type:r.string(),file_extension:r.string(),file_name:r.string().nullable(),file_size:r.number(),width:r.number().nullable(),height:r.number().nullable(),focal_x:r.number().nullable(),focal_y:r.number().nullable(),crop_x:r.number().nullable(),crop_y:r.number().nullable(),crop_width:r.number().nullable(),crop_height:r.number().nullable(),crop_rotation:r.number().nullable(),crop_skew_x:r.number().nullable(),crop_skew_y:r.number().nullable(),blur_hash:r.string().nullable(),average_color:r.string().nullable(),base64:r.string().nullable().optional(),is_dark:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),is_light:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),is_hidden:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]),translations:r.array(r.object({title:r.string().nullable(),alt:r.string().nullable(),description:r.string().nullable(),summary:r.string().nullable(),locale_code:r.string().nullable()})).optional(),poster:r.array(r.object({id:r.number(),key:r.string(),origin:r.enum([`human`,`ai_generated`,`ai_modified`]),type:r.string(),mime_type:r.string(),file_extension:r.string(),file_name:r.string().nullable(),file_size:r.number(),width:r.number().nullable(),height:r.number().nullable(),focal_x:r.number().nullable(),focal_y:r.number().nullable(),crop_x:r.number().nullable().optional(),crop_y:r.number().nullable().optional(),crop_width:r.number().nullable().optional(),crop_height:r.number().nullable().optional(),crop_rotation:r.number().nullable().optional(),crop_skew_x:r.number().nullable().optional(),crop_skew_y:r.number().nullable().optional(),blur_hash:r.string().nullable(),average_color:r.string().nullable(),base64:r.string().nullable().optional(),is_dark:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),is_light:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),crop:r.array(r.object({id:r.number(),key:r.string(),origin:r.enum([`human`,`ai_generated`,`ai_modified`]),type:r.string(),mime_type:r.string(),file_extension:r.string(),file_name:r.string().nullable(),file_size:r.number(),width:r.number().nullable(),height:r.number().nullable(),focal_x:r.number().nullable(),focal_y:r.number().nullable(),crop_x:r.number(),crop_y:r.number(),crop_width:r.number(),crop_height:r.number(),crop_rotation:r.number(),crop_skew_x:r.number(),crop_skew_y:r.number(),blur_hash:r.string().nullable(),average_color:r.string().nullable(),base64:r.string().nullable().optional(),is_dark:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),is_light:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable()})).optional(),translations:r.array(r.object({title:r.string().nullable().optional(),alt:r.string().nullable(),description:r.string().nullable().optional(),summary:r.string().nullable().optional(),locale_code:r.string().nullable()})).optional()})).optional(),crop:r.array(r.object({id:r.number(),key:r.string(),origin:r.enum([`human`,`ai_generated`,`ai_modified`]),type:r.string(),mime_type:r.string(),file_extension:r.string(),file_name:r.string().nullable(),file_size:r.number(),width:r.number().nullable(),height:r.number().nullable(),focal_x:r.number().nullable(),focal_y:r.number().nullable(),crop_x:r.number(),crop_y:r.number(),crop_width:r.number(),crop_height:r.number(),crop_rotation:r.number(),crop_skew_x:r.number(),crop_skew_y:r.number(),blur_hash:r.string().nullable(),average_color:r.string().nullable(),base64:r.string().nullable().optional(),is_dark:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),is_light:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable()})).optional(),custom_meta:r.string().nullable(),tenant_key:r.string().nullable(),is_deleted:r.union([r.literal(this.dbAdapter.config.defaults.boolean.true),r.literal(this.dbAdapter.config.defaults.boolean.false)]),is_deleted_at:r.union([r.string(),r.date()]).nullable(),deleted_by:r.number().nullable(),created_at:r.union([r.string(),r.date()]).nullable(),updated_at:r.union([r.string(),r.date()]).nullable(),updated_by:r.number().nullable(),created_by:r.number().nullable()});columnFormats={id:this.dbAdapter.getDataType(`primary`),key:this.dbAdapter.getDataType(`text`),folder_id:this.dbAdapter.getDataType(`integer`),parent_media_id:this.dbAdapter.getDataType(`integer`),relation_type:this.dbAdapter.getDataType(`text`),e_tag:this.dbAdapter.getDataType(`text`),origin:this.dbAdapter.getDataType(`text`),ai_generation_id:this.dbAdapter.getDataType(`integer`),public:this.dbAdapter.getDataType(`boolean`),type:this.dbAdapter.getDataType(`text`),mime_type:this.dbAdapter.getDataType(`text`),file_extension:this.dbAdapter.getDataType(`text`),file_name:this.dbAdapter.getDataType(`text`),file_size:this.dbAdapter.getDataType(`integer`),width:this.dbAdapter.getDataType(`integer`),height:this.dbAdapter.getDataType(`integer`),focal_x:this.dbAdapter.getDataType(`integer`),focal_y:this.dbAdapter.getDataType(`integer`),crop_x:this.dbAdapter.getDataType(`real`),crop_y:this.dbAdapter.getDataType(`real`),crop_width:this.dbAdapter.getDataType(`real`),crop_height:this.dbAdapter.getDataType(`real`),crop_rotation:this.dbAdapter.getDataType(`real`),crop_skew_x:this.dbAdapter.getDataType(`real`),crop_skew_y:this.dbAdapter.getDataType(`real`),blur_hash:this.dbAdapter.getDataType(`text`),average_color:this.dbAdapter.getDataType(`text`),base64:this.dbAdapter.getDataType(`text`),is_dark:this.dbAdapter.getDataType(`boolean`),is_light:this.dbAdapter.getDataType(`boolean`),custom_meta:this.dbAdapter.getDataType(`text`),tenant_key:this.dbAdapter.getDataType(`text`),is_hidden:this.dbAdapter.getDataType(`boolean`),is_deleted:this.dbAdapter.getDataType(`boolean`),is_deleted_at:this.dbAdapter.getDataType(`timestamp`),deleted_by:this.dbAdapter.getDataType(`integer`),created_at:this.dbAdapter.getDataType(`timestamp`),updated_at:this.dbAdapter.getDataType(`timestamp`),updated_by:this.dbAdapter.getDataType(`integer`),created_by:this.dbAdapter.getDataType(`integer`)};queryConfig={tableKeys:{filters:{key:`key`,mimeType:`mime_type`,type:`type`,extension:`file_extension`,folderId:`folder_id`,isDeleted:`is_deleted`,deletedBy:`deleted_by`,public:`public`,isHidden:`is_hidden`,origin:`origin`,fileSize:`file_size`,width:`width`,height:`height`,createdAt:`created_at`,updatedAt:`updated_at`},sorts:{createdAt:`created_at`,updatedAt:`updated_at`,fileSize:`file_size`,width:`width`,height:`height`,mimeType:`mime_type`,extension:`file_extension`,deletedBy:`deleted_by`,isDeletedAt:`is_deleted_at`}}};async sumFileSize(){let e=this.db.selectFrom(`lucid_media`).select(i`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 sumFileSizeByTenant(e){let t=this.db.selectFrom(`lucid_media`).select(i`COALESCE(SUM(file_size), 0)`.as(`total`));t=e.tenantKey===null?t.where(`tenant_key`,`is`,null):t.where(`tenant_key`,`=`,e.tenantKey);let n=await this.executeQuery(()=>t.executeTakeFirst(),{method:`sumFileSizeByTenant`});return n.response.error?n.response:{error:void 0,data:Number(n.response.data?.total??0)}}async sumFileSizeGroupedByTenant(){let e=this.db.selectFrom(`lucid_media`).select([`tenant_key`,i`COALESCE(SUM(file_size), 0)`.as(`total`)]).groupBy(`tenant_key`),t=await this.executeQuery(()=>e.execute(),{method:`sumFileSizeGroupedByTenant`});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 selectSingleActivePresentationByKey(e){let t=this.db.selectFrom(`lucid_media as requested`).innerJoin(`lucid_media as source`,e=>e.on(e=>e.or([e.and([e(`requested.relation_type`,`=`,`crop`),e(`source.id`,`=`,e.ref(`requested.parent_media_id`))]),e.and([e.or([e(`requested.relation_type`,`is`,null),e(`requested.relation_type`,`=`,`poster`)]),e(`source.id`,`=`,e.ref(`requested.id`))])]))).leftJoin(`lucid_media as active_crop`,e=>e.onRef(`active_crop.parent_media_id`,`=`,`source.id`).on(`active_crop.relation_type`,`=`,`crop`).on(`active_crop.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).select([`source.type as source_type`,`source.key as source_key`,`source.file_name as source_file_name`,`source.file_extension as source_file_extension`,`source.tenant_key as source_tenant_key`,`active_crop.id as active_crop_id`,`active_crop.type as active_crop_type`,`active_crop.key as active_crop_key`,`active_crop.file_name as active_crop_file_name`,`active_crop.file_extension as active_crop_file_extension`]).where(`requested.key`,`=`,e.key).limit(1),n=await this.executeQuery(async()=>{let e=await t.executeTakeFirst();if(e)return{type:e.active_crop_type??e.source_type,key:e.active_crop_key??e.source_key,file_name:e.active_crop_id===null?e.source_file_name:e.active_crop_file_name,file_extension:e.active_crop_file_extension??e.source_file_extension,tenant_key:e.source_tenant_key}},{method:`selectSingleActivePresentationByKey`});return n.response.error,n.response}async selectSingleById(t){let n=this.db.selectFrom(`lucid_media`).select(e=>[`id`,`key`,`folder_id`,`parent_media_id`,`relation_type`,`e_tag`,`origin`,`type`,`mime_type`,`file_extension`,`file_name`,`file_size`,`width`,`height`,`focal_x`,`focal_y`,`crop_x`,`crop_y`,`crop_width`,`crop_height`,`crop_rotation`,`crop_skew_x`,`crop_skew_y`,`created_at`,`updated_at`,`blur_hash`,`average_color`,`base64`,`is_dark`,`is_light`,`is_deleted`,`is_deleted_at`,`deleted_by`,`public`,`tenant_key`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as poster`).select([`poster.id`,`poster.key`,`poster.origin`,`poster.type`,`poster.mime_type`,`poster.file_extension`,`poster.file_name`,`poster.file_size`,`poster.width`,`poster.height`,`poster.focal_x`,`poster.focal_y`,`poster.crop_x`,`poster.crop_y`,`poster.crop_width`,`poster.crop_height`,`poster.crop_rotation`,`poster.crop_skew_x`,`poster.crop_skew_y`,`poster.blur_hash`,`poster.average_color`,`poster.base64`,`poster.is_dark`,`poster.is_light`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media_translations`).select([`lucid_media_translations.title`,`lucid_media_translations.alt`,`lucid_media_translations.description`,`lucid_media_translations.summary`,`lucid_media_translations.locale_code`]).whereRef(`lucid_media_translations.media_id`,`=`,i.ref(`poster.id`))).as(`translations`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as poster_crop`).select([`poster_crop.id`,`poster_crop.key`,`poster_crop.origin`,`poster_crop.type`,`poster_crop.mime_type`,`poster_crop.file_extension`,`poster_crop.file_name`,`poster_crop.file_size`,`poster_crop.width`,`poster_crop.height`,`poster_crop.focal_x`,`poster_crop.focal_y`,`poster_crop.crop_x`,`poster_crop.crop_y`,`poster_crop.crop_width`,`poster_crop.crop_height`,`poster_crop.crop_rotation`,`poster_crop.crop_skew_x`,`poster_crop.crop_skew_y`,`poster_crop.blur_hash`,`poster_crop.average_color`,`poster_crop.base64`,`poster_crop.is_dark`,`poster_crop.is_light`]).where(`poster_crop.parent_media_id`,`=`,i.ref(`poster.id`)).where(`poster_crop.relation_type`,`=`,`crop`).where(`poster_crop.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`crop`)]).whereRef(`poster.parent_media_id`,`=`,`lucid_media.id`).where(`poster.relation_type`,`=`,`poster`).where(`poster.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`poster`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as crop`).select([`crop.id`,`crop.key`,`crop.origin`,`crop.type`,`crop.mime_type`,`crop.file_extension`,`crop.file_name`,`crop.file_size`,`crop.width`,`crop.height`,`crop.focal_x`,`crop.focal_y`,`crop.crop_x`,`crop.crop_y`,`crop.crop_width`,`crop.crop_height`,`crop.crop_rotation`,`crop.crop_skew_x`,`crop.crop_skew_y`,`crop.blur_hash`,`crop.average_color`,`crop.base64`,`crop.is_dark`,`crop.is_light`]).whereRef(`crop.parent_media_id`,`=`,`lucid_media.id`).where(`crop.relation_type`,`=`,`crop`).where(`crop.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`crop`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media_translations`).select([`lucid_media_translations.title`,`lucid_media_translations.alt`,`lucid_media_translations.description`,`lucid_media_translations.summary`,`lucid_media_translations.locale_code`]).whereRef(`lucid_media_translations.media_id`,`=`,`lucid_media.id`)).as(`translations`)]).where(`id`,`=`,t.id).$if(t.includeOwned!==!0,e=>e.where(`parent_media_id`,`is`,null)).$call(n=>e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_media.tenant_key`})),r=await this.executeQuery(()=>n.executeTakeFirst(),{method:`selectSingleById`});return r.response.error?r.response:this.validateResponse(r,{...t.validation,mode:`single`,select:`id.key.folder_id.parent_media_id.relation_type.e_tag.origin.type.mime_type.file_extension.file_name.file_size.width.height.focal_x.focal_y.crop_x.crop_y.crop_width.crop_height.crop_rotation.crop_skew_x.crop_skew_y.created_at.updated_at.blur_hash.average_color.base64.is_dark.is_light.is_deleted.is_deleted_at.deleted_by.translations.public.poster.crop`.split(`.`)})}async selectMultipleByIds(e){let t=this.db.selectFrom(`lucid_media`).select(e=>[`id`,`key`,`folder_id`,`parent_media_id`,`relation_type`,`e_tag`,`origin`,`type`,`mime_type`,`file_extension`,`file_name`,`file_size`,`width`,`height`,`focal_x`,`focal_y`,`crop_x`,`crop_y`,`crop_width`,`crop_height`,`crop_rotation`,`crop_skew_x`,`crop_skew_y`,`created_at`,`updated_at`,`blur_hash`,`average_color`,`base64`,`is_dark`,`is_light`,`is_deleted`,`is_deleted_at`,`deleted_by`,`public`,`tenant_key`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as poster`).select([`poster.id`,`poster.key`,`poster.origin`,`poster.type`,`poster.mime_type`,`poster.file_extension`,`poster.file_name`,`poster.file_size`,`poster.width`,`poster.height`,`poster.focal_x`,`poster.focal_y`,`poster.crop_x`,`poster.crop_y`,`poster.crop_width`,`poster.crop_height`,`poster.crop_rotation`,`poster.crop_skew_x`,`poster.crop_skew_y`,`poster.blur_hash`,`poster.average_color`,`poster.base64`,`poster.is_dark`,`poster.is_light`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media_translations`).select([`lucid_media_translations.title`,`lucid_media_translations.alt`,`lucid_media_translations.description`,`lucid_media_translations.summary`,`lucid_media_translations.locale_code`]).whereRef(`lucid_media_translations.media_id`,`=`,i.ref(`poster.id`))).as(`translations`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as poster_crop`).select([`poster_crop.id`,`poster_crop.key`,`poster_crop.origin`,`poster_crop.type`,`poster_crop.mime_type`,`poster_crop.file_extension`,`poster_crop.file_name`,`poster_crop.file_size`,`poster_crop.width`,`poster_crop.height`,`poster_crop.focal_x`,`poster_crop.focal_y`,`poster_crop.crop_x`,`poster_crop.crop_y`,`poster_crop.crop_width`,`poster_crop.crop_height`,`poster_crop.crop_rotation`,`poster_crop.crop_skew_x`,`poster_crop.crop_skew_y`,`poster_crop.blur_hash`,`poster_crop.average_color`,`poster_crop.base64`,`poster_crop.is_dark`,`poster_crop.is_light`]).where(`poster_crop.parent_media_id`,`=`,i.ref(`poster.id`)).where(`poster_crop.relation_type`,`=`,`crop`).where(`poster_crop.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`crop`)]).whereRef(`poster.parent_media_id`,`=`,`lucid_media.id`).where(`poster.relation_type`,`=`,`poster`).where(`poster.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`poster`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as crop`).select([`crop.id`,`crop.key`,`crop.origin`,`crop.type`,`crop.mime_type`,`crop.file_extension`,`crop.file_name`,`crop.file_size`,`crop.width`,`crop.height`,`crop.focal_x`,`crop.focal_y`,`crop.crop_x`,`crop.crop_y`,`crop.crop_width`,`crop.crop_height`,`crop.crop_rotation`,`crop.crop_skew_x`,`crop.crop_skew_y`,`crop.blur_hash`,`crop.average_color`,`crop.base64`,`crop.is_dark`,`crop.is_light`]).whereRef(`crop.parent_media_id`,`=`,`lucid_media.id`).where(`crop.relation_type`,`=`,`crop`).where(`crop.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`crop`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media_translations`).select([`lucid_media_translations.title`,`lucid_media_translations.alt`,`lucid_media_translations.description`,`lucid_media_translations.summary`,`lucid_media_translations.locale_code`]).whereRef(`lucid_media_translations.media_id`,`=`,`lucid_media.id`)).as(`translations`)]).where(`id`,`in`,e.ids).where(`parent_media_id`,`is`,null),n=await this.executeQuery(()=>t.execute(),{method:`selectMultipleByIds`});return n.response.error?n.response:this.validateResponse(n,{...e.validation,mode:`multiple`,select:`id.key.folder_id.parent_media_id.relation_type.e_tag.origin.type.mime_type.file_extension.file_name.file_size.width.height.focal_x.focal_y.crop_x.crop_y.crop_width.crop_height.crop_rotation.crop_skew_x.crop_skew_y.created_at.updated_at.blur_hash.average_color.base64.is_dark.is_light.is_deleted.is_deleted_at.deleted_by.translations.public.poster.crop`.split(`.`)})}async selectMultipleValidationData(t){let n=this.db.selectFrom(`lucid_media`).select([`id`,`file_extension`,`width`,`height`,`type`]).where(`id`,`in`,t.ids).where(`parent_media_id`,`is`,null);n=e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_media.tenant_key`});let r=await this.executeQuery(()=>n.execute(),{method:`selectMultipleValidationData`});return r.response.error?r.response:this.validateResponse(r,{...t.validation,mode:`multiple`,select:[`id`,`file_extension`,`width`,`height`,`type`]})}async selectMultipleIdsByFolderIds(t){let n=this.db.selectFrom(`lucid_media`).select([`id`]).where(`folder_id`,`in`,t.folderIds);n=e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_media.tenant_key`});let r=await this.executeQuery(()=>n.execute(),{method:`selectMultipleIdsByFolderIds`});return r.response.error?r.response:this.validateResponse(r,{...t.validation,mode:`multiple`,schema:this.tableSchema.pick({id:!0}),select:[`id`]})}async selectMultipleFilteredFixed(n){let r=await this.executeQuery(async()=>{let r=this.db.selectFrom(`lucid_media`).leftJoin(`lucid_media_translations as translation`,e=>e.onRef(`translation.media_id`,`=`,`lucid_media.id`)).select(e=>[`lucid_media.id`,`lucid_media.key`,`lucid_media.folder_id`,`lucid_media.parent_media_id`,`lucid_media.relation_type`,`lucid_media.e_tag`,`lucid_media.origin`,`lucid_media.type`,`lucid_media.mime_type`,`lucid_media.file_extension`,`lucid_media.file_name`,`lucid_media.file_size`,`lucid_media.width`,`lucid_media.height`,`lucid_media.focal_x`,`lucid_media.focal_y`,`lucid_media.crop_x`,`lucid_media.crop_y`,`lucid_media.crop_width`,`lucid_media.crop_height`,`lucid_media.crop_rotation`,`lucid_media.crop_skew_x`,`lucid_media.crop_skew_y`,`lucid_media.blur_hash`,`lucid_media.average_color`,`lucid_media.base64`,`lucid_media.is_dark`,`lucid_media.is_light`,`lucid_media.created_at`,`lucid_media.updated_at`,`lucid_media.is_deleted`,`lucid_media.is_deleted_at`,`lucid_media.deleted_by`,`lucid_media.public`,`lucid_media.tenant_key`,e.fn.min(`translation.title`).as(`title_sort`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media_translations`).select([`lucid_media_translations.title`,`lucid_media_translations.alt`,`lucid_media_translations.description`,`lucid_media_translations.summary`,`lucid_media_translations.locale_code`]).whereRef(`lucid_media_translations.media_id`,`=`,`lucid_media.id`)).as(`translations`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as poster`).select([`poster.id`,`poster.key`,`poster.origin`,`poster.type`,`poster.mime_type`,`poster.file_extension`,`poster.file_name`,`poster.file_size`,`poster.width`,`poster.height`,`poster.focal_x`,`poster.focal_y`,`poster.crop_x`,`poster.crop_y`,`poster.crop_width`,`poster.crop_height`,`poster.crop_rotation`,`poster.crop_skew_x`,`poster.crop_skew_y`,`poster.blur_hash`,`poster.average_color`,`poster.base64`,`poster.is_dark`,`poster.is_light`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media_translations`).select([`lucid_media_translations.title`,`lucid_media_translations.alt`,`lucid_media_translations.description`,`lucid_media_translations.summary`,`lucid_media_translations.locale_code`]).whereRef(`lucid_media_translations.media_id`,`=`,i.ref(`poster.id`))).as(`translations`),t(this.db,this.dbAdapter,`poster.id`)]).whereRef(`poster.parent_media_id`,`=`,`lucid_media.id`).where(`poster.relation_type`,`=`,`poster`).where(`poster.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`poster`),t(this.db,this.dbAdapter,`lucid_media.id`)]).where(`lucid_media.is_hidden`,`=`,this.dbAdapter.getDefault(`boolean`,`false`)).where(`lucid_media.parent_media_id`,`is`,null).groupBy(`lucid_media.id`).$call(t=>e.tenantScope(t,{tenantKey:n.tenantKey,column:`lucid_media.tenant_key`})),a=this.db.selectFrom(`lucid_media`).select(i`count(distinct lucid_media.id)`.as(`count`)).leftJoin(`lucid_media_translations as translation`,e=>e.onRef(`translation.media_id`,`=`,`lucid_media.id`)).where(`lucid_media.is_hidden`,`=`,this.dbAdapter.getDefault(`boolean`,`false`)).where(`lucid_media.parent_media_id`,`is`,null).$call(t=>e.tenantScope(t,{tenantKey:n.tenantKey,column:`lucid_media.tenant_key`})),{main:o,count:s}=e.main({main:r,count:a},{queryParams:n.queryParams,database:this.dbAdapter.config,meta:{tableKeys:{filters:{title:`translation.title`,...this.queryConfig.tableKeys.filters},sorts:{title:`title_sort`,...this.queryConfig.tableKeys.sorts}},operators:{title:`contains`}}}),[c,l]=await Promise.all([o.execute(),s?.executeTakeFirst()]);return[c,l]},{method:`selectMultipleFilteredFixed`});return r.response.error?r.response:this.validateResponse(r,{...n.validation,mode:`multiple-count`,select:`id.key.folder_id.parent_media_id.relation_type.e_tag.origin.type.mime_type.file_extension.file_name.file_size.width.height.focal_x.focal_y.crop_x.crop_y.crop_width.crop_height.crop_rotation.crop_skew_x.crop_skew_y.blur_hash.average_color.base64.is_dark.is_light.created_at.updated_at.is_deleted.is_deleted_at.deleted_by.public.tenant_key.translations.poster.crop`.split(`.`)})}};export{a as default};
//# sourceMappingURL=media.mjs.map