deleteDatabase.js 934 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.js';
  8. /**
  9. * Deletes the database.
  10. * Note: this is exported separately from the DBWrapper module because most
  11. * usages of IndexedDB in workbox dont need deleting, and this way it can be
  12. * reused in tests to delete databases without creating DBWrapper instances.
  13. *
  14. * @param {string} name The database name.
  15. * @private
  16. */
  17. export const deleteDatabase = async (name) => {
  18. await new Promise((resolve, reject) => {
  19. const request = indexedDB.deleteDatabase(name);
  20. request.onerror = () => {
  21. reject(request.error);
  22. };
  23. request.onblocked = () => {
  24. reject(new Error('Delete blocked'));
  25. };
  26. request.onsuccess = () => {
  27. resolve();
  28. };
  29. });
  30. };