Repository navigation
Conversation
`@nexus.definition` names an SDK type, such as a Stream definition, that gives the type arguments of a generic resource. An operation that returns the resource takes it in place of runtime types.
This was referenced Oct 28, 2026
Owner
Author
|
Duplicate of #80, 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 adds
@nexus.definition, which names an SDK type that gives the type arguments of a generic resource.An operation that returns the resource takes the definition in place of its runtime types.
definition: type[StreamDefinition[BodyT]]as its first positional parameter, socreate_stream(Turns, stream_id=...)returns aStream[Turn]whenTurnssubclassesStreamDefinition[Turn]. The support helperdefinition_type_arguments(definition)returns the runtime types. The module of the type is imported undertyping.TYPE_CHECKING, since the SDK module that defines it can import the generated package.definition: StreamDefinition<BodyT>before its request, and the support helperdefinitionTypeArguments(definition)returns the type info. A relativetypescript-importis relative to the root of the generated package.StreamDefinition<TBody> definition, which gives the type argument.nexgen refuses
@nexus.definitionon a resource with no@nexus.type-parameter.The stream sample's Stream takes a definition. No SDK has
StreamDefinitionyet, so the sample names a type of its own support code in each language.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, and on #77.Why?
The Stream API of the proposal creates a Stream from a definition, as in
client.create_stream(Turns, id=...). A definition has the value type and the Stream name, and its form is an SDK idiom in each language, like a Workflow definition. So the SDK defines it, and nexgen accepts it where a runtime type goes. A later PR lets a source read the definition, for the Stream id of a Workflow.The methods of a resource keep the runtime types of the handle, so only an operation that returns the resource takes a definition. The design also had a standalone function whose output needs a runtime type take one, but the TypeScript and .NET resource methods call those functions, and they have no definition.
How did you test it?
A Python test creates a Stream from a definition class and checks
Stream[Turn]withassert_typeunder basedpyright. A TypeScript test checks that a create keeps the type info of the definition, and its type withexpectTypeOf. A .NET compile check creates aStream<Turn>from a definition. A unit test checks that only the create takes the definition, and a rejection fixture covers the refusal.cargo validatepasses.