diff --git a/package-lock.json b/package-lock.json index 21b3ff8..fd07adf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@dataswapcore/abi": "^0.1.2", "@glif/filecoin-rpc-client": "^2.0.43", - "@unipackage/utils": "^1.1.1", + "@unipackage/utils": "^1.4.0", "ethers": "^6.8.1", "web3": "^4.0.3" }, @@ -761,9 +761,9 @@ } }, "node_modules/@unipackage/utils": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@unipackage/utils/-/utils-1.1.1.tgz", - "integrity": "sha512-8/Wt9VQK+hCHUf9c5/8N2yBBfCTIcA7s4XzPXkeY6CuhVSEHtPcgt+B8KpYkvJaTjOEvZb4zA/HL8kntiKuukA==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@unipackage/utils/-/utils-1.4.0.tgz", + "integrity": "sha512-4ynlm1t90tiRPw6FjWL4FhSr8+MIQmz7fH72azTJcVHsRMQD65vTqh10qE/a+a4KZYPeWJq+s1m0Vc55K6JoDQ==", "dependencies": { "@types/lodash": "^4.14.199", "num-format": "^0.1.1", diff --git a/package.json b/package.json index 57c1844..f662df9 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "dependencies": { "@dataswapcore/abi": "^0.1.2", "@glif/filecoin-rpc-client": "^2.0.43", - "@unipackage/utils": "^1.1.1", + "@unipackage/utils": "^1.4.0", "ethers": "^6.8.1", "web3": "^4.0.3" }, diff --git a/src/evm/withMethod/index.ts b/src/evm/withMethod/index.ts index 9ec3763..2f58a00 100644 --- a/src/evm/withMethod/index.ts +++ b/src/evm/withMethod/index.ts @@ -19,7 +19,7 @@ ********************************************************************************/ import { isEvmTransactionOptions } from "../interface" -import { withMethods } from "../../shared/withMethods" +import { withMethods } from "@unipackage/utils" /** * withSendMethod:Decorator function to dynamically add methods to a class prototype. diff --git a/src/index.ts b/src/index.ts index bd607b4..5d275b2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,7 +35,6 @@ export { withRequestMethod } from "./rpc/withMethod" export { Rpc } from "./rpc/" export { AbstractRpc } from "./rpc/abstract" -export { withMethods } from "./shared/withMethods" export { InputParams } from "./shared/types/params" export { diff --git a/src/rpc/withMethod/index.ts b/src/rpc/withMethod/index.ts index 1deba6b..a95e260 100644 --- a/src/rpc/withMethod/index.ts +++ b/src/rpc/withMethod/index.ts @@ -19,7 +19,7 @@ ********************************************************************************/ import { isRPCOptions } from "../interface" -import { withMethods } from "../../shared/withMethods" +import { withMethods } from "@unipackage/utils" /** * Decorator function to dynamically add methods to a class prototype. diff --git a/src/shared/withMethods/index.ts b/src/shared/withMethods/index.ts deleted file mode 100644 index 1fa669a..0000000 --- a/src/shared/withMethods/index.ts +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * (c) 2023 unipackage - * - * Licensed under either the MIT License (the "MIT License") or the Apache License, Version 2.0 - * (the "Apache License"). You may not use this file except in compliance with one of these - * licenses. You may obtain a copy of the MIT License at - * - * https://opensource.org/licenses/MIT - * - * Or the Apache License, Version 2.0 at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the MIT License or the Apache License for the specific language governing permissions and - * limitations under the respective licenses. - ********************************************************************************/ - -/** - * Dynamically adds methods to a class prototype based on specified criteria. - * - * @param target - The target class constructor. - * @param methods - An array of method names to be added. - * @param baseMethod - The base method to invoke when the added methods are called. - * @param isOptions - An optional function to check if the last parameter is an options object. - */ -function addMethod( - target: any, - methods: string[], - baseMethod: string, - isOptions?: (parama: any) => boolean -) { - methods.forEach((method) => { - Object.defineProperty(target.prototype, method, { - value: async function (this: any, ...params: any[]) { - let options: any - const lastParam = params[params.length - 1] - if ( - isOptions && - typeof lastParam === "object" && - isOptions(lastParam) - ) { - options = params.pop() - } - return await this[baseMethod]( - { - method, - params, - }, - options - ) - }, - }) - }) -} - -/** - * Decorator function to dynamically add methods to a class prototype. - * - * @param methods - An array of method names to be added. - * @param baseMethod - The base method to invoke when the added methods are called. - * @param isOptions - An optional function to check if the last parameter is an options object. - * @returns A ClassDecorator function. - */ -export function withMethods( - methods: string[], - baseMethod: string, - isOptions?: (parama: any) => boolean -): ClassDecorator { - return function (target: any) { - addMethod(target, methods, baseMethod, isOptions) - } -}