Skip to content

Commit b89d442

Browse files
committed
pass object args to sendEvent
1 parent 1b2ffcc commit b89d442

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/client/index.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
RunResult,
23
WorkpoolOptions,
34
WorkpoolRetryOptions,
45
} from "@convex-dev/workpool";
@@ -267,24 +268,29 @@ export class WorkflowManager {
267268
*/
268269
async sendEvent<T = null, Name extends string = string>(
269270
ctx: RunMutationCtx,
270-
workflowId: WorkflowId,
271-
args: EventSpec<Name, T>,
272-
...runResult: T extends null ? [] : [T]
271+
{
272+
workflowId,
273+
event,
274+
value,
275+
}: (
276+
| { workflowId: WorkflowId; event: EventSpec<Name, T> }
277+
| { workflowId?: undefined; event: EventSpec<Name, T> & { id: string } }
278+
) &
279+
(
280+
| (T extends null
281+
? { value?: null; error?: undefined }
282+
: { value: T; error?: undefined })
283+
| { error: string; value?: undefined }
284+
),
273285
): Promise<EventId<Name>> {
274286
let result = {
275287
kind: "success" as const,
276-
returnValue: runResult[0] ?? (null as T),
277-
};
278-
if (args.validator && result.kind === "success") {
279-
result = {
280-
...result,
281-
returnValue: parse(args.validator, result.returnValue),
282-
};
283-
}
288+
returnValue: event.validator ? parse(event.validator, value) : value,
289+
} satisfies RunResult;
284290
return (await ctx.runMutation(this.component.event.send, {
285-
eventId: args.id,
291+
eventId: event.id,
286292
result,
287-
name: args.name,
293+
name: event.name,
288294
workflowId: workflowId,
289295
workpoolOptions: this.options?.workpoolOptions,
290296
})) as EventId<Name>;

0 commit comments

Comments
 (0)