UNPKG

32.6 kBTypeScriptView Raw
1export interface OpenDBCallbacks<DBTypes extends DBSchema | unknown> {
2 /**
3 * Called if this version of the database has never been opened before. Use it to specify the
4 * schema for the database.
5 *
6 * @param database A database instance that you can use to add/remove stores and indexes.
7 * @param oldVersion Last version of the database opened by the user.
8 * @param newVersion Whatever new version you provided.
9 * @param transaction The transaction for this upgrade.
10 * This is useful if you need to get data from other stores as part of a migration.
11 * @param event The event object for the associated 'upgradeneeded' event.
12 */
13 upgrade?(database: IDBPDatabase<DBTypes>, oldVersion: number, newVersion: number | null, transaction: IDBPTransaction<DBTypes, StoreNames<DBTypes>[], 'versionchange'>, event: IDBVersionChangeEvent): void;
14 /**
15 * Called if there are older versions of the database open on the origin, so this version cannot
16 * open.
17 *
18 * @param currentVersion Version of the database that's blocking this one.
19 * @param blockedVersion The version of the database being blocked (whatever version you provided to `openDB`).
20 * @param event The event object for the associated `blocked` event.
21 */
22 blocked?(currentVersion: number, blockedVersion: number | null, event: IDBVersionChangeEvent): void;
23 /**
24 * Called if this connection is blocking a future version of the database from opening.
25 *
26 * @param currentVersion Version of the open database (whatever version you provided to `openDB`).
27 * @param blockedVersion The version of the database that's being blocked.
28 * @param event The event object for the associated `versionchange` event.
29 */
30 blocking?(currentVersion: number, blockedVersion: number | null, event: IDBVersionChangeEvent): void;
31 /**
32 * Called if the browser abnormally terminates the connection.
33 * This is not called when `db.close()` is called.
34 */
35 terminated?(): void;
36}
37/**
38 * Open a database.
39 *
40 * @param name Name of the database.
41 * @param version Schema version.
42 * @param callbacks Additional callbacks.
43 */
44export declare function openDB<DBTypes extends DBSchema | unknown = unknown>(name: string, version?: number, { blocked, upgrade, blocking, terminated }?: OpenDBCallbacks<DBTypes>): Promise<IDBPDatabase<DBTypes>>;
45export interface DeleteDBCallbacks {
46 /**
47 * Called if there are connections to this database open, so it cannot be deleted.
48 *
49 * @param currentVersion Version of the database that's blocking the delete operation.
50 * @param event The event object for the associated `blocked` event.
51 */
52 blocked?(currentVersion: number, event: IDBVersionChangeEvent): void;
53}
54/**
55 * Delete a database.
56 *
57 * @param name Name of the database.
58 */
59export declare function deleteDB(name: string, { blocked }?: DeleteDBCallbacks): Promise<void>;
60export { unwrap, wrap } from './wrap-idb-value.js';
61declare type KeyToKeyNoIndex<T> = {
62 [K in keyof T]: string extends K ? never : number extends K ? never : K;
63};
64declare type ValuesOf<T> = T extends {
65 [K in keyof T]: infer U;
66} ? U : never;
67declare type KnownKeys<T> = ValuesOf<KeyToKeyNoIndex<T>>;
68declare type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
69export interface DBSchema {
70 [s: string]: DBSchemaValue;
71}
72interface IndexKeys {
73 [s: string]: IDBValidKey;
74}
75interface DBSchemaValue {
76 key: IDBValidKey;
77 value: any;
78 indexes?: IndexKeys;
79}
80/**
81 * Extract known object store names from the DB schema type.
82 *
83 * @template DBTypes DB schema type, or unknown if the DB isn't typed.
84 */
85export declare type StoreNames<DBTypes extends DBSchema | unknown> = DBTypes extends DBSchema ? KnownKeys<DBTypes> : string;
86/**
87 * Extract database value types from the DB schema type.
88 *
89 * @template DBTypes DB schema type, or unknown if the DB isn't typed.
90 * @template StoreName Names of the object stores to get the types of.
91 */
92export declare type StoreValue<DBTypes extends DBSchema | unknown, StoreName extends StoreNames<DBTypes>> = DBTypes extends DBSchema ? DBTypes[StoreName]['value'] : any;
93/**
94 * Extract database key types from the DB schema type.
95 *
96 * @template DBTypes DB schema type, or unknown if the DB isn't typed.
97 * @template StoreName Names of the object stores to get the types of.
98 */
99export declare type StoreKey<DBTypes extends DBSchema | unknown, StoreName extends StoreNames<DBTypes>> = DBTypes extends DBSchema ? DBTypes[StoreName]['key'] : IDBValidKey;
100/**
101 * Extract the names of indexes in certain object stores from the DB schema type.
102 *
103 * @template DBTypes DB schema type, or unknown if the DB isn't typed.
104 * @template StoreName Names of the object stores to get the types of.
105 */
106export declare type IndexNames<DBTypes extends DBSchema | unknown, StoreName extends StoreNames<DBTypes>> = DBTypes extends DBSchema ? keyof DBTypes[StoreName]['indexes'] : string;
107/**
108 * Extract the types of indexes in certain object stores from the DB schema type.
109 *
110 * @template DBTypes DB schema type, or unknown if the DB isn't typed.
111 * @template StoreName Names of the object stores to get the types of.
112 * @template IndexName Names of the indexes to get the types of.
113 */
114export declare type IndexKey<DBTypes extends DBSchema | unknown, StoreName extends StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName>> = DBTypes extends DBSchema ? IndexName extends keyof DBTypes[StoreName]['indexes'] ? DBTypes[StoreName]['indexes'][IndexName] : IDBValidKey : IDBValidKey;
115declare type CursorSource<DBTypes extends DBSchema | unknown, TxStores extends ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> | unknown, Mode extends IDBTransactionMode = 'readonly'> = IndexName extends IndexNames<DBTypes, StoreName> ? IDBPIndex<DBTypes, TxStores, StoreName, IndexName, Mode> : IDBPObjectStore<DBTypes, TxStores, StoreName, Mode>;
116declare type CursorKey<DBTypes extends DBSchema | unknown, StoreName extends StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> | unknown> = IndexName extends IndexNames<DBTypes, StoreName> ? IndexKey<DBTypes, StoreName, IndexName> : StoreKey<DBTypes, StoreName>;
117declare type IDBPDatabaseExtends = Omit<IDBDatabase, 'createObjectStore' | 'deleteObjectStore' | 'transaction' | 'objectStoreNames'>;
118/**
119 * A variation of DOMStringList with precise string types
120 */
121export interface TypedDOMStringList<T extends string> extends DOMStringList {
122 contains(string: T): boolean;
123 item(index: number): T | null;
124 [index: number]: T;
125 [Symbol.iterator](): IterableIterator<T>;
126}
127interface IDBTransactionOptions {
128 /**
129 * The durability of the transaction.
130 *
131 * The default is "default". Using "relaxed" provides better performance, but with fewer
132 * guarantees. Web applications are encouraged to use "relaxed" for ephemeral data such as caches
133 * or quickly changing records, and "strict" in cases where reducing the risk of data loss
134 * outweighs the impact to performance and power.
135 */
136 durability?: 'default' | 'strict' | 'relaxed';
137}
138export interface IDBPDatabase<DBTypes extends DBSchema | unknown = unknown> extends IDBPDatabaseExtends {
139 /**
140 * The names of stores in the database.
141 */
142 readonly objectStoreNames: TypedDOMStringList<StoreNames<DBTypes>>;
143 /**
144 * Creates a new object store.
145 *
146 * Throws a "InvalidStateError" DOMException if not called within an upgrade transaction.
147 */
148 createObjectStore<Name extends StoreNames<DBTypes>>(name: Name, optionalParameters?: IDBObjectStoreParameters): IDBPObjectStore<DBTypes, ArrayLike<StoreNames<DBTypes>>, Name, 'versionchange'>;
149 /**
150 * Deletes the object store with the given name.
151 *
152 * Throws a "InvalidStateError" DOMException if not called within an upgrade transaction.
153 */
154 deleteObjectStore(name: StoreNames<DBTypes>): void;
155 /**
156 * Start a new transaction.
157 *
158 * @param storeNames The object store(s) this transaction needs.
159 * @param mode
160 * @param options
161 */
162 transaction<Name extends StoreNames<DBTypes>, Mode extends IDBTransactionMode = 'readonly'>(storeNames: Name, mode?: Mode, options?: IDBTransactionOptions): IDBPTransaction<DBTypes, [Name], Mode>;
163 transaction<Names extends ArrayLike<StoreNames<DBTypes>>, Mode extends IDBTransactionMode = 'readonly'>(storeNames: Names, mode?: Mode, options?: IDBTransactionOptions): IDBPTransaction<DBTypes, Names, Mode>;
164 /**
165 * Add a value to a store.
166 *
167 * Rejects if an item of a given key already exists in the store.
168 *
169 * This is a shortcut that creates a transaction for this single action. If you need to do more
170 * than one action, create a transaction instead.
171 *
172 * @param storeName Name of the store.
173 * @param value
174 * @param key
175 */
176 add<Name extends StoreNames<DBTypes>>(storeName: Name, value: StoreValue<DBTypes, Name>, key?: StoreKey<DBTypes, Name> | IDBKeyRange): Promise<StoreKey<DBTypes, Name>>;
177 /**
178 * Deletes all records in a store.
179 *
180 * This is a shortcut that creates a transaction for this single action. If you need to do more
181 * than one action, create a transaction instead.
182 *
183 * @param storeName Name of the store.
184 */
185 clear(name: StoreNames<DBTypes>): Promise<void>;
186 /**
187 * Retrieves the number of records matching the given query in a store.
188 *
189 * This is a shortcut that creates a transaction for this single action. If you need to do more
190 * than one action, create a transaction instead.
191 *
192 * @param storeName Name of the store.
193 * @param key
194 */
195 count<Name extends StoreNames<DBTypes>>(storeName: Name, key?: StoreKey<DBTypes, Name> | IDBKeyRange | null): Promise<number>;
196 /**
197 * Retrieves the number of records matching the given query in an index.
198 *
199 * This is a shortcut that creates a transaction for this single action. If you need to do more
200 * than one action, create a transaction instead.
201 *
202 * @param storeName Name of the store.
203 * @param indexName Name of the index within the store.
204 * @param key
205 */
206 countFromIndex<Name extends StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, Name>>(storeName: Name, indexName: IndexName, key?: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange | null): Promise<number>;
207 /**
208 * Deletes records in a store matching the given query.
209 *
210 * This is a shortcut that creates a transaction for this single action. If you need to do more
211 * than one action, create a transaction instead.
212 *
213 * @param storeName Name of the store.
214 * @param key
215 */
216 delete<Name extends StoreNames<DBTypes>>(storeName: Name, key: StoreKey<DBTypes, Name> | IDBKeyRange): Promise<void>;
217 /**
218 * Retrieves the value of the first record in a store matching the query.
219 *
220 * Resolves with undefined if no match is found.
221 *
222 * This is a shortcut that creates a transaction for this single action. If you need to do more
223 * than one action, create a transaction instead.
224 *
225 * @param storeName Name of the store.
226 * @param query
227 */
228 get<Name extends StoreNames<DBTypes>>(storeName: Name, query: StoreKey<DBTypes, Name> | IDBKeyRange): Promise<StoreValue<DBTypes, Name> | undefined>;
229 /**
230 * Retrieves the value of the first record in an index matching the query.
231 *
232 * Resolves with undefined if no match is found.
233 *
234 * This is a shortcut that creates a transaction for this single action. If you need to do more
235 * than one action, create a transaction instead.
236 *
237 * @param storeName Name of the store.
238 * @param indexName Name of the index within the store.
239 * @param query
240 */
241 getFromIndex<Name extends StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, Name>>(storeName: Name, indexName: IndexName, query: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange): Promise<StoreValue<DBTypes, Name> | undefined>;
242 /**
243 * Retrieves all values in a store that match the query.
244 *
245 * This is a shortcut that creates a transaction for this single action. If you need to do more
246 * than one action, create a transaction instead.
247 *
248 * @param storeName Name of the store.
249 * @param query
250 * @param count Maximum number of values to return.
251 */
252 getAll<Name extends StoreNames<DBTypes>>(storeName: Name, query?: StoreKey<DBTypes, Name> | IDBKeyRange | null, count?: number): Promise<StoreValue<DBTypes, Name>[]>;
253 /**
254 * Retrieves all values in an index that match the query.
255 *
256 * This is a shortcut that creates a transaction for this single action. If you need to do more
257 * than one action, create a transaction instead.
258 *
259 * @param storeName Name of the store.
260 * @param indexName Name of the index within the store.
261 * @param query
262 * @param count Maximum number of values to return.
263 */
264 getAllFromIndex<Name extends StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, Name>>(storeName: Name, indexName: IndexName, query?: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange | null, count?: number): Promise<StoreValue<DBTypes, Name>[]>;
265 /**
266 * Retrieves the keys of records in a store matching the query.
267 *
268 * This is a shortcut that creates a transaction for this single action. If you need to do more
269 * than one action, create a transaction instead.
270 *
271 * @param storeName Name of the store.
272 * @param query
273 * @param count Maximum number of keys to return.
274 */
275 getAllKeys<Name extends StoreNames<DBTypes>>(storeName: Name, query?: StoreKey<DBTypes, Name> | IDBKeyRange | null, count?: number): Promise<StoreKey<DBTypes, Name>[]>;
276 /**
277 * Retrieves the keys of records in an index matching the query.
278 *
279 * This is a shortcut that creates a transaction for this single action. If you need to do more
280 * than one action, create a transaction instead.
281 *
282 * @param storeName Name of the store.
283 * @param indexName Name of the index within the store.
284 * @param query
285 * @param count Maximum number of keys to return.
286 */
287 getAllKeysFromIndex<Name extends StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, Name>>(storeName: Name, indexName: IndexName, query?: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange | null, count?: number): Promise<StoreKey<DBTypes, Name>[]>;
288 /**
289 * Retrieves the key of the first record in a store that matches the query.
290 *
291 * Resolves with undefined if no match is found.
292 *
293 * This is a shortcut that creates a transaction for this single action. If you need to do more
294 * than one action, create a transaction instead.
295 *
296 * @param storeName Name of the store.
297 * @param query
298 */
299 getKey<Name extends StoreNames<DBTypes>>(storeName: Name, query: StoreKey<DBTypes, Name> | IDBKeyRange): Promise<StoreKey<DBTypes, Name> | undefined>;
300 /**
301 * Retrieves the key of the first record in an index that matches the query.
302 *
303 * Resolves with undefined if no match is found.
304 *
305 * This is a shortcut that creates a transaction for this single action. If you need to do more
306 * than one action, create a transaction instead.
307 *
308 * @param storeName Name of the store.
309 * @param indexName Name of the index within the store.
310 * @param query
311 */
312 getKeyFromIndex<Name extends StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, Name>>(storeName: Name, indexName: IndexName, query: IndexKey<DBTypes, Name, IndexName> | IDBKeyRange): Promise<StoreKey<DBTypes, Name> | undefined>;
313 /**
314 * Put an item in the database.
315 *
316 * Replaces any item with the same key.
317 *
318 * This is a shortcut that creates a transaction for this single action. If you need to do more
319 * than one action, create a transaction instead.
320 *
321 * @param storeName Name of the store.
322 * @param value
323 * @param key
324 */
325 put<Name extends StoreNames<DBTypes>>(storeName: Name, value: StoreValue<DBTypes, Name>, key?: StoreKey<DBTypes, Name> | IDBKeyRange): Promise<StoreKey<DBTypes, Name>>;
326}
327declare type IDBPTransactionExtends = Omit<IDBTransaction, 'db' | 'objectStore' | 'objectStoreNames'>;
328export interface IDBPTransaction<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, Mode extends IDBTransactionMode = 'readonly'> extends IDBPTransactionExtends {
329 /**
330 * The transaction's mode.
331 */
332 readonly mode: Mode;
333 /**
334 * The names of stores in scope for this transaction.
335 */
336 readonly objectStoreNames: TypedDOMStringList<TxStores[number]>;
337 /**
338 * The transaction's connection.
339 */
340 readonly db: IDBPDatabase<DBTypes>;
341 /**
342 * Promise for the completion of this transaction.
343 */
344 readonly done: Promise<void>;
345 /**
346 * The associated object store, if the transaction covers a single store, otherwise undefined.
347 */
348 readonly store: TxStores[1] extends undefined ? IDBPObjectStore<DBTypes, TxStores, TxStores[0], Mode> : undefined;
349 /**
350 * Returns an IDBObjectStore in the transaction's scope.
351 */
352 objectStore<StoreName extends TxStores[number]>(name: StoreName): IDBPObjectStore<DBTypes, TxStores, StoreName, Mode>;
353}
354declare type IDBPObjectStoreExtends = Omit<IDBObjectStore, 'transaction' | 'add' | 'clear' | 'count' | 'createIndex' | 'delete' | 'get' | 'getAll' | 'getAllKeys' | 'getKey' | 'index' | 'openCursor' | 'openKeyCursor' | 'put' | 'indexNames'>;
355export interface IDBPObjectStore<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>, Mode extends IDBTransactionMode = 'readonly'> extends IDBPObjectStoreExtends {
356 /**
357 * The names of indexes in the store.
358 */
359 readonly indexNames: TypedDOMStringList<IndexNames<DBTypes, StoreName>>;
360 /**
361 * The associated transaction.
362 */
363 readonly transaction: IDBPTransaction<DBTypes, TxStores, Mode>;
364 /**
365 * Add a value to the store.
366 *
367 * Rejects if an item of a given key already exists in the store.
368 */
369 add: Mode extends 'readonly' ? undefined : (value: StoreValue<DBTypes, StoreName>, key?: StoreKey<DBTypes, StoreName> | IDBKeyRange) => Promise<StoreKey<DBTypes, StoreName>>;
370 /**
371 * Deletes all records in store.
372 */
373 clear: Mode extends 'readonly' ? undefined : () => Promise<void>;
374 /**
375 * Retrieves the number of records matching the given query.
376 */
377 count(key?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null): Promise<number>;
378 /**
379 * Creates a new index in store.
380 *
381 * Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.
382 */
383 createIndex: Mode extends 'versionchange' ? <IndexName extends IndexNames<DBTypes, StoreName>>(name: IndexName, keyPath: string | string[], options?: IDBIndexParameters) => IDBPIndex<DBTypes, TxStores, StoreName, IndexName, Mode> : undefined;
384 /**
385 * Deletes records in store matching the given query.
386 */
387 delete: Mode extends 'readonly' ? undefined : (key: StoreKey<DBTypes, StoreName> | IDBKeyRange) => Promise<void>;
388 /**
389 * Retrieves the value of the first record matching the query.
390 *
391 * Resolves with undefined if no match is found.
392 */
393 get(query: StoreKey<DBTypes, StoreName> | IDBKeyRange): Promise<StoreValue<DBTypes, StoreName> | undefined>;
394 /**
395 * Retrieves all values that match the query.
396 *
397 * @param query
398 * @param count Maximum number of values to return.
399 */
400 getAll(query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null, count?: number): Promise<StoreValue<DBTypes, StoreName>[]>;
401 /**
402 * Retrieves the keys of records matching the query.
403 *
404 * @param query
405 * @param count Maximum number of keys to return.
406 */
407 getAllKeys(query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null, count?: number): Promise<StoreKey<DBTypes, StoreName>[]>;
408 /**
409 * Retrieves the key of the first record that matches the query.
410 *
411 * Resolves with undefined if no match is found.
412 */
413 getKey(query: StoreKey<DBTypes, StoreName> | IDBKeyRange): Promise<StoreKey<DBTypes, StoreName> | undefined>;
414 /**
415 * Get a query of a given name.
416 */
417 index<IndexName extends IndexNames<DBTypes, StoreName>>(name: IndexName): IDBPIndex<DBTypes, TxStores, StoreName, IndexName, Mode>;
418 /**
419 * Opens a cursor over the records matching the query.
420 *
421 * Resolves with null if no matches are found.
422 *
423 * @param query If null, all records match.
424 * @param direction
425 */
426 openCursor(query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null, direction?: IDBCursorDirection): Promise<IDBPCursorWithValue<DBTypes, TxStores, StoreName, unknown, Mode> | null>;
427 /**
428 * Opens a cursor over the keys matching the query.
429 *
430 * Resolves with null if no matches are found.
431 *
432 * @param query If null, all records match.
433 * @param direction
434 */
435 openKeyCursor(query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null, direction?: IDBCursorDirection): Promise<IDBPCursor<DBTypes, TxStores, StoreName, unknown, Mode> | null>;
436 /**
437 * Put an item in the store.
438 *
439 * Replaces any item with the same key.
440 */
441 put: Mode extends 'readonly' ? undefined : (value: StoreValue<DBTypes, StoreName>, key?: StoreKey<DBTypes, StoreName> | IDBKeyRange) => Promise<StoreKey<DBTypes, StoreName>>;
442 /**
443 * Iterate over the store.
444 */
445 [Symbol.asyncIterator](): AsyncIterableIterator<IDBPCursorWithValueIteratorValue<DBTypes, TxStores, StoreName, unknown, Mode>>;
446 /**
447 * Iterate over the records matching the query.
448 *
449 * @param query If null, all records match.
450 * @param direction
451 */
452 iterate(query?: StoreKey<DBTypes, StoreName> | IDBKeyRange | null, direction?: IDBCursorDirection): AsyncIterableIterator<IDBPCursorWithValueIteratorValue<DBTypes, TxStores, StoreName, unknown, Mode>>;
453}
454declare type IDBPIndexExtends = Omit<IDBIndex, 'objectStore' | 'count' | 'get' | 'getAll' | 'getAllKeys' | 'getKey' | 'openCursor' | 'openKeyCursor'>;
455export interface IDBPIndex<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> = IndexNames<DBTypes, StoreName>, Mode extends IDBTransactionMode = 'readonly'> extends IDBPIndexExtends {
456 /**
457 * The IDBObjectStore the index belongs to.
458 */
459 readonly objectStore: IDBPObjectStore<DBTypes, TxStores, StoreName, Mode>;
460 /**
461 * Retrieves the number of records matching the given query.
462 */
463 count(key?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null): Promise<number>;
464 /**
465 * Retrieves the value of the first record matching the query.
466 *
467 * Resolves with undefined if no match is found.
468 */
469 get(query: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange): Promise<StoreValue<DBTypes, StoreName> | undefined>;
470 /**
471 * Retrieves all values that match the query.
472 *
473 * @param query
474 * @param count Maximum number of values to return.
475 */
476 getAll(query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null, count?: number): Promise<StoreValue<DBTypes, StoreName>[]>;
477 /**
478 * Retrieves the keys of records matching the query.
479 *
480 * @param query
481 * @param count Maximum number of keys to return.
482 */
483 getAllKeys(query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null, count?: number): Promise<StoreKey<DBTypes, StoreName>[]>;
484 /**
485 * Retrieves the key of the first record that matches the query.
486 *
487 * Resolves with undefined if no match is found.
488 */
489 getKey(query: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange): Promise<StoreKey<DBTypes, StoreName> | undefined>;
490 /**
491 * Opens a cursor over the records matching the query.
492 *
493 * Resolves with null if no matches are found.
494 *
495 * @param query If null, all records match.
496 * @param direction
497 */
498 openCursor(query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null, direction?: IDBCursorDirection): Promise<IDBPCursorWithValue<DBTypes, TxStores, StoreName, IndexName, Mode> | null>;
499 /**
500 * Opens a cursor over the keys matching the query.
501 *
502 * Resolves with null if no matches are found.
503 *
504 * @param query If null, all records match.
505 * @param direction
506 */
507 openKeyCursor(query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null, direction?: IDBCursorDirection): Promise<IDBPCursor<DBTypes, TxStores, StoreName, IndexName, Mode> | null>;
508 /**
509 * Iterate over the index.
510 */
511 [Symbol.asyncIterator](): AsyncIterableIterator<IDBPCursorWithValueIteratorValue<DBTypes, TxStores, StoreName, IndexName, Mode>>;
512 /**
513 * Iterate over the records matching the query.
514 *
515 * Resolves with null if no matches are found.
516 *
517 * @param query If null, all records match.
518 * @param direction
519 */
520 iterate(query?: IndexKey<DBTypes, StoreName, IndexName> | IDBKeyRange | null, direction?: IDBCursorDirection): AsyncIterableIterator<IDBPCursorWithValueIteratorValue<DBTypes, TxStores, StoreName, IndexName, Mode>>;
521}
522declare type IDBPCursorExtends = Omit<IDBCursor, 'key' | 'primaryKey' | 'source' | 'advance' | 'continue' | 'continuePrimaryKey' | 'delete' | 'update'>;
523export interface IDBPCursor<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown, Mode extends IDBTransactionMode = 'readonly'> extends IDBPCursorExtends {
524 /**
525 * The key of the current index or object store item.
526 */
527 readonly key: CursorKey<DBTypes, StoreName, IndexName>;
528 /**
529 * The key of the current object store item.
530 */
531 readonly primaryKey: StoreKey<DBTypes, StoreName>;
532 /**
533 * Returns the IDBObjectStore or IDBIndex the cursor was opened from.
534 */
535 readonly source: CursorSource<DBTypes, TxStores, StoreName, IndexName, Mode>;
536 /**
537 * Advances the cursor a given number of records.
538 *
539 * Resolves to null if no matching records remain.
540 */
541 advance<T>(this: T, count: number): Promise<T | null>;
542 /**
543 * Advance the cursor by one record (unless 'key' is provided).
544 *
545 * Resolves to null if no matching records remain.
546 *
547 * @param key Advance to the index or object store with a key equal to or greater than this value.
548 */
549 continue<T>(this: T, key?: CursorKey<DBTypes, StoreName, IndexName>): Promise<T | null>;
550 /**
551 * Advance the cursor by given keys.
552 *
553 * The operation is 'and' – both keys must be satisfied.
554 *
555 * Resolves to null if no matching records remain.
556 *
557 * @param key Advance to the index or object store with a key equal to or greater than this value.
558 * @param primaryKey and where the object store has a key equal to or greater than this value.
559 */
560 continuePrimaryKey<T>(this: T, key: CursorKey<DBTypes, StoreName, IndexName>, primaryKey: StoreKey<DBTypes, StoreName>): Promise<T | null>;
561 /**
562 * Delete the current record.
563 */
564 delete: Mode extends 'readonly' ? undefined : () => Promise<void>;
565 /**
566 * Updated the current record.
567 */
568 update: Mode extends 'readonly' ? undefined : (value: StoreValue<DBTypes, StoreName>) => Promise<StoreKey<DBTypes, StoreName>>;
569 /**
570 * Iterate over the cursor.
571 */
572 [Symbol.asyncIterator](): AsyncIterableIterator<IDBPCursorIteratorValue<DBTypes, TxStores, StoreName, IndexName, Mode>>;
573}
574declare type IDBPCursorIteratorValueExtends<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown, Mode extends IDBTransactionMode = 'readonly'> = Omit<IDBPCursor<DBTypes, TxStores, StoreName, IndexName, Mode>, 'advance' | 'continue' | 'continuePrimaryKey'>;
575export interface IDBPCursorIteratorValue<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown, Mode extends IDBTransactionMode = 'readonly'> extends IDBPCursorIteratorValueExtends<DBTypes, TxStores, StoreName, IndexName, Mode> {
576 /**
577 * Advances the cursor a given number of records.
578 */
579 advance<T>(this: T, count: number): void;
580 /**
581 * Advance the cursor by one record (unless 'key' is provided).
582 *
583 * @param key Advance to the index or object store with a key equal to or greater than this value.
584 */
585 continue<T>(this: T, key?: CursorKey<DBTypes, StoreName, IndexName>): void;
586 /**
587 * Advance the cursor by given keys.
588 *
589 * The operation is 'and' – both keys must be satisfied.
590 *
591 * @param key Advance to the index or object store with a key equal to or greater than this value.
592 * @param primaryKey and where the object store has a key equal to or greater than this value.
593 */
594 continuePrimaryKey<T>(this: T, key: CursorKey<DBTypes, StoreName, IndexName>, primaryKey: StoreKey<DBTypes, StoreName>): void;
595}
596export interface IDBPCursorWithValue<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown, Mode extends IDBTransactionMode = 'readonly'> extends IDBPCursor<DBTypes, TxStores, StoreName, IndexName, Mode> {
597 /**
598 * The value of the current item.
599 */
600 readonly value: StoreValue<DBTypes, StoreName>;
601 /**
602 * Iterate over the cursor.
603 */
604 [Symbol.asyncIterator](): AsyncIterableIterator<IDBPCursorWithValueIteratorValue<DBTypes, TxStores, StoreName, IndexName, Mode>>;
605}
606declare type IDBPCursorWithValueIteratorValueExtends<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown, Mode extends IDBTransactionMode = 'readonly'> = Omit<IDBPCursorWithValue<DBTypes, TxStores, StoreName, IndexName, Mode>, 'advance' | 'continue' | 'continuePrimaryKey'>;
607export interface IDBPCursorWithValueIteratorValue<DBTypes extends DBSchema | unknown = unknown, TxStores extends ArrayLike<StoreNames<DBTypes>> = ArrayLike<StoreNames<DBTypes>>, StoreName extends StoreNames<DBTypes> = StoreNames<DBTypes>, IndexName extends IndexNames<DBTypes, StoreName> | unknown = unknown, Mode extends IDBTransactionMode = 'readonly'> extends IDBPCursorWithValueIteratorValueExtends<DBTypes, TxStores, StoreName, IndexName, Mode> {
608 /**
609 * Advances the cursor a given number of records.
610 */
611 advance<T>(this: T, count: number): void;
612 /**
613 * Advance the cursor by one record (unless 'key' is provided).
614 *
615 * @param key Advance to the index or object store with a key equal to or greater than this value.
616 */
617 continue<T>(this: T, key?: CursorKey<DBTypes, StoreName, IndexName>): void;
618 /**
619 * Advance the cursor by given keys.
620 *
621 * The operation is 'and' – both keys must be satisfied.
622 *
623 * @param key Advance to the index or object store with a key equal to or greater than this value.
624 * @param primaryKey and where the object store has a key equal to or greater than this value.
625 */
626 continuePrimaryKey<T>(this: T, key: CursorKey<DBTypes, StoreName, IndexName>, primaryKey: StoreKey<DBTypes, StoreName>): void;
627}