Add NoExcessive type and confidential http helper#251
Open
ernest-nowacki wants to merge 3 commits intomainfrom
Open
Add NoExcessive type and confidential http helper#251ernest-nowacki wants to merge 3 commits intomainfrom
ernest-nowacki wants to merge 3 commits intomainfrom
Conversation
nolag
approved these changes
May 4, 2026
russell-stern
approved these changes
May 4, 2026
| (opts.bodyBytes !== undefined ? 1 : 0) | ||
| if (bodyFieldsSet > 1) { | ||
| throw new Error( | ||
| 'httpRequest: body, bodyString and bodyBytes are mutually exclusive (proto oneof)', |
There was a problem hiding this comment.
If this is what the developer sees we should give them a bit more clarity. They probably don't need to know we use proto under the hood so something like `'httpRequest: specify the request body using only one of: body, bodyString, or bodyBytes'
| out.bodyString = JSON.stringify(opts.body, (_k, v) => | ||
| typeof v === 'bigint' ? v.toString() : v, | ||
| ) | ||
| } |
There was a problem hiding this comment.
We should wrap this in a try/catch in case JSON.stringify errors from bad input we can give a better error message than the generic error it will return
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Two related improvements to how callers pass requests into capability methods:
httpRequesthelper forConfidentialHTTPClient— supports ability to just usebodyfield with json and make allow helper to put into the right protooneof(bodyString/bodyBytes). Havingbodyin http request is super popular and well expected within TypeScript community so I consider it worthy addon. The drawback is that we would need to manually maintain this helper if there are proto changes to the capability itself.NoExcess/CapabilityInputinput gating — every generated capability method now rejects unknown keys on the JSON input shape, even when the request is lifted into a variable. Previously TypeScript's structural typing only triggered excess-property checks on inline object literals; once a request was bound to aconst, using fields likebody(instead ofbodyString) silently compiled.Added a new workflow example demonstrating usage of the helper.
Native protobuf messages are still accepted unchanged —
CapabilityInputbranches on the$typeNamebrand and only appliesNoExcessto JSON shapes.Before / After
Before — manual proto-aware payload, plus stale keys silently allowed once bound to a variable:
After — single ergonomic
body, and unknown keys fail at the call boundary:The raw form still works for callers who want it —
httpRequestis opt-in:Notes
body,bodyString, andbodyBytesare mutually exclusive (protooneof); supplying more than one throws.headersandmultiHeadersmay both be supplied —multiHeadersis applied first,headersentries replace per-name.NoExcessrecursion stops at primitives,Uint8Array, and index-signature maps (e.g.multiHeaders[string]), so dynamic header names remain unrestricted. Depth bound is 6 to keep tsc work bounded.