@upstash/workflow 0.1.3-crpyto-canary-2 → 0.1.3
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 +1 -1
- package/astro.d.ts +1 -1
- package/astro.js +217 -203
- package/astro.mjs +1 -1
- package/{chunk-3FILROVK.mjs → chunk-35GJPVE2.mjs} +275 -209
- package/cloudflare.d.mts +1 -1
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +217 -203
- package/cloudflare.mjs +1 -1
- package/express.d.mts +1 -1
- package/express.d.ts +1 -1
- package/express.js +217 -203
- package/express.mjs +1 -1
- package/h3.d.mts +1 -1
- package/h3.d.ts +1 -1
- package/h3.js +217 -203
- package/h3.mjs +1 -1
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +217 -203
- package/hono.mjs +1 -1
- package/index.d.mts +39 -2
- package/index.d.ts +39 -2
- package/index.js +276 -210
- package/index.mjs +1 -1
- package/nextjs.d.mts +1 -1
- package/nextjs.d.ts +1 -1
- package/nextjs.js +218 -205
- package/nextjs.mjs +2 -3
- package/package.json +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +217 -203
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +1 -1
- package/svelte.d.ts +1 -1
- package/svelte.js +217 -203
- package/svelte.mjs +1 -1
- package/{types-CI-2skYU.d.mts → types-CQuc-j8n.d.mts} +14 -9
- package/{types-CI-2skYU.d.ts → types-CQuc-j8n.d.ts} +14 -9
package/h3.js
CHANGED
|
@@ -376,6 +376,190 @@ var formatWorkflowError = (error) => {
|
|
|
376
376
|
};
|
|
377
377
|
};
|
|
378
378
|
|
|
379
|
+
// src/client/utils.ts
|
|
380
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
381
|
+
const result = await requester.request({
|
|
382
|
+
path: ["v2", "notify", eventId],
|
|
383
|
+
method: "POST",
|
|
384
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
385
|
+
});
|
|
386
|
+
return result;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/context/steps.ts
|
|
390
|
+
var BaseLazyStep = class {
|
|
391
|
+
stepName;
|
|
392
|
+
// will be set in the subclasses
|
|
393
|
+
constructor(stepName) {
|
|
394
|
+
this.stepName = stepName;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
var LazyFunctionStep = class extends BaseLazyStep {
|
|
398
|
+
stepFunction;
|
|
399
|
+
stepType = "Run";
|
|
400
|
+
constructor(stepName, stepFunction) {
|
|
401
|
+
super(stepName);
|
|
402
|
+
this.stepFunction = stepFunction;
|
|
403
|
+
}
|
|
404
|
+
getPlanStep(concurrent, targetStep) {
|
|
405
|
+
return {
|
|
406
|
+
stepId: 0,
|
|
407
|
+
stepName: this.stepName,
|
|
408
|
+
stepType: this.stepType,
|
|
409
|
+
concurrent,
|
|
410
|
+
targetStep
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
async getResultStep(concurrent, stepId) {
|
|
414
|
+
let result = this.stepFunction();
|
|
415
|
+
if (result instanceof Promise) {
|
|
416
|
+
result = await result;
|
|
417
|
+
}
|
|
418
|
+
return {
|
|
419
|
+
stepId,
|
|
420
|
+
stepName: this.stepName,
|
|
421
|
+
stepType: this.stepType,
|
|
422
|
+
out: result,
|
|
423
|
+
concurrent
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
var LazySleepStep = class extends BaseLazyStep {
|
|
428
|
+
sleep;
|
|
429
|
+
stepType = "SleepFor";
|
|
430
|
+
constructor(stepName, sleep) {
|
|
431
|
+
super(stepName);
|
|
432
|
+
this.sleep = sleep;
|
|
433
|
+
}
|
|
434
|
+
getPlanStep(concurrent, targetStep) {
|
|
435
|
+
return {
|
|
436
|
+
stepId: 0,
|
|
437
|
+
stepName: this.stepName,
|
|
438
|
+
stepType: this.stepType,
|
|
439
|
+
sleepFor: this.sleep,
|
|
440
|
+
concurrent,
|
|
441
|
+
targetStep
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
async getResultStep(concurrent, stepId) {
|
|
445
|
+
return await Promise.resolve({
|
|
446
|
+
stepId,
|
|
447
|
+
stepName: this.stepName,
|
|
448
|
+
stepType: this.stepType,
|
|
449
|
+
sleepFor: this.sleep,
|
|
450
|
+
concurrent
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
455
|
+
sleepUntil;
|
|
456
|
+
stepType = "SleepUntil";
|
|
457
|
+
constructor(stepName, sleepUntil) {
|
|
458
|
+
super(stepName);
|
|
459
|
+
this.sleepUntil = sleepUntil;
|
|
460
|
+
}
|
|
461
|
+
getPlanStep(concurrent, targetStep) {
|
|
462
|
+
return {
|
|
463
|
+
stepId: 0,
|
|
464
|
+
stepName: this.stepName,
|
|
465
|
+
stepType: this.stepType,
|
|
466
|
+
sleepUntil: this.sleepUntil,
|
|
467
|
+
concurrent,
|
|
468
|
+
targetStep
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
async getResultStep(concurrent, stepId) {
|
|
472
|
+
return await Promise.resolve({
|
|
473
|
+
stepId,
|
|
474
|
+
stepName: this.stepName,
|
|
475
|
+
stepType: this.stepType,
|
|
476
|
+
sleepUntil: this.sleepUntil,
|
|
477
|
+
concurrent
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
var LazyCallStep = class extends BaseLazyStep {
|
|
482
|
+
url;
|
|
483
|
+
method;
|
|
484
|
+
body;
|
|
485
|
+
headers;
|
|
486
|
+
stepType = "Call";
|
|
487
|
+
retries;
|
|
488
|
+
constructor(stepName, url, method, body, headers, retries) {
|
|
489
|
+
super(stepName);
|
|
490
|
+
this.url = url;
|
|
491
|
+
this.method = method;
|
|
492
|
+
this.body = body;
|
|
493
|
+
this.headers = headers;
|
|
494
|
+
this.retries = retries;
|
|
495
|
+
}
|
|
496
|
+
getPlanStep(concurrent, targetStep) {
|
|
497
|
+
return {
|
|
498
|
+
stepId: 0,
|
|
499
|
+
stepName: this.stepName,
|
|
500
|
+
stepType: this.stepType,
|
|
501
|
+
concurrent,
|
|
502
|
+
targetStep
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
async getResultStep(concurrent, stepId) {
|
|
506
|
+
return await Promise.resolve({
|
|
507
|
+
stepId,
|
|
508
|
+
stepName: this.stepName,
|
|
509
|
+
stepType: this.stepType,
|
|
510
|
+
concurrent,
|
|
511
|
+
callUrl: this.url,
|
|
512
|
+
callMethod: this.method,
|
|
513
|
+
callBody: this.body,
|
|
514
|
+
callHeaders: this.headers
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
519
|
+
eventId;
|
|
520
|
+
timeout;
|
|
521
|
+
stepType = "Wait";
|
|
522
|
+
constructor(stepName, eventId, timeout) {
|
|
523
|
+
super(stepName);
|
|
524
|
+
this.eventId = eventId;
|
|
525
|
+
this.timeout = timeout;
|
|
526
|
+
}
|
|
527
|
+
getPlanStep(concurrent, targetStep) {
|
|
528
|
+
return {
|
|
529
|
+
stepId: 0,
|
|
530
|
+
stepName: this.stepName,
|
|
531
|
+
stepType: this.stepType,
|
|
532
|
+
waitEventId: this.eventId,
|
|
533
|
+
timeout: this.timeout,
|
|
534
|
+
concurrent,
|
|
535
|
+
targetStep
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
async getResultStep(concurrent, stepId) {
|
|
539
|
+
return await Promise.resolve({
|
|
540
|
+
stepId,
|
|
541
|
+
stepName: this.stepName,
|
|
542
|
+
stepType: this.stepType,
|
|
543
|
+
waitEventId: this.eventId,
|
|
544
|
+
timeout: this.timeout,
|
|
545
|
+
concurrent
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
550
|
+
stepType = "Notify";
|
|
551
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
552
|
+
super(stepName, async () => {
|
|
553
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
554
|
+
return {
|
|
555
|
+
eventId,
|
|
556
|
+
eventData,
|
|
557
|
+
notifyResponse
|
|
558
|
+
};
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
|
|
379
563
|
// node_modules/neverthrow/dist/index.es.js
|
|
380
564
|
var defaultErrorConfig = {
|
|
381
565
|
withStackTrace: false
|
|
@@ -831,10 +1015,11 @@ var triggerFirstInvocation = async (workflowContext, retries, debug) => {
|
|
|
831
1015
|
url: workflowContext.url
|
|
832
1016
|
});
|
|
833
1017
|
try {
|
|
834
|
-
|
|
1018
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
1019
|
+
await workflowContext.qstashClient.publish({
|
|
835
1020
|
headers,
|
|
836
1021
|
method: "POST",
|
|
837
|
-
body
|
|
1022
|
+
body,
|
|
838
1023
|
url: workflowContext.url
|
|
839
1024
|
});
|
|
840
1025
|
return ok("success");
|
|
@@ -960,7 +1145,7 @@ ${atob(callbackMessage.body)}`
|
|
|
960
1145
|
);
|
|
961
1146
|
}
|
|
962
1147
|
};
|
|
963
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries) => {
|
|
1148
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries) => {
|
|
964
1149
|
const baseHeaders = {
|
|
965
1150
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
966
1151
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -976,7 +1161,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
976
1161
|
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
977
1162
|
}
|
|
978
1163
|
if (step?.callUrl) {
|
|
979
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
1164
|
+
baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
|
|
980
1165
|
baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete";
|
|
981
1166
|
if (retries) {
|
|
982
1167
|
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
@@ -984,6 +1169,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
984
1169
|
}
|
|
985
1170
|
} else if (retries !== void 0) {
|
|
986
1171
|
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
1172
|
+
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
987
1173
|
}
|
|
988
1174
|
if (userHeaders) {
|
|
989
1175
|
for (const header of userHeaders.keys()) {
|
|
@@ -992,6 +1178,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
992
1178
|
} else {
|
|
993
1179
|
baseHeaders[`Upstash-Forward-${header}`] = userHeaders.get(header);
|
|
994
1180
|
}
|
|
1181
|
+
baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
|
|
995
1182
|
}
|
|
996
1183
|
}
|
|
997
1184
|
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
@@ -1175,7 +1362,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1175
1362
|
step: resultStep,
|
|
1176
1363
|
stepCount: this.stepCount
|
|
1177
1364
|
});
|
|
1178
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1365
|
+
await this.submitStepsToQStash([resultStep], [lazyStep]);
|
|
1179
1366
|
return resultStep.out;
|
|
1180
1367
|
}
|
|
1181
1368
|
/**
|
|
@@ -1207,7 +1394,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1207
1394
|
const planSteps = parallelSteps.map(
|
|
1208
1395
|
(parallelStep, index) => parallelStep.getPlanStep(parallelSteps.length, initialStepCount + index)
|
|
1209
1396
|
);
|
|
1210
|
-
await this.submitStepsToQStash(planSteps);
|
|
1397
|
+
await this.submitStepsToQStash(planSteps, parallelSteps);
|
|
1211
1398
|
break;
|
|
1212
1399
|
}
|
|
1213
1400
|
case "partial": {
|
|
@@ -1220,11 +1407,12 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1220
1407
|
const stepIndex = planStep.targetStep - initialStepCount;
|
|
1221
1408
|
validateStep(parallelSteps[stepIndex], planStep);
|
|
1222
1409
|
try {
|
|
1223
|
-
const
|
|
1410
|
+
const parallelStep = parallelSteps[stepIndex];
|
|
1411
|
+
const resultStep = await parallelStep.getResultStep(
|
|
1224
1412
|
parallelSteps.length,
|
|
1225
1413
|
planStep.targetStep
|
|
1226
1414
|
);
|
|
1227
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1415
|
+
await this.submitStepsToQStash([resultStep], [parallelStep]);
|
|
1228
1416
|
} catch (error) {
|
|
1229
1417
|
if (error instanceof QStashWorkflowAbort) {
|
|
1230
1418
|
throw error;
|
|
@@ -1285,7 +1473,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1285
1473
|
*
|
|
1286
1474
|
* @param steps steps to send
|
|
1287
1475
|
*/
|
|
1288
|
-
async submitStepsToQStash(steps) {
|
|
1476
|
+
async submitStepsToQStash(steps, lazySteps) {
|
|
1289
1477
|
if (steps.length === 0) {
|
|
1290
1478
|
throw new QStashWorkflowError(
|
|
1291
1479
|
`Unable to submit steps to QStash. Provided list is empty. Current step: ${this.stepCount}`
|
|
@@ -1330,7 +1518,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1330
1518
|
throw new QStashWorkflowAbort(steps[0].stepName, steps[0]);
|
|
1331
1519
|
}
|
|
1332
1520
|
const result = await this.context.qstashClient.batchJSON(
|
|
1333
|
-
steps.map((singleStep) => {
|
|
1521
|
+
steps.map((singleStep, index) => {
|
|
1522
|
+
const lazyStep = lazySteps[index];
|
|
1334
1523
|
const { headers } = getHeaders(
|
|
1335
1524
|
"false",
|
|
1336
1525
|
this.context.workflowRunId,
|
|
@@ -1338,7 +1527,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1338
1527
|
this.context.headers,
|
|
1339
1528
|
singleStep,
|
|
1340
1529
|
this.context.failureUrl,
|
|
1341
|
-
this.context.retries
|
|
1530
|
+
this.context.retries,
|
|
1531
|
+
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0
|
|
1342
1532
|
);
|
|
1343
1533
|
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
1344
1534
|
singleStep.out = JSON.stringify(singleStep.out);
|
|
@@ -1451,188 +1641,6 @@ var sortSteps = (steps) => {
|
|
|
1451
1641
|
return [...steps].sort((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1452
1642
|
};
|
|
1453
1643
|
|
|
1454
|
-
// src/client/utils.ts
|
|
1455
|
-
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1456
|
-
const result = await requester.request({
|
|
1457
|
-
path: ["v2", "notify", eventId],
|
|
1458
|
-
method: "POST",
|
|
1459
|
-
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1460
|
-
});
|
|
1461
|
-
return result;
|
|
1462
|
-
};
|
|
1463
|
-
|
|
1464
|
-
// src/context/steps.ts
|
|
1465
|
-
var BaseLazyStep = class {
|
|
1466
|
-
stepName;
|
|
1467
|
-
// will be set in the subclasses
|
|
1468
|
-
constructor(stepName) {
|
|
1469
|
-
this.stepName = stepName;
|
|
1470
|
-
}
|
|
1471
|
-
};
|
|
1472
|
-
var LazyFunctionStep = class extends BaseLazyStep {
|
|
1473
|
-
stepFunction;
|
|
1474
|
-
stepType = "Run";
|
|
1475
|
-
constructor(stepName, stepFunction) {
|
|
1476
|
-
super(stepName);
|
|
1477
|
-
this.stepFunction = stepFunction;
|
|
1478
|
-
}
|
|
1479
|
-
getPlanStep(concurrent, targetStep) {
|
|
1480
|
-
return {
|
|
1481
|
-
stepId: 0,
|
|
1482
|
-
stepName: this.stepName,
|
|
1483
|
-
stepType: this.stepType,
|
|
1484
|
-
concurrent,
|
|
1485
|
-
targetStep
|
|
1486
|
-
};
|
|
1487
|
-
}
|
|
1488
|
-
async getResultStep(concurrent, stepId) {
|
|
1489
|
-
let result = this.stepFunction();
|
|
1490
|
-
if (result instanceof Promise) {
|
|
1491
|
-
result = await result;
|
|
1492
|
-
}
|
|
1493
|
-
return {
|
|
1494
|
-
stepId,
|
|
1495
|
-
stepName: this.stepName,
|
|
1496
|
-
stepType: this.stepType,
|
|
1497
|
-
out: result,
|
|
1498
|
-
concurrent
|
|
1499
|
-
};
|
|
1500
|
-
}
|
|
1501
|
-
};
|
|
1502
|
-
var LazySleepStep = class extends BaseLazyStep {
|
|
1503
|
-
sleep;
|
|
1504
|
-
stepType = "SleepFor";
|
|
1505
|
-
constructor(stepName, sleep) {
|
|
1506
|
-
super(stepName);
|
|
1507
|
-
this.sleep = sleep;
|
|
1508
|
-
}
|
|
1509
|
-
getPlanStep(concurrent, targetStep) {
|
|
1510
|
-
return {
|
|
1511
|
-
stepId: 0,
|
|
1512
|
-
stepName: this.stepName,
|
|
1513
|
-
stepType: this.stepType,
|
|
1514
|
-
sleepFor: this.sleep,
|
|
1515
|
-
concurrent,
|
|
1516
|
-
targetStep
|
|
1517
|
-
};
|
|
1518
|
-
}
|
|
1519
|
-
async getResultStep(concurrent, stepId) {
|
|
1520
|
-
return await Promise.resolve({
|
|
1521
|
-
stepId,
|
|
1522
|
-
stepName: this.stepName,
|
|
1523
|
-
stepType: this.stepType,
|
|
1524
|
-
sleepFor: this.sleep,
|
|
1525
|
-
concurrent
|
|
1526
|
-
});
|
|
1527
|
-
}
|
|
1528
|
-
};
|
|
1529
|
-
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1530
|
-
sleepUntil;
|
|
1531
|
-
stepType = "SleepUntil";
|
|
1532
|
-
constructor(stepName, sleepUntil) {
|
|
1533
|
-
super(stepName);
|
|
1534
|
-
this.sleepUntil = sleepUntil;
|
|
1535
|
-
}
|
|
1536
|
-
getPlanStep(concurrent, targetStep) {
|
|
1537
|
-
return {
|
|
1538
|
-
stepId: 0,
|
|
1539
|
-
stepName: this.stepName,
|
|
1540
|
-
stepType: this.stepType,
|
|
1541
|
-
sleepUntil: this.sleepUntil,
|
|
1542
|
-
concurrent,
|
|
1543
|
-
targetStep
|
|
1544
|
-
};
|
|
1545
|
-
}
|
|
1546
|
-
async getResultStep(concurrent, stepId) {
|
|
1547
|
-
return await Promise.resolve({
|
|
1548
|
-
stepId,
|
|
1549
|
-
stepName: this.stepName,
|
|
1550
|
-
stepType: this.stepType,
|
|
1551
|
-
sleepUntil: this.sleepUntil,
|
|
1552
|
-
concurrent
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
};
|
|
1556
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
1557
|
-
url;
|
|
1558
|
-
method;
|
|
1559
|
-
body;
|
|
1560
|
-
headers;
|
|
1561
|
-
stepType = "Call";
|
|
1562
|
-
constructor(stepName, url, method, body, headers) {
|
|
1563
|
-
super(stepName);
|
|
1564
|
-
this.url = url;
|
|
1565
|
-
this.method = method;
|
|
1566
|
-
this.body = body;
|
|
1567
|
-
this.headers = headers;
|
|
1568
|
-
}
|
|
1569
|
-
getPlanStep(concurrent, targetStep) {
|
|
1570
|
-
return {
|
|
1571
|
-
stepId: 0,
|
|
1572
|
-
stepName: this.stepName,
|
|
1573
|
-
stepType: this.stepType,
|
|
1574
|
-
concurrent,
|
|
1575
|
-
targetStep
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
async getResultStep(concurrent, stepId) {
|
|
1579
|
-
return await Promise.resolve({
|
|
1580
|
-
stepId,
|
|
1581
|
-
stepName: this.stepName,
|
|
1582
|
-
stepType: this.stepType,
|
|
1583
|
-
concurrent,
|
|
1584
|
-
callUrl: this.url,
|
|
1585
|
-
callMethod: this.method,
|
|
1586
|
-
callBody: this.body,
|
|
1587
|
-
callHeaders: this.headers
|
|
1588
|
-
});
|
|
1589
|
-
}
|
|
1590
|
-
};
|
|
1591
|
-
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1592
|
-
eventId;
|
|
1593
|
-
timeout;
|
|
1594
|
-
stepType = "Wait";
|
|
1595
|
-
constructor(stepName, eventId, timeout) {
|
|
1596
|
-
super(stepName);
|
|
1597
|
-
this.eventId = eventId;
|
|
1598
|
-
this.timeout = timeout;
|
|
1599
|
-
}
|
|
1600
|
-
getPlanStep(concurrent, targetStep) {
|
|
1601
|
-
return {
|
|
1602
|
-
stepId: 0,
|
|
1603
|
-
stepName: this.stepName,
|
|
1604
|
-
stepType: this.stepType,
|
|
1605
|
-
waitEventId: this.eventId,
|
|
1606
|
-
timeout: this.timeout,
|
|
1607
|
-
concurrent,
|
|
1608
|
-
targetStep
|
|
1609
|
-
};
|
|
1610
|
-
}
|
|
1611
|
-
async getResultStep(concurrent, stepId) {
|
|
1612
|
-
return await Promise.resolve({
|
|
1613
|
-
stepId,
|
|
1614
|
-
stepName: this.stepName,
|
|
1615
|
-
stepType: this.stepType,
|
|
1616
|
-
waitEventId: this.eventId,
|
|
1617
|
-
timeout: this.timeout,
|
|
1618
|
-
concurrent
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1623
|
-
stepType = "Notify";
|
|
1624
|
-
constructor(stepName, eventId, eventData, requester) {
|
|
1625
|
-
super(stepName, async () => {
|
|
1626
|
-
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1627
|
-
return {
|
|
1628
|
-
eventId,
|
|
1629
|
-
eventData,
|
|
1630
|
-
notifyResponse
|
|
1631
|
-
};
|
|
1632
|
-
});
|
|
1633
|
-
}
|
|
1634
|
-
};
|
|
1635
|
-
|
|
1636
1644
|
// src/context/context.ts
|
|
1637
1645
|
var WorkflowContext = class {
|
|
1638
1646
|
executor;
|
|
@@ -1848,11 +1856,13 @@ var WorkflowContext = class {
|
|
|
1848
1856
|
* network call without consuming any runtime.
|
|
1849
1857
|
*
|
|
1850
1858
|
* ```ts
|
|
1851
|
-
* const
|
|
1859
|
+
* const { status, body } = await context.call<string>(
|
|
1852
1860
|
* "post call step",
|
|
1853
|
-
*
|
|
1854
|
-
*
|
|
1855
|
-
*
|
|
1861
|
+
* {
|
|
1862
|
+
* url: `https://www.some-endpoint.com/api`,
|
|
1863
|
+
* method: "POST",
|
|
1864
|
+
* body: "my-payload"
|
|
1865
|
+
* }
|
|
1856
1866
|
* );
|
|
1857
1867
|
* ```
|
|
1858
1868
|
*
|
|
@@ -1862,9 +1872,10 @@ var WorkflowContext = class {
|
|
|
1862
1872
|
*
|
|
1863
1873
|
* @param stepName
|
|
1864
1874
|
* @param url url to call
|
|
1865
|
-
* @param method call method
|
|
1875
|
+
* @param method call method. "GET" by default.
|
|
1866
1876
|
* @param body call body
|
|
1867
1877
|
* @param headers call headers
|
|
1878
|
+
* @param retries number of call retries. 0 by default
|
|
1868
1879
|
* @returns call result as {
|
|
1869
1880
|
* status: number;
|
|
1870
1881
|
* body: unknown;
|
|
@@ -1872,9 +1883,9 @@ var WorkflowContext = class {
|
|
|
1872
1883
|
* }
|
|
1873
1884
|
*/
|
|
1874
1885
|
async call(stepName, settings) {
|
|
1875
|
-
const { url, method = "GET", body, headers = {} } = settings;
|
|
1886
|
+
const { url, method = "GET", body, headers = {}, retries = 0 } = settings;
|
|
1876
1887
|
const result = await this.addStep(
|
|
1877
|
-
new LazyCallStep(stepName, url, method, body, headers
|
|
1888
|
+
new LazyCallStep(stepName, url, method, body, headers, retries)
|
|
1878
1889
|
);
|
|
1879
1890
|
if (typeof result === "string") {
|
|
1880
1891
|
try {
|
|
@@ -2021,11 +2032,14 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
2021
2032
|
};
|
|
2022
2033
|
|
|
2023
2034
|
// src/utils.ts
|
|
2024
|
-
var
|
|
2035
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
2025
2036
|
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
2026
2037
|
var NANOID_LENGTH = 21;
|
|
2027
2038
|
function nanoid() {
|
|
2028
|
-
return [...
|
|
2039
|
+
return [...import_node_crypto.default.getRandomValues(new Uint8Array(NANOID_LENGTH))].map((x) => NANOID_CHARS[x % NANOID_CHARS.length]).join("");
|
|
2040
|
+
}
|
|
2041
|
+
function getWorkflowRunId(id) {
|
|
2042
|
+
return `wfr_${id ?? nanoid()}`;
|
|
2029
2043
|
}
|
|
2030
2044
|
function decodeBase64(base64) {
|
|
2031
2045
|
try {
|
|
@@ -2131,7 +2145,7 @@ var validateRequest = (request) => {
|
|
|
2131
2145
|
`Incompatible workflow sdk protocol version. Expected ${WORKFLOW_PROTOCOL_VERSION}, got ${versionHeader} from the request.`
|
|
2132
2146
|
);
|
|
2133
2147
|
}
|
|
2134
|
-
const workflowRunId = isFirstInvocation ?
|
|
2148
|
+
const workflowRunId = isFirstInvocation ? getWorkflowRunId() : request.headers.get(WORKFLOW_ID_HEADER) ?? "";
|
|
2135
2149
|
if (workflowRunId.length === 0) {
|
|
2136
2150
|
throw new QStashWorkflowError("Couldn't get workflow id from header");
|
|
2137
2151
|
}
|
package/h3.mjs
CHANGED
package/hono.d.mts
CHANGED
package/hono.d.ts
CHANGED