UNPKG

@avonjs/avonjs

Version:

A fluent Node.js API generator.

71 lines (70 loc) 2.13 kB
import { Collection } from 'collect.js'; import { type AnyArray, type CollectionRecord, type PrimaryKey, type SearchCollection, type Searchable, type Where } from '../Contracts'; import { Fluent } from '../Models'; import Repository from './Repository'; export default abstract class CollectionRepository extends Repository<Fluent> { /** * Resolve items from the store path. */ protected resolveItems(): Array<CollectionRecord>; /** * Prepare given items for collection. */ protected prepareItems(items: AnyArray): Fluent[]; /** * Search storage for given query string. */ search(search: string, page?: number, perPage?: number): Promise<SearchCollection<Fluent>>; /** * Find all model's for the given conditions. */ all(wheres?: Where[]): Promise<Fluent[]>; /** * Search collection for given query string. */ protected searchCollection(search?: string): Collection<Fluent>; /** * Get the collection with applied constraints. */ protected getCollection(): Collection<Fluent>; /** * Make collection from entire data. */ protected makeCollection(): Collection<Fluent>; /** * Apply the where constraint on the collection item. */ protected checkAgainstWhere(item: Fluent, where: Where): boolean; /** * Perform searches on the given item. */ protected performSearch(item: Fluent, search: string): boolean; /** * Store given model into the storage. */ store(model: Fluent): Promise<Fluent>; /** * Find first model for the given conditions. */ first(wheres?: Where[]): Promise<Fluent>; /** * Store given model into the storage. */ update(model: Fluent): Promise<Fluent>; /** * Delete model for the given key. */ delete(key: PrimaryKey): Promise<void>; /** * Create new instance of model. */ model(): Fluent; /** * Generate new id for storing item. */ newId(): PrimaryKey; /** * Get key name of the item. */ abstract searchableColumns(): Searchable[]; }