@@ -2,6 +2,7 @@ import type { WalkerOS } from '@elbwalker/types';
22import type { SourceNode , Elb } from '../types' ;
33import {
44 assign ,
5+ createPushResult ,
56 isCommand ,
67 isSameType ,
78 pushToDestinations ,
@@ -15,12 +16,7 @@ export function createPush(instance: SourceNode.Instance): Elb.Fn {
1516 data : Elb . PushData = { } ,
1617 options ?: Elb . PushOptions ,
1718 ) => {
18- let result : Elb . PushResult = {
19- status : { ok : false } ,
20- successful : [ ] ,
21- queued : [ ] ,
22- failed : [ ] ,
23- } ;
19+ let result : Elb . PushResult ;
2420
2521 return await tryCatchAsync (
2622 async (
@@ -36,28 +32,19 @@ export function createPush(instance: SourceNode.Instance): Elb.Fn {
3632
3733 if ( command ) {
3834 // Command event
39- const commandResult = await handleCommand (
40- instance ,
41- command ,
42- data ,
43- options ,
44- ) ;
45- result = assign ( result , commandResult ) ;
35+ result = await handleCommand ( instance , command , data , options ) ;
4636 } else if ( event ) {
4737 // Regular event
48- const eventResult = await pushToDestinations ( instance , event ) ;
49- result = assign ( result , eventResult ) ;
50- result . event = event ;
38+ result = await pushToDestinations ( instance , event ) ;
5139 }
5240
53- return assign ( { status : { ok : true } } , result ) ;
41+ return createPushResult ( result ) ;
5442 } ,
5543 ( error ) => {
5644 // Call custom error handling
5745 if ( instance . config . onError ) instance . config . onError ( error , instance ) ;
5846
59- result . status . error = String ( error ) ;
60- return result ;
47+ return createPushResult ( { ok : false } ) ;
6148 } ,
6249 ) ( nameOrEvent , data , options ) ;
6350 } ;
0 commit comments