diff --git a/src/types.ts b/src/types.ts index 63d0469..103309e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -575,25 +575,33 @@ export class Internal { return [prop, isAsync] as const } + private static prepareArg(params: string[], args: any[]) { + const fixedArg = Object.fromEntries(params.map((name, index) => [name, args[index]])) + for (const key in fixedArg) { + if (key.endsWith("_id")) fixedArg[key] = +fixedArg[key] + } + return fixedArg + } + static define(name: string, ...params: string[]) { const [prop, isAsync] = Internal.prepareMethod(name) Internal.prototype[prop] = async function (this: Internal, ...args: any[]) { - const data = await this._get(name, Object.fromEntries(params.map((name, index) => [name, args[index]]))) + const data = await this._get(name, Internal.prepareArg(params, args)) if (!isAsync) return data } isAsync && (Internal.prototype[prop + 'Async'] = async function (this: Internal, ...args: any[]) { - await this._get(name + '_async', Object.fromEntries(params.map((name, index) => [name, args[index]]))) + await this._get(name + '_async', Internal.prepareArg(params, args)) }) } static defineExtract(name: string, key: string, ...params: string[]) { const [prop, isAsync] = Internal.prepareMethod(name) Internal.prototype[prop] = async function (this: Internal, ...args: any[]) { - const data = await this._get(name, Object.fromEntries(params.map((name, index) => [name, args[index]]))) + const data = await this._get(name, Internal.prepareArg(params, args)) return data[key] } isAsync && (Internal.prototype[prop + 'Async'] = async function (this: Internal, ...args: any[]) { - await this._get(name + '_async', Object.fromEntries(params.map((name, index) => [name, args[index]]))) + await this._get(name + '_async', Internal.prepareArg(params, args)) }) } }