Source: lib/offline/i_storage_engine.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. goog.provide('shaka.offline.IStorageEngine');
  18. goog.require('shaka.util.IDestroyable');
  19. /**
  20. * An interface to abstract away the type of storage used on a specific
  21. * platform.
  22. *
  23. * @interface
  24. * @extends {shaka.util.IDestroyable}
  25. */
  26. shaka.offline.IStorageEngine = function() {};
  27. /**
  28. * Gets whether the storage engine is initialized.
  29. *
  30. * @return {boolean}
  31. */
  32. shaka.offline.IStorageEngine.prototype.initialized;
  33. /**
  34. * Initializes the storage system and creates the required tables.
  35. *
  36. * If opt_retryCount is given, then we are creating a new database and expect
  37. * an 'upgradeneeded' event. If we don't get one, we will retry opt_retryCount
  38. * times. This is used to work around a bug in IE/Edge and is only used in
  39. * our unit tests.
  40. *
  41. * @see https://goo.gl/hOYJvN
  42. *
  43. * @param {!Object.<string, string>} storeMap
  44. * A map of store name to the key path.
  45. * @param {number=} opt_retryCount
  46. * @return {!Promise}
  47. */
  48. shaka.offline.IStorageEngine.prototype.init;
  49. /**
  50. * Gets the item with the given ID in the store.
  51. *
  52. * @param {string} storeName
  53. * @param {number} key
  54. * @return {!Promise.<T>}
  55. * @template T
  56. */
  57. shaka.offline.IStorageEngine.prototype.get;
  58. /**
  59. * Calls the given callback for each value in the store. The promise will
  60. * resolve after all items have been traversed.
  61. *
  62. * @param {string} storeName
  63. * @param {function(T)} callback
  64. * @return {!Promise}
  65. * @template T
  66. */
  67. shaka.offline.IStorageEngine.prototype.forEach;
  68. /**
  69. * Adds or updates the given value in the store.
  70. *
  71. * @param {string} storeName
  72. * @param {!Object} value
  73. * @return {!Promise}
  74. */
  75. shaka.offline.IStorageEngine.prototype.insert;
  76. /**
  77. * Removes the item with the given key.
  78. *
  79. * @param {string} storeName
  80. * @param {number} key
  81. * @return {!Promise}
  82. */
  83. shaka.offline.IStorageEngine.prototype.remove;
  84. /**
  85. * Removes the elements with the given keys.
  86. *
  87. * @param {string} storeName
  88. * @param {!Array<number>} keys
  89. * @param {function()=} opt_onKeyRemoved
  90. * @return {!Promise}
  91. */
  92. shaka.offline.IStorageEngine.prototype.removeKeys;
  93. /**
  94. * Reserves the next ID and returns it.
  95. *
  96. * @param {string} storeName
  97. * @return {number}
  98. */
  99. shaka.offline.IStorageEngine.prototype.reserveId;