@upstash/workflow 1.3.0 → 1.3.1
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 +2 -2
- package/astro.d.ts +2 -2
- package/astro.js +50 -10
- package/astro.mjs +1 -1
- package/{chunk-G24J5PCC.mjs → chunk-CWCCIOXR.mjs} +53 -10
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +50 -10
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +50 -10
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +50 -10
- package/h3.mjs +1 -1
- package/hono.d.mts +2 -2
- package/hono.d.ts +2 -2
- package/hono.js +50 -10
- package/hono.mjs +1 -1
- package/index.d.mts +24 -5
- package/index.d.ts +24 -5
- package/index.js +53 -11
- package/index.mjs +8 -3
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +50 -10
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/react-router.d.mts +2 -2
- package/react-router.d.ts +2 -2
- package/react-router.js +50 -10
- package/react-router.mjs +1 -1
- package/{serve-many-D3D9uE4u.d.mts → serve-many-CG3BFvO3.d.mts} +1 -1
- package/{serve-many-kPOasiyb.d.ts → serve-many-iJF1IUXk.d.ts} +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +50 -10
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +50 -10
- package/svelte.mjs +1 -1
- package/tanstack.d.mts +2 -2
- package/tanstack.d.ts +2 -2
- package/tanstack.js +50 -10
- package/tanstack.mjs +1 -1
- package/{types-B_E1VAK6.d.ts → types-CekOpKvz.d.mts} +14 -6
- package/{types-B_E1VAK6.d.mts → types-CekOpKvz.d.ts} +14 -6
package/tanstack.js
CHANGED
|
@@ -216,6 +216,31 @@ var import_qstash4 = require("@upstash/qstash");
|
|
|
216
216
|
// src/utils.ts
|
|
217
217
|
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
218
218
|
var NANOID_LENGTH = 21;
|
|
219
|
+
var RESOURCE_NAME_PATTERN = /^[a-zA-Z0-9\-_.]+$/;
|
|
220
|
+
function validateLabel(label) {
|
|
221
|
+
if (label === void 0) return;
|
|
222
|
+
const labels = Array.isArray(label) ? label : [label];
|
|
223
|
+
if (labels.length === 0) {
|
|
224
|
+
throw new WorkflowNonRetryableError("Invalid label: label array must not be empty.");
|
|
225
|
+
}
|
|
226
|
+
for (const value of labels) {
|
|
227
|
+
if (!RESOURCE_NAME_PATTERN.test(value)) {
|
|
228
|
+
throw new WorkflowNonRetryableError(
|
|
229
|
+
`Invalid label "${value}": must be alphanumeric, hyphen, underscore, or period.`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function serializeLabel(label) {
|
|
235
|
+
return Array.isArray(label) ? label.join(",") : label;
|
|
236
|
+
}
|
|
237
|
+
function validateFlowControl(flowControl) {
|
|
238
|
+
if (flowControl?.key !== void 0 && !RESOURCE_NAME_PATTERN.test(flowControl.key)) {
|
|
239
|
+
throw new WorkflowNonRetryableError(
|
|
240
|
+
`Invalid flow control key "${flowControl.key}": must be alphanumeric, hyphen, underscore, or period.`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
219
244
|
function getRandomInt() {
|
|
220
245
|
return Math.floor(Math.random() * NANOID_CHARS.length);
|
|
221
246
|
}
|
|
@@ -751,8 +776,8 @@ var triggerFirstInvocation = async (params) => {
|
|
|
751
776
|
if (unknownSdk) {
|
|
752
777
|
headers[WORKFLOW_UNKOWN_SDK_TRIGGER_HEADER] = "true";
|
|
753
778
|
}
|
|
754
|
-
if (workflowContext.
|
|
755
|
-
headers[WORKFLOW_LABEL_HEADER] = workflowContext.
|
|
779
|
+
if (workflowContext.labels.length > 0) {
|
|
780
|
+
headers[WORKFLOW_LABEL_HEADER] = serializeLabel(workflowContext.labels);
|
|
756
781
|
}
|
|
757
782
|
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
758
783
|
return {
|
|
@@ -1554,8 +1579,9 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
1554
1579
|
});
|
|
1555
1580
|
triggerHeaders["Upstash-Workflow-Invoke"] = "true";
|
|
1556
1581
|
if (label) {
|
|
1557
|
-
|
|
1558
|
-
triggerHeaders[
|
|
1582
|
+
const labelHeader = serializeLabel(label);
|
|
1583
|
+
triggerHeaders[WORKFLOW_LABEL_HEADER] = labelHeader;
|
|
1584
|
+
triggerHeaders[`upstash-forward-${WORKFLOW_LABEL_HEADER}`] = labelHeader;
|
|
1559
1585
|
}
|
|
1560
1586
|
return { headers: triggerHeaders, contentType };
|
|
1561
1587
|
}
|
|
@@ -2696,9 +2722,10 @@ var WorkflowContext = class {
|
|
|
2696
2722
|
*/
|
|
2697
2723
|
env;
|
|
2698
2724
|
/**
|
|
2699
|
-
*
|
|
2725
|
+
* Labels attached to the workflow run.
|
|
2700
2726
|
*
|
|
2701
|
-
* Can be used to filter the workflow run logs.
|
|
2727
|
+
* Can be used to filter the workflow run logs. A run can have multiple
|
|
2728
|
+
* labels when triggered with `label: string[]`.
|
|
2702
2729
|
*
|
|
2703
2730
|
* Can be set by passing a `label` parameter when triggering the workflow
|
|
2704
2731
|
* with `client.trigger`:
|
|
@@ -2706,11 +2733,20 @@ var WorkflowContext = class {
|
|
|
2706
2733
|
* ```ts
|
|
2707
2734
|
* await client.trigger({
|
|
2708
2735
|
* url: "https://workflow-endpoint.com",
|
|
2709
|
-
* label: "
|
|
2736
|
+
* label: ["label-1", "label-2"]
|
|
2710
2737
|
* });
|
|
2711
2738
|
* ```
|
|
2712
2739
|
*/
|
|
2713
|
-
|
|
2740
|
+
labels;
|
|
2741
|
+
/**
|
|
2742
|
+
* Label of the workflow run.
|
|
2743
|
+
*
|
|
2744
|
+
* @deprecated Use `labels` instead. When a run has multiple labels, this
|
|
2745
|
+
* only returns the first one.
|
|
2746
|
+
*/
|
|
2747
|
+
get label() {
|
|
2748
|
+
return this.labels[0];
|
|
2749
|
+
}
|
|
2714
2750
|
/**
|
|
2715
2751
|
* Number of times QStash has retried delivering the current request.
|
|
2716
2752
|
*
|
|
@@ -2741,7 +2777,7 @@ var WorkflowContext = class {
|
|
|
2741
2777
|
this.headers = headers;
|
|
2742
2778
|
this.requestPayload = initialPayload;
|
|
2743
2779
|
this.env = env ?? {};
|
|
2744
|
-
this.
|
|
2780
|
+
this.labels = label === void 0 ? [] : Array.isArray(label) ? label : label ? label.split(",") : [];
|
|
2745
2781
|
this.retried = retried ?? 0;
|
|
2746
2782
|
const middlewareManagerInstance = middlewareManager ?? new MiddlewareManager([]);
|
|
2747
2783
|
middlewareManagerInstance.assignContext(this);
|
|
@@ -2822,8 +2858,10 @@ var WorkflowContext = class {
|
|
|
2822
2858
|
await this.addStep(new LazySleepUntilStep(this, stepName, time));
|
|
2823
2859
|
}
|
|
2824
2860
|
async call(stepName, settings) {
|
|
2861
|
+
validateFlowControl(settings.flowControl);
|
|
2825
2862
|
let callStep;
|
|
2826
2863
|
if ("workflow" in settings) {
|
|
2864
|
+
validateLabel(settings.label);
|
|
2827
2865
|
const url = getNewUrlFromWorkflowId(this.url, settings.workflow.workflowId);
|
|
2828
2866
|
const stringBody = typeof settings.body === "string" ? settings.body : settings.body === void 0 ? void 0 : JSON.stringify(settings.body);
|
|
2829
2867
|
callStep = new LazyCallStep({
|
|
@@ -2931,6 +2969,8 @@ var WorkflowContext = class {
|
|
|
2931
2969
|
);
|
|
2932
2970
|
}
|
|
2933
2971
|
async invoke(stepName, settings) {
|
|
2972
|
+
validateLabel(settings.label);
|
|
2973
|
+
validateFlowControl(settings.flowControl);
|
|
2934
2974
|
return await this.addStep(
|
|
2935
2975
|
new LazyInvokeStep(this, stepName, settings)
|
|
2936
2976
|
);
|
|
@@ -3016,7 +3056,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
3016
3056
|
url: context.url,
|
|
3017
3057
|
initialPayload: context.requestPayload,
|
|
3018
3058
|
env: context.env,
|
|
3019
|
-
label: context.
|
|
3059
|
+
label: context.labels,
|
|
3020
3060
|
retried: context.retried
|
|
3021
3061
|
});
|
|
3022
3062
|
try {
|
package/tanstack.mjs
CHANGED
|
@@ -685,9 +685,10 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
685
685
|
*/
|
|
686
686
|
readonly env: Record<string, string | undefined>;
|
|
687
687
|
/**
|
|
688
|
-
*
|
|
688
|
+
* Labels attached to the workflow run.
|
|
689
689
|
*
|
|
690
|
-
* Can be used to filter the workflow run logs.
|
|
690
|
+
* Can be used to filter the workflow run logs. A run can have multiple
|
|
691
|
+
* labels when triggered with `label: string[]`.
|
|
691
692
|
*
|
|
692
693
|
* Can be set by passing a `label` parameter when triggering the workflow
|
|
693
694
|
* with `client.trigger`:
|
|
@@ -695,11 +696,18 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
695
696
|
* ```ts
|
|
696
697
|
* await client.trigger({
|
|
697
698
|
* url: "https://workflow-endpoint.com",
|
|
698
|
-
* label: "
|
|
699
|
+
* label: ["label-1", "label-2"]
|
|
699
700
|
* });
|
|
700
701
|
* ```
|
|
701
702
|
*/
|
|
702
|
-
readonly
|
|
703
|
+
readonly labels: string[];
|
|
704
|
+
/**
|
|
705
|
+
* Label of the workflow run.
|
|
706
|
+
*
|
|
707
|
+
* @deprecated Use `labels` instead. When a run has multiple labels, this
|
|
708
|
+
* only returns the first one.
|
|
709
|
+
*/
|
|
710
|
+
get label(): string | undefined;
|
|
703
711
|
/**
|
|
704
712
|
* Number of times QStash has retried delivering the current request.
|
|
705
713
|
*
|
|
@@ -718,7 +726,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
718
726
|
env?: Record<string, string | undefined>;
|
|
719
727
|
telemetry?: Telemetry;
|
|
720
728
|
invokeCount?: number;
|
|
721
|
-
label?: string;
|
|
729
|
+
label?: string | string[];
|
|
722
730
|
retried?: number;
|
|
723
731
|
middlewareManager?: MiddlewareManager<TInitialPayload>;
|
|
724
732
|
});
|
|
@@ -1311,7 +1319,7 @@ type InvokeWorkflowRequest = {
|
|
|
1311
1319
|
type LazyInvokeStepParams<TInitiaPayload, TResult> = {
|
|
1312
1320
|
workflow: InvokableWorkflow<TInitiaPayload, TResult>;
|
|
1313
1321
|
workflowRunId?: string;
|
|
1314
|
-
label?: string;
|
|
1322
|
+
label?: string | string[];
|
|
1315
1323
|
} & Pick<CallSettings, "retries" | "headers" | "flowControl" | "retryDelay"> & (TInitiaPayload extends undefined ? {
|
|
1316
1324
|
body?: undefined;
|
|
1317
1325
|
} : {
|
|
@@ -685,9 +685,10 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
685
685
|
*/
|
|
686
686
|
readonly env: Record<string, string | undefined>;
|
|
687
687
|
/**
|
|
688
|
-
*
|
|
688
|
+
* Labels attached to the workflow run.
|
|
689
689
|
*
|
|
690
|
-
* Can be used to filter the workflow run logs.
|
|
690
|
+
* Can be used to filter the workflow run logs. A run can have multiple
|
|
691
|
+
* labels when triggered with `label: string[]`.
|
|
691
692
|
*
|
|
692
693
|
* Can be set by passing a `label` parameter when triggering the workflow
|
|
693
694
|
* with `client.trigger`:
|
|
@@ -695,11 +696,18 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
695
696
|
* ```ts
|
|
696
697
|
* await client.trigger({
|
|
697
698
|
* url: "https://workflow-endpoint.com",
|
|
698
|
-
* label: "
|
|
699
|
+
* label: ["label-1", "label-2"]
|
|
699
700
|
* });
|
|
700
701
|
* ```
|
|
701
702
|
*/
|
|
702
|
-
readonly
|
|
703
|
+
readonly labels: string[];
|
|
704
|
+
/**
|
|
705
|
+
* Label of the workflow run.
|
|
706
|
+
*
|
|
707
|
+
* @deprecated Use `labels` instead. When a run has multiple labels, this
|
|
708
|
+
* only returns the first one.
|
|
709
|
+
*/
|
|
710
|
+
get label(): string | undefined;
|
|
703
711
|
/**
|
|
704
712
|
* Number of times QStash has retried delivering the current request.
|
|
705
713
|
*
|
|
@@ -718,7 +726,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
718
726
|
env?: Record<string, string | undefined>;
|
|
719
727
|
telemetry?: Telemetry;
|
|
720
728
|
invokeCount?: number;
|
|
721
|
-
label?: string;
|
|
729
|
+
label?: string | string[];
|
|
722
730
|
retried?: number;
|
|
723
731
|
middlewareManager?: MiddlewareManager<TInitialPayload>;
|
|
724
732
|
});
|
|
@@ -1311,7 +1319,7 @@ type InvokeWorkflowRequest = {
|
|
|
1311
1319
|
type LazyInvokeStepParams<TInitiaPayload, TResult> = {
|
|
1312
1320
|
workflow: InvokableWorkflow<TInitiaPayload, TResult>;
|
|
1313
1321
|
workflowRunId?: string;
|
|
1314
|
-
label?: string;
|
|
1322
|
+
label?: string | string[];
|
|
1315
1323
|
} & Pick<CallSettings, "retries" | "headers" | "flowControl" | "retryDelay"> & (TInitiaPayload extends undefined ? {
|
|
1316
1324
|
body?: undefined;
|
|
1317
1325
|
} : {
|