@upstash/workflow 0.2.10-unicode-rc → 0.2.10

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/svelte.js CHANGED
@@ -151,21 +151,22 @@ function getWorkflowRunId(id) {
151
151
  return `wfr_${id ?? nanoid()}`;
152
152
  }
153
153
  function decodeBase64(base64) {
154
- const binString = atob(base64);
155
154
  try {
155
+ const binString = atob(base64);
156
156
  const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
157
157
  return new TextDecoder().decode(intArray);
158
158
  } catch (error) {
159
159
  console.warn(
160
160
  `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
161
161
  );
162
- return binString;
162
+ return atob(base64);
163
163
  }
164
164
  }
165
165
 
166
166
  // src/context/steps.ts
167
- var BaseLazyStep = class _BaseLazyStep {
167
+ var BaseLazyStep = class {
168
168
  stepName;
169
+ // will be set in the subclasses
169
170
  constructor(stepName) {
170
171
  if (!stepName) {
171
172
  throw new WorkflowError(
@@ -174,58 +175,10 @@ var BaseLazyStep = class _BaseLazyStep {
174
175
  }
175
176
  this.stepName = stepName;
176
177
  }
177
- /**
178
- * parse the out field of a step result.
179
- *
180
- * will be called when returning the steps to the context from auto executor
181
- *
182
- * @param out field of the step
183
- * @returns parsed out field
184
- */
185
- parseOut(out) {
186
- if (out === void 0) {
187
- if (this.allowUndefinedOut) {
188
- return void 0;
189
- } else {
190
- throw new WorkflowError(
191
- `Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
192
- );
193
- }
194
- }
195
- if (typeof out === "object") {
196
- if (this.stepType !== "Wait") {
197
- console.warn(
198
- `Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
199
- );
200
- return out;
201
- }
202
- return {
203
- ...out,
204
- eventData: _BaseLazyStep.tryParsing(out.eventData)
205
- };
206
- }
207
- if (typeof out !== "string") {
208
- throw new WorkflowError(
209
- `Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
210
- );
211
- }
212
- return this.safeParseOut(out);
213
- }
214
- safeParseOut(out) {
215
- return _BaseLazyStep.tryParsing(out);
216
- }
217
- static tryParsing(stepOut) {
218
- try {
219
- return JSON.parse(stepOut);
220
- } catch {
221
- return stepOut;
222
- }
223
- }
224
178
  };
225
179
  var LazyFunctionStep = class extends BaseLazyStep {
226
180
  stepFunction;
227
181
  stepType = "Run";
228
- allowUndefinedOut = true;
229
182
  constructor(stepName, stepFunction) {
230
183
  super(stepName);
231
184
  this.stepFunction = stepFunction;
@@ -256,7 +209,6 @@ var LazyFunctionStep = class extends BaseLazyStep {
256
209
  var LazySleepStep = class extends BaseLazyStep {
257
210
  sleep;
258
211
  stepType = "SleepFor";
259
- allowUndefinedOut = true;
260
212
  constructor(stepName, sleep) {
261
213
  super(stepName);
262
214
  this.sleep = sleep;
@@ -284,7 +236,6 @@ var LazySleepStep = class extends BaseLazyStep {
284
236
  var LazySleepUntilStep = class extends BaseLazyStep {
285
237
  sleepUntil;
286
238
  stepType = "SleepUntil";
287
- allowUndefinedOut = true;
288
239
  constructor(stepName, sleepUntil) {
289
240
  super(stepName);
290
241
  this.sleepUntil = sleepUntil;
@@ -308,11 +259,8 @@ var LazySleepUntilStep = class extends BaseLazyStep {
308
259
  concurrent
309
260
  });
310
261
  }
311
- safeParseOut() {
312
- return void 0;
313
- }
314
262
  };
315
- var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
263
+ var LazyCallStep = class extends BaseLazyStep {
316
264
  url;
317
265
  method;
318
266
  body;
@@ -321,7 +269,6 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
321
269
  timeout;
322
270
  flowControl;
323
271
  stepType = "Call";
324
- allowUndefinedOut = false;
325
272
  constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
326
273
  super(stepName);
327
274
  this.url = url;
@@ -353,53 +300,11 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
353
300
  callHeaders: this.headers
354
301
  });
355
302
  }
356
- safeParseOut(out) {
357
- const { header, status, body } = JSON.parse(out);
358
- const responseHeaders = new Headers(header);
359
- if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
360
- const bytes = new Uint8Array(out.length);
361
- for (let i = 0; i < out.length; i++) {
362
- bytes[i] = out.charCodeAt(i);
363
- }
364
- const processedResult = new TextDecoder().decode(bytes);
365
- const newBody = JSON.parse(processedResult).body;
366
- return {
367
- status,
368
- header,
369
- body: BaseLazyStep.tryParsing(newBody)
370
- };
371
- } else {
372
- return { header, status, body };
373
- }
374
- }
375
- static applicationHeaders = /* @__PURE__ */ new Set([
376
- "application/json",
377
- "application/xml",
378
- "application/javascript",
379
- "application/x-www-form-urlencoded",
380
- "application/xhtml+xml",
381
- "application/ld+json",
382
- "application/rss+xml",
383
- "application/atom+xml"
384
- ]);
385
- static isText = (contentTypeHeader) => {
386
- if (!contentTypeHeader) {
387
- return false;
388
- }
389
- if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
390
- return true;
391
- }
392
- if (contentTypeHeader.startsWith("text/")) {
393
- return true;
394
- }
395
- return false;
396
- };
397
303
  };
