@upstash/workflow 0.2.10-hono-generics → 0.2.10-unicode-rc

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,22 +154,21 @@ function getWorkflowRunId(id) {
154
154
  return `wfr_${id ?? nanoid()}`;
155
155
  }
156
156
  function decodeBase64(base64) {
157
+ const binString = atob(base64);
157
158
  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 atob(base64);
165
+ return binString;
166
166
  }
167
167
  }
168
168
 
169
169
  // src/context/steps.ts
170
- var BaseLazyStep = class {
170
+ var BaseLazyStep = class _BaseLazyStep {
171
171
  stepName;
172
- // will be set in the subclasses
173
172
  constructor(stepName) {
174
173
  if (!stepName) {
175
174
  throw new WorkflowError(
@@ -178,10 +177,58 @@ var BaseLazyStep = class {
178
177
  }
179
178
  this.stepName = stepName;
180
179
  }
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
+ }
181
227
  };
182
228
  var LazyFunctionStep = class extends BaseLazyStep {
183
229
  stepFunction;
184
230
  stepType = "Run";
231
+ allowUndefinedOut = true;
185
232
  constructor(stepName, stepFunction) {
186
233
  super(stepName);
187
234
  this.stepFunction = stepFunction;
@@ -212,6 +259,7 @@ var LazyFunctionStep = class extends BaseLazyStep {
212
259
  var LazySleepStep = class extends BaseLazyStep {
213
260
  sleep;
214
261
  stepType = "SleepFor";
262
+ allowUndefinedOut = true;
215
263
  constructor(stepName, sleep) {
216
264
  super(stepName);
217
265
  this.sleep = sleep;
@@ -239,6 +287,7 @@ var LazySleepStep = class extends BaseLazyStep {
239
287
  var LazySleepUntilStep = class extends BaseLazyStep {
240
288
  sleepUntil;
241
289
  stepType = "SleepUntil";
290
+ allowUndefinedOut = true;
242
291
  constructor(stepName, sleepUntil) {
243
292
  super(stepName);
244
293
  this.sleepUntil = sleepUntil;
@@ -262,8 +311,11 @@ var LazySleepUntilStep = class extends BaseLazyStep {
262
311
  concurrent
263
312
  });
264
313
  }
314
+ safeParseOut() {
315
+ return void 0;
316
+ }
265
317
  };
266
- var LazyCallStep = class extends BaseLazyStep {
318
+ var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
267
319
  url;
268
320
  method;
269
321
  body;
@@ -272,6 +324,7 @@ var LazyCallStep = class extends BaseLazyStep {
272
324
  timeout;
273
325
  flowControl;
274
326
  stepType = "Call";
327
+ allowUndefinedOut = false;
275
328
  constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
276
329
  super(stepName);
277
330
  this.url = url;
@@ -303,11 +356,53 @@ var LazyCallStep = class extends BaseLazyStep {
303
356
  callHeaders: this.headers
304
357
  });
305
358
  }
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
+ };
306
400
  };
307
401
  var LazyWaitForEventStep = class extends BaseLazyStep {
308
402
  eventId;
309
403
  timeout;
310
404
  stepType = "Wait";
405
+ allowUndefinedOut = false;
311
406
  constructor(stepName, eventId, timeout) {
312
407
  super(stepName);
313
408
  this.eventId = eventId;
@@ -334,6 +429,13 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
334
429
  concurrent
335
430
  });
336
431
  }
432
+ safeParseOut(out) {
433
+ const result = JSON.parse(out);
434
+ return {
435
+ ...result,
436
+ eventData: BaseLazyStep.tryParsing(result.eventData)
437
+ };
438
+ }
337
439
  };
338
440
  var LazyNotifyStep = class extends LazyFunctionStep {
339
441
  stepType = "Notify";
@@ -347,10 +449,18 @@ var LazyNotifyStep = class extends LazyFunctionStep {
347
449
  };
348
450
  });
349
451
  }
452
+ safeParseOut(out) {
453
+ const result = JSON.parse(out);
454
+ return {
455
+ ...result,
456
+ eventData: BaseLazyStep.tryParsing(result.eventData)
457
+ };
458
+ }
350
459
  };
351
460
  var LazyInvokeStep = class extends BaseLazyStep {
352
461
  stepType = "Invoke";
353
462
  params;
463
+ allowUndefinedOut = false;
354
464
  constructor(stepName, {
355
465
  workflow,
356
466
  body,
@@ -390,6 +500,13 @@ var LazyInvokeStep = class extends BaseLazyStep {
390
500
  concurrent
391
501
  });
392
502
  }
503
+ safeParseOut(out) {
504
+ const result = JSON.parse(out);
505
+ return {
506
+ ...result,
507
+ body: BaseLazyStep.tryParsing(result.body)
508
+ };
509
+ }
393
510
  };
