-
Notifications
You must be signed in to change notification settings - Fork 169
Add SerializationContext API for core payload/failure conversion paths
#1996
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
Open
THardy98
wants to merge
8
commits into
main
Choose a base branch
from
feat/ts-serialization-context-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d981c4c
initial API with nice docstrings
THardy98 4205e68
Bind converters to workflow and activity serialization context
THardy98 234615e
formatting & linting
THardy98 2a7168b
add ts-prune ignore to SerializationContext interface
THardy98 ab2bd73
use Client instead of WorkflowClient
THardy98 36d0c5d
add encdec helper to reduce redundant assertions
THardy98 4fbf778
formatting
THardy98 d00913d
Merge branch 'main' into feat/ts-serialization-context-core
THardy98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import type { LoadedDataConverter } from './data-converter'; | ||
| import type { FailureConverter } from './failure-converter'; | ||
| import type { PayloadConverter } from './payload-converter'; | ||
|
|
||
| /** | ||
| * Context for payloads owned by a workflow. | ||
| * | ||
| * This is used when converting payloads sent to or received from a workflow. | ||
| * If a workflow interacts with a child workflow or an external workflow, this | ||
| * context refers to that target workflow. | ||
| * | ||
| * @experimental Serialization context is an experimental feature and may change. | ||
| */ | ||
| export interface WorkflowSerializationContext { | ||
| /** Always `'workflow'` for workflow-owned payloads. */ | ||
| type: 'workflow'; | ||
| /** Namespace of the workflow that owns the payload. */ | ||
| namespace: string; | ||
| /** Workflow ID of the workflow that owns the payload. */ | ||
| workflowId: string; | ||
| } | ||
|
|
||
| /** | ||
| * Context for payloads owned by an activity. | ||
| * | ||
| * This is used when converting activity arguments, results, heartbeat details, | ||
| * and activity-related failures. | ||
| * | ||
| * @experimental Serialization context is an experimental feature and may change. | ||
| */ | ||
| export interface ActivitySerializationContext { | ||
| /** Always `'activity'` for activity-owned payloads. */ | ||
| type: 'activity'; | ||
| /** Namespace of the activity that owns the payload. */ | ||
| namespace: string; | ||
| /** | ||
| * Activity ID of the activity that owns the payload. | ||
| * | ||
| * This may be omitted when context is supplied manually and the caller does | ||
| * not know the activity ID. | ||
| */ | ||
| activityId?: string; | ||
| /** Workflow ID of the workflow that scheduled the activity, when known. */ | ||
| workflowId?: string; | ||
| /** Whether the activity is a local activity started from a workflow. */ | ||
| isLocal: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Context passed to payload and failure converters. | ||
| * | ||
| * The context describes the workflow or activity whose payload is being converted. | ||
| * For example: | ||
| * - `client.workflow.start()` uses the target workflow's context. | ||
| * - `executeChild()` uses the child workflow's context, not the parent's. | ||
| * - `scheduleActivity()` uses the scheduled activity's context. | ||
| * | ||
| * @experimental Serialization context is an experimental feature and may change. | ||
| */ | ||
| export type SerializationContext = WorkflowSerializationContext | ActivitySerializationContext; | ||
|
|
||
| /** | ||
| * Return a payload converter bound to `context` if the converter supports context binding. | ||
| */ | ||
| export function withPayloadConverterContext( | ||
| converter: PayloadConverter, | ||
| context: SerializationContext | ||
| ): PayloadConverter { | ||
| return converter.withContext?.(context) ?? converter; | ||
| } | ||
|
|
||
| /** | ||
| * Return a failure converter bound to `context` if the converter supports context binding. | ||
| */ | ||
| export function withFailureConverterContext( | ||
| converter: FailureConverter, | ||
| context: SerializationContext | ||
| ): FailureConverter { | ||
| return converter.withContext?.(context) ?? converter; | ||
| } | ||
|
|
||
| /** | ||
| * Return a loaded data converter with its payload and failure converters bound to `context`. | ||
| * | ||
| * Internal helper for non-workflow code paths. Workflow-isolate code should bind the individual | ||
| * payload or failure converter directly to avoid pulling unnecessary code into the workflow bundle. | ||
| * | ||
| * NOTE: this does *not* bind `context` to payload codecs | ||
| */ | ||
| // ts-prune-ignore-next | ||
| export function withSerializationContext( | ||
| converter: LoadedDataConverter, | ||
| context: SerializationContext | ||
| ): LoadedDataConverter { | ||
| const payloadConverter = withPayloadConverterContext(converter.payloadConverter, context); | ||
| const failureConverter = withFailureConverterContext(converter.failureConverter, context); | ||
|
|
||
| if (payloadConverter === converter.payloadConverter && failureConverter === converter.failureConverter) { | ||
| return converter; | ||
| } | ||
|
|
||
| return { | ||
| payloadConverter, | ||
| failureConverter, | ||
| payloadCodecs: converter.payloadCodecs, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.