sarvalabs / js-moi-sdk

JavaScript library to interact with MOI Protocol via RPC API
https://js-moi-sdk.docs.moi.technology/
Apache License 2.0
24 stars 2 forks source link

Implement passing a tuple/object as arguments when invoking a routine #28

Closed Bhimgouda closed 9 months ago

Bhimgouda commented 11 months ago

Passing a tuple/object with argument keys when invoking a endpoint

Description

In the current implementation of cocolang, developers must explicitly mention argument variable names, even when passing a single argument to a function, as demonstrated by the following syntax:

someFunc(name: bhim)

Inspired by this approach, there is a proposal to enhance the js-moi-sdk by adopting a similar convention. The idea is to use tuples instead of arrays when passing arguments to endpoints, aligning the SDK syntax more closely with the cocolang convention.

The current syntax for passing arguments in the SDK looks like this:

logicDriver.routines.someFunc(["bhim"])

The proposed syntax, on the other hand, suggests using a more structured and readable format:

logicDriver.routines.someFunc({name: "Bhim"})

In this proposed change, each argument is explicitly labeled with its corresponding parameter name. To ensure code integrity, the SDK should implement thorough validation. If there is a mistake in the number of arguments provided, an invalid argument name, or a datatype mismatch, the SDK should check against the manifest and throw an appropriate error.

sarvalabs-harshrastogi commented 9 months ago

resolved in https://github.com/sarvalabs/js-moi-sdk/pull/36