zapier-async-storage
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -123,44 +123,53 @@ 'use strict'; | ||
var dbConnection = indexedDB$1.open(name, version); | ||
try { | ||
var dbConnection = indexedDB$1.open(name, version); | ||
// An upgrade needs to be performed, clear out the old object stores | ||
// and then create the new object store | ||
dbConnection.onupgradeneeded = function (evt) { | ||
var oldVersion = evt.oldVersion, | ||
newVersion = evt.newVersion; | ||
// An upgrade needs to be performed, clear out the old object stores | ||
// and then create the new object store | ||
dbConnection.onupgradeneeded = function (evt) { | ||
var oldVersion = evt.oldVersion, | ||
newVersion = evt.newVersion; | ||
var dbInstance = dbConnection.result; | ||
var dbInstance = dbConnection.result; | ||
try { | ||
dbInstance.createObjectStore(storeName); | ||
} catch (err) { | ||
if (err.name === 'ConstraintError') { | ||
console.warn('Database ' + name + ' has been upgraded from ' + oldVersion + ' -> ' + newVersion + ' but the table ' + storeName + ' already exists.'); | ||
try { | ||
dbInstance.createObjectStore(storeName); | ||
} catch (err) { | ||
if (err.name === 'ConstraintError') { | ||
console.warn('Database ' + name + ' has been upgraded from ' + oldVersion + ' -> ' + newVersion + ' but the table ' + storeName + ' already exists.'); | ||
// Force the store to clear because we've incremented the version | ||
shouldClear = true; | ||
} else { | ||
throw err; | ||
// Force the store to clear because we've incremented the version | ||
shouldClear = true; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
// An error occured attempting to connect to the DB | ||
dbConnection.onerror = function (evt) { | ||
reject(evt.target.error); | ||
}; | ||
// An error occured attempting to connect to the DB | ||
dbConnection.onerror = function (evt) { | ||
// See https://mzl.la/2wCPech | ||
if (dbConnection.error && dbConnection.error.name === 'InvalidStateError') { | ||
evt.preventDefault(); | ||
} | ||
// Successfully connected to the database | ||
dbConnection.onsuccess = function (evt) { | ||
var dbInstance = evt.target.result; | ||
reject(evt.target.error); | ||
}; | ||
if (shouldClear) { | ||
resolve(clearStore(dbInstance, storeName)); | ||
// Successfully connected to the database | ||
dbConnection.onsuccess = function (evt) { | ||
var dbInstance = evt.target.result; | ||
if (shouldClear) { | ||
resolve(clearStore(dbInstance, storeName)); | ||
return; | ||
} | ||
resolve(dbInstance); | ||
return; | ||
} | ||
}; | ||
} catch (e) { | ||
reject(e); | ||
} | ||
resolve(dbInstance); | ||
return; | ||
}; | ||
return; | ||
@@ -167,0 +176,0 @@ }); |
@@ -85,44 +85,53 @@ 'use strict'; | ||
var dbConnection = indexedDB.open(name, version); | ||
try { | ||
var dbConnection = indexedDB.open(name, version); | ||
// An upgrade needs to be performed, clear out the old object stores | ||
// and then create the new object store | ||
dbConnection.onupgradeneeded = function (evt) { | ||
var oldVersion = evt.oldVersion, | ||
newVersion = evt.newVersion; | ||
// An upgrade needs to be performed, clear out the old object stores | ||
// and then create the new object store | ||
dbConnection.onupgradeneeded = function (evt) { | ||
var oldVersion = evt.oldVersion, | ||
newVersion = evt.newVersion; | ||
var dbInstance = dbConnection.result; | ||
var dbInstance = dbConnection.result; | ||
try { | ||
dbInstance.createObjectStore(storeName); | ||
} catch (err) { | ||
if (err.name === 'ConstraintError') { | ||
console.warn('Database ' + name + ' has been upgraded from ' + oldVersion + ' -> ' + newVersion + ' but the table ' + storeName + ' already exists.'); | ||
try { | ||
dbInstance.createObjectStore(storeName); | ||
} catch (err) { | ||
if (err.name === 'ConstraintError') { | ||
console.warn('Database ' + name + ' has been upgraded from ' + oldVersion + ' -> ' + newVersion + ' but the table ' + storeName + ' already exists.'); | ||
// Force the store to clear because we've incremented the version | ||
shouldClear = true; | ||
} else { | ||
throw err; | ||
// Force the store to clear because we've incremented the version | ||
shouldClear = true; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
// An error occured attempting to connect to the DB | ||
dbConnection.onerror = function (evt) { | ||
reject(evt.target.error); | ||
}; | ||
// An error occured attempting to connect to the DB | ||
dbConnection.onerror = function (evt) { | ||
// See https://mzl.la/2wCPech | ||
if (dbConnection.error && dbConnection.error.name === 'InvalidStateError') { | ||
evt.preventDefault(); | ||
} | ||
// Successfully connected to the database | ||
dbConnection.onsuccess = function (evt) { | ||
var dbInstance = evt.target.result; | ||
reject(evt.target.error); | ||
}; | ||
if (shouldClear) { | ||
resolve((0, _clearStore2.default)(dbInstance, storeName)); | ||
// Successfully connected to the database | ||
dbConnection.onsuccess = function (evt) { | ||
var dbInstance = evt.target.result; | ||
if (shouldClear) { | ||
resolve((0, _clearStore2.default)(dbInstance, storeName)); | ||
return; | ||
} | ||
resolve(dbInstance); | ||
return; | ||
} | ||
}; | ||
} catch (e) { | ||
reject(e); | ||
} | ||
resolve(dbInstance); | ||
return; | ||
}; | ||
return; | ||
@@ -129,0 +138,0 @@ }); |
{ | ||
"name": "zapier-async-storage", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Minimalist wrapper for IndexedDB", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35742
1008