@upstash/workflow 0.1.0 → 0.1.1-canary-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -375,7 +375,40 @@ declare class WorkflowContext<TInitialPayload = unknown> {
375
375
  * @returns call result (parsed as JSON if possible)
376
376
  */
377
377
  call<TResult = unknown, TBody = unknown>(stepName: string, url: string, method: HTTPMethods, body?: TBody, headers?: Record<string, string>): Promise<TResult>;
378
+ /**
379
+ * Makes the workflow run wait until a notify request is sent or until the
380
+ * timeout ends
381
+ *
382
+ * ```ts
383
+ * const { eventData, timeout } = await context.waitForEvent(
384
+ * "wait for event step",
385
+ * "my-event-id",
386
+ * 100 // timeout after 100 seconds
387
+ * );
388
+ * ```
389
+ *
390
+ * To notify a waiting workflow run, you can use the notify method:
391
+ *
392
+ * ```ts
393
+ * import { Client } from "@upstash/workflow";
394
+ *
395
+ * const client = new Client({ token: });
396
+ *
397
+ * await client.notify({
398
+ * eventId: "my-event-id",
399
+ * eventData: "eventData"
400
+ * })
401
+ * ```
402
+ *
403
+ * @param stepName
404
+ * @param eventId event id to wake up the waiting workflow run
405
+ * @param timeout timeout duration in seconds
406
+ * @returns wait response as `{ timeout: boolean, eventData: unknown }`.
407
+ * timeout is true if the wait times out, if notified it is false. eventData
408
+ * is the value passed to `client.notify`.
409
+ */
378
410
  waitForEvent(stepName: string, eventId: string, timeout: string | number): Promise<WaitStepResponse>;
411
+ notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
379
412
  /**
380
413
  * Adds steps to the executor. Needed so that it can be overwritten in
381
414
  * DisabledWorkflowContext.
@@ -428,7 +461,7 @@ type WaitFields = {
428
461
  };
429
462
  type NotifyFields = {
430
463
  notifyEventId?: string;
431
- notifyBody?: string;
464
+ eventData?: string;
432
465
  };
433
466
  type Step<TResult = unknown, TBody = unknown> = {
434
467
  /**
@@ -582,10 +615,6 @@ type FailureFunctionPayload = {
582
615
  * Makes all fields except the ones selected required
583
616
  */
584
617
  type RequiredExceptFields<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
585
- type WaitResult<TResult = unknown> = {
586
- result: TResult;
587
- timeout: boolean;
588
- };
589
618
  type Waiter = {
590
619
  url: string;
591
620
  deadline: number;
@@ -597,7 +626,6 @@ type Waiter = {
597
626
  type NotifyResponse = {
598
627
  waiter: Waiter;
599
628
  messageId: string;
600
- deduplicated: boolean;
601
629
  error: string;
602
630
  };
603
631
  type WaitRequest = {
@@ -609,8 +637,29 @@ type WaitRequest = {
609
637
  step: Step;
610
638
  };
611
639
  type WaitStepResponse = {
640
+ /**
641
+ * whether the wait for event step timed out. false if
642
+ * the step is notified
643
+ */
612
644
  timeout: boolean;
613
- notifyBody: unknown;
645
+ /**
646
+ * body passed in notify request
647
+ */
648
+ eventData: unknown;
649
+ };
650
+ type NotifyStepResponse = {
651
+ /**
652
+ * notified event id
653
+ */
654
+ eventId: string;
655
+ /**
656
+ * event data sent with notify
657
+ */
658
+ eventData: unknown;
659
+ /**
660
+ * response from notify
661
+ */
662
+ notifyResponse: NotifyResponse[];
614
663
  };
615
664
 
616
- export { type AsyncStepFunction as A, type FinishCondition as F, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type WorkflowServeOptions as W, WorkflowContext as a, type WorkflowClient as b, type WorkflowReceiver as c, StepTypes as d, type StepType as e, type RawStep as f, type SyncStepFunction as g, type StepFunction as h, type FailureFunctionPayload as i, type RequiredExceptFields as j, type WaitResult as k, type Waiter as l, type WaitRequest as m, type WaitStepResponse as n, type WorkflowLoggerOptions as o, WorkflowLogger as p };
665
+ export { type AsyncStepFunction as A, type FinishCondition as F, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type FailureFunctionPayload as j, type RequiredExceptFields as k, type WaitRequest as l, type WaitStepResponse as m, type NotifyStepResponse as n, type WorkflowLoggerOptions as o, WorkflowLogger as p };
@@ -375,7 +375,40 @@ declare class WorkflowContext<TInitialPayload = unknown> {
375
375
  * @returns call result (parsed as JSON if possible)
376
376
  */
377
377
  call<TResult = unknown, TBody = unknown>(stepName: string, url: string, method: HTTPMethods, body?: TBody, headers?: Record<string, string>): Promise<TResult>;
378
+ /**
379
+ * Makes the workflow run wait until a notify request is sent or until the
380
+ * timeout ends
381
+ *
382
+ * ```ts
383
+ * const { eventData, timeout } = await context.waitForEvent(
384
+ * "wait for event step",
385
+ * "my-event-id",
386
+ * 100 // timeout after 100 seconds
387
+ * );
388
+ * ```
389
+ *
390
+ * To notify a waiting workflow run, you can use the notify method:
391
+ *
392
+ * ```ts
393
+ * import { Client } from "@upstash/workflow";
394
+ *
395
+ * const client = new Client({ token: });
396
+ *
397
+ * await client.notify({
398
+ * eventId: "my-event-id",
399
+ * eventData: "eventData"
400
+ * })
401
+ * ```
402
+ *
403
+ * @param stepName
404
+ * @param eventId event id to wake up the waiting workflow run
405
+ * @param timeout timeout duration in seconds
406
+ * @returns wait response as `{ timeout: boolean, eventData: unknown }`.
407
+ * timeout is true if the wait times out, if notified it is false. eventData
408
+ * is the value passed to `client.notify`.
409
+ */
378
410
  waitForEvent(stepName: string, eventId: string, timeout: string | number): Promise<WaitStepResponse>;
411
+ notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
379
412
  /**
380
413
  * Adds steps to the executor. Needed so that it can be overwritten in
381
414
  * DisabledWorkflowContext.
@@ -428,7 +461,7 @@ type WaitFields = {
428
461
  };
429
462
  type NotifyFields = {
430
463
  notifyEventId?: string;
431
- notifyBody?: string;
464
+ eventData?: string;
432
465
  };
433
466
  type Step<TResult = unknown, TBody = unknown> = {
434
467
  /**
@@ -582,10 +615,6 @@ type FailureFunctionPayload = {
582
615
  * Makes all fields except the ones selected required
583
616
  */
584
617
  type RequiredExceptFields<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
585
- type WaitResult<TResult = unknown> = {
586
- result: TResult;
587
- timeout: boolean;
588
- };
589
618
  type Waiter = {
590
619
  url: string;
591
620
  deadline: number;
@@ -597,7 +626,6 @@ type Waiter = {
597
626
  type NotifyResponse = {
598
627
  waiter: Waiter;
599
628
  messageId: string;
600
- deduplicated: boolean;
601
629
  error: string;
602
630
  };
603
631
  type WaitRequest = {
@@ -609,8 +637,29 @@ type WaitRequest = {
609
637
  step: Step;
610
638
  };
611
639
  type WaitStepResponse = {
640
+ /**
641
+ * whether the wait for event step timed out. false if
642
+ * the step is notified
643
+ */
612
644
  timeout: boolean;
613
- notifyBody: unknown;
645
+ /**
646
+ * body passed in notify request
647
+ */
648
+ eventData: unknown;
649
+ };
650
+ type NotifyStepResponse = {
651
+ /**
652
+ * notified event id
653
+ */
654
+ eventId: string;
655
+ /**
656
+ * event data sent with notify
657
+ */
658
+ eventData: unknown;
659
+ /**
660
+ * response from notify
661
+ */
662
+ notifyResponse: NotifyResponse[];
614
663
  };
615
664
 
616
- export { type AsyncStepFunction as A, type FinishCondition as F, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type WorkflowServeOptions as W, WorkflowContext as a, type WorkflowClient as b, type WorkflowReceiver as c, StepTypes as d, type StepType as e, type RawStep as f, type SyncStepFunction as g, type StepFunction as h, type FailureFunctionPayload as i, type RequiredExceptFields as j, type WaitResult as k, type Waiter as l, type WaitRequest as m, type WaitStepResponse as n, type WorkflowLoggerOptions as o, WorkflowLogger as p };
665
+ export { type AsyncStepFunction as A, type FinishCondition as F, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type FailureFunctionPayload as j, type RequiredExceptFields as k, type WaitRequest as l, type WaitStepResponse as m, type NotifyStepResponse as n, type WorkflowLoggerOptions as o, WorkflowLogger as p };