@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/nextjs.js CHANGED
@@ -154,21 +154,22 @@ function getWorkflowRunId(id) {
154
154
  return `wfr_${id ?? nanoid()}`;
155
155
  }
156
156
  function decodeBase64(base64) {
157
- const binString = atob(base64);
158
157
  try {
158
+ const binString = atob(base64);
159
159
  const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
160
160
  return new TextDecoder().decode(intArray);
161
161
  } catch (error) {
162
162
  console.warn(
163
163
  `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
164
164
  );
165
- return binString;
165
+ return atob(base64);
166
166
  }
167
167
  }
168
168
 
169
169
  // src/context/steps.ts
170
- var BaseLazyStep = class _BaseLazyStep {
170
+ var BaseLazyStep = class {
171
171
  stepName;
172
+ // will be set in the subclasses
172
173
  constructor(stepName) {
173
174
  if (!stepName) {
174
175
  throw new WorkflowError(
@@ -177,58 +178,10 @@ var BaseLazyStep = class _BaseLazyStep {
177
178
  }
178
179
  this.stepName = stepName;
179
180
  }
180
- /**
181
- * parse the out field of a step result.
182
- *
183
- * will be called when returning the steps to the context from auto executor
184
- *
185
- * @param out field of the step
186
- * @returns parsed out field
187
- */
188
- parseOut(out) {
189
- if (out === void 0) {
190
- if (this.allowUndefinedOut) {
191
- return void 0;
192
- } else {
193
- throw new WorkflowError(
194
- `Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
195
- );
196
- }
197
- }
198
- if (typeof out === "object") {
199
- if (this.stepType !== "Wait") {
200
- console.warn(
201
- `Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
202
- );
203
- return out;
204
- }
205
- return {
206
- ...out,
207
- eventData: _BaseLazyStep.tryParsing(out.eventData)
208
- };
209
- }
210
- if (typeof out !== "string") {
211
- throw new WorkflowError(
212
- `Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
213
- );
214
- }
215
- return this.safeParseOut(out);
216
- }
217
- safeParseOut(out) {
218
- return _BaseLazyStep.tryParsing(out);
219
- }
220
- static tryParsing(stepOut) {
221
- try {
222
- return JSON.parse(stepOut);
223
- } catch {
224
- return stepOut;
225
- }
226
- }
227
181
  };
228
182
  var LazyFunctionStep = class extends BaseLazyStep {
229
183
  stepFunction;
230
184
  stepType = "Run";
231
- allowUndefinedOut = true;
232
185
  constructor(stepName, stepFunction) {
233
186
  super(stepName);
234
187
  this.stepFunction = stepFunction;
@@ -259,7 +212,6 @@ var LazyFunctionStep = class extends BaseLazyStep {
259
212
  var LazySleepStep = class extends BaseLazyStep {
260
213
  sleep;
261
214
  stepType = "SleepFor";
262
- allowUndefinedOut = true;
263
215
  constructor(stepName, sleep) {
264
216
  super(stepName);
265
217
  this.sleep = sleep;
@@ -287,7 +239,6 @@ var LazySleepStep = class extends BaseLazyStep {
287
239
  var LazySleepUntilStep = class extends BaseLazyStep {
288
240
  sleepUntil;
289
241
  stepType = "SleepUntil";
290
- allowUndefinedOut = true;
291
242
  constructor(stepName, sleepUntil) {
292
243
  super(stepName);
293
244
  this.sleepUntil = sleepUntil;
@@ -311,11 +262,8 @@ var LazySleepUntilStep = class extends BaseLazyStep {
311
262
  concurrent
312
263
  });
313
264
  }
314
- safeParseOut() {
315
- return void 0;
316
- }
317
265
  };
318
- var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
266
+ var LazyCallStep = class extends BaseLazyStep {
319
267
  url;
320
268
  method;
321
269
  body;
@@ -324,7 +272,6 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
324
272
  timeout;
325
273
  flowControl;
326
274
  stepType = "Call";
327
- allowUndefinedOut = false;
328
275
  constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
329
276
  super(stepName);
330
277
  this.url = url;
@@ -356,53 +303,11 @@ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
356
303
  callHeaders: this.headers
357
304
  });
358
305
  }
359
- safeParseOut(out) {
360
- const { header, status, body } = JSON.parse(out);
361
- const responseHeaders = new Headers(header);
362
- if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
363
- const bytes = new Uint8Array(out.length);
364
- for (let i = 0; i < out.length; i++) {
365
- bytes[i] = out.charCodeAt(i);
366
- }
367
- const processedResult = new TextDecoder().decode(bytes);
368
- const newBody = JSON.parse(processedResult).body;
369
- return {
370
- status,
371
- header,
372
- body: BaseLazyStep.tryParsing(newBody)
373
- };
374
- } else {
375
- return { header, status, body };
376
- }
377
- }
378
- static applicationHeaders = /* @__PURE__ */ new Set([
379
- "application/json",
380
- "application/xml",
381
- "application/javascript",
382
- "application/x-www-form-urlencoded",
383
- "application/xhtml+xml",
384
- "application/ld+json",
385
- "application/rss+xml",
386
- "application/atom+xml"
387
- ]);
388
- static isText = (contentTypeHeader) => {
389
- if (!contentTypeHeader) {
390
- return false;
391
- }
392
- if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
393
- return true;
394
- }
395
- if (contentTypeHeader.startsWith("text/")) {
396
- return true;
397
- }
398
- return false;
399
- };
400
306
  };
401
307
  var LazyWaitForEventStep = class extends BaseLazyStep {
402
308
  eventId;
403
309
  timeout;
404
310
  stepType = "Wait";
405
- allowUndefinedOut = false;
406
311
  constructor(stepName, eventId, timeout) {
407
312
  super(stepName);
408
313
  this.eventId = eventId;
@@ -429,13 +334,6 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
429
334
  concurrent
430
335
  });
431
336
  }
432
- safeParseOut(out) {
433
- const result = JSON.parse(out);
434
- return {
435
- ...result,
436
- eventData: BaseLazyStep.tryParsing(result.eventData)
437
- };
438
- }
439
337
  };
440
338
  var LazyNotifyStep = class extends LazyFunctionStep {
441
339
  stepType = "Notify";
@@ -449,18 +347,10 @@ var LazyNotifyStep = class extends LazyFunctionStep {
449
347
  };
450
348
  });
451
349
  }
452
- safeParseOut(out) {
453
- const result = JSON.parse(out);
454
- return {
455
- ...result,
456
- eventData: BaseLazyStep.tryParsing(result.eventData)
457
- };
458
- }
459
350
  };
460
351
  var LazyInvokeStep = class extends BaseLazyStep {
461
352
  stepType = "Invoke";
462
353
  params;
463
- allowUndefinedOut = false;
464
354
  constructor(stepName, {
465
355
  workflow,
466
356
  body,
@@ -500,13 +390,6 @@ var LazyInvokeStep = class extends BaseLazyStep {
500
390
  concurrent
501
391
  });
502
392
  }
503
- safeParseOut(out) {
504
- const result = JSON.parse(out);
505
- return {
506
- ...result,
507
- body: BaseLazyStep.tryParsing(result.body)
508
- };
509
- }
510
393
  };
511
394
 
512
395
  // node_modules/neverthrow/dist/index.es.js
@@ -1489,7 +1372,7 @@ var invokeWorkflow = async ({
1489
1372
  headers: Object.fromEntries(
1490
1373
  Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
1491
1374
  ),
1492
- workflowRunId,
1375
+ workflowRunId: context.workflowRunId,
1493
1376
  workflowUrl: context.url,
1494
1377
  step: invokeStep
1495
1378
  };
@@ -1603,7 +1486,7 @@ var AutoExecutor = class _AutoExecutor {
1603
1486
  step,
1604
1487
  stepCount: this.stepCount
1605
1488
  });
