@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
|
@@ -114,15 +114,15 @@ function getWorkflowRunId(id) {
|
|
|
114
114
|
return `wfr_${id ?? nanoid()}`;
|
|
115
115
|
}
|
|
116
116
|
function decodeBase64(base64) {
|
|
117
|
-
const binString = atob(base64);
|
|
118
117
|
try {
|
|
118
|
+
const binString = atob(base64);
|
|
119
119
|
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
120
120
|
return new TextDecoder().decode(intArray);
|
|
121
121
|
} catch (error) {
|
|
122
122
|
console.warn(
|
|
123
123
|
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
124
124
|
);
|
|
125
|
-
return
|
|
125
|
+
return atob(base64);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -1153,7 +1153,7 @@ var invokeWorkflow = async ({
|
|
|
1153
1153
|
headers: Object.fromEntries(
|
|
1154
1154
|
Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
|
|
1155
1155
|
),
|
|
1156
|
-
workflowRunId,
|
|
1156
|
+
workflowRunId: context.workflowRunId,
|
|
1157
1157
|
workflowUrl: context.url,
|
|
1158
1158
|
step: invokeStep
|
|
1159
1159
|
};
|
|
@@ -1290,8 +1290,9 @@ var WorkflowTool = class {
|
|
|
1290
1290
|
};
|
|
1291
1291
|
|
|
1292
1292
|
// src/context/steps.ts
|
|
1293
|
-
var BaseLazyStep = class
|
|
1293
|
+
var BaseLazyStep = class {
|
|
1294
1294
|
stepName;
|
|
1295
|
+
// will be set in the subclasses
|
|
1295
1296
|
constructor(stepName) {
|
|
1296
1297
|
if (!stepName) {
|
|
1297
1298
|
throw new WorkflowError(
|
|
@@ -1300,58 +1301,10 @@ var BaseLazyStep = class _BaseLazyStep {
|
|
|
1300
1301
|
}
|
|
1301
1302
|
this.stepName = stepName;
|
|
1302
1303
|
}
|
|
1303
|
-
/**
|
|
1304
|
-
* parse the out field of a step result.
|
|
1305
|
-
*
|
|
1306
|
-
* will be called when returning the steps to the context from auto executor
|
|
1307
|
-
*
|
|
1308
|
-
* @param out field of the step
|
|
1309
|
-
* @returns parsed out field
|
|
1310
|
-
*/
|
|
1311
|
-
parseOut(out) {
|
|
1312
|
-
if (out === void 0) {
|
|
1313
|
-
if (this.allowUndefinedOut) {
|
|
1314
|
-
return void 0;
|
|
1315
|
-
} else {
|
|
1316
|
-
throw new WorkflowError(
|
|
1317
|
-
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
1318
|
-
);
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
if (typeof out === "object") {
|
|
1322
|
-
if (this.stepType !== "Wait") {
|
|
1323
|
-
console.warn(
|
|
1324
|
-
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
1325
|
-
);
|
|
1326
|
-
return out;
|
|
1327
|
-
}
|
|
1328
|
-
return {
|
|
1329
|
-
...out,
|
|
1330
|
-
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
if (typeof out !== "string") {
|
|
1334
|
-
throw new WorkflowError(
|
|
1335
|
-
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
1336
|
-
);
|
|
1337
|
-
}
|
|
1338
|
-
return this.safeParseOut(out);
|
|
1339
|
-
}
|
|
1340
|
-
safeParseOut(out) {
|
|
1341
|
-
return _BaseLazyStep.tryParsing(out);
|
|
1342
|
-
}
|
|
1343
|
-
static tryParsing(stepOut) {
|
|
1344
|
-
try {
|
|
1345
|
-
return JSON.parse(stepOut);
|
|
1346
|
-
} catch {
|
|
1347
|
-
return stepOut;
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
1304
|
};
|
|
1351
1305
|
var LazyFunctionStep = class extends BaseLazyStep {
|
|
1352
1306
|
stepFunction;
|
|
1353
1307
|
stepType = "Run";
|
|
1354
|
-
allowUndefinedOut = true;
|
|
1355
1308
|
constructor(stepName, stepFunction) {
|
|
1356
1309
|
super(stepName);
|
|
1357
1310
|
this.stepFunction = stepFunction;
|
|
@@ -1382,7 +1335,6 @@ var LazyFunctionStep = class extends BaseLazyStep {
|
|
|
1382
1335
|
var LazySleepStep = class extends BaseLazyStep {
|
|
1383
1336
|
sleep;
|
|
1384
1337
|
stepType = "SleepFor";
|
|
1385
|
-
allowUndefinedOut = true;
|
|
1386
1338
|
constructor(stepName, sleep) {
|
|
1387
1339
|
super(stepName);
|
|
1388
1340
|
this.sleep = sleep;
|
|
@@ -1410,7 +1362,6 @@ var LazySleepStep = class extends BaseLazyStep {
|
|
|
1410
1362
|
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1411
1363
|
sleepUntil;
|
|
1412
1364
|
stepType = "SleepUntil";
|
|
1413
|
-
allowUndefinedOut = true;
|
|
1414
1365
|
constructor(stepName, sleepUntil) {
|
|
1415
1366
|
super(stepName);
|
|
1416
1367
|
this.sleepUntil = sleepUntil;
|
|
@@ -1434,11 +1385,8 @@ var LazySleepUntilStep = class extends BaseLazyStep {
|
|
|
1434
1385
|
concurrent
|
|
1435
1386
|
});
|
|
1436
1387
|
}
|
|
1437
|
-
safeParseOut() {
|
|
1438
|
-
return void 0;
|
|
1439
|
-
}
|
|
1440
1388
|
};
|
|
1441
|
-
var LazyCallStep = class
|
|
1389
|
+
var LazyCallStep = class extends BaseLazyStep {
|
|
1442
1390
|
url;
|
|
1443
1391
|
method;
|
|
1444
1392
|
body;
|
|
@@ -1447,7 +1395,6 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1447
1395
|
timeout;
|
|
1448
1396
|
flowControl;
|
|
1449
1397
|
stepType = "Call";
|
|
1450
|
-
allowUndefinedOut = false;
|
|
1451
1398
|
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
1452
1399
|
super(stepName);
|
|
1453
1400
|
this.url = url;
|
|
@@ -1479,53 +1426,11 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1479
1426
|
callHeaders: this.headers
|
|
1480
1427
|
});
|
|
1481
1428
|
}
|
|
1482
|
-
safeParseOut(out) {
|
|
1483
|
-
const { header, status, body } = JSON.parse(out);
|
|
1484
|
-
const responseHeaders = new Headers(header);
|
|
1485
|
-
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
1486
|
-
const bytes = new Uint8Array(out.length);
|
|
1487
|
-
for (let i = 0; i < out.length; i++) {
|
|
1488
|
-
bytes[i] = out.charCodeAt(i);
|
|
1489
|
-
}
|
|
1490
|
-
const processedResult = new TextDecoder().decode(bytes);
|
|
1491
|
-
const newBody = JSON.parse(processedResult).body;
|
|
1492
|
-
return {
|
|
1493
|
-
status,
|
|
1494
|
-
header,
|
|
1495
|
-
body: BaseLazyStep.tryParsing(newBody)
|
|
1496
|
-
};
|
|
1497
|
-
} else {
|
|
1498
|
-
return { header, status, body };
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
1502
|
-
"application/json",
|
|
1503
|
-
"application/xml",
|
|
1504
|
-
"application/javascript",
|
|
1505
|
-
"application/x-www-form-urlencoded",
|
|
1506
|
-
"application/xhtml+xml",
|
|
1507
|
-
"application/ld+json",
|
|
1508
|
-
"application/rss+xml",
|
|
1509
|
-
"application/atom+xml"
|
|
1510
|
-
]);
|
|
1511
|
-
static isText = (contentTypeHeader) => {
|
|
1512
|
-
if (!contentTypeHeader) {
|
|
1513
|
-
return false;
|
|
1514
|
-
}
|
|
1515
|
-
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
1516
|
-
return true;
|
|
1517
|
-
}
|
|
1518
|
-
if (contentTypeHeader.startsWith("text/")) {
|
|
1519
|
-
return true;
|
|
1520
|
-
}
|
|
1521
|
-
return false;
|
|
1522
|
-
};
|
|
1523
1429
|
};
|
|
1524
1430
|
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1525
1431
|
eventId;
|
|
1526
1432
|
timeout;
|
|
1527
1433
|
stepType = "Wait";
|
|
1528
|
-
allowUndefinedOut = false;
|
|
1529
1434
|
constructor(stepName, eventId, timeout) {
|
|
1530
1435
|
super(stepName);
|
|
1531
1436
|
this.eventId = eventId;
|
|
@@ -1552,13 +1457,6 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1552
1457
|
concurrent
|
|
1553
1458
|
});
|
|
1554
1459
|
}
|
|
1555
|
-
safeParseOut(out) {
|
|
1556
|
-
const result = JSON.parse(out);
|
|
1557
|
-
return {
|
|
1558
|
-
...result,
|
|
1559
|
-
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1560
|
-
};
|
|
1561
|
-
}
|
|
1562
1460
|
};
|
|
1563
1461
|
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1564
1462
|
stepType = "Notify";
|
|
@@ -1572,18 +1470,10 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
1572
1470
|
};
|
|
1573
1471
|
});
|
|
1574
1472
|
}
|
|
1575
|
-
safeParseOut(out) {
|
|
1576
|
-
const result = JSON.parse(out);
|
|
1577
|
-
return {
|
|
1578
|
-
...result,
|
|
1579
|
-
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1580
|
-
};
|
|
1581
|
-
}
|
|
1582
1473
|
};
|
|
1583
1474
|
var LazyInvokeStep = class extends BaseLazyStep {
|
|
1584
1475
|
stepType = "Invoke";
|
|
1585
1476
|
params;
|
|
1586
|
-
allowUndefinedOut = false;
|
|
1587
1477
|
constructor(stepName, {
|
|
1588
1478
|
workflow,
|
|
1589
1479
|
body,
|
|
@@ -1623,13 +1513,6 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1623
1513
|
concurrent
|
|
1624
1514
|
});
|
|
1625
1515
|
}
|
|
1626
|
-
safeParseOut(out) {
|
|
1627
|
-
const result = JSON.parse(out);
|
|
1628
|
-
return {
|
|
1629
|
-
...result,
|
|
1630
|
-
body: BaseLazyStep.tryParsing(result.body)
|
|
1631
|
-
};
|
|
1632
|
-
}
|
|
1633
1516
|
};
|
|
1634
1517
|
|
|
1635
1518
|
// src/context/auto-executor.ts
|
|
@@ -1735,7 +1618,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1735
1618
|
step,
|
|
1736
1619
|
stepCount: this.stepCount
|
|
1737
1620
|
});
|
|
1738
|
-
return
|
|
1621
|
+
return step.out;
|
|
1739
1622
|
}
|
|
1740
1623
|
const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
|
|
1741
1624
|
await this.debug?.log("INFO", "RUN_SINGLE", {
|
|
@@ -1810,9 +1693,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1810
1693
|
case "last": {
|
|
1811
1694
|
const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
|
|
1812
1695
|
validateParallelSteps(parallelSteps, parallelResultSteps);
|
|
1813
|
-
return parallelResultSteps.map(
|
|
1814
|
-
(step, index) => parallelSteps[index].parseOut(step.out)
|
|
1815
|
-
);
|
|
1696
|
+
return parallelResultSteps.map((step) => step.out);
|
|
1816
1697
|
}
|
|
1817
1698
|
}
|
|
1818
1699
|
const fillValue = void 0;
|
|
@@ -2560,7 +2441,7 @@ var WorkflowContext = class {
|
|
|
2560
2441
|
*/
|
|
2561
2442
|
async run(stepName, stepFunction) {
|
|
2562
2443
|
const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
|
|
2563
|
-
return
|
|
2444
|
+
return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2564
2445
|
}
|
|
2565
2446
|
/**
|
|
2566
2447
|
* Stops the execution for the duration provided.
|
|
@@ -2631,27 +2512,43 @@ var WorkflowContext = class {
|
|
|
2631
2512
|
* }
|
|
2632
2513
|
*/
|
|
2633
2514
|
async call(stepName, settings) {
|
|
2634
|
-
const {
|
|
2635
|
-
|
|
2636
|
-
method = "GET",
|
|
2637
|
-
body: requestBody,
|
|
2638
|
-
headers = {},
|
|
2639
|
-
retries = 0,
|
|
2640
|
-
timeout,
|
|
2641
|
-
flowControl
|
|
2642
|
-
} = settings;
|
|
2643
|
-
return await this.addStep(
|
|
2515
|
+
const { url, method = "GET", body, headers = {}, retries = 0, timeout, flowControl } = settings;
|
|
2516
|
+
const result = await this.addStep(
|
|
2644
2517
|
new LazyCallStep(
|
|
2645
2518
|
stepName,
|
|
2646
2519
|
url,
|
|
2647
2520
|
method,
|
|
2648
|
-
|
|
2521
|
+
body,
|
|
2649
2522
|
headers,
|
|
2650
2523
|
retries,
|
|
2651
2524
|
timeout,
|
|
2652
2525
|
flowControl
|
|
2653
2526
|
)
|
|
2654
2527
|
);
|
|
2528
|
+
if (typeof result === "string") {
|
|
2529
|
+
try {
|
|
2530
|
+
const body2 = JSON.parse(result);
|
|
2531
|
+
return {
|
|
2532
|
+
status: 200,
|
|
2533
|
+
header: {},
|
|
2534
|
+
body: body2
|
|
2535
|
+
};
|
|
2536
|
+
} catch {
|
|
2537
|
+
return {
|
|
2538
|
+
status: 200,
|
|
2539
|
+
header: {},
|
|
2540
|
+
body: result
|
|
2541
|
+
};
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
try {
|
|
2545
|
+
return {
|
|
2546
|
+
...result,
|
|
2547
|
+
body: JSON.parse(result.body)
|
|
2548
|
+
};
|
|
2549
|
+
} catch {
|
|
2550
|
+
return result;
|
|
2551
|
+
}
|
|
2655
2552
|
}
|
|
2656
2553
|
/**
|
|
2657
2554
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -2690,7 +2587,15 @@ var WorkflowContext = class {
|
|
|
2690
2587
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
2691
2588
|
const { timeout = "7d" } = options;
|
|
2692
2589
|
const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
|
|
2693
|
-
|
|
2590
|
+
const result = await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
|
|
2591
|
+
try {
|
|
2592
|
+
return {
|
|
2593
|
+
...result,
|
|
2594
|
+
eventData: JSON.parse(result.eventData)
|
|
2595
|
+
};
|
|
2596
|
+
} catch {
|
|
2597
|
+
return result;
|
|
2598
|
+
}
|
|
2694
2599
|
}
|
|
2695
2600
|
/**
|
|
2696
2601
|
* Notify workflow runs waiting for an event
|
|
@@ -2714,12 +2619,24 @@ var WorkflowContext = class {
|
|
|
2714
2619
|
* @returns notify response which has event id, event data and list of waiters which were notified
|
|
2715
2620
|
*/
|
|
2716
2621
|
async notify(stepName, eventId, eventData) {
|
|
2717
|
-
|
|
2622
|
+
const result = await this.addStep(
|
|
2718
2623
|
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
2719
2624
|
);
|
|
2625
|
+
try {
|
|
2626
|
+
return {
|
|
2627
|
+
...result,
|
|
2628
|
+
eventData: JSON.parse(result.eventData)
|
|
2629
|
+
};
|
|
2630
|
+
} catch {
|
|
2631
|
+
return result;
|
|
2632
|
+
}
|
|
2720
2633
|
}
|
|
2721
2634
|
async invoke(stepName, settings) {
|
|
2722
|
-
|
|
2635
|
+
const result = await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
2636
|
+
return {
|
|
2637
|
+
...result,
|
|
2638
|
+
body: result.body ? JSON.parse(result.body) : void 0
|
|
2639
|
+
};
|
|
2723
2640
|
}
|
|
2724
2641
|
/**
|
|
2725
2642
|
* Cancel the current workflow run
|
|
@@ -2878,6 +2795,10 @@ var processRawSteps = (rawSteps) => {
|
|
|
2878
2795
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
2879
2796
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
2880
2797
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
2798
|
+
try {
|
|
2799
|
+
step.out = JSON.parse(step.out);
|
|
2800
|
+
} catch {
|
|
2801
|
+
}
|
|
2881
2802
|
if (step.waitEventId) {
|
|
2882
2803
|
const newOut = {
|
|
2883
2804
|
eventData: step.out ? decodeBase64(step.out) : void 0,
|
package/cloudflare.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
2
|
-
import { s as serveManyBase } from './serve-many-
|
|
1
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-CYhDXnf8.mjs';
|
|
2
|
+
import { s as serveManyBase } from './serve-many-BVDpPsF-.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|
package/cloudflare.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
2
|
-
import { s as serveManyBase } from './serve-many-
|
|
1
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-CYhDXnf8.js';
|
|
2
|
+
import { s as serveManyBase } from './serve-many-e4zufyXN.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|