Remove custom tshd types and createTshdClient boilerplate#39828
Merged
Remove custom tshd types and createTshdClient boilerplate#39828
createTshdClient boilerplate#39828Conversation
ravicious
reviewed
Mar 26, 2024
Member
ravicious
left a comment
There was a problem hiding this comment.
I reviewed the PR up until web/packages/teleterm/src/ui/DocumentGatewayApp/DocumentGatewayApp.story.tsx, I'll continue the review tomorrow.
It's looking good so far!
avatus
approved these changes
Mar 26, 2024
Contributor
avatus
left a comment
There was a problem hiding this comment.
It looks good to me. Mostly just renames and parameter refactors
ravicious
reviewed
Mar 27, 2024
Member
ravicious
left a comment
There was a problem hiding this comment.
Got to web/packages/teleterm/src/ui/services/fileTransferClient/fileTransferService.ts, will continue tomorrow.
ravicious
approved these changes
Mar 28, 2024
Member
ravicious
left a comment
There was a problem hiding this comment.
I clicked around the app a bit and everything appears to be fine. 👍
Member
There was a problem hiding this comment.
Could you add a return type for this method? It looks like if we add as const to kind, we don't have to do any casting.
Patch
diff --git a/e b/e
index 62fb227d1e..8084bfca7e 160000
--- a/e
+++ b/e
@@ -1 +1 @@
-Subproject commit 62fb227d1ec4b03e226c5ce9cdf63f588e9156b6
+Subproject commit 8084bfca7ed439777af0e9b43946b2e67704a920
diff --git a/web/packages/teleterm/src/ui/services/resources/resourcesService.ts b/web/packages/teleterm/src/ui/services/resources/resourcesService.ts
index b7de3ba213..60b3fbb3cc 100644
--- a/web/packages/teleterm/src/ui/services/resources/resourcesService.ts
+++ b/web/packages/teleterm/src/ui/services/resources/resourcesService.ts
@@ -174,7 +174,7 @@ export class ResourcesService {
async listUnifiedResources(
params: types.ListUnifiedResourcesRequest,
abortSignal: AbortSignal
- ) {
+ ): Promise<{ nextKey: string; resources: UnifiedResourceResponse[] }> {
const { response } = await this.tshClient.listUnifiedResources(params, {
abort: cloneAbortSignal(abortSignal),
});
@@ -184,28 +184,28 @@ export class ResourcesService {
.map(p => {
if (resourceOneOfIsServer(p.resource)) {
return {
- kind: 'server',
+ kind: 'server' as const,
resource: p.resource.server,
};
}
if (resourceOneOfIsDatabase(p.resource)) {
return {
- kind: 'database',
+ kind: 'database' as const,
resource: p.resource.database,
};
}
if (resourceOneOfIsApp(p.resource)) {
return {
- kind: 'app',
+ kind: 'app' as const,
resource: p.resource.app,
};
}
if (resourceOneOfIsKube(p.resource)) {
return {
- kind: 'kube',
+ kind: 'kube' as const,
resource: p.resource.kube,
};
}
@@ -214,7 +214,7 @@ export class ResourcesService {
`Ignoring unsupported resource ${JSON.stringify(p)}.`
);
})
- .filter(Boolean) as UnifiedResourceResponse[],
+ .filter(Boolean),
};
}
}
When we used `ReplaceRpcOptions`, the editor was not able to provide autocompletion for methods' parameters.
We will no longer be able to extend the tshd type, as it will be removed.
56bf00a to
83fe593
Compare
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.
e counterpart https://github.com/gravitational/teleport.e/pull/3788
Since we merged #39229, the
createTshdClientlayer is actually no longer needed, as it only converts the requests and responses between tshd types and generated proto types.This PR removes this layer, along with the custom tshd types. This makes adding new gRPC methods much simpler: you add it to the
.protofile, runmake grpcand that's it - you can start using it in the code.There is unfortunately one downside of removing the custom types: I had to also remove the typed uris. Previously we were able to cast the proto types to our types with
asincreateTshdClient(which OTOH wasn't too safe). Now there is nocreateTshdClient, so there is no place to cast the type (and doing it in every call site would be super inconvenient).I tried to use TypeScript's declaration merging to overwrite the generated
*Uri: stringtypes with our typed uris but with no luck - it is not possible to change the type of an existing property - you can only add new ones.Because of that I had to change types of URIs to strings in
uri.ts.As always, I recommend reviewing commit-by-commit (the last one is unfortunately quite big).