Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Smithy context to HandlerExecutionContext #927

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-goats-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/types": patch
---

Add Smithy context to `HandlerExecutionContext`
5 changes: 5 additions & 0 deletions .changeset/modern-vans-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/util-middleware": patch
---

Add `getSmithyContext()` helper function
11 changes: 11 additions & 0 deletions packages/types/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ export interface MiddlewareStack<Input extends object, Output extends object> ex
): InitializeHandler<InputType, OutputType>;
}

/**
* @internal
*/
export const SMITHY_CONTEXT_KEY = "__smithy_context";

/**
* @public
*
Expand Down Expand Up @@ -526,6 +531,12 @@ export interface HandlerExecutionContext {
overrideOutputFilterSensitiveLog(...args: any[]): string | void;
}>;

/**
* @internal
* Context for Smithy properties
*/
[SMITHY_CONTEXT_KEY]?: Record<string, unknown>;

[key: string]: any;
}

Expand Down
7 changes: 7 additions & 0 deletions packages/util-middleware/src/getSmithyContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { HandlerExecutionContext, SMITHY_CONTEXT_KEY } from "@smithy/types";

/**
* @internal
*/
export const getSmithyContext = (context: HandlerExecutionContext): Record<string, unknown> =>
context[SMITHY_CONTEXT_KEY] || (context[SMITHY_CONTEXT_KEY] = {});
4 changes: 4 additions & 0 deletions packages/util-middleware/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @internal
*/
export * from "./getSmithyContext";
/**
* @internal
*/
Expand Down