-
Notifications
You must be signed in to change notification settings - Fork 127
Add RawValue support for non-converted Payloads #1664
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,13 @@ import { | |
ActivityCancellationType, | ||
ApplicationFailure, | ||
defineSearchAttributeKey, | ||
RawValue, | ||
SearchAttributePair, | ||
SearchAttributeType, | ||
TypedSearchAttributes, | ||
WorkflowExecutionAlreadyStartedError, | ||
} from '@temporalio/common'; | ||
import { temporal } from '@temporalio/proto'; | ||
import { signalSchedulingWorkflow } from './activities/helpers'; | ||
import { activityStartedSignal } from './workflows/definitions'; | ||
import * as workflows from './workflows'; | ||
|
@@ -386,7 +388,7 @@ test('Query workflow metadata returns handler descriptions', async (t) => { | |
|
||
await worker.runUntil(async () => { | ||
const handle = await startWorkflow(queryWorkflowMetadata); | ||
const meta = await handle.query(workflow.workflowMetadataQuery); | ||
const meta = (await handle.query(workflow.workflowMetadataQuery)) as temporal.api.sdk.v1.IWorkflowMetadata; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not need a cast here. |
||
t.is(meta.definition?.type, 'queryWorkflowMetadata'); | ||
const queryDefinitions = meta.definition?.queryDefinitions; | ||
// Three built-in ones plus dummyQuery1 and dummyQuery2 | ||
|
@@ -1340,6 +1342,31 @@ test('can register search attributes to dev server', async (t) => { | |
await env.teardown(); | ||
}); | ||
|
||
export async function rawValueWorkflow(value: unknown): Promise<RawValue> { | ||
const { rawValueActivity } = workflow.proxyActivities({ startToCloseTimeout: '10s' }); | ||
return await rawValueActivity(new RawValue(value)); | ||
} | ||
|
||
test('workflow and activity can receive/return RawValue', async (t) => { | ||
const { executeWorkflow, createWorker } = helpers(t); | ||
const worker = await createWorker({ | ||
activities: { | ||
async rawValueActivity(value: unknown): Promise<RawValue> { | ||
return new RawValue(value); | ||
}, | ||
}, | ||
}); | ||
|
||
await worker.runUntil(async () => { | ||
const testValue = 'test'; | ||
const rawValue = new RawValue(testValue); | ||
const res = await executeWorkflow(rawValueWorkflow, { | ||
args: [rawValue], | ||
}); | ||
t.deepEqual(res, testValue); | ||
}); | ||
}); | ||
|
||
export async function ChildWorkflowInfo(): Promise<workflow.RootWorkflowInfo | undefined> { | ||
let blocked = true; | ||
workflow.setHandler(unblockSignal, () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
import * as wf from '@temporalio/workflow'; | ||
import type { EnhancedStackTrace } from '@temporalio/workflow/lib/interfaces'; | ||
import { defaultPayloadConverter } from '@temporalio/common/lib/converter/payload-converter'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import |
||
import type * as activities from '../activities'; | ||
import { unblockOrCancel } from './unblock-or-cancel'; | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ import { | |||||
WorkflowUpdateValidatorType, | ||||||
mapFromPayloads, | ||||||
fromPayloadsAtIndex, | ||||||
RawValue, | ||||||
WorkflowFunctionWithOptions, | ||||||
VersioningBehavior, | ||||||
WorkflowDefinitionOptions, | ||||||
|
@@ -30,7 +31,7 @@ import { | |||||
} from '@temporalio/common/lib/converter/payload-search-attributes'; | ||||||
import { composeInterceptors } from '@temporalio/common/lib/interceptors'; | ||||||
import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow'; | ||||||
import type { coresdk, temporal } from '@temporalio/proto'; | ||||||
import type { coresdk } from '@temporalio/proto'; | ||||||
import { alea, RNG } from './alea'; | ||||||
import { RootCancellationScope } from './cancellation-scope'; | ||||||
import { UpdateScope } from './update-scope'; | ||||||
|
@@ -41,7 +42,6 @@ import { | |||||
DefaultSignalHandler, | ||||||
StackTraceSDKInfo, | ||||||
StackTraceFileSlice, | ||||||
EnhancedStackTrace, | ||||||
StackTraceFileLocation, | ||||||
WorkflowInfo, | ||||||
WorkflowCreateOptionsInternal, | ||||||
|
@@ -263,17 +263,19 @@ export class Activator implements ActivationHandler { | |||||
'__stack_trace', | ||||||
{ | ||||||
handler: () => { | ||||||
return this.getStackTraces() | ||||||
.map((s) => s.formatted) | ||||||
.join('\n\n'); | ||||||
return new RawValue( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
this.getStackTraces() | ||||||
.map((s) => s.formatted) | ||||||
.join('\n\n') | ||||||
); | ||||||
}, | ||||||
description: 'Returns a sensible stack trace.', | ||||||
}, | ||||||
], | ||||||
[ | ||||||
'__enhanced_stack_trace', | ||||||
{ | ||||||
handler: (): EnhancedStackTrace => { | ||||||
handler: (): RawValue => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const { sourceMap } = this; | ||||||
const sdk: StackTraceSDKInfo = { name: 'typescript', version: pkg.version }; | ||||||
const stacks = this.getStackTraces().map(({ structured: locations }) => ({ locations })); | ||||||
|
@@ -293,15 +295,15 @@ export class Activator implements ActivationHandler { | |||||
} | ||||||
} | ||||||
} | ||||||
return { sdk, stacks, sources }; | ||||||
return new RawValue({ sdk, stacks, sources }); | ||||||
}, | ||||||
description: 'Returns a stack trace annotated with source information.', | ||||||
}, | ||||||
], | ||||||
[ | ||||||
'__temporal_workflow_metadata', | ||||||
{ | ||||||
handler: (): temporal.api.sdk.v1.IWorkflowMetadata => { | ||||||
handler: (): RawValue => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const workflowType = this.info.workflowType; | ||||||
const queryDefinitions = Array.from(this.queryHandlers.entries()).map(([name, value]) => ({ | ||||||
name, | ||||||
|
@@ -315,14 +317,14 @@ export class Activator implements ActivationHandler { | |||||
name, | ||||||
description: value.description, | ||||||
})); | ||||||
return { | ||||||
return new RawValue({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's sad we're loosing type safety check here… There's nothing ensuring that the arg to RawValue complies with the expected type definition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my suggestions elsewhere that adds back type safety. |
||||||
definition: { | ||||||
type: workflowType, | ||||||
queryDefinitions, | ||||||
signalDefinitions, | ||||||
updateDefinitions, | ||||||
}, | ||||||
}; | ||||||
}); | ||||||
}, | ||||||
description: 'Returns metadata associated with this workflow.', | ||||||
}, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
WorkflowReturnType, | ||
WorkflowUpdateValidatorType, | ||
SearchAttributeUpdatePair, | ||
RawValue, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import |
||
compilePriority, | ||
WorkflowDefinitionOptionsOrGetter, | ||
} from '@temporalio/common'; | ||
|
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.
For the sake of type safety, I think we should add an optional generic parameter on RawValue, and save that generic parameter using the type brand pattern. Also, we should accept passing in an optional payload converter, i.e. in cases where user want to proce a specific payload converter (not the default one, and not the one they configured on the worker or client).