@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/nextjs.js
CHANGED
|
@@ -20,7 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// platforms/nextjs.ts
|
|
21
21
|
var nextjs_exports = {};
|
|
22
22
|
__export(nextjs_exports, {
|
|
23
|
+
createWorkflow: () => createWorkflow,
|
|
24
|
+
createWorkflowPagesRouter: () => createWorkflowPagesRouter,
|
|
23
25
|
serve: () => serve,
|
|
26
|
+
serveMany: () => serveMany,
|
|
27
|
+
serveManyPagesRouter: () => serveManyPagesRouter,
|
|
24
28
|
servePagesRouter: () => servePagesRouter
|
|
25
29
|
});
|
|
26
30
|
module.exports = __toCommonJS(nextjs_exports);
|
|
@@ -89,7 +93,7 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
89
93
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
90
94
|
var NO_CONCURRENCY = 1;
|
|
91
95
|
var DEFAULT_RETRIES = 3;
|
|
92
|
-
var VERSION = "v0.2.
|
|
96
|
+
var VERSION = "v0.2.7";
|
|
93
97
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
94
98
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
95
99
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
@@ -136,6 +140,31 @@ var formatWorkflowError = (error) => {
|
|
|
136
140
|
};
|
|
137
141
|
};
|
|
138
142
|
|
|
143
|
+
// src/utils.ts
|
|
144
|
+
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
145
|
+
var NANOID_LENGTH = 21;
|
|
146
|
+
function getRandomInt() {
|
|
147
|
+
return Math.floor(Math.random() * NANOID_CHARS.length);
|
|
148
|
+
}
|
|
149
|
+
function nanoid() {
|
|
150
|
+
return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
|
|
151
|
+
}
|
|
152
|
+
function getWorkflowRunId(id) {
|
|
153
|
+
return `wfr_${id ?? nanoid()}`;
|
|
154
|
+
}
|
|
155
|
+
function decodeBase64(base64) {
|
|
156
|
+
try {
|
|
157
|
+
const binString = atob(base64);
|
|
158
|
+
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
159
|
+
return new TextDecoder().decode(intArray);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.warn(
|
|
162
|
+
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
163
|
+
);
|
|
164
|
+
return atob(base64);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
139
168
|
// src/context/steps.ts
|
|
140
169
|
var BaseLazyStep = class {
|
|
141
170
|
stepName;
|
|
@@ -316,6 +345,41 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
316
345
|
});
|
|
317
346
|
}
|
|
318
347
|
};
|
|
348
|
+
var LazyInvokeStep = class extends BaseLazyStep {
|
|
349
|
+
stepType = "Invoke";
|
|
350
|
+
params;
|
|
351
|
+
constructor(stepName, { workflow, body, headers = {}, workflowRunId, retries }) {
|
|
352
|
+
super(stepName);
|
|
353
|
+
this.params = {
|
|
354
|
+
workflow,
|
|
355
|
+
body,
|
|
356
|
+
headers,
|
|
357
|
+
workflowRunId: getWorkflowRunId(workflowRunId),
|
|
358
|
+
retries
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
getPlanStep(concurrent, targetStep) {
|
|
362
|
+
return {
|
|
363
|
+
stepId: 0,
|
|
364
|
+
stepName: this.stepName,
|
|
365
|
+
stepType: this.stepType,
|
|
366
|
+
concurrent,
|
|
367
|
+
targetStep
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* won't be used as it's the server who will add the result step
|
|
372
|
+
* in Invoke step.
|
|
373
|
+
*/
|
|
374
|
+
getResultStep(concurrent, stepId) {
|
|
375
|
+
return Promise.resolve({
|
|
376
|
+
stepId,
|
|
377
|
+
stepName: this.stepName,
|
|
378
|
+
stepType: this.stepType,
|
|
379
|
+
concurrent
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
};
|
|
319
383
|
|
|
320
384
|
// node_modules/neverthrow/dist/index.es.js
|
|
321
385
|
var defaultErrorConfig = {
|
|
@@ -740,7 +804,8 @@ var StepTypes = [
|
|
|
740
804
|
"SleepUntil",
|
|
741
805
|
"Call",
|
|
742
806
|
"Wait",
|
|
743
|
-
"Notify"
|
|
807
|
+
"Notify",
|
|
808
|
+
"Invoke"
|
|
744
809
|
];
|
|
745
810
|
|
|
746
811
|
// src/workflow-requests.ts
|
|
@@ -760,6 +825,9 @@ var triggerFirstInvocation = async ({
|
|
|
760
825
|
retries: workflowContext.retries,
|
|
761
826
|
telemetry
|
|
762
827
|
});
|
|
828
|
+
if (workflowContext.headers.get("content-type")) {
|
|
829
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
830
|
+
}
|
|
763
831
|
if (useJSONContent) {
|
|
764
832
|
headers["content-type"] = "application/json";
|
|
765
833
|
}
|
|
@@ -801,8 +869,8 @@ var triggerRouteFunction = async ({
|
|
|
801
869
|
debug
|
|
802
870
|
}) => {
|
|
803
871
|
try {
|
|
804
|
-
await onStep();
|
|
805
|
-
await onCleanup();
|
|
872
|
+
const result = await onStep();
|
|
873
|
+
await onCleanup(result);
|
|
806
874
|
return ok("workflow-finished");
|
|
807
875
|
} catch (error) {
|
|
808
876
|
const error_ = error;
|
|
@@ -823,14 +891,15 @@ var triggerRouteFunction = async ({
|
|
|
823
891
|
}
|
|
824
892
|
}
|
|
825
893
|
};
|
|
826
|
-
var triggerWorkflowDelete = async (workflowContext, debug, cancel = false) => {
|
|
894
|
+
var triggerWorkflowDelete = async (workflowContext, result, debug, cancel = false) => {
|
|
827
895
|
await debug?.log("SUBMIT", "SUBMIT_CLEANUP", {
|
|
828
896
|
deletedWorkflowRunId: workflowContext.workflowRunId
|
|
829
897
|
});
|
|
830
898
|
await workflowContext.qstashClient.http.request({
|
|
831
899
|
path: ["v2", "workflows", "runs", `${workflowContext.workflowRunId}?cancel=${cancel}`],
|
|
832
900
|
method: "DELETE",
|
|
833
|
-
parseResponseAsJson: false
|
|
901
|
+
parseResponseAsJson: false,
|
|
902
|
+
body: JSON.stringify(result)
|
|
834
903
|
});
|
|
835
904
|
await debug?.log(
|
|
836
905
|
"SUBMIT",
|
|
@@ -985,11 +1054,14 @@ var getHeaders = ({
|
|
|
985
1054
|
callTimeout,
|
|
986
1055
|
telemetry
|
|
987
1056
|
}) => {
|
|
1057
|
+
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
988
1058
|
const baseHeaders = {
|
|
989
1059
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
990
1060
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
991
1061
|
[WORKFLOW_URL_HEADER]: workflowUrl,
|
|
992
1062
|
[WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
|
|
1063
|
+
[WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
|
|
1064
|
+
"content-type": contentType,
|
|
993
1065
|
...telemetry ? getTelemetryHeaders(telemetry) : {}
|
|
994
1066
|
};
|
|
995
1067
|
if (!step?.callUrl) {
|
|
@@ -1004,6 +1076,9 @@ var getHeaders = ({
|
|
|
1004
1076
|
baseHeaders["Upstash-Failure-Callback"] = failureUrl;
|
|
1005
1077
|
}
|
|
1006
1078
|
}
|
|
1079
|
+
if (step?.stepType === "Invoke") {
|
|
1080
|
+
baseHeaders["upstash-workflow-invoke"] = "true";
|
|
1081
|
+
}
|
|
1007
1082
|
if (step?.callUrl) {
|
|
1008
1083
|
baseHeaders["Upstash-Retries"] = callRetries?.toString() ?? "0";
|
|
1009
1084
|
baseHeaders[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
|
|
@@ -1025,7 +1100,6 @@ var getHeaders = ({
|
|
|
1025
1100
|
baseHeaders[`Upstash-Failure-Callback-Forward-${header}`] = userHeaders.get(header);
|
|
1026
1101
|
}
|
|
1027
1102
|
}
|
|
1028
|
-
const contentType = (userHeaders ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
1029
1103
|
if (step?.callHeaders) {
|
|
1030
1104
|
const forwardedHeaders = Object.fromEntries(
|
|
1031
1105
|
Object.entries(step.callHeaders).map(([header, value]) => [
|
|
@@ -1075,8 +1149,7 @@ var getHeaders = ({
|
|
|
1075
1149
|
"Upstash-Workflow-Runid": [workflowRunId],
|
|
1076
1150
|
[WORKFLOW_INIT_HEADER]: ["false"],
|
|
1077
1151
|
[WORKFLOW_URL_HEADER]: [workflowUrl],
|
|
1078
|
-
"Upstash-Workflow-CallType": ["step"]
|
|
1079
|
-
"Content-Type": [contentType]
|
|
1152
|
+
"Upstash-Workflow-CallType": ["step"]
|
|
1080
1153
|
}
|
|
1081
1154
|
};
|
|
1082
1155
|
}
|
|
@@ -1371,7 +1444,23 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1371
1444
|
method: "POST",
|
|
1372
1445
|
parseResponseAsJson: false
|
|
1373
1446
|
});
|
|
1374
|
-
throw new WorkflowAbort(
|
|
1447
|
+
throw new WorkflowAbort(waitStep.stepName, waitStep);
|
|
1448
|
+
}
|
|
1449
|
+
if (steps.length === 1 && lazySteps[0] instanceof LazyInvokeStep) {
|
|
1450
|
+
const invokeStep = steps[0];
|
|
1451
|
+
const lazyInvokeStep = lazySteps[0];
|
|
1452
|
+
await lazyInvokeStep.params.workflow.callback(
|
|
1453
|
+
{
|
|
1454
|
+
body: lazyInvokeStep.params.body,
|
|
1455
|
+
headers: lazyInvokeStep.params.headers,
|
|
1456
|
+
workflowRunId: lazyInvokeStep.params.workflowRunId,
|
|
1457
|
+
workflow: lazyInvokeStep.params.workflow,
|
|
1458
|
+
retries: lazyInvokeStep.params.retries
|
|
1459
|
+
},
|
|
1460
|
+
invokeStep,
|
|
1461
|
+
this.context
|
|
1462
|
+
);
|
|
1463
|
+
throw new WorkflowAbort(invokeStep.stepName, invokeStep);
|
|
1375
1464
|
}
|
|
1376
1465
|
const result = await this.context.qstashClient.batchJSON(
|
|
1377
1466
|
steps.map((singleStep, index) => {
|
|
@@ -2288,6 +2377,13 @@ var WorkflowContext = class {
|
|
|
2288
2377
|
return result;
|
|
2289
2378
|
}
|
|
2290
2379
|
}
|
|
2380
|
+
async invoke(stepName, settings) {
|
|
2381
|
+
const result = await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
2382
|
+
return {
|
|
2383
|
+
...result,
|
|
2384
|
+
body: result.body ? JSON.parse(result.body) : void 0
|
|
2385
|
+
};
|
|
2386
|
+
}
|
|
2291
2387
|
/**
|
|
2292
2388
|
* Cancel the current workflow run
|
|
2293
2389
|
*
|
|
@@ -2365,31 +2461,6 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
2365
2461
|
}
|
|
2366
2462
|
};
|
|
2367
2463
|
|
|
2368
|
-
// src/utils.ts
|
|
2369
|
-
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
2370
|
-
var NANOID_LENGTH = 21;
|
|
2371
|
-
function getRandomInt() {
|
|
2372
|
-
return Math.floor(Math.random() * NANOID_CHARS.length);
|
|
2373
|
-
}
|
|
2374
|
-
function nanoid() {
|
|
2375
|
-
return Array.from({ length: NANOID_LENGTH }).map(() => NANOID_CHARS[getRandomInt()]).join("");
|
|
2376
|
-
}
|
|
2377
|
-
function getWorkflowRunId(id) {
|
|
2378
|
-
return `wfr_${id ?? nanoid()}`;
|
|
2379
|
-
}
|
|
2380
|
-
function decodeBase64(base64) {
|
|
2381
|
-
try {
|
|
2382
|
-
const binString = atob(base64);
|
|
2383
|
-
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
2384
|
-
return new TextDecoder().decode(intArray);
|
|
2385
|
-
} catch (error) {
|
|
2386
|
-
console.warn(
|
|
2387
|
-
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
2388
|
-
);
|
|
2389
|
-
return atob(base64);
|
|
2390
|
-
}
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
2464
|
// src/serve/authorization.ts
|
|
2394
2465
|
var import_qstash8 = require("@upstash/qstash");
|
|
2395
2466
|
var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
|
|
@@ -2835,8 +2906,8 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2835
2906
|
} else if (callReturnCheck.value === "continue-workflow") {
|
|
2836
2907
|
const result = isFirstInvocation ? await triggerFirstInvocation({ workflowContext, useJSONContent, telemetry, debug }) : await triggerRouteFunction({
|
|
2837
2908
|
onStep: async () => routeFunction(workflowContext),
|
|
2838
|
-
onCleanup: async () => {
|
|
2839
|
-
await triggerWorkflowDelete(workflowContext, debug);
|
|
2909
|
+
onCleanup: async (result2) => {
|
|
2910
|
+
await triggerWorkflowDelete(workflowContext, result2, debug);
|
|
2840
2911
|
},
|
|
2841
2912
|
onCancel: async () => {
|
|
2842
2913
|
await makeCancelRequest(workflowContext.qstashClient.http, workflowRunId);
|
|
@@ -2868,15 +2939,106 @@ var serveBase = (routeFunction, telemetry, options) => {
|
|
|
2868
2939
|
return { handler: safeHandler };
|
|
2869
2940
|
};
|
|
2870
2941
|
|
|
2942
|
+
// src/serve/serve-many.ts
|
|
2943
|
+
var serveManyBase = ({
|
|
2944
|
+
workflows,
|
|
2945
|
+
getWorkflowId
|
|
2946
|
+
}) => {
|
|
2947
|
+
const workflowIds = [];
|
|
2948
|
+
const workflowMap = Object.fromEntries(
|
|
2949
|
+
Object.entries(workflows).map((workflow) => {
|
|
2950
|
+
const workflowId = workflow[0];
|
|
2951
|
+
if (workflowIds.includes(workflowId)) {
|
|
2952
|
+
throw new WorkflowError(
|
|
2953
|
+
`Duplicate workflow name found: '${workflowId}'. Please set different workflow names in serveMany.`
|
|
2954
|
+
);
|
|
2955
|
+
}
|
|
2956
|
+
if (workflowId.includes("/")) {
|
|
2957
|
+
throw new WorkflowError(
|
|
2958
|
+
`Invalid workflow name found: '${workflowId}'. Workflow name cannot contain '/'.`
|
|
2959
|
+
);
|
|
2960
|
+
}
|
|
2961
|
+
workflowIds.push(workflowId);
|
|
2962
|
+
workflow[1].workflowId = workflowId;
|
|
2963
|
+
return [workflowId, workflow[1].handler];
|
|
2964
|
+
})
|
|
2965
|
+
);
|
|
2966
|
+
return {
|
|
2967
|
+
handler: async (...params) => {
|
|
2968
|
+
const pickedWorkflowId = getWorkflowId(...params);
|
|
2969
|
+
if (!pickedWorkflowId) {
|
|
2970
|
+
throw new WorkflowError(`Unexpected request in serveMany. workflowId not set. Please update the URL of your request.`);
|
|
2971
|
+
}
|
|
2972
|
+
const workflow = workflowMap[pickedWorkflowId];
|
|
2973
|
+
if (!workflow) {
|
|
2974
|
+
throw new WorkflowError(`No workflows in serveMany found for '${pickedWorkflowId}'. Please update the URL of your request.`);
|
|
2975
|
+
}
|
|
2976
|
+
return await workflow(...params);
|
|
2977
|
+
}
|
|
2978
|
+
};
|
|
2979
|
+
};
|
|
2980
|
+
var createInvokeCallback = (telemetry) => {
|
|
2981
|
+
const invokeCallback = async (settings, invokeStep, context) => {
|
|
2982
|
+
const { body, workflow, headers = {}, workflowRunId = getWorkflowRunId(), retries } = settings;
|
|
2983
|
+
const { workflowId } = workflow;
|
|
2984
|
+
if (!workflowId) {
|
|
2985
|
+
throw new WorkflowError("You can only invoke workflow which has a workflowId");
|
|
2986
|
+
}
|
|
2987
|
+
const { headers: invokerHeaders } = getHeaders({
|
|
2988
|
+
initHeaderValue: "false",
|
|
2989
|
+
workflowRunId: context.workflowRunId,
|
|
2990
|
+
workflowUrl: context.url,
|
|
2991
|
+
userHeaders: context.headers,
|
|
2992
|
+
failureUrl: context.failureUrl,
|
|
2993
|
+
retries: context.retries,
|
|
2994
|
+
telemetry
|
|
2995
|
+
});
|
|
2996
|
+
invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
|
|
2997
|
+
const newUrl = context.url.replace(/[^/]+$/, workflowId);
|
|
2998
|
+
const { headers: triggerHeaders } = getHeaders({
|
|
2999
|
+
initHeaderValue: "true",
|
|
3000
|
+
workflowRunId,
|
|
3001
|
+
workflowUrl: newUrl,
|
|
3002
|
+
userHeaders: new Headers(headers),
|
|
3003
|
+
retries,
|
|
3004
|
+
telemetry
|
|
3005
|
+
});
|
|
3006
|
+
triggerHeaders["Upstash-Workflow-Invoke"] = "true";
|
|
3007
|
+
const request = {
|
|
3008
|
+
body: JSON.stringify(body),
|
|
3009
|
+
headers: Object.fromEntries(
|
|
3010
|
+
Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
|
|
3011
|
+
),
|
|
3012
|
+
workflowRunId,
|
|
3013
|
+
workflowUrl: context.url,
|
|
3014
|
+
step: invokeStep
|
|
3015
|
+
};
|
|
3016
|
+
await context.qstashClient.publish({
|
|
3017
|
+
headers: triggerHeaders,
|
|
3018
|
+
method: "POST",
|
|
3019
|
+
body: JSON.stringify(request),
|
|
3020
|
+
url: newUrl
|
|
3021
|
+
});
|
|
3022
|
+
return void 0;
|
|
3023
|
+
};
|
|
3024
|
+
return invokeCallback;
|
|
3025
|
+
};
|
|
3026
|
+
|
|
2871
3027
|
// platforms/nextjs.ts
|
|
3028
|
+
var appTelemetry = {
|
|
3029
|
+
sdk: SDK_TELEMETRY,
|
|
3030
|
+
framework: "nextjs",
|
|
3031
|
+
runtime: `node@${process.version}`
|
|
3032
|
+
};
|
|
3033
|
+
var pagesTelemetry = {
|
|
3034
|
+
sdk: SDK_TELEMETRY,
|
|
3035
|
+
framework: "nextjs-pages",
|
|
3036
|
+
runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
|
|
3037
|
+
};
|
|
2872
3038
|
var serve = (routeFunction, options) => {
|
|
2873
3039
|
const { handler: serveHandler } = serveBase(
|
|
2874
3040
|
routeFunction,
|
|
2875
|
-
|
|
2876
|
-
sdk: SDK_TELEMETRY,
|
|
2877
|
-
framework: "nextjs",
|
|
2878
|
-
runtime: `node@${process.version}`
|
|
2879
|
-
},
|
|
3041
|
+
appTelemetry,
|
|
2880
3042
|
options
|
|
2881
3043
|
);
|
|
2882
3044
|
return {
|
|
@@ -2885,16 +3047,27 @@ var serve = (routeFunction, options) => {
|
|
|
2885
3047
|
}
|
|
2886
3048
|
};
|
|
2887
3049
|
};
|
|
3050
|
+
var createWorkflow = (...params) => {
|
|
3051
|
+
const { POST } = serve(...params);
|
|
3052
|
+
return {
|
|
3053
|
+
callback: createInvokeCallback(appTelemetry),
|
|
3054
|
+
handler: POST,
|
|
3055
|
+
workflowId: void 0
|
|
3056
|
+
};
|
|
3057
|
+
};
|
|
3058
|
+
var serveMany = (workflows) => {
|
|
3059
|
+
return {
|
|
3060
|
+
POST: serveManyBase({
|
|
3061
|
+
workflows,
|
|
3062
|
+
getWorkflowId(params) {
|
|
3063
|
+
const components = params.url.split("/");
|
|
3064
|
+
return components[components.length - 1];
|
|
3065
|
+
}
|
|
3066
|
+
}).handler
|
|
3067
|
+
};
|
|
3068
|
+
};
|
|
2888
3069
|
var servePagesRouter = (routeFunction, options) => {
|
|
2889
|
-
const { handler: serveHandler } = serveBase(
|
|
2890
|
-
routeFunction,
|
|
2891
|
-
{
|
|
2892
|
-
sdk: SDK_TELEMETRY,
|
|
2893
|
-
framework: "nextjs-pages",
|
|
2894
|
-
runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
|
|
2895
|
-
},
|
|
2896
|
-
options
|
|
2897
|
-
);
|
|
3070
|
+
const { handler: serveHandler } = serveBase(routeFunction, pagesTelemetry, options);
|
|
2898
3071
|
const handler = async (request_, res) => {
|
|
2899
3072
|
if (request_.method?.toUpperCase() !== "POST") {
|
|
2900
3073
|
res.status(405).json("Only POST requests are allowed in worklfows");
|
|
@@ -2913,10 +3086,37 @@ var servePagesRouter = (routeFunction, options) => {
|
|
|
2913
3086
|
const response = await serveHandler(request);
|
|
2914
3087
|
res.status(response.status).json(await response.json());
|
|
2915
3088
|
};
|
|
2916
|
-
return {
|
|
3089
|
+
return {
|
|
3090
|
+
handler
|
|
3091
|
+
};
|
|
3092
|
+
};
|
|
3093
|
+
var createWorkflowPagesRouter = (...params) => {
|
|
3094
|
+
const { handler } = servePagesRouter(...params);
|
|
3095
|
+
return {
|
|
3096
|
+
callback: createInvokeCallback(pagesTelemetry),
|
|
3097
|
+
handler,
|
|
3098
|
+
workflowId: void 0
|
|
3099
|
+
};
|
|
3100
|
+
};
|
|
3101
|
+
var serveManyPagesRouter = (workflows) => {
|
|
3102
|
+
return serveManyBase({
|
|
3103
|
+
workflows,
|
|
3104
|
+
getWorkflowId(request_) {
|
|
3105
|
+
const protocol = request_.headers["x-forwarded-proto"];
|
|
3106
|
+
const host = request_.headers.host;
|
|
3107
|
+
const baseUrl = `${protocol}://${host}`;
|
|
3108
|
+
const url = `${baseUrl}${request_.url}`;
|
|
3109
|
+
const components = url.split("/");
|
|
3110
|
+
return components[components.length - 1];
|
|
3111
|
+
}
|
|
3112
|
+
});
|
|
2917
3113
|
};
|
|
2918
3114
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2919
3115
|
0 && (module.exports = {
|
|
3116
|
+
createWorkflow,
|
|
3117
|
+
createWorkflowPagesRouter,
|
|
2920
3118
|
serve,
|
|
3119
|
+
serveMany,
|
|
3120
|
+
serveManyPagesRouter,
|
|
2921
3121
|
servePagesRouter
|
|
2922
3122
|
});
|
package/nextjs.mjs
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
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/nextjs.ts
|
|
11
|
+
var appTelemetry = {
|
|
12
|
+
sdk: SDK_TELEMETRY,
|
|
13
|
+
framework: "nextjs",
|
|
14
|
+
runtime: `node@${process.version}`
|
|
15
|
+
};
|
|
16
|
+
var pagesTelemetry = {
|
|
17
|
+
sdk: SDK_TELEMETRY,
|
|
18
|
+
framework: "nextjs-pages",
|
|
19
|
+
runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
|
|
20
|
+
};
|
|
7
21
|
var serve = (routeFunction, options) => {
|
|
8
22
|
const { handler: serveHandler } = serveBase(
|
|
9
23
|
routeFunction,
|
|
10
|
-
|
|
11
|
-
sdk: SDK_TELEMETRY,
|
|
12
|
-
framework: "nextjs",
|
|
13
|
-
runtime: `node@${process.version}`
|
|
14
|
-
},
|
|
24
|
+
appTelemetry,
|
|
15
25
|
options
|
|
16
26
|
);
|
|
17
27
|
return {
|
|
@@ -20,16 +30,27 @@ var serve = (routeFunction, options) => {
|
|
|
20
30
|
}
|
|
21
31
|
};
|
|
22
32
|
};
|
|
33
|
+
var createWorkflow = (...params) => {
|
|
34
|
+
const { POST } = serve(...params);
|
|
35
|
+
return {
|
|
36
|
+
callback: createInvokeCallback(appTelemetry),
|
|
37
|
+
handler: POST,
|
|
38
|
+
workflowId: void 0
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
var serveMany = (workflows) => {
|
|
42
|
+
return {
|
|
43
|
+
POST: serveManyBase({
|
|
44
|
+
workflows,
|
|
45
|
+
getWorkflowId(params) {
|
|
46
|
+
const components = params.url.split("/");
|
|
47
|
+
return components[components.length - 1];
|
|
48
|
+
}
|
|
49
|
+
}).handler
|
|
50
|
+
};
|
|
51
|
+
};
|
|
23
52
|
var servePagesRouter = (routeFunction, options) => {
|
|
24
|
-
const { handler: serveHandler } = serveBase(
|
|
25
|
-
routeFunction,
|
|
26
|
-
{
|
|
27
|
-
sdk: SDK_TELEMETRY,
|
|
28
|
-
framework: "nextjs-pages",
|
|
29
|
-
runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
|
|
30
|
-
},
|
|
31
|
-
options
|
|
32
|
-
);
|
|
53
|
+
const { handler: serveHandler } = serveBase(routeFunction, pagesTelemetry, options);
|
|
33
54
|
const handler = async (request_, res) => {
|
|
34
55
|
if (request_.method?.toUpperCase() !== "POST") {
|
|
35
56
|
res.status(405).json("Only POST requests are allowed in worklfows");
|
|
@@ -48,9 +69,36 @@ var servePagesRouter = (routeFunction, options) => {
|
|
|
48
69
|
const response = await serveHandler(request);
|
|
49
70
|
res.status(response.status).json(await response.json());
|
|
50
71
|
};
|
|
51
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
handler
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var createWorkflowPagesRouter = (...params) => {
|
|
77
|
+
const { handler } = servePagesRouter(...params);
|
|
78
|
+
return {
|
|
79
|
+
callback: createInvokeCallback(pagesTelemetry),
|
|
80
|
+
handler,
|
|
81
|
+
workflowId: void 0
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
var serveManyPagesRouter = (workflows) => {
|
|
85
|
+
return serveManyBase({
|
|
86
|
+
workflows,
|
|
87
|
+
getWorkflowId(request_) {
|
|
88
|
+
const protocol = request_.headers["x-forwarded-proto"];
|
|
89
|
+
const host = request_.headers.host;
|
|
90
|
+
const baseUrl = `${protocol}://${host}`;
|
|
91
|
+
const url = `${baseUrl}${request_.url}`;
|
|
92
|
+
const components = url.split("/");
|
|
93
|
+
return components[components.length - 1];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
52
96
|
};
|
|
53
97
|
export {
|
|
98
|
+
createWorkflow,
|
|
99
|
+
createWorkflowPagesRouter,
|
|
54
100
|
serve,
|
|
101
|
+
serveMany,
|
|
102
|
+
serveManyPagesRouter,
|
|
55
103
|
servePagesRouter
|
|
56
104
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@upstash/workflow","version":"v0.2.
|
|
1
|
+
{"name":"@upstash/workflow","version":"v0.2.8-rc-invoke","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.20","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@ai-sdk/openai":"^1.0.15","@upstash/qstash":"^2.7.20","ai":"^4.0.30","zod":"^3.24.1"},"directories":{"example":"examples"}}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as InvokableWorkflow } from './types-C7Y7WUQd.mjs';
|
|
2
|
+
|
|
3
|
+
declare const serveManyBase: <TServe extends (...params: any[]) => any, THandlerParams extends Parameters<TServe> = Parameters<TServe>, TInvokableWorkflow extends InvokableWorkflow<any, any, THandlerParams> = InvokableWorkflow<any, any, THandlerParams>>({ workflows, getWorkflowId, }: {
|
|
4
|
+
workflows: Record<string, TInvokableWorkflow>;
|
|
5
|
+
getWorkflowId: (...params: THandlerParams) => string;
|
|
6
|
+
}) => {
|
|
7
|
+
handler: (...params: THandlerParams) => Promise<any>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { serveManyBase as s };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as InvokableWorkflow } from './types-C7Y7WUQd.js';
|
|
2
|
+
|
|
3
|
+
declare const serveManyBase: <TServe extends (...params: any[]) => any, THandlerParams extends Parameters<TServe> = Parameters<TServe>, TInvokableWorkflow extends InvokableWorkflow<any, any, THandlerParams> = InvokableWorkflow<any, any, THandlerParams>>({ workflows, getWorkflowId, }: {
|
|
4
|
+
workflows: Record<string, TInvokableWorkflow>;
|
|
5
|
+
getWorkflowId: (...params: THandlerParams) => string;
|
|
6
|
+
}) => {
|
|
7
|
+
handler: (...params: THandlerParams) => Promise<any>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { serveManyBase as s };
|
package/solidjs.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { APIEvent } from '@solidjs/start/server';
|
|
2
|
-
import { R as RouteFunction, j as PublicServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, j as PublicServeOptions } from './types-C7Y7WUQd.mjs';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|
|
6
6
|
import '@ai-sdk/openai';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Serve method to serve a Upstash Workflow in a
|
|
9
|
+
* Serve method to serve a Upstash Workflow in a SolidJS project
|
|
10
10
|
*
|
|
11
11
|
* See for options https://upstash.com/docs/qstash/workflows/basics/serve
|
|
12
12
|
*
|
|
@@ -14,7 +14,7 @@ import '@ai-sdk/openai';
|
|
|
14
14
|
* @param options workflow options
|
|
15
15
|
* @returns
|
|
16
16
|
*/
|
|
17
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: PublicServeOptions<TInitialPayload>) => {
|
|
17
|
+
declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => {
|
|
18
18
|
POST: (event: APIEvent) => Promise<Response>;
|
|
19
19
|
};
|
|
20
20
|
|
package/solidjs.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { APIEvent } from '@solidjs/start/server';
|
|
2
|
-
import { R as RouteFunction, j as PublicServeOptions } from './types-
|
|
2
|
+
import { R as RouteFunction, j as PublicServeOptions } from './types-C7Y7WUQd.js';
|
|
3
3
|
import '@upstash/qstash';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import 'ai';
|
|
6
6
|
import '@ai-sdk/openai';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Serve method to serve a Upstash Workflow in a
|
|
9
|
+
* Serve method to serve a Upstash Workflow in a SolidJS project
|
|
10
10
|
*
|
|
11
11
|
* See for options https://upstash.com/docs/qstash/workflows/basics/serve
|
|
12
12
|
*
|
|
@@ -14,7 +14,7 @@ import '@ai-sdk/openai';
|
|
|
14
14
|
* @param options workflow options
|
|
15
15
|
* @returns
|
|
16
16
|
*/
|
|
17
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: PublicServeOptions<TInitialPayload>) => {
|
|
17
|
+
declare const serve: <TInitialPayload = unknown, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => {
|
|
18
18
|
POST: (event: APIEvent) => Promise<Response>;
|
|
19
19
|
};
|
|
20
20
|
|