From 5b6fa539a89d5f95f22cb235cb1d00eb16ec7a36 Mon Sep 17 00:00:00 2001 From: Steven Yuan Date: Wed, 13 Sep 2023 11:51:53 -0700 Subject: [PATCH] Add `getSmithyContext()` helper function --- .changeset/modern-vans-jam.md | 5 +++++ packages/util-middleware/src/getSmithyContext.ts | 7 +++++++ packages/util-middleware/src/index.ts | 4 ++++ 3 files changed, 16 insertions(+) create mode 100644 .changeset/modern-vans-jam.md create mode 100644 packages/util-middleware/src/getSmithyContext.ts diff --git a/.changeset/modern-vans-jam.md b/.changeset/modern-vans-jam.md new file mode 100644 index 00000000000..2d677d87f88 --- /dev/null +++ b/.changeset/modern-vans-jam.md @@ -0,0 +1,5 @@ +--- +"@smithy/util-middleware": patch +--- + +Add `getSmithyContext()` helper function diff --git a/packages/util-middleware/src/getSmithyContext.ts b/packages/util-middleware/src/getSmithyContext.ts new file mode 100644 index 00000000000..70ad89bcf81 --- /dev/null +++ b/packages/util-middleware/src/getSmithyContext.ts @@ -0,0 +1,7 @@ +import { HandlerExecutionContext, SMITHY_CONTEXT_KEY } from "@smithy/types"; + +/** + * @internal + */ +export const getSmithyContext = (context: HandlerExecutionContext): Record => + context[SMITHY_CONTEXT_KEY] || (context[SMITHY_CONTEXT_KEY] = {}); diff --git a/packages/util-middleware/src/index.ts b/packages/util-middleware/src/index.ts index 37e779c5d53..3869284e42a 100644 --- a/packages/util-middleware/src/index.ts +++ b/packages/util-middleware/src/index.ts @@ -1,3 +1,7 @@ +/** + * @internal + */ +export * from "./getSmithyContext"; /** * @internal */