From ed497d79d59b09e6acc3c53557c9721877664ee2 Mon Sep 17 00:00:00 2001 From: _LittleC_ <26459759+XxLittleCxX@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:13:16 +0800 Subject: [PATCH] fix: string id should be number, fix #1 (#2) --- src/types.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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)) }) } }