Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

entry.d.ts 31KB

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