Skip to content

Commit

Permalink
Merge 7d50f61 into be7d97c
Browse files Browse the repository at this point in the history
  • Loading branch information
bajtos committed Jul 16, 2018
2 parents be7d97c + 7d50f61 commit cbb2efa
Show file tree
Hide file tree
Showing 28 changed files with 308 additions and 168 deletions.
6 changes: 4 additions & 2 deletions examples/relations.js
Expand Up @@ -109,8 +109,10 @@ Physician.create({name: 'Dr John'}, function(err, physician1) {
patient1.physicians.create({name: 'Dr X'}, function(err, patient4) {
console.log('Physician 4: ', patient4, patient4.constructor.modelName);
});
});
});
}
);
}
);
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion lib/connectors/kv-memory.js
Expand Up @@ -43,7 +43,8 @@ KeyValueMemoryConnector.prototype._setupRegularCleanup = function() {
clearInterval(timer);
}
},
1000);
1000
);
this._cleanupTimer.unref();
};

Expand Down
15 changes: 10 additions & 5 deletions lib/dao.js
Expand Up @@ -135,14 +135,16 @@ function invokeConnectorMethod(connector, method, Model, args, options, cb) {
// If the DataSource is a transaction and no transaction object is provide in
// the options yet, add it to the options, see: DataSource#transaction()
var opts = dataSource.isTransaction && !options.transaction ? Object.assign(
options, {transaction: dataSource.currentTransaction}) : options;
options, {transaction: dataSource.currentTransaction}
) : options;
var optionsSupported = connector[method].length >= args.length + 3;
var transaction = opts.transaction;
if (transaction) {
if (!optionsSupported) {
return process.nextTick(function() {
cb(new Error(g.f(
'The connector does not support {{method}} within a transaction', method)));
'The connector does not support {{method}} within a transaction', method
)));
});
}
// transaction isn't always a Transaction instance. Some tests provide a
Expand Down Expand Up @@ -1749,7 +1751,8 @@ DataAccessObject._coerce = function(where, options) {
'The %s property has invalid clause %j: Expected precisely 2 values, received %d',
p,
where[p],
val.length));
val.length
));
err.statusCode = 400;
throw err;
}
Expand All @@ -1762,7 +1765,8 @@ DataAccessObject._coerce = function(where, options) {
err = new Error(g.f(
'The %s property has invalid clause %j: Expected a string or RegExp',
p,
where[p]));
where[p]
));
err.statusCode = 400;
throw err;
}
Expand Down Expand Up @@ -2998,7 +3002,8 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
err = new Error(g.f(
'The connector %s does not support {{replaceById}} operation. This is not a bug in LoopBack. ' +
'Please contact the authors of the connector, preferably via GitHub issues.',
connector.name));
connector.name
));
return cb(err);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/datasource.js
Expand Up @@ -413,7 +413,8 @@ DataSource.prototype.setup = function(dsName, settings) {
console.warn(
'A datasource is created with name %j, which is different from the name in settings (%j). ' +
'Please adjust your configuration to ensure these names match.',
dsName, settings.name);
dsName, settings.name
);
}

