Feature/expose transport layer #89
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why This Change Was Made
As per #88, our previous clients offered inconsistent and minimal transport-layer information. This PR introduces a system to expose rich metadata (HTTP status, headers, timing) for both success and error responses across all generated clients. This enables advanced use cases like client-side caching, rate-limiting, and performance monitoring, while also improving the debugging experience.
A key goal was to provide this new functionality to TypeScript users without introducing breaking changes.
The New API: What's Changed
Rust API (Breaking Change)
Successful responses are now wrapped in an
ApiResult<T>struct, which bundles the deserializedvaluewith itsmetadata.Error handling is also enhanced, with all
Errorvariants now containing metadata accessible via.transport_metadata().TypeScript API (Fully Backward-Compatible)
For Typescript we were using a custom
Resultclass so I added the metadata to that so it should be fully backward-compatible.Success Handling:
unwrap_ok()continues to return the value directly. The newmetadatais available as an optional property on theResultobject itself.Error Handling:
This remains 100% backward-compatible. The existing
.status()method on theErrclass still works, but you can now get the full metadata object via the new.transport_metadata()method.How It Was Implemented
rt.rs): The foundational Rust structs (TransportResponse,TransportMetadata,ApiResult) were created to establish a canonical model. TheClienttrait was updated to return these rich types.lib.ts): An optionalmetadataproperty was added directly to theResultclass.Future considerations
A minor trade-off is a slight "impurity" in the type definition of the TS Result. The Result class now has an optional metadata?: TransportMetadata property. The implementation always sets this on an Ok result, but the type system can't enforce this guarantee. An alternative, more type-pure approach would be a discriminated union:
1 type Result<T, E> =
2 | { kind: "ok", value: T, metadata: TransportMetadata }
3 | { kind: "err", error: E };
With this, the compiler would know that if kind is "ok", metadata is always present. The current approach was chosen to maintain the existing Result class API.