@workflow/world-testing 4.1.0-beta.66 → 4.1.0-beta.68

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.
@@ -49142,7 +49142,7 @@ function createQueue(config3) {
49142
49142
  if (typeof result?.timeoutSeconds === "number") {
49143
49143
  timeoutSeconds = Math.min(result.timeoutSeconds, LOCAL_QUEUE_MAX_VISIBILITY);
49144
49144
  }
49145
- if (timeoutSeconds) {
49145
+ if (timeoutSeconds != null) {
49146
49146
  return Response.json({ timeoutSeconds }, { status: 503 });
49147
49147
  }
49148
49148
  return Response.json({ ok: true });
@@ -50142,6 +50142,16 @@ function createEventsStorage(basedir) {
50142
50142
  wait
50143
50143
  };
50144
50144
  },
50145
+ async get(runId, eventId, params) {
50146
+ const compositeKey = `${runId}-${eventId}`;
50147
+ const eventPath = import_node_path5.default.join(basedir, "events", `${compositeKey}.json`);
50148
+ const event = await readJSON(eventPath, EventSchema);
50149
+ if (!event) {
50150
+ throw new Error(`Event ${eventId} in run ${runId} not found`);
50151
+ }
50152
+ const resolveData = params?.resolveData ?? DEFAULT_RESOLVE_DATA_OPTION;
50153
+ return filterEventData(event, resolveData);
50154
+ },
50145
50155
  async list(params) {
50146
50156
  const { runId } = params;
50147
50157
  const resolveData = params.resolveData ?? DEFAULT_RESOLVE_DATA_OPTION;
@@ -53076,7 +53086,7 @@ var RpcService3 = SemanticConvention3("rpc.service");
53076
53086
  var RpcMethod3 = SemanticConvention3("rpc.method");
53077
53087
 
53078
53088
  // ../world-vercel/dist/version.js
53079
- var version2 = "4.1.0-beta.39";
53089
+ var version2 = "4.1.0-beta.41";
53080
53090
 
53081
53091
  // ../world-vercel/dist/utils.js
53082
53092
  var WORKFLOW_SERVER_URL_OVERRIDE = "";
@@ -53388,7 +53398,7 @@ function createQueue2(config3) {
53388
53398
  attempt: metadata.deliveryCount
53389
53399
  });
53390
53400
  if (typeof result?.timeoutSeconds === "number") {
53391
- const delaySeconds = Math.min(result.timeoutSeconds, MAX_DELAY_SECONDS);
53401
+ const delaySeconds = result.timeoutSeconds > 0 ? Math.min(result.timeoutSeconds, MAX_DELAY_SECONDS) : void 0;
53392
53402
  await queue(queueName, payload, { deploymentId, delaySeconds });
53393
53403
  }
53394
53404
  });
@@ -53852,6 +53862,22 @@ async function hydrateEventRefs(events, config3, refResolveConcurrency) {
53852
53862
  });
53853
53863
  }
53854
53864
  __name(hydrateEventRefs, "hydrateEventRefs");
