Repository navigation
Conversation
A resource with `@nexus.type-parameter "<alias>"` is generic in Python, TypeScript and .NET. Its operations take a runtime type where the request can't give one, so a response decodes its generic values.
This was referenced Oct 28, 2026
Owner
Author
|
Duplicate of #78, which has the same commit. |
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.
What changed?
This PR lets a resource declare its type parameters, in Python, TypeScript and .NET.
A resource names each type parameter alias that it uses with
@nexus.type-parameter "<alias>", in order. The alias can come from another interface throughuse. The resource class is then generic, and it keeps a runtime type for each parameter.create_stream(Turn, stream_id=...)in Python, and it returns aStream[Turn].ReadRecordsResponse[body_type]as the output type. TypeScript converts the response with the model'screate<Model>TransferTypeConverterfactory and the handle'sTypeInfo. .NET calls the generic operation with the class'sTBody.nexgen also refuses a resource that uses a parameter that it doesn't declare (also through a proto-backed record), a declared parameter that the resource doesn't use, and a parameter of a bound operation that the resource doesn't declare. A generic resource can't be the result of an operation with no
@nexus.protomessage, or a field of a record, since neither carries the type arguments.The stream samples take the parameter
body-ton the bodies ofappend-recordandstream-data, and the Stream and the writer declare it. Brook's WIT takes the same directives later.The TypeScript resource methods now branch on a
stringparameter only when the parameter is a function reference. Before, a bound operation with a generic request made every optionalstringparameter branch.It is for review here before it goes upstream. It sits on the upstream stack temporalio#308, temporalio#310, temporalio#311, temporalio#297, temporalio#296, temporalio#303, temporalio#304, temporalio#309, temporalio#318, temporalio#319, temporalio#320, temporalio#321, temporalio#322, temporalio#323, temporalio#324, temporalio#325, whose head is
review/p3-base.Why?
The Stream API of the proposal is generic in its value type, as in
Stream[Turn]. The generated Stream class is that API, so the body of a read must decode as the handle's type, not as a raw payload. A resource couldn't use a type parameter at all before this PR.How did you test it?
Python tests decode a read through the System Nexus converter with the handle's body type, and check
Stream[Turn]andReadRecordsResponse[Turn]withassert_typeunder basedpyright. A TypeScript test checks that the started read decodes a body with the handle'sTypeInfo, and it checks the types withexpectTypeOf. A .NET test round trips a data item asReadRecordsResponse<Turn>, and a compile check reads aStream<Turn>. Unit tests cover the runtime types of each stream operation, and a writer parameter thatusebrings in. Rejection fixtures cover each refusal.cargo validatepasses.