UNPKG

simple-lambda-client

Version:

A simple, convenient way to invoke aws lambda functions with best practices.

26 lines 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSimpleLambdaClientCacheKey = void 0; const cross_sha256_1 = require("cross-sha256"); /** * defines the uri-safe cache key used by simple-lambda-client requests with-simple-caching */ const getSimpleLambdaClientCacheKey = ({ service: serviceName, function: functionName, stage, event, }) => { const idealKey = [ [serviceName, stage, functionName].join('-'), JSON.stringify(event), ].join('.'); // define a human readable part, to help with observability const humanPart = idealKey .replace(/:/g, '.') .replace(/[^\w\-\_\.]/g, '') .replace(/\.\./g, '.'); // define a unique part, to guarantee uniqueness const uniquePart = new cross_sha256_1.sha256() .update(JSON.stringify(idealKey)) .digest('hex'); // join the parts for the full key return [humanPart, uniquePart].join('.'); }; exports.getSimpleLambdaClientCacheKey = getSimpleLambdaClientCacheKey; //# sourceMappingURL=getSimpleLambdaClientCacheKey.js.map