serverless-api-gateway-caching
Advanced tools
Comparing version 1.3.5 to 1.3.6
{ | ||
"name": "serverless-api-gateway-caching", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.", | ||
@@ -5,0 +5,0 @@ "main": "src/apiGatewayCachingPlugin.js", |
const isEmpty = require('lodash.isempty'); | ||
const { retrieveRestApiId } = require('./restApiId'); | ||
const MAX_PATCH_OPERATIONS_PER_STAGE_UPDATE = 80; | ||
@@ -136,2 +137,27 @@ String.prototype.replaceAll = function (search, replacement) { | ||
const updateStageFor = async (serverless, params, stage, region) => { | ||
const chunkSize = MAX_PATCH_OPERATIONS_PER_STAGE_UPDATE; | ||
const { patchOperations } = params; | ||
const paramsInChunks = []; | ||
if (patchOperations.length > chunkSize) { | ||
for (let i = 0; i < patchOperations.length; i += chunkSize) { | ||
paramsInChunks.push({ | ||
restApiId: params.restApiId, | ||
stageName: params.stageName, | ||
patchOperations: patchOperations.slice(i, i + chunkSize) | ||
}); | ||
} | ||
} | ||
else { | ||
paramsInChunks.push(params); | ||
} | ||
for (let index in paramsInChunks) { | ||
serverless.cli.log(`[serverless-api-gateway-caching] Updating API Gateway cache settings (${index + 1} of ${paramsInChunks.length}).`); | ||
await serverless.providers.aws.request('APIGateway', 'updateStage', paramsInChunks[index], stage, region); | ||
} | ||
serverless.cli.log(`[serverless-api-gateway-caching] Done updating API Gateway cache settings.`); | ||
} | ||
const updateStageCacheSettings = async (settings, serverless) => { | ||
@@ -162,7 +188,5 @@ // do nothing if caching settings are not defined | ||
serverless.cli.log(`[serverless-api-gateway-caching] Updating API Gateway cache settings.`); | ||
await serverless.providers.aws.request('APIGateway', 'updateStage', params, settings.stage, settings.region); | ||
serverless.cli.log(`[serverless-api-gateway-caching] Done updating API Gateway cache settings.`); | ||
await updateStageFor(serverless, params, settings.stage, settings.region); | ||
} | ||
module.exports = updateStageCacheSettings; |
23393
431