398
304
  var LazyWaitForEventStep = class extends BaseLazyStep {
399
305
  eventId;
400
306
  timeout;
401
307
  stepType = "Wait";
402
- allowUndefinedOut = false;
403
308
  constructor(stepName, eventId, timeout) {
404
309
  super(stepName);
405
310
  this.eventId = eventId;
@@ -426,13 +331,6 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
426
331
  concurrent
427
332
  });
428
333
  }
429
- safeParseOut(out) {
430
- const result = JSON.parse(out);
431
- return {
432
- ...result,
433
- eventData: BaseLazyStep.tryParsing(result.eventData)
434
- };
435
- }
436
334
  };
437
335
  var LazyNotifyStep = class extends LazyFunctionStep {
438
336
  stepType = "Notify";
@@ -446,18 +344,10 @@ var LazyNotifyStep = class extends LazyFunctionStep {
446
344
  };
447
345
  });
448
346
  }
449
- safeParseOut(out) {
450
- const result = JSON.parse(out);
451
- return {
452
- ...result,
453
- eventData: BaseLazyStep.tryParsing(result.eventData)
454
- };
455
- }
456
347
  };
457
348
  var LazyInvokeStep = class extends BaseLazyStep {
458
349
  stepType = "Invoke";
459
350
  params;
460
- allowUndefinedOut = false;
461
351
  constructor(stepName, {
462
352
  workflow,
463
353
  body,
@@ -497,13 +387,6 @@ var LazyInvokeStep = class extends BaseLazyStep {
497
387
  concurrent
498
388
  });
499
389
  }
500
- safeParseOut(out) {
501
- const result = JSON.parse(out);
502
- return {
503
- ...result,
504
- body: BaseLazyStep.tryParsing(result.body)
505
- };
506
- }
507
390
  };
508
391
 
509
392
  // node_modules/neverthrow/dist/index.es.js
@@ -1486,7 +1369,7 @@ var invokeWorkflow = async ({
1486
1369
  headers: Object.fromEntries(
1487
1370
  Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
1488
1371
  ),
1489
- workflowRunId,
1372
+ workflowRunId: context.workflowRunId,
1490
1373
  workflowUrl: context.url,
1491
1374
  step: invokeStep
1492
1375
  };
@@ -1600,7 +1483,7 @@ var AutoExecutor = class _AutoExecutor {
1600
1483
  step,
1601
1484
  stepCount: this.stepCount
1602
1485
  });
1603
- return lazyStep.parseOut(step.out);
1486
+ return step.out;
1604
1487
  }
1605
1488
  const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
1606
1489
  await this.debug?.log("INFO", "RUN_SINGLE", {
@@ -1675,9 +1558,7 @@ var AutoExecutor = class _AutoExecutor {
1675
1558
  case "last": {
1676
1559
  const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
1677
1560
  validateParallelSteps(parallelSteps, parallelResultSteps);
1678
- return parallelResultSteps.map(
1679
- (step, index) => parallelSteps[index].parseOut(step.out)
1680
- );
1561
+ return parallelResultSteps.map((step) => step.out);
1681
1562
  }
1682
1563
  }
1683
1564
  const fillValue = void 0;
@@ -2518,7 +2399,7 @@ var WorkflowContext = class {
2518
2399
  */
2519
2400
  async run(stepName, stepFunction) {
2520
2401
  const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
2521
- return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2402
+ return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2522
2403
  }
2523
2404
  /**
2524
2405
  * Stops the execution for the duration provided.
@@ -2589,27 +2470,43 @@ var WorkflowContext = class {
2589
2470
  * }
2590
2471
  */
2591
2472
  async call(stepName, settings) {
2592
- const {
2593
- url,
2594
- method = "GET",
2595
- body: requestBody,
2596
- headers = {},
2597
- retries = 0,
2598
- timeout,
2599
- flowControl
2600
- } = settings;
2601
- return await this.addStep(
2473
+ const { url, method = "GET", body, headers = {}, retries = 0, timeout, flowControl } = settings;
2474
+ const result = await this.addStep(
2602
2475
  new LazyCallStep(
2603
2476
  stepName,
2604
2477
  url,
2605
2478
  method,
2606
- requestBody,
2479
+ body,
2607
2480
  headers,
2608
2481
  retries,
2609
2482
  timeout,
2610
2483
  flowControl
2611
2484
  )
2612
2485
  );
2486
+ if (typeof result === "string") {
2487
+ try {
2488
+ const body2 = JSON.parse(result);
2489
+ return {
2490
+ status: 200,
2491
+ header: {},
2492
+ body: body2
2493
+ };
2494
+ } catch {
2495
+ return {
2496
+ status: 200,
2497
+ header: {},
2498
+ body: result
2499
+ };
2500
+ }
2501
+ }
2502
+ try {
2503
+ return {
2504
+ ...result,
2505
+ body: JSON.parse(result.body)
2506
+ };
2507
+ } catch {
2508
+ return result;
2509
+ }
2613
2510
  }
2614
2511
  /**
2615
2512
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
@@ -2648,7 +2545,15 @@ var WorkflowContext = class {
2648
2545
  async waitForEvent(stepName, eventId, options = {}) {
2649
2546
  const { timeout = "7d" } = options;
2650
2547
  const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
2651
- return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
2548
+ const result = await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
2549
+ try {
2550
+ return {
2551
+ ...result,
2552
+ eventData: JSON.parse(result.eventData)
2553
+ };
2554
+ } catch {
2555
+ return result;
2556
+ }
2652
2557
  }
2653
2558
  /**
2654
2559
  * Notify workflow runs waiting for an event
@@ -2672,12 +2577,24 @@ var WorkflowContext = class {
2672
2577
  * @returns notify response which has event id, event data and list of waiters which were notified
2673
2578
  */
2674
2579
  async notify(stepName, eventId, eventData) {
2675
- return await this.addStep(
2580
+ const result = await this.addStep(
2676
2581
  new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
2677
2582
  );
2583
+ try {
2584
+ return {
2585
+ ...result,
2586
+ eventData: JSON.parse(result.eventData)
2587
+ };
2588
+ } catch {
2589
+ return result;
2590
+ }
2678
2591
  }
2679
2592
  async invoke(stepName, settings) {
2680
- return await this.addStep(new LazyInvokeStep(stepName, settings));
2593
+ const result = await this.addStep(new LazyInvokeStep(stepName, settings));
2594
+ return {
2595
+ ...result,
2596
+ body: result.body ? JSON.parse(result.body) : void 0
2597
+ };
2681
2598
  }
2682
2599
  /**
2683
2600
  * Cancel the current workflow run
@@ -2836,6 +2753,10 @@ var processRawSteps = (rawSteps) => {
2836
2753
  const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
2837
2754
  const otherSteps = stepsToDecode.map((rawStep) => {
2838
2755
  const step = JSON.parse(decodeBase64(rawStep.body));
2756
+ try {
2757
+ step.out = JSON.parse(step.out);
2758
+ } catch {
2759
+ }
2839
2760
  if (step.waitEventId) {
2840
2761
  const newOut = {
2841
2762
  eventData: step.out ? decodeBase64(step.out) : void 0,
package/svelte.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase,
4
4
  serveManyBase
5
- } from "./chunk-N2WV5VCD.mjs";
5
+ } from "./chunk-GFNR743S.mjs";
6
6
 
7
7
  // platforms/svelte.ts
8
8
  var telemetry = {
@@ -14,7 +14,6 @@ import * as _ai_sdk_openai from '@ai-sdk/openai';
14
14
  declare abstract class BaseLazyStep<TResult = unknown> {
15
15
  readonly stepName: string;
16
16
  abstract readonly stepType: StepType;
17
- protected abstract readonly allowUndefinedOut: boolean;
18
17
  constructor(stepName: string);
19
18
  /**
20
19
  * plan step to submit when step will run parallel with other
@@ -33,17 +32,6 @@ declare abstract class BaseLazyStep<TResult = unknown> {
33
32
  * @param stepId
34
33
  */
35
34
  abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
36
- /**
37
- * parse the out field of a step result.
38
- *
39
- * will be called when returning the steps to the context from auto executor
40
- *
41
- * @param out field of the step
42
- * @returns parsed out field
43
- */
44
- parseOut(out: unknown): TResult;
45
- protected safeParseOut(out: string): TResult;
46
- protected static tryParsing(stepOut: unknown): any;
47
35
  }
48
36
 
49
37
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
@@ -991,7 +979,11 @@ declare class WorkflowContext<TInitialPayload = unknown> {
991
979
  * @returns notify response which has event id, event data and list of waiters which were notified
992
980
  */
993
981
  notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
994
- invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<InvokeStepResponse<TResult>>;
982
+ invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<{
983
+ body: TResult;
984
+ isCanceled?: boolean;
985
+ isFailed?: boolean;
986
+ }>;
995
987
  /**
996
988
  * Cancel the current workflow run
997
989
  *
@@ -14,7 +14,6 @@ import * as _ai_sdk_openai from '@ai-sdk/openai';
14
14
  declare abstract class BaseLazyStep<TResult = unknown> {
15
15
  readonly stepName: string;
16
16
  abstract readonly stepType: StepType;
17
- protected abstract readonly allowUndefinedOut: boolean;
18
17
  constructor(stepName: string);
19
18
  /**
20
19
  * plan step to submit when step will run parallel with other
@@ -33,17 +32,6 @@ declare abstract class BaseLazyStep<TResult = unknown> {
33
32
  * @param stepId
34
33
  */
35
34
  abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
36
- /**
37
- * parse the out field of a step result.
38
- *
39
- * will be called when returning the steps to the context from auto executor
40
- *
41
- * @param out field of the step
42
- * @returns parsed out field
43
- */
44
- parseOut(out: unknown): TResult;
45
- protected safeParseOut(out: string): TResult;
46
- protected static tryParsing(stepOut: unknown): any;
47
35
  }
48
36
 
49
37
  declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
@@ -991,7 +979,11 @@ declare class WorkflowContext<TInitialPayload = unknown> {
991
979
  * @returns notify response which has event id, event data and list of waiters which were notified
992
980
  */
993
981
  notify(stepName: string, eventId: string, eventData: unknown): Promise<NotifyStepResponse>;
994
- invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<InvokeStepResponse<TResult>>;
982
+ invoke<TInitialPayload, TResult>(stepName: string, settings: LazyInvokeStepParams<TInitialPayload, TResult>): Promise<{
983
+ body: TResult;
984
+ isCanceled?: boolean;
985
+ isFailed?: boolean;
986
+ }>;
995
987
  /**
996
988
  * Cancel the current workflow run
997
989
  *