zeroant-common
Version:
Common modules for zeroant
42 lines (41 loc) • 2.51 kB
TypeScript
import { RedisPlugin } from '../plugins/redis.plugin.js';
import { type ModelFactory } from 'zeroant-factory/model.factory';
import { WorkerFactory, type WorkerFactoryConstructor } from 'zeroant-factory/worker.factory';
import { PaginationDto } from '../dto/pagination.dto.js';
import { type IPaginationResult } from '../interfaces/pagination.interface.js';
import { PubSocket } from '../plugins/pubSocket.plugin.js';
import { type ZeroantContext } from 'zeroant-factory/zeroant.context';
import { type PrismaClient } from '@prisma/client';
import { type Config } from 'zeroant-config';
export type ServiceImplementSerializer<T, R extends ModelFactory> = (entity: T) => R;
export declare abstract class ServiceImplement<T extends keyof PrismaClient, R extends ModelFactory, Entity> {
#private;
protected repoName: T;
protected Model: new () => R;
protected pk: keyof Entity;
protected queue: WorkerFactory<R, any>;
protected state: RedisPlugin;
protected socket: PubSocket<any>;
constructor(repoName: T, Model: new () => R, pk: keyof Entity);
getRepo(): Promise<PrismaClient[T]>;
isNumber<T>(value: any, yes: T, no: T): T;
get serializer(): ServiceImplementSerializer<Entity, R>;
useQueue(queue: WorkerFactory<R, any>): this;
useState(state: RedisPlugin): this;
useSocket(socket: PubSocket<any>): this;
get hasSocket(): boolean;
get hasState(): boolean;
get hasQueue(): boolean;
ensureState(): void;
ensureQueue(): void;
ensureSocket(): void;
serializeMany: (entities: Entity[]) => R[];
makeFindBy: (key: keyof Entity) => (value: number | string, include?: Record<string, any>) => Promise<R | null>;
makeFindByFields: (pk: keyof Entity, ...keys: Array<keyof Entity>) => (value: number | string, include?: Record<string, any>) => Promise<R | null>;
findBy(key: keyof Entity, value: number | string, ...keys: Array<keyof Entity>): Promise<R | null>;
findByAnd(key: keyof Entity, value: number | string, ...keys: Array<keyof Entity>): Promise<R | null>;
findByPk: (value: number | string, include?: Record<string, any>) => Promise<R | null>;
list: <T_1, Relation>(pagination?: PaginationDto<T_1, Relation> | undefined) => Promise<IPaginationResult<R>>;
protected static _from<T>(zeroant: ZeroantContext<Config>, Service: new () => T, workerClass?: WorkerFactoryConstructor<any>): T;
findByIdOrRef: <Input>(id: string | number, userRef?: string, include?: Input | undefined) => Promise<R | null>;
}