/** * @jest-environment node */ import { ModelInterface } from "./interfaces/model.interface"; import { FirestoreOrmRepository } from "./repository"; import { Query, LIST_EVENTS } from "./query"; import type { 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'; import type { CollectionReference, DocumentData, DocumentReference, DocumentSnapshot, FieldPath, OrderByDirection, WhereFilterOp } from 'firebase/firestore'; import type { UploadTask } from 'firebase/storage'; /** * Represents a base model for Firebase ORM. */ export declare class BaseModel implements ModelInterface { /** * The flag for the created_at field. */ protected static CREATED_AT_FLAG: string; /** * The flag for the updated_at field. */ protected static UPDATED_AT_FLAG: string; /** * The ID of the model. */ id: string; protected _referencePath: string; protected isAutoTime: boolean; created_at: any; updated_at: any; protected unlistenFunc: any; protected is_exist: boolean; protected currentModel: this & BaseModel; protected static aliasFieldsMapper: any; protected static reverseAliasFieldsMapper: 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; protected pathParams: Map; protected _createdViaGetModel: boolean; constructor(); /** * Initializes the properties of the model. */ initProp(): void; /** * Sets path parameters for the model. * Manages the pathParams map property that will be used in getPathList, etc. * * Supports two signatures: * 1. setPathParams(key: string, value: any) - Set a single parameter * 2. setPathParams(params: Record) - Set multiple parameters from an object * * @param keyOrParams - Either a parameter key (string) or an object with key-value pairs * @param value - The parameter value (only used when first argument is a string) * @returns The updated model instance */ setPathParams(keyOrParams: string | Record, value?: any): this; /** * Checks if instance query methods are allowed on this model. * Instance query methods should only be called on models created via getModel() or static methods. * @throws Error if instance query methods are not allowed */ protected checkInstanceQueryAllowed(): void; /** * Gets the current path parameters map. * @returns The pathParams Map */ getPathParams(): Map; /** * Static method to initialize a model with path parameters. * Provides a convenient way to set multiple path parameters at once. * * @template T - The type of the model * @param params - An object containing key-value pairs for path parameters * @returns A new instance of the model with path parameters set * * @example * // Simple usage with getAll() * const questions = await Question.initPathParams({ * 'course_id': courseId, * 'lesson_id': lessonId * }).getAll(); * * @example * // Chaining with where clause * const activeQuestions = await Question.initPathParams({ * 'course_id': courseId, * 'lesson_id': lessonId * }).where('status', '==', 'active').get(); * * @example * // Using query builder * const query = Question.initPathParams({ * 'course_id': courseId, * 'lesson_id': lessonId * }).query().where('difficulty', '>', 3).limit(10); */ static initPathParams(this: { new (): T; }, params: { [key: string]: any; }): T & BaseModel; /** * Alias for initPathParams - shorter and more ergonomic. * Static method to initialize a model with path parameters. * * @template T - The type of the model * @param params - An object containing key-value pairs for path parameters * @returns A new instance of the model with path parameters set * * @example * // Simple usage with getAll() * const questions = await Question.initPath({ * 'course_id': courseId, * 'lesson_id': lessonId * }).getAll(); * * @example * // Chaining with where clause * const activeQuestions = await Question.initPath({ * 'course_id': courseId, * 'lesson_id': lessonId * }).where('status', '==', 'active').get(); * * @example * // Using query builder and multiple chaining * const query = Question.initPath({ * 'course_id': courseId, * 'lesson_id': lessonId * }).query().where('difficulty', '>', 3).limit(10); */ static initPath(this: { new (): T; }, params: { [key: string]: any; }): T & BaseModel; /** * Parses the text indexing fields. * @param text - The text to parse. * @returns An array of parsed text indexing fields. */ parseTextIndexingFields(text: string): string[]; /** * Refreshes text indexing for all fields marked with is_text_indexing. * This method recreates the text index for fields that have values but missing text indices. */ refreshTextIndexing(): void; /** * Gets the ID of the object. * @returns The ID of the object. */ getId(): string; /** * Initializes the fields of the model. */ initFields(): void; /** * Checks if the model exists. * @returns True if the model exists, false otherwise. */ isExist(): boolean; /** * Gets one relation (legacy method - use loadBelongsTo instead). * @param model - The model to get the relation from. * @returns A promise that resolves to the related model. */ getOneRel(model: { new (): T; }): Promise; /** * Gets many relations (legacy method - use loadHasMany instead). * For backward compatibility, this method assumes the target model * has a foreign key field that matches this model's pathId. * @param model - The model to get the relations from. * @returns A promise that resolves to an array of related models. */ getManyRel(model: { new (): T; }): Promise>; /** * Load a belongsTo relationship * @param relationshipName - The name of the relationship property */ loadBelongsTo(relationshipName: string): Promise; /** * Load a hasOne relationship * @param relationshipName - The name of the relationship property */ loadHasOne(relationshipName: string): Promise; /** * Load a hasMany relationship * @param relationshipName - The name of the relationship property */ loadHasMany(relationshipName: string): Promise>; /** * Load a belongsToMany relationship * @param relationshipName - The name of the relationship property */ loadBelongsToMany(relationshipName: string): Promise>; /** * Load all defined relationships or specific ones */ loadWithRelationships(relationshipNames?: string[]): Promise; /** * Gets the model instance. * @param model - The model to get the instance of. * @returns The model instance. */ getModel(model: { new (): T; }): T & BaseModel; /** * Gets the current model instance. * @returns The current model instance. * @throws Error if modelType is not set */ getCurrentModel(): this; /** * Converts the model to a string. * @returns The model as a string. */ toString(): string; /** * Loads the model from a string. * @param jsonString - The string representation of the model. * @returns The loaded model. */ loadFromString(jsonString: string): this; /** * Initializes the object from a string. * @param jsonString - The string representation of the model. * @returns The initialized model. */ initFromString(jsonString: string): this; /** * Gets the repository reference for the model. * @returns The repository reference. */ getRepositoryReference(): DocumentReference | CollectionReference | null; /** * Gets the repository reference for the model (async version). * @returns The repository reference. */ getRepositoryReferenceAsync(): Promise | CollectionReference | null>; /** * Gets the document repository reference for the model. * @returns The document repository reference. */ getDocRepositoryReference(): DocumentReference | null; /** * Gets the document repository reference for the model (async version). * @returns The document repository reference. */ getDocRepositoryReferenceAsync(): Promise | null>; /** * Gets the document reference for the model. * @returns The document reference. */ getDocReference(): DocumentReference | null; /** * Gets the document reference for the model (async version). * @returns The document reference. */ getDocReferenceAsync(): Promise | null>; /** * Sets the model type. * @param model - The model type. * @returns The updated model instance. */ setModelType(model: any): this; /** * Gets the model type. * @returns The model type. */ getModelType(): any; /** * Creates a query with a where clause. * @param fieldPath - The field path to filter on. * @param opStr - The operator string. * @param value - The value to compare against. * @returns The query with the where clause. */ static where(this: { new (): T; }, fieldPath: string, opStr: WhereFilterOp, value: any): Query; /** * Creates a query with a where clause. * @param fieldPath - The field path to filter on. * @param opStr - The operator string. * @param value - The value to compare against. * @returns The query with the where clause. * @throws Error if called on a model not created via getModel() */ where(fieldPath: string, opStr: WhereFilterOp, value: any): Query; /** * Gets one document from the current query. * @returns A promise that resolves to the document. */ getOne(): Promise; /** * Sets the ID of the model. * @param id - The ID to set. * @returns The updated model instance. */ setId(id: string): this; /** * Loads the model with the specified ID. * @param id - The ID of the model to load. * @param params - Additional parameters for loading the model. * @returns A promise that resolves to the loaded model. */ load(id: string, params?: { [key: string]: string; }): Promise; /** * Initializes the model with the specified ID. * @param id - The ID of the model to initialize. * @param params - Additional parameters for initializing the model. * @returns A promise that resolves to the initialized model. */ init(id: string, params?: { [key: string]: string; }): Promise; /** * Initializes and loads the model with the specified ID. * Provides a simpler alternative to the `new Model(); await model.load(id)` pattern. * * @example * // Load a simple model * const user = await User.init(userId); * if (user) { * console.log(user.name); * } * * // Load a nested model with path parameters * const member = await Member.init(memberId, { website_id: websiteId }); * if (member) { * console.log(member.name); * } * * // For creating new instances, use the constructor * const newUser = new User(); * newUser.name = "John"; * await newUser.save(); * * @param id - The ID of the model to load. This parameter is required. * @param pathParams - Path parameters for nested collections (e.g., { website_id: 'abc123' }). * @returns A promise that resolves to the loaded model, or null if the model is not found. */ static init(this: { new (): T; }, id: string, pathParams?: { [key: string]: string; }): Promise<(T & BaseModel) | null>; /** * Removes the model from the database. * @returns A promise that resolves to true if the removal was successful, false otherwise. */ remove(): Promise; /** * Creates a query for the model. * @returns The query for the model. */ static query(this: { new (): T; }): Query; /** * Creates a collection query for the model. * @returns The collection query for the model. */ static collectionQuery(this: { new (): T; }): Query; /** * Creates a query for the model. * @returns The query for the model. * @throws Error if called on a model not created via getModel() */ query(): Query; /** * Gets the collection name for the model. * @returns The collection name. */ getCollectionName(): string; /** * Executes a full SQL query on Elasticsearch. * @param sql - The SQL query to execute. * @param limit - The maximum number of results to return. * @param filters - Additional filters to apply to the query. * @param cursor - The cursor for pagination. * @param columns - The columns to include in the result. * @param asObject - Whether to return the result as an object or not. * @returns A promise that resolves to the Elasticsearch SQL response. */ static elasticFullSql(this: { new (): T; }, sql?: string, limit?: number, filters?: any, cursor?: any, columns?: any, asObject?: boolean): Promise; /** * Escapes special characters in a string for SQL queries. * @param str - The string to escape. * @returns The escaped string. */ escapeStringSql(str: string): any; /** * Parses a value into a SQL string representation. * * @param value - The value to be parsed. * @returns The SQL string representation of the value. */ parseValueSql(value: any): string; /** * Executes an Elasticsearch SQL query. * * @template T - The type of the model. * @param {string | any} whereSql - The SQL query or an array containing the query and its parameters. * @param {number} [limit] - The maximum number of results to return. * @param {any} [filters] - Additional filters to apply to the query. * @param {any} [cursor] - The cursor for pagination. * @param {any} [columns] - The columns to select in the query. * @param {boolean} [asObject=true] - Indicates whether to return the result as an object or an array. * @param {boolean} [asCount=false] - Indicates whether to return the count of the result. * @returns {Promise} A promise that resolves to the result of the Elasticsearch SQL query. */ static elasticSql(this: { new (): T; }, whereSql?: string | any, limit?: number, filters?: any, cursor?: any, columns?: any, asObject?: boolean, asCount?: boolean): Promise; /** * Retrieves all documents of a specific model type from Firestore. * * @template T - The type of the model. * @param {Array} [whereArr] - An array of where conditions to filter the documents. * @param {{ fieldPath: string | FieldPath; directionStr?: OrderByDirection; }} [orderBy] - The field to order the documents by and the direction of the ordering. * @param {number} [limit] - The maximum number of documents to retrieve. * @param {{ [key: string]: string }} [params] - Additional parameters for the query. * @returns {Promise>} - A promise that resolves to an array of documents of the specified model type. */ static getAll(this: { new (): T; }, whereArr?: Array, orderBy?: { fieldPath: string | FieldPath; directionStr?: OrderByDirection; }, limit?: number, params?: { [key: string]: string; }): Promise>; /** * Retrieves all the records from the database that match the specified conditions. * * @param whereArr - An optional array of conditions to filter the records. * @param orderBy - An optional object specifying the field to order the records by and the direction of the ordering. * @param limit - An optional number specifying the maximum number of records to retrieve. * @param params - An optional object containing additional parameters for the query. * @returns A promise that resolves to an array of records. * @throws Error if called on a model not created via getModel() */ getAll(whereArr?: Array, orderBy?: { fieldPath: string | FieldPath; directionStr?: OrderByDirection; }, limit?: number, params?: { [key: string]: string; }): Promise>; /** * Returns the repository associated with this model. * @returns The repository instance. */ getRepository(): FirestoreOrmRepository; /** * Sets the repository for the model. * * @param repository - The repository to set. * @returns The updated model instance. */ 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; /** * Listens for changes on the current object and invokes the provided callback function. * @param callback - The callback function to be invoked when the object changes. * @returns A function that can be used to stop listening for changes. */ listen(callback?: CallableFunction): any; /** * Stops listening for changes on the model. * @returns {any} The result of the unlisten function, or `false` if there is no unlisten function. */ unlisten(): any; /** * Creates an instance of the current model from a Firestore DocumentSnapshot. * * @param doc - The DocumentSnapshot containing the data. * @returns A Promise that resolves to an instance of the current model. */ createFromDoc(doc: DocumentSnapshot): Promise; /** * Creates an instance of the model from a Firestore DocumentSnapshot. * * @template T - The type of the model. * @param {DocumentSnapshot} doc - The Firestore DocumentSnapshot. * @returns {Promise} - A promise that resolves to the created model instance. */ static createFromDoc(this: { new (): T; }, doc: DocumentSnapshot): Promise; static createFromDocRef(this: { new (): T; }, doc: DocumentReference): Promise; createFromDocRef(this: { new (): T; }, doc: DocumentReference): Promise; createFromData(data: Object, targetObject?: this): this; getOriginName(key: string): string; initFromData(data: Object, targetObject?: this): this; initFromDoc(doc: 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. * @throws Error if called on a model not created via getModel() */ 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. * @throws Error if called on a model not created via getModel() */ 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. * @throws Error if called on a model not created via getModel() */ onList(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. * @throws Error if called on a model not created via getModel() */ 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. * @throws Error if called on a model not created via getModel() */ 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; format(field: string, format: string): any; moment(field: string): any; date(field: string): Date; initAutoTime(): void; makeId(length: number): string; getStorageFile(target: string): Promise; initUpdateTask(uploadTask: UploadTask, target: string, onProcessingCallback?: any, onErrorCallback?: any, onFinishCallback?: any): Promise; getCreatedAt(): Moment | null; getUpdatedAt(): Moment | null; save(customId?: string): Promise; /** * Alias for save() - Persists the current instance to the database. * Common alias used in many ORM frameworks for creating new records. * * @param {string} [customId] - Optional custom ID for the document. * @returns {Promise} A promise that resolves to the current instance after creation. */ create(customId?: string): Promise; /** * Alias for save() - Updates the current instance in the database. * Common alias used in many ORM frameworks for updating existing records. * * @param {Partial} [updateData] - Optional data to update the instance with before saving. * @returns {Promise} A promise that resolves to the current instance after update. */ update(updateData?: Partial): Promise; /** * Alias for remove() - Destroys the current instance in the database. * Common alias used in many ORM frameworks. * * @returns {Promise} A promise that resolves to true if the destruction was successful. */ destroy(): Promise; /** * Alias for remove() - Deletes the current instance from the database. * Common alias used in many ORM frameworks. * * @returns {Promise} A promise that resolves to true if the deletion was successful. */ delete(): Promise; getReferencePath(): string; getDocRefPath(): Promise; /** * Initializes an instance of the model by retrieving data from a specified reference path. * @param path - The reference path to retrieve the data from. * @returns A promise that resolves to an instance of the model with the retrieved data, or null if the reference path is not provided or the repository is not available. */ static initByRef(this: { new (): T; }, path?: string): Promise; /** * Finds and retrieves an array of objects that match the specified criteria. * * @template T - The type of the objects to be retrieved. * @param {string} fieldPath - The field path to filter on. * @param {WhereFilterOp} opStr - The comparison operator. * @param {any} value - The value to compare against. * @returns {Promise>} - A promise that resolves to an array of objects that match the specified criteria. */ static find(this: { new (): T; }, fieldPath: string, opStr: WhereFilterOp, value: any): Promise>; /** * Finds a single document in the collection that matches the specified criteria. * * @template T - The type of the document to be returned. * @param {string} fieldPath - The field path to query on. * @param {WhereFilterOp} opStr - The operator to use for the query. * @param {any} value - The value to compare against. * @returns {Promise} A promise that resolves to the matching document, or null if no document is found. */ static findOne(this: { new (): T; }, fieldPath: string, opStr: WhereFilterOp, value: any): Promise; /** * Alias for getAll() - Gets all documents from the collection. * Common alias used in many ORM frameworks. * * @template T - The type of the document to be returned. * @param {Array} [whereArr] - An array of where conditions. * @param {{ fieldPath: string | FieldPath; directionStr?: OrderByDirection }} [orderBy] - The ordering specification. * @param {number} [limit] - The maximum number of documents to retrieve. * @param {{ [key: string]: string }} [params] - Additional parameters for the query. * @returns {Promise>} - A promise that resolves to an array of documents. */ static all(this: { new (): T; }, whereArr?: Array, orderBy?: { fieldPath: string | FieldPath; directionStr?: OrderByDirection; }, limit?: number, params?: { [key: string]: string; }): Promise>; /** * Alias for findOne() - Finds the first document that matches the specified criteria. * Common alias used in many ORM frameworks. * * @template T - The type of the document to be returned. * @param {string} fieldPath - The field path to query on. * @param {WhereFilterOp} opStr - The operator to use for the query. * @param {any} value - The value to compare against. * @returns {Promise} A promise that resolves to the first matching document, or null if no document is found. */ static first(this: { new (): T; }, fieldPath: string, opStr: WhereFilterOp, value: any): Promise; /** * Creates a new instance of the model with the given data and saves it to the database. * Common alias used in many ORM frameworks. * * @template T - The type of the document to be created. * @param {Partial} data - The data to populate the new instance with. * @param {string} [customId] - Optional custom ID for the document. * @returns {Promise} A promise that resolves to the created and saved instance. */ static create(this: { new (): T; }, data: Partial, customId?: string): Promise; /** * Updates documents in the collection that match the specified criteria. * Common alias used in many ORM frameworks. * * @template T - The type of the document to be updated. * @param {string} fieldPath - The field path to query on. * @param {WhereFilterOp} opStr - The operator to use for the query. * @param {any} value - The value to compare against. * @param {Partial} updateData - The data to update the matching documents with. * @returns {Promise>} A promise that resolves to an array of updated documents. */ static update(this: { new (): T; }, fieldPath: string, opStr: WhereFilterOp, value: any, updateData: Partial): Promise>; /** * Alias for find() followed by remove() - Destroys documents that match the specified criteria. * Common alias used in many ORM frameworks. * * @template T - The type of the document to be destroyed. * @param {string} fieldPath - The field path to query on. * @param {WhereFilterOp} opStr - The operator to use for the query. * @param {any} value - The value to compare against. * @returns {Promise} A promise that resolves to true if all documents were successfully destroyed. */ static destroy(this: { new (): T; }, fieldPath: string, opStr: WhereFilterOp, value: any): Promise; /** * Finds documents in the collection that match the specified criteria. * * @param fieldPath - The field path to filter on. * @param opStr - The comparison operator. * @param value - The value to compare against. * @returns A promise that resolves to an array of documents that match the criteria. * @throws Error if called on a model not created via getModel() */ find(fieldPath: string, opStr: WhereFilterOp, value: any): Promise>; /** * Retrieves a snapshot of the document associated with this model. * @returns A promise that resolves with the document snapshot. */ getSnapshot(): Promise; /** * Finds a single document in the collection that matches the specified criteria. * * @param fieldPath - The field path to query on. * @param opStr - The comparison operator. * @param value - The value to compare against. * @returns A promise that resolves to the found document or null if no document is found. * @throws Error if called on a model not created via getModel() */ findOne(fieldPath: string, opStr: WhereFilterOp, value: any): Promise; /** * Retrieves the required fields for the model. * @returns An array of strings representing the required fields. */ getRequiredFields(): Array; /** * Verifies if all the required fields of the model have values. * @returns {boolean} Returns true if all the required fields have values, otherwise returns false. * @throws {Error} If throw_on_required_field_null is enabled and a required field is null */ verifyRequiredFields(): boolean; /** * Retrieves the field name for the given key. * If an aliasFieldsMapper is defined and it contains a mapping for the key, the mapped field name is returned. * Otherwise, the key itself is returned as the field name. * * @param key - The key for which to retrieve the field name. * @returns The field name corresponding to the key. */ getFieldName(key: string): string; /** * Returns the alias name for the given key. * If a reverse alias fields mapper is defined and the key exists in the mapper, the corresponding alias name is returned. * Otherwise, the key itself is returned. * * @param key - The key for which to retrieve the alias name. * @returns The alias name for the given key. */ getAliasName(key: string): string; /** * Retrieves the document data as an object. * * @param useAliasName - Indicates whether to use the alias name for field names. * @returns An object containing the document data. */ getDocumentData(useAliasName?: boolean): Object; /** * Copies the properties from the given object to the current object. * Only copies properties that are defined in the given object. * * @param object - The object from which to copy the properties. */ copy(object: this): void; /** * Alias of getDocumentData */ getData(useAliasName?: boolean): Object; /** * Retrieves the path list for the current model instance. * The path list is an array of objects, where each object represents a segment of the path. * Each object has a `type` property indicating whether it's a "collection" or "document", * and a `value` property containing the corresponding path segment value. * If any path segment is missing, it returns `false`. * * @returns An array of objects representing the path segments, or `false` if any segment is missing. */ getPathList(): Array<{ type: string; value: string; }> | boolean; /** * Initializes the path of the model from a string. * @param path - The string representing the path. */ initPathFromStr(path: string): void; /** * Retrieves the parameters required for constructing the path list. * @returns An object containing the path list parameters. */ getPathListParams(): any; /** * Returns an array of keys extracted from the reference path. * @returns An array of string keys. */ getPathListKeys(): Array; /** * Returns an array of objects containing the keys and positions of the path list. * @returns An array of objects with `key` and `pos` properties. */ getPathListKeysWithPos(): Array<{ key: string; pos: number; }>; /** * Converts the model instance to a JSON object. * @returns The JSON representation of the model instance. */ toJSON(): Object; }