@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
12 lines • 25.3 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_users`)}tableSchema=n.object({id:n.number(),super_admin:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]),email:n.email(),username:n.string(),first_name:n.string().nullable(),last_name:n.string().nullable(),password:n.string().nullable(),secret:n.string(),triggered_password_reset:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]),invitation_accepted:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]),is_locked:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]),is_deleted:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]),is_deleted_at:n.union([n.string(),n.date()]).nullable(),deleted_by:n.number().nullable(),profile_picture_media_id:n.number().nullable().optional(),profile_picture:n.array(n.object({id:n.number(),key:n.string(),origin:n.enum([`human`,`ai_generated`,`ai_modified`]),folder_id:n.number().nullable(),e_tag:n.string().nullable(),type:n.string(),mime_type:n.string(),file_extension:n.string(),file_name:n.string().nullable(),file_size:n.number(),width:n.number().nullable(),height:n.number().nullable(),focal_x:n.number().nullable(),focal_y:n.number().nullable(),created_at:n.union([n.string(),n.date()]).nullable(),updated_at:n.union([n.string(),n.date()]).nullable(),blur_hash:n.string().nullable(),average_color:n.string().nullable(),base64:n.string().nullable().optional(),is_dark:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),is_light:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),crop:n.array(n.object({id:n.number(),key:n.string(),origin:n.enum([`human`,`ai_generated`,`ai_modified`]),type:n.string(),mime_type:n.string(),file_extension:n.string(),file_name:n.string().nullable(),file_size:n.number(),width:n.number().nullable(),height:n.number().nullable(),focal_x:n.number().nullable(),focal_y:n.number().nullable(),crop_x:n.number(),crop_y:n.number(),crop_width:n.number(),crop_height:n.number(),crop_rotation:n.number(),crop_skew_x:n.number(),crop_skew_y:n.number(),blur_hash:n.string().nullable(),average_color:n.string().nullable(),base64:n.string().nullable().optional(),is_dark:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable(),is_light:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]).nullable()})).optional(),is_deleted:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]),is_deleted_at:n.union([n.string(),n.date()]).nullable(),deleted_by:n.number().nullable(),public:n.union([n.literal(this.dbAdapter.config.defaults.boolean.true),n.literal(this.dbAdapter.config.defaults.boolean.false)]),translations:n.array(n.object({title:n.string().nullable(),alt:n.string().nullable(),locale_code:n.string().nullable()})).optional()})).optional(),auth_providers:n.array(n.object({id:n.number(),provider_key:n.string(),provider_user_id:n.string(),linked_at:n.union([n.string(),n.date()]).nullable()})).optional(),roles:n.array(n.object({id:n.number(),name:n.string().nullable().optional(),translations:n.array(n.object({name:n.string().nullable(),locale_code:n.string().nullable()})).optional(),permissions:n.array(n.object({permission:n.string()})).optional()})).optional(),tenants:n.array(n.object({tenant_key:n.string()})).optional(),created_at:n.union([n.string(),n.date()]).nullable(),updated_at:n.union([n.string(),n.date()]).nullable()});columnFormats={id:this.dbAdapter.getDataType(`primary`),super_admin:this.dbAdapter.getDataType(`boolean`),email:this.dbAdapter.getDataType(`text`),username:this.dbAdapter.getDataType(`text`),first_name:this.dbAdapter.getDataType(`text`),last_name:this.dbAdapter.getDataType(`text`),password:this.dbAdapter.getDataType(`text`),secret:this.dbAdapter.getDataType(`text`),triggered_password_reset:this.dbAdapter.getDataType(`boolean`),invitation_accepted:this.dbAdapter.getDataType(`boolean`),is_locked:this.dbAdapter.getDataType(`boolean`),is_deleted:this.dbAdapter.getDataType(`boolean`),is_deleted_at:this.dbAdapter.getDataType(`timestamp`),deleted_by:this.dbAdapter.getDataType(`integer`),profile_picture_media_id:this.dbAdapter.getDataType(`integer`),created_at:this.dbAdapter.getDataType(`timestamp`),updated_at:this.dbAdapter.getDataType(`timestamp`)};queryConfig={tableKeys:{filters:{firstName:`lucid_users.first_name`,lastName:`lucid_users.last_name`,email:`lucid_users.email`,username:`lucid_users.username`,roleIds:`lucid_user_roles.role_id`,id:`lucid_users.id`,invitationAccepted:`lucid_users.invitation_accepted`,superAdmin:`lucid_users.super_admin`,triggerPasswordReset:`lucid_users.triggered_password_reset`,isLocked:`lucid_users.is_locked`,isDeleted:`lucid_users.is_deleted`,deletedBy:`lucid_users.deleted_by`,createdAt:`lucid_users.created_at`,updatedAt:`lucid_users.updated_at`},sorts:{createdAt:`lucid_users.created_at`,updatedAt:`lucid_users.updated_at`,firstName:`lucid_users.first_name`,lastName:`lucid_users.last_name`,email:`lucid_users.email`,username:`lucid_users.username`,isLocked:`lucid_users.is_locked`}},operators:{firstName:`contains`,lastName:`contains`,email:`contains`,username:`contains`}};async selectAccessTokenUser(t){let n=this.db.selectFrom(`lucid_users`).select(n=>[`id`,`username`,`email`,`super_admin`,this.dbAdapter.jsonArrayFrom(n.selectFrom(`lucid_user_roles`).innerJoin(`lucid_roles`,`lucid_roles.id`,`lucid_user_roles.role_id`).select(e=>[`lucid_roles.id`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_role_translations`).select([`lucid_role_translations.name`,`lucid_role_translations.locale_code`]).whereRef(`lucid_role_translations.role_id`,`=`,`lucid_roles.id`)).as(`translations`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_role_permissions`).select([`permission`]).whereRef(`role_id`,`=`,`lucid_roles.id`)).as(`permissions`)]).whereRef(`user_id`,`=`,`lucid_users.id`).$call(n=>e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_roles.tenant_key`}))).as(`roles`),this.dbAdapter.jsonArrayFrom(n.selectFrom(`lucid_user_tenants`).select([`lucid_user_tenants.tenant_key`]).whereRef(`lucid_user_tenants.user_id`,`=`,`lucid_users.id`)).as(`tenants`)]);n=e.select(n,t.where);let r=await this.executeQuery(()=>n.executeTakeFirst(),{method:`selectAccessTokenUser`});return r.response.error?r.response:this.validateResponse(r,{...t.validation,mode:`single`,select:[`id`,`username`,`email`,`super_admin`,`roles`,`tenants`]})}async selectAuditActorById(e){let t=this.db.selectFrom(`lucid_users`).select(t=>[`id`,`super_admin`,this.dbAdapter.jsonArrayFrom(t.selectFrom(`lucid_user_roles`).innerJoin(`lucid_roles`,`lucid_roles.id`,`lucid_user_roles.role_id`).leftJoin(`lucid_role_translations as translation`,t=>t.onRef(`translation.role_id`,`=`,`lucid_roles.id`).on(`translation.locale_code`,`=`,e.defaultLocale)).select([`lucid_roles.id`,`translation.name`]).whereRef(`user_id`,`=`,`lucid_users.id`).orderBy(`lucid_roles.id`,`asc`)).as(`roles`)]).where(`id`,`=`,e.id),n=await this.executeQuery(()=>t.executeTakeFirst(),{method:`selectAuditActorById`});return n.response.error?n.response:this.validateResponse(n,{...e.validation,mode:`single`,select:[`id`,`super_admin`,`roles`]})}async selectSinglePreset(t){let n=this.db.selectFrom(`lucid_users`).select(n=>[`email`,`first_name`,`last_name`,`id`,`created_at`,`updated_at`,`username`,`super_admin`,`triggered_password_reset`,`invitation_accepted`,`is_locked`,`is_deleted`,`is_deleted_at`,`password`,this.dbAdapter.jsonArrayFrom(n.selectFrom(`lucid_user_roles`).innerJoin(`lucid_roles`,`lucid_roles.id`,`lucid_user_roles.role_id`).select(e=>[`lucid_roles.id`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_role_translations`).select([`lucid_role_translations.name`,`lucid_role_translations.locale_code`]).whereRef(`lucid_role_translations.role_id`,`=`,`lucid_roles.id`)).as(`translations`),this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_role_permissions`).select([`permission`]).whereRef(`role_id`,`=`,`lucid_roles.id`)).as(`permissions`)]).whereRef(`user_id`,`=`,`lucid_users.id`).$call(n=>e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_roles.tenant_key`}))).as(`roles`),this.dbAdapter.jsonArrayFrom(n.selectFrom(`lucid_user_auth_providers`).select([`lucid_user_auth_providers.id`,`lucid_user_auth_providers.provider_key`,`lucid_user_auth_providers.provider_user_id`,`lucid_user_auth_providers.linked_at`]).whereRef(`lucid_user_auth_providers.user_id`,`=`,`lucid_users.id`)).as(`auth_providers`),this.dbAdapter.jsonArrayFrom(n.selectFrom(`lucid_media`).select(e=>[`lucid_media.id`,`lucid_media.key`,`lucid_media.origin`,`lucid_media.folder_id`,`lucid_media.e_tag`,`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.created_at`,`lucid_media.updated_at`,`lucid_media.blur_hash`,`lucid_media.average_color`,`lucid_media.base64`,`lucid_media.is_dark`,`lucid_media.is_light`,`lucid_media.is_deleted`,`lucid_media.is_deleted_at`,`lucid_media.deleted_by`,`lucid_media.public`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as profile_crop`).select([`profile_crop.id`,`profile_crop.key`,`profile_crop.origin`,`profile_crop.type`,`profile_crop.mime_type`,`profile_crop.file_extension`,`profile_crop.file_name`,`profile_crop.file_size`,`profile_crop.width`,`profile_crop.height`,`profile_crop.focal_x`,`profile_crop.focal_y`,`profile_crop.crop_x`,`profile_crop.crop_y`,`profile_crop.crop_width`,`profile_crop.crop_height`,`profile_crop.crop_rotation`,`profile_crop.crop_skew_x`,`profile_crop.crop_skew_y`,`profile_crop.blur_hash`,`profile_crop.average_color`,`profile_crop.base64`,`profile_crop.is_dark`,`profile_crop.is_light`]).where(`profile_crop.parent_media_id`,`=`,r.ref(`lucid_media.id`)).where(`profile_crop.relation_type`,`=`,`crop`).where(`profile_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`)]).whereRef(`lucid_media.id`,`=`,`lucid_users.profile_picture_media_id`).where(`lucid_media.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`profile_picture`),this.dbAdapter.jsonArrayFrom(n.selectFrom(`lucid_user_tenants`).select([`lucid_user_tenants.tenant_key`]).whereRef(`lucid_user_tenants.user_id`,`=`,`lucid_users.id`)).as(`tenants`)]);n=e.select(n,t.where),n=this.applyUserTenantScope(n,t.tenantKey);let i=await this.executeQuery(()=>n.executeTakeFirst(),{method:`selectSingleById`});return i.response.error?i.response:this.validateResponse(i,{...t.validation,mode:`single`,select:[`email`,`first_name`,`last_name`,`id`,`created_at`,`updated_at`,`username`,`super_admin`,`triggered_password_reset`,`invitation_accepted`,`is_locked`,`password`,`roles`,`auth_providers`,`profile_picture`,`tenants`]})}async selectMultipleByIds(t){let n=this.db.selectFrom(`lucid_users`).select(e=>[`email`,`first_name`,`last_name`,`id`,`created_at`,`updated_at`,`username`,`super_admin`,`is_locked`,`is_deleted`,`is_deleted_at`,`invitation_accepted`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media`).select(e=>[`lucid_media.id`,`lucid_media.key`,`lucid_media.origin`,`lucid_media.folder_id`,`lucid_media.e_tag`,`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.created_at`,`lucid_media.updated_at`,`lucid_media.blur_hash`,`lucid_media.average_color`,`lucid_media.base64`,`lucid_media.is_dark`,`lucid_media.is_light`,`lucid_media.is_deleted`,`lucid_media.is_deleted_at`,`lucid_media.deleted_by`,`lucid_media.public`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as profile_crop`).select([`profile_crop.id`,`profile_crop.key`,`profile_crop.origin`,`profile_crop.type`,`profile_crop.mime_type`,`profile_crop.file_extension`,`profile_crop.file_name`,`profile_crop.file_size`,`profile_crop.width`,`profile_crop.height`,`profile_crop.focal_x`,`profile_crop.focal_y`,`profile_crop.crop_x`,`profile_crop.crop_y`,`profile_crop.crop_width`,`profile_crop.crop_height`,`profile_crop.crop_rotation`,`profile_crop.crop_skew_x`,`profile_crop.crop_skew_y`,`profile_crop.blur_hash`,`profile_crop.average_color`,`profile_crop.base64`,`profile_crop.is_dark`,`profile_crop.is_light`]).where(`profile_crop.parent_media_id`,`=`,r.ref(`lucid_media.id`)).where(`profile_crop.relation_type`,`=`,`crop`).where(`profile_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`)]).whereRef(`lucid_media.id`,`=`,`lucid_users.profile_picture_media_id`).where(`lucid_media.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`profile_picture`)]).where(`id`,`in`,t.ids);t.where!==void 0&&t.where.length>0&&(n=e.select(n,t.where)),n=this.applyUserTenantScope(n,t.tenantKey);let i=await this.executeQuery(()=>n.execute(),{method:`selectMultipleByIds`});return i.response.error?i.response:this.validateResponse(i,{...t.validation,mode:`multiple`,select:[`email`,`first_name`,`last_name`,`id`,`created_at`,`updated_at`,`username`,`super_admin`,`invitation_accepted`,`is_locked`,`profile_picture`]})}async selectSingleByEmailUsername(e){let t=this.db.selectFrom(`lucid_users`).select(e.select).where(t=>t.or([t(`username`,`=`,e.where.username),t(`email`,`=`,e.where.email)])),n=await this.executeQuery(()=>t.executeTakeFirst(),{method:`selectSingleByEmailUsername`});return n.response.error?n.response:this.validateResponse(n,{...e.validation,mode:`single`,select:e.select})}async selectMultipleFilteredFixed(t){let n=await this.executeQuery(async()=>{let n=this.db.selectFrom(`lucid_users`).select(n=>[`lucid_users.email`,`lucid_users.first_name`,`lucid_users.last_name`,`lucid_users.id`,`lucid_users.created_at`,`lucid_users.updated_at`,`lucid_users.username`,`lucid_users.super_admin`,`lucid_users.password`,`lucid_users.triggered_password_reset`,`lucid_users.is_locked`,`lucid_users.is_deleted`,`lucid_users.is_deleted_at`,`lucid_users.invitation_accepted`,this.dbAdapter.jsonArrayFrom(n.selectFrom(`lucid_user_roles`).innerJoin(`lucid_roles`,`lucid_roles.id`,`lucid_user_roles.role_id`).select(e=>[`lucid_roles.id`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_role_translations`).select([`lucid_role_translations.name`,`lucid_role_translations.locale_code`]).whereRef(`lucid_role_translations.role_id`,`=`,`lucid_roles.id`)).as(`translations`)]).whereRef(`user_id`,`=`,`lucid_users.id`).$call(n=>e.tenantScope(n,{tenantKey:t.tenantKey,column:`lucid_roles.tenant_key`}))).as(`roles`),this.dbAdapter.jsonArrayFrom(n.selectFrom(`lucid_media`).select(e=>[`lucid_media.id`,`lucid_media.key`,`lucid_media.origin`,`lucid_media.folder_id`,`lucid_media.e_tag`,`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.created_at`,`lucid_media.updated_at`,`lucid_media.blur_hash`,`lucid_media.average_color`,`lucid_media.base64`,`lucid_media.is_dark`,`lucid_media.is_light`,`lucid_media.is_deleted`,`lucid_media.is_deleted_at`,`lucid_media.deleted_by`,`lucid_media.public`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as profile_crop`).select([`profile_crop.id`,`profile_crop.key`,`profile_crop.origin`,`profile_crop.type`,`profile_crop.mime_type`,`profile_crop.file_extension`,`profile_crop.file_name`,`profile_crop.file_size`,`profile_crop.width`,`profile_crop.height`,`profile_crop.focal_x`,`profile_crop.focal_y`,`profile_crop.crop_x`,`profile_crop.crop_y`,`profile_crop.crop_width`,`profile_crop.crop_height`,`profile_crop.crop_rotation`,`profile_crop.crop_skew_x`,`profile_crop.crop_skew_y`,`profile_crop.blur_hash`,`profile_crop.average_color`,`profile_crop.base64`,`profile_crop.is_dark`,`profile_crop.is_light`]).where(`profile_crop.parent_media_id`,`=`,r.ref(`lucid_media.id`)).where(`profile_crop.relation_type`,`=`,`crop`).where(`profile_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`)]).whereRef(`lucid_media.id`,`=`,`lucid_users.profile_picture_media_id`).where(`lucid_media.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`profile_picture`)]).$if(t.includeTenants===!0,e=>e.select(e=>[this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_user_tenants`).select([`lucid_user_tenants.tenant_key`]).whereRef(`lucid_user_tenants.user_id`,`=`,`lucid_users.id`)).as(`tenants`)])).leftJoin(`lucid_user_roles`,e=>e.onRef(`lucid_user_roles.user_id`,`=`,`lucid_users.id`)).groupBy(`lucid_users.id`).$call(e=>this.applyUserTenantScope(e,t.tenantKey)),i=this.db.selectFrom(`lucid_users`).select(r`count(distinct lucid_users.id)`.as(`count`)).leftJoin(`lucid_user_roles`,e=>e.onRef(`lucid_user_roles.user_id`,`=`,`lucid_users.id`)).$call(e=>this.applyUserTenantScope(e,t.tenantKey)),{main:a,count:o}=e.main({main:n,count:i},{queryParams:t.queryParams,database:this.dbAdapter.config,meta:this.queryConfig}),[s,c]=await Promise.all([a.execute(),o?.executeTakeFirst()]);return[s,c]},{method:`selectMultipleFilteredFixed`});return n.response.error?n.response:this.validateResponse(n,{...t.validation,mode:`multiple-count`,select:[`email`,`first_name`,`last_name`,`id`,`created_at`,`updated_at`,`username`,`super_admin`,`password`,`triggered_password_reset`,`is_locked`,`roles`,`invitation_accepted`,`profile_picture`,...t.includeTenants===!0?[`tenants`]:[]]})}async selectMultiplePublishReviewers(t){let n=await this.executeQuery(()=>{let n=this.dbAdapter.getDefault(`boolean`,`true`),i=this.dbAdapter.getDefault(`boolean`,`false`),a=this.dbAdapter.getDefault(`boolean`,`false`);return this.applyUserTenantScope(this.db.selectFrom(`lucid_users`).select(e=>[`id`,`email`,`username`,`first_name as firstName`,`last_name as lastName`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media`).select(e=>[`lucid_media.id`,`lucid_media.key`,`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.blur_hash`,`lucid_media.average_color`,`lucid_media.base64`,`lucid_media.is_dark`,`lucid_media.is_light`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as profile_crop`).select([`profile_crop.id`,`profile_crop.key`,`profile_crop.origin`,`profile_crop.type`,`profile_crop.mime_type`,`profile_crop.file_extension`,`profile_crop.file_name`,`profile_crop.file_size`,`profile_crop.width`,`profile_crop.height`,`profile_crop.focal_x`,`profile_crop.focal_y`,`profile_crop.crop_x`,`profile_crop.crop_y`,`profile_crop.crop_width`,`profile_crop.crop_height`,`profile_crop.crop_rotation`,`profile_crop.crop_skew_x`,`profile_crop.crop_skew_y`,`profile_crop.blur_hash`,`profile_crop.average_color`,`profile_crop.base64`,`profile_crop.is_dark`,`profile_crop.is_light`]).where(`profile_crop.parent_media_id`,`=`,r.ref(`lucid_media.id`)).where(`profile_crop.relation_type`,`=`,`crop`).where(`profile_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`)]).whereRef(`lucid_media.id`,`=`,`lucid_users.profile_picture_media_id`).where(`lucid_media.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`profile_picture`)]).where(`is_deleted`,`=`,i).where(`is_locked`,`=`,a).where(({or:i,eb:a,exists:o,selectFrom:s})=>i([a(`super_admin`,`=`,n),o(e.tenantScope(s(`lucid_user_roles`).innerJoin(`lucid_roles`,`lucid_roles.id`,`lucid_user_roles.role_id`).innerJoin(`lucid_role_permissions`,`lucid_role_permissions.role_id`,`lucid_roles.id`).select(r.lit(1).as(`one`)).whereRef(`lucid_user_roles.user_id`,`=`,`lucid_users.id`).where(`lucid_role_permissions.permission`,`=`,t.permission),{tenantKey:t.tenantKey,column:`lucid_roles.tenant_key`}))])).orderBy(`email`,`asc`),t.tenantKey).execute()},{method:`selectMultiplePublishReviewers`});return n.response.error?n.response:this.validateResponse(n,{...t.validation,mode:`multiple`})}async selectMultipleWithPermission(t){let n=await this.executeQuery(()=>{let n=this.dbAdapter.getDefault(`boolean`,`true`),i=this.dbAdapter.getDefault(`boolean`,`false`),a=this.dbAdapter.getDefault(`boolean`,`false`);return this.applyUserTenantScope(this.db.selectFrom(`lucid_users`).select(e=>[`id`,`email`,`username`,`first_name as firstName`,`last_name as lastName`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media`).select(e=>[`lucid_media.id`,`lucid_media.key`,`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.blur_hash`,`lucid_media.average_color`,`lucid_media.base64`,`lucid_media.is_dark`,`lucid_media.is_light`,this.dbAdapter.jsonArrayFrom(e.selectFrom(`lucid_media as profile_crop`).select([`profile_crop.id`,`profile_crop.key`,`profile_crop.origin`,`profile_crop.type`,`profile_crop.mime_type`,`profile_crop.file_extension`,`profile_crop.file_name`,`profile_crop.file_size`,`profile_crop.width`,`profile_crop.height`,`profile_crop.focal_x`,`profile_crop.focal_y`,`profile_crop.crop_x`,`profile_crop.crop_y`,`profile_crop.crop_width`,`profile_crop.crop_height`,`profile_crop.crop_rotation`,`profile_crop.crop_skew_x`,`profile_crop.crop_skew_y`,`profile_crop.blur_hash`,`profile_crop.average_color`,`profile_crop.base64`,`profile_crop.is_dark`,`profile_crop.is_light`]).where(`profile_crop.parent_media_id`,`=`,r.ref(`lucid_media.id`)).where(`profile_crop.relation_type`,`=`,`crop`).where(`profile_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`)]).whereRef(`lucid_media.id`,`=`,`lucid_users.profile_picture_media_id`).where(`lucid_media.is_deleted`,`=`,this.dbAdapter.getDefault(`boolean`,`false`))).as(`profile_picture`)]).where(`is_deleted`,`=`,i).where(`is_locked`,`=`,a).where(({or:i,eb:a,exists:o,selectFrom:s})=>i([a(`super_admin`,`=`,n),o(e.tenantScope(s(`lucid_user_roles`).innerJoin(`lucid_roles`,`lucid_roles.id`,`lucid_user_roles.role_id`).innerJoin(`lucid_role_permissions`,`lucid_role_permissions.role_id`,`lucid_roles.id`).select(r.lit(1).as(`one`)).whereRef(`lucid_user_roles.user_id`,`=`,`lucid_users.id`).where(`lucid_role_permissions.permission`,`=`,t.permission),{tenantKey:t.tenantKey,column:`lucid_roles.tenant_key`}))])).orderBy(`email`,`asc`),t.tenantKey).execute()},{method:`selectMultipleWithPermission`});return n.response.error?n.response:this.validateResponse(n,{...t.validation,mode:`multiple`})}applyUserTenantScope(e,t){return t==null?e:e.where(r`(
exists (
select 1 from lucid_user_tenants
where lucid_user_tenants.user_id = lucid_users.id
and lucid_user_tenants.tenant_key = ${t}
)
or not exists (
select 1 from lucid_user_tenants
where lucid_user_tenants.user_id = lucid_users.id
)
)`)}};export{i as default};
//# sourceMappingURL=users.mjs.map