import 'reflect-metadata'; type QueryDirection = 'asc' | 'desc'; type QueryFieldKey = Extract; type ComparableValue = string | number | bigint | Date; type ComparableFieldKey = { [K in QueryFieldKey]-?: T[K] extends ComparableValue ? K : never; }[QueryFieldKey]; type NumericFieldKey = { [K in QueryFieldKey]-?: T[K] extends number ? K : never; }[QueryFieldKey]; type StringFieldKey = { [K in QueryFieldKey]-?: T[K] extends string ? K : never; }[QueryFieldKey]; type ArrayFieldKey = { [K in QueryFieldKey]-?: T[K] extends readonly any[] ? K : never; }[QueryFieldKey]; type ArrayElement = T extends readonly (infer U)[] ? U : never; type ContainsValue = T extends string ? string : T extends readonly (infer U)[] ? U : never; type QueryOperator = 'equals' | 'gt' | 'gte' | 'lt' | 'lte' | 'startsWith' | 'endsWith' | 'contains' | 'matches' | 'between' | 'notBetween' | 'in' | 'notIn' | 'containsAny' | 'containsAll'; type GroupCountResult> = Array & { count: number; }>; declare class FieldQueryBuilder> { private parent; private field; constructor(parent: QueryBuilder, field: K); equals(value: T[K]): QueryBuilder; gt(value: T[K] extends ComparableValue ? T[K] : never): QueryBuilder; gte(value: T[K] extends ComparableValue ? T[K] : never): QueryBuilder; lt(value: T[K] extends ComparableValue ? T[K] : never): QueryBuilder; lte(value: T[K] extends ComparableValue ? T[K] : never): QueryBuilder; startsWith(this: FieldQueryBuilder>, value: string): QueryBuilder; endsWith(this: FieldQueryBuilder>, value: string): QueryBuilder; contains(this: FieldQueryBuilder> | FieldQueryBuilder>, value: ContainsValue): QueryBuilder; matches(this: FieldQueryBuilder>, value: RegExp | string): QueryBuilder; between(start: T[K] extends ComparableValue ? T[K] : never, end: T[K] extends ComparableValue ? T[K] : never): QueryBuilder; notBetween(start: T[K] extends ComparableValue ? T[K] : never, end: T[K] extends ComparableValue ? T[K] : never): QueryBuilder; in(values: Array): QueryBuilder; notIn(values: Array): QueryBuilder; containsAny(this: FieldQueryBuilder>, values: Array>): QueryBuilder; containsAll(this: FieldQueryBuilder>, values: Array>): QueryBuilder; and>(field: K2): FieldQueryBuilder; or(): QueryBuilder; } declare class QueryBuilder { private db; private storeName; private transaction?; private clauses; private orderField?; private orderDirection; private limitCount?; private offsetCount?; private indexName?; private rangeStart?; private rangeEnd?; private currentField?; private groupField?; private pendingConnector; constructor(db: IDBDatabase, storeName: string, transaction?: IDBTransaction); where>(field: K): FieldQueryBuilder; where(builder: (query: QueryBuilder) => QueryBuilder | void): this; and>(field: K): FieldQueryBuilder; and(builder: (query: QueryBuilder) => QueryBuilder | void): this; or(): this; private addNestedGroup; clearCurrentField(): void; appendCondition(field: string, op: QueryOperator, value: any): void; private appendClause; private requireCurrentField; private addCondition; equals(value: any): this; gt(value: any): this; gte(value: any): this; lt(value: any): this; lte(value: any): this; startsWith(value: string): this; endsWith(value: string): this; contains(value: any): this; matches(value: RegExp | string): this; between(start: any, end: any): this; notBetween(start: any, end: any): this; ['in'](values: any[]): this; notIn(values: any[]): this; containsAny(values: any[]): this; containsAll(values: any[]): this; orderBy(field: Extract, direction?: QueryDirection): this; limit(n: number): this; offset(n: number): this; useIndex(indexName: string): this; range(start: any, end: any): this; groupBy>(field: K): QueryBuilder & { count(): Promise>; }; private loadCandidates; private createReadRequest; private matchesClause; private evaluateClauses; private collectMatches; private sortResults; private applyPagination; private aggregateValues; private aggregateGroupedCount; execute(): Promise; count(): Promise>>; sum(field: NumericFieldKey): Promise; avg(field: NumericFieldKey): Promise; min(field: ComparableFieldKey): Promise; max(field: ComparableFieldKey): Promise; } interface KeyPathOptions { autoIncrement?: boolean; generator?: 'uuid' | 'timestamp' | 'random' | ((item?: any) => string | number); } interface RetentionPolicyOptions { seconds: number; enabled?: boolean; field?: string; } interface RetentionPolicyMetadata { seconds: number; enabled: boolean; field: string; } interface KeyPathMetadata { fields: string | string[]; options?: KeyPathOptions; } declare class KeyGenerators { static uuid(): string; static timestamp(): number; static random(): string; } declare function KeyPath(options?: KeyPathOptions): PropertyDecorator; declare function CompositeKeyPath(fields: string[], options?: KeyPathOptions): ClassDecorator; declare function Index(options?: IDBIndexParameters): PropertyDecorator; declare function Validate(predicate: (value: any, item: T) => boolean, message: string): PropertyDecorator; declare function RetentionPolicy(options: RetentionPolicyOptions): ClassDecorator; interface DataClassOptions { version?: number; } declare function DataClass(options?: DataClassOptions): ClassDecorator; interface EntityRepository { create(item: T): Promise; createMany(items: T[]): Promise; read(key: string | string[] | number): Promise; update(item: T): Promise; updateMany(items: T[]): Promise; delete(key: string | string[] | number): Promise; deleteMany(keys: Array): Promise; deleteWhere(predicate: (query: QueryBuilder) => QueryBuilder | void): Promise; list(): Promise; listPaginated(page: number, pageSize: number): Promise; findByIndex(indexName: string, value: any): Promise; findOneByIndex(indexName: string, value: any): Promise; count(): Promise; exists(key: string): Promise; clear(): Promise; query(): QueryBuilder; } interface TransactionController { commit(): Promise; rollback(): Promise; } type TransactionalDatabase>> = T & TransactionController; type DatabaseWithRepositories> = Database & T; declare class Database { private dbName; private classes; private db; private entityRepositories; private dbVersion; private retentionTimer; private retentionCleanupRunning; private retentionPolicies; private printEnabled; private printDebug; private printError; private constructor(); private calculateDatabaseVersion; static build>>(dbName: string, classes: Function[]): Promise>; private initDB; private generateEntityRepositories; private calculateRetentionCleanupIntervalMs; private startRetentionCleanup; private runRetentionCleanup; private cleanupExpiredRecords; private createEntityRepository; private performOperation; private createTransactionHandle; beginTransaction(entityNames: string[], mode?: IDBTransactionMode): Promise>>>; transaction(callback: (tx: TransactionalDatabase>>) => Promise | T): Promise; close(): void; getAvailableEntities(): string[]; getDatabaseVersion(): number; getEntityVersions(): Map; getEntityVersion(entityName: string): number | undefined; } export { Database, KeyPath, CompositeKeyPath, DataClass, Index, Validate, RetentionPolicy, EntityRepository, KeyGenerators, }; export type { DatabaseWithRepositories, DataClassOptions, KeyPathOptions, KeyPathMetadata, RetentionPolicyOptions, RetentionPolicyMetadata, };