1606
- return lazyStep.parseOut(step.out);
1489
+ return step.out;
1607
1490
  }
1608
1491
  const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
1609
1492
  await this.debug?.log("INFO", "RUN_SINGLE", {
@@ -1678,9 +1561,7 @@ var AutoExecutor = class _AutoExecutor {
1678
1561
  case "last": {
1679
1562
  const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
1680
1563
  validateParallelSteps(parallelSteps, parallelResultSteps);
1681
- return parallelResultSteps.map(
1682
- (step, index) => parallelSteps[index].parseOut(step.out)
1683
- );
1564
+ return parallelResultSteps.map((step) => step.out);
1684
1565
  }
1685
1566
  }
1686
1567
  const fillValue = void 0;
@@ -2521,7 +2402,7 @@ var WorkflowContext = class {
2521
2402
  */
2522
2403
  async run(stepName, stepFunction) {
2523
2404
  const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
2524
- return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2405
+ return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2525
2406
  }
2526
2407
  /**
2527
2408
  * Stops the execution for the duration provided.
@@ -2592,27 +2473,43 @@ var WorkflowContext = class {
2592
2473
  * }
2593
2474
  */
2594
2475
  async call(stepName, settings) {
2595
- const {
2596
- url,
2597
- method = "GET",
2598
- body: requestBody,
2599
- headers = {},
2600
- retries = 0,
2601
- timeout,
2602
- flowControl
2603
- } = settings;
2604
- return await this.addStep(
2476
+ const { url, method = "GET", body, headers = {}, retries = 0, timeout, flowControl } = settings;
2477
+ const result = await this.addStep(
2605
2478
  new LazyCallStep(
2606
2479
  stepName,
2607
2480
  url,
2608
2481
  method,
2609
- requestBody,
2482
+ body,
2610
2483
  headers,
2611
2484
  retries,
2612
2485
  timeout,
2613
2486
  flowControl
2614
2487
  )
2615
2488
  );
2489
+ if (typeof result === "string") {
2490
+ try {
2491
+ const body2 = JSON.parse(result);
2492
+ return {
2493
+ status: 200,
2494
+ header: {},
2495
+ body: body2
2496
+ };
2497
+ } catch {
2498
+ return {
2499
+ status: 200,
2500
+ header: {},
2501
+ body: result
2502
+ };
2503
+ }
2504
+ }
2505
+ try {
2506
+ return {
2507
+ ...result,
2508
+ body: JSON.parse(result.body)
2509
+ };
2510
+ } catch {
2511
+ return result;
2512
+ }
2616
2513
  }
2617
2514
  /**
2618
2515
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
@@ -2651,7 +2548,15 @@ var WorkflowContext = class {
2651
2548
  async waitForEvent(stepName, eventId, options = {}) {
2652
2549
  const { timeout = "7d" } = options;
2653
2550
  const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
2654
- return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
2551
+ const result = await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
2552
+ try {
2553
+ return {
2554
+ ...result,
2555
+ eventData: JSON.parse(result.eventData)
2556
+ };
2557
+ } catch {
2558
+ return result;
2559
+ }
2655
2560
  }
2656
2561
  /**
2657
2562
  * Notify workflow runs waiting for an event
@@ -2675,12 +2580,24 @@ var WorkflowContext = class {
2675
2580
  * @returns notify response which has event id, event data and list of waiters which were notified
2676
2581
  */
2677
2582
  async notify(stepName, eventId, eventData) {
2678
- return await this.addStep(
2583
+ const result = await this.addStep(
2679
2584
  new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
2680
2585
  );
2586
+ try {
2587
+ return {
2588
+ ...result,
2589
+ eventData: JSON.parse(result.eventData)
2590
+ };
2591
+ } catch {
2592
+ return result;
2593
+ }
2681
2594
  }
2682
2595
  async invoke(stepName, settings) {
2683
- return await this.addStep(new LazyInvokeStep(stepName, settings));
2596
+ const result = await this.addStep(new LazyInvokeStep(stepName, settings));
2597
+ return {
2598
+ ...result,
2599
+ body: result.body ? JSON.parse(result.body) : void 0
2600
+ };
2684
2601
  }
2685
2602
  /**
2686
2603
  * Cancel the current workflow run
@@ -2839,6 +2756,10 @@ var processRawSteps = (rawSteps) => {
2839
2756
  const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
2840
2757
  const otherSteps = stepsToDecode.map((rawStep) => {
2841
2758
  const step = JSON.parse(decodeBase64(rawStep.body));
2759
+ try {
2760
+ step.out = JSON.parse(step.out);
2761
+ } catch {
2762
+ }
2842
2763
  if (step.waitEventId) {
2843
2764
  const newOut = {
2844
2765
  eventData: step.out ? decodeBase64(step.out) : void 0,
package/nextjs.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/nextjs.ts
8
8
  var appTelemetry = {
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@upstash/workflow","version":"v0.2.10-unicode-rc","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.0","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^4.21.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.20","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@ai-sdk/openai":"^1.0.15","@upstash/qstash":"^2.7.22","ai":"^4.0.30","zod":"^3.24.1"},"directories":{"example":"examples"}}
1
+ {"name":"@upstash/workflow","version":"v0.2.10","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"},"./astro":{"import":"./astro.mjs","require":"./astro.js"},"./express":{"import":"./express.mjs","require":"./express.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","@types/express":"^5.0.0","astro":"^4.16.7","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","express":"^4.21.1","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.20","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsup":"^8.3.0","typescript":"^5.7.2","typescript-eslint":"^8.18.0"},"dependencies":{"@ai-sdk/openai":"^1.0.15","@upstash/qstash":"^2.7.22","ai":"^4.0.30","zod":"^3.24.1"},"directories":{"example":"examples"}}
@@ -1,4 +1,4 @@
1
- import { k as PublicServeOptions, R as RouteFunction, t as InvokableWorkflow } from './types-Dg_9L83G.mjs';
1
+ import { k as PublicServeOptions, R as RouteFunction, t as InvokableWorkflow } from './types-CYhDXnf8.mjs';
2
2
 
3
3
  type OmitOptionsInServeMany<TOptions> = Omit<TOptions, "env" | "url" | "schema" | "initialPayloadParser">;
4
4
  declare const serveManyBase: <THandler extends (...params: any[]) => any, TOptions extends OmitOptionsInServeMany<PublicServeOptions> = OmitOptionsInServeMany<PublicServeOptions>, TServeParams extends [routeFunction: RouteFunction<any, any>, options: TOptions] = [routeFunction: RouteFunction<any, any>, options: TOptions]>({ workflows, getUrl, serveMethod, options, }: {
@@ -1,4 +1,4 @@
1
- import { k as PublicServeOptions, R as RouteFunction, t as InvokableWorkflow } from './types-Dg_9L83G.js';
1
+ import { k as PublicServeOptions, R as RouteFunction, t as InvokableWorkflow } from './types-CYhDXnf8.js';
2
2
 
3
3
  type OmitOptionsInServeMany<TOptions> = Omit<TOptions, "env" | "url" | "schema" | "initialPayloadParser">;
4
4
  declare const serveManyBase: <THandler extends (...params: any[]) => any, TOptions extends OmitOptionsInServeMany<PublicServeOptions> = OmitOptionsInServeMany<PublicServeOptions>, TServeParams extends [routeFunction: RouteFunction<any, any>, options: TOptions] = [routeFunction: RouteFunction<any, any>, options: TOptions]>({ workflows, getUrl, serveMethod, options, }: {
package/solidjs.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, k as PublicServeOptions } from './types-Dg_9L83G.mjs';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-CYhDXnf8.mjs';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';
package/solidjs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { APIEvent } from '@solidjs/start/server';
2
- import { R as RouteFunction, k as PublicServeOptions } from './types-Dg_9L83G.js';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-CYhDXnf8.js';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';