@upstash/workflow 0.2.12 → 0.2.14

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/index.mjs CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  makeNotifyRequest,
11
11
  serve,
12
12
  triggerFirstInvocation
13
- } from "./chunk-4GTHIL7S.mjs";
13
+ } from "./chunk-RMS2NQ3K.mjs";
14
14
 
15
15
  // src/client/index.ts
16
16
  import { Client as QStashClient } from "@upstash/qstash";
@@ -140,63 +140,39 @@ var Client = class {
140
140
  async getWaiters({ eventId }) {
141
141
  return await makeGetWaitersRequest(this.client.http, eventId);
142
142
  }
143
- /**
144
- * Trigger new workflow run and returns the workflow run id
145
- *
146
- * ```ts
147
- * const { workflowRunId } = await client.trigger({
148
- * url: "https://workflow-endpoint.com",
149
- * body: "hello there!", // Optional body
150
- * headers: { ... }, // Optional headers
151
- * workflowRunId: "my-workflow", // Optional workflow run ID
152
- * retries: 3 // Optional retries for the initial request
153
- * });
154
- *
155
- * console.log(workflowRunId)
156
- * // wfr_my-workflow
157
- * ```
158
- *
159
- * @param url URL of the workflow
160
- * @param body body to start the workflow with
161
- * @param headers headers to use in the request
162
- * @param workflowRunId optional workflow run id to use. mind that
163
- * you should pass different workflow run ids for different runs.
164
- * The final workflowRunId will be `wfr_${workflowRunId}`, in
165
- * other words: the workflow run id you pass will be prefixed
166
- * with `wfr_`.
167
- * @param retries retry to use in the initial request. in the rest of
168
- * the workflow, `retries` option of the `serve` will be used.
169
- * @returns workflow run id
170
- */
171
- async trigger({
172
- url,
173
- body,
174
- headers,
175
- workflowRunId,
176
- retries,
177
- flowControl
178
- }) {
179
- const finalWorkflowRunId = getWorkflowRunId(workflowRunId);
180
- const context = new WorkflowContext({
181
- qstashClient: this.client,
182
- // @ts-expect-error headers type mismatch
183
- headers: new Headers(headers ?? {}),
184
- initialPayload: body,
185
- steps: [],
186
- url,
187
- workflowRunId: finalWorkflowRunId,
188
- retries,
189
- telemetry: void 0,
190
- // can't know workflow telemetry here
191
- flowControl
192
- });
193
- const result = await triggerFirstInvocation({
194
- workflowContext: context,
195
- telemetry: void 0
196
- // can't know workflow telemetry here
143
+ async trigger(params) {
144
+ const isBatchInput = Array.isArray(params);
145
+ const options = isBatchInput ? params : [params];
146
+ const invocations = options.map((option) => {
147
+ const failureUrl = option.useFailureFunction ? option.url : option.failureUrl;
148
+ const finalWorkflowRunId = getWorkflowRunId(option.workflowRunId);
149
+ const context = new WorkflowContext({
150
+ qstashClient: this.client,
151
+ // @ts-expect-error headers type mismatch
152
+ headers: new Headers(option.headers ?? {}),
153
+ initialPayload: option.body,
154
+ steps: [],
155
+ url: option.url,
156
+ workflowRunId: finalWorkflowRunId,
157
+ retries: option.retries,
158
+ telemetry: void 0,
159
+ // can't know workflow telemetry here
160
+ flowControl: option.flowControl,
161
+ failureUrl
162
+ });
163
+ return {
164
+ workflowContext: context,
165
+ telemetry: void 0,
166
+ // can't know workflow telemetry here
167
+ delay: option.delay
168
+ };
197
169
  });
170
+ const result = await triggerFirstInvocation(invocations);
171
+ const workflowRunIds = invocations.map(
172
+ (invocation) => invocation.workflowContext.workflowRunId
173
+ );
198
174
  if (result.isOk()) {
199
- return { workflowRunId: finalWorkflowRunId };
175
+ return isBatchInput ? workflowRunIds.map((id) => ({ workflowRunId: id })) : { workflowRunId: workflowRunIds[0] };
200
176
  } else {
201
177
  throw result.error;
202
178
  }
package/nextjs.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
2
- import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.mjs';
3
- import { s as serveManyBase } from './serve-many-DLguU9iR.mjs';
2
+ import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-C1WIgVLA.mjs';
3
+ import { s as serveManyBase } from './serve-many-BF71QZHQ.mjs';
4
4
  import '@upstash/qstash';
5
5
  import 'zod';
6
6
  import 'ai';
package/nextjs.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
2
- import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.js';
3
- import { s as serveManyBase } from './serve-many-BdMq5rFX.js';
2
+ import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-C1WIgVLA.js';
3
+ import { s as serveManyBase } from './serve-many-BMlN2PAB.js';
4
4
  import '@upstash/qstash';
5
5
  import 'zod';
6
6
  import 'ai';