import { firestore } from 'firebase-admin'; import { IDocumentRef } from './field.types'; import { Query } from '..'; export interface IEntity { id: string; ref: IDocumentRef; toData(): Record; } export interface IQuery { where(property: keyof T, op: FirebaseFirestore.WhereFilterOp, value: any): IQuery; orderBy(property: keyof T, sort?: FirebaseFirestore.OrderByDirection): IQuery; limit(amount: number): IQuery; startAt(...fieldValues: any[]): IQuery; startAfter(...fieldValues: any[]): Query; endAt(...fieldValues: any[]): Query; endBefore(...fieldValues: any[]): Query; onSnapshot(onNext: (snapshot: IQuerySnapshot) => void, onError?: (error: Error) => void): (() => void); get(): Promise>; } export interface IQuerySnapshot { docs: T[]; size: number; empty: boolean; query: IQuery; forEach: (callback: ((doc: T, index: number) => void)) => void; docChanges: () => DocumentChange[]; } export interface IDocumentSnapshot { doc: T; exists: boolean; ref: IDocumentRef; } export interface ICollection { native: firestore.CollectionReference; path: string; parent?: IDocumentRef

| null; query: () => IQuery; create: (entity: T) => Promise; update: (entity: T) => Promise; doc: (id: string) => IDocumentRef; get: (id: string) => Promise; find: (query?: ICollectionQuery) => Promise; remove: (id: string) => Promise; } export interface ICollectionGroup { native: firestore.CollectionGroup; id: string; query: () => IQuery; get: (id: string) => Promise; find: (query?: ICollectionQuery) => Promise; remove: (id: string) => Promise; } export interface DocumentChange { doc: T; type: firestore.DocumentChangeType; newIndex: number; oldIndex: number; } export interface ICollectionConfig { name: string; } declare type WhereQuery = [ keyof T, FirebaseFirestore.WhereFilterOp, any ]; declare type OrderByQuery = [ keyof T, FirebaseFirestore.OrderByDirection? ]; declare type StartAtQuery = T | any; declare type StartAfterQuery = T | any; declare type EndAtQuery = T | any; declare type EndBeforeQuery = T | any; export interface ICollectionQuery { where?: WhereQuery[]; orderBy?: OrderByQuery[]; limit?: number; startAt?: StartAtQuery; startAfter?: StartAfterQuery; endAt?: EndAtQuery; endBefore?: EndBeforeQuery; } export interface ISubCollectionConfig extends ICollectionConfig { entity: new () => IEntity; } export {};