QueueDb.d.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { RequestData } from './StorableRequest.js';
  2. import '../_version.js';
  3. export interface UnidentifiedQueueStoreEntry {
  4. requestData: RequestData;
  5. timestamp: number;
  6. id?: number;
  7. queueName?: string;
  8. metadata?: object;
  9. }
  10. export interface QueueStoreEntry extends UnidentifiedQueueStoreEntry {
  11. id: number;
  12. }
  13. /**
  14. * A class to interact directly an IndexedDB created specifically to save and
  15. * retrieve QueueStoreEntries. This class encapsulates all the schema details
  16. * to store the representation of a Queue.
  17. *
  18. * @private
  19. */
  20. export declare class QueueDb {
  21. private _db;
  22. /**
  23. * Add QueueStoreEntry to underlying db.
  24. *
  25. * @param {UnidentifiedQueueStoreEntry} entry
  26. */
  27. addEntry(entry: UnidentifiedQueueStoreEntry): Promise<void>;
  28. /**
  29. * Returns the first entry id in the ObjectStore.
  30. *
  31. * @return {number | undefined}
  32. */
  33. getFirstEntryId(): Promise<number | undefined>;
  34. /**
  35. * Get all the entries filtered by index
  36. *
  37. * @param queueName
  38. * @return {Promise<QueueStoreEntry[]>}
  39. */
  40. getAllEntriesByQueueName(queueName: string): Promise<QueueStoreEntry[]>;
  41. /**
  42. * Returns the number of entries filtered by index
  43. *
  44. * @param queueName
  45. * @return {Promise<number>}
  46. */
  47. getEntryCountByQueueName(queueName: string): Promise<number>;
  48. /**
  49. * Deletes a single entry by id.
  50. *
  51. * @param {number} id the id of the entry to be deleted
  52. */
  53. deleteEntry(id: number): Promise<void>;
  54. /**
  55. *
  56. * @param queueName
  57. * @returns {Promise<QueueStoreEntry | undefined>}
  58. */
  59. getFirstEntryByQueueName(queueName: string): Promise<QueueStoreEntry | undefined>;
  60. /**
  61. *
  62. * @param queueName
  63. * @returns {Promise<QueueStoreEntry | undefined>}
  64. */
  65. getLastEntryByQueueName(queueName: string): Promise<QueueStoreEntry | undefined>;
  66. /**
  67. * Returns either the first or the last entries, depending on direction.
  68. * Filtered by index.
  69. *
  70. * @param {IDBCursorDirection} direction
  71. * @param {IDBKeyRange} query
  72. * @return {Promise<QueueStoreEntry | undefined>}
  73. * @private
  74. */
  75. getEndEntryFromIndex(query: IDBKeyRange, direction: IDBCursorDirection): Promise<QueueStoreEntry | undefined>;
  76. /**
  77. * Returns an open connection to the database.
  78. *
  79. * @private
  80. */
  81. private getDb;
  82. /**
  83. * Upgrades QueueDB
  84. *
  85. * @param {IDBPDatabase<QueueDBSchema>} db
  86. * @param {number} oldVersion
  87. * @private
  88. */
  89. private _upgradeDb;
  90. }