@middy/util 7.0.0-alpha.2 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +43 -0
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -174,6 +174,49 @@ export const clearCache = (inputKeys = null) => {
174
174
  }
175
175
  };
176
176
 
177
+ // context
178
+ // https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html
179
+ export const lambdaContextKeys = [
180
+ "functionName",
181
+ "functionVersion",
182
+ "invokedFunctionArn",
183
+ "memoryLimitInMB",
184
+ "awsRequestId",
185
+ "logGroupName",
186
+ "logStreamName",
187
+ "identity",
188
+ "clientContext",
189
+ "callbackWaitsForEmptyEventLoop",
190
+ ];
191
+
192
+ export const executionContextKeys = [
193
+ //'requestId',
194
+ "tenantId",
195
+ ];
196
+
197
+ export const isExecutionModeDurable = (context) => {
198
+ // using `context instanceof DurableContextImpl` would be better
199
+ // but would require an extra dependency
200
+ if (context.constructor.name === "DurableContextImpl") {
201
+ return true;
202
+ }
203
+ return false;
204
+ };
205
+
206
+ export const executionContext = (key, context) => {
207
+ if (isExecutionModeDurable(context)) {
208
+ return request.context.executionContext[key];
209
+ }
210
+ return request.context[key];
211
+ };
212
+
213
+ export const lambdaContext = (key, context) => {
214
+ if (isExecutionModeDurable(context)) {
215
+ return request.context.lambdaContext[key];
216
+ }
217
+ return request.context[key];
218
+ };
219
+
177
220
  export const jsonSafeParse = (text, reviver) => {
178
221
  if (typeof text !== "string") return text;
179
222
  const firstChar = text[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/util",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0",
4
4
  "description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "@aws-sdk/client-ssm": "^3.0.0",
62
- "@middy/core": "7.0.0-alpha.2",
62
+ "@middy/core": "7.0.0",
63
63
  "@types/aws-lambda": "^8.10.76",
64
64
  "@types/node": "^22.0.0",
65
65
  "aws-xray-sdk": "^3.3.3"