js-algorand-sdk icon indicating copy to clipboard operation
js-algorand-sdk copied to clipboard

Convert all client responses to typed objects

Open Eric-Warehime opened this issue 1 year ago • 2 comments

Problem

Responses from the client are not automatically converted into the defined model types (for all endpoints).

We've done this for some endpoints (see https://github.com/algorand/js-algorand-sdk/blob/a89046acaf9502f496fca9d781bf33047c969c01/src/client/v2/algod/getApplicationBoxes.ts#L57-L60), but other endpoints, in order to avoid backwards incompatible changes, do not implement this (see https://github.com/algorand/js-algorand-sdk/blob/a89046acaf9502f496fca9d781bf33047c969c01/src/client/v2/algod/getApplicationByID.ts for example).

Solution

Implement the response.from_obj_for_encoding(body) for all endpoints which return structured data.

Dependencies

N/A

Urgency

We should group this with any other breaking changes being made in the next major version bump.

Eric-Warehime avatar Apr 26 '23 18:04 Eric-Warehime

If we want to make typed response objects available sooner, we could consider introducing a new set of functions that can be used in place of do, e.g. doTyped or execute, which would return a typed response. We could then consider deprecating and removing do in v3 -- this would arguably be a safer way of swapping the behavior, since instead of changing a function's return type, we'd be removing the function in favor of a different one.

jasonpaulos avatar May 03 '23 18:05 jasonpaulos

An additional issue to consider w/ this mentioned in #533 is handling the conversion of the returned keys which include hyphens to the JS camel case keys.

Eric-Warehime avatar May 23 '23 20:05 Eric-Warehime