@upstash/workflow 0.1.3-crpyto-canary → 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 +227 -202
- package/astro.mjs +1 -1
- package/{chunk-VIOVJ6QS.mjs → chunk-35GJPVE2.mjs} +275 -208
- package/cloudflare.d.mts +1 -1
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +227 -202
- package/cloudflare.mjs +1 -1
- package/express.d.mts +1 -1
- package/express.d.ts +1 -1
- package/express.js +217 -202
- package/express.mjs +1 -1
- package/h3.d.mts +1 -1
- package/h3.d.ts +1 -1
- package/h3.js +227 -202
- package/h3.mjs +1 -1
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +227 -202
- package/hono.mjs +1 -1
- package/index.d.mts +39 -2
- package/index.d.ts +39 -2
- package/index.js +286 -209
- package/index.mjs +1 -1
- package/nextjs.d.mts +1 -1
- package/nextjs.d.ts +1 -1
- package/nextjs.js +228 -204
- 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 +227 -202
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +1 -1
- package/svelte.d.ts +1 -1
- package/svelte.js +227 -202
- 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/astro.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIContext, APIRoute } from 'astro';
|
|
2
|
-
import { b as WorkflowContext, W as WorkflowServeOptions } from './types-
|
|
2
|
+
import { b as WorkflowContext, W as WorkflowServeOptions } from './types-CQuc-j8n.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
declare function serve<TInitialPayload = unknown>(routeFunction: (workflowContext: WorkflowContext<TInitialPayload>, apiContext: APIContext) => Promise<void>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">): {
|
package/astro.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIContext, APIRoute } from 'astro';
|
|
2
|
-
import { b as WorkflowContext, W as WorkflowServeOptions } from './types-
|
|
2
|
+
import { b as WorkflowContext, W as WorkflowServeOptions } from './types-CQuc-j8n.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
|
|
5
5
|
declare function serve<TInitialPayload = unknown>(routeFunction: (workflowContext: WorkflowContext<TInitialPayload>, apiContext: APIContext) => Promise<void>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">): {
|
package/astro.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// platforms/astro.ts
|
|
@@ -54,6 +64,190 @@ var formatWorkflowError = (error) => {
|
|
|
54
64
|
};
|
|
55
65
|
};
|
|
56
66
|
|
|
67
|
+
// src/client/utils.ts
|
|
68
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
69
|
+
const result = await requester.request({
|
|
70
|
+
path: ["v2", "notify", eventId],
|
|
71
|
+
method: "POST",
|
|
72
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
73
|
+
});
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/context/steps.ts
|
|
78
|
+
var BaseLazyStep = class {
|
|
79
|
+
stepName;
|
|
80
|
+
// will be set in the subclasses
|
|
81
|
+
constructor(stepName) {
|
|
82
|
+
this.stepName = stepName;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var LazyFunctionStep = class extends BaseLazyStep {
|
|
86
|
+
stepFunction;
|
|
87
|
+
stepType = "Run";
|
|
88
|
+
constructor(stepName, stepFunction) {
|
|
89
|
+
super(stepName);
|
|
90
|
+
this.stepFunction = stepFunction;
|
|
91
|
+
}
|
|
92
|
+
getPlanStep(concurrent, targetStep) {
|
|
93
|
+
return {
|
|
94
|
+
stepId: 0,
|
|
95
|
+
stepName: this.stepName,
|
|
96
|
+
stepType: this.stepType,
|
|
97
|
+
concurrent,
|
|
98
|
+
targetStep
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async getResultStep(concurrent, stepId) {
|
|
102
|
+
let result = this.stepFunction();
|
|
103
|
+
if (result instanceof Promise) {
|
|
104
|
+
result = await result;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
stepId,
|
|
108
|
+
stepName: this.stepName,
|
|
109
|
+
stepType: this.stepType,
|
|
110
|
+
out: result,
|
|
111
|
+
concurrent
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var LazySleepStep = class extends BaseLazyStep {
|
|
116
|
+
sleep;
|
|
117
|
+
stepType = "SleepFor";
|
|
118
|
+
constructor(stepName, sleep) {
|
|
119
|
+
super(stepName);
|
|
120
|
+
this.sleep = sleep;
|
|
121
|
+
}
|
|
122
|
+
getPlanStep(concurrent, targetStep) {
|
|
123
|
+
return {
|
|
124
|
+
stepId: 0,
|
|
125
|
+
stepName: this.stepName,
|
|
126
|
+
stepType: this.stepType,
|
|
127
|
+
sleepFor: this.sleep,
|
|
128
|
+
concurrent,
|
|
129
|
+
targetStep
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async getResultStep(concurrent, stepId) {
|
|
133
|
+
return await Promise.resolve({
|
|
134
|
+
stepId,
|
|
135
|
+
stepName: this.stepName,
|
|
136
|
+
stepType: this.stepType,
|
|
137
|
+
sleepFor: this.sleep,
|
|
138
|
+
concurrent
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
143
|
+
sleepUntil;
|
|
144
|
+
stepType = "SleepUntil";
|
|
145
|
+
constructor(stepName, sleepUntil) {
|
|
146
|
+
super(stepName);
|
|
147
|
+
this.sleepUntil = sleepUntil;
|
|
148
|
+
}
|
|
149
|
+
getPlanStep(concurrent, targetStep) {
|
|
150
|
+
return {
|
|
151
|
+
stepId: 0,
|
|
152
|
+
stepName: this.stepName,
|
|
153
|
+
stepType: this.stepType,
|
|
154
|
+
sleepUntil: this.sleepUntil,
|
|
155
|
+
concurrent,
|
|
156
|
+
targetStep
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async getResultStep(concurrent, stepId) {
|
|
160
|
+
return await Promise.resolve({
|
|
161
|
+
stepId,
|
|
162
|
+
stepName: this.stepName,
|
|
163
|
+
stepType: this.stepType,
|
|
164
|
+
sleepUntil: this.sleepUntil,
|
|
165
|
+
concurrent
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var LazyCallStep = class extends BaseLazyStep {
|
|
170
|
+
url;
|
|
171
|
+
method;
|
|
172
|
+
body;
|
|
173
|
+
headers;
|
|
174
|
+
stepType = "Call";
|
|
175
|
+
retries;
|
|
176
|
+
constructor(stepName, url, method, body, headers, retries) {
|
|
177
|
+
super(stepName);
|
|
178
|
+
this.url = url;
|
|
179
|
+
this.method = method;
|
|
180
|
+
this.body = body;
|
|
181
|
+
this.headers = headers;
|
|
182
|
+
this.retries = retries;
|
|
183
|
+
}
|
|
184
|
+
getPlanStep(concurrent, targetStep) {
|
|
185
|
+
return {
|
|
186
|
+
stepId: 0,
|
|
187
|
+
stepName: this.stepName,
|
|
188
|
+
stepType: this.stepType,
|
|
189
|
+
concurrent,
|
|
190
|
+
targetStep
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async getResultStep(concurrent, stepId) {
|
|
194
|
+
return await Promise.resolve({
|
|
195
|
+
stepId,
|
|
196
|
+
stepName: this.stepName,
|
|
197
|
+
stepType: this.stepType,
|
|
198
|
+
concurrent,
|
|
199
|
+
callUrl: this.url,
|
|
200
|
+
callMethod: this.method,
|
|
201
|
+
callBody: this.body,
|
|
202
|
+
callHeaders: this.headers
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
207
|
+
eventId;
|
|
208
|
+
timeout;
|
|
209
|
+
stepType = "Wait";
|
|
210
|
+
constructor(stepName, eventId, timeout) {
|
|
211
|
+
super(stepName);
|
|
212
|
+
this.eventId = eventId;
|
|
213
|
+
this.timeout = timeout;
|
|
214
|
+
}
|
|
215
|
+
getPlanStep(concurrent, targetStep) {
|
|
216
|
+
return {
|
|
217
|
+
stepId: 0,
|
|
218
|
+
stepName: this.stepName,
|
|
219
|
+
stepType: this.stepType,
|
|
220
|
+
waitEventId: this.eventId,
|
|
221
|
+
timeout: this.timeout,
|
|
222
|
+
concurrent,
|
|
223
|
+
targetStep
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
async getResultStep(concurrent, stepId) {
|
|
227
|
+
return await Promise.resolve({
|
|
228
|
+
stepId,
|
|
229
|
+
stepName: this.stepName,
|
|
230
|
+
stepType: this.stepType,
|
|
231
|
+
waitEventId: this.eventId,
|
|
232
|
+
timeout: this.timeout,
|
|
233
|
+
concurrent
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
238
|
+
stepType = "Notify";
|
|
239
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
240
|
+
super(stepName, async () => {
|
|
241
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
242
|
+
return {
|
|
243
|
+
eventId,
|
|
244
|
+
eventData,
|
|
245
|
+
notifyResponse
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
57
251
|
// node_modules/neverthrow/dist/index.es.js
|
|
58
252
|
var defaultErrorConfig = {
|
|
59
253
|
withStackTrace: false
|
|
@@ -509,10 +703,11 @@ var triggerFirstInvocation = async (workflowContext, retries, debug) => {
|
|
|
509
703
|
url: workflowContext.url
|
|
510
704
|
});
|
|
511
705
|
try {
|
|
512
|
-
|
|
706
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
707
|
+
await workflowContext.qstashClient.publish({
|
|
513
708
|
headers,
|
|
514
709
|
method: "POST",
|
|
515
|
-
body
|
|
710
|
+
body,
|
|
516
711
|
url: workflowContext.url
|
|
517
712
|
});
|
|
518
713
|
return ok("success");
|
|
@@ -638,7 +833,7 @@ ${atob(callbackMessage.body)}`
|
|
|
638
833
|
);
|
|
639
834
|
}
|
|
640
835
|
};
|
|
641
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries) => {
|
|
836
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries) => {
|
|
642
837
|
const baseHeaders = {
|
|
643
838
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
644
839
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -654,7 +849,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
654
849
|
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
655
850
|
}
|
|
656
851
|
if (step?.callUrl) {
|
|
657
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
852
|
+
baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
|
|
658
853
|
baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete";
|
|
659
854
|
if (retries) {
|
|
660
855
|
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
@@ -662,6 +857,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
662
857
|
}
|
|
663
858
|
} else if (retries !== void 0) {
|
|
664
859
|
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
860
|
+
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
665
861
|
}
|
|
666
862
|
if (userHeaders) {
|
|
667
863
|
for (const header of userHeaders.keys()) {
|
|
@@ -670,6 +866,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
670
866
|
} else {
|
|
671
867
|
baseHeaders[`Upstash-Forward-${header}`] = userHeaders.get(header);
|
|
672
868
|
}
|
|
869
|
+
baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
|
|
673
870
|
}
|
|
674
871
|
}
|
|
675
872
|
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
@@ -853,7 +1050,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
853
1050
|
step: resultStep,
|
|
854
1051
|
stepCount: this.stepCount
|
|
855
1052
|
});
|
|
856
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1053
|
+
await this.submitStepsToQStash([resultStep], [lazyStep]);
|
|
857
1054
|
return resultStep.out;
|
|
858
1055
|
}
|
|
859
1056
|
/**
|
|
@@ -885,7 +1082,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
885
1082
|
const planSteps = parallelSteps.map(
|
|
886
1083
|
(parallelStep, index) => parallelStep.getPlanStep(parallelSteps.length, initialStepCount + index)
|
|
887
1084
|
);
|
|
888
|
-
await this.submitStepsToQStash(planSteps);
|
|
1085
|
+
await this.submitStepsToQStash(planSteps, parallelSteps);
|
|
889
1086
|
break;
|
|
890
1087
|
}
|
|
891
1088
|
case "partial": {
|
|
@@ -898,11 +1095,12 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
898
1095
|
const stepIndex = planStep.targetStep - initialStepCount;
|
|
899
1096
|
validateStep(parallelSteps[stepIndex], planStep);
|
|
900
1097
|
try {
|
|
901
|
-
const
|
|
1098
|
+
const parallelStep = parallelSteps[stepIndex];
|
|
1099
|
+
const resultStep = await parallelStep.getResultStep(
|
|
902
1100
|
parallelSteps.length,
|
|
903
1101
|
planStep.targetStep
|
|
904
1102
|
);
|
|
905
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1103
|
+
await this.submitStepsToQStash([resultStep], [parallelStep]);
|
|
906
1104
|
} catch (error) {
|
|
907
1105
|
if (error instanceof QStashWorkflowAbort) {
|
|
908
1106
|
throw error;
|
|
@@ -963,7 +1161,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
963
1161
|
*
|
|
964
1162
|
* @param steps steps to send
|
|
965
1163
|
*/
|
|
966
|
-
async submitStepsToQStash(steps) {
|
|
1164
|
+
async submitStepsToQStash(steps, lazySteps) {
|
|
967
1165
|
if (steps.length === 0) {
|
|
968
1166
|
throw new QStashWorkflowError(
|
|
969
1167
|
`Unable to submit steps to QStash. Provided list is empty. Current step: ${this.stepCount}`
|
|
@@ -1008,7 +1206,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1008
1206
|
throw new QStashWorkflowAbort(steps[0].stepName, steps[0]);
|
|
1009
1207
|
}
|
|
1010
1208
|
const result = await this.context.qstashClient.batchJSON(
|
|
1011
|
-
steps.map((singleStep) => {
|
|
1209
|
+
steps.map((singleStep, index) => {
|
|
1210
|
+
const lazyStep = lazySteps[index];
|
|
1012
1211
|
const { headers } = getHeaders(
|
|
1013
1212
|
"false",
|
|
1014
1213
|
this.context.workflowRunId,
|
|
@@ -1016,7 +1215,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1016
1215
|
this.context.headers,
|
|
1017
1216
|
singleStep,
|
|
1018
1217
|
this.context.failureUrl,
|
|
1019
|
-
this.context.retries
|
|
1218
|
+
this.context.retries,
|
|
1219
|
+
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0
|
|
1020
1220
|
);
|
|
1021
1221
|
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
1022
1222
|
singleStep.out = JSON.stringify(singleStep.out);
|
|
@@ -1129,188 +1329,6 @@ var sortSteps = (steps) => {
|
|
|
1129
1329
|
return [...steps].sort((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1130
1330
|
};
|
|
1131
1331
|
|
|
1132
|
-
// src/client/utils.ts
|
|
1133
|
-
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1134
|
-
const result = await requester.request({
|
|
1135
|
-
path: ["v2", "notify", eventId],
|
|
1136
|
-
method: "POST",
|
|
1137
|
-
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1138
|
-
});
|
|
1139
|
-
return result;
|
|
1140
|
-
};
|
|
1141
|
-
|
|
1142
|
-
// src/context/steps.ts
|
|
1143
|
-
var BaseLazyStep = class {
|
|
1144
|
-
stepName;
|
|
1145
|
-
// will be set in the subclasses
|
|
1146
|
-
constructor(stepName) {
|
|
1147
|
-
this.stepName = stepName;
|
|
1148
|
-
}
|
|
1149
|
-
};
|
|
1150
|
-
var LazyFunctionStep = class extends BaseLazyStep {
|
|
1151
|
-
stepFunction;
|
|
1152
|
-
stepType = "Run";
|
|
1153
|
-
constructor(stepName, stepFunction) {
|
|
1154
|
-
super(stepName);
|
|
1155
|
-
this.stepFunction = stepFunction;
|
|
1156
|
-
}
|
|
1157
|
-
getPlanStep(concurrent, targetStep) {
|
|
1158
|
-
return {
|
|
1159
|
-
stepId: 0,
|
|
1160
|
-
stepName: this.stepName,
|
|
1161
|
-
stepType: this.stepType,
|
|
1162
|
-
concurrent,
|
|
1163
|
-
targetStep
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
async getResultStep(concurrent, stepId) {
|
|
1167
|
-
let result = this.stepFunction();
|
|
1168
|
-
if (result instanceof Promise) {
|
|
1169
|
-
result = await result;
|
|
1170
|
-
}
|
|
1171
|
-
return {
|
|
1172
|
-
stepId,
|
|
1173
|
-
stepName: this.stepName,
|
|
1174
|
-
stepType: this.stepType,
|
|
1175
|
-
out: result,
|
|
1176
|
-
concurrent
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
};
|
|
1180
|
-
var LazySleepStep = class extends BaseLazyStep {
|
|
1181
|
-
sleep;
|
|
1182
|
-
stepType = "SleepFor";
|
|
1183
|
-
constructor(stepName, sleep) {
|
|
1184
|
-
super(stepName);
|
|
1185
|
-
this.sleep = sleep;
|
|
1186
|
-
}
|
|
1187
|
-
getPlanStep(concurrent, targetStep) {
|
|
1188
|
-
return {
|
|
1189
|
-
stepId: 0,
|
|
1190
|
-
stepName: this.stepName,
|
|
1191
|
-
stepType: this.stepType,
|
|
1192
|
-
sleepFor: this.sleep,
|
|
1193
|
-
concurrent,
|
|
1194
|
-
targetStep
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
async getResultStep(concurrent, stepId) {
|
|
1198
|
-
return await Promise.resolve({
|
|
1199
|
-
stepId,
|
|
1200
|
-
stepName: this.stepName,
|
|
1201
|
-
stepType: this.stepType,
|
|
1202
|
-
sleepFor: this.sleep,
|
|
1203
|
-
concurrent
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1208
|
-
sleepUntil;
|
|
1209
|
-
stepType = "SleepUntil";
|
|
1210
|
-
constructor(stepName, sleepUntil) {
|
|
1211
|
-
super(stepName);
|
|
1212
|
-
this.sleepUntil = sleepUntil;
|
|
1213
|
-
}
|
|
1214
|
-
getPlanStep(concurrent, targetStep) {
|
|
1215
|
-
return {
|
|
1216
|
-
stepId: 0,
|
|
1217
|
-
stepName: this.stepName,
|
|
1218
|
-
stepType: this.stepType,
|
|
1219
|
-
sleepUntil: this.sleepUntil,
|
|
1220
|
-
concurrent,
|
|
1221
|
-
targetStep
|
|
1222
|
-
};
|
|
1223
|
-
}
|
|
1224
|
-
async getResultStep(concurrent, stepId) {
|
|
1225
|
-
return await Promise.resolve({
|
|
1226
|
-
stepId,
|
|
1227
|
-
stepName: this.stepName,
|
|
1228
|
-
stepType: this.stepType,
|
|
1229
|
-
sleepUntil: this.sleepUntil,
|
|
1230
|
-
concurrent
|
|
1231
|
-
});
|
|
1232
|
-
}
|
|
1233
|
-
};
|
|
1234
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
1235
|
-
url;
|
|
1236
|
-
method;
|
|
1237
|
-
body;
|
|
1238
|
-
headers;
|
|
1239
|
-
stepType = "Call";
|
|
1240
|
-
constructor(stepName, url, method, body, headers) {
|
|
1241
|
-
super(stepName);
|
|
1242
|
-
this.url = url;
|
|
1243
|
-
this.method = method;
|
|
1244
|
-
this.body = body;
|
|
1245
|
-
this.headers = headers;
|
|
1246
|
-
}
|
|
1247
|
-
getPlanStep(concurrent, targetStep) {
|
|
1248
|
-
return {
|
|
1249
|
-
stepId: 0,
|
|
1250
|
-
stepName: this.stepName,
|
|
1251
|
-
stepType: this.stepType,
|
|
1252
|
-
concurrent,
|
|
1253
|
-
targetStep
|
|
1254
|
-
};
|
|
1255
|
-
}
|
|
1256
|
-
async getResultStep(concurrent, stepId) {
|
|
1257
|
-
return await Promise.resolve({
|
|
1258
|
-
stepId,
|
|
1259
|
-
stepName: this.stepName,
|
|
1260
|
-
stepType: this.stepType,
|
|
1261
|
-
concurrent,
|
|
1262
|
-
callUrl: this.url,
|
|
1263
|
-
callMethod: this.method,
|
|
1264
|
-
callBody: this.body,
|
|
1265
|
-
callHeaders: this.headers
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
};
|
|
1269
|
-
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1270
|
-
eventId;
|
|
1271
|
-
timeout;
|
|
1272
|
-
stepType = "Wait";
|
|
1273
|
-
constructor(stepName, eventId, timeout) {
|
|
1274
|
-
super(stepName);
|
|
1275
|
-
this.eventId = eventId;
|
|
1276
|
-
this.timeout = timeout;
|
|
1277
|
-
}
|
|
1278
|
-
getPlanStep(concurrent, targetStep) {
|
|
1279
|
-
return {
|
|
1280
|
-
stepId: 0,
|
|
1281
|
-
stepName: this.stepName,
|
|
1282
|
-
stepType: this.stepType,
|
|
1283
|
-
waitEventId: this.eventId,
|
|
1284
|
-
timeout: this.timeout,
|
|
1285
|
-
concurrent,
|
|
1286
|
-
targetStep
|
|
1287
|
-
};
|
|
1288
|
-
}
|
|
1289
|
-
async getResultStep(concurrent, stepId) {
|
|
1290
|
-
return await Promise.resolve({
|
|
1291
|
-
stepId,
|
|
1292
|
-
stepName: this.stepName,
|
|
1293
|
-
stepType: this.stepType,
|
|
1294
|
-
waitEventId: this.eventId,
|
|
1295
|
-
timeout: this.timeout,
|
|
1296
|
-
concurrent
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1301
|
-
stepType = "Notify";
|
|
1302
|
-
constructor(stepName, eventId, eventData, requester) {
|
|
1303
|
-
super(stepName, async () => {
|
|
1304
|
-
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1305
|
-
return {
|
|
1306
|
-
eventId,
|
|
1307
|
-
eventData,
|
|
1308
|
-
notifyResponse
|
|
1309
|
-
};
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
};
|
|
1313
|
-
|
|
1314
1332
|
// src/context/context.ts
|
|
1315
1333
|
var WorkflowContext = class {
|
|
1316
1334
|
executor;
|
|
@@ -1526,11 +1544,13 @@ var WorkflowContext = class {
|
|
|
1526
1544
|
* network call without consuming any runtime.
|
|
1527
1545
|
*
|
|
1528
1546
|
* ```ts
|
|
1529
|
-
* const
|
|
1547
|
+
* const { status, body } = await context.call<string>(
|
|
1530
1548
|
* "post call step",
|
|
1531
|
-
*
|
|
1532
|
-
*
|
|
1533
|
-
*
|
|
1549
|
+
* {
|
|
1550
|
+
* url: `https://www.some-endpoint.com/api`,
|
|
1551
|
+
* method: "POST",
|
|
1552
|
+
* body: "my-payload"
|
|
1553
|
+
* }
|
|
1534
1554
|
* );
|
|
1535
1555
|
* ```
|
|
1536
1556
|
*
|
|
@@ -1540,9 +1560,10 @@ var WorkflowContext = class {
|
|
|
1540
1560
|
*
|
|
1541
1561
|
* @param stepName
|
|
1542
1562
|
* @param url url to call
|
|
1543
|
-
* @param method call method
|
|
1563
|
+
* @param method call method. "GET" by default.
|
|
1544
1564
|
* @param body call body
|
|
1545
1565
|
* @param headers call headers
|
|
1566
|
+
* @param retries number of call retries. 0 by default
|
|
1546
1567
|
* @returns call result as {
|
|
1547
1568
|
* status: number;
|
|
1548
1569
|
* body: unknown;
|
|
@@ -1550,9 +1571,9 @@ var WorkflowContext = class {
|
|
|
1550
1571
|
* }
|
|
1551
1572
|
*/
|
|
1552
1573
|
async call(stepName, settings) {
|
|
1553
|
-
const { url, method = "GET", body, headers = {} } = settings;
|
|
1574
|
+
const { url, method = "GET", body, headers = {}, retries = 0 } = settings;
|
|
1554
1575
|
const result = await this.addStep(
|
|
1555
|
-
new LazyCallStep(stepName, url, method, body, headers
|
|
1576
|
+
new LazyCallStep(stepName, url, method, body, headers, retries)
|
|
1556
1577
|
);
|
|
1557
1578
|
if (typeof result === "string") {
|
|
1558
1579
|
try {
|
|
@@ -1699,10 +1720,14 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
1699
1720
|
};
|
|
1700
1721
|
|
|
1701
1722
|
// src/utils.ts
|
|
1723
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
1702
1724
|
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
1703
1725
|
var NANOID_LENGTH = 21;
|
|
1704
1726
|
function nanoid() {
|
|
1705
|
-
return [...
|
|
1727
|
+
return [...import_node_crypto.default.getRandomValues(new Uint8Array(NANOID_LENGTH))].map((x) => NANOID_CHARS[x % NANOID_CHARS.length]).join("");
|
|
1728
|
+
}
|
|
1729
|
+
function getWorkflowRunId(id) {
|
|
1730
|
+
return `wfr_${id ?? nanoid()}`;
|
|
1706
1731
|
}
|
|
1707
1732
|
function decodeBase64(base64) {
|
|
1708
1733
|
try {
|
|
@@ -1808,7 +1833,7 @@ var validateRequest = (request) => {
|
|
|
1808
1833
|
`Incompatible workflow sdk protocol version. Expected ${WORKFLOW_PROTOCOL_VERSION}, got ${versionHeader} from the request.`
|
|
1809
1834
|
);
|
|
1810
1835
|
}
|
|
1811
|
-
const workflowRunId = isFirstInvocation ?
|
|
1836
|
+
const workflowRunId = isFirstInvocation ? getWorkflowRunId() : request.headers.get(WORKFLOW_ID_HEADER) ?? "";
|
|
1812
1837
|
if (workflowRunId.length === 0) {
|
|
1813
1838
|
throw new QStashWorkflowError("Couldn't get workflow id from header");
|
|
1814
1839
|
}
|