@upstash/workflow 0.2.22 → 0.2.23-rc
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 +178 -59
- package/astro.mjs +1 -1
- package/{chunk-BON2RKOR.mjs → chunk-KAGTWBLF.mjs} +178 -59
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +178 -59
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +178 -59
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +178 -59
- package/h3.mjs +1 -1
- package/hono.d.mts +2 -2
- package/hono.d.ts +2 -2
- package/hono.js +178 -59
- package/hono.mjs +1 -1
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +178 -59
- package/index.mjs +1 -1
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +178 -59
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/{serve-many-CctdYIfB.d.mts → serve-many-B5Vbacm6.d.mts} +1 -1
- package/{serve-many-BXDr30rl.d.ts → serve-many-BCV7INWe.d.ts} +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +178 -59
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +178 -59
- package/svelte.mjs +1 -1
- package/tanstack.d.mts +2 -2
- package/tanstack.d.ts +2 -2
- package/tanstack.js +178 -59
- package/tanstack.mjs +1 -1
- package/{types-9nCq6bRP.d.ts → types-BD06btU6.d.mts} +20 -5
- package/{types-9nCq6bRP.d.mts → types-BD06btU6.d.ts} +20 -5
package/astro.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIContext, APIRoute } from 'astro';
|
|
2
|
-
import { h as WorkflowContext, o as PublicServeOptions, z as InvokableWorkflow } from './types-
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { h as WorkflowContext, o as PublicServeOptions, z as InvokableWorkflow } from './types-BD06btU6.mjs';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-B5Vbacm6.mjs';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|
package/astro.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIContext, APIRoute } from 'astro';
|
|
2
|
-
import { h as WorkflowContext, o as PublicServeOptions, z as InvokableWorkflow } from './types-
|
|
3
|
-
import { s as serveManyBase } from './serve-many-
|
|
2
|
+
import { h as WorkflowContext, o as PublicServeOptions, z as InvokableWorkflow } from './types-BD06btU6.js';
|
|
3
|
+
import { s as serveManyBase } from './serve-many-BCV7INWe.js';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'ai';
|
package/astro.js
CHANGED
|
@@ -199,8 +199,8 @@ var NANOID_LENGTH = 21;
|
|
|
199
199
|
function getRandomInt() {
|
|
200
200
|
return Math.floor(Math.random() * NANOID_CHARS.length);
|
|
201
201
|
}
|
|
202
|
-
function nanoid() {
|
|
203
|
-
return Array.from({ length
|
|
202
|
+
function nanoid(length = NANOID_LENGTH) {
|
|
203
|
+
return Array.from({ length }).map(() => NANOID_CHARS[getRandomInt()]).join("");
|
|
204
204
|
}
|
|
205
205
|
function getWorkflowRunId(id) {
|
|
206
206
|
return `wfr_${id ?? nanoid()}`;
|
|
@@ -217,6 +217,37 @@ function decodeBase64(base64) {
|
|
|
217
217
|
return binString;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
function getUserIdFromToken(qstashClient) {
|
|
221
|
+
try {
|
|
222
|
+
const token = qstashClient.token;
|
|
223
|
+
const decodedToken = decodeBase64(token);
|
|
224
|
+
const tokenPayload = JSON.parse(decodedToken);
|
|
225
|
+
const userId = tokenPayload.UserID;
|
|
226
|
+
if (!userId) {
|
|
227
|
+
throw new WorkflowError("QStash token payload does not contain userId");
|
|
228
|
+
}
|
|
229
|
+
return userId;
|
|
230
|
+
} catch (error) {
|
|
231
|
+
throw new WorkflowError(
|
|
232
|
+
`Failed to decode QStash token while running create webhook step: ${error.message}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function getQStashUrl(qstashClient) {
|
|
237
|
+
try {
|
|
238
|
+
const requester = qstashClient.http;
|
|
239
|
+
const baseUrl = requester.baseUrl;
|
|
240
|
+
if (!baseUrl) {
|
|
241
|
+
throw new WorkflowError("QStash client does not have a baseUrl");
|
|
242
|
+
}
|
|
243
|
+
return baseUrl;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
throw new WorkflowError(`Failed to get QStash URL from client: ${error.message}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function getEventId() {
|
|
249
|
+
return `evt_${nanoid(15)}`;
|
|
250
|
+
}
|
|
220
251
|
|
|
221
252
|
// node_modules/neverthrow/dist/index.es.js
|
|
222
253
|
var defaultErrorConfig = {
|
|
@@ -642,7 +673,9 @@ var StepTypes = [
|
|
|
642
673
|
"Call",
|
|
643
674
|
"Wait",
|
|
644
675
|
"Notify",
|
|
645
|
-
"Invoke"
|
|
676
|
+
"Invoke",
|
|
677
|
+
"CreateWebhook",
|
|
678
|
+
"WaitForWebhook"
|
|
646
679
|
];
|
|
647
680
|
|
|
648
681
|
// src/workflow-requests.ts
|
|
@@ -954,7 +987,9 @@ If you want to disable QStash Verification, you should clear env variables QSTAS
|
|
|
954
987
|
// src/context/steps.ts
|
|
955
988
|
var BaseLazyStep = class _BaseLazyStep {
|
|
956
989
|
stepName;
|
|
957
|
-
|
|
990
|
+
context;
|
|
991
|
+
constructor(context, stepName) {
|
|
992
|
+
this.context = context;
|
|
958
993
|
if (!stepName) {
|
|
959
994
|
throw new WorkflowError(
|
|
960
995
|
"A workflow step name cannot be undefined or an empty string. Please provide a name for your workflow step."
|
|
@@ -972,13 +1007,14 @@ var BaseLazyStep = class _BaseLazyStep {
|
|
|
972
1007
|
*
|
|
973
1008
|
* will be called when returning the steps to the context from auto executor
|
|
974
1009
|
*
|
|
975
|
-
* @param
|
|
1010
|
+
* @param step step
|
|
976
1011
|
* @returns parsed out field
|
|
977
1012
|
*/
|
|
978
|
-
parseOut(
|
|
1013
|
+
parseOut(step) {
|
|
1014
|
+
const out = step.out;
|
|
979
1015
|
if (out === void 0) {
|
|
980
1016
|
if (this.allowUndefinedOut) {
|
|
981
|
-
return
|
|
1017
|
+
return this.handleUndefinedOut(step);
|
|
982
1018
|
} else {
|
|
983
1019
|
throw new WorkflowError(
|
|
984
1020
|
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
@@ -986,27 +1022,26 @@ var BaseLazyStep = class _BaseLazyStep {
|
|
|
986
1022
|
}
|
|
987
1023
|
}
|
|
988
1024
|
if (typeof out === "object") {
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
return out;
|
|
994
|
-
}
|
|
995
|
-
return {
|
|
996
|
-
...out,
|
|
997
|
-
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
998
|
-
};
|
|
1025
|
+
console.warn(
|
|
1026
|
+
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
1027
|
+
);
|
|
1028
|
+
return out;
|
|
999
1029
|
}
|
|
1000
1030
|
if (typeof out !== "string") {
|
|
1001
1031
|
throw new WorkflowError(
|
|
1002
1032
|
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
1003
1033
|
);
|
|
1004
1034
|
}
|
|
1005
|
-
return this.safeParseOut(out);
|
|
1035
|
+
return this.safeParseOut(out, step);
|
|
1006
1036
|
}
|
|
1007
|
-
|
|
1037
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1038
|
+
safeParseOut(out, step) {
|
|
1008
1039
|
return _BaseLazyStep.tryParsing(out);
|
|
1009
1040
|
}
|
|
1041
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1042
|
+
handleUndefinedOut(step) {
|
|
1043
|
+
return void 0;
|
|
1044
|
+
}
|
|
1010
1045
|
static tryParsing(stepOut) {
|
|
1011
1046
|
try {
|
|
1012
1047
|
return JSON.parse(stepOut);
|
|
@@ -1057,8 +1092,8 @@ var LazyFunctionStep = class extends BaseLazyStep {
|
|
|
1057
1092
|
stepFunction;
|
|
1058
1093
|
stepType = "Run";
|
|
1059
1094
|
allowUndefinedOut = true;
|
|
1060
|
-
constructor(stepName, stepFunction) {
|
|
1061
|
-
super(stepName);
|
|
1095
|
+
constructor(context, stepName, stepFunction) {
|
|
1096
|
+
super(context, stepName);
|
|
1062
1097
|
this.stepFunction = stepFunction;
|
|
1063
1098
|
}
|
|
1064
1099
|
getPlanStep(concurrent, targetStep) {
|
|
@@ -1088,8 +1123,8 @@ var LazySleepStep = class extends BaseLazyStep {
|
|
|
1088
1123
|
sleep;
|
|
1089
1124
|
stepType = "SleepFor";
|
|
1090
1125
|
allowUndefinedOut = true;
|
|
1091
|
-
constructor(stepName, sleep) {
|
|
1092
|
-
super(stepName);
|
|
1126
|
+
constructor(context, stepName, sleep) {
|
|
1127
|
+
super(context, stepName);
|
|
1093
1128
|
this.sleep = sleep;
|
|
1094
1129
|
}
|
|
1095
1130
|
getPlanStep(concurrent, targetStep) {
|
|
@@ -1130,8 +1165,8 @@ var LazySleepUntilStep = class extends BaseLazyStep {
|
|
|
1130
1165
|
sleepUntil;
|
|
1131
1166
|
stepType = "SleepUntil";
|
|
1132
1167
|
allowUndefinedOut = true;
|
|
1133
|
-
constructor(stepName, sleepUntil) {
|
|
1134
|
-
super(stepName);
|
|
1168
|
+
constructor(context, stepName, sleepUntil) {
|
|
1169
|
+
super(context, stepName);
|
|
1135
1170
|
this.sleepUntil = sleepUntil;
|
|
1136
1171
|
}
|
|
1137
1172
|
getPlanStep(concurrent, targetStep) {
|
|
@@ -1183,8 +1218,8 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1183
1218
|
stringifyBody;
|
|
1184
1219
|
stepType = "Call";
|
|
1185
1220
|
allowUndefinedOut = false;
|
|
1186
|
-
constructor(stepName, url, method, body, headers, retries, retryDelay, timeout, flowControl, stringifyBody) {
|
|
1187
|
-
super(stepName);
|
|
1221
|
+
constructor(context, stepName, url, method, body, headers, retries, retryDelay, timeout, flowControl, stringifyBody) {
|
|
1222
|
+
super(context, stepName);
|
|
1188
1223
|
this.url = url;
|
|
1189
1224
|
this.method = method;
|
|
1190
1225
|
this.body = body;
|
|
@@ -1328,13 +1363,12 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
|
1328
1363
|
]);
|
|
1329
1364
|
}
|
|
1330
1365
|
};
|
|
1331
|
-
var
|
|
1366
|
+
var LazyWaitEventStep = class extends BaseLazyStep {
|
|
1332
1367
|
eventId;
|
|
1333
1368
|
timeout;
|
|
1334
|
-
stepType = "Wait";
|
|
1335
1369
|
allowUndefinedOut = false;
|
|
1336
|
-
constructor(stepName, eventId, timeout) {
|
|
1337
|
-
super(stepName);
|
|
1370
|
+
constructor(context, stepName, eventId, timeout) {
|
|
1371
|
+
super(context, stepName);
|
|
1338
1372
|
this.eventId = eventId;
|
|
1339
1373
|
this.timeout = timeout;
|
|
1340
1374
|
}
|
|
@@ -1359,13 +1393,6 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1359
1393
|
concurrent
|
|
1360
1394
|
});
|
|
1361
1395
|
}
|
|
1362
|
-
safeParseOut(out) {
|
|
1363
|
-
const result = JSON.parse(out);
|
|
1364
|
-
return {
|
|
1365
|
-
...result,
|
|
1366
|
-
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1367
|
-
};
|
|
1368
|
-
}
|
|
1369
1396
|
getHeaders({ context, telemetry: telemetry2, invokeCount, step }) {
|
|
1370
1397
|
const headers = super.getHeaders({ context, telemetry: telemetry2, invokeCount, step });
|
|
1371
1398
|
headers.headers["Upstash-Workflow-CallType"] = "step";
|
|
@@ -1399,7 +1426,7 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1399
1426
|
timeoutHeaders,
|
|
1400
1427
|
step: {
|
|
1401
1428
|
stepId: step.stepId,
|
|
1402
|
-
stepType:
|
|
1429
|
+
stepType: this.stepType,
|
|
1403
1430
|
stepName: step.stepName,
|
|
1404
1431
|
concurrent: step.concurrent,
|
|
1405
1432
|
targetStep: step.targetStep
|
|
@@ -1420,8 +1447,8 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1420
1447
|
};
|
|
1421
1448
|
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1422
1449
|
stepType = "Notify";
|
|
1423
|
-
constructor(stepName, eventId, eventData, requester) {
|
|
1424
|
-
super(stepName, async () => {
|
|
1450
|
+
constructor(context, stepName, eventId, eventData, requester) {
|
|
1451
|
+
super(context, stepName, async () => {
|
|
1425
1452
|
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1426
1453
|
return {
|
|
1427
1454
|
eventId,
|
|
@@ -1446,7 +1473,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1446
1473
|
* workflow id of the invoked workflow
|
|
1447
1474
|
*/
|
|
1448
1475
|
workflowId;
|
|
1449
|
-
constructor(stepName, {
|
|
1476
|
+
constructor(context, stepName, {
|
|
1450
1477
|
workflow,
|
|
1451
1478
|
body,
|
|
1452
1479
|
headers = {},
|
|
@@ -1456,7 +1483,7 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1456
1483
|
flowControl,
|
|
1457
1484
|
stringifyBody = true
|
|
1458
1485
|
}) {
|
|
1459
|
-
super(stepName);
|
|
1486
|
+
super(context, stepName);
|
|
1460
1487
|
this.params = {
|
|
1461
1488
|
workflow,
|
|
1462
1489
|
body,
|
|
@@ -1517,6 +1544,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1517
1544
|
userHeaders: context.headers,
|
|
1518
1545
|
invokeCount
|
|
1519
1546
|
});
|
|
1547
|
+
context.qstashClient.http.headers?.forEach((value, key) => {
|
|
1548
|
+
invokerHeaders[key] = value;
|
|
1549
|
+
});
|
|
1520
1550
|
invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
|
|
1521
1551
|
let invokeBody;
|
|
1522
1552
|
if (this.params.stringifyBody) {
|
|
@@ -1588,6 +1618,91 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1588
1618
|
return [result];
|
|
1589
1619
|
}
|
|
1590
1620
|
};
|
|
1621
|
+
var LazyCreateWebhookStep = class extends BaseLazyStep {
|
|
1622
|
+
stepType = "CreateWebhook";
|
|
1623
|
+
allowUndefinedOut = false;
|
|
1624
|
+
getPlanStep(concurrent, targetStep) {
|
|
1625
|
+
return {
|
|
1626
|
+
stepId: 0,
|
|
1627
|
+
stepName: this.stepName,
|
|
1628
|
+
stepType: this.stepType,
|
|
1629
|
+
concurrent,
|
|
1630
|
+
targetStep
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
async getResultStep(concurrent, stepId) {
|
|
1634
|
+
return {
|
|
1635
|
+
stepId,
|
|
1636
|
+
stepName: this.stepName,
|
|
1637
|
+
stepType: this.stepType,
|
|
1638
|
+
out: void 0,
|
|
1639
|
+
concurrent
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
getBody({ step, context }) {
|
|
1643
|
+
const userId = getUserIdFromToken(context.qstashClient);
|
|
1644
|
+
const out = [userId, context.workflowRunId, getEventId()].join("/");
|
|
1645
|
+
return JSON.stringify({
|
|
1646
|
+
...step,
|
|
1647
|
+
out
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
safeParseOut(out) {
|
|
1651
|
+
const [userId, workflowRunId, eventId] = out.split("/");
|
|
1652
|
+
const qstashUrl = getQStashUrl(this.context.qstashClient);
|
|
1653
|
+
return {
|
|
1654
|
+
webhookUrl: `${qstashUrl}/v2/workflows/hooks/${userId}/${workflowRunId}/${eventId}`,
|
|
1655
|
+
eventId
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
var LazyWaitForWebhookStep = class extends LazyWaitEventStep {
|
|
1660
|
+
stepType = "WaitForWebhook";
|
|
1661
|
+
allowUndefinedOut = true;
|
|
1662
|
+
constructor(context, stepName, webhook, timeout) {
|
|
1663
|
+
super(context, stepName, webhook.eventId, timeout);
|
|
1664
|
+
}
|
|
1665
|
+
safeParseOut(out) {
|
|
1666
|
+
const eventData = decodeBase64(out);
|
|
1667
|
+
const parsedEventData = BaseLazyStep.tryParsing(eventData);
|
|
1668
|
+
const body = parsedEventData.body;
|
|
1669
|
+
const parsedBody = typeof body === "string" ? decodeBase64(body) : void 0;
|
|
1670
|
+
const request = new Request(
|
|
1671
|
+
`${parsedEventData.proto}://${parsedEventData.host}${parsedEventData.url}`,
|
|
1672
|
+
{
|
|
1673
|
+
method: parsedEventData.method,
|
|
1674
|
+
headers: parsedEventData.header,
|
|
1675
|
+
body: parsedBody
|
|
1676
|
+
}
|
|
1677
|
+
);
|
|
1678
|
+
return {
|
|
1679
|
+
request,
|
|
1680
|
+
timeout: false
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
handleUndefinedOut() {
|
|
1684
|
+
return {
|
|
1685
|
+
timeout: true,
|
|
1686
|
+
request: void 0
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
var LazyWaitForEventStep = class extends LazyWaitEventStep {
|
|
1691
|
+
stepType = "Wait";
|
|
1692
|
+
allowUndefinedOut = true;
|
|
1693
|
+
parseWaitForEventOut(out, waitTimeout) {
|
|
1694
|
+
return {
|
|
1695
|
+
eventData: out ? BaseLazyStep.tryParsing(decodeBase64(out)) : void 0,
|
|
1696
|
+
timeout: waitTimeout ?? false
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
safeParseOut(out, step) {
|
|
1700
|
+
return this.parseWaitForEventOut(out, step.waitTimeout);
|
|
1701
|
+
}
|
|
1702
|
+
handleUndefinedOut(step) {
|
|
1703
|
+
return this.parseWaitForEventOut(void 0, step.waitTimeout);
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1591
1706
|
|
|
1592
1707
|
// src/agents/constants.ts
|
|
1593
1708
|
var AGENT_NAME_HEADER = "upstash-agent-name";
|
|
@@ -1992,7 +2107,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1992
2107
|
step,
|
|
1993
2108
|
stepCount: this.stepCount
|
|
1994
2109
|
});
|
|
1995
|
-
return lazyStep.parseOut(step
|
|
2110
|
+
return lazyStep.parseOut(step);
|
|
1996
2111
|
}
|
|
1997
2112
|
const resultStep = await submitSingleStep({
|
|
1998
2113
|
context: this.context,
|
|
@@ -2079,7 +2194,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
2079
2194
|
const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
|
|
2080
2195
|
validateParallelSteps(parallelSteps, parallelResultSteps);
|
|
2081
2196
|
return parallelResultSteps.map(
|
|
2082
|
-
(step, index) => parallelSteps[index].parseOut(step
|
|
2197
|
+
(step, index) => parallelSteps[index].parseOut(step)
|
|
2083
2198
|
);
|
|
2084
2199
|
}
|
|
2085
2200
|
}
|
|
@@ -2135,7 +2250,6 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
2135
2250
|
* @param index index of the current step
|
|
2136
2251
|
* @returns result[index] if lazyStepList > 1, otherwise result
|
|
2137
2252
|
*/
|
|
2138
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
2139
2253
|
static getResult(lazyStepList, result, index) {
|
|
2140
2254
|
if (lazyStepList.length === 1) {
|
|
2141
2255
|
return result;
|
|
@@ -2927,7 +3041,7 @@ var WorkflowContext = class {
|
|
|
2927
3041
|
*/
|
|
2928
3042
|
async run(stepName, stepFunction) {
|
|
2929
3043
|
const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
|
|
2930
|
-
return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
3044
|
+
return await this.addStep(new LazyFunctionStep(this, stepName, wrappedStepFunction));
|
|
2931
3045
|
}
|
|
2932
3046
|
/**
|
|
2933
3047
|
* Stops the execution for the duration provided.
|
|
@@ -2941,7 +3055,7 @@ var WorkflowContext = class {
|
|
|
2941
3055
|
* @returns undefined
|
|
2942
3056
|
*/
|
|
2943
3057
|
async sleep(stepName, duration) {
|
|
2944
|
-
await this.addStep(new LazySleepStep(stepName, duration));
|
|
3058
|
+
await this.addStep(new LazySleepStep(this, stepName, duration));
|
|
2945
3059
|
}
|
|
2946
3060
|
/**
|
|
2947
3061
|
* Stops the execution until the date time provided.
|
|
@@ -2963,13 +3077,14 @@ var WorkflowContext = class {
|
|
|
2963
3077
|
datetime = typeof datetime === "string" ? new Date(datetime) : datetime;
|
|
2964
3078
|
time = Math.round(datetime.getTime() / 1e3);
|
|
2965
3079
|
}
|
|
2966
|
-
await this.addStep(new LazySleepUntilStep(stepName, time));
|
|
3080
|
+
await this.addStep(new LazySleepUntilStep(this, stepName, time));
|
|
2967
3081
|
}
|
|
2968
3082
|
async call(stepName, settings) {
|
|
2969
3083
|
let callStep;
|
|
2970
3084
|
if ("workflow" in settings) {
|
|
2971
3085
|
const url = getNewUrlFromWorkflowId(this.url, settings.workflow.workflowId);
|
|
2972
3086
|
callStep = new LazyCallStep(
|
|
3087
|
+
this,
|
|
2973
3088
|
stepName,
|
|
2974
3089
|
url,
|
|
2975
3090
|
"POST",
|
|
@@ -2994,6 +3109,7 @@ var WorkflowContext = class {
|
|
|
2994
3109
|
stringifyBody = true
|
|
2995
3110
|
} = settings;
|
|
2996
3111
|
callStep = new LazyCallStep(
|
|
3112
|
+
this,
|
|
2997
3113
|
stepName,
|
|
2998
3114
|
url,
|
|
2999
3115
|
method,
|
|
@@ -3045,7 +3161,9 @@ var WorkflowContext = class {
|
|
|
3045
3161
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
3046
3162
|
const { timeout = "7d" } = options;
|
|
3047
3163
|
const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
|
|
3048
|
-
return await this.addStep(
|
|
3164
|
+
return await this.addStep(
|
|
3165
|
+
new LazyWaitForEventStep(this, stepName, eventId, timeoutStr)
|
|
3166
|
+
);
|
|
3049
3167
|
}
|
|
3050
3168
|
/**
|
|
3051
3169
|
* Notify workflow runs waiting for an event
|
|
@@ -3070,11 +3188,19 @@ var WorkflowContext = class {
|
|
|
3070
3188
|
*/
|
|
3071
3189
|
async notify(stepName, eventId, eventData) {
|
|
3072
3190
|
return await this.addStep(
|
|
3073
|
-
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
3191
|
+
new LazyNotifyStep(this, stepName, eventId, eventData, this.qstashClient.http)
|
|
3074
3192
|
);
|
|
3075
3193
|
}
|
|
3076
3194
|
async invoke(stepName, settings) {
|
|
3077
|
-
return await this.addStep(
|
|
3195
|
+
return await this.addStep(
|
|
3196
|
+
new LazyInvokeStep(this, stepName, settings)
|
|
3197
|
+
);
|
|
3198
|
+
}
|
|
3199
|
+
async createWebhook(stepName) {
|
|
3200
|
+
return await this.addStep(new LazyCreateWebhookStep(this, stepName));
|
|
3201
|
+
}
|
|
3202
|
+
async waitForWebhook(stepName, webhook, timeout) {
|
|
3203
|
+
return await this.addStep(new LazyWaitForWebhookStep(this, stepName, webhook, timeout));
|
|
3078
3204
|
}
|
|
3079
3205
|
/**
|
|
3080
3206
|
* Cancel the current workflow run
|
|
@@ -3238,13 +3364,6 @@ var processRawSteps = (rawSteps) => {
|
|
|
3238
3364
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
3239
3365
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
3240
3366
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
3241
|
-
if (step.waitEventId) {
|
|
3242
|
-
const newOut = {
|
|
3243
|
-
eventData: step.out ? decodeBase64(step.out) : void 0,
|
|
3244
|
-
timeout: step.waitTimeout ?? false
|
|
3245
|
-
};
|
|
3246
|
-
step.out = newOut;
|
|
3247
|
-
}
|
|
3248
3367
|
return step;
|
|
3249
3368
|
});
|
|
3250
3369
|
const steps = [initialStep, ...otherSteps];
|