// Disconnected by default
Expand Down Expand Up @@ -2339,7 +2340,8 @@ DataSource.prototype.transaction = function(execute, options, cb) {
if (!transaction) {
process.nextTick(function() {
cb(new Error(g.f(
'Transaction is not ready, wait for the returned promise to resolve')));
'Transaction is not ready, wait for the returned promise to resolve'
)));
});
}
return transaction;
Expand Down
7 changes: 4 additions & 3 deletions lib/relation-definition.js
Expand Up @@ -114,8 +114,8 @@ function preventFkOverride(inst, data, fkProp) {
'Cannot override foreign key %s from %s to %s',
fkProp,
inst[fkProp],
data[fkProp])
);
data[fkProp]
));
}
return err;
}
Expand Down Expand Up @@ -1825,7 +1825,8 @@ HasOne.prototype.create = function(targetModelData, options, cb) {
} else {
cb && cb(new Error(g.f(
'{{HasOne}} relation cannot create more than one instance of %s',
modelTo.modelName)));
modelTo.modelName
)));
}
});
return cb.promise;
Expand Down
6 changes: 2 additions & 4 deletions lib/transaction.js
Expand Up @@ -149,8 +149,7 @@ if (Transaction) {
// The connection should have been released back the pool
this.connection = null;
cb(err);
}
);
});
}
return cb.promise;
};
Expand Down Expand Up @@ -189,8 +188,7 @@ if (Transaction) {
// The connection should have been released back the pool
this.connection = null;
cb(err);
}
);
});
}
return cb.promise;
};
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.js
Expand Up @@ -571,7 +571,8 @@ function uniq(a) {
}
assert(Array.isArray(a), 'array argument is required');
var comparableA = a.map(
item => item.hasOwnProperty('_bsontype') ? item.toString() : item);
item => item.hasOwnProperty('_bsontype') ? item.toString() : item
);
for (var i = 0, n = comparableA.length; i < n; i++) {
if (comparableA.indexOf(comparableA[i]) === i) {
uniqArray.push(a[i]);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -38,8 +38,8 @@
"async-iterators": "^0.2.2",
"bson": "^1.0.4",
"coveralls": "^3.0.1",
"eslint": "^4.19.1",
"eslint-config-loopback": "^10.0.0",
"eslint": "^5.1.0",
"eslint-config-loopback": "^11.0.0",
"loopback-connector-throwing": "file:./test/fixtures/loopback-connector-throwing",
"mocha": "^5.2.0",
"nyc": "^12.0.2",
Expand Down
15 changes: 10 additions & 5 deletions support/describe-operation-hooks.js
Expand Up @@ -51,13 +51,15 @@ var operations = [
function findOrCreate_found(ds) {
return ds.TestModel.findOrCreate(
{where: {name: ds.existingInstance.name}},
{name: ds.existingInstance.name});
{name: ds.existingInstance.name}
);
},

function findOrCreate_create(ds) {
return ds.TestModel.findOrCreate(
{where: {name: 'new-record'}},
{name: 'new-record'});
{name: 'new-record'}
);
},

function updateOrCreate_create(ds) {
Expand All @@ -66,7 +68,8 @@ var operations = [

function updateOrCreate_update(ds) {
return ds.TestModel.updateOrCreate(
{id: ds.existingInstance.id, name: 'new name'});
{id: ds.existingInstance.id, name: 'new name'}
);
},

function replaceOrCreate_create(ds) {
Expand All @@ -75,13 +78,15 @@ var operations = [

function replaceOrCreate_update(ds) {
return ds.TestModel.replaceOrCreate(
{id: ds.existingInstance.id, name: 'new name'});
{id: ds.existingInstance.id, name: 'new name'}
);
},

function replaceById(ds) {
return ds.TestModel.replaceById(
ds.existingInstance.id,
{name: 'new name'});
{name: 'new name'}
);
},

function updateAll(ds) {
Expand Down
3 changes: 2 additions & 1 deletion test/async-observer.test.js
Expand Up @@ -322,7 +322,8 @@ describe('async observer', function() {
},
function(err) {
err.should.eql(testError);
});
}
);
});
});

Expand Down
6 changes: 4 additions & 2 deletions test/basic-querying.test.js
Expand Up @@ -126,9 +126,11 @@ describe('basic-querying', function() {
return u.name;
});
names.should.eql(
[createdUsers[2].name, createdUsers[1].name, createdUsers[0].name]);
[createdUsers[2].name, createdUsers[1].name, createdUsers[0].name]
);
done();
});
}
);
});

