@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/nextjs.js
CHANGED
|
@@ -65,6 +65,190 @@ var formatWorkflowError = (error) => {
|
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
// src/client/utils.ts
|
|
69
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
70
|
+
const result = await requester.request({
|
|
71
|
+
path: ["v2", "notify", eventId],
|
|
72
|
+
method: "POST",
|
|
73
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
74
|
+
});
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/context/steps.ts
|
|
79
|
+
var BaseLazyStep = class {
|
|
80
|
+
stepName;
|
|
81
|
+
// will be set in the subclasses
|
|
82
|
+
constructor(stepName) {
|
|
83
|
+
this.stepName = stepName;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var LazyFunctionStep = class extends BaseLazyStep {
|
|
87
|
+
stepFunction;
|
|
88
|
+
stepType = "Run";
|
|
89
|
+
constructor(stepName, stepFunction) {
|
|
90
|
+
super(stepName);
|
|
91
|
+
this.stepFunction = stepFunction;
|
|
92
|
+
}
|
|
93
|
+
getPlanStep(concurrent, targetStep) {
|
|
94
|
+
return {
|
|
95
|
+
stepId: 0,
|
|
96
|
+
stepName: this.stepName,
|
|
97
|
+
stepType: this.stepType,
|
|
98
|
+
concurrent,
|
|
99
|
+
targetStep
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async getResultStep(concurrent, stepId) {
|
|
103
|
+
let result = this.stepFunction();
|
|
104
|
+
if (result instanceof Promise) {
|
|
105
|
+
result = await result;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
stepId,
|
|
109
|
+
stepName: this.stepName,
|
|
110
|
+
stepType: this.stepType,
|
|
111
|
+
out: result,
|
|
112
|
+
concurrent
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var LazySleepStep = class extends BaseLazyStep {
|
|
117
|
+
sleep;
|
|
118
|
+
stepType = "SleepFor";
|
|
119
|
+
constructor(stepName, sleep) {
|
|
120
|
+
super(stepName);
|
|
121
|
+
this.sleep = sleep;
|
|
122
|
+
}
|
|
123
|
+
getPlanStep(concurrent, targetStep) {
|
|
124
|
+
return {
|
|
125
|
+
stepId: 0,
|
|
126
|
+
stepName: this.stepName,
|
|
127
|
+
stepType: this.stepType,
|
|
128
|
+
sleepFor: this.sleep,
|
|
129
|
+
concurrent,
|
|
130
|
+
targetStep
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async getResultStep(concurrent, stepId) {
|
|
134
|
+
return await Promise.resolve({
|
|
135
|
+
stepId,
|
|
136
|
+
stepName: this.stepName,
|
|
137
|
+
stepType: this.stepType,
|
|
138
|
+
sleepFor: this.sleep,
|
|
139
|
+
concurrent
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
144
|
+
sleepUntil;
|
|
145
|
+
stepType = "SleepUntil";
|
|
146
|
+
constructor(stepName, sleepUntil) {
|
|
147
|
+
super(stepName);
|
|
148
|
+
this.sleepUntil = sleepUntil;
|
|
149
|
+
}
|
|
150
|
+
getPlanStep(concurrent, targetStep) {
|
|
151
|
+
return {
|
|
152
|
+
stepId: 0,
|
|
153
|
+
stepName: this.stepName,
|
|
154
|
+
stepType: this.stepType,
|
|
155
|
+
sleepUntil: this.sleepUntil,
|
|
156
|
+
concurrent,
|
|
157
|
+
targetStep
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async getResultStep(concurrent, stepId) {
|
|
161
|
+
return await Promise.resolve({
|
|
162
|
+
stepId,
|
|
163
|
+
stepName: this.stepName,
|
|
164
|
+
stepType: this.stepType,
|
|
165
|
+
sleepUntil: this.sleepUntil,
|
|
166
|
+
concurrent
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var LazyCallStep = class extends BaseLazyStep {
|
|
171
|
+
url;
|
|
172
|
+
method;
|
|
173
|
+
body;
|
|
174
|
+
headers;
|
|
175
|
+
stepType = "Call";
|
|
176
|
+
retries;
|
|
177
|
+
constructor(stepName, url, method, body, headers, retries) {
|
|
178
|
+
super(stepName);
|
|
179
|
+
this.url = url;
|
|
180
|
+
this.method = method;
|
|
181
|
+
this.body = body;
|
|
182
|
+
this.headers = headers;
|
|
183
|
+
this.retries = retries;
|
|
184
|
+
}
|
|
185
|
+
getPlanStep(concurrent, targetStep) {
|
|
186
|
+
return {
|
|
187
|
+
stepId: 0,
|
|
188
|
+
stepName: this.stepName,
|
|
189
|
+
stepType: this.stepType,
|
|
190
|
+
concurrent,
|
|
191
|
+
targetStep
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
async getResultStep(concurrent, stepId) {
|
|
195
|
+
return await Promise.resolve({
|
|
196
|
+
stepId,
|
|
197
|
+
stepName: this.stepName,
|
|
198
|
+
stepType: this.stepType,
|
|
199
|
+
concurrent,
|
|
200
|
+
callUrl: this.url,
|
|
201
|
+
callMethod: this.method,
|
|
202
|
+
callBody: this.body,
|
|
203
|
+
callHeaders: this.headers
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
208
|
+
eventId;
|
|
209
|
+
timeout;
|
|
210
|
+
stepType = "Wait";
|
|
211
|
+
constructor(stepName, eventId, timeout) {
|
|
212
|
+
super(stepName);
|
|
213
|
+
this.eventId = eventId;
|
|
214
|
+
this.timeout = timeout;
|
|
215
|
+
}
|
|
216
|
+
getPlanStep(concurrent, targetStep) {
|
|
217
|
+
return {
|
|
218
|
+
stepId: 0,
|
|
219
|
+
stepName: this.stepName,
|
|
220
|
+
stepType: this.stepType,
|
|
221
|
+
waitEventId: this.eventId,
|
|
222
|
+
timeout: this.timeout,
|
|
223
|
+
concurrent,
|
|
224
|
+
targetStep
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
async getResultStep(concurrent, stepId) {
|
|
228
|
+
return await Promise.resolve({
|
|
229
|
+
stepId,
|
|
230
|
+
stepName: this.stepName,
|
|
231
|
+
stepType: this.stepType,
|
|
232
|
+
waitEventId: this.eventId,
|
|
233
|
+
timeout: this.timeout,
|
|
234
|
+
concurrent
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
239
|
+
stepType = "Notify";
|
|
240
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
241
|
+
super(stepName, async () => {
|
|
242
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
243
|
+
return {
|
|
244
|
+
eventId,
|
|
245
|
+
eventData,
|
|
246
|
+
notifyResponse
|
|
247
|
+
};
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
68
252
|
// node_modules/neverthrow/dist/index.es.js
|
|
69
253
|
var defaultErrorConfig = {
|
|
70
254
|
withStackTrace: false
|
|
@@ -520,10 +704,11 @@ var triggerFirstInvocation = async (workflowContext, retries, debug) => {
|
|
|
520
704
|
url: workflowContext.url
|
|
521
705
|
});
|
|
522
706
|
try {
|
|
523
|
-
|
|
707
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
708
|
+
await workflowContext.qstashClient.publish({
|
|
524
709
|
headers,
|
|
525
710
|
method: "POST",
|
|
526
|
-
body
|
|
711
|
+
body,
|
|
527
712
|
url: workflowContext.url
|
|
528
713
|
});
|
|
529
714
|
return ok("success");
|
|
@@ -649,7 +834,7 @@ ${atob(callbackMessage.body)}`
|
|
|
649
834
|
);
|
|
650
835
|
}
|
|
651
836
|
};
|
|
652
|
-
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries) => {
|
|
837
|
+
var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step, failureUrl, retries, callRetries) => {
|
|
653
838
|
const baseHeaders = {
|
|
654
839
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
655
840
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -665,7 +850,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
665
850
|
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
666
851
|
}
|
|
667
852
|
if (step?.callUrl) {
|
|
668
|
-
baseHeaders["Upstash-Retries"] = "0";
|
|
853
|
+
baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
|
|
669
854
|
baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete";
|
|
670
855
|
if (retries) {
|
|
671
856
|
baseHeaders["Upstash-Callback-Retries"] = retries.toString();
|
|
@@ -673,6 +858,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
673
858
|
}
|
|
674
859
|
} else if (retries !== void 0) {
|
|
675
860
|
baseHeaders["Upstash-Retries"] = retries.toString();
|
|
861
|
+
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
676
862
|
}
|
|
677
863
|
if (userHeaders) {
|
|
678
864
|
for (const header of userHeaders.keys()) {
|
|
@@ -681,6 +867,7 @@ var getHeaders = (initHeaderValue, workflowRunId, workflowUrl, userHeaders, step
|
|
|
681
867
|
} else {
|
|
682
868
|
baseHeaders[`Upstash-Forward-${header}`] = userHeaders.get(header);
|
|
683
869
|
}
|
|
870
|
+
baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
|
|
684
871
|
}
|
|
685
872
|
}
|
|
686
873
|
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
@@ -864,7 +1051,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
864
1051
|
step: resultStep,
|
|
865
1052
|
stepCount: this.stepCount
|
|
866
1053
|
});
|
|
867
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1054
|
+
await this.submitStepsToQStash([resultStep], [lazyStep]);
|
|
868
1055
|
return resultStep.out;
|
|
869
1056
|
}
|
|
870
1057
|
/**
|
|
@@ -896,7 +1083,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
896
1083
|
const planSteps = parallelSteps.map(
|
|
897
1084
|
(parallelStep, index) => parallelStep.getPlanStep(parallelSteps.length, initialStepCount + index)
|
|
898
1085
|
);
|
|
899
|
-
await this.submitStepsToQStash(planSteps);
|
|
1086
|
+
await this.submitStepsToQStash(planSteps, parallelSteps);
|
|
900
1087
|
break;
|
|
901
1088
|
}
|
|
902
1089
|
case "partial": {
|
|
@@ -909,11 +1096,12 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
909
1096
|
const stepIndex = planStep.targetStep - initialStepCount;
|
|
910
1097
|
validateStep(parallelSteps[stepIndex], planStep);
|
|
911
1098
|
try {
|
|
912
|
-
const
|
|
1099
|
+
const parallelStep = parallelSteps[stepIndex];
|
|
1100
|
+
const resultStep = await parallelStep.getResultStep(
|
|
913
1101
|
parallelSteps.length,
|
|
914
1102
|
planStep.targetStep
|
|
915
1103
|
);
|
|
916
|
-
await this.submitStepsToQStash([resultStep]);
|
|
1104
|
+
await this.submitStepsToQStash([resultStep], [parallelStep]);
|
|
917
1105
|
} catch (error) {
|
|
918
1106
|
if (error instanceof QStashWorkflowAbort) {
|
|
919
1107
|
throw error;
|
|
@@ -974,7 +1162,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
974
1162
|
*
|
|
975
1163
|
* @param steps steps to send
|
|
976
1164
|
*/
|
|
977
|
-
async submitStepsToQStash(steps) {
|
|
1165
|
+
async submitStepsToQStash(steps, lazySteps) {
|
|
978
1166
|
if (steps.length === 0) {
|
|
979
1167
|
throw new QStashWorkflowError(
|
|
980
1168
|
`Unable to submit steps to QStash. Provided list is empty. Current step: ${this.stepCount}`
|
|
@@ -1019,7 +1207,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1019
1207
|
throw new QStashWorkflowAbort(steps[0].stepName, steps[0]);
|
|
1020
1208
|
}
|
|
1021
1209
|
const result = await this.context.qstashClient.batchJSON(
|
|
1022
|
-
steps.map((singleStep) => {
|
|
1210
|
+
steps.map((singleStep, index) => {
|
|
1211
|
+
const lazyStep = lazySteps[index];
|
|
1023
1212
|
const { headers } = getHeaders(
|
|
1024
1213
|
"false",
|
|
1025
1214
|
this.context.workflowRunId,
|
|
@@ -1027,7 +1216,8 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1027
1216
|
this.context.headers,
|
|
1028
1217
|
singleStep,
|
|
1029
1218
|
this.context.failureUrl,
|
|
1030
|
-
this.context.retries
|
|
1219
|
+
this.context.retries,
|
|
1220
|
+
lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0
|
|
1031
1221
|
);
|
|
1032
1222
|
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
1033
1223
|
singleStep.out = JSON.stringify(singleStep.out);
|
|
@@ -1140,188 +1330,6 @@ var sortSteps = (steps) => {
|
|
|
1140
1330
|
return [...steps].sort((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1141
1331
|
};
|
|
1142
1332
|
|
|
1143
|
-
// src/client/utils.ts
|
|
1144
|
-
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1145
|
-
const result = await requester.request({
|
|
1146
|
-
path: ["v2", "notify", eventId],
|
|
1147
|
-
method: "POST",
|
|
1148
|
-
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1149
|
-
});
|
|
1150
|
-
return result;
|
|
1151
|
-
};
|
|
1152
|
-
|
|
1153
|
-
// src/context/steps.ts
|
|
1154
|
-
var BaseLazyStep = class {
|
|
1155
|
-
stepName;
|
|
1156
|
-
// will be set in the subclasses
|
|
1157
|
-
constructor(stepName) {
|
|
1158
|
-
this.stepName = stepName;
|
|
1159
|
-
}
|
|
1160
|
-
};
|
|
1161
|
-
var LazyFunctionStep = class extends BaseLazyStep {
|
|
1162
|
-
stepFunction;
|
|
1163
|
-
stepType = "Run";
|
|
1164
|
-
constructor(stepName, stepFunction) {
|
|
1165
|
-
super(stepName);
|
|
1166
|
-
this.stepFunction = stepFunction;
|
|
1167
|
-
}
|
|
1168
|
-
getPlanStep(concurrent, targetStep) {
|
|
1169
|
-
return {
|
|
1170
|
-
stepId: 0,
|
|
1171
|
-
stepName: this.stepName,
|
|
1172
|
-
stepType: this.stepType,
|
|
1173
|
-
concurrent,
|
|
1174
|
-
targetStep
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
async getResultStep(concurrent, stepId) {
|
|
1178
|
-
let result = this.stepFunction();
|
|
1179
|
-
if (result instanceof Promise) {
|
|
1180
|
-
result = await result;
|
|
1181
|
-
}
|
|
1182
|
-
return {
|
|
1183
|
-
stepId,
|
|
1184
|
-
stepName: this.stepName,
|
|
1185
|
-
stepType: this.stepType,
|
|
1186
|
-
out: result,
|
|
1187
|
-
concurrent
|
|
1188
|
-
};
|
|
1189
|
-
}
|
|
1190
|
-
};
|
|
1191
|
-
var LazySleepStep = class extends BaseLazyStep {
|
|
1192
|
-
sleep;
|
|
1193
|
-
stepType = "SleepFor";
|
|
1194
|
-
constructor(stepName, sleep) {
|
|
1195
|
-
super(stepName);
|
|
1196
|
-
this.sleep = sleep;
|
|
1197
|
-
}
|
|
1198
|
-
getPlanStep(concurrent, targetStep) {
|
|
1199
|
-
return {
|
|
1200
|
-
stepId: 0,
|
|
1201
|
-
stepName: this.stepName,
|
|
1202
|
-
stepType: this.stepType,
|
|
1203
|
-
sleepFor: this.sleep,
|
|
1204
|
-
concurrent,
|
|
1205
|
-
targetStep
|
|
1206
|
-
};
|
|
1207
|
-
}
|
|
1208
|
-
async getResultStep(concurrent, stepId) {
|
|
1209
|
-
return await Promise.resolve({
|
|
1210
|
-
stepId,
|
|
1211
|
-
stepName: this.stepName,
|
|
1212
|
-
stepType: this.stepType,
|
|
1213
|
-
sleepFor: this.sleep,
|
|
1214
|
-
concurrent
|
|
1215
|
-
});
|
|
1216
|
-
}
|
|
1217
|
-
};
|
|
1218
|
-
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1219
|
-
sleepUntil;
|
|
1220
|
-
stepType = "SleepUntil";
|
|
1221
|
-
constructor(stepName, sleepUntil) {
|
|
1222
|
-
super(stepName);
|
|
1223
|
-
this.sleepUntil = sleepUntil;
|
|
1224
|
-
}
|
|
1225
|
-
getPlanStep(concurrent, targetStep) {
|
|
1226
|
-
return {
|
|
1227
|
-
stepId: 0,
|
|
1228
|
-
stepName: this.stepName,
|
|
1229
|
-
stepType: this.stepType,
|
|
1230
|
-
sleepUntil: this.sleepUntil,
|
|
1231
|
-
concurrent,
|
|
1232
|
-
targetStep
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
async getResultStep(concurrent, stepId) {
|
|
1236
|
-
return await Promise.resolve({
|
|
1237
|
-
stepId,
|
|
1238
|
-
stepName: this.stepName,
|
|
1239
|
-
stepType: this.stepType,
|
|
1240
|
-
sleepUntil: this.sleepUntil,
|
|
1241
|
-
concurrent
|
|
1242
|
-
});
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
1246
|
-
url;
|
|
1247
|
-
method;
|
|
1248
|
-
body;
|
|
1249
|
-
headers;
|
|
1250
|
-
stepType = "Call";
|
|
1251
|
-
constructor(stepName, url, method, body, headers) {
|
|
1252
|
-
super(stepName);
|
|
1253
|
-
this.url = url;
|
|
1254
|
-
this.method = method;
|
|
1255
|
-
this.body = body;
|
|
1256
|
-
this.headers = headers;
|
|
1257
|
-
}
|
|
1258
|
-
getPlanStep(concurrent, targetStep) {
|
|
1259
|
-
return {
|
|
1260
|
-
stepId: 0,
|
|
1261
|
-
stepName: this.stepName,
|
|
1262
|
-
stepType: this.stepType,
|
|
1263
|
-
concurrent,
|
|
1264
|
-
targetStep
|
|
1265
|
-
};
|
|
1266
|
-
}
|
|
1267
|
-
async getResultStep(concurrent, stepId) {
|
|
1268
|
-
return await Promise.resolve({
|
|
1269
|
-
stepId,
|
|
1270
|
-
stepName: this.stepName,
|
|
1271
|
-
stepType: this.stepType,
|
|
1272
|
-
concurrent,
|
|
1273
|
-
callUrl: this.url,
|
|
1274
|
-
callMethod: this.method,
|
|
1275
|
-
callBody: this.body,
|
|
1276
|
-
callHeaders: this.headers
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
};
|
|
1280
|
-
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1281
|
-
eventId;
|
|
1282
|
-
timeout;
|
|
1283
|
-
stepType = "Wait";
|
|
1284
|
-
constructor(stepName, eventId, timeout) {
|
|
1285
|
-
super(stepName);
|
|
1286
|
-
this.eventId = eventId;
|
|
1287
|
-
this.timeout = timeout;
|
|
1288
|
-
}
|
|
1289
|
-
getPlanStep(concurrent, targetStep) {
|
|
1290
|
-
return {
|
|
1291
|
-
stepId: 0,
|
|
1292
|
-
stepName: this.stepName,
|
|
1293
|
-
stepType: this.stepType,
|
|
1294
|
-
waitEventId: this.eventId,
|
|
1295
|
-
timeout: this.timeout,
|
|
1296
|
-
concurrent,
|
|
1297
|
-
targetStep
|
|
1298
|
-
};
|
|
1299
|
-
}
|
|
1300
|
-
async getResultStep(concurrent, stepId) {
|
|
1301
|
-
return await Promise.resolve({
|
|
1302
|
-
stepId,
|
|
1303
|
-
stepName: this.stepName,
|
|
1304
|
-
stepType: this.stepType,
|
|
1305
|
-
waitEventId: this.eventId,
|
|
1306
|
-
timeout: this.timeout,
|
|
1307
|
-
concurrent
|
|
1308
|
-
});
|
|
1309
|
-
}
|
|
1310
|
-
};
|
|
1311
|
-
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1312
|
-
stepType = "Notify";
|
|
1313
|
-
constructor(stepName, eventId, eventData, requester) {
|
|
1314
|
-
super(stepName, async () => {
|
|
1315
|
-
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1316
|
-
return {
|
|
1317
|
-
eventId,
|
|
1318
|
-
eventData,
|
|
1319
|
-
notifyResponse
|
|
1320
|
-
};
|
|
1321
|
-
});
|
|
1322
|
-
}
|
|
1323
|
-
};
|
|
1324
|
-
|
|
1325
1333
|
// src/context/context.ts
|
|
1326
1334
|
var WorkflowContext = class {
|
|
1327
1335
|
executor;
|
|
@@ -1537,11 +1545,13 @@ var WorkflowContext = class {
|
|
|
1537
1545
|
* network call without consuming any runtime.
|
|
1538
1546
|
*
|
|
1539
1547
|
* ```ts
|
|
1540
|
-
* const
|
|
1548
|
+
* const { status, body } = await context.call<string>(
|
|
1541
1549
|
* "post call step",
|
|
1542
|
-
*
|
|
1543
|
-
*
|
|
1544
|
-
*
|
|
1550
|
+
* {
|
|
1551
|
+
* url: `https://www.some-endpoint.com/api`,
|
|
1552
|
+
* method: "POST",
|
|
1553
|
+
* body: "my-payload"
|
|
1554
|
+
* }
|
|
1545
1555
|
* );
|
|
1546
1556
|
* ```
|
|
1547
1557
|
*
|
|
@@ -1551,9 +1561,10 @@ var WorkflowContext = class {
|
|
|
1551
1561
|
*
|
|
1552
1562
|
* @param stepName
|
|
1553
1563
|
* @param url url to call
|
|
1554
|
-
* @param method call method
|
|
1564
|
+
* @param method call method. "GET" by default.
|
|
1555
1565
|
* @param body call body
|
|
1556
1566
|
* @param headers call headers
|
|
1567
|
+
* @param retries number of call retries. 0 by default
|
|
1557
1568
|
* @returns call result as {
|
|
1558
1569
|
* status: number;
|
|
1559
1570
|
* body: unknown;
|
|
@@ -1561,9 +1572,9 @@ var WorkflowContext = class {
|
|
|
1561
1572
|
* }
|
|
1562
1573
|
*/
|
|
1563
1574
|
async call(stepName, settings) {
|
|
1564
|
-
const { url, method = "GET", body, headers = {} } = settings;
|
|
1575
|
+
const { url, method = "GET", body, headers = {}, retries = 0 } = settings;
|
|
1565
1576
|
const result = await this.addStep(
|
|
1566
|
-
new LazyCallStep(stepName, url, method, body, headers
|
|
1577
|
+
new LazyCallStep(stepName, url, method, body, headers, retries)
|
|
1567
1578
|
);
|
|
1568
1579
|
if (typeof result === "string") {
|
|
1569
1580
|
try {
|
|
@@ -1710,11 +1721,14 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
1710
1721
|
};
|
|
1711
1722
|
|
|
1712
1723
|
// src/utils.ts
|
|
1713
|
-
var
|
|
1724
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
1714
1725
|
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
1715
1726
|
var NANOID_LENGTH = 21;
|
|
1716
1727
|
function nanoid() {
|
|
1717
|
-
return [...
|
|
1728
|
+
return [...import_node_crypto.default.getRandomValues(new Uint8Array(NANOID_LENGTH))].map((x) => NANOID_CHARS[x % NANOID_CHARS.length]).join("");
|
|
1729
|
+
}
|
|
1730
|
+
function getWorkflowRunId(id) {
|
|
1731
|
+
return `wfr_${id ?? nanoid()}`;
|
|
1718
1732
|
}
|
|
1719
1733
|
function decodeBase64(base64) {
|
|
1720
1734
|
try {
|
|
@@ -1820,7 +1834,7 @@ var validateRequest = (request) => {
|
|
|
1820
1834
|
`Incompatible workflow sdk protocol version. Expected ${WORKFLOW_PROTOCOL_VERSION}, got ${versionHeader} from the request.`
|
|
1821
1835
|
);
|
|
1822
1836
|
}
|
|
1823
|
-
const workflowRunId = isFirstInvocation ?
|
|
1837
|
+
const workflowRunId = isFirstInvocation ? getWorkflowRunId() : request.headers.get(WORKFLOW_ID_HEADER) ?? "";
|
|
1824
1838
|
if (workflowRunId.length === 0) {
|
|
1825
1839
|
throw new QStashWorkflowError("Couldn't get workflow id from header");
|
|
1826
1840
|
}
|
|
@@ -2148,8 +2162,7 @@ var servePagesRouter = (routeFunction, options) => {
|
|
|
2148
2162
|
const protocol = request_.headers["x-forwarded-proto"];
|
|
2149
2163
|
const baseUrl = options?.baseUrl ?? `${protocol}://${request_.headers.host}`;
|
|
2150
2164
|
const request = new Request(options?.url ?? `${baseUrl}${request_.url}`, {
|
|
2151
|
-
|
|
2152
|
-
body: JSON.stringify(request_.body) ?? "",
|
|
2165
|
+
body: (typeof request_.body === "string" ? request_.body : typeof request_.body === "undefined" ? void 0 : JSON.stringify(request_.body)) ?? "",
|
|
2153
2166
|
headers: new Headers(request_.headersDistinct),
|
|
2154
2167
|
method: "POST"
|
|
2155
2168
|
});
|
package/nextjs.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
serve
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-35GJPVE2.mjs";
|
|
4
4
|
|
|
5
5
|
// platforms/nextjs.ts
|
|
6
6
|
var serve2 = (routeFunction, options) => {
|
|
@@ -27,8 +27,7 @@ var servePagesRouter = (routeFunction, options) => {
|
|
|
27
27
|
const protocol = request_.headers["x-forwarded-proto"];
|
|
28
28
|
const baseUrl = options?.baseUrl ?? `${protocol}://${request_.headers.host}`;
|
|
29
29
|
const request = new Request(options?.url ?? `${baseUrl}${request_.url}`, {
|
|
30
|
-
|
|
31
|
-
body: JSON.stringify(request_.body) ?? "",
|
|
30
|
+
body: (typeof request_.body === "string" ? request_.body : typeof request_.body === "undefined" ? void 0 : JSON.stringify(request_.body)) ?? "",
|
|
32
31
|
headers: new Headers(request_.headersDistinct),
|
|
33
32
|
method: "POST"
|
|
34
33
|
});
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@upstash/workflow","version":"v0.1.3
|
|
1
|
+
{"name":"@upstash/workflow","version":"v0.1.3","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.0","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^4.21.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsc":"^2.0.4","tsup":"^8.3.0","typescript":"5.4.5","typescript-eslint":"^8.8.0"},"dependencies":{"@upstash/qstash":"^2.7.12"},"directories":{"example":"examples"}}
|
package/solidjs.d.mts
CHANGED
package/solidjs.d.ts
CHANGED