@upstash/workflow 0.2.6 → 0.2.8-rc-invoke
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 +8 -3
- package/astro.d.ts +8 -3
- package/astro.js +241 -65
- package/astro.mjs +33 -7
- package/{chunk-OLNSY3BB.mjs → chunk-IWAW7GIG.mjs} +106 -38
- package/chunk-LCZMBGEM.mjs +95 -0
- package/cloudflare.d.mts +9 -4
- package/cloudflare.d.ts +9 -4
- package/cloudflare.js +244 -71
- package/cloudflare.mjs +36 -13
- package/express.d.mts +7 -3
- package/express.d.ts +7 -3
- package/express.js +257 -69
- package/express.mjs +47 -11
- package/h3.d.mts +9 -7
- package/h3.d.ts +9 -7
- package/h3.js +252 -78
- package/h3.mjs +44 -20
- package/hono.d.mts +10 -4
- package/hono.d.ts +10 -4
- package/hono.js +243 -73
- package/hono.mjs +35 -15
- package/index.d.mts +17 -4
- package/index.d.ts +17 -4
- package/index.js +105 -38
- package/index.mjs +2 -2
- package/nextjs.d.mts +14 -5
- package/nextjs.d.ts +14 -5
- package/nextjs.js +252 -52
- package/nextjs.mjs +64 -16
- package/package.json +1 -1
- package/serve-many-BlBvXfBS.d.mts +10 -0
- package/serve-many-Dw-UUnH6.d.ts +10 -0
- package/solidjs.d.mts +3 -3
- package/solidjs.d.ts +3 -3
- package/solidjs.js +110 -46
- package/solidjs.mjs +7 -10
- package/svelte.d.mts +12 -4
- package/svelte.d.ts +12 -4
- package/svelte.js +243 -71
- package/svelte.mjs +35 -13
- package/{types-Cuqlx2Cr.d.mts → types-C7Y7WUQd.d.mts} +31 -3
- package/{types-Cuqlx2Cr.d.ts → types-C7Y7WUQd.d.ts} +31 -3
package/svelte.js
CHANGED
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// platforms/svelte.ts
|
|
21
21
|
var svelte_exports = {};
|
|
22
22
|
__export(svelte_exports, {
|
|
23
|
-
|
|
23
|
+
createWorkflow: () => createWorkflow,
|
|
24
|
+
serve: () => serve,
|
|
25
|
+
serveMany: () => serveMany
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(svelte_exports);
|
|
26
28
|
|
|
@@ -88,7 +90,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
88
90
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
89
91
|
var NO_CONCURRENCY = 1;
|
|
90
92
|
var DEFAULT_RETRIES = 3;
|
|
91
|
-
var VERSION = "v0.2.
|
|
93
|
+
var VERSION = "v0.2.7";
|
|
92
94
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
93
95
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
94
96
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -135,6 +137,31 @@ var formatWorkflowError = (error) => {
|
|
|
135
137
|
};
|
|
136
138
|
};
|
|
137
139
|
|
|
140
|
+
// src/utils.ts
|
|
141
|
+
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
142
|
+
var NANOID_LENGTH = 21;
|
|
143
|
+
function getRandomInt() {
|
|
144
|
+
return Math.floor(Math.random() * NANOID_CHARS.length);
|
|
145
|
+
}
|
|
146
|
+
function nanoid() {
|
|
147
|
+
return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
|
|
148
|
+
}
|
|
149
|
+
function getWorkflowRunId(id) {
|
|
150
|
+
return `wfr_${id ?? nanoid()}`;
|
|
151
|
+
}
|
|
152
|
+
function decodeBase64(base64) {
|
|
153
|
+
try {
|
|
154
|
+
const binString = atob(base64);
|
|
155
|
+
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
156
|
+
return new TextDecoder().decode(intArray);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.warn(
|
|
159
|
+
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
160
|
+
);
|
|
161
|
+
return atob(base64);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
138
165
|
// src/context/steps.ts
|
|
139
166
|
var BaseLazyStep = class {
|
|
140
167
|
stepName;
|
|
@@ -315,6 +342,41 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
315
342
|
});
|
|
316
343
|
}
|
|
317
344
|
};
|
|
345
|
+
var LazyInvokeStep = class extends BaseLazyStep {
|
|
346
|
+
stepType = "Invoke";
|
|
347
|
+
params;
|
|
348
|
+
constructor(stepName, { workflow, body, headers = {}, workflowRunId, retries }) {
|
|
349
|
+
super(stepName);
|
|
350
|
+
this.params = {
|
|
351
|
+
workflow,
|
|
352
|
+
body,
|
|
353
|
+
headers,
|
|
354
|
+
workflowRunId: getWorkflowRunId(workflowRunId),
|
|
355
|
+
retries
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
getPlanStep(concurrent, targetStep) {
|
|
359
|
+
return {
|
|
360
|
+
stepId: 0,
|
|
361
|
+
stepName: this.stepName,
|
|
362
|
+
stepType: this.stepType,
|
|
363
|
+
concurrent,
|
|
364
|
+
targetStep
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* won't be used as it's the server who will add the result step
|
|
369
|
+
* in Invoke step.
|
|
370
|
+
*/
|
|
371
|
+
getResultStep(concurrent, stepId) {
|
|
372
|
+
return Promise.resolve({
|
|
373
|
+
stepId,
|
|
374
|
+
stepName: this.stepName,
|
|
375
|
+
stepType: this.stepType,
|
|
376
|
+
concurrent
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
};
|
|
318
380
|
|
|
319
381
|
// node_modules/neverthrow/dist/index.es.js
|
|
320
382
|
var defaultErrorConfig = {
|
|
@@ -739,7 +801,8 @@ var StepTypes = [
|
|
|
739
801
|
"SleepUntil",
|
|
740
802
|
"Call",
|
|
741
803
|
"Wait",
|
|
742
|
-
"Notify"
|
|
804
|
+
"Notify",
|
|
805
|
+
"Invoke"
|
|
743
806
|
];
|
|
744
807
|
|
|
745
808
|
// src/workflow-requests.ts
|
|
@@ -747,7 +810,7 @@ var import_qstash3 = require("@upstash/qstash");
|
|
|
747
810
|
var triggerFirstInvocation = async ({
|
|
748
811
|
workflowContext,
|
|
749
812
|
useJSONContent,
|
|
750
|
-
telemetry,
|
|
813
|
+
telemetry: telemetry2,
|
|
751
814
|
debug
|
|
752
815
|
}) => {
|
|
753
816
|
const { headers } = getHeaders({
|
|
@@ -757,8 +820,11 @@ var triggerFirstInvocation = async ({
|
|
|
757
820
|
userHeaders: workflowContext.headers,
|
|
758
821
|
failureUrl: workflowContext.failureUrl,
|
|
759
822
|
retries: workflowContext.retries,
|
|
760
|
-
telemetry
|
|
823
|
+
telemetry: telemetry2
|
|
761
824
|
});
|
|
825
|
+
if (workflowContext.headers.get("content-type")) {
|
|
826
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
827
|
+
}
|
|
762
828
|
if (useJSONContent) {
|
|
763
829
|
headers["content-type"] = "application/json";
|
|
764
830
|
}
|
|
@@ -800,8 +866,8 @@ var triggerRouteFunction = async ({
|
|
|
800
866
|
debug
|
|
801
867
|
}) => {
|
|
802
868
|
try {
|
|
803
|
-
await onStep();
|
|
804
|
-
await onCleanup();
|
|
869
|
+
const result = await onStep();
|
|
870
|
+
await onCleanup(result);
|
|
805
871
|
return ok("workflow-finished");
|
|
806
872
|
} catch (error) {
|
|
807
873
|
const error_ = error;
|
|
@@ -822,14 +888,15 @@ var triggerRouteFunction = async ({
|
|
|
822
888
|
}
|
|
823
889
|
}
|
|
824
890
|
};
|
|
825
|
-
var triggerWorkflowDelete = async (workflowContext, debug, cancel = false) => {
|
|
891
|
+
var triggerWorkflowDelete = async (workflowContext, result, debug, cancel = false) => {
|
|
826
892
|
await debug?.log("SUBMIT", "SUBMIT_CLEANUP", {
|
|
827
893
|
deletedWorkflowRunId: workflowContext.workflowRunId
|
|
828
894
|
});
|
|
829
895
|
await workflowContext.qstashClient.http.request({
|
|
830
896
|
path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
|
|
831
897
|
method: "DELETE",
|
|
832
|
-
parseResponseAsJson: false
|
|
898
|
+
parseResponseAsJson: false,
|
|
899
|
+
body: JSON.stringify(result)
|
|
833
900
|
});
|
|
834
901
|
await debug?.log(
|
|
835
902
|
"SUBMIT",
|
|
@@ -858,7 +925,7 @@ var handleThirdPartyCallResult = async ({
|
|
|
858
925
|
workflowUrl,
|
|
859
926
|
failureUrl,
|
|
860
927
|
retries,
|
|
861
|
-
telemetry,
|
|
928
|
+
telemetry: telemetry2,
|
|
862
929
|
debug
|
|
863
930
|
}) => {
|
|
864
931
|
try {
|
|
@@ -926,7 +993,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
926
993
|
userHeaders,
|
|
927
994
|
failureUrl,
|
|
928
995
|
retries,
|
|
929
|
-
telemetry
|
|
996
|
+
telemetry: telemetry2
|
|
930
997
|
});
|
|
931
998
|
const callResponse = {
|
|
932
999
|
status: callbackMessage.status,
|
|
@@ -965,11 +1032,11 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
965
1032
|
);
|
|
966
1033
|
}
|
|
967
1034
|
};
|
|
968
|
-
var getTelemetryHeaders = (
|
|
1035
|
+
var getTelemetryHeaders = (telemetry2) => {
|
|
969
1036
|
return {
|
|
970
|
-
[TELEMETRY_HEADER_SDK]:
|
|
971
|
-
[TELEMETRY_HEADER_FRAMEWORK]:
|
|
972
|
-
[TELEMETRY_HEADER_RUNTIME]:
|
|
1037
|
+
[TELEMETRY_HEADER_SDK]: telemetry2.sdk,
|
|
1038
|
+
[TELEMETRY_HEADER_FRAMEWORK]: telemetry2.framework,
|
|
1039
|
+
[TELEMETRY_HEADER_RUNTIME]: telemetry2.runtime ?? "unknown"
|
|
973
1040
|
};
|
|
974
1041
|
};
|
|
975
1042
|
var getHeaders = ({
|
|
@@ -982,14 +1049,17 @@ var getHeaders = ({
|
|
|
982
1049
|
step,
|
|
983
1050
|
callRetries,
|
|
984
1051
|
callTimeout,
|
|
985
|
-
telemetry
|
|
1052
|
+
telemetry: telemetry2
|
|
986
1053
|
}) => {
|
|
1054
|
+
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
987
1055
|
const baseHeaders = {
|
|
988
1056
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
989
1057
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
990
1058
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
991
1059
|
[WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
|
|
992
|
-
|
|
1060
|
+
[WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
|
|
1061
|
+
"content-type": contentType,
|
|
1062
|
+
...telemetry2 ? getTelemetryHeaders(telemetry2) : {}
|
|
993
1063
|
};
|
|
994
1064
|
if (!step?.callUrl) {
|
|
995
1065
|
baseHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
|
|
@@ -1003,6 +1073,9 @@ var getHeaders = ({
|
|
|
1003
1073
|
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
1004
1074
|
}
|
|
1005
1075
|
}
|
|
1076
|
+
if (step?.stepType === "Invoke") {
|
|
1077
|
+
baseHeaders["upstash-workflow-invoke"] = "true";
|
|
1078
|
+
}
|
|
1006
1079
|
if (step?.callUrl) {
|
|
1007
1080
|
baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
|
|
1008
1081
|
baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
|
|
@@ -1024,7 +1097,6 @@ var getHeaders = ({
|
|
|
1024
1097
|
baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
|
|
1025
1098
|
}
|
|
1026
1099
|
}
|
|
1027
|
-
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
1028
1100
|
if (step?.callHeaders) {
|
|
1029
1101
|
const forwardedHeaders = Object.fromEntries(
|
|
1030
1102
|
Object.entries(step.callHeaders).map(([header, value]) => [
|
|
@@ -1064,8 +1136,8 @@ var getHeaders = ({
|
|
|
1064
1136
|
Object.entries(baseHeaders).map(([header, value]) => [header, [value]])
|
|
1065
1137
|
),
|
|
1066
1138
|
// to include telemetry headers:
|
|
1067
|
-
...
|
|
1068
|
-
Object.entries(getTelemetryHeaders(
|
|
1139
|
+
...telemetry2 ? Object.fromEntries(
|
|
1140
|
+
Object.entries(getTelemetryHeaders(telemetry2)).map(([header, value]) => [
|
|
1069
1141
|
header,
|
|
1070
1142
|
[value]
|
|
1071
1143
|
])
|
|
@@ -1074,8 +1146,7 @@ var getHeaders = ({
|
|
|
1074
1146
|
"Upstash-Workflow-Runid": [workflowRunId],
|
|
1075
1147
|
[WORKFLOW_INIT_HEADER]: ["false"],
|
|
1076
1148
|
[WORKFLOW_URL_HEADER]: [workflowUrl],
|
|
1077
|
-
"Upstash-Workflow-CallType": ["step"]
|
|
1078
|
-
"Content-Type": [contentType]
|
|
1149
|
+
"Upstash-Workflow-CallType": ["step"]
|
|
1079
1150
|
}
|
|
1080
1151
|
};
|
|
1081
1152
|
}
|
|
@@ -1121,10 +1192,10 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1121
1192
|
stepCount = 0;
|
|
1122
1193
|
planStepCount = 0;
|
|
1123
1194
|
executingStep = false;
|
|
1124
|
-
constructor(context, steps,
|
|
1195
|
+
constructor(context, steps, telemetry2, debug) {
|
|
1125
1196
|
this.context = context;
|
|
1126
1197
|
this.steps = steps;
|
|
1127
|
-
this.telemetry =
|
|
1198
|
+
this.telemetry = telemetry2;
|
|
1128
1199
|
this.debug = debug;
|
|
1129
1200
|
this.nonPlanStepCount = this.steps.filter((step) => !step.targetStep).length;
|
|
1130
1201
|
}
|
|
@@ -1370,7 +1441,23 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1370
1441
|
method: "POST",
|
|
1371
1442
|
parseResponseAsJson: false
|
|
1372
1443
|
});
|
|
1373
|
-
throw new WorkflowAbort(
|
|
1444
|
+
throw new WorkflowAbort(waitStep.stepName, waitStep);
|
|
1445
|
+
}
|
|
1446
|
+
if (steps.length === 1 && lazySteps[0] instanceof LazyInvokeStep) {
|
|
1447
|
+
const invokeStep = steps[0];
|
|
1448
|
+
const lazyInvokeStep = lazySteps[0];
|
|
1449
|
+
await lazyInvokeStep.params.workflow.callback(
|
|
1450
|
+
{
|
|
1451
|
+
body: lazyInvokeStep.params.body,
|
|
1452
|
+
headers: lazyInvokeStep.params.headers,
|
|
1453
|
+
workflowRunId: lazyInvokeStep.params.workflowRunId,
|
|
1454
|
+
workflow: lazyInvokeStep.params.workflow,
|
|
1455
|
+
retries: lazyInvokeStep.params.retries
|
|
1456
|
+
},
|
|
1457
|
+
invokeStep,
|
|
1458
|
+
this.context
|
|
1459
|
+
);
|
|
1460
|
+
throw new WorkflowAbort(invokeStep.stepName, invokeStep);
|
|
1374
1461
|
}
|
|
1375
1462
|
const result = await this.context.qstashClient.batchJSON(
|
|
1376
1463
|
steps.map((singleStep, index) => {
|
|
@@ -2056,7 +2143,7 @@ var WorkflowContext = class {
|
|
|
2056
2143
|
initialPayload,
|
|
2057
2144
|
env,
|
|
2058
2145
|
retries,
|
|
2059
|
-
telemetry
|
|
2146
|
+
telemetry: telemetry2
|
|
2060
2147
|
}) {
|
|
2061
2148
|
this.qstashClient = qstashClient;
|
|
2062
2149
|
this.workflowRunId = workflowRunId;
|
|
@@ -2067,7 +2154,7 @@ var WorkflowContext = class {
|
|
|
2067
2154
|
this.requestPayload = initialPayload;
|
|
2068
2155
|
this.env = env ?? {};
|
|
2069
2156
|
this.retries = retries ?? DEFAULT_RETRIES;
|
|
2070
|
-
this.executor = new AutoExecutor(this, this.steps,
|
|
2157
|
+
this.executor = new AutoExecutor(this, this.steps, telemetry2, debug);
|
|
2071
2158
|
}
|
|
2072
2159
|
/**
|
|
2073
2160
|
* Executes a workflow step
|
|
@@ -2287,6 +2374,13 @@ var WorkflowContext = class {
|
|
|
2287
2374
|
return result;
|
|
2288
2375
|
}
|
|
2289
2376
|
}
|
|
2377
|
+
async invoke(stepName, settings) {
|
|
2378
|
+
const result = await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
2379
|
+
return {
|
|
2380
|
+
...result,
|
|
2381
|
+
body: result.body ? JSON.parse(result.body) : void 0
|
|
2382
|
+
};
|
|
2383
|
+
}
|
|
2290
2384
|
/**
|
|
2291
2385
|
* Cancel the current workflow run
|
|
2292
2386
|
*
|
|
@@ -2364,31 +2458,6 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
2364
2458
|
}
|
|
2365
2459
|
};
|
|
2366
2460
|
|
|
2367
|
-
// src/utils.ts
|
|
2368
|
-
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
2369
|
-
var NANOID_LENGTH = 21;
|
|
2370
|
-
function getRandomInt() {
|
|
2371
|
-
return Math.floor(Math.random() * NANOID_CHARS.length);
|
|
2372
|
-
}
|
|
2373
|
-
function nanoid() {
|
|
2374
|
-
return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
|
|
2375
|
-
}
|
|
2376
|
-
function getWorkflowRunId(id) {
|
|
2377
|
-
return `wfr_${id ?? nanoid()}`;
|
|
2378
|
-
}
|
|
2379
|
-
function decodeBase64(base64) {
|
|
2380
|
-
try {
|
|
2381
|
-
const binString = atob(base64);
|
|
2382
|
-
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
2383
|
-
return new TextDecoder().decode(intArray);
|
|
2384
|
-
} catch (error) {
|
|
2385
|
-
console.warn(
|
|
2386
|
-
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
2387
|
-
);
|
|
2388
|
-
return atob(base64);
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
|
|
2392
2461
|
// src/serve/authorization.ts
|
|
2393
2462
|
var import_qstash8 = require("@upstash/qstash");
|
|
2394
2463
|
var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
|
|
@@ -2726,7 +2795,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
|
|
|
2726
2795
|
var AUTH_FAIL_MESSAGE = `Failed to authenticate Workflow request. If this is unexpected, see the caveat https://upstash.com/docs/workflow/basics/caveats#avoid-non-deterministic-code-outside-context-run`;
|
|
2727
2796
|
|
|
2728
2797
|
// src/serve/index.ts
|
|
2729
|
-
var serveBase = (routeFunction,
|
|
2798
|
+
var serveBase = (routeFunction, telemetry2, options) => {
|
|
2730
2799
|
const {
|
|
2731
2800
|
qstashClient,
|
|
2732
2801
|
onStepFinish,
|
|
@@ -2742,7 +2811,7 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2742
2811
|
useJSONContent,
|
|
2743
2812
|
disableTelemetry
|
|
2744
2813
|
} = processOptions(options);
|
|
2745
|
-
|
|
2814
|
+
telemetry2 = disableTelemetry ? void 0 : telemetry2;
|
|
2746
2815
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
2747
2816
|
const handler = async (request) => {
|
|
2748
2817
|
await debug?.log("INFO", "ENDPOINT_START");
|
|
@@ -2800,7 +2869,7 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2800
2869
|
debug,
|
|
2801
2870
|
env,
|
|
2802
2871
|
retries,
|
|
2803
|
-
telemetry
|
|
2872
|
+
telemetry: telemetry2
|
|
2804
2873
|
});
|
|
2805
2874
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
2806
2875
|
routeFunction,
|
|
@@ -2823,7 +2892,7 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2823
2892
|
workflowUrl,
|
|
2824
2893
|
failureUrl: workflowFailureUrl,
|
|
2825
2894
|
retries,
|
|
2826
|
-
telemetry,
|
|
2895
|
+
telemetry: telemetry2,
|
|
2827
2896
|
debug
|
|
2828
2897
|
});
|
|
2829
2898
|
if (callReturnCheck.isErr()) {
|
|
@@ -2832,10 +2901,10 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2832
2901
|
});
|
|
2833
2902
|
throw callReturnCheck.error;
|
|
2834
2903
|
} else if (callReturnCheck.value === "continue-workflow") {
|
|
2835
|
-
const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry, debug }) : await triggerRouteFunction({
|
|
2904
|
+
const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry: telemetry2, debug }) : await triggerRouteFunction({
|
|
2836
2905
|
onStep: async () => routeFunction(workflowContext),
|
|
2837
|
-
onCleanup: async () => {
|
|
2838
|
-
await triggerWorkflowDelete(workflowContext, debug);
|
|
2906
|
+
onCleanup: async (result2) => {
|
|
2907
|
+
await triggerWorkflowDelete(workflowContext, result2, debug);
|
|
2839
2908
|
},
|
|
2840
2909
|
onCancel: async () => {
|
|
2841
2910
|
await makeCancelRequest(workflowContext.qstashClient.http, workflowRunId);
|
|
@@ -2867,25 +2936,128 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2867
2936
|
return { handler: safeHandler };
|
|
2868
2937
|
};
|
|
2869
2938
|
|
|
2939
|
+
// src/serve/serve-many.ts
|
|
2940
|
+
var serveManyBase = ({
|
|
2941
|
+
workflows,
|
|
2942
|
+
getWorkflowId
|
|
2943
|
+
}) => {
|
|
2944
|
+
const workflowIds = [];
|
|
2945
|
+
const workflowMap = Object.fromEntries(
|
|
2946
|
+
Object.entries(workflows).map((workflow) => {
|
|
2947
|
+
const workflowId = workflow[0];
|
|
2948
|
+
if (workflowIds.includes(workflowId)) {
|
|
2949
|
+
throw new WorkflowError(
|
|
2950
|
+
`Duplicate workflow name found: '${workflowId}'. Please set different workflow names in serveMany.`
|
|
2951
|
+
);
|
|
2952
|
+
}
|
|
2953
|
+
if (workflowId.includes("/")) {
|
|
2954
|
+
throw new WorkflowError(
|
|
2955
|
+
`Invalid workflow name found: '${workflowId}'. Workflow name cannot contain '/'.`
|
|
2956
|
+
);
|
|
2957
|
+
}
|
|
2958
|
+
workflowIds.push(workflowId);
|
|
2959
|
+
workflow[1].workflowId = workflowId;
|
|
2960
|
+
return [workflowId, workflow[1].handler];
|
|
2961
|
+
})
|
|
2962
|
+
);
|
|
2963
|
+
return {
|
|
2964
|
+
handler: async (...params) => {
|
|
2965
|
+
const pickedWorkflowId = getWorkflowId(...params);
|
|
2966
|
+
if (!pickedWorkflowId) {
|
|
2967
|
+
throw new WorkflowError(`Unexpected request in serveMany. workflowId not set. Please update the URL of your request.`);
|
|
2968
|
+
}
|
|
2969
|
+
const workflow = workflowMap[pickedWorkflowId];
|
|
2970
|
+
if (!workflow) {
|
|
2971
|
+
throw new WorkflowError(`No workflows in serveMany found for '${pickedWorkflowId}'. Please update the URL of your request.`);
|
|
2972
|
+
}
|
|
2973
|
+
return await workflow(...params);
|
|
2974
|
+
}
|
|
2975
|
+
};
|
|
2976
|
+
};
|
|
2977
|
+
var createInvokeCallback = (telemetry2) => {
|
|
2978
|
+
const invokeCallback = async (settings, invokeStep, context) => {
|
|
2979
|
+
const { body, workflow, headers = {}, workflowRunId = getWorkflowRunId(), retries } = settings;
|
|
2980
|
+
const { workflowId } = workflow;
|
|
2981
|
+
if (!workflowId) {
|
|
2982
|
+
throw new WorkflowError("You can only invoke workflow which has a workflowId");
|
|
2983
|
+
}
|
|
2984
|
+
const { headers: invokerHeaders } = getHeaders({
|
|
2985
|
+
initHeaderValue: "false",
|
|
2986
|
+
workflowRunId: context.workflowRunId,
|
|
2987
|
+
workflowUrl: context.url,
|
|
2988
|
+
userHeaders: context.headers,
|
|
2989
|
+
failureUrl: context.failureUrl,
|
|
2990
|
+
retries: context.retries,
|
|
2991
|
+
telemetry: telemetry2
|
|
2992
|
+
});
|
|
2993
|
+
invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
|
|
2994
|
+
const newUrl = context.url.replace(/[^/]+$/, workflowId);
|
|
2995
|
+
const { headers: triggerHeaders } = getHeaders({
|
|
2996
|
+
initHeaderValue: "true",
|
|
2997
|
+
workflowRunId,
|
|
2998
|
+
workflowUrl: newUrl,
|
|
2999
|
+
userHeaders: new Headers(headers),
|
|
3000
|
+
retries,
|
|
3001
|
+
telemetry: telemetry2
|
|
3002
|
+
});
|
|
3003
|
+
triggerHeaders["Upstash-Workflow-Invoke"] = "true";
|
|
3004
|
+
const request = {
|
|
3005
|
+
body: JSON.stringify(body),
|
|
3006
|
+
headers: Object.fromEntries(
|
|
3007
|
+
Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
|
|
3008
|
+
),
|
|
3009
|
+
workflowRunId,
|
|
3010
|
+
workflowUrl: context.url,
|
|
3011
|
+
step: invokeStep
|
|
3012
|
+
};
|
|
3013
|
+
await context.qstashClient.publish({
|
|
3014
|
+
headers: triggerHeaders,
|
|
3015
|
+
method: "POST",
|
|
3016
|
+
body: JSON.stringify(request),
|
|
3017
|
+
url: newUrl
|
|
3018
|
+
});
|
|
3019
|
+
return void 0;
|
|
3020
|
+
};
|
|
3021
|
+
return invokeCallback;
|
|
3022
|
+
};
|
|
3023
|
+
|
|
2870
3024
|
// platforms/svelte.ts
|
|
3025
|
+
var telemetry = {
|
|
3026
|
+
sdk: SDK_TELEMETRY,
|
|
3027
|
+
framework: "svelte"
|
|
3028
|
+
};
|
|
2871
3029
|
var serve = (routeFunction, options) => {
|
|
2872
3030
|
const handler = async ({ request }) => {
|
|
2873
|
-
const { handler: serveHandler } = serveBase(
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
framework: "svelte"
|
|
2878
|
-
},
|
|
2879
|
-
{
|
|
2880
|
-
...options,
|
|
2881
|
-
useJSONContent: true
|
|
2882
|
-
}
|
|
2883
|
-
);
|
|
3031
|
+
const { handler: serveHandler } = serveBase(routeFunction, telemetry, {
|
|
3032
|
+
...options,
|
|
3033
|
+
useJSONContent: true
|
|
3034
|
+
});
|
|
2884
3035
|
return await serveHandler(request);
|
|
2885
3036
|
};
|
|
2886
3037
|
return { POST: handler };
|
|
2887
3038
|
};
|
|
3039
|
+
var createWorkflow = (...params) => {
|
|
3040
|
+
const { POST } = serve(...params);
|
|
3041
|
+
return {
|
|
3042
|
+
callback: createInvokeCallback(telemetry),
|
|
3043
|
+
handler: POST,
|
|
3044
|
+
workflowId: void 0
|
|
3045
|
+
};
|
|
3046
|
+
};
|
|
3047
|
+
var serveMany = (workflows) => {
|
|
3048
|
+
return {
|
|
3049
|
+
POST: serveManyBase({
|
|
3050
|
+
workflows,
|
|
3051
|
+
getWorkflowId(params) {
|
|
3052
|
+
const components = params.url.toString().split("/");
|
|
3053
|
+
return components[components.length - 1];
|
|
3054
|
+
}
|
|
3055
|
+
}).handler
|
|
3056
|
+
};
|
|
3057
|
+
};
|
|
2888
3058
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2889
3059
|
0 && (module.exports = {
|
|
2890
|
-
|
|
3060
|
+
createWorkflow,
|
|
3061
|
+
serve,
|
|
3062
|
+
serveMany
|
|
2891
3063
|
});
|
package/svelte.mjs
CHANGED
|
@@ -1,26 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createInvokeCallback,
|
|
3
|
+
serveManyBase
|
|
4
|
+
} from "./chunk-LCZMBGEM.mjs";
|
|
1
5
|
import {
|
|
2
6
|
SDK_TELEMETRY,
|
|
3
7
|
serveBase
|
|
4
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-IWAW7GIG.mjs";
|
|
5
9
|
|
|
6
10
|
// platforms/svelte.ts
|
|
11
|
+
var telemetry = {
|
|
12
|
+
sdk: SDK_TELEMETRY,
|
|
13
|
+
framework: "svelte"
|
|
14
|
+
};
|
|
7
15
|
var serve = (routeFunction, options) => {
|
|
8
16
|
const handler = async ({ request }) => {
|
|
9
|
-
const { handler: serveHandler } = serveBase(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
framework: "svelte"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
...options,
|
|
17
|
-
useJSONContent: true
|
|
18
|
-
}
|
|
19
|
-
);
|
|
17
|
+
const { handler: serveHandler } = serveBase(routeFunction, telemetry, {
|
|
18
|
+
...options,
|
|
19
|
+
useJSONContent: true
|
|
20
|
+
});
|
|
20
21
|
return await serveHandler(request);
|
|
21
22
|
};
|
|
22
23
|
return { POST: handler };
|
|
23
24
|
};
|
|
25
|
+
var createWorkflow = (...params) => {
|
|
26
|
+
const { POST } = serve(...params);
|
|
27
|
+
return {
|
|
28
|
+
callback: createInvokeCallback(telemetry),
|
|
29
|
+
handler: POST,
|
|
30
|
+
workflowId: void 0
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
var serveMany = (workflows) => {
|
|
34
|
+
return {
|
|
35
|
+
POST: serveManyBase({
|
|
36
|
+
workflows,
|
|
37
|
+
getWorkflowId(params) {
|
|
38
|
+
const components = params.url.toString().split("/");
|
|
39
|
+
return components[components.length - 1];
|
|
40
|
+
}
|
|
41
|
+
}).handler
|
|
42
|
+
};
|
|
43
|
+
};
|
|
24
44
|
export {
|
|
25
|
-
|
|
45
|
+
createWorkflow,
|
|
46
|
+
serve,
|
|
47
|
+
serveMany
|
|
26
48
|
};
|
|
@@ -33,6 +33,11 @@ declare abstract class BaseLazyStep<TResult = unknown> {
|
|
|
33
33
|
*/
|
|
34
34
|
abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
|
|
35
35
|
}
|
|
36
|
+
type LazyInvokeStepParams<TInitiaPayload, TResult> = {
|
|
37
|
+
workflow: Pick<InvokableWorkflow<TInitiaPayload, TResult, unknown[]>, "callback" | "workflowId">;
|
|
38
|
+
body: TInitiaPayload;
|
|
39
|
+
workflowRunId?: string;
|
|
40
|
+
} & Pick<CallSettings, "retries" | "headers">;
|
|
36
41
|
|
|
37
42
|
declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
|
|
38
43
|
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
@@ -917,6 +922,11 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
917
922
|
* @returns notify response which has event id, event data and list of waiters which were notified
|
|
918
923
|
*/
|
|
919
924
|
notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
|
|
925
|
+
invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<{
|
|
926
|
+
body: any;
|
|
927
|
+
isCanceled?: boolean;
|
|
928
|
+
isFailed?: boolean;
|
|
929
|
+
}>;
|
|
920
930
|
/**
|
|
921
931
|
* Cancel the current workflow run
|
|
922
932
|
*
|
|
@@ -952,7 +962,7 @@ type WorkflowClient = {
|
|
|
952
962
|
type WorkflowReceiver = {
|
|
953
963
|
verify: InstanceType<typeof Receiver>["verify"];
|
|
954
964
|
};
|
|
955
|
-
declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call", "Wait", "Notify"];
|
|
965
|
+
declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call", "Wait", "Notify", "Invoke"];
|
|
956
966
|
type StepType = (typeof StepTypes)[number];
|
|
957
967
|
type ThirdPartyCallFields<TBody = unknown> = {
|
|
958
968
|
/**
|
|
@@ -1035,7 +1045,7 @@ type SyncStepFunction<TResult> = () => TResult;
|
|
|
1035
1045
|
type AsyncStepFunction<TResult> = () => Promise<TResult>;
|
|
1036
1046
|
type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResult>;
|
|
1037
1047
|
type ParallelCallState = "first" | "partial" | "discard" | "last";
|
|
1038
|
-
type RouteFunction<TInitialPayload> = (context: WorkflowContext<TInitialPayload>) => Promise<
|
|
1048
|
+
type RouteFunction<TInitialPayload, TResult = unknown> = (context: WorkflowContext<TInitialPayload>) => Promise<TResult>;
|
|
1039
1049
|
type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback" | "workflow-already-ended";
|
|
1040
1050
|
type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload = unknown> = ValidationOptions<TInitialPayload> & {
|
|
1041
1051
|
/**
|
|
@@ -1312,5 +1322,23 @@ type HeaderParams = {
|
|
|
1312
1322
|
*/
|
|
1313
1323
|
callTimeout?: never;
|
|
1314
1324
|
});
|
|
1325
|
+
type InvokeWorkflowRequest = {
|
|
1326
|
+
workflowUrl: string;
|
|
1327
|
+
workflowRunId: string;
|
|
1328
|
+
headers: Record<string, string[]>;
|
|
1329
|
+
step: Step;
|
|
1330
|
+
body: string;
|
|
1331
|
+
};
|
|
1332
|
+
type InvokeStepResponse<TBody> = {
|
|
1333
|
+
body: TBody;
|
|
1334
|
+
isCanceled?: boolean;
|
|
1335
|
+
isFailed?: boolean;
|
|
1336
|
+
};
|
|
1337
|
+
type InvokeCallback<TInitiaPayload, TResult> = (settings: LazyInvokeStepParams<TInitiaPayload, TResult>, invokeStep: Step, context: WorkflowContext) => Promise<TResult>;
|
|
1338
|
+
type InvokableWorkflow<TInitialPayload, TResult, THandlerParams extends unknown[]> = {
|
|
1339
|
+
handler: (...args: THandlerParams) => any;
|
|
1340
|
+
callback: InvokeCallback<TInitialPayload, TResult>;
|
|
1341
|
+
workflowId?: string;
|
|
1342
|
+
};
|
|
1315
1343
|
|
|
1316
|
-
export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type
|
|
1344
|
+
export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type ExclusiveValidationOptions as E, type FinishCondition as F, type HeaderParams as H, type InvokeWorkflowRequest as I, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type InvokeStepResponse as r, type InvokeCallback as s, type InvokableWorkflow as t, type WorkflowLoggerOptions as u, WorkflowLogger as v };
|