Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing instanceof Array checks to Array.isArray #5606

Merged
merged 1 commit into from Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cache/RedisQueryResultCache.ts
Expand Up @@ -61,7 +61,7 @@ export class RedisQueryResultCache implements QueryResultCache {
this.client = new this.redis();
}
} else if (this.clientType === "ioredis/cluster") {
if (cacheOptions && cacheOptions.options && cacheOptions.options instanceof Array) {
if (cacheOptions && cacheOptions.options && Array.isArray(cacheOptions.options)) {
this.client = new this.redis.Cluster(cacheOptions.options);
} else if (cacheOptions && cacheOptions.options && cacheOptions.options.startupNodes) {
this.client = new this.redis.Cluster(cacheOptions.options.startupNodes, cacheOptions.options.options);
Expand Down
12 changes: 6 additions & 6 deletions src/entity-manager/EntityManager.ts
Expand Up @@ -511,7 +511,7 @@ export class EntityManager {
target = target.options.name;

// if user passed empty array of entities then we don't need to do anything
if (entity instanceof Array && entity.length === 0)
if (Array.isArray(entity) && entity.length === 0)
return Promise.resolve(entity);

// execute soft-remove operation
Expand Down Expand Up @@ -564,7 +564,7 @@ export class EntityManager {
target = target.options.name;

// if user passed empty array of entities then we don't need to do anything
if (entity instanceof Array && entity.length === 0)
if (Array.isArray(entity) && entity.length === 0)
return Promise.resolve(entity);

// execute recover operation
Expand Down Expand Up @@ -683,15 +683,15 @@ export class EntityManager {
if (criteria === undefined ||
criteria === null ||
criteria === "" ||
(criteria instanceof Array && criteria.length === 0)) {
(Array.isArray(criteria) && criteria.length === 0)) {

return Promise.reject(new Error(`Empty criteria(s) are not allowed for the delete method.`));
}

if (typeof criteria === "string" ||
typeof criteria === "number" ||
criteria instanceof Date ||
criteria instanceof Array) {
Array.isArray(criteria)) {

return this.createQueryBuilder()
.softDelete()
Expand Down Expand Up @@ -721,15 +721,15 @@ export class EntityManager {
if (criteria === undefined ||
criteria === null ||
criteria === "" ||
(criteria instanceof Array && criteria.length === 0)) {
(Array.isArray(criteria) && criteria.length === 0)) {

return Promise.reject(new Error(`Empty criteria(s) are not allowed for the delete method.`));
}

if (typeof criteria === "string" ||
typeof criteria === "number" ||
criteria instanceof Date ||
criteria instanceof Array) {
Array.isArray(criteria)) {

return this.createQueryBuilder()
.restore()
Expand Down
10 changes: 5 additions & 5 deletions src/metadata/RelationMetadata.ts
Expand Up @@ -281,11 +281,11 @@ export class RelationMetadata {
this.givenInverseSidePropertyFactory = args.inverseSideProperty;

this.isLazy = args.isLazy || false;
this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("insert") !== -1);
this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("update") !== -1);
this.isCascadeRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("remove") !== -1);
this.isCascadeSoftRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("soft-remove") !== -1);
this.isCascadeRecover = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("recover") !== -1);
// this.isCascadeInsert = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("insert") !== -1);
// this.isCascadeUpdate = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("update") !== -1);
// this.isCascadeRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("remove") !== -1);
// this.isCascadeSoftRemove = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("soft-remove") !== -1);
// this.isCascadeRecover = args.options.cascade === true || (args.options.cascade instanceof Array && args.options.cascade.indexOf("recover") !== -1);
this.isCascadeInsert = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf("insert") !== -1);
this.isCascadeUpdate = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf("update") !== -1);
this.isCascadeRemove = args.options.cascade === true || (Array.isArray(args.options.cascade) && args.options.cascade.indexOf("remove") !== -1);
Expand Down
2 changes: 1 addition & 1 deletion src/query-builder/QueryBuilder.ts
Expand Up @@ -778,7 +778,7 @@ export abstract class QueryBuilder<Entity> {
return where(this);

} else if (where instanceof Object) {
const wheres: ObjectLiteral[] = where instanceof Array ? where : [where];
const wheres: ObjectLiteral[] = Array.isArray(where) ? where : [where];
let andConditions: string[];
let parameterIndex = Object.keys(this.expressionMap.nativeParameters).length;

Expand Down
4 changes: 2 additions & 2 deletions src/query-builder/SoftDeleteQueryBuilder.ts
Expand Up @@ -334,7 +334,7 @@ export class SoftDeleteQueryBuilder<Entity> extends QueryBuilder<Entity> impleme
throw new Error(`.whereEntity method can only be used on queries which update real entity table.`);

this.expressionMap.wheres = [];
const entities: Entity[] = entity instanceof Array ? entity : [entity];
const entities: Entity[] = Array.isArray(entity) ? entity : [entity];
entities.forEach(entity => {

const entityIdMap = this.expressionMap.mainAlias!.metadata.getEntityIdMap(entity);
Expand Down Expand Up @@ -456,4 +456,4 @@ export class SoftDeleteQueryBuilder<Entity> extends QueryBuilder<Entity> impleme
return "";
}

}
}
2 changes: 1 addition & 1 deletion src/util/DateUtils.ts
Expand Up @@ -146,7 +146,7 @@ export class DateUtils {
* Converts each item in the given array to string joined by "," separator.
*/
static simpleArrayToString(value: any[]|any): string[]|any {
if (value instanceof Array) {
if (Array.isArray(value)) {
return (value as any[])
.map(i => String(i))
.join(",");
Expand Down
2 changes: 1 addition & 1 deletion test/github-issues/587/issue-587.ts
Expand Up @@ -16,7 +16,7 @@ describe("github issues > #587 Ordering of fields in composite indexes defined u
it("should preserve field ordering when fields are specified as string[]", () => Promise.all(connections.map(async connection => {
connection.entityMetadatas.forEach(entityMetadata => {
entityMetadata.indices.forEach(index => {
if (index.givenColumnNames && index.givenColumnNames instanceof Array) {
if (index.givenColumnNames && Array.isArray(index.givenColumnNames)) {
for (let i = 0; i < index.columns.length; i++) {
const givenColumn = (index.givenColumnNames as string[])[i];
const actualColumn = index.columns[i];
Expand Down