idb-ts 3.15.0 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -88,10 +88,12 @@ declare class QueryBuilder<T> {
88
88
  limit(n: number): this;
89
89
  offset(n: number): this;
90
90
  useIndex(indexName: string): this;
91
- range(start: any, end: any): this;
91
+ range(start: IDBValidKey | undefined, end: IDBValidKey | undefined): this;
92
92
  groupBy<K extends QueryFieldKey<T>>(field: K): QueryBuilder<T> & {
93
93
  count(): Promise<GroupCountResult<T, K>>;
94
94
  };
95
+ clone(): QueryBuilder<T>;
96
+ reset(): this;
95
97
  private loadCandidates;
96
98
  private createReadRequest;
97
99
  private matchesClause;
@@ -110,7 +112,7 @@ declare class QueryBuilder<T> {
110
112
  }
111
113
  interface KeyPathOptions {
112
114
  autoIncrement?: boolean;
113
- generator?: 'uuid' | 'timestamp' | 'random' | ((item?: any) => string | number);
115
+ generator?: 'uuid' | 'uuidv4' | 'uuidv6' | 'timestamp' | 'random' | ((item?: any) => string | number);
114
116
  }
115
117
  interface RetentionPolicyOptions {
116
118
  seconds: number;
@@ -127,6 +129,9 @@ interface KeyPathMetadata {
127
129
  options?: KeyPathOptions;
128
130
  }
129
131
  declare class KeyGenerators {
132
+ private static getRandomValues;
133
+ static uuidV4(): string;
134
+ static uuidV6(): string;
130
135
  static uuid(): string;
131
136
  static timestamp(): number;
132
137
  static random(): string;
@@ -135,6 +140,7 @@ declare function KeyPath(options?: KeyPathOptions): PropertyDecorator;
135
140
  declare function CompositeKeyPath(fields: string[], options?: KeyPathOptions): ClassDecorator;
136
141
  declare function Index(options?: IDBIndexParameters): PropertyDecorator;
137
142
  declare function Validate<T = any>(predicate: (value: any, item: T) => boolean, message: string): PropertyDecorator;
143
+ declare function Calculated<T = any>(compute: (item: T) => any): PropertyDecorator;
138
144
  declare function RetentionPolicy(options: RetentionPolicyOptions): ClassDecorator;
139
145
  interface DataClassOptions {
140
146
  version?: number;
@@ -151,10 +157,11 @@ interface EntityRepository<T> {
151
157
  deleteWhere(predicate: (query: QueryBuilder<T>) => QueryBuilder<T> | void): Promise<void>;
152
158
  list(): Promise<T[]>;
153
159
  listPaginated(page: number, pageSize: number): Promise<T[]>;
154
- findByIndex(indexName: string, value: any): Promise<T[]>;
155
- findOneByIndex(indexName: string, value: any): Promise<T | undefined>;
160
+ findByIndex(indexName: string, value: IDBValidKey): Promise<T[]>;
161
+ findOneByIndex(indexName: string, value: IDBValidKey): Promise<T | undefined>;
156
162
  count(): Promise<number>;
157
- exists(key: string): Promise<boolean>;
163
+ getKeys(): Promise<IDBValidKey[]>;
164
+ exists(key: string | string[] | number): Promise<boolean>;
158
165
  clear(): Promise<void>;
159
166
  query(): QueryBuilder<T>;
160
167
  }
@@ -164,9 +171,15 @@ interface TransactionController {
164
171
  }
165
172
  type TransactionalDatabase<T extends Record<string, EntityRepository<any>>> = T & TransactionController;
166
173
  type DatabaseWithRepositories<T extends Record<string, any>> = Database & T;
174
+ interface SyncAdapter {
175
+ push(entityName: string, records: unknown[]): Promise<void>;
176
+ pull(entityName: string): Promise<unknown[] | undefined>;
177
+ }
167
178
  declare class Database {
168
179
  private dbName;
169
180
  private classes;
181
+ private schemas;
182
+ private migrator;
170
183
  private db;
171
184
  private entityRepositories;
172
185
  private dbVersion;
@@ -177,7 +190,8 @@ declare class Database {
177
190
  private printDebug;
178
191
  private printError;
179
192
  private constructor();
180
- private calculateDatabaseVersion;
193
+ private readPersistedVersion;
194
+ private openConnection;
181
195
  static build<T extends Record<string, EntityRepository<any>>>(dbName: string, classes: Function[]): Promise<DatabaseWithRepositories<T>>;
182
196
  private initDB;
183
197
  private generateEntityRepositories;
@@ -190,11 +204,17 @@ declare class Database {
190
204
  private createTransactionHandle;
191
205
  beginTransaction(entityNames: string[], mode?: IDBTransactionMode): Promise<TransactionalDatabase<Record<string, EntityRepository<any>>>>;
192
206
  transaction<T>(callback: (tx: TransactionalDatabase<Record<string, EntityRepository<any>>>) => Promise<T> | T): Promise<T>;
207
+ exportDatabase(): Promise<Record<string, unknown[]>>;
208
+ importDatabase(dump: Record<string, unknown[]>, options?: {
209
+ clear?: boolean;
210
+ }): Promise<void>;
211
+ pushTo(adapter: SyncAdapter): Promise<void>;
212
+ pullFrom(adapter: SyncAdapter): Promise<void>;
193
213
  close(): void;
194
214
  getAvailableEntities(): string[];
195
215
  getDatabaseVersion(): number;
196
216
  getEntityVersions(): Map<string, number>;
197
217
  getEntityVersion(entityName: string): number | undefined;
198
218
  }
199
- export { Database, KeyPath, CompositeKeyPath, DataClass, Index, Validate, RetentionPolicy, EntityRepository, KeyGenerators, };
200
- export type { DatabaseWithRepositories, DataClassOptions, KeyPathOptions, KeyPathMetadata, RetentionPolicyOptions, RetentionPolicyMetadata, };
219
+ export { Database, KeyPath, CompositeKeyPath, DataClass, Index, Validate, Calculated, RetentionPolicy, EntityRepository, KeyGenerators, };
220
+ export type { DatabaseWithRepositories, DataClassOptions, KeyPathOptions, KeyPathMetadata, RetentionPolicyOptions, RetentionPolicyMetadata, SyncAdapter, };