import 'reflect-metadata'; import { Job } from 'node-schedule'; import crypto from 'node:crypto'; import { CacheManager } from './util/cacheManager'; declare var models: { name: string; model: any; }[]; export { models }; import { NexormConfig, NexormConfigType } from '../types/config'; /** * @name AllowNull * @description This decorator is used to define a column in the database. * @example @AllowNull * @public * @returns {void} */ export declare function AllowNull(target: any, key: string): void; /** * @name UUID * @description This decorator is used to define a column in the database. * @example @UUID(4) * @public * @param v * @returns {Function} */ export declare function UUID(v?: 1 | 4 | 6 | 7 | { v1?: boolean; v3?: { namespace: string; name: string; }; v4?: boolean; v5?: { namespace: string; name: string; }; v6?: boolean; v7?: boolean; }): Function; /** * @name Enum * @description This decorator is used to define a column in the database. * @example @Enum * @public * @param values * @returns {Function} */ export declare function Enum(values: any[]): Function; /** * @name AutoIncrement * @description This decorator is used to define a column in the database. * @example @AutoIncrement * @public * @returns {void} */ export declare function AutoIncrement(target: any, key: string): void; /** * @name Default * @description This decorator is used to define a column in the database. * @example @Default * @public * @param value * @returns {Function} */ export declare function Default(value: any): Function; /** * @name Required * @description This decorator is used to define a column in the database. * @example @Required * @public * @returns {void} */ export declare function Required(target: any, key: string): void; /** * @name Unique * @description This decorator is used to define a column in the database. * @example @Unique * @public * @returns {void} */ export declare function Unique(target: any, key: string): void; /** * @name Index * @description This decorator is used to define a column in the database. * @example @Index * @public * @returns {void} */ export declare function Index(target: any, key: string): void; /** * @name PrimaryKey * @description This decorator is used to define a column in the database. * @example @PrimaryKey * @public * @returns {void} */ export declare function PrimaryKey(target: any, key: string): void; /** * @name ForeignKey * @description This decorator is used to define a foreign key in the database. * @example @ForeignKey * @public * @param target * @param key * @returns {void} * @throws {Error} **/ export declare function ForeignKey(relatedModel: () => any): Function; /** * @name Comment * @description This decorator is used to define a column in the database. * @example @Comment * @public * @param comment * @returns {Function} */ export declare function Comment(comment: string): Function; /** * @name Hash * @description This decorator is used to define a column in the database. * @example @Hash * @public * @param method * @param digest * @returns {Function} */ export declare function Hash(method: string, digest?: crypto.BinaryToTextEncoding): Function; /** * @name Encrypt * @description This decorator is used to define a column in the database. * @example @Encrypt * @public * @param method * @param cipherKey * @param iv * @returns {Function} * @throws {Error} */ export declare function Encrypt(method: string, cipherKey: string, iv: string): Function; /** * @name Decrypt * @description This decorator is used to define a column in the database. * @example @Decrypt * @public * @param method * @param cipherKey * @param iv * @returns {Function} * @throws {Error} */ export declare function Decrypt(method: string, cipherKey: string, iv: string): Function; /** * @name Reference * @description This decorator is used to define a column in the database. * @example @Reference * @public * @param value * @returns {Function} */ export declare function Reference(value: { model: string | string[]; key: string; }): Function; /** * @description * @default * { * $onDelete: 'CASCADE', * $onUpdate: 'CASCADE' * } */ export interface RelationshipOneToManyOptions { $as?: string; $constraints?: boolean; $foreignKey?: string; $foreignKeyConstraint?: boolean; $hooks?: boolean; $keyType?: any; $onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION'; $onUpdate?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION'; $sourceKey?: string; } export interface RelationshipOneToOneOptions { $as?: string; $constraints?: boolean; $foreignKey?: string | object; $foreignKeyConstraint?: boolean; $hooks?: boolean; $keyType?: string; $onDelete?: string; $onUpdate?: string; $sourceKey?: string; } export interface RelationshipManyToOneOptions { $as?: string; $constraints?: boolean; $foreignKey?: string | object; $foreignKeyConstraint?: boolean; $hooks?: boolean; $keyType?: string; $onDelete?: string; $onUpdate?: string; $targetKey?: string; } export interface RelationshipManyToManyOptions { $as?: string; $constraints?: boolean; $foreignKey?: any; $foreignKeyConstraint?: boolean; $hooks?: boolean; $onDelete?: string; $onUpdate?: string; $otherKey?: string; $sourceKey?: string; $targetKey?: string; $through?: string; $timestamps?: boolean; $uniqueKey?: string; } export declare function OneToMany(relatedModel: () => T, inverse: (model: T) => any, options?: RelationshipOneToManyOptions): (target: any, propertyKey: any) => void; export declare function OneToOne(relatedModel: () => T, inverse: (model: T) => any, options?: RelationshipOneToOneOptions): (target: any, propertyKey: any) => void; export declare function ManyToOne(relatedModel: () => T, inverse: (model: T) => any, options?: RelationshipManyToOneOptions): (target: any, propertyKey: any) => void; export declare function ManyToMany(relatedModel: () => T, inverse: (model: T) => any, options?: RelationshipManyToManyOptions): (target: any, propertyKey: any) => void; export declare function CreatedAt(target: any, key: string): void; export declare function UpdatedAt(target: any, key: string): void; export declare function DeletedAt(target: any, key: string): void; export declare function IdColumn(target: any, key: string): void; export declare function Column(target: any, key: any): void; export declare function Paranoid(target: any): void; export declare function Debug(target: any): void; export declare function Provider(providerName: string): (target: any) => void; export type RolesProps = { [K in keyof T]?: boolean; }; export type RolesType = Record>>; export declare function Roles any>(roles: RolesType): (target: T) => void; type StaticScope = { $where?: StaticProps> & SQLWhereOperators, any>; $options?: SearchMethodsOptions>; }; type DynamicScope = (...args: any[]) => StaticScope; export declare function Scopes any>(scopes: Record | DynamicScope>): (target: T) => void; type ExtendType = T & U; type ExtractPrimitiveType = T extends StringConstructor | string ? string | null : T extends (NumberConstructor | number) ? number | null : T extends (BigIntConstructor | bigint) ? number | null : T extends (BooleanConstructor | boolean) ? boolean | null : T extends (DateConstructor | Date) ? Date | null : T extends (BufferConstructor | Buffer) ? Buffer | null : T extends ArrayConstructor ? Array : T extends (StringConstructor[] | string[]) ? string[] | null : T extends (NumberConstructor[] | number[]) ? number[] | null : T extends (BigIntConstructor[] | bigint[]) ? number[] | null : T extends (BufferConstructor[] | Buffer[]) ? Buffer[] | null : T extends (BooleanConstructor[] | boolean[]) ? boolean[] | null : T extends (DateConstructor[] | Date[]) ? Date[] | null : T extends (ObjectConstructor) ? object | null : T extends new (...args: any[]) => any ? { [K in keyof Omit]?: ExtractPrimitiveType; } | null : T extends object ? { [K in keyof T]?: ExtractPrimitiveType; } | null : T; export type StaticProps = { [K in keyof T]?: T extends { [key in K]?: T[K]; } ? ExtractPrimitiveType | SQLOperators> : never; } & { [key: string]: any; }; export type BuildProps = { [K in keyof T]?: T extends { [key in K]?: T[K]; } ? ExtractPrimitiveType : never; }; type ArrayPropsOnly = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (string[] | number[] | boolean[] | Date[] | any[] | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (string[] | number[] | boolean[] | Date[] | any[] | null) ? never : K; }[keyof T]>; type StringPropsOnly = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (string | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (string | null) ? never : K; }[keyof T]>; type NumberPropsOnly = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (number | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (number | null) ? never : K; }[keyof T]>; type BooleanPropsOnly = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (boolean | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (boolean | null) ? never : K; }[keyof T]>; type ObjectPropsOnly = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type ParseArrayToTypeOnlyOne = T extends (infer U)[] ? U : never; interface SQLWhereOperators { $or?: StaticProps[]; $and?: StaticProps[]; } interface SQLOperators { $eq?: K; $ne?: K; $gt?: K; $gte?: K; $lt?: K; $lte?: K; $between?: [K, K]; $notBetween?: [K, K]; $in?: K[]; $notIn?: K[]; $like?: string; $notLike?: string; $startsWith?: string; $endsWith?: string; $substring?: string; $and?: StaticProps[]; $or?: StaticProps[]; $is?: K; $not?: K; $overlap?: K[]; $contains?: K[]; $contained?: any; $any?: K[]; $regexp?: string; $notRegexp?: string; $iLike?: string; $notILike?: string; $adjacent?: K[]; $exists?: boolean; $elementMatch?: StaticProps; $ceil?: K; $match?: K; $strictLeft?: K; $strictRight?: K; $noExtendLeft?: K; $noExtendRight?: K; $placeholder?: K; $all?: K[]; } type PushOptionsExtra = { $each?: K; $position?: number; $sort?: 1 | -1 | boolean; }; type PullOptionsExtra = { $in?: K; $nin?: K; $position?: number; } & (K extends number | number[] ? { $lte?: number; $gte?: number; $lt?: number; $gt?: number; $ne?: number; $eq?: number; } : {}); type AddToSetOptionsExtra = { $each?: K; }; type SliceOptionsExtra = { $begin?: number; $end?: number; }; type PushOptions = { [K in keyof SchemaProps]?: PushOptionsExtra | ParseArrayToTypeOnlyOne; }; type PullOptions = { [K in keyof SchemaProps]?: ParseArrayToTypeOnlyOne | PullOptionsExtra; }; type PopOptions = { [K in keyof SchemaProps]?: 1 | -1 | boolean; }; type AddToSetOptions = { [K in keyof SchemaProps]?: AddToSetOptionsExtra | ParseArrayToTypeOnlyOne; }; type SliceOptions = { [K in keyof SchemaProps]?: SliceOptionsExtra; }; type ConcatOptions = { [K in keyof SchemaProps]?: SchemaProps[K]; }; type ToogleOptions = { [K in keyof SchemaProps]?: boolean; }; type ObjectPushProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type ObjectPopProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type ObjectPullProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type ObjectAddToSetProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type ObjectSliceArrayProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type ObjectConcatProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type ObjectSliceProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type ObjectReplaceProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type StringReplaceProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (string | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (string | null) ? never : K; }[keyof T]> & Record; type StringSliceProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (string | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (string | null) ? never : K; }[keyof T]> & Record; type ObjectOmitProps = Omit<{ [K in keyof T]?: ExtractPrimitiveType extends (object | null) ? ExtractPrimitiveType : never; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; type GlobalUpdateExtraProps = Omit<{ [K in keyof T]?: boolean; }, { [K in keyof T]: ExtractPrimitiveType extends (object | null) ? never : K; }[keyof T]> & Record; export interface ArrayUpdateOptions { $push?: PushOptions> | ObjectPushProps; $pop?: PopOptions> | ObjectPopProps; $pull?: PullOptions> | ObjectPullProps; $addToSet?: AddToSetOptions> | ObjectAddToSetProps; $sliceArray?: SliceOptions> | ObjectSliceArrayProps; $concat?: ConcatOptions> | ObjectConcatProps; } export interface NumberUpdateOptions { $inc?: NumberPropsOnly | ObjectPropsOnly; $dec?: NumberPropsOnly | ObjectPropsOnly; $mul?: NumberPropsOnly | ObjectPropsOnly; $div?: NumberPropsOnly | ObjectPropsOnly; $min?: NumberPropsOnly | ObjectPropsOnly; $max?: NumberPropsOnly | ObjectPropsOnly; $sqrt?: NumberPropsOnly | ObjectPropsOnly; $floor?: NumberPropsOnly | ObjectPropsOnly; $random?: NumberPropsOnly | ObjectPropsOnly; $abs?: NumberPropsOnly | ObjectPropsOnly; $ceil?: NumberPropsOnly | ObjectPropsOnly; $pow?: NumberPropsOnly | ObjectPropsOnly; $toFixed?: NumberPropsOnly | ObjectPropsOnly; $toExponential?: NumberPropsOnly | ObjectPropsOnly; $toPrecision?: NumberPropsOnly | ObjectPropsOnly; $round?: NumberPropsOnly | ObjectPropsOnly; $trunc?: NumberPropsOnly | ObjectPropsOnly; $mod?: NumberPropsOnly | ObjectPropsOnly; } export interface StringUpdateOptions { $append?: StringPropsOnly | ObjectPropsOnly; $prepend?: StringPropsOnly | ObjectPropsOnly; $replace?: StringReplaceProps | ObjectReplaceProps; $trim?: StringPropsOnly | ObjectPropsOnly; $substr?: StringPropsOnly | ObjectPropsOnly; $capitalize?: StringPropsOnly | ObjectPropsOnly; $reverse?: StringPropsOnly | ObjectPropsOnly; $slice?: StringSliceProps | ObjectSliceProps; $lowercase?: StringPropsOnly | ObjectPropsOnly; $uppercase?: StringPropsOnly | ObjectPropsOnly; $camelcase?: StringPropsOnly | ObjectPropsOnly; $kebabcase?: StringPropsOnly | ObjectPropsOnly; $snakecase?: StringPropsOnly | ObjectPropsOnly; $titlecase?: StringPropsOnly | ObjectPropsOnly; } export interface BooleanUpdateOptions { $toggle?: ToogleOptions | ObjectPropsOnly>; } export interface UpdateOptions { $push?: ArrayUpdateOptions["$push"]; $pop?: ArrayUpdateOptions["$pop"]; $pull?: ArrayUpdateOptions["$pull"]; $addToSet?: ArrayUpdateOptions["$addToSet"]; $sliceArray?: ArrayUpdateOptions["$sliceArray"]; $concat?: ArrayUpdateOptions["$concat"]; $inc?: NumberUpdateOptions["$inc"]; $dec?: NumberUpdateOptions["$dec"]; $mul?: NumberUpdateOptions["$mul"]; $div?: NumberUpdateOptions["$div"]; $min?: NumberUpdateOptions["$min"]; $max?: NumberUpdateOptions["$max"]; $sqrt?: NumberUpdateOptions["$sqrt"]; $floor?: NumberUpdateOptions["$floor"]; $random?: NumberUpdateOptions["$random"]; $abs?: NumberUpdateOptions["$abs"]; $ceil?: NumberUpdateOptions["$ceil"]; $pow?: NumberUpdateOptions["$pow"]; $toFixed?: NumberUpdateOptions["$toFixed"]; $toExponential?: NumberUpdateOptions["$toExponential"]; $toPrecision?: NumberUpdateOptions["$toPrecision"]; $round?: NumberUpdateOptions["$round"]; $trunc?: NumberUpdateOptions["$trunc"]; $mod?: NumberUpdateOptions["$mod"]; $toggle?: BooleanUpdateOptions["$toggle"]; $append?: StringUpdateOptions["$append"]; $prepend?: StringUpdateOptions["$prepend"]; $replace?: StringUpdateOptions["$replace"]; $trim?: StringUpdateOptions["$trim"]; $substr?: StringUpdateOptions["$substr"]; $capitalize?: StringUpdateOptions["$capitalize"]; $reverse?: StringUpdateOptions["$reverse"]; $slice?: StringUpdateOptions["$slice"]; $lowercase?: StringUpdateOptions["$lowercase"]; $uppercase?: StringUpdateOptions["$uppercase"]; $camelcase?: StringUpdateOptions["$camelcase"]; $kebabcase?: StringUpdateOptions["$kebabcase"]; $snakecase?: StringUpdateOptions["$snakecase"]; $titlecase?: StringUpdateOptions["$titlecase"]; $omit?: ObjectOmitProps; $set?: StaticProps; $unset?: GlobalUpdateExtraProps; $clear?: GlobalUpdateExtraProps; } export type RulesOperators = { $required?: boolean; } & (K extends number ? { $enum?: number[]; $multipleOf?: number; $positive?: boolean; $negative?: boolean; $integer?: boolean; $float?: boolean; $even?: boolean; $odd?: boolean; $prime?: boolean; $perfect?: boolean; $fibonacci?: boolean; $powerOfTwo?: boolean; $powerOfTen?: boolean; $powerOf?: number; $range?: { $min: number; $max: number; }; $greaterThan?: number; $lessThan?: number; $greaterThanOrEqual?: number; $lessThanOrEqual?: number; $finite?: boolean; $infinite?: boolean; $palindrome?: boolean; $harshad?: boolean; $epochTime?: boolean; $angle?: { $unit: 'radian' | 'degree'; $range: { $min: number; $max: number; }; }; $logicalOr?: RulesOperators[]; $logicalNot?: RulesOperators; $custom?: (value: number) => boolean; } : {}) & (K extends string ? { $minLength?: number; $maxLength?: number; $exactLength?: number; $alphaNumeric?: boolean; $contains?: string; $startsWith?: string; $endsWith?: string; $exclude?: string; $noWhitespace?: boolean; $onlySpecialChars?: boolean; $noSpecialChars?: boolean; $alpha?: boolean; $numeric?: boolean; $locale?: string; $enum?: string[]; $match?: RegExp; $validEmail?: boolean; $validURL?: boolean; $validIP?: boolean; $validIPv4?: boolean; $validIPv6?: boolean; $validUUID?: boolean; $validCreditCard?: boolean; $custom?: (value: string) => boolean; } : {}) & (K extends boolean ? { $mustBeTrue?: boolean; $mustBeFalse?: boolean; } : {}); export type RulesOptions = { [K in keyof SchemaProps]?: RulesOperators; }; export type UpdateMethodsOptions = { $upsert?: boolean; $hooks?: boolean; $transaction?: Transaction; $multi?: boolean; $cache?: boolean | number | { $key: string; $ttl: number; }; }; export type RestoreMethodsOptions = { $limit?: number; $hooks?: boolean; $transaction?: Transaction; $logging?: boolean | ((sql: string, benchmark?: number) => void); }; export type CountMethodsOptions = { $logging?: boolean | ((sql: string, benchmark?: number) => void); $col?: keyof SchemaProps; $transaction?: Transaction; $attributes?: AttributesOption; $group?: keyof SchemaProps; $distinct?: boolean; $paranoid?: boolean; }; export type SearchMethodsOptions = { $limit?: number; $offset?: number; $transaction?: Transaction; $sort?: SortOption; $attributes?: AttributesOption; $group?: GroupOption; $having?: HavingOption; $include?: IncludeOption; $raw?: boolean; $paranoid?: boolean; $subQuery?: boolean; $logging?: boolean | ((sql: string, benchmark?: number) => void); $useMaster?: boolean; $lock?: boolean | { $level: 'key_share' | 'update'; $of: any; }; $skipLocked?: boolean; $plain?: boolean; $cache?: boolean | number | { $key: string; $ttl: number; }; }; export type DeleteMethodsOptions = { $limit?: number; $force?: boolean; $hooks?: boolean; $transaction?: Transaction; $truncate?: boolean; $logging?: boolean | ((sql: string, benchmark?: number) => void); }; export type BuildMethodsOptions = { $transaction?: Transaction; $hooks?: boolean; $logging?: boolean | ((sql: string, benchmark?: number) => void); }; type SortOption = { [K in keyof SchemaProps]?: 1 | -1 | boolean; }; type HavingOption = { [K in keyof SchemaProps]?: SQLOperators> | ExtractPrimitiveType; }; type IncludeOption = any[] | { $model: any; $as?: string; $attributes?: AttributesOption; } | any; type GroupOption = (keyof T)[]; type AttributesOption = (keyof T)[] | { $exclude?: (keyof T)[]; $include?: (keyof T)[]; }; type Transaction = { $id: string; $provider: string; $commit: () => Promise; $rollback: () => Promise; $afterCommit: (callback: () => void) => void; }; /** * Nexorm * @description Nexorm Main Class * @class Nexorm * @public * @async * @type {Class} * @example import Nexorm from 'nexorm'; * @returns {Class} */ export declare class Nexorm { /** * Nexorm Config * @type {NexormConfig} * @public * @static * @example Nexorm.$config */ static $configs: NexormConfig; /** * Nexorm Providers * @type {string[]} * @public * @static * @example Nexorm.$providers */ static $providers: string[]; /** * Nexorm Scheduled Jobs * @static * @public * @example Nexorm.$crons * @description Get All Scheduled Jobs * @example Nexorm.$crons.$every() * @example Nexorm.$crons.$get('jobName') * @returns {Object} */ static $crons: { /** * Get All Scheduled Jobs * @returns {Job[]} * @example Nexorm.$crons.$every() * @description Get All Scheduled Jobs */ $every: () => Job[]; /** * Get Scheduled Job by Name * @param {string} name - Job Name * @returns {Job | undefined} * @example Nexorm.$crons.$get('jobName') * @description Get Scheduled Job by Name */ $get: (name: string) => Job | undefined; /** * Add a Scheduled Job * @param {string} name - Job Name * @param {string} cron - Cron Expression * @param {() => void} callback - Callback Function * @returns {Job} * @example Nexorm.$crons.$addSchedule('jobName', '0 0 * * *', () => { console.log('Job executed'); }) * @description Add a Scheduled Job */ $addSchedule: (name: string, cron: string, callback: () => void) => Job; /** * Cancel a Scheduled Job * @param {string} name - Job Name * @returns {boolean} * @example Nexorm.$crons.$cancel('jobName') * @description Cancel a Scheduled Job */ $cancel: (name: string) => boolean; /** * Cancel All Scheduled Jobs * @returns {boolean} * @example Nexorm.$crons.$cancelAll() * @description Cancel All Scheduled Jobs */ $cancelAll: () => boolean; }; /** * Nexorm Connections * @type {Object} * @public * @static * @example Nexorm.$connections.$size * @example Nexorm.$connections.$list * @returns {Object} * @description Get All Connections * @example Nexorm.$connections */ static $connections: { $size: number; $list: string[]; }; /** * Connect To Database * @param providerName Provider Name * @returns Promise * @example await Nexorm.$connect('nexorm') */ static $connect(providerName?: string): Promise; /** * Disconnect From Database * @param providerName Provider Name * @returns Promise * @example await Nexorm.$disconnect('nexorm') */ static $disconnect(providerName?: string): Promise; /** * Drop Database * @param providerName Provider Name * @returns Promise * @example await Nexorm.$drop('nexorm') */ static $drop(providerName?: string): Promise; /** * Close All Connections * @returns Promise * @example await Nexorm.$closeAllConnections() * @description Close All Connections */ static $closeAllConnections(): Promise; /** * Connect All Providers * @returns Promise * @example await Nexorm.$connectAll() * @description Connect All Providers */ static $connectAll(): Promise; /** * Transaction * @param providerName Provider Name * @returns Promise * @example await Nexorm.$transaction('nexorm') * @description Create a Transaction */ static $transaction(providerName?: string): Promise; } export interface FunctionResponseList { /** * @description Save the model instance to the database * @param {BuildProps>} dataValue - Data to save * @returns {Promise>>} */ $save: (dataValue?: BuildProps>) => Promise>>; /** * @description Convert the model instance to a plain object * @returns {StaticProps>} */ $toObject: () => StaticProps>; /** * @description Convert the model instance to a JSON object * @returns {StaticProps>} */ $toJSON: () => StaticProps>; /** * @description Convert the model instance to a JSON string * @returns {string} */ $toStringify: () => string; /** * @description Clone the model instance * @returns {StaticProps>} */ $clone: () => StaticProps>; /** * @description Soft delete the model instance * @returns {Promise>>} */ $softDelete: () => Promise>>; /** * @description Hard delete the model instance * @returns {Promise>>} */ $delete: () => Promise>>; /** * @description Get a property value on the model instance * @param {keyof Omit} property - Property name * @returns {any} */ $get: (property: keyof Omit) => any; /** * @description Set a property value on the model instance * @param {keyof Omit} property - Property name * @param {any} value - Property value * @returns {any} */ $set: (property: keyof Omit, value: any) => any; /** * @description Automatically delete after a certain time * @param {uniqueCronName: string, spec: string, options?: { $force?: boolean, $continuity?: boolean } } * @returns {Object} */ $expiresAt: (uniqueCronName: string, spec: string, options?: { $force?: boolean; $continuity?: boolean; }) => { $cancel: () => boolean; }; /** * @description Is Deleted * @returns {boolean} */ $isDeleted: () => boolean; /** * @description Is Modified * @returns {boolean} */ $isModified: () => boolean; /** * @description Is Valid * @returns {boolean} */ $isValid: () => boolean; /** * @description Refresh the model instance * @returns {Promise> | null>} * */ $refresh: () => Promise> | null>; /** * @description Reload the model instance * @param {Array>} keys - Keys to reload * @returns {Promise>>} */ $reload: (keys: (keyof Omit)[]) => Promise>>; /** * @description Role the model instance * @param {string} role - Role name * @returns {StaticProps>} */ $role: (role: string) => StaticProps>; /** * @description Update the model instance * @param {UpdateOptions>} updateQuery - Update query * @returns {Promise>>} */ $update: (updateQuery: UpdateOptions>) => Promise>>; /** * @description Restore the model instance * @returns {Promise>>} */ $restore: () => Promise>>; } export type SelectKeys = Pick; export declare function Model(Schema: SchemaProps): ModelEngine & { new (dataValue?: Omit<{ [K in keyof SchemaProps]?: ExtractPrimitiveType | undefined; }, "prototype">): Omit<{ [K in keyof SchemaProps]?: ExtractPrimitiveType | undefined; }, "prototype"> & { /** * @description Convert the model instance to a plain object * @returns {SchemaStatics} */ $toObject: () => Omit<{ [K in keyof SchemaProps]?: ExtractPrimitiveType | undefined; }, "prototype">; /** * @description Save the model instance to the database * @param {BuildProps} dataValue - Data to save * @returns {Promise>>} */ $save: (dataValue?: BuildProps | undefined; }, "prototype">> | undefined) => Promise | undefined; }, "prototype">, FunctionResponseList | undefined; }, "prototype">>>>; /** * @description Get a model instance by primary key * @param {string | number} primaryKey - Primary key value * @returns {Promise>>} */ $get: (property: Exclude) => any; /** * @description Set a property value on the model instance * @param {keyof SchemaStatics} property - Property name * @param {any} * @returns {any} */ $set: (property: Exclude, value: any) => any; /** * @description Clear all properties on the model instance * @returns {void} */ $clear: () => void; /** * @description Check if the model instance is new * @returns {boolean} */ $toJSON: () => Omit<{ [K in keyof SchemaProps]?: ExtractPrimitiveType | undefined; }, "prototype">; /** * @description Convert the model instance to a JSON string * @returns {string} */ $toStringify: () => string; /** * @description Check if the model instance is new * @returns {boolean} */ $isNew: () => boolean; }; }; export declare namespace FunctionResponse { type Responses = SelectKeys, '$clone' | '$delete' | '$expiresAt' | '$get' | '$isDeleted' | '$isModified' | '$isValid' | '$refresh' | '$reload' | '$restore' | '$role' | '$save' | '$set' | '$softDelete' | '$toJSON' | '$toObject' | '$toStringify' | '$update'>; } export declare class ModelEngine { #private; private Schema; $type: Omit; $model: any; $middlewares: any[]; $cache: CacheManager; $config: NexormConfigType; $debugMode: boolean; $schema: Omit; $provider: string; constructor(Schema: SchemaProps); initialize(): this; /** * Scope * */ $scope(scopes: string | string[], ...args: any[]): { $searchOne: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: SearchMethodsOptions>; }) => Promise, { ObjectId: string; }>>, FunctionResponse.Responses>>; $search: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: SearchMethodsOptions>; }) => Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; $update: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $update: UpdateOptions>; $rules?: Omit>, "$upsert">; }) => Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; $updateMany: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $update: UpdateOptions>; $rules?: Omit>, "$upsert">; }) => Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; $delete: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; }) => Promise; $deleteMany: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; }) => Promise; $count: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: CountMethodsOptions>; }) => Promise; $searchAndCount: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; }) => Promise<[ExtendType, { ObjectId: string; }>>, FunctionResponse.Responses>[], number]>; $restore: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; }) => Promise; $softDelete: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; }) => Promise; $softDeleteMany: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; }) => Promise; $upsert: (query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $update?: UpdateOptions>; $rules?: Omit>, "$upsert">; }) => Promise, { ObjectId: string; }>>, FunctionResponse.Responses>>; $distinct: (query?: { $field: (keyof ExtendType, { ObjectId: string; }>)[]; $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; }) => Promise; }; $searchAndReplace(query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $replace?: StaticProps>; $options?: UpdateMethodsOptions; $rules?: Omit>, '$upsert'>; }): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; /** * Search * @param query Query * @param query.$where Where * @param query.$options Options * @returns Promise> * @example model.$search({ $where: { name: 'John' } }) * @async * @public * @type {Function} */ $search(query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: SearchMethodsOptions>; }): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; /** * Search First * @returns Promise> * @example model.$searchFirst() * @async * @public * @type {Function} */ $searchFirst(): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>>; /** * Search One * @param query Query * @param query.$where Where * @param query.$options Options * @returns Promise> * @example model.$searchOne({ $where: { name: 'John' } }) * @async * @public * @type {Function} */ $searchOne(query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: SearchMethodsOptions>; }): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>>; /** * Search By Id * @param id ID * @returns Promise:string}>> * @example model.$searchById('1') * @async * @public * @type {Function} */ $searchById(id: number): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>>; /** * Search By Ids * @param ids Nexorm IDs * @returns Promise> * @example model.$searchByIds(['1','2','3']) * @async * @public * @type {Function} */ $searchByIds(ids: number[]): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; /** * Search And Count * @param query Query * @param query.$where Where * @returns Promise<[StaticProps>[], number]> * @example model.$searchAndCount({ $where: { name: 'John' } }) * @async * @public * @type {Function} */ $searchAndCount(query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; }): Promise<[ ExtendType, { ObjectId: string; }>>, FunctionResponse.Responses>[], number ]>; /** * Create * @param data Data * @returns Promise> * @example model.$create({ name: 'John' }) * @async * @public * @type {Function} */ $everything(): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; /** * Build * @param data Data * @returns Promise> * @example model.$build({ name: 'John' }) * @async * @public * @type {Function} */ $build(query?: { $data?: BuildProps, { ObjectId: string; }>>; $options?: BuildMethodsOptions; }): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>>; /** * Build Many * @param data Data * @returns Promise> * @example model.$buildMany([{ name: 'John' }, { name: 'Doe' }]) * @async * @public * @type {Function} */ $buildMany(query?: { $data: BuildProps, { ObjectId: string; }>>[]; $options?: BuildMethodsOptions; }): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; /** * Update * @param query Query * @param query.$where Where * @param query.$update Update * @param query.$rules Rules * @param query.$options Options * @returns Promise> * @example model.$update({ $where: { name: 'John' }, $update: { $set: { name: 'Five' } } }) * @async * @public * @type {Function} */ $update(query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $update?: UpdateOptions>; $rules?: RulesOptions>>; $options?: UpdateMethodsOptions; }): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>>; /** * Update Many * @param query Query * @param query.$where Where * @param query.$update Update * @param query.$rules Rules * @param query.$options Options * @returns Promise> * @example model.$updateMany({ $where: { name: 'John' }, $update: { $set: { name: 'Five' } } }) * @async * @public * @type {Function} */ $updateMany(query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $update?: UpdateOptions>; $rules?: RulesOptions>>; $options?: Omit; }): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>[]>; /** * Delete * @param query Query * @param query.$where Where * @param query.$options Options * @returns Promise * @example model.$delete({ $where: { name: 'John' } }) * @async * @public * @type {Function} * @returns {Promise} */ $delete(query?: { $where: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: DeleteMethodsOptions>; }): Promise; /** * Delete Many * @param query Query * @param query.$where Where * @param query.$options Options * @returns Promise * @example model.$deleteMany({ $where: { name: 'John' } }) * @async * @public * @type {Function} * @returns {Promise} */ $deleteMany(query?: { $where: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: DeleteMethodsOptions>; }): Promise; /** * Soft Delete * @param query Query * @param query.$where Where * @param query.$options Options * @returns Promise * @example model.$softDelete({ $where: { name: 'John' } }) * @async * @public * @type {Function} * @returns {Promise} */ $softDelete(query?: { $where: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: Omit>, '$force'>; }): Promise; /** * Soft Delete Many * @param query Query * @param query.$where Where * @param query.$options Options * @returns Promise * @example model.$softDeleteMany({ $where: { name: 'John' } }) * @async * @public * @type {Function} * @returns {Promise} */ $softDeleteMany(query?: { $where: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: Omit>, '$force'>; }): Promise; /** * Restore * @param query Query * @param query.$where Where * @param query.$options Options * @returns Promise * @example model.$restore({ $where: { name: 'John' } }) * @async * @public * @type {Function} * @returns {Promise} */ $restore(query?: { $where: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: RestoreMethodsOptions; }): Promise; $count(query?: { $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: CountMethodsOptions, { ObjectId: string; }>>; }): Promise; /** * Upsert * @param query Query * @param query.$where Where * @param query.$update Update * @param query.$rules Rules * @param query.$options Options * @returns Promise> * @example model.$upsert({ $where: { name: 'John' }, $update: { $set: { name: 'Five' } } }) * @async * @public * @type {Function} */ $upsert(query: { $where: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $update: UpdateOptions>; $rules?: RulesOptions>>; $options?: Omit; }): Promise, { ObjectId: string; }>>, FunctionResponse.Responses>>; /** * Query * @param query Query * @returns Promise * @example model.$query('SELECT * FROM users') * @async * @public * @type {Function} */ $query(query: string): Promise; /** * Distinct * @param query Query * @param query.$field Field * @param query.$where Where * @param query.$options Options * @returns Promise * @example model.$distinct({ $field: ['name'] }) * @example model.$distinct({ $field: ['name'], $where: { age: { $gt: 18 } } }) * @async * @public * @type {Function} */ $distinct(query: { $field: (keyof ExtendType, { ObjectId: string; }>)[]; $where?: StaticProps, { ObjectId: string; }>> & SQLWhereOperators, { ObjectId: string; }>, SchemaProps>; $options?: Omit; }): Promise; /** * Truncate * @returns Promise * @example model.$truncate() * @async * @public * @type {Function} */ $truncate(): Promise; /** * Hooks * @description Nexorm Hooks * @public * @async * @example model.$hooks.$beforeCreate((values, fields) => {}) * @example model.$hooks.$afterCreate((values, fields) => {}) */ $hooks: { /** * Before Create Hook * @param callback Callback Function * @returns void * @example model.$hooks.$beforeCreate((values, fields) => {}) * @description Before Create Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $beforeCreate: (callback: (values: BuildProps, { ObjectId: string; }>>, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * After Create Hook * @param callback Callback Function * @returns void * @example model.$hooks.$afterCreate((values, fields) => {}) * @description After Create Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $afterCreate: (callback: (values: BuildProps, { ObjectId: string; }>>, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * After Update Hook * @param callback Callback Function * @returns void * @example model.$hooks.$afterUpdate((values, fields) => {}) * @description After Update Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $afterUpdate: (callback: (values: BuildProps, { ObjectId: string; }>>, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * Before Destroy Hook * @param callback Callback Function * @returns void * @example model.$hooks.$beforeDestroy((values) => {}) * @description Before Destroy Hook * @public * @async * @type {Function} * @returns {void} * @param values */ $beforeDestroy: (callback: (values: BuildProps, { ObjectId: string; }>>) => void) => void; /** * After Destroy Hook * @param callback Callback Function * @returns void * @example model.$hooks.$afterDestroy((values) => {}) * @description After Destroy Hook * @public * @async * @type {Function} * @returns {void} * @param values */ $afterDestroy: (callback: (values: BuildProps, { ObjectId: string; }>>) => void) => void; /** * Before Update Hook * @param callback Callback Function * @returns void * @example model.$hooks.$beforeUpdate((values, fields) => {}) * @description Before Update Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $beforeUpdate: (callback: (values: BuildProps, { ObjectId: string; }>>, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * Before Save Hook * @param callback Callback Function * @returns void * @example model.$hooks.$beforeSave((values, fields) => {}) * @description Before Save Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $beforeSave: (callback: (values: BuildProps, { ObjectId: string; }>>, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * After Save Hook * @param callback Callback Function * @returns void * @example model.$hooks.$afterSave((values, fields) => {}) * @description After Save Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $afterSave: (callback: (values: BuildProps, { ObjectId: string; }>>, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * Before Bulk Create Hook * @param callback Callback Function * @returns void * @example model.$hooks.$beforeBulkCreate((values) => {}) * @description Before Bulk Create Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $beforeBulkCreate: (callback: (values: BuildProps, { ObjectId: string; }>>[], fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * After Bulk Create Hook * @param callback Callback Function * @returns void * @example model.$hooks.$afterBulkCreate((values) => {}) * @description After Bulk Create Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $afterBulkCreate: (callback: (values: BuildProps, { ObjectId: string; }>>[], fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * Before Bulk Update Hook * @param callback Callback Function * @returns void * @example model.$hooks.$beforeBulkUpdate((values, fields) => {}) * @description Before Bulk Update Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $beforeBulkUpdate: (callback: (name: string, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * After Bulk Update Hook * @param callback Callback Function * @returns void * @example model.$hooks.$afterBulkUpdate((values, fields) => {}) * @description After Bulk Update Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $afterBulkUpdate: (callback: (name: string, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * Before Bulk Destroy Hook * @param callback Callback Function * @returns void * @example model.$hooks.$beforeBulkDestroy((values) => {}) * @description Before Bulk Destroy Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $beforeBulkDestroy: (callback: (name: string, fields: BuildProps, { ObjectId: string; }>>[]) => void) => void; /** * After Bulk Destroy Hook * @param callback Callback Function * @returns void * @example model.$hooks.$afterBulkDestroy((values) => {}) * @description After Bulk Destroy Hook * @public * @async * @type {Function} * @returns {void} * @param values * @param fields */ $afterBulkDestroy: (callback: (name: string) => void) => void; /** * Before Find Hook * @param callback Callback Function * @returns void * @example model.$hooks.$beforeFind((values) => {}) * @description Before Find Hook * @public * @async * @type {Function} * @returns {void} * @param values */ $beforeFind: (callback: (values: BuildProps, { ObjectId: string; }>>) => void) => void; /** * After Find Hook * @param callback Callback Function * @returns void * @example model.$hooks.$afterFind((values) => {}) * @description After Find Hook * @public * @async * @type {Function} * @returns {void} * @param values */ $afterFind: (callback: (values: BuildProps, { ObjectId: string; }>>) => void) => void; }; }