import { TableSchema } from '../migration/migration.interface.js'; import { Connector } from '../connection/connector.js'; import { HasOne } from '../relations/has-one.js'; import { HasMany } from '../relations/has-many.js'; import { HasManyThroughMulti } from '../relations/has-many-through-multi.js'; import { HasManyMulti } from '../relations/has-many-multi.js'; /** * Default index name and attribute name for auto-generating key */ export declare const DEFAULT_PRIMARY_ID = "_id"; export interface AggregateInterface { count(): Promise; average(attribute: string): Promise; reduce(func: (value: U, result: any) => any, defaultCarry?: any): Promise; reduce(func: (value: any, result: any) => any, defaultCarry?: any): Promise; reduce(func: (value: any, result: any) => any, defaultCarry?: any): Promise; } /** * Transaction modes available */ export declare enum TransactionModes { ReadOnly = "readonly", Write = "readwrite", VersionChange = "versionchange" } /** * Relation Types available */ export declare enum RelationTypes { HasOne = "hasOne", HasMany = "hasMany", HasManyMultiEntry = "hasManyMultiEntry", HasManyThroughMultiEntry = "hasManyThroughMultiEntry" } export interface Relation { model: ModelInterface | string; type: RelationTypes; foreignKey: string; attributeName?: string | undefined; localKey?: string | undefined; func?(builder: QueryBuilderInterface): QueryBuilderInterface; } export interface OrmRelationBuilderInterface { hasOne(model: ModelConstructorInterface, foreignKey: string, localKey?: string, parentKeyName?: string): HasOne; hasMany(model: ModelConstructorInterface, foreignKey: string, localKey?: string, parentKeyName?: string): HasMany; hasManyMultiEntry(model: ModelConstructorInterface, foreignKey: string, localKey?: string, parentKeyName?: string): HasManyMulti; hasManyThroughMultiEntry(model: ModelConstructorInterface, foreignKey: string, localKey?: string, parentKeyName?: string): HasManyThroughMulti; } export interface RelationQueryBuilder { relations: Relation[]; customRelations: string[]; tableNames(relations: TableSchema[]): string[]; with(relations: (Relation | string)[]): RelationQueryBuilder | ModelInterface; /** * @deprecated * @param modelName * @param type * @param localKey * @param foreignKey * @param func */ relation(modelName: string, type: RelationTypes, localKey: string, foreignKey: string, func?: (builder: QueryBuilderInterface) => QueryBuilderInterface): RelationQueryBuilder | ModelInterface; } export declare enum QueryTypes { Between = "between", Where = "where", WhereIn = "whereIn", WhereInArray = "whereInArray", GreaterThan = "gt", GreaterThanEqual = "gte", LessThanEqual = "lte", LessThan = "lt" } export declare enum CursorDirection { Ascending = "next", AscendingUnique = "nextunique", Descending = "prev", DescendingUnique = "prevunique" } export interface IndexBuilder { index: string; value: any | any[]; type: QueryTypes; } export interface Builder { attribute: string; value: any; type: QueryTypes; } export interface QueryBuilderInterface extends RelationQueryBuilder { indexBuilder: IndexBuilder | null; builder: Builder[]; cursor: CursorDirection | null; whereIndex(indexName: string, value: any): QueryBuilderInterface | ModelInterface; whereIndexIn(indexName: string, values: any[]): QueryBuilderInterface | ModelInterface; whereMultiIndexIn(indexName: string, values: any[], unique?: boolean): QueryBuilderInterface | ModelInterface; indexGte(indexName: string, value: any): QueryBuilderInterface | ModelInterface; indexGt(indexName: string, value: any): QueryBuilderInterface | ModelInterface; indexLt(indexName: string, value: any): QueryBuilderInterface | ModelInterface; indexLte(indexName: string, value: any): QueryBuilderInterface | ModelInterface; indexBetween(indexName: string, lower: any, upper: any): QueryBuilderInterface | ModelInterface; where(attributeName: string, value: any): QueryBuilderInterface | ModelInterface; whereIn(attributeName: string, values: any[]): QueryBuilderInterface | ModelInterface; gte(attributeName: string, value: any): QueryBuilderInterface | ModelInterface; gt(attributeName: string, value: any): QueryBuilderInterface | ModelInterface; lte(attributeName: string, value: any): QueryBuilderInterface | ModelInterface; lt(attributeName: string, value: any): QueryBuilderInterface | ModelInterface; between(attributeName: string, lower: any, upper: any): QueryBuilderInterface | ModelInterface; whereInArray(attributeName: string, values: any[], unique: boolean): QueryBuilderInterface | ModelInterface; cursorDirection(direction: CursorDirection): QueryBuilderInterface | ModelInterface; keyRange(indexBuilder: IndexBuilder): IDBKeyRange; resetBuilder(): QueryBuilderInterface | ModelInterface; } export interface TransactionHandling { getTransaction(stores: string[], mode: TransactionModes, overwrite: boolean): IDBTransaction; setTransaction(transaction: IDBTransaction): void; createTransaction(stores: string[], mode: TransactionModes): IDBTransaction; openTransaction(mode: TransactionModes): { models: ModelKeysInterface; transaction: IDBTransaction; }; } export interface ActionOrFailInterface { findOrFail(id: any): Promise; findOrFail(id: any): Promise; findIndexOrFail(indexName: string, id: any): Promise; findIndexOrFail(indexName: string, id: any): Promise; firstOrFail(): Promise; firstOrFail(): Promise; } export interface FindOrCreateActionInterface { firstOrCreate(data: any): Promise; firstOrCreate(data: any): Promise; findOrCreate(id: any, data: any): Promise; findOrCreate(id: any, data: any): Promise; findIndexOrCreate(indexName: string, id: any, data: any): Promise; findIndexOrCreate(indexName: string, id: any, data: any): Promise; } export interface BaseWriteActionsInterface { create(data: any): Promise; create(data: any): Promise; createMultiple(entries: any[]): Promise; createMultiple(entries: any[]): Promise; update(data: any, mergeDeep: boolean): Promise; delete(id: any): Promise; destroy(): Promise; deleteIndex(indexName: string, value: any, isMulti: boolean): Promise; save(id: any, data: any, mergeDeep: boolean): Promise; saveIndex(indexName: string, id: any, data: any, mergeDeep: boolean): Promise; saveAllIndex(indexName: string, id: any, data: any, mergeDeep: boolean): Promise; /** * @deprecated * @param id */ destroyId(id: any): Promise; truncate(): Promise; } export interface BaseSearchActionsInterface { all(): Promise; all(): Promise; find(id: any): Promise; find(id: any): Promise; findIndex(indexName: string, id: any): Promise; findIndex(indexName: string, id: any): Promise; findAllIndex(indexName: string, id: any): Promise; findAllIndex(indexName: string, id: any): Promise; first(): Promise; first(): Promise; } export interface ModelConstructorInterface { new (db: IDBDatabase, table: TableSchema, connector: Connector): ModelInterface; readonly prototype: ModelInterface; TableName: string; } export interface BaseModelInterface { table: TableSchema; } export interface ModelInterface extends AggregateInterface, RelationQueryBuilder, QueryBuilderInterface, TransactionHandling, ActionOrFailInterface, FindOrCreateActionInterface, BaseSearchActionsInterface, BaseWriteActionsInterface, BaseModelInterface { sync(id: any, data: any, mergeDeep?: boolean): Promise; sync(id: any, data: any, mergeDeep?: boolean): Promise; syncIndex(indexName: string, id: any, data: any, mergeDeep?: boolean): Promise; syncIndex(indexName: string, id: any, data: any, mergeDeep?: boolean): Promise; syncAllIndex(indexName: string, id: any, data: any, mergeDeep?: boolean): Promise; syncAllIndex(indexName: string, id: any, data: any, mergeDeep?: boolean): Promise; } export declare type ModelKeysInterface = Record;