@@ -237,7 +237,7 @@ export class WorkflowContext<TInitialPayload = unknown> {
237
237
) : Promise < TResult > {
238
238
const wrappedStepFunction = ( ( ) =>
239
239
this . executor . wrapStep ( stepName , stepFunction ) ) as StepFunction < TResult > ;
240
- return this . addStep < TResult > ( new LazyFunctionStep ( stepName , wrappedStepFunction ) ) ;
240
+ return await this . addStep < TResult > ( new LazyFunctionStep ( stepName , wrappedStepFunction ) ) ;
241
241
}
242
242
243
243
/**
@@ -316,51 +316,28 @@ export class WorkflowContext<TInitialPayload = unknown> {
316
316
stepName : string ,
317
317
settings : CallSettings < TBody >
318
318
) : Promise < CallResponse < TResult > > {
319
- const { url, method = "GET" , body, headers = { } , retries = 0 , timeout, flowControl } = settings ;
319
+ const {
320
+ url,
321
+ method = "GET" ,
322
+ body : requestBody ,
323
+ headers = { } ,
324
+ retries = 0 ,
325
+ timeout,
326
+ flowControl,
327
+ } = settings ;
320
328
321
- const result = await this . addStep (
322
- new LazyCallStep < CallResponse < string > | string > (
329
+ return await this . addStep (
330
+ new LazyCallStep < TResult > (
323
331
stepName ,
324
332
url ,
325
333
method ,
326
- body ,
334
+ requestBody ,
327
335
headers ,
328
336
retries ,
329
337
timeout ,
330
338
flowControl
331
339
)
332
340
) ;
333
-
334
- // <for backwards compatibity>
335
- // if you transition to upstash/workflow from upstash/qstash,
336
- // the out field in the steps will be the body of the response.
337
- // we need to handle them explicitly here
338
- if ( typeof result === "string" ) {
339
- try {
340
- const body = JSON . parse ( result ) ;
341
- return {
342
- status : 200 ,
343
- header : { } ,
344
- body,
345
- } ;
346
- } catch {
347
- return {
348
- status : 200 ,
349
- header : { } ,
350
- body : result as TResult ,
351
- } ;
352
- }
353
- }
354
- // </for backwards compatibity>
355
-
356
- try {
357
- return {
358
- ...result ,
359
- body : JSON . parse ( result . body as string ) ,
360
- } ;
361
- } catch {
362
- return result as CallResponse < TResult > ;
363
- }
364
341
}
365
342
366
343
/**
@@ -406,16 +383,7 @@ export class WorkflowContext<TInitialPayload = unknown> {
406
383
407
384
const timeoutStr = typeof timeout === "string" ? timeout : `${ timeout } s` ;
408
385
409
- const result = await this . addStep ( new LazyWaitForEventStep ( stepName , eventId , timeoutStr ) ) ;
410
-
411
- try {
412
- return {
413
- ...result ,
414
- eventData : JSON . parse ( result . eventData as string ) ,
415
- } ;
416
- } catch {
417
- return result ;
418
- }
386
+ return await this . addStep ( new LazyWaitForEventStep ( stepName , eventId , timeoutStr ) ) ;
419
387
}
420
388
421
389
/**
@@ -444,30 +412,16 @@ export class WorkflowContext<TInitialPayload = unknown> {
444
412
eventId : string ,
445
413
eventData : unknown
446
414
) : Promise < NotifyStepResponse > {
447
- const result = await this . addStep (
415
+ return await this . addStep (
448
416
new LazyNotifyStep ( stepName , eventId , eventData , this . qstashClient . http )
449
417
) ;
450
-
451
- try {
452
- return {
453
- ...result ,
454
- eventData : JSON . parse ( result . eventData as string ) ,
455
- } ;
456
- } catch {
457
- return result ;
458
- }
459
418
}
460
419
461
420
public async invoke < TInitialPayload , TResult > (
462
421
stepName : string ,
463
422
settings : LazyInvokeStepParams < TInitialPayload , TResult >
464
423
) {
465
- const result = await this . addStep ( new LazyInvokeStep ( stepName , settings ) ) ;
466
-
467
- return {
468
- ...result ,
469
- body : ( result . body ? JSON . parse ( result . body as string ) : undefined ) as TResult ,
470
- } ;
424
+ return await this . addStep ( new LazyInvokeStep ( stepName , settings ) ) ;
471
425
}
472
426
473
427
/**
0 commit comments