diff options
author | Sebastian <sebasjm@gmail.com> | 2023-11-03 18:59:27 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-11-03 18:59:27 -0300 |
commit | 08898c7aa32b5a4dbc40c2fecd82a5a652126705 (patch) | |
tree | 9a82a960784e025caf0f2eb7f32e9b8292d46403 /packages/taler-util/src/operation.ts | |
parent | 368a87a361e845dd748036f10a66b7f202f84df8 (diff) | |
download | wallet-core-08898c7aa32b5a4dbc40c2fecd82a5a652126705.tar.xz |
update to the new bank api breaking changes
Diffstat (limited to 'packages/taler-util/src/operation.ts')
-rw-r--r-- | packages/taler-util/src/operation.ts | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/packages/taler-util/src/operation.ts b/packages/taler-util/src/operation.ts index 8adbbb0e2..9d7594d14 100644 --- a/packages/taler-util/src/operation.ts +++ b/packages/taler-util/src/operation.ts @@ -67,8 +67,29 @@ export async function failOrThrow<E>(s: E, cb: () => Promise<OperationResult<unk export type ResultByMethod<TT extends object, p extends keyof TT> = TT[p] extends (...args: any[]) => infer Ret ? Ret extends Promise<infer Result> ? - Result : + Result extends OperationResult<any, any> ? Result : never : never : //api always use Promises never; //error cases just for functions export type FailCasesByMethod<TT extends object, p extends keyof TT> = Exclude<ResultByMethod<TT, p>, OperationOk<any>> + +type MethodsOfOperations<T extends object> = keyof { + [P in keyof T as + //when the property is a function + T[P] extends (...args: any[]) => infer Ret ? + // that returns a promise + Ret extends Promise<infer Result> ? + // of an operation + Result extends OperationResult<any, any> ? + P : never + : never + : never]: any +} + +type AllKnownCases<t extends object, d extends keyof t> = "success" | FailCasesByMethod<t, d>["case"] + +export type TestForApi<ApiType extends object> = { + [OpType in MethodsOfOperations<ApiType> as `test_${OpType & string}`]: { + [c in AllKnownCases<ApiType, OpType>]: undefined | ((api: ApiType) => Promise<void>); + }; +}; |