it('should query by ids and condition', function(done) {
Expand Down
3 changes: 2 additions & 1 deletion test/crud-with-options.test.js
Expand Up @@ -89,7 +89,8 @@ describe('crud-with-options', function() {
function(done) {
User.findById(undefined, {}, function(err, u) {
err.should.be.eql(
new Error('Model::findById requires the id argument'));
new Error('Model::findById requires the id argument')
);
done();
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/datatype.test.js
Expand Up @@ -194,7 +194,8 @@ describe('datatypes', function() {
},
{
persistUndefinedAsNull: true,
});
}
);

isStrict = TestModel.definition.settings.strict;

Expand Down
9 changes: 6 additions & 3 deletions test/discovery.test.js
Expand Up @@ -80,7 +80,8 @@ describe('Memory connector with mocked discovery', function() {
var s = schemas['STRONGLOOP.INVENTORY'];
s.name.should.be.eql('Inventory');
Object.keys(s.properties).should.be.eql(
['productId', 'locationId', 'available', 'total']);
['productId', 'locationId', 'available', 'total']
);
done();
});
});
Expand All @@ -97,7 +98,8 @@ describe('Memory connector with mocked discovery', function() {
var s = schemas['STRONGLOOP.INVENTORY'];
s.name.should.be.eql('inventory');
Object.keys(s.properties).should.be.eql(
['product_id', 'location_id', 'available', 'total']);
['product_id', 'location_id', 'available', 'total']
);
done();
});
});
Expand All @@ -110,7 +112,8 @@ describe('Memory connector with mocked discovery', function() {
var s = schemas['STRONGLOOP.INVENTORY'];
s.name.should.be.eql('INVENTORY');
Object.keys(s.properties).should.be.eql(
['PRODUCT_ID', 'LOCATION_ID', 'AVAILABLE', 'TOTAL']);
['PRODUCT_ID', 'LOCATION_ID', 'AVAILABLE', 'TOTAL']
);
done();
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/hooks.test.js
Expand Up @@ -411,7 +411,8 @@ describe('hooks', function() {
it('should describe isValid sequence', function(done) {
should.not.exist(
user.constructor._validations,
'Expected user to have no validations, but she have');
'Expected user to have no validations, but she have'
);
user.isValid(function(valid) {
valid.should.be.true;
life.should.eql([
Expand Down
6 changes: 2 additions & 4 deletions test/include.test.js
Expand Up @@ -1633,8 +1633,7 @@ describe('Model instance with included relation .toJSON()', function() {
foreignKey: '',
},
},
}
);
});
GameParticipationModel = db.createModel('GameParticipation',
{
date: Date,
Expand All @@ -1652,8 +1651,7 @@ describe('Model instance with included relation .toJSON()', function() {
foreignKey: '',
},
},
}
);
});
ResultModel = db.createModel('Result', {
points: Number,
}, {
Expand Down
6 changes: 4 additions & 2 deletions test/kvao/expire.suite.js
Expand Up @@ -49,7 +49,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
function(err) {
err.message.should.match(/expired-key/);
err.should.have.property('statusCode', 404);
});
}
);
});

it('returns error when key does not exist', function() {
Expand All @@ -58,7 +59,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
function(err) {
err.message.should.match(/key-does-not-exist/);
err.should.have.property('statusCode', 404);
});
}
);
});

function setupCacheItem() {
Expand Down
12 changes: 8 additions & 4 deletions test/kvao/ttl.suite.js
Expand Up @@ -26,7 +26,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
it('gets TTL when key with unexpired TTL exists - Promise API',
function() {
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(function() { return CacheItem.ttl('a-key'); })
.then(function(ttl) { ttl.should.be.within(1, INITIAL_TTL); });
Expand All @@ -52,7 +53,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {

it('fails when getting TTL for a key with expired TTL', function() {
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(function() {
return CacheItem.ttl('expired-key');
Expand All @@ -62,7 +64,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
function(err) {
err.message.should.match(/expired-key/);
err.should.have.property('statusCode', 404);
});
}
);
});

it('fails when key does not exist', function() {
Expand All @@ -71,7 +74,8 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
function(err) {
err.message.should.match(/key-does-not-exist/);
err.should.have.property('statusCode', 404);
});
}
);
});

function setupCacheItem() {
Expand Down
6 changes: 4 additions & 2 deletions test/loopback-dl.test.js
Expand Up @@ -741,9 +741,11 @@ describe('Model loaded with a base', function() {
Customer1.definition.properties.should.have.property('name');
Customer2.definition.properties.should.have.property('name');
Customer1.definition.properties.name.should.not.be.equal(
Customer2.definition.properties.name);
Customer2.definition.properties.name
);
Customer1.definition.properties.name.should.eql(
Customer2.definition.properties.name);
Customer2.definition.properties.name
);
});

it('can remove properties from base model', function() {
Expand Down

0 comments on commit cbb2efa

Please sign in to comment.