@workflow/world-testing 4.0.1-beta.6 → 4.0.1-beta.7
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/dist/.well-known/workflow/v1/flow.js +233 -80
- package/dist/.well-known/workflow/v1/flow.js.map +1 -1
- package/dist/.well-known/workflow/v1/manifest.debug.json +5 -8
- package/dist/.well-known/workflow/v1/step.js +100 -88
- package/dist/.well-known/workflow/v1/step.js.map +1 -1
- package/package.json +4 -4
|
@@ -1156,43 +1156,43 @@ var require_ms = __commonJS({
|
|
|
1156
1156
|
}
|
|
1157
1157
|
}
|
|
1158
1158
|
__name(parse4, "parse");
|
|
1159
|
-
function fmtShort(
|
|
1160
|
-
var msAbs = Math.abs(
|
|
1159
|
+
function fmtShort(ms3) {
|
|
1160
|
+
var msAbs = Math.abs(ms3);
|
|
1161
1161
|
if (msAbs >= d) {
|
|
1162
|
-
return Math.round(
|
|
1162
|
+
return Math.round(ms3 / d) + "d";
|
|
1163
1163
|
}
|
|
1164
1164
|
if (msAbs >= h) {
|
|
1165
|
-
return Math.round(
|
|
1165
|
+
return Math.round(ms3 / h) + "h";
|
|
1166
1166
|
}
|
|
1167
1167
|
if (msAbs >= m) {
|
|
1168
|
-
return Math.round(
|
|
1168
|
+
return Math.round(ms3 / m) + "m";
|
|
1169
1169
|
}
|
|
1170
1170
|
if (msAbs >= s) {
|
|
1171
|
-
return Math.round(
|
|
1171
|
+
return Math.round(ms3 / s) + "s";
|
|
1172
1172
|
}
|
|
1173
|
-
return
|
|
1173
|
+
return ms3 + "ms";
|
|
1174
1174
|
}
|
|
1175
1175
|
__name(fmtShort, "fmtShort");
|
|
1176
|
-
function fmtLong(
|
|
1177
|
-
var msAbs = Math.abs(
|
|
1176
|
+
function fmtLong(ms3) {
|
|
1177
|
+
var msAbs = Math.abs(ms3);
|
|
1178
1178
|
if (msAbs >= d) {
|
|
1179
|
-
return plural(
|
|
1179
|
+
return plural(ms3, msAbs, d, "day");
|
|
1180
1180
|
}
|
|
1181
1181
|
if (msAbs >= h) {
|
|
1182
|
-
return plural(
|
|
1182
|
+
return plural(ms3, msAbs, h, "hour");
|
|
1183
1183
|
}
|
|
1184
1184
|
if (msAbs >= m) {
|
|
1185
|
-
return plural(
|
|
1185
|
+
return plural(ms3, msAbs, m, "minute");
|
|
1186
1186
|
}
|
|
1187
1187
|
if (msAbs >= s) {
|
|
1188
|
-
return plural(
|
|
1188
|
+
return plural(ms3, msAbs, s, "second");
|
|
1189
1189
|
}
|
|
1190
|
-
return
|
|
1190
|
+
return ms3 + " ms";
|
|
1191
1191
|
}
|
|
1192
1192
|
__name(fmtLong, "fmtLong");
|
|
1193
|
-
function plural(
|
|
1193
|
+
function plural(ms3, msAbs, n, name) {
|
|
1194
1194
|
var isPlural = msAbs >= n * 1.5;
|
|
1195
|
-
return Math.round(
|
|
1195
|
+
return Math.round(ms3 / n) + " " + name + (isPlural ? "s" : "");
|
|
1196
1196
|
}
|
|
1197
1197
|
__name(plural, "plural");
|
|
1198
1198
|
}
|
|
@@ -1236,8 +1236,8 @@ var require_common = __commonJS({
|
|
|
1236
1236
|
}
|
|
1237
1237
|
const self2 = debug2;
|
|
1238
1238
|
const curr = Number(/* @__PURE__ */ new Date());
|
|
1239
|
-
const
|
|
1240
|
-
self2.diff =
|
|
1239
|
+
const ms3 = curr - (prevTime || curr);
|
|
1240
|
+
self2.diff = ms3;
|
|
1241
1241
|
self2.prev = prevTime;
|
|
1242
1242
|
self2.curr = curr;
|
|
1243
1243
|
prevTime = curr;
|
|
@@ -4815,6 +4815,10 @@ var import_functions3 = __toESM(require_functions(), 1);
|
|
|
4815
4815
|
// ../errors/dist/index.js
|
|
4816
4816
|
var import_ms = __toESM(require_ms(), 1);
|
|
4817
4817
|
var BASE_URL = "https://useworkflow.dev/err";
|
|
4818
|
+
function isError(value) {
|
|
4819
|
+
return typeof value === "object" && value !== null && "name" in value && "message" in value;
|
|
4820
|
+
}
|
|
4821
|
+
__name(isError, "isError");
|
|
4818
4822
|
var ERROR_SLUGS = {
|
|
4819
4823
|
NODE_JS_MODULE_IN_WORKFLOW: "node-js-module-in-workflow",
|
|
4820
4824
|
START_INVALID_WORKFLOW_FUNCTION: "start-invalid-workflow-function",
|
|
@@ -4839,6 +4843,9 @@ Learn more: ${BASE_URL}/${options.slug}` : message;
|
|
|
4839
4843
|
Caused by: ${options.cause.stack}`;
|
|
4840
4844
|
}
|
|
4841
4845
|
}
|
|
4846
|
+
static is(value) {
|
|
4847
|
+
return isError(value) && value.name === "WorkflowError";
|
|
4848
|
+
}
|
|
4842
4849
|
};
|
|
4843
4850
|
var WorkflowAPIError = class extends WorkflowError {
|
|
4844
4851
|
static {
|
|
@@ -4856,6 +4863,9 @@ var WorkflowAPIError = class extends WorkflowError {
|
|
|
4856
4863
|
this.code = options?.code;
|
|
4857
4864
|
this.url = options?.url;
|
|
4858
4865
|
}
|
|
4866
|
+
static is(value) {
|
|
4867
|
+
return isError(value) && value.name === "WorkflowAPIError";
|
|
4868
|
+
}
|
|
4859
4869
|
};
|
|
4860
4870
|
var WorkflowRuntimeError = class extends WorkflowError {
|
|
4861
4871
|
static {
|
|
@@ -4867,6 +4877,9 @@ var WorkflowRuntimeError = class extends WorkflowError {
|
|
|
4867
4877
|
});
|
|
4868
4878
|
this.name = "WorkflowRuntimeError";
|
|
4869
4879
|
}
|
|
4880
|
+
static is(value) {
|
|
4881
|
+
return isError(value) && value.name === "WorkflowRuntimeError";
|
|
4882
|
+
}
|
|
4870
4883
|
};
|
|
4871
4884
|
var WorkflowRunNotFoundError = class extends WorkflowError {
|
|
4872
4885
|
static {
|
|
@@ -4878,6 +4891,9 @@ var WorkflowRunNotFoundError = class extends WorkflowError {
|
|
|
4878
4891
|
this.name = "WorkflowRunNotFoundError";
|
|
4879
4892
|
this.runId = runId;
|
|
4880
4893
|
}
|
|
4894
|
+
static is(value) {
|
|
4895
|
+
return isError(value) && value.name === "WorkflowRunNotFoundError";
|
|
4896
|
+
}
|
|
4881
4897
|
};
|
|
4882
4898
|
var FatalError = class extends Error {
|
|
4883
4899
|
static {
|
|
@@ -4888,9 +4904,12 @@ var FatalError = class extends Error {
|
|
|
4888
4904
|
super(message);
|
|
4889
4905
|
this.name = "FatalError";
|
|
4890
4906
|
}
|
|
4907
|
+
static is(value) {
|
|
4908
|
+
return isError(value) && value.name === "FatalError";
|
|
4909
|
+
}
|
|
4891
4910
|
};
|
|
4892
4911
|
// ../core/dist/global.js
|
|
4893
|
-
var WorkflowSuspension = class extends Error {
|
|
4912
|
+
var WorkflowSuspension = class _WorkflowSuspension extends Error {
|
|
4894
4913
|
static {
|
|
4895
4914
|
__name(this, "WorkflowSuspension");
|
|
4896
4915
|
}
|
|
@@ -4898,9 +4917,11 @@ var WorkflowSuspension = class extends Error {
|
|
|
4898
4917
|
globalThis;
|
|
4899
4918
|
stepCount;
|
|
4900
4919
|
hookCount;
|
|
4920
|
+
waitCount;
|
|
4901
4921
|
constructor(steps, global2) {
|
|
4902
4922
|
const stepCount = steps.filter((s) => s.type === "step").length;
|
|
4903
4923
|
const hookCount = steps.filter((s) => s.type === "hook").length;
|
|
4924
|
+
const waitCount = steps.filter((s) => s.type === "wait").length;
|
|
4904
4925
|
const parts = [];
|
|
4905
4926
|
if (stepCount > 0) {
|
|
4906
4927
|
parts.push(`${stepCount} ${stepCount === 1 ? "step" : "steps"}`);
|
|
@@ -4908,7 +4929,10 @@ var WorkflowSuspension = class extends Error {
|
|
|
4908
4929
|
if (hookCount > 0) {
|
|
4909
4930
|
parts.push(`${hookCount} ${hookCount === 1 ? "hook" : "hooks"}`);
|
|
4910
4931
|
}
|
|
4911
|
-
|
|
4932
|
+
if (waitCount > 0) {
|
|
4933
|
+
parts.push(`${waitCount} ${waitCount === 1 ? "wait" : "waits"}`);
|
|
4934
|
+
}
|
|
4935
|
+
const totalCount = stepCount + hookCount + waitCount;
|
|
4912
4936
|
const hasOrHave = totalCount === 1 ? "has" : "have";
|
|
4913
4937
|
let action;
|
|
4914
4938
|
if (stepCount > 0) {
|
|
@@ -4917,6 +4941,9 @@ var WorkflowSuspension = class extends Error {
|
|
|
4917
4941
|
else if (hookCount > 0) {
|
|
4918
4942
|
action = "created";
|
|
4919
4943
|
}
|
|
4944
|
+
else if (waitCount > 0) {
|
|
4945
|
+
action = "created";
|
|
4946
|
+
}
|
|
4920
4947
|
else {
|
|
4921
4948
|
action = "received";
|
|
4922
4949
|
}
|
|
@@ -4927,6 +4954,10 @@ var WorkflowSuspension = class extends Error {
|
|
|
4927
4954
|
this.globalThis = global2;
|
|
4928
4955
|
this.stepCount = stepCount;
|
|
4929
4956
|
this.hookCount = hookCount;
|
|
4957
|
+
this.waitCount = waitCount;
|
|
4958
|
+
}
|
|
4959
|
+
static is(value) {
|
|
4960
|
+
return value instanceof _WorkflowSuspension;
|
|
4930
4961
|
}
|
|
4931
4962
|
};
|
|
4932
4963
|
function ENOTSUP() {
|
|
@@ -4957,8 +4988,8 @@ function once(fn) {
|
|
|
4957
4988
|
return result;
|
|
4958
4989
|
}
|
|
4959
4990
|
__name(once, "once");
|
|
4960
|
-
function buildWorkflowSuspensionMessage(runId, stepCount, hookCount) {
|
|
4961
|
-
if (stepCount === 0 && hookCount === 0) {
|
|
4991
|
+
function buildWorkflowSuspensionMessage(runId, stepCount, hookCount, waitCount) {
|
|
4992
|
+
if (stepCount === 0 && hookCount === 0 && waitCount === 0) {
|
|
4962
4993
|
return null;
|
|
4963
4994
|
}
|
|
4964
4995
|
const parts = [];
|
|
@@ -4968,7 +4999,20 @@ function buildWorkflowSuspensionMessage(runId, stepCount, hookCount) {
|
|
|
4968
4999
|
if (hookCount > 0) {
|
|
4969
5000
|
parts.push(`${hookCount} ${hookCount === 1 ? "hook" : "hooks"}`);
|
|
4970
5001
|
}
|
|
4971
|
-
|
|
5002
|
+
if (waitCount > 0) {
|
|
5003
|
+
parts.push(`${waitCount} ${waitCount === 1 ? "timer" : "timers"}`);
|
|
5004
|
+
}
|
|
5005
|
+
const resumeMsgParts = [];
|
|
5006
|
+
if (stepCount > 0) {
|
|
5007
|
+
resumeMsgParts.push("steps are completed");
|
|
5008
|
+
}
|
|
5009
|
+
if (hookCount > 0) {
|
|
5010
|
+
resumeMsgParts.push("hooks are received");
|
|
5011
|
+
}
|
|
5012
|
+
if (waitCount > 0) {
|
|
5013
|
+
resumeMsgParts.push("timers have elapsed");
|
|
5014
|
+
}
|
|
5015
|
+
const resumeMsg = resumeMsgParts.join(" and ");
|
|
4972
5016
|
return `[Workflows] "${runId}" - ${parts.join(" and ")} to be enqueued
|
|
4973
5017
|
Workflow will suspend and resume when ${resumeMsg}`;
|
|
4974
5018
|
}
|
|
@@ -18033,6 +18077,8 @@ var EventTypeSchema = external_exports.enum([
|
|
|
18033
18077
|
"hook_created",
|
|
18034
18078
|
"hook_received",
|
|
18035
18079
|
"hook_disposed",
|
|
18080
|
+
"wait_created",
|
|
18081
|
+
"wait_completed",
|
|
18036
18082
|
"workflow_completed",
|
|
18037
18083
|
"workflow_failed",
|
|
18038
18084
|
"workflow_started"
|
|
@@ -18084,6 +18130,17 @@ var HookDisposedEventSchema = BaseEventSchema.extend({
|
|
|
18084
18130
|
eventType: external_exports.literal("hook_disposed"),
|
|
18085
18131
|
correlationId: external_exports.string()
|
|
18086
18132
|
});
|
|
18133
|
+
var WaitCreatedEventSchema = BaseEventSchema.extend({
|
|
18134
|
+
eventType: external_exports.literal("wait_created"),
|
|
18135
|
+
correlationId: external_exports.string(),
|
|
18136
|
+
eventData: external_exports.object({
|
|
18137
|
+
resumeAt: external_exports.coerce.date()
|
|
18138
|
+
})
|
|
18139
|
+
});
|
|
18140
|
+
var WaitCompletedEventSchema = BaseEventSchema.extend({
|
|
18141
|
+
eventType: external_exports.literal("wait_completed"),
|
|
18142
|
+
correlationId: external_exports.string()
|
|
18143
|
+
});
|
|
18087
18144
|
var WorkflowCompletedEventSchema = BaseEventSchema.extend({
|
|
18088
18145
|
eventType: external_exports.literal("workflow_completed")
|
|
18089
18146
|
});
|
|
@@ -18104,6 +18161,8 @@ var CreateEventSchema = external_exports.discriminatedUnion("eventType", [
|
|
|
18104
18161
|
HookCreatedEventSchema,
|
|
18105
18162
|
HookReceivedEventSchema,
|
|
18106
18163
|
HookDisposedEventSchema,
|
|
18164
|
+
WaitCreatedEventSchema,
|
|
18165
|
+
WaitCompletedEventSchema,
|
|
18107
18166
|
WorkflowCompletedEventSchema,
|
|
18108
18167
|
WorkflowFailedEventSchema,
|
|
18109
18168
|
WorkflowStartedEventSchema
|
|
@@ -18208,7 +18267,8 @@ var StepSchema = external_exports.object({
|
|
|
18208
18267
|
startedAt: external_exports.coerce.date().optional(),
|
|
18209
18268
|
completedAt: external_exports.coerce.date().optional(),
|
|
18210
18269
|
createdAt: external_exports.coerce.date(),
|
|
18211
|
-
updatedAt: external_exports.coerce.date()
|
|
18270
|
+
updatedAt: external_exports.coerce.date(),
|
|
18271
|
+
retryAfter: external_exports.coerce.date().optional()
|
|
18212
18272
|
});
|
|
18213
18273
|
// ../../node_modules/.pnpm/ulid@3.0.1/node_modules/ulid/dist/node/index.js
|
|
18214
18274
|
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
@@ -18374,6 +18434,7 @@ function monotonicFactory(prng) {
|
|
|
18374
18434
|
}
|
|
18375
18435
|
__name(monotonicFactory, "monotonicFactory");
|
|
18376
18436
|
// ../world-local/dist/queue.js
|
|
18437
|
+
var LOCAL_QUEUE_MAX_VISIBILITY = parseInt(process.env.WORKFLOW_LOCAL_QUEUE_MAX_VISIBILITY ?? "0", 10) || Infinity;
|
|
18377
18438
|
function createQueue(port) {
|
|
18378
18439
|
const transport = new JsonTransport();
|
|
18379
18440
|
const generateId = monotonicFactory();
|
|
@@ -18425,8 +18486,8 @@ function createQueue(port) {
|
|
|
18425
18486
|
const text = await response.text();
|
|
18426
18487
|
if (response.status === 503) {
|
|
18427
18488
|
try {
|
|
18428
|
-
const
|
|
18429
|
-
await (0, import_promises.setTimeout)(
|
|
18489
|
+
const timeoutSeconds = Number(JSON.parse(text).timeoutSeconds);
|
|
18490
|
+
await (0, import_promises.setTimeout)(timeoutSeconds * 1e3);
|
|
18430
18491
|
defaultRetriesLeft++;
|
|
18431
18492
|
continue;
|
|
18432
18493
|
}
|
|
@@ -18468,10 +18529,13 @@ function createQueue(port) {
|
|
|
18468
18529
|
}
|
|
18469
18530
|
const body = await new JsonTransport().deserialize(req.body);
|
|
18470
18531
|
try {
|
|
18471
|
-
const
|
|
18472
|
-
|
|
18473
|
-
if (
|
|
18474
|
-
|
|
18532
|
+
const result = await handler(body, { attempt, queueName, messageId });
|
|
18533
|
+
let timeoutSeconds = null;
|
|
18534
|
+
if (typeof result?.timeoutSeconds === "number") {
|
|
18535
|
+
timeoutSeconds = Math.min(result.timeoutSeconds, LOCAL_QUEUE_MAX_VISIBILITY);
|
|
18536
|
+
}
|
|
18537
|
+
if (timeoutSeconds) {
|
|
18538
|
+
return Response.json({ timeoutSeconds }, { status: 503 });
|
|
18475
18539
|
}
|
|
18476
18540
|
return Response.json({ ok: true });
|
|
18477
18541
|
}
|
|
@@ -20788,6 +20852,7 @@ var MessageWrapper = object({
|
|
|
20788
20852
|
payload: QueuePayloadSchema,
|
|
20789
20853
|
queueName: ValidQueueName
|
|
20790
20854
|
});
|
|
20855
|
+
var VERCEL_QUEUE_MAX_VISIBILITY = 82800;
|
|
20791
20856
|
function createQueue2(config3) {
|
|
20792
20857
|
const { baseUrl, usingProxy } = getHttpUrl(config3);
|
|
20793
20858
|
const headers = getHeaders(config3);
|
|
@@ -20816,13 +20881,20 @@ function createQueue2(config3) {
|
|
|
20816
20881
|
const createQueueHandler = /* @__PURE__ */ __name((prefix, handler) => {
|
|
20817
20882
|
return handleCallback({
|
|
20818
20883
|
[`${prefix}*`]: {
|
|
20819
|
-
default: /* @__PURE__ */ __name((body, meta) => {
|
|
20884
|
+
default: /* @__PURE__ */ __name(async (body, meta) => {
|
|
20820
20885
|
const { payload, queueName } = MessageWrapper.parse(body);
|
|
20821
|
-
|
|
20886
|
+
const result = await handler(payload, {
|
|
20822
20887
|
queueName,
|
|
20823
20888
|
messageId: MessageId.parse(meta.messageId),
|
|
20824
20889
|
attempt: meta.deliveryCount
|
|
20825
20890
|
});
|
|
20891
|
+
if (typeof result?.timeoutSeconds === "number") {
|
|
20892
|
+
const adjustedTimeoutSeconds = Math.min(result.timeoutSeconds, VERCEL_QUEUE_MAX_VISIBILITY);
|
|
20893
|
+
if (adjustedTimeoutSeconds !== result.timeoutSeconds) {
|
|
20894
|
+
result.timeoutSeconds = adjustedTimeoutSeconds;
|
|
20895
|
+
}
|
|
20896
|
+
}
|
|
20897
|
+
return result;
|
|
20826
20898
|
}, "default")
|
|
20827
20899
|
}
|
|
20828
20900
|
});
|
|
@@ -21923,6 +21995,7 @@ __name(stringify_primitive, "stringify_primitive");
|
|
|
21923
21995
|
// ../core/dist/symbols.js
|
|
21924
21996
|
var WORKFLOW_USE_STEP = Symbol.for("WORKFLOW_USE_STEP");
|
|
21925
21997
|
var WORKFLOW_CREATE_HOOK = Symbol.for("WORKFLOW_CREATE_HOOK");
|
|
21998
|
+
var WORKFLOW_SLEEP = Symbol.for("WORKFLOW_SLEEP");
|
|
21926
21999
|
var WORKFLOW_CONTEXT = Symbol.for("WORKFLOW_CONTEXT");
|
|
21927
22000
|
var WORKFLOW_GET_STREAM_ID = Symbol.for("WORKFLOW_GET_STREAM_ID");
|
|
21928
22001
|
var STREAM_NAME_SYMBOL = Symbol.for("WORKFLOW_STREAM_NAME");
|
|
@@ -22270,30 +22343,6 @@ var HookFound = SemanticConvention("workflow.hook.found");
|
|
|
22270
22343
|
var WebhookHandlersTriggered = SemanticConvention("webhook.handlers.triggered");
|
|
22271
22344
|
// ../core/dist/types.js
|
|
22272
22345
|
var import_node_util = require("node:util");
|
|
22273
|
-
function getConstructorName(obj) {
|
|
22274
|
-
if (obj === null || obj === void 0) {
|
|
22275
|
-
return null;
|
|
22276
|
-
}
|
|
22277
|
-
const ctor = obj.constructor;
|
|
22278
|
-
if (!ctor || ctor.name === "Object") {
|
|
22279
|
-
return null;
|
|
22280
|
-
}
|
|
22281
|
-
return ctor.name;
|
|
22282
|
-
}
|
|
22283
|
-
__name(getConstructorName, "getConstructorName");
|
|
22284
|
-
function getConstructorNames(obj) {
|
|
22285
|
-
const proto = Object.getPrototypeOf(obj);
|
|
22286
|
-
const name = getConstructorName(proto);
|
|
22287
|
-
if (name === null) {
|
|
22288
|
-
return [];
|
|
22289
|
-
}
|
|
22290
|
-
return [name, ...getConstructorNames(proto)];
|
|
22291
|
-
}
|
|
22292
|
-
__name(getConstructorNames, "getConstructorNames");
|
|
22293
|
-
function isInstanceOf(v, ctor) {
|
|
22294
|
-
return getConstructorNames(v).includes(ctor.name);
|
|
22295
|
-
}
|
|
22296
|
-
__name(isInstanceOf, "isInstanceOf");
|
|
22297
22346
|
function getErrorName(v) {
|
|
22298
22347
|
if (import_node_util.types.isNativeError(v)) {
|
|
22299
22348
|
return v.name;
|
|
@@ -22661,6 +22710,63 @@ function createCreateHook(ctx) {
|
|
|
22661
22710
|
}, "createHookImpl");
|
|
22662
22711
|
}
|
|
22663
22712
|
__name(createCreateHook, "createCreateHook");
|
|
22713
|
+
// ../core/dist/workflow/sleep.js
|
|
22714
|
+
var import_ms3 = __toESM(require_ms(), 1);
|
|
22715
|
+
function createSleep(ctx) {
|
|
22716
|
+
return /* @__PURE__ */ __name(async function sleepImpl(param) {
|
|
22717
|
+
const { promise: promise2, resolve } = withResolvers();
|
|
22718
|
+
const correlationId = `wait_${ctx.generateUlid()}`;
|
|
22719
|
+
let resumeAt;
|
|
22720
|
+
if (typeof param === "string") {
|
|
22721
|
+
const durationMs = (0, import_ms3.default)(param);
|
|
22722
|
+
if (typeof durationMs !== "number" || durationMs < 0) {
|
|
22723
|
+
throw new Error(`Invalid sleep duration: "${param}". Expected a valid duration string like "1s", "1m", "1h", etc.`);
|
|
22724
|
+
}
|
|
22725
|
+
resumeAt = new Date(Date.now() + durationMs);
|
|
22726
|
+
}
|
|
22727
|
+
else if (param instanceof Date || param && typeof param === "object" && typeof param.getTime === "function") {
|
|
22728
|
+
const dateParam = param instanceof Date ? param : new Date(param.getTime());
|
|
22729
|
+
resumeAt = dateParam;
|
|
22730
|
+
}
|
|
22731
|
+
else {
|
|
22732
|
+
throw new Error(`Invalid sleep parameter. Expected a duration string or Date object.`);
|
|
22733
|
+
}
|
|
22734
|
+
ctx.invocationsQueue.push({
|
|
22735
|
+
type: "wait",
|
|
22736
|
+
correlationId,
|
|
22737
|
+
resumeAt
|
|
22738
|
+
});
|
|
22739
|
+
ctx.eventsConsumer.subscribe((event) => {
|
|
22740
|
+
if (!event) {
|
|
22741
|
+
setTimeout(() => {
|
|
22742
|
+
ctx.onWorkflowError(new WorkflowSuspension(ctx.invocationsQueue, ctx.globalThis));
|
|
22743
|
+
}, 0);
|
|
22744
|
+
return EventConsumerResult.NotConsumed;
|
|
22745
|
+
}
|
|
22746
|
+
if (event?.eventType === "wait_created" && event.correlationId === correlationId) {
|
|
22747
|
+
const waitItem = ctx.invocationsQueue.find((item) => item.type === "wait" && item.correlationId === correlationId);
|
|
22748
|
+
if (waitItem) {
|
|
22749
|
+
waitItem.hasCreatedEvent = true;
|
|
22750
|
+
waitItem.resumeAt = event.eventData.resumeAt;
|
|
22751
|
+
}
|
|
22752
|
+
return EventConsumerResult.Consumed;
|
|
22753
|
+
}
|
|
22754
|
+
if (event?.eventType === "wait_completed" && event.correlationId === correlationId) {
|
|
22755
|
+
const index = ctx.invocationsQueue.findIndex((item) => item.type === "wait" && item.correlationId === correlationId);
|
|
22756
|
+
if (index !== -1) {
|
|
22757
|
+
ctx.invocationsQueue.splice(index, 1);
|
|
22758
|
+
}
|
|
22759
|
+
setTimeout(() => {
|
|
22760
|
+
resolve();
|
|
22761
|
+
}, 0);
|
|
22762
|
+
return EventConsumerResult.Finished;
|
|
22763
|
+
}
|
|
22764
|
+
return EventConsumerResult.NotConsumed;
|
|
22765
|
+
});
|
|
22766
|
+
return promise2;
|
|
22767
|
+
}, "sleepImpl");
|
|
22768
|
+
}
|
|
22769
|
+
__name(createSleep, "createSleep");
|
|
22664
22770
|
// ../core/dist/workflow.js
|
|
22665
22771
|
async function runWorkflow(workflowCode2, workflowRun, events) {
|
|
22666
22772
|
return trace2(`WORKFLOW.run ${workflowRun.workflowName}`, async (span) => {
|
|
@@ -22698,8 +22804,10 @@ async function runWorkflow(workflowCode2, workflowRun, events) {
|
|
|
22698
22804
|
});
|
|
22699
22805
|
const useStep = createUseStep(workflowContext);
|
|
22700
22806
|
const createHook2 = createCreateHook(workflowContext);
|
|
22807
|
+
const sleep = createSleep(workflowContext);
|
|
22701
22808
|
vmGlobalThis[WORKFLOW_USE_STEP] = useStep;
|
|
22702
22809
|
vmGlobalThis[WORKFLOW_CREATE_HOOK] = createHook2;
|
|
22810
|
+
vmGlobalThis[WORKFLOW_SLEEP] = sleep;
|
|
22703
22811
|
vmGlobalThis[WORKFLOW_GET_STREAM_ID] = (namespace) => getWorkflowRunStreamId(workflowRun.runId, namespace);
|
|
22704
22812
|
const url2 = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : `http://localhost:${process.env.PORT || 3e3}`;
|
|
22705
22813
|
const ctx = {
|
|
@@ -23132,6 +23240,20 @@ function workflowEntrypoint(workflowCode2) {
|
|
|
23132
23240
|
return;
|
|
23133
23241
|
}
|
|
23134
23242
|
const events = await getAllWorkflowRunEvents(workflowRun.runId);
|
|
23243
|
+
const now = Date.now();
|
|
23244
|
+
for (const event of events) {
|
|
23245
|
+
if (event.eventType === "wait_created") {
|
|
23246
|
+
const resumeAt = event.eventData.resumeAt;
|
|
23247
|
+
const hasCompleted = events.some((e) => e.eventType === "wait_completed" && e.correlationId === event.correlationId);
|
|
23248
|
+
if (!hasCompleted && now >= resumeAt.getTime()) {
|
|
23249
|
+
const completedEvent = await world.events.create(runId, {
|
|
23250
|
+
eventType: "wait_completed",
|
|
23251
|
+
correlationId: event.correlationId
|
|
23252
|
+
});
|
|
23253
|
+
events.push(completedEvent);
|
|
23254
|
+
}
|
|
23255
|
+
}
|
|
23256
|
+
}
|
|
23135
23257
|
const result = await runWorkflow(workflowCode2, workflowRun, events);
|
|
23136
23258
|
await world.runs.update(runId, {
|
|
23137
23259
|
status: "completed",
|
|
@@ -23143,10 +23265,11 @@ function workflowEntrypoint(workflowCode2) {
|
|
|
23143
23265
|
});
|
|
23144
23266
|
}
|
|
23145
23267
|
catch (err) {
|
|
23146
|
-
if (
|
|
23147
|
-
const suspensionMessage = buildWorkflowSuspensionMessage(runId, err.stepCount, err.hookCount);
|
|
23268
|
+
if (WorkflowSuspension.is(err)) {
|
|
23269
|
+
const suspensionMessage = buildWorkflowSuspensionMessage(runId, err.stepCount, err.hookCount, err.waitCount);
|
|
23148
23270
|
if (suspensionMessage) {
|
|
23149
23271
|
}
|
|
23272
|
+
let minTimeoutSeconds = null;
|
|
23150
23273
|
for (const queueItem of err.steps) {
|
|
23151
23274
|
if (queueItem.type === "step") {
|
|
23152
23275
|
const ops = [];
|
|
@@ -23169,7 +23292,7 @@ function workflowEntrypoint(workflowCode2) {
|
|
|
23169
23292
|
});
|
|
23170
23293
|
}
|
|
23171
23294
|
catch (err2) {
|
|
23172
|
-
if (
|
|
23295
|
+
if (WorkflowAPIError.is(err2) && err2.status === 409) {
|
|
23173
23296
|
console.warn(`Step "${queueItem.stepName}" with correlation ID "${queueItem.correlationId}" already exists, skipping: ${err2.message}`);
|
|
23174
23297
|
continue;
|
|
23175
23298
|
}
|
|
@@ -23190,7 +23313,7 @@ function workflowEntrypoint(workflowCode2) {
|
|
|
23190
23313
|
});
|
|
23191
23314
|
}
|
|
23192
23315
|
catch (err2) {
|
|
23193
|
-
if (
|
|
23316
|
+
if (WorkflowAPIError.is(err2)) {
|
|
23194
23317
|
if (err2.status === 409) {
|
|
23195
23318
|
console.warn(`Hook with correlation ID "${queueItem.correlationId}" already exists, skipping: ${err2.message}`);
|
|
23196
23319
|
continue;
|
|
@@ -23203,11 +23326,41 @@ function workflowEntrypoint(workflowCode2) {
|
|
|
23203
23326
|
throw err2;
|
|
23204
23327
|
}
|
|
23205
23328
|
}
|
|
23329
|
+
else if (queueItem.type === "wait") {
|
|
23330
|
+
try {
|
|
23331
|
+
if (!queueItem.hasCreatedEvent) {
|
|
23332
|
+
await world.events.create(runId, {
|
|
23333
|
+
eventType: "wait_created",
|
|
23334
|
+
correlationId: queueItem.correlationId,
|
|
23335
|
+
eventData: {
|
|
23336
|
+
resumeAt: queueItem.resumeAt
|
|
23337
|
+
}
|
|
23338
|
+
});
|
|
23339
|
+
}
|
|
23340
|
+
const now = Date.now();
|
|
23341
|
+
const resumeAtMs = queueItem.resumeAt.getTime();
|
|
23342
|
+
const delayMs = Math.max(1e3, resumeAtMs - now);
|
|
23343
|
+
const timeoutSeconds = Math.ceil(delayMs / 1e3);
|
|
23344
|
+
if (minTimeoutSeconds === null || timeoutSeconds < minTimeoutSeconds) {
|
|
23345
|
+
minTimeoutSeconds = timeoutSeconds;
|
|
23346
|
+
}
|
|
23347
|
+
}
|
|
23348
|
+
catch (err2) {
|
|
23349
|
+
if (WorkflowAPIError.is(err2) && err2.status === 409) {
|
|
23350
|
+
console.warn(`Wait with correlation ID "${queueItem.correlationId}" already exists, skipping: ${err2.message}`);
|
|
23351
|
+
continue;
|
|
23352
|
+
}
|
|
23353
|
+
throw err2;
|
|
23354
|
+
}
|
|
23355
|
+
}
|
|
23206
23356
|
}
|
|
23207
23357
|
span?.setAttributes({
|
|
23208
23358
|
...WorkflowRunStatus("pending_steps"),
|
|
23209
23359
|
...WorkflowStepsCreated(err.steps.length)
|
|
23210
23360
|
});
|
|
23361
|
+
if (minTimeoutSeconds !== null) {
|
|
23362
|
+
return { timeoutSeconds: minTimeoutSeconds };
|
|
23363
|
+
}
|
|
23211
23364
|
}
|
|
23212
23365
|
else {
|
|
23213
23366
|
const errorName = getErrorName(err);
|
|
@@ -23241,6 +23394,25 @@ var __export = (target, all) => {
|
|
|
23241
23394
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23242
23395
|
};
|
|
23243
23396
|
|
|
23397
|
+
// workflows/addition.ts
|
|
23398
|
+
var addition_exports = {};
|
|
23399
|
+
__export(addition_exports, {
|
|
23400
|
+
addition: () => addition
|
|
23401
|
+
});
|
|
23402
|
+
async function add(num, num2) {
|
|
23403
|
+
return globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//workflows/addition.ts//add")(num, num2);
|
|
23404
|
+
}
|
|
23405
|
+
__name(add, "add");
|
|
23406
|
+
async function addition(num, num2) {
|
|
23407
|
+
const result = await add(num, num2);
|
|
23408
|
+
console.log({
|
|
23409
|
+
result
|
|
23410
|
+
});
|
|
23411
|
+
return result;
|
|
23412
|
+
}
|
|
23413
|
+
__name(addition, "addition");
|
|
23414
|
+
addition.workflowId = "workflow//workflows/addition.ts//addition";
|
|
23415
|
+
|
|
23244
23416
|
// workflows/noop.ts
|
|
23245
23417
|
var noop_exports = {};
|
|
23246
23418
|
__export(noop_exports, {
|
|
@@ -23277,29 +23449,10 @@ async function brokenWf() {
|
|
|
23277
23449
|
__name(brokenWf, "brokenWf");
|
|
23278
23450
|
brokenWf.workflowId = "workflow//workflows/noop.ts//brokenWf";
|
|
23279
23451
|
|
|
23280
|
-
// workflows/addition.ts
|
|
23281
|
-
var addition_exports = {};
|
|
23282
|
-
__export(addition_exports, {
|
|
23283
|
-
addition: () => addition
|
|
23284
|
-
});
|
|
23285
|
-
async function add(num, num2) {
|
|
23286
|
-
return globalThis[Symbol.for("WORKFLOW_USE_STEP")]("step//workflows/addition.ts//add")(num, num2);
|
|
23287
|
-
}
|
|
23288
|
-
__name(add, "add");
|
|
23289
|
-
async function addition(num, num2) {
|
|
23290
|
-
const result = await add(num, num2);
|
|
23291
|
-
console.log({
|
|
23292
|
-
result
|
|
23293
|
-
});
|
|
23294
|
-
return result;
|
|
23295
|
-
}
|
|
23296
|
-
__name(addition, "addition");
|
|
23297
|
-
addition.workflowId = "workflow//workflows/addition.ts//addition";
|
|
23298
|
-
|
|
23299
23452
|
// virtual-entry.js
|
|
23300
23453
|
globalThis.__private_workflows = /* @__PURE__ */ new Map();
|
|
23301
|
-
Object.values(noop_exports).map((item) => item?.workflowId && globalThis.__private_workflows.set(item.workflowId, item));
|
|
23302
23454
|
Object.values(addition_exports).map((item) => item?.workflowId && globalThis.__private_workflows.set(item.workflowId, item));
|
|
23455
|
+
Object.values(noop_exports).map((item) => item?.workflowId && globalThis.__private_workflows.set(item.workflowId, item));
|
|
23303
23456
|
`;
|
|
23304
23457
|
var POST = workflowEntrypoint(workflowCode);
|
|
23305
23458
|
// Annotate the CommonJS export names for ESM import in node:
|