import type Connection from './Connection'; import type { BuildForeignKeyDefinitionsResult, DocumentData } from './Document'; import type LogHandler from './LogHandler'; import { type Filter, type QueryConstructorOptions } from './Query'; import type Schema from './Schema'; import type { FlattenDocument, InferModelObject, SchemaDefinition } from './Schema'; import type { SchemaTypeDefinitionNumber } from './schemaType'; import type { DbServerDelimiters, DbSubroutineInputIncrementOperation, DbSubroutineUserDefinedOptions, Remap } from './types'; export interface ModelConstructorOptions { _id?: string | null; __v?: string | null; data?: DocumentData; record?: string; } export type ModelConstructor = ReturnType>; export type Model = InstanceType>; type RequiredModelMetaProperties = '_id' | '__v'; /** Used as an intersection type to make specific model properties required */ export type RequiredModelMeta = { [K in RequiredModelMetaProperties]: NonNullable[K]>; }; /** * An intersection type that combines the `Model` class instance with the * inferred shape of the model object based on the schema definition. */ export type ModelCompositeValue = Remap & InferModelObject>; export interface ModelFindAndCountResult { /** Number of documents returned */ count: number; /** Model instances for the returned documents */ documents: ModelCompositeValue[]; } export interface ModelIncrementResult { originalDocument: ModelCompositeValue; updatedDocument: ModelCompositeValue; } export interface ModelDatabaseExecutionOptions { userDefined?: DbSubroutineUserDefinedOptions; requestId?: string; /** Maximum allowed return payload size in bytes */ maxReturnPayloadSize?: number; } export type ModelDeleteByIdOptions = ModelDatabaseExecutionOptions; export type ModelFindOptions = QueryConstructorOptions & ModelDatabaseExecutionOptions; export interface ModelFindByIdOptions extends ModelDatabaseExecutionOptions { /** Array of projection properties */ projection?: string[]; } export interface ModelIncrementOptions extends ModelDatabaseExecutionOptions { /** * Number of retries to perform when record is locked * @defaultValue 5 */ retry?: number; /** * Delay between retries in seconds when record is locked * @defaultValue 1 */ retryDelay?: number; } export type IncrementOperation = TSchema extends Schema ? { path: Extract, string>; value: number; } : never; export type ModelReadFileContentsByIdOptions = ModelDatabaseExecutionOptions; export type ModelSaveOptions = ModelDatabaseExecutionOptions; export type ModelCheckForRecordLockByIdOptions = ModelDatabaseExecutionOptions; /** Define a new model */ declare const compileModel: (connection: Connection, schema: TSchema, file: string, dbServerDelimiters: DbServerDelimiters, logHandler: LogHandler) => { new (options: ModelConstructorOptions): { [key: string]: unknown; /** Document version hash */ readonly __v: string | null; /** Id of model instance */ _id: string | null; /** Original record string that model was generated from */ readonly _originalRecordString: string | null; /** Private id tracking property */ "__#2@#_id": string | null; /** Save a document to the database */ save(options?: ModelSaveOptions): Promise>; /** Convert model instance to multivalue string */ "__#2@#convertToMvString"(): string; /** Validate the model instance */ "__#2@#validate"(): asserts this is { _id: string; }; /** Build a list of foreign key definitions to be used by the database for foreign key validation */ "__#2@#buildForeignKeyDefinitions"(): BuildForeignKeyDefinitionsResult[]; _raw: TSchema extends Schema> ? never : import("./types").MvRecord; _transformationErrors: import("./errors").TransformDataError[]; readonly "__#1@#schema": TSchema; "__#1@#record": import("./types").MvRecord; readonly "__#1@#isSubdocument": boolean; transformDocumentToRecord(): import("./types").MvRecord; buildForeignKeyDefinitions(): BuildForeignKeyDefinitionsResult[]; validate(): Map; "__#1@#transformRecordToDocument"(): void; }; /** Connection instance which constructed this model definition */ readonly connection: Connection; /** Database file this model acts against */ readonly file: string; /** Schema that defines this model */ readonly schema: TSchema; /** Log handler instance used for diagnostic logging */ readonly "__#2@#logHandler": LogHandler; /** Database server delimiters */ readonly "__#2@#dbServerDelimiters": DbServerDelimiters; /** * Check to see if a record is locked by another user/process * @returns `true` when record is locked */ checkForRecordLockById(id: string, options?: ModelCheckForRecordLockByIdOptions): Promise; /** Delete a document */ deleteById(id: string, options?: ModelDeleteByIdOptions): Promise | null>; /** Find documents via query */ find(selectionCriteria?: Filter, options?: ModelFindOptions): Promise[]>; /** Find documents via query, returning them along with a count */ findAndCount(selectionCriteria?: Filter, options?: ModelFindOptions): Promise>; /** Find a document by its id */ findById(id: string, options?: ModelFindByIdOptions): Promise | null>; /** Find multiple documents by their ids */ findByIds(ids: string | string[], options?: ModelFindByIdOptions): Promise<(ModelCompositeValue | null)[]>; /** * Increment fields in a document by values * @throws {Error} if schema is not defined * @throws {Error} if no result is returned from increment operation */ increment(id: string, operations: IncrementOperation[], options?: ModelIncrementOptions): Promise>; /** Read a DIR file type record directly from file system as Base64 string by its id */ readFileContentsById(id: string, options?: ModelReadFileContentsByIdOptions): Promise; /** Create a new Model instance from a record string */ "__#2@#createModelFromRecordString"(recordString: string, _id: string, __v?: string | null): ModelCompositeValue; /** Format projection option */ "__#2@#formatProjection"(projection?: string[]): number[] | null; /** * Format increment operations to be sent to the database */ "__#2@#formatIncrementOperations"(operations: IncrementOperation[]): DbSubroutineInputIncrementOperation[]; createSubdocumentFromRecord(schema: TSchema_1, record: import("./types").MvRecord): import("./Document").DocumentCompositeValue; createSubdocumentFromData(schema: TSchema_1, data: DocumentData): import("./Document").DocumentCompositeValue; createDocumentFromRecordString(schema: TSchema_1, recordString: string, dbServerDelimiters: DbServerDelimiters): import("./Document").DocumentCompositeValue; convertMvStringToArray(recordString: string, dbServerDelimiters: DbServerDelimiters): import("./types").MvRecord; }; export default compileModel;