@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
|
@@ -60,6 +60,197 @@ var formatWorkflowError = (error) => {
|
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
+
// src/client/utils.ts
|
|
64
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
65
|
+
const result = await requester.request({
|
|
66
|
+
path: ["v2", "notify", eventId],
|
|
67
|
+
method: "POST",
|
|
68
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
69
|
+
});
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
var makeGetWaitersRequest = async (requester, eventId) => {
|
|
73
|
+
const result = await requester.request({
|
|
74
|
+
path: ["v2", "waiters", eventId],
|
|
75
|
+
method: "GET"
|
|
76
|
+
});
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/context/steps.ts
|
|
81
|
+
var BaseLazyStep = class {
|
|
82
|
+
stepName;
|
|
83
|
+
// will be set in the subclasses
|
|
84
|
+
constructor(stepName) {
|
|
85
|
+
this.stepName = stepName;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var LazyFunctionStep = class extends BaseLazyStep {
|
|
89
|
+
stepFunction;
|
|
90
|
+
stepType = "Run";
|
|
91
|
+
constructor(stepName, stepFunction) {
|
|
92
|
+
super(stepName);
|
|
93
|
+
this.stepFunction = stepFunction;
|
|
94
|
+
}
|
|
95
|
+
getPlanStep(concurrent, targetStep) {
|
|
96
|
+
return {
|
|
97
|
+
stepId: 0,
|
|
98
|
+
stepName: this.stepName,
|
|
99
|
+
stepType: this.stepType,
|
|
100
|
+
concurrent,
|
|
101
|
+
targetStep
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async getResultStep(concurrent, stepId) {
|
|
105
|
+
let result = this.stepFunction();
|
|
106
|
+
if (result instanceof Promise) {
|
|
107
|
+
result = await result;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
stepId,
|
|
111
|
+
stepName: this.stepName,
|
|
112
|
+
stepType: this.stepType,
|
|
113
|
+
out: result,
|
|
114
|
+
concurrent
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var LazySleepStep = class extends BaseLazyStep {
|
|
119
|
+
sleep;
|
|
120
|
+
stepType = "SleepFor";
|
|
121
|
+
constructor(stepName, sleep) {
|
|
122
|
+
super(stepName);
|
|
123
|
+
this.sleep = sleep;
|
|
124
|
+
}
|
|
125
|
+
getPlanStep(concurrent, targetStep) {
|
|
126
|
+
return {
|
|
127
|
+
stepId: 0,
|
|
128
|
+
stepName: this.stepName,
|
|
129
|
+
stepType: this.stepType,
|
|
130
|
+
sleepFor: this.sleep,
|
|
131
|
+
concurrent,
|
|
132
|
+
targetStep
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
async getResultStep(concurrent, stepId) {
|
|
136
|
+
return await Promise.resolve({
|
|
137
|
+
stepId,
|
|
138
|
+
stepName: this.stepName,
|
|
139
|
+
stepType: this.stepType,
|
|
140
|
+
sleepFor: this.sleep,
|
|
141
|
+
concurrent
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
146
|
+
sleepUntil;
|
|
147
|
+
stepType = "SleepUntil";
|
|
148
|
+
constructor(stepName, sleepUntil) {
|
|
149
|
+
super(stepName);
|
|
150
|
+
this.sleepUntil = sleepUntil;
|
|
151
|
+
}
|
|
152
|
+
getPlanStep(concurrent, targetStep) {
|
|
153
|
+
return {
|
|
154
|
+
stepId: 0,
|
|
155
|
+
stepName: this.stepName,
|
|
156
|
+
stepType: this.stepType,
|
|
157
|
+
sleepUntil: this.sleepUntil,
|
|
158
|
+
concurrent,
|
|
159
|
+
targetStep
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async getResultStep(concurrent, stepId) {
|
|
163
|
+
return await Promise.resolve({
|
|
164
|
+
stepId,
|
|
165
|
+
stepName: this.stepName,
|
|
166
|
+
stepType: this.stepType,
|
|
167
|
+
sleepUntil: this.sleepUntil,
|
|
168
|
+
concurrent
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var LazyCallStep = class extends BaseLazyStep {
|
|
173
|
+
url;
|
|
174
|
+
method;
|
|
175
|
+
body;
|
|
176
|
+
headers;
|
|
177
|
+
stepType = "Call";
|
|
178
|
+
retries;
|
|
179
|
+
constructor(stepName, url, method, body, headers, retries) {
|
|
180
|
+
super(stepName);
|
|
181
|
+
this.url = url;
|
|
182
|
+
this.method = method;
|
|
183
|
+
this.body = body;
|
|
184
|
+
this.headers = headers;
|
|
185
|
+
this.retries = retries;
|
|
186
|
+
}
|
|
187
|
+
getPlanStep(concurrent, targetStep) {
|
|
188
|
+
return {
|
|
189
|
+
stepId: 0,
|
|
190
|
+
stepName: this.stepName,
|
|
191
|
+
stepType: this.stepType,
|
|
192
|
+
concurrent,
|
|
193
|
+
targetStep
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async getResultStep(concurrent, stepId) {
|
|
197
|
+
return await Promise.resolve({
|
|
198
|
+
stepId,
|
|
199
|
+
stepName: this.stepName,
|
|
200
|
+
stepType: this.stepType,
|
|
201
|
+
concurrent,
|
|
202
|
+
callUrl: this.url,
|
|
203
|
+
callMethod: this.method,
|
|
204
|
+
callBody: this.body,
|
|
205
|
+
callHeaders: this.headers
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
210
|
+
eventId;
|
|
211
|
+
timeout;
|
|
212
|
+
stepType = "Wait";
|
|
213
|
+
constructor(stepName, eventId, timeout) {
|
|
214
|
+
super(stepName);
|
|
215
|
+
this.eventId = eventId;
|
|
216
|
+
this.timeout = timeout;
|
|
217
|
+
}
|
|
218
|
+
getPlanStep(concurrent, targetStep) {
|
|
219
|
+
return {
|
|
220
|
+
stepId: 0,
|
|
221
|
+
stepName: this.stepName,
|
|
222
|
+
stepType: this.stepType,
|
|
223
|
+
waitEventId: this.eventId,
|
|
224
|
+
timeout: this.timeout,
|
|
225
|
+
concurrent,
|
|
226
|
+
targetStep
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
async getResultStep(concurrent, stepId) {
|
|
230
|
+
return await Promise.resolve({
|
|
231
|
+
stepId,
|
|
232
|
+
stepName: this.stepName,
|
|
233
|
+
stepType: this.stepType,
|
|
234
|
+
waitEventId: this.eventId,
|
|
235
|
+
timeout: this.timeout,
|
|
236
|
+
concurrent
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
241
|
+
stepType = "Notify";
|
|
242
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
243
|
+
super(stepName, async () => {
|
|
244
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
245
|
+
return {
|
|
246
|
+
eventId,
|
|
247
|
+
eventData,
|
|
248
|
+
notifyResponse
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
63
254
|
// node_modules/neverthrow/dist/index.es.js
|
|
64
255
|
var defaultErrorConfig = {
|
|
65
256
|
withStackTrace: false
|
|
@@ -515,10 +706,11 @@ var triggerFirstInvocation = async (workflowContext, retries, debug) => {
|
|
|
515
706
|
url: workflowContext.url
|
|
516
707
|
});
|
|
517
708
|
try {
|
|
518
|
-
|
|
709
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
710
|
+
await workflowContext.qstashClient.publish({
|
|
519
711
|
headers,
|
|
520
712
|
method: "POST",
|
|
521
|
-
body
|
|
713
|
+
body,
|
|
522
714
|
url: workflowContext.url
|
|
523
715
|
});
|
|
524
716
|
return ok("success");
|
|
@@ -644,7 +836,7 @@ ${atob(callbackMessage.body)}`
|
|
|
644
836
|
);
|
|
645
837
|
}
|
|
646
838
|
};
|
|
647
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries) => {
|
|
839
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries) => {
|
|
648
840
|
const baseHeaders = {
|
|
649
841
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
650
842
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -660,7 +852,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
660
852
|
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
661
853
|
}
|
|
662
854
|
if (step?.callUrl) {
|
|
663
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
855
|
+
baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
|
|
664
856
|
baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete";
|
|
665
857
|
if (retries) {
|
|
666
858
|
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
@@ -668,6 +860,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
668
860
|
}
|
|
669
861
|
} else if (retries !== void 0) {
|
|
670
862
|
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
863
|
+
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
671
864
|
}
|
|
672
865
|
if (userHeaders) {
|
|
673
866
|
for (const header of userHeaders.keys()) {
|
|
@@ -676,6 +869,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
676
869
|
} else {
|
|
677
870
|
baseHeaders[`Upstash-Forward-${header}`] = userHeaders.get(header);
|
|
678
871
|
}
|
|
872
|
+
baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
|
|
679
873
|
}
|
|
680
874
|
}
|
|
681
875
|
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
@@ -859,7 +1053,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
859
1053
|
step: resultStep,
|
|
860
1054
|
stepCount: this.stepCount
|
|
861
1055
|
});
|
|
862
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1056
|
+
await this.submitStepsToQStash([resultStep], [lazyStep]);
|
|
863
1057
|
return resultStep.out;
|
|
864
1058
|
}
|
|
865
1059
|
/**
|
|
@@ -891,7 +1085,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
891
1085
|
const planSteps = parallelSteps.map(
|
|
892
1086
|
(parallelStep, index) => parallelStep.getPlanStep(parallelSteps.length, initialStepCount + index)
|
|
893
1087
|
);
|
|
894
|
-
await this.submitStepsToQStash(planSteps);
|
|
1088
|
+
await this.submitStepsToQStash(planSteps, parallelSteps);
|
|
895
1089
|
break;
|
|
896
1090
|
}
|
|
897
1091
|
case "partial": {
|
|
@@ -904,11 +1098,12 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
904
1098
|
const stepIndex = planStep.targetStep - initialStepCount;
|
|
905
1099
|
validateStep(parallelSteps[stepIndex], planStep);
|
|
906
1100
|
try {
|
|
907
|
-
const
|
|
1101
|
+
const parallelStep = parallelSteps[stepIndex];
|
|
1102
|
+
const resultStep = await parallelStep.getResultStep(
|
|
908
1103
|
parallelSteps.length,
|
|
909
1104
|
planStep.targetStep
|
|
910
1105
|
);
|
|
911
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1106
|
+
await this.submitStepsToQStash([resultStep], [parallelStep]);
|
|
912
1107
|
} catch (error) {
|
|
913
1108
|
if (error instanceof QStashWorkflowAbort) {
|
|
914
1109
|
throw error;
|
|
@@ -969,7 +1164,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
969
1164
|
*
|
|
970
1165
|
* @param steps steps to send
|
|
971
1166
|
*/
|
|
972
|
-
async submitStepsToQStash(steps) {
|
|
1167
|
+
async submitStepsToQStash(steps, lazySteps) {
|
|
973
1168
|
if (steps.length === 0) {
|
|
974
1169
|
throw new QStashWorkflowError(
|
|
975
1170
|
`Unable to submit steps to QStash. Provided list is empty. Current step: ${this.stepCount}`
|
|
@@ -1014,7 +1209,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1014
1209
|
throw new QStashWorkflowAbort(steps[0].stepName, steps[0]);
|
|
1015
1210
|
}
|
|
1016
1211
|
const result = await this.context.qstashClient.batchJSON(
|
|
1017
|
-
steps.map((singleStep) => {
|
|
1212
|
+
steps.map((singleStep, index) => {
|
|
1213
|
+
const lazyStep = lazySteps[index];
|
|
1018
1214
|
const { headers } = getHeaders(
|
|
1019
1215
|
"false",
|
|
1020
1216
|
this.context.workflowRunId,
|
|
@@ -1022,7 +1218,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1022
1218
|
this.context.headers,
|
|
1023
1219
|
singleStep,
|
|
1024
1220
|
this.context.failureUrl,
|
|
1025
|
-
this.context.retries
|
|
1221
|
+
this.context.retries,
|
|
1222
|
+
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0
|
|
1026
1223
|
);
|
|
1027
1224
|
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
1028
1225
|
singleStep.out = JSON.stringify(singleStep.out);
|
|
@@ -1135,195 +1332,6 @@ var sortSteps = (steps) => {
|
|
|
1135
1332
|
return [...steps].sort((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1136
1333
|
};
|
|
1137
1334
|
|
|
1138
|
-
// src/client/utils.ts
|
|
1139
|
-
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1140
|
-
const result = await requester.request({
|
|
1141
|
-
path: ["v2", "notify", eventId],
|
|
1142
|
-
method: "POST",
|
|
1143
|
-
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1144
|
-
});
|
|
1145
|
-
return result;
|
|
1146
|
-
};
|
|
1147
|
-
var makeGetWaitersRequest = async (requester, eventId) => {
|
|
1148
|
-
const result = await requester.request({
|
|
1149
|
-
path: ["v2", "waiters", eventId],
|
|
1150
|
-
method: "GET"
|
|
1151
|
-
});
|
|
1152
|
-
return result;
|
|
1153
|
-
};
|
|
1154
|
-
|
|
1155
|
-
// src/context/steps.ts
|
|
1156
|
-
var BaseLazyStep = class {
|
|
1157
|
-
stepName;
|
|
1158
|
-
// will be set in the subclasses
|
|
1159
|
-
constructor(stepName) {
|
|
1160
|
-
this.stepName = stepName;
|
|
1161
|
-
}
|
|
1162
|
-
};
|
|
1163
|
-
var LazyFunctionStep = class extends BaseLazyStep {
|
|
1164
|
-
stepFunction;
|
|
1165
|
-
stepType = "Run";
|
|
1166
|
-
constructor(stepName, stepFunction) {
|
|
1167
|
-
super(stepName);
|
|
1168
|
-
this.stepFunction = stepFunction;
|
|
1169
|
-
}
|
|
1170
|
-
getPlanStep(concurrent, targetStep) {
|
|
1171
|
-
return {
|
|
1172
|
-
stepId: 0,
|
|
1173
|
-
stepName: this.stepName,
|
|
1174
|
-
stepType: this.stepType,
|
|
1175
|
-
concurrent,
|
|
1176
|
-
targetStep
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
async getResultStep(concurrent, stepId) {
|
|
1180
|
-
let result = this.stepFunction();
|
|
1181
|
-
if (result instanceof Promise) {
|
|
1182
|
-
result = await result;
|
|
1183
|
-
}
|
|
1184
|
-
return {
|
|
1185
|
-
stepId,
|
|
1186
|
-
stepName: this.stepName,
|
|
1187
|
-
stepType: this.stepType,
|
|
1188
|
-
out: result,
|
|
1189
|
-
concurrent
|
|
1190
|
-
};
|
|
1191
|
-
}
|
|
1192
|
-
};
|
|
1193
|
-
var LazySleepStep = class extends BaseLazyStep {
|
|
1194
|
-
sleep;
|
|
1195
|
-
stepType = "SleepFor";
|
|
1196
|
-
constructor(stepName, sleep) {
|
|
1197
|
-
super(stepName);
|
|
1198
|
-
this.sleep = sleep;
|
|
1199
|
-
}
|
|
1200
|
-
getPlanStep(concurrent, targetStep) {
|
|
1201
|
-
return {
|
|
1202
|
-
stepId: 0,
|
|
1203
|
-
stepName: this.stepName,
|
|
1204
|
-
stepType: this.stepType,
|
|
1205
|
-
sleepFor: this.sleep,
|
|
1206
|
-
concurrent,
|
|
1207
|
-
targetStep
|
|
1208
|
-
};
|
|
1209
|
-
}
|
|
1210
|
-
async getResultStep(concurrent, stepId) {
|
|
1211
|
-
return await Promise.resolve({
|
|
1212
|
-
stepId,
|
|
1213
|
-
stepName: this.stepName,
|
|
1214
|
-
stepType: this.stepType,
|
|
1215
|
-
sleepFor: this.sleep,
|
|
1216
|
-
concurrent
|
|
1217
|
-
});
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
1220
|
-
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1221
|
-
sleepUntil;
|
|
1222
|
-
stepType = "SleepUntil";
|
|
1223
|
-
constructor(stepName, sleepUntil) {
|
|
1224
|
-
super(stepName);
|
|
1225
|
-
this.sleepUntil = sleepUntil;
|
|
1226
|
-
}
|
|
1227
|
-
getPlanStep(concurrent, targetStep) {
|
|
1228
|
-
return {
|
|
1229
|
-
stepId: 0,
|
|
1230
|
-
stepName: this.stepName,
|
|
1231
|
-
stepType: this.stepType,
|
|
1232
|
-
sleepUntil: this.sleepUntil,
|
|
1233
|
-
concurrent,
|
|
1234
|
-
targetStep
|
|
1235
|
-
};
|
|
1236
|
-
}
|
|
1237
|
-
async getResultStep(concurrent, stepId) {
|
|
1238
|
-
return await Promise.resolve({
|
|
1239
|
-
stepId,
|
|
1240
|
-
stepName: this.stepName,
|
|
1241
|
-
stepType: this.stepType,
|
|
1242
|
-
sleepUntil: this.sleepUntil,
|
|
1243
|
-
concurrent
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
};
|
|
1247
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
1248
|
-
url;
|
|
1249
|
-
method;
|
|
1250
|
-
body;
|
|
1251
|
-
headers;
|
|
1252
|
-
stepType = "Call";
|
|
1253
|
-
constructor(stepName, url, method, body, headers) {
|
|
1254
|
-
super(stepName);
|
|
1255
|
-
this.url = url;
|
|
1256
|
-
this.method = method;
|
|
1257
|
-
this.body = body;
|
|
1258
|
-
this.headers = headers;
|
|
1259
|
-
}
|
|
1260
|
-
getPlanStep(concurrent, targetStep) {
|
|
1261
|
-
return {
|
|
1262
|
-
stepId: 0,
|
|
1263
|
-
stepName: this.stepName,
|
|
1264
|
-
stepType: this.stepType,
|
|
1265
|
-
concurrent,
|
|
1266
|
-
targetStep
|
|
1267
|
-
};
|
|
1268
|
-
}
|
|
1269
|
-
async getResultStep(concurrent, stepId) {
|
|
1270
|
-
return await Promise.resolve({
|
|
1271
|
-
stepId,
|
|
1272
|
-
stepName: this.stepName,
|
|
1273
|
-
stepType: this.stepType,
|
|
1274
|
-
concurrent,
|
|
1275
|
-
callUrl: this.url,
|
|
1276
|
-
callMethod: this.method,
|
|
1277
|
-
callBody: this.body,
|
|
1278
|
-
callHeaders: this.headers
|
|
1279
|
-
});
|
|
1280
|
-
}
|
|
1281
|
-
};
|
|
1282
|
-
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1283
|
-
eventId;
|
|
1284
|
-
timeout;
|
|
1285
|
-
stepType = "Wait";
|
|
1286
|
-
constructor(stepName, eventId, timeout) {
|
|
1287
|
-
super(stepName);
|
|
1288
|
-
this.eventId = eventId;
|
|
1289
|
-
this.timeout = timeout;
|
|
1290
|
-
}
|
|
1291
|
-
getPlanStep(concurrent, targetStep) {
|
|
1292
|
-
return {
|
|
1293
|
-
stepId: 0,
|
|
1294
|
-
stepName: this.stepName,
|
|
1295
|
-
stepType: this.stepType,
|
|
1296
|
-
waitEventId: this.eventId,
|
|
1297
|
-
timeout: this.timeout,
|
|
1298
|
-
concurrent,
|
|
1299
|
-
targetStep
|
|
1300
|
-
};
|
|
1301
|
-
}
|
|
1302
|
-
async getResultStep(concurrent, stepId) {
|
|
1303
|
-
return await Promise.resolve({
|
|
1304
|
-
stepId,
|
|
1305
|
-
stepName: this.stepName,
|
|
1306
|
-
stepType: this.stepType,
|
|
1307
|
-
waitEventId: this.eventId,
|
|
1308
|
-
timeout: this.timeout,
|
|
1309
|
-
concurrent
|
|
1310
|
-
});
|
|
1311
|
-
}
|
|
1312
|
-
};
|
|
1313
|
-
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1314
|
-
stepType = "Notify";
|
|
1315
|
-
constructor(stepName, eventId, eventData, requester) {
|
|
1316
|
-
super(stepName, async () => {
|
|
1317
|
-
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1318
|
-
return {
|
|
1319
|
-
eventId,
|
|
1320
|
-
eventData,
|
|
1321
|
-
notifyResponse
|
|
1322
|
-
};
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
};
|
|
1326
|
-
|
|
1327
1335
|
// src/context/context.ts
|
|
1328
1336
|
var WorkflowContext = class {
|
|
1329
1337
|
executor;
|
|
@@ -1539,11 +1547,13 @@ var WorkflowContext = class {
|
|
|
1539
1547
|
* network call without consuming any runtime.
|
|
1540
1548
|
*
|
|
1541
1549
|
* ```ts
|
|
1542
|
-
* const
|
|
1550
|
+
* const { status, body } = await context.call<string>(
|
|
1543
1551
|
* "post call step",
|
|
1544
|
-
*
|
|
1545
|
-
*
|
|
1546
|
-
*
|
|
1552
|
+
* {
|
|
1553
|
+
* url: `https://www.some-endpoint.com/api`,
|
|
1554
|
+
* method: "POST",
|
|
1555
|
+
* body: "my-payload"
|
|
1556
|
+
* }
|
|
1547
1557
|
* );
|
|
1548
1558
|
* ```
|
|
1549
1559
|
*
|
|
@@ -1553,9 +1563,10 @@ var WorkflowContext = class {
|
|
|
1553
1563
|
*
|
|
1554
1564
|
* @param stepName
|
|
1555
1565
|
* @param url url to call
|
|
1556
|
-
* @param method call method
|
|
1566
|
+
* @param method call method. "GET" by default.
|
|
1557
1567
|
* @param body call body
|
|
1558
1568
|
* @param headers call headers
|
|
1569
|
+
* @param retries number of call retries. 0 by default
|
|
1559
1570
|
* @returns call result as {
|
|
1560
1571
|
* status: number;
|
|
1561
1572
|
* body: unknown;
|
|
@@ -1563,9 +1574,9 @@ var WorkflowContext = class {
|
|
|
1563
1574
|
* }
|
|
1564
1575
|
*/
|
|
1565
1576
|
async call(stepName, settings) {
|
|
1566
|
-
const { url, method = "GET", body, headers = {} } = settings;
|
|
1577
|
+
const { url, method = "GET", body, headers = {}, retries = 0 } = settings;
|
|
1567
1578
|
const result = await this.addStep(
|
|
1568
|
-
new LazyCallStep(stepName, url, method, body, headers
|
|
1579
|
+
new LazyCallStep(stepName, url, method, body, headers, retries)
|
|
1569
1580
|
);
|
|
1570
1581
|
if (typeof result === "string") {
|
|
1571
1582
|
try {
|
|
@@ -1712,12 +1723,15 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
1712
1723
|
};
|
|
1713
1724
|
|
|
1714
1725
|
// src/utils.ts
|
|
1715
|
-
import crypto from "crypto";
|
|
1726
|
+
import crypto from "node:crypto";
|
|
1716
1727
|
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
1717
1728
|
var NANOID_LENGTH = 21;
|
|
1718
1729
|
function nanoid() {
|
|
1719
1730
|
return [...crypto.getRandomValues(new Uint8Array(NANOID_LENGTH))].map((x) => NANOID_CHARS[x % NANOID_CHARS.length]).join("");
|
|
1720
1731
|
}
|
|
1732
|
+
function getWorkflowRunId(id) {
|
|
1733
|
+
return `wfr_${id ?? nanoid()}`;
|
|
1734
|
+
}
|
|
1721
1735
|
function decodeBase64(base64) {
|
|
1722
1736
|
try {
|
|
1723
1737
|
const binString = atob(base64);
|
|
@@ -1822,7 +1836,7 @@ var validateRequest = (request) => {
|
|
|
1822
1836
|
`Incompatible workflow sdk protocol version. Expected ${WORKFLOW_PROTOCOL_VERSION}, got ${versionHeader} from the request.`
|
|
1823
1837
|
);
|
|
1824
1838
|
}
|
|
1825
|
-
const workflowRunId = isFirstInvocation ?
|
|
1839
|
+
const workflowRunId = isFirstInvocation ? getWorkflowRunId() : request.headers.get(WORKFLOW_ID_HEADER) ?? "";
|
|
1826
1840
|
if (workflowRunId.length === 0) {
|
|
1827
1841
|
throw new QStashWorkflowError("Couldn't get workflow id from header");
|
|
1828
1842
|
}
|
|
@@ -2192,6 +2206,58 @@ var Client3 = class {
|
|
|
2192
2206
|
async getWaiters({ eventId }) {
|
|
2193
2207
|
return await makeGetWaitersRequest(this.client.http, eventId);
|
|
2194
2208
|
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Trigger new workflow run and returns the workflow run id
|
|
2211
|
+
*
|
|
2212
|
+
* ```ts
|
|
2213
|
+
* const { workflowRunId } await client.trigger({
|
|
2214
|
+
* url: "https://workflow-endpoint.com",
|
|
2215
|
+
* body: "hello there!", // optional body
|
|
2216
|
+
* headers: { ... }, // optional headers
|
|
2217
|
+
* workflowRunId: "my-workflow", // optional workflow run id
|
|
2218
|
+
* retries: 3 // optional retries in the initial request
|
|
2219
|
+
* })
|
|
2220
|
+
*
|
|
2221
|
+
* console.log(workflowRunId)
|
|
2222
|
+
* // wfr_my-workflow
|
|
2223
|
+
* ```
|
|
2224
|
+
*
|
|
2225
|
+
* @param url URL of the workflow
|
|
2226
|
+
* @param body body to start the workflow with
|
|
2227
|
+
* @param headers headers to use in the request
|
|
2228
|
+
* @param workflowRunId optional workflow run id to use. mind that
|
|
2229
|
+
* you should pass different workflow run ids for different runs.
|
|
2230
|
+
* The final workflowRunId will be `wfr_${workflowRunId}`, in
|
|
2231
|
+
* other words: the workflow run id you pass will be prefixed
|
|
2232
|
+
* with `wfr_`.
|
|
2233
|
+
* @param retries retry to use in the initial request. in the rest of
|
|
2234
|
+
* the workflow, `retries` option of the `serve` will be used.
|
|
2235
|
+
* @returns workflow run id
|
|
2236
|
+
*/
|
|
2237
|
+
async trigger({
|
|
2238
|
+
url,
|
|
2239
|
+
body,
|
|
2240
|
+
headers,
|
|
2241
|
+
workflowRunId,
|
|
2242
|
+
retries
|
|
2243
|
+
}) {
|
|
2244
|
+
const finalWorkflowRunId = getWorkflowRunId(workflowRunId);
|
|
2245
|
+
const context = new WorkflowContext({
|
|
2246
|
+
qstashClient: this.client,
|
|
2247
|
+
// @ts-expect-error headers type mismatch
|
|
2248
|
+
headers: new Headers(headers ?? {}),
|
|
2249
|
+
initialPayload: body,
|
|
2250
|
+
steps: [],
|
|
2251
|
+
url,
|
|
2252
|
+
workflowRunId: finalWorkflowRunId
|
|
2253
|
+
});
|
|
2254
|
+
const result = await triggerFirstInvocation(context, retries ?? DEFAULT_RETRIES);
|
|
2255
|
+
if (result.isOk()) {
|
|
2256
|
+
return { workflowRunId: finalWorkflowRunId };
|
|
2257
|
+
} else {
|
|
2258
|
+
throw result.error;
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2195
2261
|
};
|
|
2196
2262
|
|
|
2197
2263
|
export {
|
package/cloudflare.d.mts
CHANGED
package/cloudflare.d.ts
CHANGED