@upstash/workflow 0.1.1-canary → 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.
@@ -374,13 +374,41 @@ declare class WorkflowContext<TInitialPayload = unknown> {
374
374
  * @param headers call headers
375
375
  * @returns call result (parsed as JSON if possible)
376
376
  */
377
- call(stepName: string, callSettings: {
378
- url: string;
379
- method?: HTTPMethods;
380
- body?: unknown;
381
- headers?: Record<string, string>;
382
- }): Promise<CallResponse>;
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
+ */
383
410
  waitForEvent(stepName: string, eventId: string, timeout: string | number): Promise<WaitStepResponse>;
411
+ notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
384
412
  /**
385
413
  * Adds steps to the executor. Needed so that it can be overwritten in
386
414
  * DisabledWorkflowContext.
@@ -433,7 +461,7 @@ type WaitFields = {
433
461
  };
434
462
  type NotifyFields = {
435
463
  notifyEventId?: string;
436
- notifyBody?: string;
464
+ eventData?: string;
437
465
  };
438
466
  type Step<TResult = unknown, TBody = unknown> = {
439
467
  /**
@@ -587,10 +615,6 @@ type FailureFunctionPayload = {
587
615
  * Makes all fields except the ones selected required
588
616
  */
589
617
  type RequiredExceptFields<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
590
- type WaitResult<TResult = unknown> = {
591
- result: TResult;
592
- timeout: boolean;
593
- };
594
618
  type Waiter = {
595
619
  url: string;
596
620
  deadline: number;
@@ -602,7 +626,6 @@ type Waiter = {
602
626
  type NotifyResponse = {
603
627
  waiter: Waiter;
604
628
  messageId: string;
605
- deduplicated: boolean;
606
629
  error: string;
607
630
  };
608
631
  type WaitRequest = {
@@ -614,13 +637,29 @@ type WaitRequest = {
614
637
  step: Step;
615
638
  };
616
639
  type WaitStepResponse = {
640
+ /**
641
+ * whether the wait for event step timed out. false if
642
+ * the step is notified
643
+ */
617
644
  timeout: boolean;
618
- notifyBody: unknown;
645
+ /**
646
+ * body passed in notify request
647
+ */
648
+ eventData: unknown;
619
649
  };
620
- type CallResponse = {
621
- status: number;
622
- body: unknown;
623
- header: Record<string, string[]>;
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[];
624
663
  };
625
664
 
626
- export { type AsyncStepFunction as A, type CallResponse as C, 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 };
@@ -374,13 +374,41 @@ declare class WorkflowContext<TInitialPayload = unknown> {
374
374
  * @param headers call headers
375
375
  * @returns call result (parsed as JSON if possible)
376
376
  */
377
- call(stepName: string, callSettings: {
378
- url: string;
379
- method?: HTTPMethods;
380
- body?: unknown;
381
- headers?: Record<string, string>;
382
- }): Promise<CallResponse>;
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
+ */
383
410
  waitForEvent(stepName: string, eventId: string, timeout: string | number): Promise<WaitStepResponse>;
411
+ notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
384
412
  /**
385
413
  * Adds steps to the executor. Needed so that it can be overwritten in
386
414
  * DisabledWorkflowContext.
@@ -433,7 +461,7 @@ type WaitFields = {
433
461
  };
434
462
  type NotifyFields = {
435
463
  notifyEventId?: string;
436
- notifyBody?: string;
464
+ eventData?: string;
437
465
  };
438
466
  type Step<TResult = unknown, TBody = unknown> = {
439
467
  /**
@@ -587,10 +615,6 @@ type FailureFunctionPayload = {
587
615
  * Makes all fields except the ones selected required
588
616
  */
589
617
  type RequiredExceptFields<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
590
- type WaitResult<TResult = unknown> = {
591
- result: TResult;
592
- timeout: boolean;
593
- };
594
618
  type Waiter = {
595
619
  url: string;
596
620
  deadline: number;
@@ -602,7 +626,6 @@ type Waiter = {
602
626
  type NotifyResponse = {
603
627
  waiter: Waiter;
604
628
  messageId: string;
605
- deduplicated: boolean;
606
629
  error: string;
607
630
  };
608
631
  type WaitRequest = {
@@ -614,13 +637,29 @@ type WaitRequest = {
614
637
  step: Step;
615
638
  };
616
639
  type WaitStepResponse = {
640
+ /**
641
+ * whether the wait for event step timed out. false if
642
+ * the step is notified
643
+ */
617
644
  timeout: boolean;
618
- notifyBody: unknown;
645
+ /**
646
+ * body passed in notify request
647
+ */
648
+ eventData: unknown;
619
649
  };
620
- type CallResponse = {
621
- status: number;
622
- body: unknown;
623
- header: Record<string, string[]>;
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[];
624
663
  };
625
664
 
626
- export { type AsyncStepFunction as A, type CallResponse as C, 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 };