Skip to content

Commit dd268d7

Browse files
committed
Rename protocol to version
1 parent ad0cc1c commit dd268d7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/client.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
ServerReflectionResponse,
2121
} from './reflection_providers/v1alpha/reflection_pb';
2222

23-
const supportedReflectionProtocols = {
23+
const supportedReflectionAPIVersions = {
2424
v1alpha: {
2525
priority: 0,
2626
serviceName: 'grpc.reflection.v1alpha.ServerReflection',
@@ -98,9 +98,9 @@ export class Client {
9898
private async evaluateServerReflectionProtocol() {
9999
const evaluationPromises = [];
100100

101-
// Check protocol compatibility and initialize gRPC client based on that
102-
for (const protocol of Object.keys(supportedReflectionProtocols)) {
103-
type PromiseReturnType = {
101+
// Check version compatibility and initialize gRPC client based on that
102+
for (const version of Object.keys(supportedReflectionAPIVersions)) {
103+
type ReflectionCheckPromiseReturnType = {
104104
successful: boolean;
105105
priority: number;
106106
effect?: () => void;
@@ -109,10 +109,10 @@ export class Client {
109109

110110
evaluationPromises.push(
111111
// eslint-disable-next-line no-async-promise-executor
112-
new Promise<PromiseReturnType>(async resolve => {
112+
new Promise<ReflectionCheckPromiseReturnType>(async resolve => {
113113
const protocolConfig =
114-
supportedReflectionProtocols[
115-
protocol as keyof typeof supportedReflectionProtocols
114+
supportedReflectionAPIVersions[
115+
version as keyof typeof supportedReflectionAPIVersions
116116
];
117117
const {
118118
service: servicePromise,
@@ -145,7 +145,7 @@ export class Client {
145145
priority: protocolConfig.priority,
146146
effect: () => {
147147
this.grpcClient = grpcClientForProtocol;
148-
this.compatibleProtocol = protocol;
148+
this.compatibleProtocol = version;
149149
this.CompatibleServerReflectionRequest =
150150
protocolClient.ServerReflectionRequest;
151151
this.reflectionResponseCache = reflectionResponse;
@@ -169,8 +169,9 @@ export class Client {
169169
.sort((res1, res2) => res2.priority - res1.priority);
170170

171171
if (!successfulReflectionByPriority) {
172+
// TODO: Do we error out here or just return empty results?
172173
const noCompatibleProtocolRrror = new Error(
173-
'No compatible reflection protocol found.'
174+
'No compatible reflection API found on server.'
174175
);
175176

176177
const resultWithServiceError = evaluationResults.find(res => {
@@ -181,7 +182,7 @@ export class Client {
181182
throw resultWithServiceError?.error || noCompatibleProtocolRrror;
182183
}
183184

184-
// Set grpc client and other properties based on highest priority successful protocol
185+
// Set grpc client and other properties based on highest priority successful version
185186
successfulReflectionByPriority.effect!();
186187
}
187188

0 commit comments

Comments
 (0)