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 const DEFAULT_PRIMARY_ID = '_id' ; export interface AggregateInterface { count ( ) : Promise < number > ; average ( attribute ) : Promise < number > ; reduce < T , U > ( func , defaultCarry ? ) : Promise < T > ; reduce < T > ( func , defaultCarry ? ) : Promise < T > ; reduce ( func , defaultCarry ? ) : Promise < any > ; } /**
 * Transaction modes available
 */ export enum TransactionModes { ReadOnly = 'readonly' , Write = 'readwrite' , VersionChange = 'versionchange' } /**
 * Relation Types available
 */ export 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 ; } export interface OrmRelationBuilderInterface { hasOne ( model , foreignKey , localKey ? , parentKeyName ? ) : HasOne ; hasMany ( model , foreignKey , localKey ? , parentKeyName ? ) : HasMany ; hasManyMultiEntry ( model , foreignKey , localKey ? , parentKeyName ? ) : HasManyMulti ; hasManyThroughMultiEntry ( model , foreignKey , localKey ? , parentKeyName ? ) : HasManyThroughMulti ; } export interface RelationQueryBuilder { relations : Relation [ ] ; customRelations : string [ ] ; tableNames ( relations ) : string [ ] ; with ( relations ) : RelationQueryBuilder | ModelInterface ; withCustom ( relations ) : RelationQueryBuilder | ModelInterface ; deprecated param modelName param type param localKey param foreignKey param func relation ( modelName , type , localKey , foreignKey , func ? ) : RelationQueryBuilder | ModelInterface ; } export enum QueryTypes { Between = 'between' , Where = 'where' , WhereIn = 'whereIn' , WhereInArray = 'whereInArray' , GreaterThan = 'gt' , GreaterThanEqual = 'gte' , LessThanEqual = 'lte' , LessThan = 'lt' } export 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 , value ) : QueryBuilderInterface | ModelInterface ; whereIndexIn ( indexName , values ) : QueryBuilderInterface | ModelInterface ; whereMultiIndexIn ( indexName , values , unique ? ) : QueryBuilderInterface | ModelInterface ; indexGte ( indexName , value ) : QueryBuilderInterface | ModelInterface ; indexGt ( indexName , value ) : QueryBuilderInterface | ModelInterface ; indexLt ( indexName , value ) : QueryBuilderInterface | ModelInterface ; indexLte ( indexName , value ) : QueryBuilderInterface | ModelInterface ; indexBetween ( indexName , lower , upper ) : QueryBuilderInterface | ModelInterface ; where ( attributeName , value ) : QueryBuilderInterface | ModelInterface ; whereIn ( attributeName , values ) : QueryBuilderInterface | ModelInterface ; gte ( attributeName , value ) : QueryBuilderInterface | ModelInterface ; gt ( attributeName , value ) : QueryBuilderInterface | ModelInterface ; lte ( attributeName , value ) : QueryBuilderInterface | ModelInterface ; lt ( attributeName , value ) : QueryBuilderInterface | ModelInterface ; between ( attributeName , lower , upper ) : QueryBuilderInterface | ModelInterface ; whereInArray ( attributeName , values , unique ) : QueryBuilderInterface | ModelInterface ; cursorDirection ( direction ) : QueryBuilderInterface | ModelInterface ; keyRange ( indexBuilder ) : IDBKeyRange ; resetBuilder ( ) : QueryBuilderInterface | ModelInterface ; } export interface TransactionHandling { getTransaction ( stores , mode , overwrite ) : IDBTransaction ; setTransaction ( transaction ) : void ; createTransaction ( stores , mode ) : IDBTransaction ; openTransaction ( mode ) : { models : ModelKeysInterface ; transaction : IDBTransaction ; } ; } export interface ActionOrFailInterface { findOrFail < T > ( id ) : Promise < T | null > ; findOrFail ( id ) : Promise < any | null > ; findIndexOrFail < T > ( indexName , id ) : Promise < T > ; findIndexOrFail ( indexName , id ) : Promise < any > ; firstOrFail ( ) : Promise < any > ; firstOrFail < T > ( ) : Promise < T > ; } export interface FindOrCreateActionInterface { firstOrCreate < T > ( data ) : Promise < T > ; firstOrCreate ( data ) : Promise < any > ; findOrCreate < T > ( id , data ) : Promise < T > ; findOrCreate ( id , data ) : Promise < any > ; findIndexOrCreate < T > ( indexName , id , data ) : Promise < T > ; findIndexOrCreate ( indexName , id , data ) : Promise < any > ; } export interface BaseWriteActionsInterface { create < T > ( data ) : Promise < T > ; create ( data ) : Promise < any > ; createMultiple < T > ( entries ) : Promise < T [ ] > ; createMultiple ( entries ) : Promise < any [ ] > ; update ( data , mergeDeep ) : Promise < number > ; delete ( id ) : Promise < boolean > ; destroy ( ) : Promise < boolean > ; deleteIndex ( indexName , value , isMulti ) : Promise < boolean > ; save ( id , data , mergeDeep ) : Promise < boolean > ; saveIndex ( indexName , id , data , mergeDeep ) : Promise < boolean > ; saveAllIndex ( indexName , id , data , mergeDeep ) : Promise < boolean > ; deprecated param id destroyId ( id ) : Promise < boolean > ; truncate ( ) : Promise < boolean > ; } export interface BaseSearchActionsInterface { all < T > ( ) : Promise < T [ ] > ; all ( ) : Promise < any [ ] > ; find < T > ( id ) : Promise < T | null > ; find ( id ) : Promise < any | null > ; findIndex < T > ( indexName , id ) : Promise < T > ; findIndex ( indexName , id ) : Promise < any > ; findAllIndex < T > ( indexName , id ) : Promise < T [ ] > ; findAllIndex ( indexName , id ) : Promise < any [ ] > ; first ( ) : Promise < any > ; first < T > ( ) : Promise < T > ; } export interface ModelConstructorInterface { new ( db , table , connector ) : ModelInterface ; readonly prototype : ModelInterface ; TableName : string ; } export interface ModelInterface extends AggregateInterface , RelationQueryBuilder , QueryBuilderInterface , TransactionHandling , ActionOrFailInterface , FindOrCreateActionInterface , BaseSearchActionsInterface , BaseWriteActionsInterface { table : TableSchema ; sync < T > ( id , data , mergeDeep ? ) : Promise < T > ; sync ( id , data , mergeDeep ? ) : Promise < any > ; syncIndex < T > ( indexName , id , data , mergeDeep ? ) : Promise < T > ; syncIndex ( indexName , id , data , mergeDeep ? ) : Promise < any > ; syncAllIndex < T > ( indexName , id , data , mergeDeep ? ) : Promise < T [ ] > ; syncAllIndex ( indexName , id , data , mergeDeep ? ) : Promise < any [ ] > ; } export interface ModelKeysInterface { [ key ] : ModelInterface ; }