UNPKG

@goatlab/fluent

Version:

Readable query Interface & API generator for TS and Node

113 lines (112 loc) 3.92 kB
import { Collection } from '@goatlab/js-utils'; import { AnyObject, FindByIdFilter, FluentBelongsToManyParams, FluentBelongsToParams, FluentHasManyParams, FluentQuery, Primitives, QueryFieldSelector, QueryOutput } from './types'; export declare abstract class BaseConnector<ModelDTO, InputDTO, OutputDTO> { protected outputKeys: string[]; protected relatedQuery?: { entity: new () => ModelDTO; query?: FluentQuery<ModelDTO>; repository?: any; key?: string; pivot?: any; }; protected chunk: null; protected pullSize: null; protected paginator: undefined; protected rawQuery: undefined; protected modelRelations: any; isMongoDB: boolean; constructor(); /** * * @param data */ insertMany(_data: InputDTO[]): Promise<OutputDTO[]>; /** * * @param id * @param data */ updateById(_id: string, _data: InputDTO): Promise<OutputDTO>; /** * * @param query */ findMany<T extends FluentQuery<ModelDTO>>(_query?: T): Promise<QueryOutput<T, ModelDTO>[]>; /** * Executes the findMany() method and * returns it's first result * * @return {Object} First result */ findFirst<T extends FluentQuery<ModelDTO>>(query?: T): Promise<QueryOutput<T, ModelDTO> | null>; requireById(id: string, q?: FindByIdFilter<ModelDTO>): Promise<QueryOutput<FindByIdFilter<ModelDTO>, ModelDTO>>; requireFirst<T extends FluentQuery<ModelDTO>>(query?: T): Promise<QueryOutput<T, ModelDTO>>; findByIds<T extends FindByIdFilter<ModelDTO>>(ids: string[], q?: T): Promise<QueryOutput<T, ModelDTO>[]>; findById<T extends FindByIdFilter<ModelDTO>>(id: string, q?: T): Promise<QueryOutput<T, ModelDTO> | null>; /** * * Gets the data in the current query and * transforms it into a collection * @returns {Collection} Fluent Collection */ collect(query: FluentQuery<ModelDTO>): Promise<Collection<OutputDTO>>; /** * Gets all values for a given KEY * @returns {Array} * @param path */ pluck(path: QueryFieldSelector<ModelDTO>, query?: FluentQuery<ModelDTO>): Promise<Primitives[]>; /** * Sets the relatedQuery param, to be used by the * different LOAD methods * @param r */ protected setRelatedQuery(r: { entity: new () => ModelDTO; query?: FluentQuery<ModelDTO>; repository?: any; key?: string; }): void; /** * Associate One-to-Many relationship. * Associate an object to the parent. * @param data */ associate(data: InputDTO | OutputDTO): Promise<OutputDTO[]>; /** * Attach an object with Many-to-Many relation * @param id */ attach(id: string, pivot?: AnyObject): Promise<any[]>; /** * One-to-Many relationship * To be used in the "parent" entity (One) */ protected hasMany<T extends FluentHasManyParams<T>>(r: T): InstanceType<T['repository']>; /** * Inverse One-to-Many relationship * To be used in the "children" entity (Many) */ protected belongsTo<T extends FluentBelongsToParams<T>>(r: T): InstanceType<T['repository']>; /** * One-to-One model relationship */ protected hasOne(): void; /** * Many-to-Many relationship * To be used in both of the Related models (excluding pivot) */ protected belongsToMany<T extends FluentBelongsToManyParams<T>>(r: T): InstanceType<T['repository']>; /** * */ protected hasManyThrough(): void; /** * Maps the given Data to show only those fields * explicitly detailed on the Select function * * @param {Array} data Data from local or remote DB * @returns {Array} Formatted data with the selected columns */ protected jsApplySelect(select: FluentQuery<ModelDTO>['select'], data: ModelDTO[]): ModelDTO[]; }