refac: SammoAPI Path 정의에 NumVar, StrVar 추가

This commit is contained in:
2022-03-25 23:29:10 +09:00
parent 11e28b7a87
commit 00ceb3f842
5 changed files with 51 additions and 33 deletions
+17
View File
@@ -6,6 +6,14 @@ export type ValidResponse = {
result: true
}
export type RawArgType = Record<string, unknown>|Record<string, unknown>[];
export interface CallbackT<ArgType extends RawArgType, ResultType extends ValidResponse = ValidResponse, ErrorType extends InvalidResponse = InvalidResponse>{
(args?: ArgType): Promise<ResultType>;
(args: ArgType | undefined, returnError: false): Promise<ResultType>;
(args: ArgType | undefined, returnError: true): Promise<ResultType | ErrorType>;
}
export async function callSammoAPI<ResultType extends ValidResponse>(path: string | string[], args?: Record<string, unknown> | Record<string, unknown>[]): Promise<ResultType>;
export async function callSammoAPI<ResultType extends ValidResponse>(path: string | string[], args: Record<string, unknown> | Record<string, unknown>[] | undefined, returnError: false): Promise<ResultType>;
export async function callSammoAPI<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(path: string | string[], args: Record<string, unknown> | Record<string, unknown>[] | undefined, returnError: true): Promise<ResultType | ErrorType>;
@@ -29,4 +37,13 @@ export async function callSammoAPI<ResultType extends ValidResponse, ErrorType e
throw result.reason;
}
return result;
}
export async function done<ResultType extends ValidResponse>(args?: RawArgType): Promise<ResultType>;
export async function done<ResultType extends ValidResponse>(args: RawArgType | undefined, returnError: false): Promise<ResultType>;
export async function done<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(args: RawArgType | undefined, returnError: true): Promise<ResultType | ErrorType>;
export async function done<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(args?: RawArgType, returnError = false): Promise<ResultType | ErrorType> {
console.error(`Can't directly call. ${args}, ${returnError}. Use auto-generated path API.`);
return callSammoAPI<ResultType, ErrorType>([], args, true);
}