import { ModelGroupRelationFields } from "./utils/helpers/base.service.helpers"; import { PrismaModels, PrismaClient, ExtractPrismaFilters, ExtractPrismaData, ExtractPrismaQueryOptions } from "../../generated"; import { ServiceBaseContext } from "./types/base.service.types"; type Models = PrismaModels; type CreateData = ExtractPrismaData; type CreateManyData = ExtractPrismaData; type CreateOptions = ExtractPrismaQueryOptions; type CreateManyOptions = ExtractPrismaQueryOptions; type CountFilters = ExtractPrismaFilters; type FindManyFilters = ExtractPrismaFilters; type FindManyOptions = ExtractPrismaQueryOptions; type FindOneFilters = ExtractPrismaFilters; type FindOneOptions = ExtractPrismaQueryOptions; type UpdateOneFilters = ExtractPrismaFilters; type UpdateOneData = ExtractPrismaData; type UpdateOneOptions = ExtractPrismaQueryOptions; type UpdateManyFilters = ExtractPrismaFilters; type UpdateManyData = ExtractPrismaData; type UpdateManyOptions = ExtractPrismaQueryOptions; type DeleteOneFilters = ExtractPrismaFilters; type DeleteManyFilters = ExtractPrismaFilters; type GetPayload> = PrismaModels[TModelName]["GetPayload"]; export interface ServiceOperationHooks { beforeOperation?: (params: any) => void | Promise; afterOperation?: (result: any, params: any) => void | Promise; beforePrisma?: (prismaArgs: any, params: any) => any | Promise; afterPrisma?: (result: any, params: any) => any | Promise; } /** * Base service class for handling CRUD operations on a specific model. * This class provides standard implementation of data operations that can be extended * by model-specific service classes. * * @class BaseService * * @example * ```ts * import { BaseService } from "arkos/services"; * * export class UserService extends BaseService<"user"> {} * * const userService = new UserService("user"); * ``` * * @see {@link https://www.arkosjs.com/docs/reference/base-service} * @see {@link https://www.arkosjs.com/docs/guide/accessing-request-context-in-services} */ export declare class BaseService { modelName: TModelName; relationFields: ModelGroupRelationFields; private prismaInstace?; constructor(modelName: TModelName); get prisma(): PrismaClient; private executeOperation; private executeTransactionOperation; private executeHooks; private buildHookParams; private buildTransactionHookParams; private handlePasswordHashing; private processRelationFieldsInBody; private buildPrismaArgs; private executeTransactionLogic; private shouldHashPassword; private processPasswordHashing; /** * Creates a single record in the database. * * @param data - The data for creating the record * @param queryOptions - Optional Prisma query options (select, include, etc.) * @param context - Optional service execution context * * @example * ```ts * const user = await userService.createOne({ * name: "John Doe", * email: "john@example.com" * }); * ``` */ createOne>(data: CreateData, queryOptions?: TOptions, context?: ServiceBaseContext): Promise>; /** * Creates multiple records in the database. * * @param data - Array of data objects or object with data array * @param queryOptions - Optional Prisma query options * @param context - Optional service execution context * * @example * ```ts * const result = await userService.createMany([ * { name: "John Doe", email: "john@example.com" }, * { name: "Jane Smith", email: "jane@example.com" } * ]); * ``` */ createMany>(data: CreateManyData, queryOptions?: TOptions, context?: ServiceBaseContext): Promise[]>; /** * Counts records matching the specified filters. * * @param filters - Optional where conditions * @param queryOptions - Optional Prisma query options * @param context - Optional service execution context * * @example * ```ts * const total = await userService.count({ status: "active" }); * ``` */ count(filters?: CountFilters, context?: ServiceBaseContext): Promise; /** * Finds multiple records matching the specified filters. * * @param filters - Optional where conditions * @param queryOptions - Optional Prisma query options (select, include, orderBy, skip, take, etc.) * @param context - Optional service execution context * * @example * ```ts * const users = await userService.findMany( * { status: "active" }, * { orderBy: { createdAt: "desc" }, take: 10 } * ); * ``` */ findMany>(filters?: FindManyFilters, queryOptions?: TOptions, context?: ServiceBaseContext): Promise[]>; /** * Finds a single record by its ID. * * @param id - The unique identifier of the record * @param queryOptions - Optional Prisma query options (select, include, etc.) * @param context - Optional service execution context * * @example * ```ts * const user = await userService.findById("user-123"); * ``` */ findById>(id: string | number, queryOptions?: TOptions, context?: ServiceBaseContext): Promise | null>; /** * Finds the first record matching the specified filters. * * @param filters - Where conditions to filter records * @param queryOptions - Optional Prisma query options * @param context - Optional service execution context * * @example * ```ts * const user = await userService.findOne({ email: "john@example.com" }); * ``` */ findOne>(filters: FindOneFilters, queryOptions?: TOptions, context?: ServiceBaseContext): Promise | null>; /** * Updates a single record matching the specified filters. * * @param filters - Where conditions to identify the record * @param data - The data to update * @param queryOptions - Optional Prisma query options * @param context - Optional service execution context * * @example * ```ts * const updated = await userService.updateOne( * { id: "user-123" }, * { name: "John Updated" } * ); * ``` */ updateOne>(filters: UpdateOneFilters, data: UpdateOneData, queryOptions?: TOptions, context?: ServiceBaseContext): Promise>; /** * Updates a single record matching the specified id. * * @param id - The unique identifier of the record * @param data - The data to update * @param queryOptions - Optional Prisma query options * @param context - Optional service execution context * * @example * ```ts * const updated = await userService.updateById("user-123", { name: "John Updated" }); * ``` */ updateById>(id: string | number, data: UpdateOneData, queryOptions?: TOptions, context?: ServiceBaseContext): Promise>; /** * Updates multiple records matching the specified filters. * * @param filters - Where conditions to identify records * @param data - The data to update * @param queryOptions - Optional Prisma query options * @param context - Optional service execution context * * @example * ```ts * const result = await userService.updateMany( * { status: "pending" }, * { status: "active" } * ); * ``` */ updateMany>(filters: UpdateManyFilters, data: UpdateManyData, queryOptions?: TOptions, context?: ServiceBaseContext): Promise<{ count: number; }>; /** * Deletes a single record by its ID. * * @param id - The unique identifier of the record * @param context - Optional service execution context * * @example * ```ts * const deleted = await userService.deleteById("user-123"); * ``` */ deleteById(id: string | number, context?: ServiceBaseContext): Promise>; /** * Deletes a single record matching the specified filters. * * @param filters - Where conditions to identify the record * @param context - Optional service execution context * * @example * ```ts * const deleted = await userService.deleteOne({ id: "user-123" }); * ``` */ deleteOne(filters: DeleteOneFilters, context?: ServiceBaseContext): Promise>; /** * Deletes multiple records matching the specified filters. * * @param filters - Where conditions to identify records * @param context - Optional service execution context * * @example * ```ts * const result = await userService.deleteMany({ status: "inactive" }); * ``` */ deleteMany(filters: DeleteManyFilters, context?: ServiceBaseContext): Promise<{ count: number; }>; /** * Performs multiple update operations in a single transaction. * * @param dataArray - Array of update objects each containing filter criteria and data * @param queryOptions - Optional Prisma query options applied to all updates * @param context - Optional service execution context * * @example * ```ts * const results = await userService.batchUpdate([ * { id: "user-1", status: "active" }, * { id: "user-2", status: "inactive" } * ]); * ``` */ batchUpdate>(dataArray: UpdateOneData[], queryOptions?: TOptions, context?: ServiceBaseContext): Promise[]>; /** * Performs multiple delete operations in a single transaction. * * @param batchFilters - Array of where conditions each identifying a record to delete * @param context - Optional service execution context * * @example * ```ts * const deleted = await userService.batchDelete([ * { id: "user-1" }, * { id: "user-2" } * ]); * ``` */ batchDelete(batchFilters: Array>, context?: ServiceBaseContext): Promise[]>; } export {};