UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 3.81 kB
{"version":3,"file":"role-translations.mjs","names":[],"sources":["../../../src/libs/repositories/role-translations.ts"],"sourcesContent":["import z from \"zod\";\nimport type DatabaseAdapter from \"../db/adapter-base.js\";\nimport type {\n\tInsert,\n\tKyselyDB,\n\tLucidRoleTranslations,\n\tSelect,\n} from \"../db/types.js\";\nimport StaticRepository from \"./parents/static-repository.js\";\nimport type { QueryProps } from \"./types.js\";\n\nexport default class RoleTranslationsRepository extends StaticRepository<\"lucid_role_translations\"> {\n\tconstructor(db: KyselyDB, dbAdapter: DatabaseAdapter) {\n\t\tsuper(db, dbAdapter, \"lucid_role_translations\");\n\t}\n\ttableSchema = z.object({\n\t\tid: z.number(),\n\t\trole_id: z.number(),\n\t\tlocale_code: z.string(),\n\t\tname: z.string().nullable(),\n\t\tdescription: z.string().nullable(),\n\t});\n\tcolumnFormats = {\n\t\tid: this.dbAdapter.getDataType(\"primary\"),\n\t\trole_id: this.dbAdapter.getDataType(\"integer\"),\n\t\tlocale_code: this.dbAdapter.getDataType(\"text\"),\n\t\tname: this.dbAdapter.getDataType(\"text\"),\n\t\tdescription: this.dbAdapter.getDataType(\"text\"),\n\t};\n\tqueryConfig = undefined;\n\n\t/**\n\t * Upserts internal admin UI role translations using the supplied row as truth.\n\t */\n\tasync upsertMultiple<\n\t\tK extends keyof Select<LucidRoleTranslations>,\n\t\tV extends boolean = false,\n\t>(\n\t\tprops: QueryProps<\n\t\t\tV,\n\t\t\t{\n\t\t\t\tdata: Partial<Insert<LucidRoleTranslations>>[];\n\t\t\t\treturning?: K[];\n\t\t\t\treturnAll?: true;\n\t\t\t}\n\t\t>,\n\t) {\n\t\tconst query = this.db\n\t\t\t.insertInto(\"lucid_role_translations\")\n\t\t\t.values(\n\t\t\t\tprops.data.map((d) =>\n\t\t\t\t\tthis.formatData(d, {\n\t\t\t\t\t\ttype: \"insert\",\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.onConflict((oc) =>\n\t\t\t\toc.columns([\"role_id\", \"locale_code\"]).doUpdateSet((eb) => ({\n\t\t\t\t\tname: eb.ref(\"excluded.name\"),\n\t\t\t\t\tdescription: eb.ref(\"excluded.description\"),\n\t\t\t\t})),\n\t\t\t)\n\t\t\t.$if(\n\t\t\t\tprops.returnAll !== true &&\n\t\t\t\t\tprops.returning !== undefined &&\n\t\t\t\t\tprops.returning.length > 0,\n\t\t\t\t(qb) => qb.returning(props.returning as K[]),\n\t\t\t)\n\t\t\t.$if(props.returnAll ?? false, (qb) => qb.returningAll());\n\n\t\tconst exec = await this.executeQuery(\n\t\t\t() =>\n\t\t\t\tquery.execute() as Promise<Pick<Select<LucidRoleTranslations>, K>[]>,\n\t\t\t{\n\t\t\t\tmethod: \"upsertMultiple\",\n\t\t\t},\n\t\t);\n\t\tif (exec.response.error) return exec.response;\n\n\t\treturn this.validateResponse(exec, {\n\t\t\t...props.validation,\n\t\t\tmode: \"multiple\",\n\t\t\tselect: props.returning as string[],\n\t\t\tselectAll: props.returnAll,\n\t\t});\n\t}\n}\n"],"mappings":"kEAWA,IAAqB,EAArB,cAAwD,CAA4C,CACnG,YAAY,EAAc,EAA4B,CACrD,MAAM,EAAI,EAAW,yBAAyB,CAC/C,CACA,YAAc,EAAE,OAAO,CACtB,GAAI,EAAE,OAAO,EACb,QAAS,EAAE,OAAO,EAClB,YAAa,EAAE,OAAO,EACtB,KAAM,EAAE,OAAO,CAAC,CAAC,SAAS,EAC1B,YAAa,EAAE,OAAO,CAAC,CAAC,SAAS,CAClC,CAAC,EACD,cAAgB,CACf,GAAI,KAAK,UAAU,YAAY,SAAS,EACxC,QAAS,KAAK,UAAU,YAAY,SAAS,EAC7C,YAAa,KAAK,UAAU,YAAY,MAAM,EAC9C,KAAM,KAAK,UAAU,YAAY,MAAM,EACvC,YAAa,KAAK,UAAU,YAAY,MAAM,CAC/C,EACA,YAAc,IAAA,GAKd,MAA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