Skip to content

Commit 882d3db

Browse files
committed
improve RawValue API
1 parent 0d9b4d8 commit 882d3db

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/common/src/converter/payload-converter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ export class RawValue<T = unknown> {
122122
private readonly _payload: Payload;
123123
private readonly [rawPayloadTypeBrand]: T = undefined as T;
124124

125-
constructor(value: T, payloadConverter: PayloadConverter = defaultPayloadConverter) {
126-
this._payload = payloadConverter.toPayload(value);
125+
private constructor(payload: Payload) {
126+
this._payload = payload;
127+
}
128+
129+
static fromValue<T>(value: T, converter: PayloadConverter = defaultPayloadConverter): RawValue<T> {
130+
return new RawValue<T>(converter.toPayload(value));
127131
}
128132

129133
get payload(): Payload {

packages/test/src/test-integration-workflows.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,22 +1320,22 @@ test.serial('can register search attributes to dev server', async (t) => {
13201320

13211321
export async function rawValueWorkflow(value: unknown): Promise<RawValue> {
13221322
const { rawValueActivity } = workflow.proxyActivities({ startToCloseTimeout: '10s' });
1323-
return await rawValueActivity(new RawValue(value));
1323+
return await rawValueActivity(RawValue.fromValue(value));
13241324
}
13251325

13261326
test('workflow and activity can receive/return RawValue', async (t) => {
13271327
const { executeWorkflow, createWorker } = helpers(t);
13281328
const worker = await createWorker({
13291329
activities: {
13301330
async rawValueActivity(value: unknown): Promise<RawValue> {
1331-
return new RawValue(value);
1331+
return RawValue.fromValue(value);
13321332
},
13331333
},
13341334
});
13351335

13361336
await worker.runUntil(async () => {
13371337
const testValue = 'test';
1338-
const rawValue = new RawValue(testValue);
1338+
const rawValue = RawValue.fromValue(testValue);
13391339
const res = await executeWorkflow(rawValueWorkflow, {
13401340
args: [rawValue],
13411341
});

packages/workflow/src/internals.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export class Activator implements ActivationHandler {
280280
STACK_TRACE_QUERY_NAME,
281281
{
282282
handler: () => {
283-
return new RawValue<string>(
283+
return RawValue.fromValue(
284284
this.getStackTraces()
285285
.map((s) => s.formatted)
286286
.join('\n\n')
@@ -312,7 +312,7 @@ export class Activator implements ActivationHandler {
312312
}
313313
}
314314
}
315-
return new RawValue<EnhancedStackTrace>({ sdk, stacks, sources });
315+
return RawValue.fromValue({ sdk, stacks, sources });
316316
},
317317
description: 'Returns a stack trace annotated with source information.',
318318
},
@@ -334,7 +334,7 @@ export class Activator implements ActivationHandler {
334334
name,
335335
description: value.description,
336336
}));
337-
return new RawValue<temporal.api.sdk.v1.IWorkflowMetadata>({
337+
return RawValue.fromValue({
338338
definition: {
339339
type: workflowType,
340340
queryDefinitions,

0 commit comments

Comments
 (0)