Socket
Socket
Sign inDemoInstall

idb

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idb - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

63

lib/idb.js

@@ -8,6 +8,4 @@ 'use strict';

function promisifyRequest(obj, method, args) {
var request;
var p = new Promise(function(resolve, reject) {
request = obj[method].apply(obj, args)
function promisifyRequest(request) {
return new Promise(function(resolve, reject) {
request.onsuccess = function() {

@@ -21,3 +19,11 @@ resolve(request.result);

});
}
function promisifyRequestCall(obj, method, args) {
var request;
var p = new Promise(function(resolve, reject) {
request = obj[method].apply(obj, args);
promisifyRequest(request).then(resolve, reject);
});
p.request = request;

@@ -27,4 +33,4 @@ return p;

function promisifyCursorRequest(obj, method, args) {
var p = promisifyRequest(obj, method, args);
function promisifyCursorRequestCall(obj, method, args) {
var p = promisifyRequestCall(obj, method, args);
return p.then(function(value) {

@@ -50,3 +56,3 @@ if (!value) return;

ProxyClass.prototype[prop] = function() {
return promisifyRequest(this[targetProp], prop, arguments);
return promisifyRequestCall(this[targetProp], prop, arguments);
};

@@ -69,3 +75,3 @@ });

ProxyClass.prototype[prop] = function() {
return promisifyCursorRequest(this[targetProp], prop, arguments);
return promisifyCursorRequestCall(this[targetProp], prop, arguments);
};

@@ -122,10 +128,8 @@ });

var args = arguments;
return new Promise(function(resolve, reject) {
return Promise.resolve().then(function() {
cursor._cursor[methodName].apply(cursor._cursor, args);
cursor._request.onsuccess = function() {
resolve(new Cursor(cursor._cursor), cursor._request);
};
cursor._request.onerror = function() {
reject(cursor._request.error);
};
return promisifyRequest(cursor._request).then(function(value) {
if (!value) return;
return new Cursor(value, cursor._request);
});
});

@@ -253,5 +257,30 @@ };

// polyfill getAll
[Index, ObjectStore].forEach(function(Constructor) {
if (Constructor.prototype.getAll) return;
Constructor.prototype.getAll = function(query, count) {
var instance = this;
var items = [];
return new Promise(function(resolve) {
instance.iterateCursor(query, function(cursor) {
if (!cursor) {
resolve(items);
return;
}
items.push(cursor.value);
if (count !== undefined && items.length == count) {
resolve(items);
return;
}
cursor.continue();
});
});
};
});
var exp = {
open: function(name, version, upgradeCallback) {
var p = promisifyRequest(indexedDB, 'open', [name, version]);
var p = promisifyRequestCall(indexedDB, 'open', [name, version]);
var request = p.request;

@@ -270,3 +299,3 @@

delete: function(name) {
return promisifyRequest(indexedDB, 'deleteDatabase', [name]);
return promisifyRequestCall(indexedDB, 'deleteDatabase', [name]);
}

@@ -273,0 +302,0 @@ };

{
"name": "idb",
"version": "1.0.1",
"version": "1.1.0",
"description": "IndexedDB but with promises",

@@ -5,0 +5,0 @@ "main": "lib/idb.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc