/** * @jest-environment node */ import 'firebase/firestore'; import { ModelInterface } from "./interfaces/model.interface"; import { FirestoreOrmRepository } from "./repository"; import * as firebase from "firebase/app"; import 'firebase/firestore'; import { Query, LIST_EVENTS } from "./query"; import { Moment } from "moment"; import { StorageReference } from "./interfaces/storage.file.reference.interface"; import { ElasticWhereSqlResponse } from "./interfaces/elastic.where.sql.response.interface"; import { ElasticSqlResponse } from "./interfaces/elastic.sql.response.interface"; import { ModelAllListOptions } from './interfaces/model.alllist.options.interface'; /** * Base model orm application */ export declare class BaseModel implements ModelInterface { protected static CREATED_AT_FLAG: string; protected static UPDATED_AT_FLAG: string; id: string; referencePath: string; protected _referencePath: string; protected isAutoTime: boolean; createdAt: any; updatedAt: any; protected unlistenFunc: any; protected is_exist: boolean; pathId: string; protected currentModel: this & BaseModel; protected static aliasFieldsMapper: any; protected static textIndexingFields: any; protected static ignoreFields: any; protected static fields: any; protected static requiredFields: Array; protected static internalFields: Array; protected repository: FirestoreOrmRepository; protected globalModel: this; protected currentQuery: any; protected data: any; protected currentQueryListener: any; protected modelType: any; constructor(); /** * Init properties */ initProp(): void; /** * Parse text indexing fields * @param text : string */ parseTextIndexingFields(text: string): string[]; /** * Get object id */ getId(): string; /** * Get path id */ getPathId(): string; /** * Init fields */ initFields(): void; /** * Init exist */ isExist(): boolean; /** * Get one relation * @param model */ getOneRel(model: { new (): T; }): Promise; /** * Get many relation */ getManyRel(model: { new (): T; }): Promise>; getModel(model: { new (): T; }): T & BaseModel; getCurrentModel(): this; toString(): string; /** * load from string * @return fields array */ loadFromString(jsonString: string): this; /** * Init object from string * @return fields array */ initFromString(jsonString: string): this; getReference(): firebase.firestore.CollectionReference; getDocReference(): firebase.firestore.DocumentReference; setModelType(model: any): this; getModelType(): any; static where(this: { new (): T; }, fieldPath: string, opStr: firebase.firestore.WhereFilterOp, value: any): Query; where(this: { new (): T; }, fieldPath: string, opStr: firebase.firestore.WhereFilterOp, value: any): Query; getOne(): Promise; setId(id: string): this; load(id: string, params?: { [key: string]: string; }): Promise; init(id: string, params?: { [key: string]: string; }): Promise; static init(this: { new (): T; }, id: string, params?: { [key: string]: string; }): Promise; remove(): Promise; static query(this: { new (): T; }): Query; query(): Query; getCollectionName(): string; static elasticFullSql(this: { new (): T; }, sql?: string, limit?: number, filters?: any, cursor?: any, columns?: any, asObject?: boolean): Promise; escapeStringSql(str: string): any; parseValueSql(value: any): string; static elasticSql(this: { new (): T; }, whereSql?: string | any, limit?: number, filters?: any, cursor?: any, columns?: any, asObject?: boolean, asCount?: boolean): Promise; static getAll(this: { new (): T; }, whereArr?: Array, orderBy?: { fieldPath: string | firebase.firestore.FieldPath; directionStr?: firebase.firestore.OrderByDirection; }, limit?: number, params?: { [key: string]: string; }): Promise>; getAll(whereArr?: Array, orderBy?: { fieldPath: string | firebase.firestore.FieldPath; directionStr?: firebase.firestore.OrderByDirection; }, limit?: number, params?: { [key: string]: string; }): Promise>; getRepository(): FirestoreOrmRepository; setRepository(repository: FirestoreOrmRepository): this; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ on(callback: CallableFunction): CallableFunction; listen(callback?: CallableFunction): any; unlisten(): any; sql(sql: string, asObject?: boolean, isInsideQuery?: boolean): Promise>; onSql(sql: string, callback: CallableFunction, asObject?: boolean, isInsideQuery?: boolean): void; createFromDoc(doc: firebase.firestore.DocumentSnapshot): Promise; static createFromDoc(this: { new (): T; }, doc: firebase.firestore.DocumentSnapshot): Promise; static createFromDocRef(this: { new (): T; }, doc: firebase.firestore.DocumentReference): Promise; createFromDocRef(this: { new (): T; }, doc: firebase.firestore.DocumentReference): Promise; createFromData(data: Object, targetObject?: this): this; getOriginName(key: string): string | null; initFromData(data: Object, targetObject?: this): this; initFromDoc(doc: firebase.firestore.DocumentSnapshot): this; /** * Set document data directly * @param key * @param value */ setParam(key: string, value: any): this; /** * Get document data directly * @param key * @param value */ getParam(key: string, defaultValue: any): any; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ static onAllList(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ onAllList(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ onModeList(options: ModelAllListOptions): any; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ static onModeList(options: ModelAllListOptions): any; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ static onList(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ onList(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ static onListLegacy(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ onListLegacy(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Get New element in collectio * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ static onCreatedList(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Get New element in collectio * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ onCreatedList(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Get Updated element in collectio * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ onUpdatedList(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; /** * Get Updated element in collectio * Attaches a listener for QuerySnapshot events. You may either pass * individual `onNext` and `onError` callbacks or pass a single observer * object with `next` and `error` callbacks. The listener can be cancelled by * calling the function that is returned when `onSnapshot` is called. * * NOTE: Although an `onCompletion` callback can be provided, it will * never be called because the snapshot stream is never-ending. * * @param callback A single object containing `next` and `error` callbacks. * @return An unsubscribe function that can be called to cancel * the snapshot listener. */ static onUpdatedList(callback: CallableFunction, eventType?: LIST_EVENTS): CallableFunction; initAutoTime(): void; makeId(length: number): string; getStorageFile(target: string): StorageReference; initUpdateTask(uploadTask: firebase.storage.UploadTask, target: string, onProcessingCallback?: any, onErrorCallback?: any, onFinishCallback?: any): Promise<{}>; getCreatedAt(): Moment | null; getUpdatedAt(): Moment | null; save(): Promise; getReferencePath(): string; static find(this: { new (): T; }, fieldPath: string, opStr: firebase.firestore.WhereFilterOp, value: any): Promise>; static findOne(this: { new (): T; }, fieldPath: string, opStr: firebase.firestore.WhereFilterOp, value: any): Promise; find(fieldPath: string, opStr: firebase.firestore.WhereFilterOp, value: any): Promise>; getSnapshot(): Promise; findOne(fieldPath: string, opStr: firebase.firestore.WhereFilterOp, value: any): Promise; getRequiredFields(): Array; verifyRequiredFields(): boolean; getFieldName(key: string): string; getDocumentData(): Object; copy(object: this): void; /** * Alias of getDocumentData */ getData(): Object; getPathList(): Array<{ type: string; value: string; }> | boolean; getPathListParams(): any; getPathListKeys(): Array; }