UNPKG

@lucidcms/core

Version:

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

83 lines (82 loc) 4.25 kB
import { QueryParams } from "../../../types/query-params.mjs"; import { Insert, LucidDB, Select, Update } from "../../db/types.mjs"; import { QueryProps, QueryResult } from "../types.mjs"; import { QueryBuilderWhere } from "../../db/query-builder/index.mjs"; import BaseRepository from "./base-repository.mjs"; //#region src/libs/repositories/parents/static-repository.d.ts /** * The static repository class that all repositories should extend. This class provides basic CRUD operations for a single table. * * For tables that need more complex queries with joins or subqueries. Its expect you override the methods in this class while keeping the same paramaters if posible. * * @todo Any queryBuilder helper functions likley need to make use of the columnFormats config so they can correctly parse the data if needed. For ex if the where array includes an op on a boolean column, the value needs to be correctly formatted. * @todo Add callback support for the validation / tweak required. Sometimes instead of returning an error on required failing we want to handle it differently * @todo Improve validation error messages. Allow error overides for differnt types, required, validation etc. * @todo look into using $if for conditional query builder options * @todo try and get the retuning and select props correctly typed instead of typing it ourselved with the Select helper. Likley allows us to get rid of the 'as Promise<Pick<Select<T>, K> | undefined>' and lets Kysely handle the return type * @todo Support for DB Adapters overiding queries. Probs best as a method that repos can opt into? * */ declare abstract class StaticRepository<Table extends keyof LucidDB, T extends LucidDB[Table] = LucidDB[Table]> extends BaseRepository<Table, T> { count<V extends boolean = false>(props: QueryProps<V, { where?: QueryBuilderWhere<Table>; }>): Promise<QueryResult<{ count: string | number; }, V>>; selectSingle<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { select: K[]; where: QueryBuilderWhere<Table>; }>): Promise<QueryResult<Pick<Select<T>, K>, V>>; selectMultiple<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { select: K[]; where?: QueryBuilderWhere<Table>; orderBy?: { column: K; direction: "asc" | "desc"; }[]; limit?: number; offset?: number; }>): Promise<QueryResult<Pick<Select<T>, K>[], V>>; selectMultipleFiltered<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { select: K[]; where?: QueryBuilderWhere<Table>; queryParams: Partial<QueryParams>; }>): Promise<QueryResult<readonly [Pick<Select<T>, K>[], { count: string; } | undefined], V>>; deleteSingle<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { returning?: K[]; returnAll?: true; where: QueryBuilderWhere<Table>; }>): Promise<QueryResult<Pick<Select<T>, K>, V>>; deleteMultiple<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { returning?: K[]; returnAll?: true; where: QueryBuilderWhere<Table>; }>): Promise<QueryResult<Pick<Select<T>, K>[], V>>; createSingle<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { data: Partial<Insert<T>>; returning?: K[]; returnAll?: true; }>): Promise<QueryResult<Pick<Select<T>, K>, V>>; createMultiple<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { data: Partial<Insert<T>>[]; returning?: K[]; returnAll?: true; }>): Promise<QueryResult<Pick<Select<T>, K>[], V>>; updateSingle<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { data: Partial<Update<T>>; where: QueryBuilderWhere<Table>; returning?: K[]; returnAll?: true; }>): Promise<QueryResult<Pick<Select<T>, K>, V>>; updateMultiple<K extends keyof Select<T>, V extends boolean = false>(props: QueryProps<V, { data: Partial<Update<T>>; where: QueryBuilderWhere<Table>; returning?: K[]; returnAll?: true; }>): Promise<QueryResult<Pick<Select<T>, K>[], V>>; } //#endregion export { StaticRepository as default }; //# sourceMappingURL=static-repository.d.mts.map