refac: SammoAPI Path 정의에 NumVar, StrVar 추가
This commit is contained in:
+4
-22
@@ -1,27 +1,9 @@
|
||||
import type { InvalidResponse, ReserveBulkCommandResponse } from "./defs";
|
||||
import type { Args } from "./processing/args";
|
||||
import { callSammoAPI, type ValidResponse } from "./util/callSammoAPI";
|
||||
import { callSammoAPI, done, type CallbackT, type RawArgType, type ValidResponse } from "./util/callSammoAPI";
|
||||
export type { ValidResponse, InvalidResponse };
|
||||
|
||||
import { APIPathGen } from "./util/APIPathGen.js";
|
||||
|
||||
type RawArgType = Record<string, unknown>|Record<string, unknown>[];
|
||||
|
||||
interface CallbackT<ResultType extends ValidResponse, ErrorType extends InvalidResponse, ArgType extends RawArgType>{
|
||||
(args?: ArgType): Promise<ResultType>;
|
||||
(args: ArgType | undefined, returnError: false): Promise<ResultType>;
|
||||
(args: ArgType | undefined, returnError: true): Promise<ResultType | ErrorType>;
|
||||
}
|
||||
|
||||
async function done<ResultType extends ValidResponse>(args?: RawArgType): Promise<ResultType>;
|
||||
async function done<ResultType extends ValidResponse>(args: RawArgType | undefined, returnError: false): Promise<ResultType>;
|
||||
async function done<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(args: RawArgType | undefined, returnError: true): Promise<ResultType | ErrorType>;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
const apiRealPath = {
|
||||
Betting: {
|
||||
Bet: done,
|
||||
@@ -33,11 +15,11 @@ const apiRealPath = {
|
||||
PushCommand: done,
|
||||
RepeatCommand: done,
|
||||
ReserveCommand: done,
|
||||
ReserveBulkCommand: done as CallbackT<ReserveBulkCommandResponse, InvalidResponse, {
|
||||
ReserveBulkCommand: done as CallbackT<{
|
||||
turnList: number[],
|
||||
action: string,
|
||||
arg: Args
|
||||
}[]>,
|
||||
}[], ReserveBulkCommandResponse>,
|
||||
},
|
||||
General: {
|
||||
Join: done,
|
||||
@@ -75,4 +57,4 @@ export const SammoAPI = APIPathGen(apiRealPath, (path: string[]) => {
|
||||
}
|
||||
return callSammoAPI(path.join('/'), args);
|
||||
};
|
||||
}) as typeof apiRealPath;
|
||||
});
|
||||
Reference in New Issue
Block a user