@upstash/workflow 0.2.10-unicode-rc → 0.2.10
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/astro.d.mts +2 -2
- package/astro.d.ts +2 -2
- package/astro.js +63 -142
- package/astro.mjs +1 -1
- package/{chunk-N2WV5VCD.mjs → chunk-GFNR743S.mjs} +63 -142
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +63 -142
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +63 -142
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +63 -142
- package/h3.mjs +1 -1
- package/hono.d.mts +3 -3
- package/hono.d.ts +3 -3
- package/hono.js +63 -142
- package/hono.mjs +1 -1
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +63 -142
- package/index.mjs +1 -1
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +63 -142
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/{serve-many-wMUWrSIP.d.mts → serve-many-BVDpPsF-.d.mts} +1 -1
- package/{serve-many-jCRazho9.d.ts → serve-many-e4zufyXN.d.ts} +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +63 -142
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +63 -142
- package/svelte.mjs +1 -1
- package/{types-Dg_9L83G.d.ts → types-CYhDXnf8.d.mts} +5 -13
- package/{types-Dg_9L83G.d.mts → types-CYhDXnf8.d.ts} +5 -13
package/index.js
CHANGED
|
@@ -163,21 +163,22 @@ function getWorkflowRunId(id) {
|
|
|
163
163
|
return `wfr_${id ?? nanoid()}`;
|
|
164
164
|
}
|
|
165
165
|
function decodeBase64(base64) {
|
|
166
|
-
const binString = atob(base64);
|
|
167
166
|
try {
|
|
167
|
+
const binString = atob(base64);
|
|
168
168
|
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
169
169
|
return new TextDecoder().decode(intArray);
|
|
170
170
|
} catch (error) {
|
|
171
171
|
console.warn(
|
|
172
172
|
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
173
173
|
);
|
|
174
|
-
return
|
|
174
|
+
return atob(base64);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
// src/context/steps.ts
|
|
179
|
-
var BaseLazyStep = class
|
|
179
|
+
var BaseLazyStep = class {
|
|
180
180
|
stepName;
|
|
181
|
+
// will be set in the subclasses
|
|
181
182
|
constructor(stepName) {
|
|
182
183
|
if (!stepName) {
|
|
183
184
|
throw new WorkflowError(
|
|
@@ -186,58 +187,10 @@ var BaseLazyStep = class _BaseLazyStep {
|
|
|
186
187
|
}
|
|
187
188
|
this.stepName = stepName;
|
|
188
189
|
}
|
|
189
|
-
/**
|
|
190
|
-
* parse the out field of a step result.
|
|
191
|
-
*
|
|
192
|
-
* will be called when returning the steps to the context from auto executor
|
|
193
|
-
*
|
|
194
|
-
* @param out field of the step
|
|
195
|
-
* @returns parsed out field
|
|
196
|
-
*/
|
|
197
|
-
parseOut(out) {
|
|
198
|
-
if (out === void 0) {
|
|
199
|
-
if (this.allowUndefinedOut) {
|
|
200
|
-
return void 0;
|
|
201
|
-
} else {
|
|
202
|
-
throw new WorkflowError(
|
|
203
|
-
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (typeof out === "object") {
|
|
208
|
-
if (this.stepType !== "Wait") {
|
|
209
|
-
console.warn(
|
|
210
|
-
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
211
|
-
);
|
|
212
|
-
return out;
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
...out,
|
|
216
|
-
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
if (typeof out !== "string") {
|
|
220
|
-
throw new WorkflowError(
|
|
221
|
-
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
return this.safeParseOut(out);
|
|
225
|
-
}
|
|
226
|
-
safeParseOut(out) {
|
|
227
|
-
return _BaseLazyStep.tryParsing(out);
|
|
228
|
-
}
|
|
229
|
-
static tryParsing(stepOut) {
|
|
230
|
-
try {
|
|
231
|
-
return JSON.parse(stepOut);
|
|
232
|
-
} catch {
|
|
233
|
-
return stepOut;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
190
|
};
|
|
237
191
|
var LazyFunctionStep = class extends BaseLazyStep {
|
|
238
192
|
stepFunction;
|
|
239
193
|
stepType = "Run";
|
|
240
|
-
allowUndefinedOut = true;
|
|
241
194
|
constructor(stepName, stepFunction) {
|
|
242
195
|
super(stepName);
|
|
243
196
|
this.stepFunction = stepFunction;
|
|
@@ -268,7 +221,6 @@ var LazyFunctionStep = class extends BaseLazyStep {
|
|
|
268
221
|
var LazySleepStep = class extends BaseLazyStep {
|
|
269
222
|
sleep;
|
|
270
223
|
stepType = "SleepFor";
|
|
271
|
-
allowUndefinedOut = true;
|
|
272
224
|
constructor(stepName, sleep) {
|
|
273
225
|
super(stepName);
|
|
274
226
|
this.sleep = sleep;
|
|
@@ -296,7 +248,6 @@ var LazySleepStep = class extends BaseLazyStep {
|
|
|
296
248
|
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
297
249
|
sleepUntil;
|
|
298
250
|
stepType = "SleepUntil";
|
|
299
|
-
allowUndefinedOut = true;
|
|
300
251
|
constructor(stepName, sleepUntil) {
|
|
301
252
|
super(stepName);
|
|
302
253
|
this.sleepUntil = sleepUntil;
|
|
@@ -320,11 +271,8 @@ var LazySleepUntilStep = class extends BaseLazyStep {
|
|
|
320
271
|
concurrent
|
|
321
272
|
});
|
|
322
273
|
}
|
|
323
|
-
safeParseOut() {
|
|
324
|
-
return void 0;
|
|
325
|
-
}
|
|
326
274
|
};
|
|
327
|
-
var LazyCallStep = class
|
|
275
|
+
var LazyCallStep = class extends BaseLazyStep {
|
|
328
276
|
url;
|
|
329
277
|
method;
|
|
330
278
|
body;
|
|
@@ -333,7 +281,6 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
333
281
|
timeout;
|
|
334
282
|
flowControl;
|
|
335
283
|
stepType = "Call";
|
|
336
|
-
allowUndefinedOut = false;
|
|
337
284
|
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
338
285
|
super(stepName);
|
|
339
286
|
this.url = url;
|
|
@@ -365,53 +312,11 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
365
312
|
callHeaders: this.headers
|
|
366
313
|
});
|
|
367
314
|
}
|
|
368
|
-
safeParseOut(out) {
|
|
369
|
-
const { header, status, body } = JSON.parse(out);
|
|
370
|
-
const responseHeaders = new Headers(header);
|
|
371
|
-
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
372
|
-
const bytes = new Uint8Array(out.length);
|
|
373
|
-
for (let i = 0; i < out.length; i++) {
|
|
374
|
-
bytes[i] = out.charCodeAt(i);
|
|
375
|
-
}
|
|
376
|
-
const processedResult = new TextDecoder().decode(bytes);
|
|
377
|
-
const newBody = JSON.parse(processedResult).body;
|
|
378
|
-
return {
|
|
379
|
-
status,
|
|
380
|
-
header,
|
|
381
|
-
body: BaseLazyStep.tryParsing(newBody)
|
|
382
|
-
};
|
|
383
|
-
} else {
|
|
384
|
-
return { header, status, body };
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
388
|
-
"application/json",
|
|
389
|
-
"application/xml",
|
|
390
|
-
"application/javascript",
|
|
391
|
-
"application/x-www-form-urlencoded",
|
|
392
|
-
"application/xhtml+xml",
|
|
393
|
-
"application/ld+json",
|
|
394
|
-
"application/rss+xml",
|
|
395
|
-
"application/atom+xml"
|
|
396
|
-
]);
|
|
397
|
-
static isText = (contentTypeHeader) => {
|
|
398
|
-
if (!contentTypeHeader) {
|
|
399
|
-
return false;
|
|
400
|
-
}
|
|
401
|
-
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
402
|
-
return true;
|
|
403
|
-
}
|
|
404
|
-
if (contentTypeHeader.startsWith("text/")) {
|
|
405
|
-
return true;
|
|
406
|
-
}
|
|
407
|
-
return false;
|
|
408
|
-
};
|
|
409
315
|
};
|
|
410
316
|
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
411
317
|
eventId;
|
|
412
318
|
timeout;
|
|
413
319
|
stepType = "Wait";
|
|
414
|
-
allowUndefinedOut = false;
|
|
415
320
|
constructor(stepName, eventId, timeout) {
|
|
416
321
|
super(stepName);
|
|
417
322
|
this.eventId = eventId;
|
|
@@ -438,13 +343,6 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
438
343
|
concurrent
|
|
439
344
|
});
|
|
440
345
|
}
|
|
441
|
-
safeParseOut(out) {
|
|
442
|
-
const result = JSON.parse(out);
|
|
443
|
-
return {
|
|
444
|
-
...result,
|
|
445
|
-
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
346
|
};
|
|
449
347
|
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
450
348
|
stepType = "Notify";
|
|
@@ -458,18 +356,10 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
458
356
|
};
|
|
459
357
|
});
|
|
460
358
|
}
|
|
461
|
-
safeParseOut(out) {
|
|
462
|
-
const result = JSON.parse(out);
|
|
463
|
-
return {
|
|
464
|
-
...result,
|
|
465
|
-
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
359
|
};
|
|
469
360
|
var LazyInvokeStep = class extends BaseLazyStep {
|
|
470
361
|
stepType = "Invoke";
|
|
471
362
|
params;
|
|
472
|
-
allowUndefinedOut = false;
|
|
473
363
|
constructor(stepName, {
|
|
474
364
|
workflow,
|
|
475
365
|
body,
|
|
@@ -509,13 +399,6 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
509
399
|
concurrent
|
|
510
400
|
});
|
|
511
401
|
}
|
|
512
|
-
safeParseOut(out) {
|
|
513
|
-
const result = JSON.parse(out);
|
|
514
|
-
return {
|
|
515
|
-
...result,
|
|
516
|
-
body: BaseLazyStep.tryParsing(result.body)
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
402
|
};
|
|
520
403
|
|
|
521
404
|
// node_modules/neverthrow/dist/index.es.js
|
|
@@ -1437,7 +1320,7 @@ var invokeWorkflow = async ({
|
|
|
1437
1320
|
headers: Object.fromEntries(
|
|
1438
1321
|
Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
|
|
1439
1322
|
),
|
|
1440
|
-
workflowRunId,
|
|
1323
|
+
workflowRunId: context.workflowRunId,
|
|
1441
1324
|
workflowUrl: context.url,
|
|
1442
1325
|
step: invokeStep
|
|
1443
1326
|
};
|
|
@@ -1551,7 +1434,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1551
1434
|
step,
|
|
1552
1435
|
stepCount: this.stepCount
|
|
1553
1436
|
});
|
|
1554
|
-
return
|
|
1437
|
+
return step.out;
|
|
1555
1438
|
}
|
|
1556
1439
|
const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
|
|
1557
1440
|
await this.debug?.log("INFO", "RUN_SINGLE", {
|
|
@@ -1626,9 +1509,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1626
1509
|
case "last": {
|
|
1627
1510
|
const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
|
|
1628
1511
|
validateParallelSteps(parallelSteps, parallelResultSteps);
|
|
1629
|
-
return parallelResultSteps.map(
|
|
1630
|
-
(step, index) => parallelSteps[index].parseOut(step.out)
|
|
1631
|
-
);
|
|
1512
|
+
return parallelResultSteps.map((step) => step.out);
|
|
1632
1513
|
}
|
|
1633
1514
|
}
|
|
1634
1515
|
const fillValue = void 0;
|
|
@@ -2500,7 +2381,7 @@ var WorkflowContext = class {
|
|
|
2500
2381
|
*/
|
|
2501
2382
|
async run(stepName, stepFunction) {
|
|
2502
2383
|
const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
|
|
2503
|
-
return
|
|
2384
|
+
return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2504
2385
|
}
|
|
2505
2386
|
/**
|
|
2506
2387
|
* Stops the execution for the duration provided.
|
|
@@ -2571,27 +2452,43 @@ var WorkflowContext = class {
|
|
|
2571
2452
|
* }
|
|
2572
2453
|
*/
|
|
2573
2454
|
async call(stepName, settings) {
|
|
2574
|
-
const {
|
|
2575
|
-
|
|
2576
|
-
method = "GET",
|
|
2577
|
-
body: requestBody,
|
|
2578
|
-
headers = {},
|
|
2579
|
-
retries = 0,
|
|
2580
|
-
timeout,
|
|
2581
|
-
flowControl
|
|
2582
|
-
} = settings;
|
|
2583
|
-
return await this.addStep(
|
|
2455
|
+
const { url, method = "GET", body, headers = {}, retries = 0, timeout, flowControl } = settings;
|
|
2456
|
+
const result = await this.addStep(
|
|
2584
2457
|
new LazyCallStep(
|
|
2585
2458
|
stepName,
|
|
2586
2459
|
url,
|
|
2587
2460
|
method,
|
|
2588
|
-
|
|
2461
|
+
body,
|
|
2589
2462
|
headers,
|
|
2590
2463
|
retries,
|
|
2591
2464
|
timeout,
|
|
2592
2465
|
flowControl
|
|
2593
2466
|
)
|
|
2594
2467
|
);
|
|
2468
|
+
if (typeof result === "string") {
|
|
2469
|
+
try {
|
|
2470
|
+
const body2 = JSON.parse(result);
|
|
2471
|
+
return {
|
|
2472
|
+
status: 200,
|
|
2473
|
+
header: {},
|
|
2474
|
+
body: body2
|
|
2475
|
+
};
|
|
2476
|
+
} catch {
|
|
2477
|
+
return {
|
|
2478
|
+
status: 200,
|
|
2479
|
+
header: {},
|
|
2480
|
+
body: result
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
try {
|
|
2485
|
+
return {
|
|
2486
|
+
...result,
|
|
2487
|
+
body: JSON.parse(result.body)
|
|
2488
|
+
};
|
|
2489
|
+
} catch {
|
|
2490
|
+
return result;
|
|
2491
|
+
}
|
|
2595
2492
|
}
|
|
2596
2493
|
/**
|
|
2597
2494
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -2630,7 +2527,15 @@ var WorkflowContext = class {
|
|
|
2630
2527
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
2631
2528
|
const { timeout = "7d" } = options;
|
|
2632
2529
|
const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
|
|
2633
|
-
|
|
2530
|
+
const result = await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
|
|
2531
|
+
try {
|
|
2532
|
+
return {
|
|
2533
|
+
...result,
|
|
2534
|
+
eventData: JSON.parse(result.eventData)
|
|
2535
|
+
};
|
|
2536
|
+
} catch {
|
|
2537
|
+
return result;
|
|
2538
|
+
}
|
|
2634
2539
|
}
|
|
2635
2540
|
/**
|
|
2636
2541
|
* Notify workflow runs waiting for an event
|
|
@@ -2654,12 +2559,24 @@ var WorkflowContext = class {
|
|
|
2654
2559
|
* @returns notify response which has event id, event data and list of waiters which were notified
|
|
2655
2560
|
*/
|
|
2656
2561
|
async notify(stepName, eventId, eventData) {
|
|
2657
|
-
|
|
2562
|
+
const result = await this.addStep(
|
|
2658
2563
|
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
2659
2564
|
);
|
|
2565
|
+
try {
|
|
2566
|
+
return {
|
|
2567
|
+
...result,
|
|
2568
|
+
eventData: JSON.parse(result.eventData)
|
|
2569
|
+
};
|
|
2570
|
+
} catch {
|
|
2571
|
+
return result;
|
|
2572
|
+
}
|
|
2660
2573
|
}
|
|
2661
2574
|
async invoke(stepName, settings) {
|
|
2662
|
-
|
|
2575
|
+
const result = await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
2576
|
+
return {
|
|
2577
|
+
...result,
|
|
2578
|
+
body: result.body ? JSON.parse(result.body) : void 0
|
|
2579
|
+
};
|
|
2663
2580
|
}
|
|
2664
2581
|
/**
|
|
2665
2582
|
* Cancel the current workflow run
|
|
@@ -2818,6 +2735,10 @@ var processRawSteps = (rawSteps) => {
|
|
|
2818
2735
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
2819
2736
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
2820
2737
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
2738
|
+
try {
|
|
2739
|
+
step.out = JSON.parse(step.out);
|
|
2740
|
+
} catch {
|
|
2741
|
+
}
|
|
2821
2742
|
if (step.waitEventId) {
|
|
2822
2743
|
const newOut = {
|
|
2823
2744
|
eventData: step.out ? decodeBase64(step.out) : void 0,
|
package/index.mjs
CHANGED
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-
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-CYhDXnf8.mjs';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-BVDpPsF-.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-
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-CYhDXnf8.js';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-e4zufyXN.js';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|