不要怂,就是干,撸起袖子干!

Commit a0e244f9 by Simon Schick Committed by GitHub

refactor: use native versions (#12159)

1 parent c130d070
...@@ -7,7 +7,7 @@ const assert = require('assert'); ...@@ -7,7 +7,7 @@ const assert = require('assert');
function getDeclaredManuals() { function getDeclaredManuals() {
const declaredManualGroups = require('./manual-groups.json'); const declaredManualGroups = require('./manual-groups.json');
return _.flatten(_.values(declaredManualGroups)).map(file => { return _.flatten(Object.values(declaredManualGroups)).map(file => {
return normalize(`./docs/manual/${file}`); return normalize(`./docs/manual/${file}`);
}); });
} }
...@@ -34,4 +34,4 @@ function checkManuals() { ...@@ -34,4 +34,4 @@ function checkManuals() {
} }
} }
module.exports = { getDeclaredManuals, getAllManuals, checkManuals }; module.exports = { getDeclaredManuals, getAllManuals, checkManuals };
\ No newline at end of file
...@@ -75,7 +75,7 @@ const Mixin = { ...@@ -75,7 +75,7 @@ const Mixin = {
}, },
getAssociations(target) { getAssociations(target) {
return _.values(this.associations).filter(association => association.target.name === target.name); return Object.values(this.associations).filter(association => association.target.name === target.name);
}, },
getAssociationForAlias(target, alias) { getAssociationForAlias(target, alias) {
......
...@@ -1041,7 +1041,7 @@ dialectMap.mariadb = require('./dialects/mariadb/data-types')(DataTypes); ...@@ -1041,7 +1041,7 @@ dialectMap.mariadb = require('./dialects/mariadb/data-types')(DataTypes);
dialectMap.sqlite = require('./dialects/sqlite/data-types')(DataTypes); dialectMap.sqlite = require('./dialects/sqlite/data-types')(DataTypes);
dialectMap.mssql = require('./dialects/mssql/data-types')(DataTypes); dialectMap.mssql = require('./dialects/mssql/data-types')(DataTypes);
const dialectList = _.values(dialectMap); const dialectList = Object.values(dialectMap);
for (const dataTypes of dialectList) { for (const dataTypes of dialectList) {
_.each(dataTypes, (DataType, key) => { _.each(dataTypes, (DataType, key) => {
......
...@@ -206,7 +206,7 @@ class AbstractQuery { ...@@ -206,7 +206,7 @@ class AbstractQuery {
} }
handleShowTablesQuery(results) { handleShowTablesQuery(results) {
return _.flatten(results.map(resultSet => _.values(resultSet))); return _.flatten(results.map(resultSet => Object.values(resultSet)));
} }
isShowIndexesQuery() { isShowIndexesQuery() {
...@@ -334,7 +334,7 @@ class AbstractQuery { ...@@ -334,7 +334,7 @@ class AbstractQuery {
const logQueryParameters = this.sequelize.options.logQueryParameters || options.logQueryParameters; const logQueryParameters = this.sequelize.options.logQueryParameters || options.logQueryParameters;
const startTime = Date.now(); const startTime = Date.now();
let logParameter = ''; let logParameter = '';
if (logQueryParameters && parameters) { if (logQueryParameters && parameters) {
const delimiter = sql.endsWith(';') ? '' : ';'; const delimiter = sql.endsWith(';') ? '' : ';';
let paramStr; let paramStr;
......
...@@ -384,7 +384,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { ...@@ -384,7 +384,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
throw new Error('Cannot LIMIT delete without a model.'); throw new Error('Cannot LIMIT delete without a model.');
} }
const pks = _.values(model.primaryKeys).map(pk => this.quoteIdentifier(pk.field)).join(','); const pks = Object.values(model.primaryKeys).map(pk => this.quoteIdentifier(pk.field)).join(',');
primaryKeys = model.primaryKeyAttributes.length > 1 ? `(${pks})` : pks; primaryKeys = model.primaryKeyAttributes.length > 1 ? `(${pks})` : pks;
primaryKeysSelection = pks; primaryKeysSelection = pks;
...@@ -840,10 +840,6 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { ...@@ -840,10 +840,6 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
return matches.slice(0, -1); return matches.slice(0, -1);
} }
padInt(i) {
return i < 10 ? `0${i.toString()}` : i.toString();
}
dataTypeMapping(tableName, attr, dataType) { dataTypeMapping(tableName, attr, dataType) {
if (dataType.includes('PRIMARY KEY')) { if (dataType.includes('PRIMARY KEY')) {
dataType = dataType.replace('PRIMARY KEY', ''); dataType = dataType.replace('PRIMARY KEY', '');
......
...@@ -121,7 +121,7 @@ class Query extends AbstractQuery { ...@@ -121,7 +121,7 @@ class Query extends AbstractQuery {
})); }));
} }
if (isTableNameQuery) { if (isTableNameQuery) {
return rows.map(row => _.values(row)); return rows.map(row => Object.values(row));
} }
if (rows[0] && rows[0].sequelize_caught_exception !== undefined) { if (rows[0] && rows[0].sequelize_caught_exception !== undefined) {
......
...@@ -23,7 +23,7 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator { ...@@ -23,7 +23,7 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
options = options || {}; options = options || {};
const primaryKeys = []; const primaryKeys = [];
const needsMultiplePrimaryKeys = _.values(attributes).filter(definition => definition.includes('PRIMARY KEY')).length > 1; const needsMultiplePrimaryKeys = Object.values(attributes).filter(definition => definition.includes('PRIMARY KEY')).length > 1;
const attrArray = []; const attrArray = [];
for (const attr in attributes) { for (const attr in attributes) {
......
...@@ -9,7 +9,6 @@ class AssociationError extends BaseError { ...@@ -9,7 +9,6 @@ class AssociationError extends BaseError {
constructor(message) { constructor(message) {
super(message); super(message);
this.name = 'SequelizeAssociationError'; this.name = 'SequelizeAssociationError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -11,7 +11,6 @@ class BaseError extends Error { ...@@ -11,7 +11,6 @@ class BaseError extends Error {
constructor(message) { constructor(message) {
super(message); super(message);
this.name = 'SequelizeBaseError'; this.name = 'SequelizeBaseError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -15,7 +15,6 @@ class BulkRecordError extends BaseError { ...@@ -15,7 +15,6 @@ class BulkRecordError extends BaseError {
this.name = 'SequelizeBulkRecordError'; this.name = 'SequelizeBulkRecordError';
this.errors = error; this.errors = error;
this.record = record; this.record = record;
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -16,7 +16,6 @@ class ConnectionError extends BaseError { ...@@ -16,7 +16,6 @@ class ConnectionError extends BaseError {
*/ */
this.parent = parent; this.parent = parent;
this.original = parent; this.original = parent;
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class AccessDeniedError extends ConnectionError { ...@@ -9,7 +9,6 @@ class AccessDeniedError extends ConnectionError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeAccessDeniedError'; this.name = 'SequelizeAccessDeniedError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class ConnectionAcquireTimeoutError extends ConnectionError { ...@@ -9,7 +9,6 @@ class ConnectionAcquireTimeoutError extends ConnectionError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeConnectionAcquireTimeoutError'; this.name = 'SequelizeConnectionAcquireTimeoutError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class ConnectionRefusedError extends ConnectionError { ...@@ -9,7 +9,6 @@ class ConnectionRefusedError extends ConnectionError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeConnectionRefusedError'; this.name = 'SequelizeConnectionRefusedError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class ConnectionTimedOutError extends ConnectionError { ...@@ -9,7 +9,6 @@ class ConnectionTimedOutError extends ConnectionError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeConnectionTimedOutError'; this.name = 'SequelizeConnectionTimedOutError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class HostNotFoundError extends ConnectionError { ...@@ -9,7 +9,6 @@ class HostNotFoundError extends ConnectionError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeHostNotFoundError'; this.name = 'SequelizeHostNotFoundError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class HostNotReachableError extends ConnectionError { ...@@ -9,7 +9,6 @@ class HostNotReachableError extends ConnectionError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeHostNotReachableError'; this.name = 'SequelizeHostNotReachableError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class InvalidConnectionError extends ConnectionError { ...@@ -9,7 +9,6 @@ class InvalidConnectionError extends ConnectionError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeInvalidConnectionError'; this.name = 'SequelizeInvalidConnectionError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -29,7 +29,6 @@ class DatabaseError extends BaseError { ...@@ -29,7 +29,6 @@ class DatabaseError extends BaseError {
* @type {Array<any>} * @type {Array<any>}
*/ */
this.parameters = parent.parameters; this.parameters = parent.parameters;
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -17,7 +17,6 @@ class ExclusionConstraintError extends DatabaseError { ...@@ -17,7 +17,6 @@ class ExclusionConstraintError extends DatabaseError {
this.constraint = options.constraint; this.constraint = options.constraint;
this.fields = options.fields; this.fields = options.fields;
this.table = options.table; this.table = options.table;
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -19,7 +19,6 @@ class ForeignKeyConstraintError extends DatabaseError { ...@@ -19,7 +19,6 @@ class ForeignKeyConstraintError extends DatabaseError {
this.value = options.value; this.value = options.value;
this.index = options.index; this.index = options.index;
this.reltype = options.reltype; this.reltype = options.reltype;
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class TimeoutError extends DatabaseError { ...@@ -9,7 +9,6 @@ class TimeoutError extends DatabaseError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeTimeoutError'; this.name = 'SequelizeTimeoutError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -17,7 +17,6 @@ class UnknownConstraintError extends DatabaseError { ...@@ -17,7 +17,6 @@ class UnknownConstraintError extends DatabaseError {
this.constraint = options.constraint; this.constraint = options.constraint;
this.fields = options.fields; this.fields = options.fields;
this.table = options.table; this.table = options.table;
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class EagerLoadingError extends BaseError { ...@@ -9,7 +9,6 @@ class EagerLoadingError extends BaseError {
constructor(message) { constructor(message) {
super(message); super(message);
this.name = 'SequelizeEagerLoadingError'; this.name = 'SequelizeEagerLoadingError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class EmptyResultError extends BaseError { ...@@ -9,7 +9,6 @@ class EmptyResultError extends BaseError {
constructor(message) { constructor(message) {
super(message); super(message);
this.name = 'SequelizeEmptyResultError'; this.name = 'SequelizeEmptyResultError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class InstanceError extends BaseError { ...@@ -9,7 +9,6 @@ class InstanceError extends BaseError {
constructor(message) { constructor(message) {
super(message); super(message);
this.name = 'SequelizeInstanceError'; this.name = 'SequelizeInstanceError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -28,7 +28,6 @@ class OptimisticLockError extends BaseError { ...@@ -28,7 +28,6 @@ class OptimisticLockError extends BaseError {
* @type {object} * @type {object}
*/ */
this.where = options.where; this.where = options.where;
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class QueryError extends BaseError { ...@@ -9,7 +9,6 @@ class QueryError extends BaseError {
constructor(message) { constructor(message) {
super(message); super(message);
this.name = 'SequelizeQueryError'; this.name = 'SequelizeQueryError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -9,7 +9,6 @@ class SequelizeScopeError extends BaseError { ...@@ -9,7 +9,6 @@ class SequelizeScopeError extends BaseError {
constructor(parent) { constructor(parent) {
super(parent); super(parent);
this.name = 'SequelizeScopeError'; this.name = 'SequelizeScopeError';
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -30,7 +30,6 @@ class ValidationError extends BaseError { ...@@ -30,7 +30,6 @@ class ValidationError extends BaseError {
} else if (this.errors.length > 0 && this.errors[0].message) { } else if (this.errors.length > 0 && this.errors[0].message) {
this.message = this.errors.map(err => `${err.type || err.origin}: ${err.message}`).join(',\n'); this.message = this.errors.map(err => `${err.type || err.origin}: ${err.message}`).join(',\n');
} }
Error.captureStackTrace(this, this.constructor);
} }
/** /**
......
...@@ -19,7 +19,6 @@ class UniqueConstraintError extends ValidationError { ...@@ -19,7 +19,6 @@ class UniqueConstraintError extends ValidationError {
this.parent = options.parent; this.parent = options.parent;
this.original = options.parent; this.original = options.parent;
this.sql = options.parent.sql; this.sql = options.parent.sql;
Error.captureStackTrace(this, this.constructor);
} }
} }
......
...@@ -344,7 +344,7 @@ class InstanceValidator { ...@@ -344,7 +344,7 @@ class InstanceValidator {
*/ */
_validateSchema(rawAttribute, field, value) { _validateSchema(rawAttribute, field, value) {
if (rawAttribute.allowNull === false && (value === null || value === undefined)) { if (rawAttribute.allowNull === false && (value === null || value === undefined)) {
const association = _.values(this.modelInstance.constructor.associations).find(association => association instanceof BelongsTo && association.foreignKey === rawAttribute.fieldName); const association = Object.values(this.modelInstance.constructor.associations).find(association => association instanceof BelongsTo && association.foreignKey === rawAttribute.fieldName);
if (!association || !this.modelInstance.get(association.associationAccessor)) { if (!association || !this.modelInstance.get(association.associationAccessor)) {
const validators = this.modelInstance.validators[field]; const validators = this.modelInstance.validators[field];
const errMsg = _.get(validators, 'notNull.msg', `${this.modelInstance.constructor.name}.${field} cannot be null`); const errMsg = _.get(validators, 'notNull.msg', `${this.modelInstance.constructor.name}.${field} cannot be null`);
......
...@@ -296,7 +296,7 @@ class QueryInterface { ...@@ -296,7 +296,7 @@ class QueryInterface {
if (!skip.includes(tableName.tableName || tableName)) { if (!skip.includes(tableName.tableName || tableName)) {
await this.dropTable(tableName, Object.assign({}, options, { cascade: true }) ); await this.dropTable(tableName, Object.assign({}, options, { cascade: true }) );
} }
} }
}; };
const tableNames = await this.showAllTables(options); const tableNames = await this.showAllTables(options);
...@@ -556,7 +556,7 @@ class QueryInterface { ...@@ -556,7 +556,7 @@ class QueryInterface {
const attributes = {}; const attributes = {};
options = options || {}; options = options || {};
if (_.values(DataTypes).includes(dataTypeOrOptions)) { if (Object.values(DataTypes).includes(dataTypeOrOptions)) {
attributes[attributeName] = { type: dataTypeOrOptions, allowNull: true }; attributes[attributeName] = { type: dataTypeOrOptions, allowNull: true };
} else { } else {
attributes[attributeName] = dataTypeOrOptions; attributes[attributeName] = dataTypeOrOptions;
......
...@@ -7,7 +7,7 @@ const uuidv1 = require('uuid/v1'); ...@@ -7,7 +7,7 @@ const uuidv1 = require('uuid/v1');
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
const Promise = require('./promise'); const Promise = require('./promise');
const operators = require('./operators'); const operators = require('./operators');
const operatorsSet = new Set(_.values(operators)); const operatorsSet = new Set(Object.values(operators));
let inflection = require('inflection'); let inflection = require('inflection');
......
...@@ -5,8 +5,7 @@ const chai = require('chai'), ...@@ -5,8 +5,7 @@ const chai = require('chai'),
Support = require('../support'), Support = require('../support'),
DataTypes = require('../../../lib/data-types'), DataTypes = require('../../../lib/data-types'),
Sequelize = require('../../../index'), Sequelize = require('../../../index'),
Promise = Sequelize.Promise, Promise = Sequelize.Promise;
_ = require('lodash');
describe(Support.getTestDialectTeaser('Self'), () => { describe(Support.getTestDialectTeaser('Self'), () => {
it('supports freezeTableName', function() { it('supports freezeTableName', function() {
...@@ -52,7 +51,7 @@ describe(Support.getTestDialectTeaser('Self'), () => { ...@@ -52,7 +51,7 @@ describe(Support.getTestDialectTeaser('Self'), () => {
Person.belongsToMany(Person, { as: 'Parents', through: 'Family', foreignKey: 'ChildId', otherKey: 'PersonId' }); Person.belongsToMany(Person, { as: 'Parents', through: 'Family', foreignKey: 'ChildId', otherKey: 'PersonId' });
Person.belongsToMany(Person, { as: 'Childs', through: 'Family', foreignKey: 'PersonId', otherKey: 'ChildId' }); Person.belongsToMany(Person, { as: 'Childs', through: 'Family', foreignKey: 'PersonId', otherKey: 'ChildId' });
const foreignIdentifiers = _.values(Person.associations).map(v => v.foreignIdentifier); const foreignIdentifiers = Object.values(Person.associations).map(v => v.foreignIdentifier);
const rawAttributes = Object.keys(this.sequelize.models.Family.rawAttributes); const rawAttributes = Object.keys(this.sequelize.models.Family.rawAttributes);
expect(foreignIdentifiers.length).to.equal(2); expect(foreignIdentifiers.length).to.equal(2);
...@@ -94,7 +93,7 @@ describe(Support.getTestDialectTeaser('Self'), () => { ...@@ -94,7 +93,7 @@ describe(Support.getTestDialectTeaser('Self'), () => {
Person.belongsToMany(Person, { as: 'Parents', through: Family, foreignKey: 'preexisting_child', otherKey: 'preexisting_parent' }); Person.belongsToMany(Person, { as: 'Parents', through: Family, foreignKey: 'preexisting_child', otherKey: 'preexisting_parent' });
Person.belongsToMany(Person, { as: 'Children', through: Family, foreignKey: 'preexisting_parent', otherKey: 'preexisting_child' }); Person.belongsToMany(Person, { as: 'Children', through: Family, foreignKey: 'preexisting_parent', otherKey: 'preexisting_child' });
const foreignIdentifiers = _.values(Person.associations).map(v => v.foreignIdentifier); const foreignIdentifiers = Object.values(Person.associations).map(v => v.foreignIdentifier);
const rawAttributes = Object.keys(Family.rawAttributes); const rawAttributes = Object.keys(Family.rawAttributes);
expect(foreignIdentifiers.length).to.equal(2); expect(foreignIdentifiers.length).to.equal(2);
......
...@@ -925,13 +925,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -925,13 +925,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return userWithDefaults.sync({ force: true }).then(() => { return userWithDefaults.sync({ force: true }).then(() => {
return userWithDefaults.create({}).then(user => { return userWithDefaults.create({}).then(user => {
return userWithDefaults.findByPk(user.id).then(user => { return userWithDefaults.findByPk(user.id).then(user => {
const now = new Date(), const now = new Date();
pad = function(number) { const pad = number => number.toString().padStart(2, '0');
if (number > 9) {
return number;
}
return `0${number}`;
};
expect(user.year).to.equal(`${now.getUTCFullYear()}-${pad(now.getUTCMonth() + 1)}-${pad(now.getUTCDate())}`); expect(user.year).to.equal(`${now.getUTCFullYear()}-${pad(now.getUTCMonth() + 1)}-${pad(now.getUTCDate())}`);
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!