@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/index.js
CHANGED
|
@@ -70,6 +70,197 @@ var formatWorkflowError = (error) => {
|
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
// src/client/utils.ts
|
|
74
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
75
|
+
const result = await requester.request({
|
|
76
|
+
path: ["v2", "notify", eventId],
|
|
77
|
+
method: "POST",
|
|
78
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
79
|
+
});
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
var makeGetWaitersRequest = async (requester, eventId) => {
|
|
83
|
+
const result = await requester.request({
|
|
84
|
+
path: ["v2", "waiters", eventId],
|
|
85
|
+
method: "GET"
|
|
86
|
+
});
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/context/steps.ts
|
|
91
|
+
var BaseLazyStep = class {
|
|
92
|
+
stepName;
|
|
93
|
+
// will be set in the subclasses
|
|
94
|
+
constructor(stepName) {
|
|
95
|
+
this.stepName = stepName;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var LazyFunctionStep = class extends BaseLazyStep {
|
|
99
|
+
stepFunction;
|
|
100
|
+
stepType = "Run";
|
|
101
|
+
constructor(stepName, stepFunction) {
|
|
102
|
+
super(stepName);
|
|
103
|
+
this.stepFunction = stepFunction;
|
|
104
|
+
}
|
|
105
|
+
getPlanStep(concurrent, targetStep) {
|
|
106
|
+
return {
|
|
107
|
+
stepId: 0,
|
|
108
|
+
stepName: this.stepName,
|
|
109
|
+
stepType: this.stepType,
|
|
110
|
+
concurrent,
|
|
111
|
+
targetStep
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async getResultStep(concurrent, stepId) {
|
|
115
|
+
let result = this.stepFunction();
|
|
116
|
+
if (result instanceof Promise) {
|
|
117
|
+
result = await result;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
stepId,
|
|
121
|
+
stepName: this.stepName,
|
|
122
|
+
stepType: this.stepType,
|
|
123
|
+
out: result,
|
|
124
|
+
concurrent
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var LazySleepStep = class extends BaseLazyStep {
|
|
129
|
+
sleep;
|
|
130
|
+
stepType = "SleepFor";
|
|
131
|
+
constructor(stepName, sleep) {
|
|
132
|
+
super(stepName);
|
|
133
|
+
this.sleep = sleep;
|
|
134
|
+
}
|
|
135
|
+
getPlanStep(concurrent, targetStep) {
|
|
136
|
+
return {
|
|
137
|
+
stepId: 0,
|
|
138
|
+
stepName: this.stepName,
|
|
139
|
+
stepType: this.stepType,
|
|
140
|
+
sleepFor: this.sleep,
|
|
141
|
+
concurrent,
|
|
142
|
+
targetStep
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async getResultStep(concurrent, stepId) {
|
|
146
|
+
return await Promise.resolve({
|
|
147
|
+
stepId,
|
|
148
|
+
stepName: this.stepName,
|
|
149
|
+
stepType: this.stepType,
|
|
150
|
+
sleepFor: this.sleep,
|
|
151
|
+
concurrent
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
156
|
+
sleepUntil;
|
|
157
|
+
stepType = "SleepUntil";
|
|
158
|
+
constructor(stepName, sleepUntil) {
|
|
159
|
+
super(stepName);
|
|
160
|
+
this.sleepUntil = sleepUntil;
|
|
161
|
+
}
|
|
162
|
+
getPlanStep(concurrent, targetStep) {
|
|
163
|
+
return {
|
|
164
|
+
stepId: 0,
|
|
165
|
+
stepName: this.stepName,
|
|
166
|
+
stepType: this.stepType,
|
|
167
|
+
sleepUntil: this.sleepUntil,
|
|
168
|
+
concurrent,
|
|
169
|
+
targetStep
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async getResultStep(concurrent, stepId) {
|
|
173
|
+
return await Promise.resolve({
|
|
174
|
+
stepId,
|
|
175
|
+
stepName: this.stepName,
|
|
176
|
+
stepType: this.stepType,
|
|
177
|
+
sleepUntil: this.sleepUntil,
|
|
178
|
+
concurrent
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
var LazyCallStep = class extends BaseLazyStep {
|
|
183
|
+
url;
|
|
184
|
+
method;
|
|
185
|
+
body;
|
|
186
|
+
headers;
|
|
187
|
+
stepType = "Call";
|
|
188
|
+
retries;
|
|
189
|
+
constructor(stepName, url, method, body, headers, retries) {
|
|
190
|
+
super(stepName);
|
|
191
|
+
this.url = url;
|
|
192
|
+
this.method = method;
|
|
193
|
+
this.body = body;
|
|
194
|
+
this.headers = headers;
|
|
195
|
+
this.retries = retries;
|
|
196
|
+
}
|
|
197
|
+
getPlanStep(concurrent, targetStep) {
|
|
198
|
+
return {
|
|
199
|
+
stepId: 0,
|
|
200
|
+
stepName: this.stepName,
|
|
201
|
+
stepType: this.stepType,
|
|
202
|
+
concurrent,
|
|
203
|
+
targetStep
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async getResultStep(concurrent, stepId) {
|
|
207
|
+
return await Promise.resolve({
|
|
208
|
+
stepId,
|
|
209
|
+
stepName: this.stepName,
|
|
210
|
+
stepType: this.stepType,
|
|
211
|
+
concurrent,
|
|
212
|
+
callUrl: this.url,
|
|
213
|
+
callMethod: this.method,
|
|
214
|
+
callBody: this.body,
|
|
215
|
+
callHeaders: this.headers
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
220
|
+
eventId;
|
|
221
|
+
timeout;
|
|
222
|
+
stepType = "Wait";
|
|
223
|
+
constructor(stepName, eventId, timeout) {
|
|
224
|
+
super(stepName);
|
|
225
|
+
this.eventId = eventId;
|
|
226
|
+
this.timeout = timeout;
|
|
227
|
+
}
|
|
228
|
+
getPlanStep(concurrent, targetStep) {
|
|
229
|
+
return {
|
|
230
|
+
stepId: 0,
|
|
231
|
+
stepName: this.stepName,
|
|
232
|
+
stepType: this.stepType,
|
|
233
|
+
waitEventId: this.eventId,
|
|
234
|
+
timeout: this.timeout,
|
|
235
|
+
concurrent,
|
|
236
|
+
targetStep
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
async getResultStep(concurrent, stepId) {
|
|
240
|
+
return await Promise.resolve({
|
|
241
|
+
stepId,
|
|
242
|
+
stepName: this.stepName,
|
|
243
|
+
stepType: this.stepType,
|
|
244
|
+
waitEventId: this.eventId,
|
|
245
|
+
timeout: this.timeout,
|
|
246
|
+
concurrent
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
251
|
+
stepType = "Notify";
|
|
252
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
253
|
+
super(stepName, async () => {
|
|
254
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
255
|
+
return {
|
|
256
|
+
eventId,
|
|
257
|
+
eventData,
|
|
258
|
+
notifyResponse
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
73
264
|
// node_modules/neverthrow/dist/index.es.js
|
|
74
265
|
var defaultErrorConfig = {
|
|
75
266
|
withStackTrace: false
|
|
@@ -525,10 +716,11 @@ var triggerFirstInvocation = async (workflowContext, retries, debug) => {
|
|
|
525
716
|
url: workflowContext.url
|
|
526
717
|
});
|
|
527
718
|
try {
|
|
528
|
-
|
|
719
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
720
|
+
await workflowContext.qstashClient.publish({
|
|
529
721
|
headers,
|
|
530
722
|
method: "POST",
|
|
531
|
-
body
|
|
723
|
+
body,
|
|
532
724
|
url: workflowContext.url
|
|
533
725
|
});
|
|
534
726
|
return ok("success");
|
|
@@ -654,7 +846,7 @@ ${atob(callbackMessage.body)}`
|
|
|
654
846
|
);
|
|
655
847
|
}
|
|
656
848
|
};
|
|
657
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries) => {
|
|
849
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries) => {
|
|
658
850
|
const baseHeaders = {
|
|
659
851
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
660
852
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -670,7 +862,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
670
862
|
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
671
863
|
}
|
|
672
864
|
if (step?.callUrl) {
|
|
673
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
865
|
+
baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
|
|
674
866
|
baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete";
|
|
675
867
|
if (retries) {
|
|
676
868
|
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
@@ -678,6 +870,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
678
870
|
}
|
|
679
871
|
} else if (retries !== void 0) {
|
|
680
872
|
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
873
|
+
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
681
874
|
}
|
|
682
875
|
if (userHeaders) {
|
|
683
876
|
for (const header of userHeaders.keys()) {
|
|
@@ -686,6 +879,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
686
879
|
} else {
|
|
687
880
|
baseHeaders[`Upstash-Forward-${header}`] = userHeaders.get(header);
|
|
688
881
|
}
|
|
882
|
+
baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
|
|
689
883
|
}
|
|
690
884
|
}
|
|
691
885
|
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
@@ -869,7 +1063,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
869
1063
|
step: resultStep,
|
|
870
1064
|
stepCount: this.stepCount
|
|
871
1065
|
});
|
|
872
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1066
|
+
await this.submitStepsToQStash([resultStep], [lazyStep]);
|
|
873
1067
|
return resultStep.out;
|
|
874
1068
|
}
|
|
875
1069
|
/**
|
|
@@ -901,7 +1095,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
901
1095
|
const planSteps = parallelSteps.map(
|
|
902
1096
|
(parallelStep, index) => parallelStep.getPlanStep(parallelSteps.length, initialStepCount + index)
|
|
903
1097
|
);
|
|
904
|
-
await this.submitStepsToQStash(planSteps);
|
|
1098
|
+
await this.submitStepsToQStash(planSteps, parallelSteps);
|
|
905
1099
|
break;
|
|
906
1100
|
}
|
|
907
1101
|
case "partial": {
|
|
@@ -914,11 +1108,12 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
914
1108
|
const stepIndex = planStep.targetStep - initialStepCount;
|
|
915
1109
|
validateStep(parallelSteps[stepIndex], planStep);
|
|
916
1110
|
try {
|
|
917
|
-
const
|
|
1111
|
+
const parallelStep = parallelSteps[stepIndex];
|
|
1112
|
+
const resultStep = await parallelStep.getResultStep(
|
|
918
1113
|
parallelSteps.length,
|
|
919
1114
|
planStep.targetStep
|
|
920
1115
|
);
|
|
921
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1116
|
+
await this.submitStepsToQStash([resultStep], [parallelStep]);
|
|
922
1117
|
} catch (error) {
|
|
923
1118
|
if (error instanceof QStashWorkflowAbort) {
|
|
924
1119
|
throw error;
|
|
@@ -979,7 +1174,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
979
1174
|
*
|
|
980
1175
|
* @param steps steps to send
|
|
981
1176
|
*/
|
|
982
|
-
async submitStepsToQStash(steps) {
|
|
1177
|
+
async submitStepsToQStash(steps, lazySteps) {
|
|
983
1178
|
if (steps.length === 0) {
|
|
984
1179
|
throw new QStashWorkflowError(
|
|
985
1180
|
`Unable to submit steps to QStash. Provided list is empty. Current step: ${this.stepCount}`
|
|
@@ -1024,7 +1219,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1024
1219
|
throw new QStashWorkflowAbort(steps[0].stepName, steps[0]);
|
|
1025
1220
|
}
|
|
1026
1221
|
const result = await this.context.qstashClient.batchJSON(
|
|
1027
|
-
steps.map((singleStep) => {
|
|
1222
|
+
steps.map((singleStep, index) => {
|
|
1223
|
+
const lazyStep = lazySteps[index];
|
|
1028
1224
|
const { headers } = getHeaders(
|
|
1029
1225
|
"false",
|
|
1030
1226
|
this.context.workflowRunId,
|
|
@@ -1032,7 +1228,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1032
1228
|
this.context.headers,
|
|
1033
1229
|
singleStep,
|
|
1034
1230
|
this.context.failureUrl,
|
|
1035
|
-
this.context.retries
|
|
1231
|
+
this.context.retries,
|
|
1232
|
+
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0
|
|
1036
1233
|
);
|
|
1037
1234
|
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
1038
1235
|
singleStep.out = JSON.stringify(singleStep.out);
|
|
@@ -1145,195 +1342,6 @@ var sortSteps = (steps) => {
|
|
|
1145
1342
|
return [...steps].sort((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1146
1343
|
};
|
|
1147
1344
|
|
|
1148
|
-
// src/client/utils.ts
|
|
1149
|
-
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1150
|
-
const result = await requester.request({
|
|
1151
|
-
path: ["v2", "notify", eventId],
|
|
1152
|
-
method: "POST",
|
|
1153
|
-
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1154
|
-
});
|
|
1155
|
-
return result;
|
|
1156
|
-
};
|
|
1157
|
-
var makeGetWaitersRequest = async (requester, eventId) => {
|
|
1158
|
-
const result = await requester.request({
|
|
1159
|
-
path: ["v2", "waiters", eventId],
|
|
1160
|
-
method: "GET"
|
|
1161
|
-
});
|
|
1162
|
-
return result;
|
|
1163
|
-
};
|
|
1164
|
-
|
|
1165
|
-
// src/context/steps.ts
|
|
1166
|
-
var BaseLazyStep = class {
|
|
1167
|
-
stepName;
|
|
1168
|
-
// will be set in the subclasses
|
|
1169
|
-
constructor(stepName) {
|
|
1170
|
-
this.stepName = stepName;
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
var LazyFunctionStep = class extends BaseLazyStep {
|
|
1174
|
-
stepFunction;
|
|
1175
|
-
stepType = "Run";
|
|
1176
|
-
constructor(stepName, stepFunction) {
|
|
1177
|
-
super(stepName);
|
|
1178
|
-
this.stepFunction = stepFunction;
|
|
1179
|
-
}
|
|
1180
|
-
getPlanStep(concurrent, targetStep) {
|
|
1181
|
-
return {
|
|
1182
|
-
stepId: 0,
|
|
1183
|
-
stepName: this.stepName,
|
|
1184
|
-
stepType: this.stepType,
|
|
1185
|
-
concurrent,
|
|
1186
|
-
targetStep
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
async getResultStep(concurrent, stepId) {
|
|
1190
|
-
let result = this.stepFunction();
|
|
1191
|
-
if (result instanceof Promise) {
|
|
1192
|
-
result = await result;
|
|
1193
|
-
}
|
|
1194
|
-
return {
|
|
1195
|
-
stepId,
|
|
1196
|
-
stepName: this.stepName,
|
|
1197
|
-
stepType: this.stepType,
|
|
1198
|
-
out: result,
|
|
1199
|
-
concurrent
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
};
|
|
1203
|
-
var LazySleepStep = class extends BaseLazyStep {
|
|
1204
|
-
sleep;
|
|
1205
|
-
stepType = "SleepFor";
|
|
1206
|
-
constructor(stepName, sleep) {
|
|
1207
|
-
super(stepName);
|
|
1208
|
-
this.sleep = sleep;
|
|
1209
|
-
}
|
|
1210
|
-
getPlanStep(concurrent, targetStep) {
|
|
1211
|
-
return {
|
|
1212
|
-
stepId: 0,
|
|
1213
|
-
stepName: this.stepName,
|
|
1214
|
-
stepType: this.stepType,
|
|
1215
|
-
sleepFor: this.sleep,
|
|
1216
|
-
concurrent,
|
|
1217
|
-
targetStep
|
|
1218
|
-
};
|
|
1219
|
-
}
|
|
1220
|
-
async getResultStep(concurrent, stepId) {
|
|
1221
|
-
return await Promise.resolve({
|
|
1222
|
-
stepId,
|
|
1223
|
-
stepName: this.stepName,
|
|
1224
|
-
stepType: this.stepType,
|
|
1225
|
-
sleepFor: this.sleep,
|
|
1226
|
-
concurrent
|
|
1227
|
-
});
|
|
1228
|
-
}
|
|
1229
|
-
};
|
|
1230
|
-
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1231
|
-
sleepUntil;
|
|
1232
|
-
stepType = "SleepUntil";
|
|
1233
|
-
constructor(stepName, sleepUntil) {
|
|
1234
|
-
super(stepName);
|
|
1235
|
-
this.sleepUntil = sleepUntil;
|
|
1236
|
-
}
|
|
1237
|
-
getPlanStep(concurrent, targetStep) {
|
|
1238
|
-
return {
|
|
1239
|
-
stepId: 0,
|
|
1240
|
-
stepName: this.stepName,
|
|
1241
|
-
stepType: this.stepType,
|
|
1242
|
-
sleepUntil: this.sleepUntil,
|
|
1243
|
-
concurrent,
|
|
1244
|
-
targetStep
|
|
1245
|
-
};
|
|
1246
|
-
}
|
|
1247
|
-
async getResultStep(concurrent, stepId) {
|
|
1248
|
-
return await Promise.resolve({
|
|
1249
|
-
stepId,
|
|
1250
|
-
stepName: this.stepName,
|
|
1251
|
-
stepType: this.stepType,
|
|
1252
|
-
sleepUntil: this.sleepUntil,
|
|
1253
|
-
concurrent
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
|
-
};
|
|
1257
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
1258
|
-
url;
|
|
1259
|
-
method;
|
|
1260
|
-
body;
|
|
1261
|
-
headers;
|
|
1262
|
-
stepType = "Call";
|
|
1263
|
-
constructor(stepName, url, method, body, headers) {
|
|
1264
|
-
super(stepName);
|
|
1265
|
-
this.url = url;
|
|
1266
|
-
this.method = method;
|
|
1267
|
-
this.body = body;
|
|
1268
|
-
this.headers = headers;
|
|
1269
|
-
}
|
|
1270
|
-
getPlanStep(concurrent, targetStep) {
|
|
1271
|
-
return {
|
|
1272
|
-
stepId: 0,
|
|
1273
|
-
stepName: this.stepName,
|
|
1274
|
-
stepType: this.stepType,
|
|
1275
|
-
concurrent,
|
|
1276
|
-
targetStep
|
|
1277
|
-
};
|
|
1278
|
-
}
|
|
1279
|
-
async getResultStep(concurrent, stepId) {
|
|
1280
|
-
return await Promise.resolve({
|
|
1281
|
-
stepId,
|
|
1282
|
-
stepName: this.stepName,
|
|
1283
|
-
stepType: this.stepType,
|
|
1284
|
-
concurrent,
|
|
1285
|
-
callUrl: this.url,
|
|
1286
|
-
callMethod: this.method,
|
|
1287
|
-
callBody: this.body,
|
|
1288
|
-
callHeaders: this.headers
|
|
1289
|
-
});
|
|
1290
|
-
}
|
|
1291
|
-
};
|
|
1292
|
-
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1293
|
-
eventId;
|
|
1294
|
-
timeout;
|
|
1295
|
-
stepType = "Wait";
|
|
1296
|
-
constructor(stepName, eventId, timeout) {
|
|
1297
|
-
super(stepName);
|
|
1298
|
-
this.eventId = eventId;
|
|
1299
|
-
this.timeout = timeout;
|
|
1300
|
-
}
|
|
1301
|
-
getPlanStep(concurrent, targetStep) {
|
|
1302
|
-
return {
|
|
1303
|
-
stepId: 0,
|
|
1304
|
-
stepName: this.stepName,
|
|
1305
|
-
stepType: this.stepType,
|
|
1306
|
-
waitEventId: this.eventId,
|
|
1307
|
-
timeout: this.timeout,
|
|
1308
|
-
concurrent,
|
|
1309
|
-
targetStep
|
|
1310
|
-
};
|
|
1311
|
-
}
|
|
1312
|
-
async getResultStep(concurrent, stepId) {
|
|
1313
|
-
return await Promise.resolve({
|
|
1314
|
-
stepId,
|
|
1315
|
-
stepName: this.stepName,
|
|
1316
|
-
stepType: this.stepType,
|
|
1317
|
-
waitEventId: this.eventId,
|
|
1318
|
-
timeout: this.timeout,
|
|
1319
|
-
concurrent
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
};
|
|
1323
|
-
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1324
|
-
stepType = "Notify";
|
|
1325
|
-
constructor(stepName, eventId, eventData, requester) {
|
|
1326
|
-
super(stepName, async () => {
|
|
1327
|
-
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1328
|
-
return {
|
|
1329
|
-
eventId,
|
|
1330
|
-
eventData,
|
|
1331
|
-
notifyResponse
|
|
1332
|
-
};
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
};
|
|
1336
|
-
|
|
1337
1345
|
// src/context/context.ts
|
|
1338
1346
|
var WorkflowContext = class {
|
|
1339
1347
|
executor;
|
|
@@ -1549,11 +1557,13 @@ var WorkflowContext = class {
|
|
|
1549
1557
|
* network call without consuming any runtime.
|
|
1550
1558
|
*
|
|
1551
1559
|
* ```ts
|
|
1552
|
-
* const
|
|
1560
|
+
* const { status, body } = await context.call<string>(
|
|
1553
1561
|
* "post call step",
|
|
1554
|
-
*
|
|
1555
|
-
*
|
|
1556
|
-
*
|
|
1562
|
+
* {
|
|
1563
|
+
* url: `https://www.some-endpoint.com/api`,
|
|
1564
|
+
* method: "POST",
|
|
1565
|
+
* body: "my-payload"
|
|
1566
|
+
* }
|
|
1557
1567
|
* );
|
|
1558
1568
|
* ```
|
|
1559
1569
|
*
|
|
@@ -1563,9 +1573,10 @@ var WorkflowContext = class {
|
|
|
1563
1573
|
*
|
|
1564
1574
|
* @param stepName
|
|
1565
1575
|
* @param url url to call
|
|
1566
|
-
* @param method call method
|
|
1576
|
+
* @param method call method. "GET" by default.
|
|
1567
1577
|
* @param body call body
|
|
1568
1578
|
* @param headers call headers
|
|
1579
|
+
* @param retries number of call retries. 0 by default
|
|
1569
1580
|
* @returns call result as {
|
|
1570
1581
|
* status: number;
|
|
1571
1582
|
* body: unknown;
|
|
@@ -1573,9 +1584,9 @@ var WorkflowContext = class {
|
|
|
1573
1584
|
* }
|
|
1574
1585
|
*/
|
|
1575
1586
|
async call(stepName, settings) {
|
|
1576
|
-
const { url, method = "GET", body, headers = {} } = settings;
|
|
1587
|
+
const { url, method = "GET", body, headers = {}, retries = 0 } = settings;
|
|
1577
1588
|
const result = await this.addStep(
|
|
1578
|
-
new LazyCallStep(stepName, url, method, body, headers
|
|
1589
|
+
new LazyCallStep(stepName, url, method, body, headers, retries)
|
|
1579
1590
|
);
|
|
1580
1591
|
if (typeof result === "string") {
|
|
1581
1592
|
try {
|
|
@@ -1722,11 +1733,14 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
1722
1733
|
};
|
|
1723
1734
|
|
|
1724
1735
|
// src/utils.ts
|
|
1725
|
-
var
|
|
1736
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
1726
1737
|
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
1727
1738
|
var NANOID_LENGTH = 21;
|
|
1728
1739
|
function nanoid() {
|
|
1729
|
-
return [...
|
|
1740
|
+
return [...import_node_crypto.default.getRandomValues(new Uint8Array(NANOID_LENGTH))].map((x) => NANOID_CHARS[x % NANOID_CHARS.length]).join("");
|
|
1741
|
+
}
|
|
1742
|
+
function getWorkflowRunId(id) {
|
|
1743
|
+
return `wfr_${id ?? nanoid()}`;
|
|
1730
1744
|
}
|
|
1731
1745
|
function decodeBase64(base64) {
|
|
1732
1746
|
try {
|
|
@@ -1832,7 +1846,7 @@ var validateRequest = (request) => {
|
|
|
1832
1846
|
`Incompatible workflow sdk protocol version. Expected ${WORKFLOW_PROTOCOL_VERSION}, got ${versionHeader} from the request.`
|
|
1833
1847
|
);
|
|
1834
1848
|
}
|
|
1835
|
-
const workflowRunId = isFirstInvocation ?
|
|
1849
|
+
const workflowRunId = isFirstInvocation ? getWorkflowRunId() : request.headers.get(WORKFLOW_ID_HEADER) ?? "";
|
|
1836
1850
|
if (workflowRunId.length === 0) {
|
|
1837
1851
|
throw new QStashWorkflowError("Couldn't get workflow id from header");
|
|
1838
1852
|
}
|
|
@@ -2202,6 +2216,58 @@ var Client3 = class {
|
|
|
2202
2216
|
async getWaiters({ eventId }) {
|
|
2203
2217
|
return await makeGetWaitersRequest(this.client.http, eventId);
|
|
2204
2218
|
}
|
|
2219
|
+
/**
|
|
2220
|
+
* Trigger new workflow run and returns the workflow run id
|
|
2221
|
+
*
|
|
2222
|
+
* ```ts
|
|
2223
|
+
* const { workflowRunId } await client.trigger({
|
|
2224
|
+
* url: "https://workflow-endpoint.com",
|
|
2225
|
+
* body: "hello there!", // optional body
|
|
2226
|
+
* headers: { ... }, // optional headers
|
|
2227
|
+
* workflowRunId: "my-workflow", // optional workflow run id
|
|
2228
|
+
* retries: 3 // optional retries in the initial request
|
|
2229
|
+
* })
|
|
2230
|
+
*
|
|
2231
|
+
* console.log(workflowRunId)
|
|
2232
|
+
* // wfr_my-workflow
|
|
2233
|
+
* ```
|
|
2234
|
+
*
|
|
2235
|
+
* @param url URL of the workflow
|
|
2236
|
+
* @param body body to start the workflow with
|
|
2237
|
+
* @param headers headers to use in the request
|
|
2238
|
+
* @param workflowRunId optional workflow run id to use. mind that
|
|
2239
|
+
* you should pass different workflow run ids for different runs.
|
|
2240
|
+
* The final workflowRunId will be `wfr_${workflowRunId}`, in
|
|
2241
|
+
* other words: the workflow run id you pass will be prefixed
|
|
2242
|
+
* with `wfr_`.
|
|
2243
|
+
* @param retries retry to use in the initial request. in the rest of
|
|
2244
|
+
* the workflow, `retries` option of the `serve` will be used.
|
|
2245
|
+
* @returns workflow run id
|
|
2246
|
+
*/
|
|
2247
|
+
async trigger({
|
|
2248
|
+
url,
|
|
2249
|
+
body,
|
|
2250
|
+
headers,
|
|
2251
|
+
workflowRunId,
|
|
2252
|
+
retries
|
|
2253
|
+
}) {
|
|
2254
|
+
const finalWorkflowRunId = getWorkflowRunId(workflowRunId);
|
|
2255
|
+
const context = new WorkflowContext({
|
|
2256
|
+
qstashClient: this.client,
|
|
2257
|
+
// @ts-expect-error headers type mismatch
|
|
2258
|
+
headers: new Headers(headers ?? {}),
|
|
2259
|
+
initialPayload: body,
|
|
2260
|
+
steps: [],
|
|
2261
|
+
url,
|
|
2262
|
+
workflowRunId: finalWorkflowRunId
|
|
2263
|
+
});
|
|
2264
|
+
const result = await triggerFirstInvocation(context, retries ?? DEFAULT_RETRIES);
|
|
2265
|
+
if (result.isOk()) {
|
|
2266
|
+
return { workflowRunId: finalWorkflowRunId };
|
|
2267
|
+
} else {
|
|
2268
|
+
throw result.error;
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2205
2271
|
};
|
|
2206
2272
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2207
2273
|
0 && (module.exports = {
|
package/index.mjs
CHANGED
package/nextjs.d.mts
CHANGED
package/nextjs.d.ts
CHANGED