Skip to content

Commit

Permalink
Replacing _.isArray with Array.isArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Bero committed Mar 4, 2024
1 parent 74b0106 commit 96c6042
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/links/lib/createSearchFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ function getIdQueryFieldStorage(object, fieldStorage, isMany = false) {
const [root, ...rest] = fieldStorage.split('.');
if (rest.length === 0) {
const ids = object[fieldStorage];
return _.isArray(ids) ? {$in: ids} : ids;
return Array.isArray(ids) ? {$in: ids} : ids;
}

const nestedPath = rest.join('.');
const rootValue = object[root];
if (_.isArray(rootValue)) {
if (Array.isArray(rootValue)) {
return {$in: _.uniq(_.union(...rootValue.map(item => dot.pick(nestedPath, item))))};
}
else if (_.isObject(rootValue)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/query/hypernova/aggregateSearchFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function getIdsFromObject(object, field) {
}

const rootValue = object[parts[0]];
if (_.isArray(rootValue)) {
if (Array.isArray(rootValue)) {
return rootValue.map(item => dot.pick(parts.slice(1).join('.'), item));
}
else if (_.isObject(rootValue)) {
Expand Down
10 changes: 5 additions & 5 deletions lib/query/hypernova/assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ function getIdsForMany(parentResult, fieldStorage) {

// Option A.
if (nested.length === 0) {
return _.isArray(value) ? value : [value];
return Array.isArray(value) ? value : [value];
}

// Option C.
if (_.isArray(value)) {
if (Array.isArray(value)) {
return _.flatten(value.map(v => getIdsFromObject(v, nested.join('.'))));
}

Expand All @@ -75,7 +75,7 @@ function getIdsForMany(parentResult, fieldStorage) {

function getIdsFromObject(object, path) {
const pickedValue = dot.pick(path, object);
return _.isArray(pickedValue) ? pickedValue : ((_.isUndefined(pickedValue) || _.isNull(pickedValue)) ? [] : [pickedValue]);
return Array.isArray(pickedValue) ? pickedValue : ((_.isUndefined(pickedValue) || _.isNull(pickedValue)) ? [] : [pickedValue]);
}

export function assembleMany(parentResult, {
Expand All @@ -94,7 +94,7 @@ export function assembleMany(parentResult, {
}

const [, ...nestedLinkPath] = childCollectionNode.linkName.split('.');
if (nestedLinkPath.length > 0 && _.isArray(rootValue)) {
if (nestedLinkPath.length > 0 && Array.isArray(rootValue)) {
rootValue.forEach(result => {
const results = _.flatten(_.union(...getIdsForMany(result, rest.join('.')).map(id => resultsByKeyId[id])));
const data = filterAssembledData(
Expand Down Expand Up @@ -173,7 +173,7 @@ export function assembleOne(parentResult, {
// todo: using linker.linkName should be correct here since it should be the same as childCollectionNode.linkName
const path = childCollectionNode.linkName.split('.');

if (_.isArray(rootValue)) {
if (Array.isArray(rootValue)) {
rootValue.forEach(result => {
const value = dot.pick(rest.join('.'), result);
const data = filterAssembledData(
Expand Down
2 changes: 1 addition & 1 deletion lib/query/hypernova/buildVirtualNodeProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function (childCollectionNode, filters, options, userId) {
delete a[key];
}

if (!_.isArray(value) && _.isObject(value) && !(value instanceof Date)) {
if (!Array.isArray(value) && _.isObject(value) && !(value instanceof Date)) {
a[key] = cleanUndefinedLeafs(value);
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/query/hypernova/processVirtualNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function(childCollectionNode, results, metaFilters, options = {})
if (isMany) {
comparator = (result, parent) => {
const [root, ...nestedFields] = linkField.split('.');
const rootValue = _.isArray(result[root]) ? result[root] : [result[root]];
const rootValue = Array.isArray(result[root]) ? result[root] : [result[root]];
if (nestedFields.length > 0) {
return _.contains(rootValue.map(nestedObject => dot.pick(nestedFields.join('.'), nestedObject)), parent[linker.foreignIdentityField]);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/query/lib/prepareForDelivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function removeLinkStorages(node, sameLevelResults) {

function removeArrayFromObject(result, linkName) {
const linkData = dot.pick(linkName, result);
if (linkData && _.isArray(linkData)) {
if (linkData && Array.isArray(linkData)) {
dot.remove(linkName, result);
dot.str(linkName, _.first(linkData), result);
}
Expand All @@ -154,7 +154,7 @@ function removeArrayForOneResult(result, linkName) {
const [root, ...rest] = linkName.split('.');

const rootValue = result[root];
if (rest.length > 0 && _.isArray(rootValue)) {
if (rest.length > 0 && Array.isArray(rootValue)) {
rootValue.forEach(value => {
removeArrayFromObject(value, rest.join('.'));
});
Expand Down Expand Up @@ -183,7 +183,7 @@ export function storeOneResults(node, sameLevelResults) {
}
else {
const rootValue = result[root];
if (_.isArray(rootValue)) {
if (Array.isArray(rootValue)) {
rootValue.forEach(value => {
storeOneResults(collectionNode, dot.pick(rest.join('.'), value));
});
Expand Down
2 changes: 1 addition & 1 deletion lib/query/lib/recursiveFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function fetch(node, parentObject, fetchOptions = {}) {
}
else {
const value = result[root];
if (_.isArray(value)) {
if (Array.isArray(value)) {
const [, ...storageRest] = collectionNode.linker.linkStorageField.split('.');
const nestedPath = storageRest.join('.');
value.forEach(item => {
Expand Down

0 comments on commit 96c6042

Please sign in to comment.