@upstash/workflow 0.1.4 → 0.2.0

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.
package/hono.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  serve
3
- } from "./chunk-HO2SB246.mjs";
3
+ } from "./chunk-5R2BFC3N.mjs";
4
4
 
5
5
  // platforms/hono.ts
6
6
  var serve2 = (routeFunction, options) => {
package/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-CQuc-j8n.mjs';
2
- export { A as AsyncStepFunction, C as CallResponse, D as Duration, j as FailureFunctionPayload, F as FinishCondition, L as LogLevel, n as NotifyStepResponse, P as ParallelCallState, g as RawStep, k as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, l as WaitRequest, m as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, p as WorkflowLogger, o as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-CQuc-j8n.mjs';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-Cki_MHrh.mjs';
2
+ export { A as AsyncStepFunction, C as CallResponse, D as Duration, j as FailureFunctionPayload, F as FinishCondition, L as LogLevel, n as NotifyStepResponse, P as ParallelCallState, g as RawStep, k as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, o as WaitEventOptions, l as WaitRequest, m as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, q as WorkflowLogger, p as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-Cki_MHrh.mjs';
3
3
  import { Client as Client$1, QstashError } from '@upstash/qstash';
4
4
 
5
5
  /**
@@ -30,20 +30,62 @@ declare class Client {
30
30
  /**
31
31
  * Cancel an ongoing workflow
32
32
  *
33
+ * Returns true if workflow is canceled succesfully. Otherwise, throws error.
34
+ *
35
+ * There are multiple ways you can cancel workflows:
36
+ * - pass one or more workflow run ids to cancel them
37
+ * - pass a workflow url to cancel all runs starting with this url
38
+ * - cancel all pending or active workflow runs
39
+ *
40
+ * ### Cancel a set of workflow runs
41
+ *
33
42
  * ```ts
34
- * import { Client } from "@upstash/workflow";
43
+ * // cancel a single workflow
44
+ * await client.cancel({ ids: "<WORKFLOW_RUN_ID>" })
35
45
  *
36
- * const client = new Client({ token: "<QSTASH_TOKEN>" })
37
- * await client.cancel({ workflowRunId: "<WORKFLOW_RUN_ID>" })
46
+ * // cancel a set of workflow runs
47
+ * await client.cancel({ ids: [
48
+ * "<WORKFLOW_RUN_ID_1>",
49
+ * "<WORKFLOW_RUN_ID_2>",
50
+ * ]})
38
51
  * ```
39
52
  *
40
- * @param workflowRunId run id of the workflow to delete
53
+ * ### Cancel workflows starting with a url
54
+ *
55
+ * If you have an endpoint called `https://your-endpoint.com` and you
56
+ * want to cancel all workflow runs on it, you can use `urlStartingWith`.
57
+ *
58
+ * Note that this will cancel workflows in all endpoints under
59
+ * `https://your-endpoint.com`.
60
+ *
61
+ * ```ts
62
+ * await client.cancel({ urlStartingWith: "https://your-endpoint.com" })
63
+ * ```
64
+ *
65
+ * ### Cancel *all* workflows
66
+ *
67
+ * To cancel all pending and currently running workflows, you can
68
+ * do it like this:
69
+ *
70
+ * ```ts
71
+ * await client.cancel({ all: true })
72
+ * ```
73
+ *
74
+ * @param ids run id of the workflow to delete
75
+ * @param urlStartingWith cancel workflows starting with this url. Will be ignored
76
+ * if `ids` parameter is set.
77
+ * @param all set to true in order to cancel all workflows. Will be ignored
78
+ * if `ids` or `urlStartingWith` parameters are set.
41
79
  * @returns true if workflow is succesfully deleted. Otherwise throws QStashError
42
80
  */
43
- cancel({ workflowRunId }: {
44
- workflowRunId: string;
45
- }): Promise<true | {
46
- error: string;
81
+ cancel({ ids, urlStartingWith, all, }: {
82
+ ids?: string | string[];
83
+ urlStartingWith?: string;
84
+ all?: true;
85
+ }): Promise<{
86
+ cancelled: number;
87
+ } & {
88
+ error?: string;
47
89
  }>;
48
90
  /**
49
91
  * Notify a workflow run waiting for an event
@@ -86,13 +128,13 @@ declare class Client {
86
128
  * Trigger new workflow run and returns the workflow run id
87
129
  *
88
130
  * ```ts
89
- * const { workflowRunId } await client.trigger({
131
+ * const { workflowRunId } = await client.trigger({
90
132
  * url: "https://workflow-endpoint.com",
91
- * body: "hello there!", // optional body
92
- * headers: { ... }, // optional headers
93
- * workflowRunId: "my-workflow", // optional workflow run id
94
- * retries: 3 // optional retries in the initial request
95
- * })
133
+ * body: "hello there!", // Optional body
134
+ * headers: { ... }, // Optional headers
135
+ * workflowRunId: "my-workflow", // Optional workflow run ID
136
+ * retries: 3 // Optional retries for the initial request
137
+ * });
96
138
  *
97
139
  * console.log(workflowRunId)
98
140
  * // wfr_my-workflow
@@ -124,16 +166,27 @@ declare class Client {
124
166
  /**
125
167
  * Error raised during Workflow execution
126
168
  */
127
- declare class QStashWorkflowError extends QstashError {
169
+ declare class WorkflowError extends QstashError {
128
170
  constructor(message: string);
129
171
  }
130
172
  /**
131
- * Raised when the workflow executes a function and aborts
173
+ * Raised when the workflow executes a function successfully
174
+ * and aborts to end the execution
132
175
  */
133
- declare class QStashWorkflowAbort extends Error {
176
+ declare class WorkflowAbort extends Error {
134
177
  stepInfo?: Step;
135
178
  stepName: string;
136
- constructor(stepName: string, stepInfo?: Step);
179
+ /**
180
+ * whether workflow is to be canceled on abort
181
+ */
182
+ cancelWorkflow: boolean;
183
+ /**
184
+ *
185
+ * @param stepName name of the aborting step
186
+ * @param stepInfo step information
187
+ * @param cancelWorkflow
188
+ */
189
+ constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
137
190
  }
138
191
 
139
- export { Client, NotifyResponse, QStashWorkflowAbort, QStashWorkflowError, RouteFunction, Step, Waiter, WorkflowServeOptions, serve };
192
+ export { Client, NotifyResponse, RouteFunction, Step, Waiter, WorkflowAbort, WorkflowError, WorkflowServeOptions, serve };
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-CQuc-j8n.js';
2
- export { A as AsyncStepFunction, C as CallResponse, D as Duration, j as FailureFunctionPayload, F as FinishCondition, L as LogLevel, n as NotifyStepResponse, P as ParallelCallState, g as RawStep, k as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, l as WaitRequest, m as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, p as WorkflowLogger, o as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-CQuc-j8n.js';
1
+ import { R as RouteFunction, W as WorkflowServeOptions, N as NotifyResponse, a as Waiter, S as Step } from './types-Cki_MHrh.js';
2
+ export { A as AsyncStepFunction, C as CallResponse, D as Duration, j as FailureFunctionPayload, F as FinishCondition, L as LogLevel, n as NotifyStepResponse, P as ParallelCallState, g as RawStep, k as RequiredExceptFields, i as StepFunction, f as StepType, e as StepTypes, h as SyncStepFunction, o as WaitEventOptions, l as WaitRequest, m as WaitStepResponse, c as WorkflowClient, b as WorkflowContext, q as WorkflowLogger, p as WorkflowLoggerOptions, d as WorkflowReceiver } from './types-Cki_MHrh.js';
3
3
  import { Client as Client$1, QstashError } from '@upstash/qstash';
4
4
 
5
5
  /**
@@ -30,20 +30,62 @@ declare class Client {
30
30
  /**
31
31
  * Cancel an ongoing workflow
32
32
  *
33
+ * Returns true if workflow is canceled succesfully. Otherwise, throws error.
34
+ *
35
+ * There are multiple ways you can cancel workflows:
36
+ * - pass one or more workflow run ids to cancel them
37
+ * - pass a workflow url to cancel all runs starting with this url
38
+ * - cancel all pending or active workflow runs
39
+ *
40
+ * ### Cancel a set of workflow runs
41
+ *
33
42
  * ```ts
34
- * import { Client } from "@upstash/workflow";
43
+ * // cancel a single workflow
44
+ * await client.cancel({ ids: "<WORKFLOW_RUN_ID>" })
35
45
  *
36
- * const client = new Client({ token: "<QSTASH_TOKEN>" })
37
- * await client.cancel({ workflowRunId: "<WORKFLOW_RUN_ID>" })
46
+ * // cancel a set of workflow runs
47
+ * await client.cancel({ ids: [
48
+ * "<WORKFLOW_RUN_ID_1>",
49
+ * "<WORKFLOW_RUN_ID_2>",
50
+ * ]})
38
51
  * ```
39
52
  *
40
- * @param workflowRunId run id of the workflow to delete
53
+ * ### Cancel workflows starting with a url
54
+ *
55
+ * If you have an endpoint called `https://your-endpoint.com` and you
56
+ * want to cancel all workflow runs on it, you can use `urlStartingWith`.
57
+ *
58
+ * Note that this will cancel workflows in all endpoints under
59
+ * `https://your-endpoint.com`.
60
+ *
61
+ * ```ts
62
+ * await client.cancel({ urlStartingWith: "https://your-endpoint.com" })
63
+ * ```
64
+ *
65
+ * ### Cancel *all* workflows
66
+ *
67
+ * To cancel all pending and currently running workflows, you can
68
+ * do it like this:
69
+ *
70
+ * ```ts
71
+ * await client.cancel({ all: true })
72
+ * ```
73
+ *
74
+ * @param ids run id of the workflow to delete
75
+ * @param urlStartingWith cancel workflows starting with this url. Will be ignored
76
+ * if `ids` parameter is set.
77
+ * @param all set to true in order to cancel all workflows. Will be ignored
78
+ * if `ids` or `urlStartingWith` parameters are set.
41
79
  * @returns true if workflow is succesfully deleted. Otherwise throws QStashError
42
80
  */
43
- cancel({ workflowRunId }: {
44
- workflowRunId: string;
45
- }): Promise<true | {
46
- error: string;
81
+ cancel({ ids, urlStartingWith, all, }: {
82
+ ids?: string | string[];
83
+ urlStartingWith?: string;
84
+ all?: true;
85
+ }): Promise<{
86
+ cancelled: number;
87
+ } & {
88
+ error?: string;
47
89
  }>;
48
90
  /**
49
91
  * Notify a workflow run waiting for an event
@@ -86,13 +128,13 @@ declare class Client {
86
128
  * Trigger new workflow run and returns the workflow run id
87
129
  *
88
130
  * ```ts
89
- * const { workflowRunId } await client.trigger({
131
+ * const { workflowRunId } = await client.trigger({
90
132
  * url: "https://workflow-endpoint.com",
91
- * body: "hello there!", // optional body
92
- * headers: { ... }, // optional headers
93
- * workflowRunId: "my-workflow", // optional workflow run id
94
- * retries: 3 // optional retries in the initial request
95
- * })
133
+ * body: "hello there!", // Optional body
134
+ * headers: { ... }, // Optional headers
135
+ * workflowRunId: "my-workflow", // Optional workflow run ID
136
+ * retries: 3 // Optional retries for the initial request
137
+ * });
96
138
  *
97
139
  * console.log(workflowRunId)
98
140
  * // wfr_my-workflow
@@ -124,16 +166,27 @@ declare class Client {
124
166
  /**
125
167
  * Error raised during Workflow execution
126
168
  */
127
- declare class QStashWorkflowError extends QstashError {
169
+ declare class WorkflowError extends QstashError {
128
170
  constructor(message: string);
129
171
  }
130
172
  /**
131
- * Raised when the workflow executes a function and aborts
173
+ * Raised when the workflow executes a function successfully
174
+ * and aborts to end the execution
132
175
  */
133
- declare class QStashWorkflowAbort extends Error {
176
+ declare class WorkflowAbort extends Error {
134
177
  stepInfo?: Step;
135
178
  stepName: string;
136
- constructor(stepName: string, stepInfo?: Step);
179
+ /**
180
+ * whether workflow is to be canceled on abort
181
+ */
182
+ cancelWorkflow: boolean;
183
+ /**
184
+ *
185
+ * @param stepName name of the aborting step
186
+ * @param stepInfo step information
187
+ * @param cancelWorkflow
188
+ */
189
+ constructor(stepName: string, stepInfo?: Step, cancelWorkflow?: boolean);
137
190
  }
138
191
 
139
- export { Client, NotifyResponse, QStashWorkflowAbort, QStashWorkflowError, RouteFunction, Step, Waiter, WorkflowServeOptions, serve };
192
+ export { Client, NotifyResponse, RouteFunction, Step, Waiter, WorkflowAbort, WorkflowError, WorkflowServeOptions, serve };