@@ -4,19 +4,19 @@ import type { ClientContext, ClientOptions, ClientPromiseResult, FriendlyClientO
44import { isDefinedError } from './error'
55
66export type SafeResult < TOutput , TError > =
7- | [ error : null , data : TOutput , isDefined : false , success : true ]
8- & { error : null , data : TOutput , isDefined : false , success : true }
9- | [ error : Exclude < TError , ORPCError < any , any > > , data : undefined , isDefined : false , success : false ]
10- & { error : Exclude < TError , ORPCError < any , any > > , data : undefined , isDefined : false , success : false }
11- | [ error : Extract < TError , ORPCError < any , any > > , data : undefined , isDefined : true , success : false ]
12- & { error : Extract < TError , ORPCError < any , any > > , data : undefined , isDefined : true , success : false }
7+ | [ error : null , data : TOutput , isDefined : false , isSuccess : true ]
8+ & { error : null , data : TOutput , isDefined : false , isSuccess : true }
9+ | [ error : Exclude < TError , ORPCError < any , any > > , data : undefined , isDefined : false , isSuccess : false ]
10+ & { error : Exclude < TError , ORPCError < any , any > > , data : undefined , isDefined : false , isSuccess : false }
11+ | [ error : Extract < TError , ORPCError < any , any > > , data : undefined , isDefined : true , isSuccess : false ]
12+ & { error : Extract < TError , ORPCError < any , any > > , data : undefined , isDefined : true , isSuccess : false }
1313
1414export async function safe < TOutput , TError = ThrowableError > ( promise : ClientPromiseResult < TOutput , TError > ) : Promise < SafeResult < TOutput , TError > > {
1515 try {
1616 const output = await promise
1717 return Object . assign (
1818 [ null , output , false , true ] satisfies [ null , TOutput , false , true ] ,
19- { error : null , data : output , isDefined : false as const , success : true as const } ,
19+ { error : null , data : output , isDefined : false as const , isSuccess : true as const } ,
2020 )
2121 }
2222 catch ( e ) {
@@ -25,13 +25,13 @@ export async function safe<TOutput, TError = ThrowableError>(promise: ClientProm
2525 if ( isDefinedError ( error ) ) {
2626 return Object . assign (
2727 [ error , undefined , true , false ] satisfies [ typeof error , undefined , true , false ] ,
28- { error, data : undefined , isDefined : true as const , success : false as const } ,
28+ { error, data : undefined , isDefined : true as const , isSuccess : false as const } ,
2929 )
3030 }
3131
3232 return Object . assign (
3333 [ error as Exclude < TError , ORPCError < any , any > > , undefined , false , false ] satisfies [ Exclude < TError , ORPCError < any , any > > , undefined , false , false ] ,
34- { error : error as Exclude < TError , ORPCError < any , any > > , data : undefined , isDefined : false as const , success : false as const } ,
34+ { error : error as Exclude < TError , ORPCError < any , any > > , data : undefined , isDefined : false as const , isSuccess : false as const } ,
3535 )
3636 }
3737}
0 commit comments