From b867df147aea5e1f57a9d275e2a389efbbcf38aa Mon Sep 17 00:00:00 2001 From: Piotr Grzesik Date: Wed, 23 Sep 2020 13:13:54 +0200 Subject: [PATCH] refactor: Replace `_.{entries|entriesIn|toPairs}` with `Object.entries` (PR #8275) --- lib/classes/ConfigSchemaHandler/index.js | 2 +- lib/classes/ConfigSchemaHandler/normalizeAjvErrors.js | 6 +++--- lib/classes/PluginManager.js | 2 +- lib/plugins/aws/invokeLocal/index.js | 2 +- lib/plugins/aws/package/compile/events/alb/lib/validate.js | 2 +- .../package/compile/events/apiGateway/lib/method/index.js | 2 +- .../compile/events/apiGateway/lib/method/integration.js | 2 +- .../package/compile/events/apiGateway/lib/stage/index.js | 2 +- .../package/compile/events/apiGateway/lib/usagePlanKeys.js | 2 +- lib/plugins/aws/package/compile/events/httpApi/index.js | 6 ++++-- lib/plugins/aws/package/compile/events/s3/index.js | 2 +- lib/plugins/aws/package/lib/mergeCustomProviderResources.js | 4 ++-- lib/plugins/package/lib/packageService.js | 2 +- 13 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/classes/ConfigSchemaHandler/index.js b/lib/classes/ConfigSchemaHandler/index.js index f5fa2d5001d..3cabca001dd 100644 --- a/lib/classes/ConfigSchemaHandler/index.js +++ b/lib/classes/ConfigSchemaHandler/index.js @@ -10,7 +10,7 @@ const ERROR_PREFIX = 'Configuration error'; const WARNING_PREFIX = 'Configuration warning'; const normalizeSchemaObject = (object, instanceSchema) => { - for (const [key, value] of _.entries(object)) { + for (const [key, value] of Object.entries(object)) { if (!_.isObject(value)) continue; if (!value.$ref) { normalizeSchemaObject(value, instanceSchema); diff --git a/lib/classes/ConfigSchemaHandler/normalizeAjvErrors.js b/lib/classes/ConfigSchemaHandler/normalizeAjvErrors.js index 9d524d7cafe..a5bcbe96dc7 100644 --- a/lib/classes/ConfigSchemaHandler/normalizeAjvErrors.js +++ b/lib/classes/ConfigSchemaHandler/normalizeAjvErrors.js @@ -18,7 +18,7 @@ const filterIrreleventEventConfigurationErrors = resultErrorsSet => { const eventTypeErrorsByEvent = _.groupBy(eventTypeErrors, ({ dataPath }) => dataPath); // 3. Process each error group individually - for (const [dataPath, eventEventTypeErrors] of _.entries(eventTypeErrorsByEvent)) { + for (const [dataPath, eventEventTypeErrors] of Object.entries(eventTypeErrorsByEvent)) { // 3.1 Resolve error that signals that no event schema was matched const noMatchingEventError = eventEventTypeErrors.find(({ keyword }) => oneOfKeywords.has(keyword) @@ -35,7 +35,7 @@ const filterIrreleventEventConfigurationErrors = resultErrorsSet => { delete eventEventTypeErrorsByTypeIndex.root; // 3.3 Resolve eventual type configuration errors for intended event type - const eventConfiguredEventTypeErrors = _.entries( + const eventConfiguredEventTypeErrors = Object.entries( eventEventTypeErrorsByTypeIndex ).find(([, errors]) => errors.every(({ keyword }) => keyword !== 'required')); @@ -95,7 +95,7 @@ const filterIrrelevantAnyOfErrors = resultErrorsSet => { } } // 2. Process resolved groups - for (const [oneOfPath, oneOfPathErrors] of _.entries(oneOfErrorsByPath)) { + for (const [oneOfPath, oneOfPathErrors] of Object.entries(oneOfErrorsByPath)) { // 2.1. If just one error, set was already filtered by event configuration errors filter if (oneOfPathErrors.length === 1) continue; // 2.2. Group by dataPath diff --git a/lib/classes/PluginManager.js b/lib/classes/PluginManager.js index 2c52dd00367..8c3dc247f9e 100644 --- a/lib/classes/PluginManager.js +++ b/lib/classes/PluginManager.js @@ -303,7 +303,7 @@ class PluginManager { loadVariableResolvers(pluginInstance) { const pluginName = pluginInstance.constructor.name; - for (const [variablePrefix, resolverOrOptions] of _.entries( + for (const [variablePrefix, resolverOrOptions] of Object.entries( pluginInstance.variableResolvers || {} )) { let options = resolverOrOptions; diff --git a/lib/plugins/aws/invokeLocal/index.js b/lib/plugins/aws/invokeLocal/index.js index 113990d1312..7bae1e1195d 100644 --- a/lib/plugins/aws/invokeLocal/index.js +++ b/lib/plugins/aws/invokeLocal/index.js @@ -183,7 +183,7 @@ class AwsInvokeLocal { const configuredEnvVars = this.getConfiguredEnvVars(); - const promises = _.entries(configuredEnvVars).map(([name, value]) => { + const promises = Object.entries(configuredEnvVars).map(([name, value]) => { let resolver; if (value['Fn::ImportValue']) { resolver = resolveCfImportValue(this.provider, value['Fn::ImportValue']); diff --git a/lib/plugins/aws/package/compile/events/alb/lib/validate.js b/lib/plugins/aws/package/compile/events/alb/lib/validate.js index a09c06441c4..8b31c149f64 100644 --- a/lib/plugins/aws/package/compile/events/alb/lib/validate.js +++ b/lib/plugins/aws/package/compile/events/alb/lib/validate.js @@ -13,7 +13,7 @@ module.exports = { const authorizers = {}; const albAuthConfig = this.serverless.service.provider.alb; if (albAuthConfig) { - for (const [name, auth] of _.entries(albAuthConfig.authorizers)) { + for (const [name, auth] of Object.entries(albAuthConfig.authorizers)) { switch (auth.type) { case 'cognito': case 'oidc': diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.js index 43031ae970b..6ade873b7db 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.js @@ -94,7 +94,7 @@ module.exports = { this.apiGatewayMethodLogicalIds.push(methodLogicalId); if (event.http.request && event.http.request.schema) { - for (const requestSchema of _.entries(event.http.request.schema)) { + for (const requestSchema of Object.entries(event.http.request.schema)) { const contentType = requestSchema[0]; const schema = requestSchema[1]; diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/integration.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/integration.js index 140b18edd6b..060f205a9fb 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/integration.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/integration.js @@ -209,7 +209,7 @@ module.exports = { // set custom request templates if provided if (http.request && typeof http.request.template === 'object') { - _.entries(http.request.template).forEach(([contentType, template]) => { + Object.entries(http.request.template).forEach(([contentType, template]) => { if (template === null) { delete integrationRequestTemplates[contentType]; } else { diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/stage/index.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/stage/index.js index 77beb8baa5f..bc36ef2efea 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/stage/index.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/stage/index.js @@ -24,7 +24,7 @@ module.exports = { // Tags const tagsMerged = Object.assign({}, provider.stackTags, provider.tags); - const Tags = _.entriesIn(tagsMerged).map(pair => ({ + const Tags = Object.entries(tagsMerged).map(pair => ({ Key: pair[0], Value: pair[1], })); diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/usagePlanKeys.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/usagePlanKeys.js index b0becd001c5..df88c5bfa04 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/usagePlanKeys.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/usagePlanKeys.js @@ -35,7 +35,7 @@ module.exports = { this.serverless.service.provider.apiKeys.forEach(apiKeyDefinition => { // if multiple API key types are used - const apiKey = _.entries(apiKeyDefinition)[0]; + const apiKey = Object.entries(apiKeyDefinition)[0]; const name = apiKey[0]; const value = _.last(apiKey); const usagePlansIncludeName = this.apiGatewayUsagePlanNames.includes(name); diff --git a/lib/plugins/aws/package/compile/events/httpApi/index.js b/lib/plugins/aws/package/compile/events/httpApi/index.js index 8c6eb53d790..150f362a218 100644 --- a/lib/plugins/aws/package/compile/events/httpApi/index.js +++ b/lib/plugins/aws/package/compile/events/httpApi/index.js @@ -270,7 +270,7 @@ Object.defineProperties( 'EXTERNAL_HTTP_API_AUTHORIZERS_CONFIG' ); } - for (const [name, authorizerConfig] of _.entries(userAuthorizers)) { + for (const [name, authorizerConfig] of Object.entries(userAuthorizers)) { authorizers.set(name, { name: authorizerConfig.name || name, identitySource: authorizerConfig.identitySource, @@ -302,7 +302,9 @@ Object.defineProperties( })}`; } - for (const [functionName, functionData] of _.entries(this.serverless.service.functions)) { + for (const [functionName, functionData] of Object.entries( + this.serverless.service.functions + )) { const routeTargetData = { functionName, functionAlias: functionData.targetAlias, diff --git a/lib/plugins/aws/package/compile/events/s3/index.js b/lib/plugins/aws/package/compile/events/s3/index.js index 7693cc09473..19eb8f76c84 100644 --- a/lib/plugins/aws/package/compile/events/s3/index.js +++ b/lib/plugins/aws/package/compile/events/s3/index.js @@ -177,7 +177,7 @@ class AwsCompileS3Events { if (bucketsMeta[bucketName]) { const providerBucket = providerS3[bucketsMeta[bucketName].bucketRef]; bucketConf = {}; - for (const [key, value] of _.entries(providerBucket)) { + for (const [key, value] of Object.entries(providerBucket)) { if (key !== 'name') { if (!this.allowedBucketProperties.has(key)) { const errorMessage = [ diff --git a/lib/plugins/aws/package/lib/mergeCustomProviderResources.js b/lib/plugins/aws/package/lib/mergeCustomProviderResources.js index cf6b1909f38..1ca753236ca 100644 --- a/lib/plugins/aws/package/lib/mergeCustomProviderResources.js +++ b/lib/plugins/aws/package/lib/mergeCustomProviderResources.js @@ -27,8 +27,8 @@ module.exports = { if (extensions) { const template = this.serverless.service.provider.compiledCloudFormationTemplate; - for (const [resourceName, resourceDefinition] of _.entries(extensions)) { - for (const [extensionAttributeName, value] of _.entries(resourceDefinition)) { + for (const [resourceName, resourceDefinition] of Object.entries(extensions)) { + for (const [extensionAttributeName, value] of Object.entries(resourceDefinition)) { if (!template.Resources[resourceName]) { template.Resources[resourceName] = {}; this.serverless._logDeprecation( diff --git a/lib/plugins/package/lib/packageService.js b/lib/plugins/package/lib/packageService.js index c27502f0c5d..50357122564 100644 --- a/lib/plugins/package/lib/packageService.js +++ b/lib/plugins/package/lib/packageService.js @@ -267,7 +267,7 @@ module.exports = { filePathStates[key] = !exclude; }); }); - const filePaths = _.toPairs(filePathStates) + const filePaths = Object.entries(filePathStates) .filter(r => r[1] === true) .map(r => r[0]); if (filePaths.length !== 0) return filePaths;