QueueStore.d.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 manage storing requests from a Queue in IndexedDB,
  15. * indexed by their queue name for easier access.
  16. *
  17. * @private
  18. */
  19. export declare class QueueStore {
  20. private readonly _queueName;
  21. private readonly _db;
  22. /**
  23. * Associates this instance with a Queue instance, so entries added can be
  24. * identified by their queue name.
  25. *
  26. * @param {string} queueName
  27. * @private
  28. */
  29. constructor(queueName: string);
  30. /**
  31. * Append an entry last in the queue.
  32. *
  33. * @param {Object} entry
  34. * @param {Object} entry.requestData
  35. * @param {number} [entry.timestamp]
  36. * @param {Object} [entry.metadata]
  37. * @private
  38. */
  39. pushEntry(entry: UnidentifiedQueueStoreEntry): Promise<void>;
  40. /**
  41. * Prepend an entry first in the queue.
  42. *
  43. * @param {Object} entry
  44. * @param {Object} entry.requestData
  45. * @param {number} [entry.timestamp]
  46. * @param {Object} [entry.metadata]
  47. * @private
  48. */
  49. unshiftEntry(entry: UnidentifiedQueueStoreEntry): Promise<void>;
  50. /**
  51. * Removes and returns the last entry in the queue matching the `queueName`.
  52. *
  53. * @return {Promise<Object>}
  54. * @private
  55. */
  56. popEntry(): Promise<QueueStoreEntry>;
  57. /**
  58. * Removes and returns the first entry in the queue matching the `queueName`.
  59. *
  60. * @return {Promise<Object>}
  61. * @private
  62. */
  63. shiftEntry(): Promise<QueueStoreEntry>;
  64. /**
  65. * Returns all entries in the store matching the `queueName`.
  66. *
  67. * @param {Object} options See {@link module:workbox-background-sync.Queue~getAll}
  68. * @return {Promise<Array<Object>>}
  69. * @private
  70. */
  71. getAll(): Promise<QueueStoreEntry[]>;
  72. /**
  73. * Deletes the entry for the given ID.
  74. *
  75. * WARNING: this method does not ensure the deleted enry belongs to this
  76. * queue (i.e. matches the `queueName`). But this limitation is acceptable
  77. * as this class is not publicly exposed. An additional check would make
  78. * this method slower than it needs to be.
  79. *
  80. * @private
  81. * @param {number} id
  82. */
  83. deleteEntry(id: number): Promise<void>;
  84. /**
  85. * Removes and returns the first or last entry in the queue (based on the
  86. * `direction` argument) matching the `queueName`.
  87. *
  88. * @return {Promise<Object>}
  89. * @private
  90. */
  91. _removeEntry({ direction }: {
  92. direction?: IDBCursorDirection;
  93. }): Promise<any>;
  94. /**
  95. * Upgrades the database given an `upgradeneeded` event.
  96. *
  97. * @param {Event} event
  98. * @private
  99. */
  100. private _upgradeDb;
  101. }