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

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

Merged
merged 2 commits into from
Jul 28, 2022
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
7 changes: 4 additions & 3 deletions lib/plugins/aws/deploy/lib/check-for-changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -272,7 +273,7 @@ module.exports = {
return { FunctionName, functionName, logGroupName, logSubscriptionSerialNumber };
});
})
);
.flat();

const cloudwatchLogEventsMap = _.groupBy(cloudwatchLogEvents, 'logGroupName');
const logGroupNames = Object.keys(cloudwatchLogEventsMap);
Expand Down
9 changes: 4 additions & 5 deletions lib/plugins/aws/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ 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));
}
result.push(this.provider.naming.getWebsocketsRouteLogicalId(event.route));
return result;
})
);
.flat();

const websocketsTemplatePart = pickWebsocketsTemplatePart(
this.serverless.service.provider.compiledCloudFormationTemplate,
this.provider.naming.getWebsocketsApiLogicalId()
Expand Down
4 changes: 1 addition & 3 deletions lib/plugins/aws/utils/get-s3-objects-from-stacks.js
Original file line number Diff line number Diff line change
@@ -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}`,
}));