Skip to content

feat(rpc): document every export with JSDoc, add getBalance and Valid… - #15

Open
thethclup wants to merge 1 commit into
canopy-network:mainfrom
thethclup:claude/canopy-ts-sdk-improvements-csyi9p
Open

feat(rpc): document every export with JSDoc, add getBalance and Valid…#15
thethclup wants to merge 1 commit into
canopy-network:mainfrom
thethclup:claude/canopy-ts-sdk-improvements-csyi9p

Conversation

@thethclup

Copy link
Copy Markdown

…ationError

The SDK was announced publicly as "a fully typed, documented toolkit to query the chain and ship apps." Three things stood between that pitch and the code a new developer meets after npm i.

Docs were Python-style Args:/Returns: docstrings, a port artifact from the Python SDK: editors render them as one undifferentiated paragraph, so hovering a parameter told you nothing, and they referenced ValueError, an exception this SDK never throws. Every public export in rpc.ts now carries a real JSDoc block -- description, @PARAM, @returns, @throws, and a runnable @example -- so the answers surface inline in the editor.

Reading a balance meant calling account(), receiving a Record<string, any>, and knowing to reach for amount -- a field name discoverable only by reading the e2e tests. getBalance() returns it as a zod-validated number, with the same height option for historical lookups.

Argument validation threw a plain Error, so an invalid address -- the most common mistake a new developer makes -- was the one failure that escaped the CanopyError hierarchy the README promises. It now throws ValidationError, carrying the offending input on .value.

Centralizing the address/hash checks (previously copy-pasted across six functions) also closed two gaps: they verified length but not hex content, so a 40-character non-hex string reached the node and came back as an opaque RPC failure, and NaN slipped past the < 0 guards on height and ID arguments. Both are now rejected up front.

Tests: 42 new unit tests covering getBalance and validation across every argument-taking export; e2e smoke coverage asserting getBalance agrees with the raw account query against a live devnet. 285 unit tests pass, build clean.

…ationError

The SDK was announced publicly as "a fully typed, documented toolkit to query
the chain and ship apps." Three things stood between that pitch and the code a
new developer meets after `npm i`.

Docs were Python-style `Args:`/`Returns:` docstrings, a port artifact from the
Python SDK: editors render them as one undifferentiated paragraph, so hovering
a parameter told you nothing, and they referenced `ValueError`, an exception
this SDK never throws. Every public export in rpc.ts now carries a real JSDoc
block -- description, @PARAM, @returns, @throws, and a runnable @example --
so the answers surface inline in the editor.

Reading a balance meant calling account(), receiving a Record<string, any>,
and knowing to reach for `amount` -- a field name discoverable only by reading
the e2e tests. getBalance() returns it as a zod-validated number, with the
same `height` option for historical lookups.

Argument validation threw a plain Error, so an invalid address -- the most
common mistake a new developer makes -- was the one failure that escaped the
CanopyError hierarchy the README promises. It now throws ValidationError,
carrying the offending input on `.value`.

Centralizing the address/hash checks (previously copy-pasted across six
functions) also closed two gaps: they verified length but not hex content, so
a 40-character non-hex string reached the node and came back as an opaque RPC
failure, and NaN slipped past the `< 0` guards on height and ID arguments.
Both are now rejected up front.

Tests: 42 new unit tests covering getBalance and validation across every
argument-taking export; e2e smoke coverage asserting getBalance agrees with
the raw account query against a live devnet. 285 unit tests pass, build clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants