@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/solidjs.js CHANGED
@@ -149,21 +149,22 @@ function getWorkflowRunId(id) {
149
149
  return `wfr_${id ?? nanoid()}`;
150
150
  }
151
151
  function decodeBase64(base64) {
152
- const binString = atob(base64);
153
152
  try {
153
+ const binString = atob(base64);
154
154
  const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
155
155
  return new TextDecoder().decode(intArray);
156
156
  } catch (error) {
157
157
  console.warn(
158
158
  `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
159
159
  );
160
- return binString;
160
+ return atob(base64);
161
161
  }
162
162
  }
163
163
 
164
164
  // src/context/steps.ts
165
- var BaseLazyStep = class _BaseLazyStep {
165
+ var BaseLazyStep = class {
166
166
  stepName;
167
+ // will be set in the subclasses
167
168
  constructor(stepName) {
168
169
  if (!stepName) {
169
170
  throw new WorkflowError(
@@ -172,58 +173,10 @@ var BaseLazyStep = class _BaseLazyStep {
172
173
  }
173
174
  this.stepName = stepName;
174
175
  }
175
- /**
176
- * parse the out field of a step result.
177
- *
178
- * will be called when returning the steps to the context from auto executor
179
- *
180
- * @param out field of the step
181
- * @returns parsed out field
182
- */
183
- parseOut(out) {
184
- if (out === void 0) {
185
- if (this.allowUndefinedOut) {
186
- return void 0;
187
- } else {
188
- throw new WorkflowError(
189
- `Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
190
- );
191
- }
192
- }
193
- if (typeof out === "object") {
194
- if (this.stepType !== "Wait") {
195
- console.warn(
196
- `Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
197
- );
198
- return out;
199
- }
200
- return {
201
- ...out,
202
- eventData: _BaseLazyStep.tryParsing(out.eventData)
203
- };
204
- }
205
- if (typeof out !== "string") {
206
- throw new WorkflowError(
207
- `Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
208
- );
209
- }
210
- return this.safeParseOut(out);
211
- }
212
- safeParseOut(out) {
213
- return _BaseLazyStep.tryParsing(out);
214
- }
215
- static tryParsing(stepOut) {
216
- try {
217
- return JSON.parse(stepOut);
218
- } catch {
219
- return stepOut;
220
- }
221
- }
222
176
  };
223
177
  var LazyFunctionStep = class extends BaseLazyStep {
224
178
  stepFunction;
225
179
  stepType = "Run";
226
- allowUndefinedOut = true;
227
180
  constructor(stepName, stepFunction) {
228
181
  super(stepName);
229
182
  this.stepFunction = stepFunction;
@@ -254,7 +207,6 @@ var LazyFunctionStep = class extends BaseLazyStep {
254
207
  var LazySleepStep = class extends BaseLazyStep {
255
208
  sleep;
256
209
  stepType = "SleepFor";
257
- allowUndefinedOut = true;
258
210
  constructor(stepName, sleep) {
259
211
  super(stepName);
260
212
  this.sleep = sleep;
@@ -282,7 +234,6 @@ var LazySleepStep = class extends BaseLazyStep {
282
234
  var LazySleepUntilStep = class extends BaseLazyStep {
283
235
  sleepUntil;
284
236
  stepType = "SleepUntil";
285
- allowUndefinedOut = true;
286
237
  constructor(stepName, sleepUntil) {
287
238
  super(stepName);
288
239
  this.sleepUntil = sleepUntil;
@@ -306,11 +257,8 @@ var LazySleepUntilStep = class extends BaseLazyStep {
306
257
  concurrent
307
258
  });
308
259
  }
309
- safeParseOut() {
310
- return void 0;
311
- }
312
260
  };
313
- var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
261
+ var LazyCallStep = class extends BaseLazyStep {
314
262
  url;
315
263
  method;
316
264
  body;
@@ -319,7 +267,6 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
319
267
  timeout;
320
268
  flowControl;
321
269
  stepType = "Call";
322
- allowUndefinedOut = false;
323
270
  constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
324
271
  super(stepName);
325
272
  this.url = url;
@@ -351,53 +298,11 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
351
298
  callHeaders: this.headers
352
299
  });
353
300
  }
354
- safeParseOut(out) {
355
- const { header, status, body } = JSON.parse(out);
356
- const responseHeaders = new Headers(header);
357
- if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
358
- const bytes = new Uint8Array(out.length);
359
- for (let i = 0; i < out.length; i++) {
360
- bytes[i] = out.charCodeAt(i);
361
- }
362
- const processedResult = new TextDecoder().decode(bytes);
363
- const newBody = JSON.parse(processedResult).body;
364
- return {
365
- status,
366
- header,
367
- body: BaseLazyStep.tryParsing(newBody)
368
- };
369
- } else {
370
- return { header, status, body };
371
- }
372
- }
373
- static applicationHeaders = /* @__PURE__ */ new Set([
374
- "application/json",
375
- "application/xml",
376
- "application/javascript",
377
- "application/x-www-form-urlencoded",
378
- "application/xhtml+xml",
379
- "application/ld+json",
380
- "application/rss+xml",
381
- "application/atom+xml"
382
- ]);
383
- static isText = (contentTypeHeader) => {
384
- if (!contentTypeHeader) {
385
- return false;
386
- }
387
- if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
388
- return true;
389
- }
390
- if (contentTypeHeader.startsWith("text/")) {
391
- return true;
392
- }
393
- return false;
394
- };
395
301
  };
396
302
  var LazyWaitForEventStep = class extends BaseLazyStep {
397
303
  eventId;
398
304
  timeout;
399
305
  stepType = "Wait";
400
- allowUndefinedOut = false;
401
306
  constructor(stepName, eventId, timeout) {
402
307
  super(stepName);
403
308
  this.eventId = eventId;
@@ -424,13 +329,6 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
424
329
  concurrent
425
330
  });
426
331
  }
427
- safeParseOut(out) {
428
- const result = JSON.parse(out);
429
- return {
430
- ...result,
431
- eventData: BaseLazyStep.tryParsing(result.eventData)
432
- };
433
- }
434
332
  };
435
333
  var LazyNotifyStep = class extends LazyFunctionStep {
436
334
  stepType = "Notify";
@@ -444,18 +342,10 @@ var LazyNotifyStep = class extends LazyFunctionStep {
444
342
  };
445
343
  });
446
344
  }
447
- safeParseOut(out) {
448
- const result = JSON.parse(out);
449
- return {
450
- ...result,
451
- eventData: BaseLazyStep.tryParsing(result.eventData)
452
- };
453
- }
454
345
  };
455
346
  var LazyInvokeStep = class extends BaseLazyStep {
456
347
  stepType = "Invoke";
457
348
  params;
458
- allowUndefinedOut = false;
459
349
  constructor(stepName, {
460
350
  workflow,
461
351
  body,
@@ -495,13 +385,6 @@ var LazyInvokeStep = class extends BaseLazyStep {
495
385
  concurrent
496
386
  });
497
387
  }
498
- safeParseOut(out) {
499
- const result = JSON.parse(out);
500
- return {
501
- ...result,
502
- body: BaseLazyStep.tryParsing(result.body)
503
- };
504
- }
505
388
  };
506
389
 
507
390
  // node_modules/neverthrow/dist/index.es.js
@@ -1423,7 +1306,7 @@ var invokeWorkflow = async ({
1423
1306
  headers: Object.fromEntries(
1424
1307
  Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
1425
1308
  ),
1426
- workflowRunId,
1309
+ workflowRunId: context.workflowRunId,
1427
1310
  workflowUrl: context.url,
1428
1311
  step: invokeStep
1429
1312
  };
@@ -1537,7 +1420,7 @@ var AutoExecutor = class _AutoExecutor {
1537
1420
  step,
1538
1421
  stepCount: this.stepCount
1539
1422
  });
1540
- return lazyStep.parseOut(step.out);
1423
+ return step.out;
1541
1424
  }
1542
1425
  const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
1543
1426
  await this.debug?.log("INFO", "RUN_SINGLE", {
@@ -1612,9 +1495,7 @@ var AutoExecutor = class _AutoExecutor {
1612
1495
  case "last": {
1613
1496
  const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
1614
1497
  validateParallelSteps(parallelSteps, parallelResultSteps);
1615
- return parallelResultSteps.map(
1616
- (step, index) => parallelSteps[index].parseOut(step.out)
1617
- );
1498
+ return parallelResultSteps.map((step) => step.out);
1618
1499
  }
1619
1500
  }
1620
1501
  const fillValue = void 0;
@@ -2455,7 +2336,7 @@ var WorkflowContext = class {
2455
2336
  */
2456
2337
  async run(stepName, stepFunction) {
2457
2338
  const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
2458
- return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2339
+ return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2459
2340
  }
2460
2341
  /**
2461
2342
  * Stops the execution for the duration provided.
@@ -2526,27 +2407,43 @@ var WorkflowContext = class {
2526
2407
  * }
2527
2408
  */
2528
2409
  async call(stepName, settings) {
2529
- const {
2530
- url,
2531
- method = "GET",
2532
- body: requestBody,
2533
- headers = {},
2534
- retries = 0,
2535
- timeout,
2536
- flowControl
2537
- } = settings;
2538
- return await this.addStep(
2410
+ const { url, method = "GET", body, headers = {}, retries = 0, timeout, flowControl } = settings;
2411
+ const result = await this.addStep(
2539
2412
  new LazyCallStep(
2540
2413
  stepName,
2541
2414
  url,
2542
2415
  method,
2543
- requestBody,
2416
+ body,
2544
2417
  headers,
2545
2418
  retries,
2546
2419
  timeout,
2547
2420
  flowControl
2548
2421
  )
2549
2422
  );
2423
+ if (typeof result === "string") {
2424
+ try {
2425
+ const body2 = JSON.parse(result);
2426
+ return {
2427
+ status: 200,
2428
+ header: {},
2429
+ body: body2
2430
+ };
2431
+ } catch {
2432
+ return {
2433
+ status: 200,
2434
+ header: {},
2435
+ body: result
2436
+ };
2437
+ }
2438
+ }
2439
+ try {
2440
+ return {
2441
+ ...result,
2442
+ body: JSON.parse(result.body)
2443
+ };
2444
+ } catch {
2445
+ return result;
2446
+ }
2550
2447
  }
2551
2448
  /**
2552
2449
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
@@ -2585,7 +2482,15 @@ var WorkflowContext = class {
2585
2482
  async waitForEvent(stepName, eventId, options = {}) {
2586
2483
  const { timeout = "7d" } = options;
2587
2484
  const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
2588
- return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
2485
+ const result = await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
2486
+ try {
2487
+ return {
2488
+ ...result,
2489
+ eventData: JSON.parse(result.eventData)
2490
+ };
2491
+ } catch {
2492
+ return result;
2493
+ }
2589
2494
  }
2590
2495
  /**
2591
2496
  * Notify workflow runs waiting for an event
@@ -2609,12 +2514,24 @@ var WorkflowContext = class {
2609
2514
  * @returns notify response which has event id, event data and list of waiters which were notified
2610
2515
  */
2611
2516
  async notify(stepName, eventId, eventData) {
2612
- return await this.addStep(
2517
+ const result = await this.addStep(
2613
2518
  new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
2614
2519
  );
2520
+ try {
2521
+ return {
2522
+ ...result,
2523
+ eventData: JSON.parse(result.eventData)
2524
+ };
2525
+ } catch {
2526
+ return result;
2527
+ }
2615
2528
  }
2616
2529
  async invoke(stepName, settings) {
2617
- return await this.addStep(new LazyInvokeStep(stepName, settings));
2530
+ const result = await this.addStep(new LazyInvokeStep(stepName, settings));
2531
+ return {
2532
+ ...result,
2533
+ body: result.body ? JSON.parse(result.body) : void 0
2534
+ };
2618
2535
  }
2619
2536
  /**
2620
2537
  * Cancel the current workflow run
@@ -2773,6 +2690,10 @@ var processRawSteps = (rawSteps) => {
2773
2690
  const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
2774
2691
  const otherSteps = stepsToDecode.map((rawStep) => {
2775
2692
  const step = JSON.parse(decodeBase64(rawStep.body));
2693
+ try {
2694
+ step.out = JSON.parse(step.out);
2695
+ } catch {
2696
+ }
2776
2697
  if (step.waitEventId) {
2777
2698
  const newOut = {
2778
2699
  eventData: step.out ? decodeBase64(step.out) : void 0,
package/solidjs.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
3
  serveBase
4
- } from "./chunk-N2WV5VCD.mjs";
4
+ } from "./chunk-GFNR743S.mjs";
5
5
 
6
6
  // platforms/solidjs.ts
7
7
  var serve = (routeFunction, options) => {
package/svelte.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _sveltejs_kit from '@sveltejs/kit';
2
2
  import { RequestHandler } from '@sveltejs/kit';
3
- import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-Dg_9L83G.mjs';
4
- import { s as serveManyBase } from './serve-many-wMUWrSIP.mjs';
3
+ import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-CYhDXnf8.mjs';
4
+ import { s as serveManyBase } from './serve-many-BVDpPsF-.mjs';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'ai';
package/svelte.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _sveltejs_kit from '@sveltejs/kit';
2
2
  import { RequestHandler } from '@sveltejs/kit';
3
- import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-Dg_9L83G.js';
4
- import { s as serveManyBase } from './serve-many-jCRazho9.js';
3
+ import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-CYhDXnf8.js';
4
+ import { s as serveManyBase } from './serve-many-e4zufyXN.js';
5
5
  import '@upstash/qstash';
6
6
  import 'zod';
7
7
  import 'ai';