|
1 | 1 | import type { |
| 2 | + RunResult, |
2 | 3 | WorkpoolOptions, |
3 | 4 | WorkpoolRetryOptions, |
4 | 5 | } from "@convex-dev/workpool"; |
@@ -267,24 +268,29 @@ export class WorkflowManager { |
267 | 268 | */ |
268 | 269 | async sendEvent<T = null, Name extends string = string>( |
269 | 270 | 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 | + ), |
273 | 285 | ): Promise<EventId<Name>> { |
274 | 286 | let result = { |
275 | 287 | 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; |
284 | 290 | return (await ctx.runMutation(this.component.event.send, { |
285 | | - eventId: args.id, |
| 291 | + eventId: event.id, |
286 | 292 | result, |
287 | | - name: args.name, |
| 293 | + name: event.name, |
288 | 294 | workflowId: workflowId, |
289 | 295 | workpoolOptions: this.options?.workpoolOptions, |
290 | 296 | })) as EventId<Name>; |
|
0 commit comments