Skip to content

Commit b265f8e

Browse files
authored
Accept WorkflowOptions as const (#1082)
1 parent cddbffb commit b265f8e

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

packages/client/src/schedule-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export function compileScheduleOptions(options: ScheduleOptions): CompiledSchedu
215215
...options.action,
216216
workflowId: options.action.workflowId ?? `${options.scheduleId}-workflow`,
217217
workflowType,
218-
args: options.action.args ?? [],
218+
args: (options.action.args ?? []) as unknown[],
219219
},
220220
};
221221
}
@@ -228,7 +228,7 @@ export function compileUpdatedScheduleOptions(options: ScheduleUpdateOptions): C
228228
action: {
229229
...options.action,
230230
workflowType,
231-
args: options.action.args ?? [],
231+
args: (options.action.args ?? []) as unknown[],
232232
},
233233
};
234234
}

packages/common/src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export type WorkflowResultType<W extends Workflow> = ReturnType<W> extends Promi
6262
*
6363
* Dates are serialized as ISO strings.
6464
*/
65-
export type SearchAttributes = Record<string, SearchAttributeValue | undefined>;
65+
export type SearchAttributes = Record<string, SearchAttributeValue | Readonly<SearchAttributeValue> | undefined>;
6666
export type SearchAttributeValue = string[] | number[] | boolean[] | Date[];
6767

6868
export interface ActivityFunction<P extends any[] = any[], R = any> {

packages/common/src/workflow-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ export type WithWorkflowArgs<W extends Workflow, T> = T &
9696
/**
9797
* Arguments to pass to the Workflow
9898
*/
99-
args: Parameters<W>;
99+
args: Parameters<W> | Readonly<Parameters<W>>;
100100
}
101101
: {
102102
/**
103103
* Arguments to pass to the Workflow
104104
*/
105-
args?: Parameters<W>;
105+
args?: Parameters<W> | Readonly<Parameters<W>>;
106106
});
107107

108108
export interface WorkflowDurationOptions {

packages/test/src/test-schedules.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ if (RUN_INTEGRATION_TESTS) {
4545
test('Can create schedule with calendar', async (t) => {
4646
const { client } = t.context;
4747
const scheduleId = `can-create-schedule-with-calendar-${randomUUID()}`;
48+
const action = {
49+
type: 'startWorkflow',
50+
workflowType: dummyWorkflow,
51+
taskQueue,
52+
} as const;
4853
const handle = await client.schedule.create({
4954
scheduleId,
5055
spec: {
5156
calendars: [{ hour: { start: 2, end: 7, step: 1 } }],
5257
},
53-
action: {
54-
type: 'startWorkflow',
55-
workflowType: dummyWorkflow,
56-
taskQueue,
57-
},
58+
action,
5859
});
5960

6061
try {
@@ -181,23 +182,24 @@ if (RUN_INTEGRATION_TESTS) {
181182
test('Can create schedule with startWorkflow action (with args)', async (t) => {
182183
const { client } = t.context;
183184
const scheduleId = `can-create-schedule-with-startWorkflow-action-${randomUUID()}`;
185+
const action = {
186+
type: 'startWorkflow',
187+
workflowType: dummyWorkflowWith2Args,
188+
args: [3, 4],
189+
taskQueue,
190+
memo: {
191+
'my-memo': 'foo',
192+
},
193+
searchAttributes: {
194+
CustomKeywordField: ['test-value2'],
195+
},
196+
} as const;
184197
const handle = await client.schedule.create({
185198
scheduleId,
186199
spec: {
187200
calendars: [{ hour: { start: 2, end: 7, step: 1 } }],
188201
},
189-
action: {
190-
type: 'startWorkflow',
191-
workflowType: dummyWorkflowWith2Args,
192-
args: [3, 4],
193-
taskQueue,
194-
memo: {
195-
'my-memo': 'foo',
196-
},
197-
searchAttributes: {
198-
CustomKeywordField: ['test-value2'],
199-
},
200-
},
202+
action,
201203
});
202204

203205
try {

packages/workflow/src/workflow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ export async function startChild<T extends Workflow>(
694694
options?: WithWorkflowArgs<T, ChildWorkflowOptions>
695695
): Promise<ChildWorkflowHandle<T>> {
696696
const activator = getActivator();
697-
const optionsWithDefaults = addDefaultWorkflowOptions(options ?? {});
697+
const optionsWithDefaults = addDefaultWorkflowOptions(options ?? ({} as any));
698698
const workflowType = typeof workflowTypeOrFunc === 'string' ? workflowTypeOrFunc : workflowTypeOrFunc.name;
699699
const execute = composeInterceptors(
700700
activator.interceptors.outbound,
@@ -793,7 +793,7 @@ export async function executeChild<T extends Workflow>(
793793
options?: WithWorkflowArgs<T, ChildWorkflowOptions>
794794
): Promise<WorkflowResultType<T>> {
795795
const activator = getActivator();
796-
const optionsWithDefaults = addDefaultWorkflowOptions(options ?? {});
796+
const optionsWithDefaults = addDefaultWorkflowOptions(options ?? ({} as any));
797797
const workflowType = typeof workflowTypeOrFunc === 'string' ? workflowTypeOrFunc : workflowTypeOrFunc.name;
798798
const execute = composeInterceptors(
799799
activator.interceptors.outbound,

0 commit comments

Comments
 (0)