Merge pull request #1631 from strongloop/drop-bluebird
[SEMVER-MAJOR] Switch from Bluebird to native Promise
This commit is contained in:
commit
b285737382
|
@ -30,7 +30,6 @@ exports.rankArrayElements = rankArrayElements;
|
||||||
var g = require('strong-globalize')();
|
var g = require('strong-globalize')();
|
||||||
var traverse = require('traverse');
|
var traverse = require('traverse');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var Promise = require('bluebird');
|
|
||||||
|
|
||||||
function safeRequire(module) {
|
function safeRequire(module) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.6.0",
|
"async": "^2.6.0",
|
||||||
"bluebird": "^3.1.1",
|
|
||||||
"debug": "^3.1.0",
|
"debug": "^3.1.0",
|
||||||
"depd": "^1.0.0",
|
"depd": "^1.0.0",
|
||||||
"inflection": "^1.6.0",
|
"inflection": "^1.6.0",
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
var ModelBuilder = require('../').ModelBuilder;
|
var ModelBuilder = require('../').ModelBuilder;
|
||||||
var should = require('./init');
|
var should = require('./init');
|
||||||
var Promise = require('bluebird');
|
|
||||||
|
|
||||||
describe('async observer', function() {
|
describe('async observer', function() {
|
||||||
var TestModel;
|
var TestModel;
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Promise = require('bluebird');
|
|
||||||
|
|
||||||
exports.givenCacheItem = givenCacheItem;
|
exports.givenCacheItem = givenCacheItem;
|
||||||
exports.givenKeys = givenKeys;
|
exports.givenKeys = givenKeys;
|
||||||
exports.givenModel = givenModel;
|
exports.givenModel = givenModel;
|
||||||
|
exports.delay = delay;
|
||||||
|
|
||||||
function givenCacheItem(dataSourceFactory) {
|
function givenCacheItem(dataSourceFactory) {
|
||||||
const modelProperties = {
|
const modelProperties = {
|
||||||
|
@ -34,3 +33,9 @@ function givenKeys(Model, keys, cb) {
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function delay(ms) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
var bdd = require('../helpers/bdd-if');
|
var bdd = require('../helpers/bdd-if');
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
var helpers = require('./_helpers');
|
var helpers = require('./_helpers');
|
||||||
var Promise = require('bluebird');
|
|
||||||
|
|
||||||
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
// While we support millisecond precision, for the purpose of tests
|
// While we support millisecond precision, for the purpose of tests
|
||||||
|
@ -35,14 +34,14 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
it('sets key ttl - Promise API', function() {
|
it('sets key ttl - Promise API', function() {
|
||||||
return CacheItem.set('a-key', 'a-value')
|
return CacheItem.set('a-key', 'a-value')
|
||||||
.then(function() { return CacheItem.expire('a-key', ttlPrecision); })
|
.then(function() { return CacheItem.expire('a-key', ttlPrecision); })
|
||||||
.delay(2 * ttlPrecision)
|
.then(() => helpers.delay(2 * ttlPrecision))
|
||||||
.then(function() { return CacheItem.get('a-key'); })
|
.then(function() { return CacheItem.get('a-key'); })
|
||||||
.then(function(value) { should.equal(value, null); });
|
.then(function(value) { should.equal(value, null); });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns error when expiring a key that has expired', function() {
|
it('returns error when expiring a key that has expired', function() {
|
||||||
return Promise.resolve(CacheItem.set('expired-key', 'a-value', ttlPrecision))
|
return Promise.resolve(CacheItem.set('expired-key', 'a-value', ttlPrecision))
|
||||||
.delay(2 * ttlPrecision)
|
.then(() => helpers.delay(2 * ttlPrecision))
|
||||||
.then(function() { return CacheItem.expire('expired-key', 1000); })
|
.then(function() { return CacheItem.expire('expired-key', 1000); })
|
||||||
.then(
|
.then(
|
||||||
function() { throw new Error('expire() should have failed'); },
|
function() { throw new Error('expire() should have failed'); },
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
var helpers = require('./_helpers');
|
var helpers = require('./_helpers');
|
||||||
var Promise = require('bluebird');
|
|
||||||
|
|
||||||
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
var TTL_PRECISION = connectorCapabilities.ttlPrecision;
|
var TTL_PRECISION = connectorCapabilities.ttlPrecision;
|
||||||
|
@ -69,7 +68,7 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
|
|
||||||
it('honours options.ttl', function() {
|
it('honours options.ttl', function() {
|
||||||
return CacheItem.set('a-key', 'a-value', {ttl: TTL_PRECISION})
|
return CacheItem.set('a-key', 'a-value', {ttl: TTL_PRECISION})
|
||||||
.delay(2 * TTL_PRECISION)
|
.then(() => helpers.delay(2 * TTL_PRECISION))
|
||||||
.then(function() { return CacheItem.get('a-key'); })
|
.then(function() { return CacheItem.get('a-key'); })
|
||||||
.then(function(value) { should.equal(value, null); });
|
.then(function(value) { should.equal(value, null); });
|
||||||
});
|
});
|
||||||
|
@ -84,7 +83,7 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
describe('set', function() {
|
describe('set', function() {
|
||||||
it('converts numeric options arg to options.ttl', function() {
|
it('converts numeric options arg to options.ttl', function() {
|
||||||
return CacheItem.set('a-key', 'a-value', TTL_PRECISION)
|
return CacheItem.set('a-key', 'a-value', TTL_PRECISION)
|
||||||
.delay(2 * TTL_PRECISION)
|
.then(() => helpers.delay(2 * TTL_PRECISION))
|
||||||
.then(function() { return CacheItem.get('a-key'); })
|
.then(function() { return CacheItem.get('a-key'); })
|
||||||
.then(function(value) { should.equal(value, null); });
|
.then(function(value) { should.equal(value, null); });
|
||||||
});
|
});
|
||||||
|
@ -94,7 +93,7 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return CacheItem.set('a-key', 'another-value'); // no TTL
|
return CacheItem.set('a-key', 'another-value'); // no TTL
|
||||||
})
|
})
|
||||||
.delay(2 * TTL_PRECISION)
|
.then(() => helpers.delay(2 * TTL_PRECISION))
|
||||||
.then(function() { return CacheItem.get('a-key'); })
|
.then(function() { return CacheItem.get('a-key'); })
|
||||||
.then(function(value) { should.equal(value, 'another-value'); });
|
.then(function(value) { should.equal(value, 'another-value'); });
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
var asyncIterators = require('async-iterators');
|
var asyncIterators = require('async-iterators');
|
||||||
var bdd = require('../helpers/bdd-if');
|
var bdd = require('../helpers/bdd-if');
|
||||||
var helpers = require('./_helpers');
|
var helpers = require('./_helpers');
|
||||||
var Promise = require('bluebird');
|
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
var toArray = Promise.promisify(asyncIterators.toArray);
|
|
||||||
|
|
||||||
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
var canIterateKeys = connectorCapabilities.canIterateKeys !== false;
|
var canIterateKeys = connectorCapabilities.canIterateKeys !== false;
|
||||||
|
@ -52,3 +50,15 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A promisified version of asyncIterators.toArray
|
||||||
|
// Node.js 8.x does not have util.promisify function,
|
||||||
|
// we are adding promise support manually here
|
||||||
|
function toArray(iter) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
asyncIterators.toArray(iter, (err, result) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
else resolve(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
var bdd = require('../helpers/bdd-if');
|
var bdd = require('../helpers/bdd-if');
|
||||||
var helpers = require('./_helpers');
|
var helpers = require('./_helpers');
|
||||||
var Promise = require('bluebird');
|
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
|
|
||||||
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
var bdd = require('../helpers/bdd-if');
|
var bdd = require('../helpers/bdd-if');
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
var helpers = require('./_helpers');
|
var helpers = require('./_helpers');
|
||||||
var Promise = require('bluebird');
|
|
||||||
|
|
||||||
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
var TTL_PRECISION = connectorCapabilities.ttlPrecision;
|
var TTL_PRECISION = connectorCapabilities.ttlPrecision;
|
||||||
|
@ -28,7 +27,7 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
CacheItem.set('a-key', 'a-value', {ttl: INITIAL_TTL})
|
CacheItem.set('a-key', 'a-value', {ttl: INITIAL_TTL})
|
||||||
)
|
)
|
||||||
.delay(SMALL_DELAY)
|
.then(() => helpers.delay(SMALL_DELAY))
|
||||||
.then(function() { return CacheItem.ttl('a-key'); })
|
.then(function() { return CacheItem.ttl('a-key'); })
|
||||||
.then(function(ttl) { ttl.should.be.within(1, INITIAL_TTL); });
|
.then(function(ttl) { ttl.should.be.within(1, INITIAL_TTL); });
|
||||||
});
|
});
|
||||||
|
@ -55,7 +54,7 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
CacheItem.set('expired-key', 'a-value', {ttl: TTL_PRECISION})
|
CacheItem.set('expired-key', 'a-value', {ttl: TTL_PRECISION})
|
||||||
)
|
)
|
||||||
.delay(2 * TTL_PRECISION)
|
.then(() => helpers.delay(2 * TTL_PRECISION))
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return CacheItem.ttl('expired-key');
|
return CacheItem.ttl('expired-key');
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Promise = require('bluebird');
|
|
||||||
var ValidationError = require('../..').ValidationError;
|
var ValidationError = require('../..').ValidationError;
|
||||||
|
|
||||||
var contextTestHelpers = require('../helpers/context-test-helpers');
|
var contextTestHelpers = require('../helpers/context-test-helpers');
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Promise = require('bluebird');
|
|
||||||
var ValidationError = require('../..').ValidationError;
|
var ValidationError = require('../..').ValidationError;
|
||||||
|
|
||||||
var contextTestHelpers = require('../helpers/context-test-helpers');
|
var contextTestHelpers = require('../helpers/context-test-helpers');
|
||||||
|
|
Loading…
Reference in New Issue