@upstash/workflow 0.2.7 → 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 +238 -65
- package/astro.mjs +33 -7
- package/{chunk-U6XFLG7W.mjs → chunk-IWAW7GIG.mjs} +103 -38
- package/chunk-LCZMBGEM.mjs +95 -0
- package/cloudflare.d.mts +9 -4
- package/cloudflare.d.ts +9 -4
- package/cloudflare.js +241 -71
- package/cloudflare.mjs +36 -13
- package/express.d.mts +7 -3
- package/express.d.ts +7 -3
- package/express.js +248 -68
- package/express.mjs +41 -10
- package/h3.d.mts +9 -7
- package/h3.d.ts +9 -7
- package/h3.js +249 -78
- package/h3.mjs +44 -20
- package/hono.d.mts +10 -4
- package/hono.d.ts +10 -4
- package/hono.js +240 -73
- package/hono.mjs +35 -15
- package/index.d.mts +17 -4
- package/index.d.ts +17 -4
- package/index.js +102 -38
- package/index.mjs +2 -2
- package/nextjs.d.mts +14 -5
- package/nextjs.d.ts +14 -5
- package/nextjs.js +249 -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 +107 -46
- package/solidjs.mjs +7 -10
- package/svelte.d.mts +12 -4
- package/svelte.d.ts +12 -4
- package/svelte.js +240 -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,7 +820,7 @@ 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
|
});
|
|
762
825
|
if (workflowContext.headers.get("content-type")) {
|
|
763
826
|
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
@@ -803,8 +866,8 @@ var triggerRouteFunction = async ({
|
|
|
803
866
|
debug
|
|
804
867
|
}) => {
|
|
805
868
|
try {
|
|
806
|
-
await onStep();
|
|
807
|
-
await onCleanup();
|
|
869
|
+
const result = await onStep();
|
|
870
|
+
await onCleanup(result);
|
|
808
871
|
return ok("workflow-finished");
|
|
809
872
|
} catch (error) {
|
|
810
873
|
const error_ = error;
|
|
@@ -825,14 +888,15 @@ var triggerRouteFunction = async ({
|
|
|
825
888
|
}
|
|
826
889
|
}
|
|
827
890
|
};
|
|
828
|
-
var triggerWorkflowDelete = async (workflowContext, debug, cancel = false) => {
|
|
891
|
+
var triggerWorkflowDelete = async (workflowContext, result, debug, cancel = false) => {
|
|
829
892
|
await debug?.log("SUBMIT", "SUBMIT_CLEANUP", {
|
|
830
893
|
deletedWorkflowRunId: workflowContext.workflowRunId
|
|
831
894
|
});
|
|
832
895
|
await workflowContext.qstashClient.http.request({
|
|
833
896
|
path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
|
|
834
897
|
method: "DELETE",
|
|
835
|
-
parseResponseAsJson: false
|
|
898
|
+
parseResponseAsJson: false,
|
|
899
|
+
body: JSON.stringify(result)
|
|
836
900
|
});
|
|
837
901
|
await debug?.log(
|
|
838
902
|
"SUBMIT",
|
|
@@ -861,7 +925,7 @@ var handleThirdPartyCallResult = async ({
|
|
|
861
925
|
workflowUrl,
|
|
862
926
|
failureUrl,
|
|
863
927
|
retries,
|
|
864
|
-
telemetry,
|
|
928
|
+
telemetry: telemetry2,
|
|
865
929
|
debug
|
|
866
930
|
}) => {
|
|
867
931
|
try {
|
|
@@ -929,7 +993,7 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
929
993
|
userHeaders,
|
|
930
994
|
failureUrl,
|
|
931
995
|
retries,
|
|
932
|
-
telemetry
|
|
996
|
+
telemetry: telemetry2
|
|
933
997
|
});
|
|
934
998
|
const callResponse = {
|
|
935
999
|
status: callbackMessage.status,
|
|
@@ -968,11 +1032,11 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
968
1032
|
);
|
|
969
1033
|
}
|
|
970
1034
|
};
|
|
971
|
-
var getTelemetryHeaders = (
|
|
1035
|
+
var getTelemetryHeaders = (telemetry2) => {
|
|
972
1036
|
return {
|
|
973
|
-
[TELEMETRY_HEADER_SDK]:
|
|
974
|
-
[TELEMETRY_HEADER_FRAMEWORK]:
|
|
975
|
-
[TELEMETRY_HEADER_RUNTIME]:
|
|
1037
|
+
[TELEMETRY_HEADER_SDK]: telemetry2.sdk,
|
|
1038
|
+
[TELEMETRY_HEADER_FRAMEWORK]: telemetry2.framework,
|
|
1039
|
+
[TELEMETRY_HEADER_RUNTIME]: telemetry2.runtime ?? "unknown"
|
|
976
1040
|
};
|
|
977
1041
|
};
|
|
978
1042
|
var getHeaders = ({
|
|
@@ -985,14 +1049,17 @@ var getHeaders = ({
|
|
|
985
1049
|
step,
|
|
986
1050
|
callRetries,
|
|
987
1051
|
callTimeout,
|
|
988
|
-
telemetry
|
|
1052
|
+
telemetry: telemetry2
|
|
989
1053
|
}) => {
|
|
1054
|
+
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
990
1055
|
const baseHeaders = {
|
|
991
1056
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
992
1057
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
993
1058
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
994
1059
|
[WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
|
|
995
|
-
|
|
1060
|
+
[WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
|
|
1061
|
+
"content-type": contentType,
|
|
1062
|
+
...telemetry2 ? getTelemetryHeaders(telemetry2) : {}
|
|
996
1063
|
};
|
|
997
1064
|
if (!step?.callUrl) {
|
|
998
1065
|
baseHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
|
|
@@ -1006,6 +1073,9 @@ var getHeaders = ({
|
|
|
1006
1073
|
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
1007
1074
|
}
|
|
1008
1075
|
}
|
|
1076
|
+
if (step?.stepType === "Invoke") {
|
|
1077
|
+
baseHeaders["upstash-workflow-invoke"] = "true";
|
|
1078
|
+
}
|
|
1009
1079
|
if (step?.callUrl) {
|
|
1010
1080
|
baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
|
|
1011
1081
|
baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
|
|
@@ -1027,7 +1097,6 @@ var getHeaders = ({
|
|
|
1027
1097
|
baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
|
|
1028
1098
|
}
|
|
1029
1099
|
}
|
|
1030
|
-
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
1031
1100
|
if (step?.callHeaders) {
|
|
1032
1101
|
const forwardedHeaders = Object.fromEntries(
|
|
1033
1102
|
Object.entries(step.callHeaders).map(([header, value]) => [
|
|
@@ -1067,8 +1136,8 @@ var getHeaders = ({
|
|
|
1067
1136
|
Object.entries(baseHeaders).map(([header, value]) => [header, [value]])
|
|
1068
1137
|
),
|
|
1069
1138
|
// to include telemetry headers:
|
|
1070
|
-
...
|
|
1071
|
-
Object.entries(getTelemetryHeaders(
|
|
1139
|
+
...telemetry2 ? Object.fromEntries(
|
|
1140
|
+
Object.entries(getTelemetryHeaders(telemetry2)).map(([header, value]) => [
|
|
1072
1141
|
header,
|
|
1073
1142
|
[value]
|
|
1074
1143
|
])
|
|
@@ -1077,8 +1146,7 @@ var getHeaders = ({
|
|
|
1077
1146
|
"Upstash-Workflow-Runid": [workflowRunId],
|
|
1078
1147
|
[WORKFLOW_INIT_HEADER]: ["false"],
|
|
1079
1148
|
[WORKFLOW_URL_HEADER]: [workflowUrl],
|
|
1080
|
-
"Upstash-Workflow-CallType": ["step"]
|
|
1081
|
-
"Content-Type": [contentType]
|
|
1149
|
+
"Upstash-Workflow-CallType": ["step"]
|
|
1082
1150
|
}
|
|
1083
1151
|
};
|
|
1084
1152
|
}
|
|
@@ -1124,10 +1192,10 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1124
1192
|
stepCount = 0;
|
|
1125
1193
|
planStepCount = 0;
|
|
1126
1194
|
executingStep = false;
|
|
1127
|
-
constructor(context, steps,
|
|
1195
|
+
constructor(context, steps, telemetry2, debug) {
|
|
1128
1196
|
this.context = context;
|
|
1129
1197
|
this.steps = steps;
|
|
1130
|
-
this.telemetry =
|
|
1198
|
+
this.telemetry = telemetry2;
|
|
1131
1199
|
this.debug = debug;
|
|
1132
1200
|
this.nonPlanStepCount = this.steps.filter((step) => !step.targetStep).length;
|
|
1133
1201
|
}
|
|
@@ -1373,7 +1441,23 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1373
1441
|
method: "POST",
|
|
1374
1442
|
parseResponseAsJson: false
|
|
1375
1443
|
});
|
|
1376
|
-
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);
|
|
1377
1461
|
}
|
|
1378
1462
|
const result = await this.context.qstashClient.batchJSON(
|
|
1379
1463
|
steps.map((singleStep, index) => {
|
|
@@ -2059,7 +2143,7 @@ var WorkflowContext = class {
|
|
|
2059
2143
|
initialPayload,
|
|
2060
2144
|
env,
|
|
2061
2145
|
retries,
|
|
2062
|
-
telemetry
|
|
2146
|
+
telemetry: telemetry2
|
|
2063
2147
|
}) {
|
|
2064
2148
|
this.qstashClient = qstashClient;
|
|
2065
2149
|
this.workflowRunId = workflowRunId;
|
|
@@ -2070,7 +2154,7 @@ var WorkflowContext = class {
|
|
|
2070
2154
|
this.requestPayload = initialPayload;
|
|
2071
2155
|
this.env = env ?? {};
|
|
2072
2156
|
this.retries = retries ?? DEFAULT_RETRIES;
|
|
2073
|
-
this.executor = new AutoExecutor(this, this.steps,
|
|
2157
|
+
this.executor = new AutoExecutor(this, this.steps, telemetry2, debug);
|
|
2074
2158
|
}
|
|
2075
2159
|
/**
|
|
2076
2160
|
* Executes a workflow step
|
|
@@ -2290,6 +2374,13 @@ var WorkflowContext = class {
|
|
|
2290
2374
|
return result;
|
|
2291
2375
|
}
|
|
2292
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
|
+
}
|
|
2293
2384
|
/**
|
|
2294
2385
|
* Cancel the current workflow run
|
|
2295
2386
|
*
|
|
@@ -2367,31 +2458,6 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
2367
2458
|
}
|
|
2368
2459
|
};
|
|
2369
2460
|
|
|
2370
|
-
// src/utils.ts
|
|
2371
|
-
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
2372
|
-
var NANOID_LENGTH = 21;
|
|
2373
|
-
function getRandomInt() {
|
|
2374
|
-
return Math.floor(Math.random() * NANOID_CHARS.length);
|
|
2375
|
-
}
|
|
2376
|
-
function nanoid() {
|
|
2377
|
-
return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
|
|
2378
|
-
}
|
|
2379
|
-
function getWorkflowRunId(id) {
|
|
2380
|
-
return `wfr_${id ?? nanoid()}`;
|
|
2381
|
-
}
|
|
2382
|
-
function decodeBase64(base64) {
|
|
2383
|
-
try {
|
|
2384
|
-
const binString = atob(base64);
|
|
2385
|
-
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
2386
|
-
return new TextDecoder().decode(intArray);
|
|
2387
|
-
} catch (error) {
|
|
2388
|
-
console.warn(
|
|
2389
|
-
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
2390
|
-
);
|
|
2391
|
-
return atob(base64);
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
2461
|
// src/serve/authorization.ts
|
|
2396
2462
|
var import_qstash8 = require("@upstash/qstash");
|
|
2397
2463
|
var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
|
|
@@ -2729,7 +2795,7 @@ var determineUrls = async (request, url, baseUrl, failureFunction, failureUrl, d
|
|
|
2729
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`;
|
|
2730
2796
|
|
|
2731
2797
|
// src/serve/index.ts
|
|
2732
|
-
var serveBase = (routeFunction,
|
|
2798
|
+
var serveBase = (routeFunction, telemetry2, options) => {
|
|
2733
2799
|
const {
|
|
2734
2800
|
qstashClient,
|
|
2735
2801
|
onStepFinish,
|
|
@@ -2745,7 +2811,7 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2745
2811
|
useJSONContent,
|
|
2746
2812
|
disableTelemetry
|
|
2747
2813
|
} = processOptions(options);
|
|
2748
|
-
|
|
2814
|
+
telemetry2 = disableTelemetry ? void 0 : telemetry2;
|
|
2749
2815
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
2750
2816
|
const handler = async (request) => {
|
|
2751
2817
|
await debug?.log("INFO", "ENDPOINT_START");
|
|
@@ -2803,7 +2869,7 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2803
2869
|
debug,
|
|
2804
2870
|
env,
|
|
2805
2871
|
retries,
|
|
2806
|
-
telemetry
|
|
2872
|
+
telemetry: telemetry2
|
|
2807
2873
|
});
|
|
2808
2874
|
const authCheck = await DisabledWorkflowContext.tryAuthentication(
|
|
2809
2875
|
routeFunction,
|
|
@@ -2826,7 +2892,7 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2826
2892
|
workflowUrl,
|
|
2827
2893
|
failureUrl: workflowFailureUrl,
|
|
2828
2894
|
retries,
|
|
2829
|
-
telemetry,
|
|
2895
|
+
telemetry: telemetry2,
|
|
2830
2896
|
debug
|
|
2831
2897
|
});
|
|
2832
2898
|
if (callReturnCheck.isErr()) {
|
|
@@ -2835,10 +2901,10 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2835
2901
|
});
|
|
2836
2902
|
throw callReturnCheck.error;
|
|
2837
2903
|
} else if (callReturnCheck.value === "continue-workflow") {
|
|
2838
|
-
const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry, debug }) : await triggerRouteFunction({
|
|
2904
|
+
const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry: telemetry2, debug }) : await triggerRouteFunction({
|
|
2839
2905
|
onStep: async () => routeFunction(workflowContext),
|
|
2840
|
-
onCleanup: async () => {
|
|
2841
|
-
await triggerWorkflowDelete(workflowContext, debug);
|
|
2906
|
+
onCleanup: async (result2) => {
|
|
2907
|
+
await triggerWorkflowDelete(workflowContext, result2, debug);
|
|
2842
2908
|
},
|
|
2843
2909
|
onCancel: async () => {
|
|
2844
2910
|
await makeCancelRequest(workflowContext.qstashClient.http, workflowRunId);
|
|
@@ -2870,25 +2936,128 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2870
2936
|
return { handler: safeHandler };
|
|
2871
2937
|
};
|
|
2872
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
|
+
|
|
2873
3024
|
// platforms/svelte.ts
|
|
3025
|
+
var telemetry = {
|
|
3026
|
+
sdk: SDK_TELEMETRY,
|
|
3027
|
+
framework: "svelte"
|
|
3028
|
+
};
|
|
2874
3029
|
var serve = (routeFunction, options) => {
|
|
2875
3030
|
const handler = async ({ request }) => {
|
|
2876
|
-
const { handler: serveHandler } = serveBase(
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
framework: "svelte"
|
|
2881
|
-
},
|
|
2882
|
-
{
|
|
2883
|
-
...options,
|
|
2884
|
-
useJSONContent: true
|
|
2885
|
-
}
|
|
2886
|
-
);
|
|
3031
|
+
const { handler: serveHandler } = serveBase(routeFunction, telemetry, {
|
|
3032
|
+
...options,
|
|
3033
|
+
useJSONContent: true
|
|
3034
|
+
});
|
|
2887
3035
|
return await serveHandler(request);
|
|
2888
3036
|
};
|
|
2889
3037
|
return { POST: handler };
|
|
2890
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
|
+
};
|
|
2891
3058
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2892
3059
|
0 && (module.exports = {
|
|
2893
|
-
|
|
3060
|
+
createWorkflow,
|
|
3061
|
+
serve,
|
|
3062
|
+
serveMany
|
|
2894
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 };
|