394
511
 
395
512
  // node_modules/neverthrow/dist/index.es.js
@@ -1486,7 +1603,7 @@ var AutoExecutor = class _AutoExecutor {
1486
1603
  step,
1487
1604
  stepCount: this.stepCount
1488
1605
  });
1489
- return step.out;
1606
+ return lazyStep.parseOut(step.out);
1490
1607
  }
1491
1608
  const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
1492
1609
  await this.debug?.log("INFO", "RUN_SINGLE", {
@@ -1561,7 +1678,9 @@ var AutoExecutor = class _AutoExecutor {
1561
1678
  case "last": {
1562
1679
  const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
1563
1680
  validateParallelSteps(parallelSteps, parallelResultSteps);
1564
- return parallelResultSteps.map((step) => step.out);
1681
+ return parallelResultSteps.map(
1682
+ (step, index) => parallelSteps[index].parseOut(step.out)
1683
+ );
1565
1684
  }
1566
1685
  }
1567
1686
  const fillValue = void 0;
@@ -2402,7 +2521,7 @@ var WorkflowContext = class {
2402
2521
  */
2403
2522
  async run(stepName, stepFunction) {
2404
2523
  const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
2405
- return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2524
+ return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
2406
2525
  }
2407
2526
  /**
2408
2527
  * Stops the execution for the duration provided.
@@ -2473,43 +2592,27 @@ var WorkflowContext = class {
2473
2592
  * }
2474
2593
  */
2475
2594
  async call(stepName, settings) {
2476
- const { url, method = "GET", body, headers = {}, retries = 0, timeout, flowControl } = settings;
2477
- const result = await this.addStep(
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(
2478
2605
  new LazyCallStep(
2479
2606
  stepName,
2480
2607
  url,
2481
2608
  method,
2482
- body,
2609
+ requestBody,
2483
2610
  headers,
2484
2611
  retries,
2485
2612
  timeout,
2486
2613
  flowControl
2487
2614
  )
2488
2615
  );
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
- }
2513
2616
  }
2514
2617
  /**
2515
2618
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
@@ -2548,15 +2651,7 @@ var WorkflowContext = class {
2548
2651
  async waitForEvent(stepName, eventId, options = {}) {
2549
2652
  const { timeout = "7d" } = options;
2550
2653
  const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
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
- }
2654
+ return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
2560
2655
  }
2561
2656
  /**
2562
2657
  * Notify workflow runs waiting for an event
@@ -2580,24 +2675,12 @@ var WorkflowContext = class {
2580
2675
  * @returns notify response which has event id, event data and list of waiters which were notified
2581
2676
  */
2582
2677
  async notify(stepName, eventId, eventData) {
2583
- const result = await this.addStep(
2678
+ return await this.addStep(
2584
2679
  new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
2585
2680
  );
2586
- try {
2587
- return {
2588
- ...result,
2589
- eventData: JSON.parse(result.eventData)
2590
- };
2591
- } catch {
2592
- return result;
2593
- }
2594
2681
  }
2595
2682
  async invoke(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
- };
2683
+ return await this.addStep(new LazyInvokeStep(stepName, settings));
2601
2684
  }
2602
2685
  /**
2603
2686
  * Cancel the current workflow run
@@ -2756,10 +2839,6 @@ var processRawSteps = (rawSteps) => {
2756
2839
  const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
2757
2840
  const otherSteps = stepsToDecode.map((rawStep) => {
2758
2841
  const step = JSON.parse(decodeBase64(rawStep.body));
2759
- try {
2760
- step.out = JSON.parse(step.out);
2761
- } catch {
2762
- }
2763
2842
  if (step.waitEventId) {
2764
2843
  const newOut = {
2765
2844
  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-IPXJZU3K.mjs";
5
+ } from "./chunk-N2WV5VCD.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-hono-generics","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-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,4 +1,4 @@
1
- import { k as PublicServeOptions, R as RouteFunction, t as InvokableWorkflow } from './types-CYhDXnf8.js';
1
+ import { k as PublicServeOptions, R as RouteFunction, t as InvokableWorkflow } from './types-Dg_9L83G.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, }: {
@@ -1,4 +1,4 @@
1
- import { k as PublicServeOptions, R as RouteFunction, t as InvokableWorkflow } from './types-CYhDXnf8.mjs';
1
+ import { k as PublicServeOptions, R as RouteFunction, t as InvokableWorkflow } from './types-Dg_9L83G.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, }: {
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-CYhDXnf8.mjs';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-Dg_9L83G.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-CYhDXnf8.js';
2
+ import { R as RouteFunction, k as PublicServeOptions } from './types-Dg_9L83G.js';
3
3
  import '@upstash/qstash';
4
4
  import 'zod';
5
5
  import 'ai';