53865
+ async function getEvent(runId, eventId, params, config3) {
53866
+ const resolveData = params?.resolveData ?? DEFAULT_RESOLVE_DATA_OPTION2;
53867
+ const remoteRefBehavior = resolveData === "none" ? "lazy" : "resolve";
53868
+ const searchParams = new URLSearchParams();
53869
+ searchParams.set("remoteRefBehavior", remoteRefBehavior);
53870
+ const queryString = searchParams.toString();
53871
+ const endpoint = `/v2/runs/${runId}/events/${eventId}${queryString ? `?${queryString}` : ""}`;
53872
+ const event = await makeRequest({
53873
+ endpoint,
53874
+ options: { method: "GET" },
53875
+ config: config3,
53876
+ schema: resolveData === "none" ? EventWithRefsSchema : EventSchema
53877
+ });
53878
+ return filterEventData2(event, resolveData);
53879
+ }
53880
+ __name(getEvent, "getEvent");
53855
53881
  async function getWorkflowRunEvents(params, config3) {
53856
53882
  const searchParams = new URLSearchParams();
53857
53883
  const { pagination, resolveData = DEFAULT_RESOLVE_DATA_OPTION2 } = params;
@@ -54109,6 +54135,7 @@ function createStorage2(config3) {
54109
54135
  },
54110
54136
  events: {
54111
54137
  create: /* @__PURE__ */ __name((runId, data, params) => createWorkflowRunEvent(runId, data, params, config3), "create"),
54138
+ get: /* @__PURE__ */ __name((runId, eventId, params) => getEvent(runId, eventId, params, config3), "get"),
54112
54139
  list: /* @__PURE__ */ __name((params) => getWorkflowRunEvents(params, config3), "list"),
54113
54140
  listByCorrelationId: /* @__PURE__ */ __name((params) => getWorkflowRunEvents(params, config3), "listByCorrelationId")
54114
54141
  },
@@ -55303,6 +55330,19 @@ function getStepFunction(stepId) {
55303
55330
  return void 0;
55304
55331
  }
55305
55332
  __name(getStepFunction, "getStepFunction");
55333
+ function scheduleWhenIdle(ctx, fn) {
55334
+ const check2 = /* @__PURE__ */ __name(() => {
55335
+ if (ctx.pendingDeliveries > 0) {
55336
+ ctx.promiseQueue.then(() => {
55337
+ setTimeout(check2, 0);
55338
+ });
55339
+ } else {
55340
+ fn();
55341
+ }
55342
+ }, "check");
55343
+ setTimeout(check2, 0);
55344
+ }
55345
+ __name(scheduleWhenIdle, "scheduleWhenIdle");
55306
55346
 
55307
55347
  // ../core/dist/serialization.js
55308
55348
  var SerializationFormat = {
@@ -56371,7 +56411,7 @@ async function handleSuspension({ suspension, world, run, span }) {
56371
56411
  ...WorkflowWaitsCreated(waitItems.length)
56372
56412
  });
56373
56413
  if (hasHookConflict) {
56374
- return { timeoutSeconds: 1 };
56414
+ return { timeoutSeconds: 0 };
56375
56415
  }
56376
56416
  if (minTimeoutSeconds !== null) {
56377
56417
  return { timeoutSeconds: minTimeoutSeconds };
@@ -57161,7 +57201,7 @@ function createUseStep(ctx) {
57161
57201
  });
57162
57202
  ctx.eventsConsumer.subscribe((event) => {
57163
57203
  if (!event) {
57164
- ctx.promiseQueue = ctx.promiseQueue.then(() => {
57204
+ scheduleWhenIdle(ctx, () => {
57165
57205
  ctx.onWorkflowError(new WorkflowSuspension(ctx.invocationsQueue, ctx.globalThis));
57166
57206
  });
57167
57207
  return EventConsumerResult.NotConsumed;
@@ -57211,12 +57251,15 @@ function createUseStep(ctx) {
57211
57251
  }
57212
57252
  if (event.eventType === "step_completed") {
57213
57253
  ctx.invocationsQueue.delete(event.correlationId);
57254
+ ctx.pendingDeliveries++;
57214
57255
  ctx.promiseQueue = ctx.promiseQueue.then(async () => {
57215
57256
  try {
57216
57257
  const hydratedResult = await hydrateStepReturnValue(event.eventData.result, ctx.runId, ctx.encryptionKey, ctx.globalThis);
57217
57258
  resolve3(hydratedResult);
57218
57259
  } catch (error48) {
57219
57260
  reject(error48);
57261
+ } finally {
57262
+ ctx.pendingDeliveries--;
57220
57263
  }
57221
57264
  });
57222
57265
  return EventConsumerResult.Finished;
@@ -57380,8 +57423,8 @@ function createCreateHook(ctx) {
57380
57423
  ctx.eventsConsumer.subscribe((event) => {
57381
57424
  if (!event) {
57382
57425
  eventLogEmpty = true;
57383
- if (promises.length > 0) {
57384
- ctx.promiseQueue = ctx.promiseQueue.then(() => {
57426
+ if (promises.length > 0 && payloadsQueue.length === 0) {
57427
+ scheduleWhenIdle(ctx, () => {
57385
57428
  ctx.onWorkflowError(new WorkflowSuspension(ctx.invocationsQueue, ctx.globalThis));
57386
57429
  });
57387
57430
  }
@@ -57416,12 +57459,15 @@ function createCreateHook(ctx) {
57416
57459
  if (promises.length > 0) {
57417
57460
  const next2 = promises.shift();
57418
57461
  if (next2) {
57462
+ ctx.pendingDeliveries++;
57419
57463
  ctx.promiseQueue = ctx.promiseQueue.then(async () => {
57420
57464
  try {
57421
57465
  const payload = await hydrateStepReturnValue(event.eventData.payload, ctx.runId, ctx.encryptionKey, ctx.globalThis);
57422
57466
  next2.resolve(payload);
57423
57467
  } catch (error48) {
57424
57468
  next2.reject(error48);
57469
+ } finally {
57470
+ ctx.pendingDeliveries--;
57425
57471
  }
57426
57472
  });
57427
57473
  }
@@ -57452,19 +57498,22 @@ function createCreateHook(ctx) {
57452
57498
  if (payloadsQueue.length > 0) {
57453
57499
  const nextPayload = payloadsQueue.shift();
57454
57500
  if (nextPayload) {
57501
+ ctx.pendingDeliveries++;
57455
57502
  ctx.promiseQueue = ctx.promiseQueue.then(async () => {
57456
57503
  try {
57457
57504
  const payload = await hydrateStepReturnValue(nextPayload.eventData.payload, ctx.runId, ctx.encryptionKey, ctx.globalThis);
57458
57505
  resolvers.resolve(payload);
57459
57506
  } catch (error48) {
57460
57507
  resolvers.reject(error48);
57508
+ } finally {
57509
+ ctx.pendingDeliveries--;
57461
57510
  }
57462
57511
  });
57463
57512
  return resolvers.promise;
57464
57513
  }
57465
57514
  }
57466
57515
  if (eventLogEmpty) {
57467
- ctx.promiseQueue = ctx.promiseQueue.then(() => {
57516
+ scheduleWhenIdle(ctx, () => {
57468
57517
  ctx.onWorkflowError(new WorkflowSuspension(ctx.invocationsQueue, ctx.globalThis));
57469
57518
  });
57470
57519
  }
@@ -57486,7 +57535,7 @@ function createCreateHook(ctx) {
57486
57535
  }
57487
57536
  if (promises.length > 0) {
57488
57537
  promises.length = 0;
57489
- ctx.promiseQueue = ctx.promiseQueue.then(() => {
57538
+ scheduleWhenIdle(ctx, () => {
57490
57539
  ctx.onWorkflowError(new WorkflowSuspension(ctx.invocationsQueue, ctx.globalThis));
57491
57540
  });
57492
57541
  }
@@ -57531,7 +57580,7 @@ function createSleep(ctx) {
57531
57580
  ctx.invocationsQueue.set(correlationId, waitItem);
57532
57581
  ctx.eventsConsumer.subscribe((event) => {
57533
57582
  if (!event) {
57534
- ctx.promiseQueue = ctx.promiseQueue.then(() => {
57583
+ scheduleWhenIdle(ctx, () => {
57535
57584
  ctx.onWorkflowError(new WorkflowSuspension(ctx.invocationsQueue, ctx.globalThis));
57536
57585
  });
57537
57586
  return EventConsumerResult.NotConsumed;
@@ -57596,7 +57645,8 @@ async function runWorkflow(workflowCode2, workflowRun, events, encryptionKey) {
57596
57645
  if (!startedAt) {
57597
57646
  throw new Error(`Workflow run "${workflowRun.runId}" has no "startedAt" timestamp (should not happen)`);
57598
57647
  }
57599
- const port = await getPort();
57648
+ const isVercel = process.env.VERCEL_URL !== void 0;
57649
+ const port = isVercel ? void 0 : await getPort();
57600
57650
  const { context: context2, globalThis: vmGlobalThis, updateTimestamp } = createContext({
57601
57651
  seed: `${workflowRun.runId}:${workflowRun.workflowName}:${+startedAt}`,
57602
57652
  fixedTimestamp: +startedAt
@@ -57627,7 +57677,8 @@ async function runWorkflow(workflowCode2, workflowRun, events, encryptionKey) {
57627
57677
  },
57628
57678
  set promiseQueue(value) {
57629
57679
  promiseQueueHolder.current = value;
57630
- }
57680
+ },
57681
+ pendingDeliveries: 0
57631
57682
  };
57632
57683
  workflowContext.eventsConsumer.subscribe((event) => {
57633
57684
  const createdAt = event?.createdAt;
@@ -57655,8 +57706,9 @@ async function runWorkflow(workflowCode2, workflowRun, events, encryptionKey) {
57655
57706
  vmGlobalThis[WORKFLOW_CREATE_HOOK] = createHook;
57656
57707
  vmGlobalThis[WORKFLOW_SLEEP] = sleep;
57657
57708
  vmGlobalThis[WORKFLOW_GET_STREAM_ID] = (namespace) => getWorkflowRunStreamId(workflowRun.runId, namespace);
57658
- const url2 = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : `http://localhost:${port ?? 3e3}`;
57709
+ const url2 = isVercel ? `https://${process.env.VERCEL_URL}` : `http://localhost:${port ?? 3e3}`;
57659
57710
  const ctx = {
57711
+ workflowName: workflowRun.workflowName,
57660
57712
  workflowRunId: workflowRun.runId,
57661
57713
  workflowStartedAt: new vmGlobalThis.Date(+startedAt),
57662
57714
  url: url2
@@ -58076,8 +58128,9 @@ var stepHandler = getWorldHandlers().createQueueHandler("__wkf_step_", async (me
58076
58128
  return await withTraceContext(traceContext, async () => {
58077
58129
  const stepName = metadata.queueName.slice("__wkf_step_".length);
58078
58130
  const world = getWorld();
58131
+ const isVercel = process.env.VERCEL_URL !== void 0;
58079
58132
  const [port, spanKind] = await Promise.all([
58080
- getPort(),
58133
+ isVercel ? void 0 : getPort(),
58081
58134
  getSpanKind("CONSUMER")
58082
58135
  ]);
58083
58136
  return trace2(`STEP ${stepName}`, { kind: spanKind, links: spanLinks }, async (span) => {
@@ -58253,16 +58306,18 @@ var stepHandler = getWorldHandlers().createQueueHandler("__wkf_step_", async (me
58253
58306
  result = await trace2("step.execute", {}, async () => {
58254
58307
  return await contextStorage.run({
58255
58308
  stepMetadata: {
58309
+ stepName,
58256
58310
  stepId,
58257
58311
  stepStartedAt: /* @__PURE__ */ new Date(+stepStartedAt),
58258
58312
  attempt
58259
58313
  },
58260
58314
  workflowMetadata: {
58315
+ workflowName,
58261
58316
  workflowRunId,
58262
58317
  workflowStartedAt: /* @__PURE__ */ new Date(+workflowStartedAt),
58263
58318
  // TODO: there should be a getUrl method on the world interface itself. This
58264
58319
  // solution only works for vercel + local worlds.
58265
- url: process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : `http://localhost:${port ?? 3e3}`
58320
+ url: isVercel ? `https://${process.env.VERCEL_URL}` : `http://localhost:${port ?? 3e3}`
58266
58321
  },
58267
58322
  ops,
58268
58323
  closureVars: hydratedInput.closureVars,
@@ -58939,7 +58994,7 @@ function getWritable(options = {}) {
58939
58994
  __name(getWritable, "getWritable");
58940
58995
 
58941
58996
  // ../workflow/dist/stdlib.js
58942
- var fetch = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//workflow@4.2.0-beta.65//fetch");
58997
+ var fetch = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//workflow@4.2.0-beta.67//fetch");
58943
58998
 
58944
58999
  // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js
58945
59000
  var NEVER = Object.freeze({
@@ -1,21 +1,11 @@
1
1
  {
2
2
  "version": "1.0.0",
3
3
  "steps": {
4
- "workflow/dist/stdlib.js": {
5
- "fetch": {
6
- "stepId": "step//workflow@4.2.0-beta.65//fetch"
7
- }
8
- },
9
4
  "workflows/hooks.ts": {
10
5
  "writeEvent": {
11
6
  "stepId": "step//./workflows/hooks//writeEvent"
12
7
  }
13
8
  },
14
- "workflows/addition.ts": {
15
- "add": {
16
- "stepId": "step//./workflows/addition//add"
17
- }
18
- },
19
9
  "workflows/noop.ts": {
20
10
  "noop": {
21
11
  "stepId": "step//./workflows/noop//noop"
@@ -26,6 +16,14 @@
26
16
  "stepId": "step//./workflows/null-byte//nullByteStep"
27
17
  }
28
18
  },
19
+ "workflows/retriable-and-fatal.ts": {
20
+ "stepThatFails": {
21
+ "stepId": "step//./workflows/retriable-and-fatal//stepThatFails"
22
+ },
23
+ "stepThatThrowsRetryableError": {
24
+ "stepId": "step//./workflows/retriable-and-fatal//stepThatThrowsRetryableError"
25
+ }
26
+ },
29
27
  "workflow/dist/internal/builtins.js": {
30
28
  "__builtin_response_array_buffer": {
31
29
  "stepId": "__builtin_response_array_buffer"
@@ -37,12 +35,14 @@
37
35
  "stepId": "__builtin_response_text"
38
36
  }
39
37
  },
40
- "workflows/retriable-and-fatal.ts": {
41
- "stepThatFails": {
42
- "stepId": "step//./workflows/retriable-and-fatal//stepThatFails"
43
- },
44
- "stepThatThrowsRetryableError": {
45
- "stepId": "step//./workflows/retriable-and-fatal//stepThatThrowsRetryableError"
38
+ "workflows/addition.ts": {
39
+ "add": {
40
+ "stepId": "step//./workflows/addition//add"
41
+ }
42
+ },
43
+ "workflow/dist/stdlib.js": {
44
+ "fetch": {
45
+ "stepId": "step//workflow@4.2.0-beta.67//fetch"
46
46
  }
47
47
  }
48
48
  },
@@ -80,16 +80,16 @@
80
80
  }
81
81
  }
82
82
  },
83
- "workflows/addition.ts": {
84
- "addition": {
85
- "workflowId": "workflow//./workflows/addition//addition",
83
+ "workflows/noop.ts": {
84
+ "brokenWf": {
85
+ "workflowId": "workflow//./workflows/noop//brokenWf",
86
86
  "graph": {
87
87
  "nodes": [
88
88
  {
89
89
  "id": "start",
90
90
  "type": "workflowStart",
91
91
  "data": {
92
- "label": "Start: addition",
92
+ "label": "Start: brokenWf",
93
93
  "nodeKind": "workflow_start"
94
94
  }
95
95
  },
@@ -113,16 +113,16 @@
113
113
  }
114
114
  }
115
115
  },
116
- "workflows/noop.ts": {
117
- "brokenWf": {
118
- "workflowId": "workflow//./workflows/noop//brokenWf",
116
+ "workflows/null-byte.ts": {
117
+ "nullByteWorkflow": {
118
+ "workflowId": "workflow//./workflows/null-byte//nullByteWorkflow",
119
119
  "graph": {
120
120
  "nodes": [
121
121
  {
122
122
  "id": "start",
123
123
  "type": "workflowStart",
124
124
  "data": {
125
- "label": "Start: brokenWf",
125
+ "label": "Start: nullByteWorkflow",
126
126
  "nodeKind": "workflow_start"
127
127
  }
128
128
  },
@@ -146,16 +146,16 @@
146
146
  }
147
147
  }
148
148
  },
149
- "workflows/null-byte.ts": {
150
- "nullByteWorkflow": {
151
- "workflowId": "workflow//./workflows/null-byte//nullByteWorkflow",
149
+ "workflows/retriable-and-fatal.ts": {
150
+ "retryableAndFatalErrorWorkflow": {
151
+ "workflowId": "workflow//./workflows/retriable-and-fatal//retryableAndFatalErrorWorkflow",
152
152
  "graph": {
153
153
  "nodes": [
154
154
  {
155
155
  "id": "start",
156
156
  "type": "workflowStart",
157
157
  "data": {
158
- "label": "Start: nullByteWorkflow",
158
+ "label": "Start: retryableAndFatalErrorWorkflow",
159
159
  "nodeKind": "workflow_start"
160
160
  }
161
161
  },
@@ -179,16 +179,16 @@
179
179
  }
180
180
  }
181
181
  },
182
- "workflows/retriable-and-fatal.ts": {
183
- "retryableAndFatalErrorWorkflow": {
184
- "workflowId": "workflow//./workflows/retriable-and-fatal//retryableAndFatalErrorWorkflow",
182
+ "workflows/addition.ts": {
183
+ "addition": {
184
+ "workflowId": "workflow//./workflows/addition//addition",
185
185
  "graph": {
186
186
  "nodes": [
187
187
  {
188
188
  "id": "start",
189
189
  "type": "workflowStart",
190
190
  "data": {
191
- "label": "Start: retryableAndFatalErrorWorkflow",
191
+ "label": "Start: addition",
192
192
  "nodeKind": "workflow_start"
193
193
  }
194
194
  },