idb-ts 3.14.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/README.md +395 -84
- package/lib/index.cjs +457 -102
- package/lib/index.d.ts +31 -8
- package/lib/index.esm.js +457 -103
- package/lib/index.js +457 -103
- package/package.json +15 -12
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:
|
|
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:
|
|
155
|
-
findOneByIndex(indexName: string, value:
|
|
160
|
+
findByIndex(indexName: string, value: IDBValidKey): Promise<T[]>;
|
|
161
|
+
findOneByIndex(indexName: string, value: IDBValidKey): Promise<T | undefined>;
|
|
156
162
|
count(): Promise<number>;
|
|
157
|
-
|
|
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,17 +171,27 @@ 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;
|
|
173
186
|
private retentionTimer;
|
|
174
187
|
private retentionCleanupRunning;
|
|
175
188
|
private retentionPolicies;
|
|
189
|
+
private printEnabled;
|
|
190
|
+
private printDebug;
|
|
191
|
+
private printError;
|
|
176
192
|
private constructor();
|
|
177
|
-
private
|
|
193
|
+
private readPersistedVersion;
|
|
194
|
+
private openConnection;
|
|
178
195
|
static build<T extends Record<string, EntityRepository<any>>>(dbName: string, classes: Function[]): Promise<DatabaseWithRepositories<T>>;
|
|
179
196
|
private initDB;
|
|
180
197
|
private generateEntityRepositories;
|
|
@@ -187,11 +204,17 @@ declare class Database {
|
|
|
187
204
|
private createTransactionHandle;
|
|
188
205
|
beginTransaction(entityNames: string[], mode?: IDBTransactionMode): Promise<TransactionalDatabase<Record<string, EntityRepository<any>>>>;
|
|
189
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>;
|
|
190
213
|
close(): void;
|
|
191
214
|
getAvailableEntities(): string[];
|
|
192
215
|
getDatabaseVersion(): number;
|
|
193
216
|
getEntityVersions(): Map<string, number>;
|
|
194
217
|
getEntityVersion(entityName: string): number | undefined;
|
|
195
218
|
}
|
|
196
|
-
export { Database, KeyPath, CompositeKeyPath, DataClass, Index, Validate, RetentionPolicy, EntityRepository, KeyGenerators, };
|
|
197
|
-
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, };
|