refactor: Replace _.flatten with Array.prototype.flat (#11271)

This commit is contained in:
pjmattingly 2022-07-28 04:42:51 -06:00 committed by GitHub
parent 4f7e12939c
commit b36cdf2db6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 15 deletions

View File

@ -255,8 +255,9 @@ module.exports = {
const partition = account.partition;
const functionNames = await this.serverless.service.getAllFunctions();
const cloudwatchLogEvents = _.flatten(
functionNames.map((functionName) => {
const cloudwatchLogEvents = functionNames
.map((functionName) => {
const functionObj = this.serverless.service.getFunction(functionName);
const FunctionName = functionObj.name;
const events = functionObj.events;
@ -272,7 +273,7 @@ module.exports = {
return { FunctionName, functionName, logGroupName, logSubscriptionSerialNumber };
});
})
);
.flat();
const cloudwatchLogEventsMap = _.groupBy(cloudwatchLogEvents, 'logGroupName');
const logGroupNames = Object.keys(cloudwatchLogEventsMap);

View File

@ -113,11 +113,10 @@ class AwsMetrics {
if (metrics && metrics.length > 0) {
const getDatapointsByLabel = (Label) =>
_.flatten(
_.flatten(metrics)
.filter((metric) => metric.Label === Label)
.map((metric) => metric.Datapoints)
);
metrics
.flat(2)
.filter((metric) => metric.Label === Label)
.map((metric) => metric.Datapoints);
const invocationsCount = _.sumBy(getDatapointsByLabel('Invocations'), 'Sum');
const throttlesCount = _.sumBy(getDatapointsByLabel('Throttles'), 'Sum');

View File

@ -43,7 +43,10 @@ module.exports = {
if (
_.isObject(apiKeyDefinition) &&
Array.isArray(usagePlan) &&
_.flatten(usagePlan.map((item) => Object.keys(item))).includes(name)
usagePlan
.map((item) => Object.keys(item))
.flat()
.includes(name)
) {
keyNumber = 0;
apiKeyDefinition[name].forEach((key) => {

View File

@ -6,8 +6,8 @@ const pickWebsocketsTemplatePart = require('./pick-websockets-template-part');
module.exports = {
compileDeployment() {
const dependentResourceIds = _.flatten(
this.validated.events.map((event) => {
const dependentResourceIds = this.validated.events
.map((event) => {
const result = [];
if (event.routeResponseSelectionExpression) {
result.push(this.provider.naming.getWebsocketsRouteResponseLogicalId(event.route));
@ -15,7 +15,8 @@ module.exports = {
result.push(this.provider.naming.getWebsocketsRouteLogicalId(event.route));
return result;
})
);
.flat();
const websocketsTemplatePart = pickWebsocketsTemplatePart(
this.serverless.service.provider.compiledCloudFormationTemplate,
this.provider.naming.getWebsocketsApiLogicalId()

View File

@ -1,8 +1,6 @@
'use strict';
const _ = require('lodash');
module.exports = (stacks, prefix, service, stage) =>
_.flatten(stacks).map((entry) => ({
stacks.flat().map((entry) => ({
Key: `${prefix}/${service}/${stage}/${entry.directory}/${entry.file}`,
}));