Skip to content

Commit f64867e

Browse files
committed
Yet another declaration + tests (w/o grpc-js-xds)
1 parent 4289fc4 commit f64867e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+418
-109
lines changed

packages/grpc-health-check/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"scripts": {
1818
"compile": "tsc -p .",
1919
"prepare": "npm run generate-types && npm run compile",
20-
"generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ -O src/generated health/v1/health.proto",
20+
"test": "gulp test",
21+
"pretest": "npm run generate-types && npm run generate-test-types && npm run compile",
22+
"generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ -O src/generated --grpcLib=@grpc/grpc-js health/v1/health.proto",
2123
"generate-test-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ -O test/generated --grpcLib=@grpc/grpc-js health/v1/health.proto"
2224
},
2325
"dependencies": {
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,129 @@
11
// Original file: proto/health/v1/health.proto
22

3+
import type * as grpc from '@grpc/grpc-js'
34
import type { MethodDefinition } from '@grpc/proto-loader'
45
import type { HealthCheckRequest as _grpc_health_v1_HealthCheckRequest, HealthCheckRequest__Output as _grpc_health_v1_HealthCheckRequest__Output } from '../../../grpc/health/v1/HealthCheckRequest';
56
import type { HealthCheckResponse as _grpc_health_v1_HealthCheckResponse, HealthCheckResponse__Output as _grpc_health_v1_HealthCheckResponse__Output } from '../../../grpc/health/v1/HealthCheckResponse';
67

7-
export interface HealthDefinition {
8+
/**
9+
* Health is gRPC's mechanism for checking whether a server is able to handle
10+
* RPCs. Its semantics are documented in
11+
* https://github.com/grpc/grpc/blob/master/doc/health-checking.md.
12+
*/
13+
export interface HealthClient extends grpc.ServiceClient {
14+
/**
15+
* Check gets the health of the specified service. If the requested service
16+
* is unknown, the call will fail with status NOT_FOUND. If the caller does
17+
* not specify a service name, the server should respond with its overall
18+
* health status.
19+
*
20+
* Clients should set a deadline when calling Check, and can declare the
21+
* server unhealthy if they do not receive a timely response.
22+
*
23+
* Check implementations should be idempotent and side effect free.
24+
*/
25+
Check(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall;
26+
Check(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall;
27+
Check(argument: _grpc_health_v1_HealthCheckRequest, options: grpc.CallOptions, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall;
28+
Check(argument: _grpc_health_v1_HealthCheckRequest, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall;
29+
/**
30+
* Check gets the health of the specified service. If the requested service
31+
* is unknown, the call will fail with status NOT_FOUND. If the caller does
32+
* not specify a service name, the server should respond with its overall
33+
* health status.
34+
*
35+
* Clients should set a deadline when calling Check, and can declare the
36+
* server unhealthy if they do not receive a timely response.
37+
*
38+
* Check implementations should be idempotent and side effect free.
39+
*/
40+
check(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, options: grpc.CallOptions, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall;
41+
check(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall;
42+
check(argument: _grpc_health_v1_HealthCheckRequest, options: grpc.CallOptions, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall;
43+
check(argument: _grpc_health_v1_HealthCheckRequest, callback: grpc.requestCallback<_grpc_health_v1_HealthCheckResponse__Output>): grpc.ClientUnaryCall;
44+
45+
/**
46+
* Performs a watch for the serving status of the requested service.
47+
* The server will immediately send back a message indicating the current
48+
* serving status. It will then subsequently send a new message whenever
49+
* the service's serving status changes.
50+
*
51+
* If the requested service is unknown when the call is received, the
52+
* server will send a message setting the serving status to
53+
* SERVICE_UNKNOWN but will *not* terminate the call. If at some
54+
* future point, the serving status of the service becomes known, the
55+
* server will send a new message with the service's serving status.
56+
*
57+
* If the call terminates with status UNIMPLEMENTED, then clients
58+
* should assume this method is not supported and should not retry the
59+
* call. If the call terminates with any other status (including OK),
60+
* clients should retry the call with appropriate exponential backoff.
61+
*/
62+
Watch(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientReadableStream<_grpc_health_v1_HealthCheckResponse__Output>;
63+
Watch(argument: _grpc_health_v1_HealthCheckRequest, options?: grpc.CallOptions): grpc.ClientReadableStream<_grpc_health_v1_HealthCheckResponse__Output>;
64+
/**
65+
* Performs a watch for the serving status of the requested service.
66+
* The server will immediately send back a message indicating the current
67+
* serving status. It will then subsequently send a new message whenever
68+
* the service's serving status changes.
69+
*
70+
* If the requested service is unknown when the call is received, the
71+
* server will send a message setting the serving status to
72+
* SERVICE_UNKNOWN but will *not* terminate the call. If at some
73+
* future point, the serving status of the service becomes known, the
74+
* server will send a new message with the service's serving status.
75+
*
76+
* If the call terminates with status UNIMPLEMENTED, then clients
77+
* should assume this method is not supported and should not retry the
78+
* call. If the call terminates with any other status (including OK),
79+
* clients should retry the call with appropriate exponential backoff.
80+
*/
81+
watch(argument: _grpc_health_v1_HealthCheckRequest, metadata: grpc.Metadata, options?: grpc.CallOptions): grpc.ClientReadableStream<_grpc_health_v1_HealthCheckResponse__Output>;
82+
watch(argument: _grpc_health_v1_HealthCheckRequest, options?: grpc.CallOptions): grpc.ClientReadableStream<_grpc_health_v1_HealthCheckResponse__Output>;
83+
84+
}
85+
86+
/**
87+
* Health is gRPC's mechanism for checking whether a server is able to handle
88+
* RPCs. Its semantics are documented in
89+
* https://github.com/grpc/grpc/blob/master/doc/health-checking.md.
90+
*/
91+
export interface HealthHandlers extends grpc.UntypedServiceImplementation {
92+
/**
93+
* Check gets the health of the specified service. If the requested service
94+
* is unknown, the call will fail with status NOT_FOUND. If the caller does
95+
* not specify a service name, the server should respond with its overall
96+
* health status.
97+
*
98+
* Clients should set a deadline when calling Check, and can declare the
99+
* server unhealthy if they do not receive a timely response.
100+
*
101+
* Check implementations should be idempotent and side effect free.
102+
*/
103+
Check: grpc.handleUnaryCall<_grpc_health_v1_HealthCheckRequest__Output, _grpc_health_v1_HealthCheckResponse>;
104+
105+
/**
106+
* Performs a watch for the serving status of the requested service.
107+
* The server will immediately send back a message indicating the current
108+
* serving status. It will then subsequently send a new message whenever
109+
* the service's serving status changes.
110+
*
111+
* If the requested service is unknown when the call is received, the
112+
* server will send a message setting the serving status to
113+
* SERVICE_UNKNOWN but will *not* terminate the call. If at some
114+
* future point, the serving status of the service becomes known, the
115+
* server will send a new message with the service's serving status.
116+
*
117+
* If the call terminates with status UNIMPLEMENTED, then clients
118+
* should assume this method is not supported and should not retry the
119+
* call. If the call terminates with any other status (including OK),
120+
* clients should retry the call with appropriate exponential backoff.
121+
*/
122+
Watch: grpc.handleServerStreamingCall<_grpc_health_v1_HealthCheckRequest__Output, _grpc_health_v1_HealthCheckResponse>;
123+
124+
}
125+
126+
export interface HealthDefinition extends grpc.ServiceDefinition {
8127
Check: MethodDefinition<_grpc_health_v1_HealthCheckRequest, _grpc_health_v1_HealthCheckResponse, _grpc_health_v1_HealthCheckRequest__Output, _grpc_health_v1_HealthCheckResponse__Output>
9128
Watch: MethodDefinition<_grpc_health_v1_HealthCheckRequest, _grpc_health_v1_HealthCheckResponse, _grpc_health_v1_HealthCheckRequest__Output, _grpc_health_v1_HealthCheckResponse__Output>
10129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type * as grpc from '@grpc/grpc-js';
2+
import type { MessageTypeDefinition } from '@grpc/proto-loader';
3+
4+
import type { HealthClient as _grpc_health_v1_HealthClient, HealthDefinition as _grpc_health_v1_HealthDefinition } from './grpc/health/v1/Health';
5+
6+
type SubtypeConstructor<Subtype extends grpc.ServiceClient> = {
7+
new (address: string, credentials: grpc.ChannelCredentials, options?: Partial<grpc.ChannelOptions>): Subtype;
8+
} & grpc.ServiceClientConstructor;
9+
10+
export interface ProtoGrpcType extends grpc.GrpcObject {
11+
grpc: {
12+
health: {
13+
v1: {
14+
/**
15+
* Health is gRPC's mechanism for checking whether a server is able to handle
16+
* RPCs. Its semantics are documented in
17+
* https://github.com/grpc/grpc/blob/master/doc/health-checking.md.
18+
*/
19+
Health: SubtypeConstructor<_grpc_health_v1_HealthClient> & { service: _grpc_health_v1_HealthDefinition }
20+
HealthCheckRequest: MessageTypeDefinition
21+
HealthCheckResponse: MessageTypeDefinition
22+
}
23+
}
24+
}
25+
}
26+

packages/grpc-health-check/src/health.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@
1717
*/
1818

1919
import * as path from 'path';
20-
import { loadSync, ServiceDefinition } from '@grpc/proto-loader';
20+
import * as grpc from '@grpc/grpc-js';
21+
import * as protoLoader from '@grpc/proto-loader';
22+
import type { ProtoGrpcType as HealthGrpc } from './generated/health';
2123
import { HealthCheckRequest__Output } from './generated/grpc/health/v1/HealthCheckRequest';
2224
import { HealthCheckResponse } from './generated/grpc/health/v1/HealthCheckResponse';
2325
import { sendUnaryData, Server, ServerUnaryCall, ServerWritableStream } from './server-type';
2426

25-
const loadedProto = loadSync('health/v1/health.proto', {
27+
const healthProto = protoLoader.loadSync('health/v1/health.proto', {
2628
keepCase: true,
2729
longs: String,
2830
enums: String,
2931
defaults: true,
3032
oneofs: true,
3133
includeDirs: [`${__dirname}/../../proto`],
3234
});
35+
const healthGrpc = grpc.loadPackageDefinition(healthProto) as HealthGrpc;
3336

34-
export const service = loadedProto['grpc.health.v1.Health'] as ServiceDefinition;
37+
export const service = healthGrpc.grpc.health.v1.Health.service;
3538

3639
const GRPC_STATUS_NOT_FOUND = 5;
3740

packages/grpc-health-check/src/server-type.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*
1616
*/
1717

18-
import { ServiceDefinition } from '@grpc/proto-loader';
18+
import * as grpc from '@grpc/grpc-js';
19+
import * as protoLoader from '@grpc/proto-loader';
1920
import { ObjectReadable, ObjectWritable } from './object-stream';
2021
import { EventEmitter } from 'events';
2122

@@ -99,5 +100,6 @@ export interface UntypedServiceImplementation {
99100
}
100101

101102
export interface Server {
102-
addService(service: ServiceDefinition, implementation: UntypedServiceImplementation): void;
103+
addService(service: protoLoader.ServiceDefinition, implementation: UntypedServiceImplementation): void;
104+
addService<ImplType = UntypedServiceImplementation>(service: grpc.ServiceDefinition, implementation: ImplType): void;
103105
}

packages/grpc-health-check/test/generated/grpc/health/v1/Health.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { HealthCheckResponse as _grpc_health_v1_HealthCheckResponse, Health
1010
* RPCs. Its semantics are documented in
1111
* https://github.com/grpc/grpc/blob/master/doc/health-checking.md.
1212
*/
13-
export interface HealthClient extends grpc.Client {
13+
export interface HealthClient extends grpc.ServiceClient {
1414
/**
1515
* Check gets the health of the specified service. If the requested service
1616
* is unknown, the call will fail with status NOT_FOUND. If the caller does

packages/grpc-health-check/test/generated/health.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type { MessageTypeDefinition } from '@grpc/proto-loader';
33

44
import type { HealthClient as _grpc_health_v1_HealthClient, HealthDefinition as _grpc_health_v1_HealthDefinition } from './grpc/health/v1/Health';
55

6-
type SubtypeConstructor<Constructor extends new (...args: any) => any, Subtype> = {
7-
new(...args: ConstructorParameters<Constructor>): Subtype;
8-
};
6+
type SubtypeConstructor<Subtype extends grpc.ServiceClient> = {
7+
new (address: string, credentials: grpc.ChannelCredentials, options?: Partial<grpc.ChannelOptions>): Subtype;
8+
} & grpc.ServiceClientConstructor;
99

10-
export interface ProtoGrpcType {
10+
export interface ProtoGrpcType extends grpc.GrpcObject {
1111
grpc: {
1212
health: {
1313
v1: {
@@ -16,7 +16,7 @@ export interface ProtoGrpcType {
1616
* RPCs. Its semantics are documented in
1717
* https://github.com/grpc/grpc/blob/master/doc/health-checking.md.
1818
*/
19-
Health: SubtypeConstructor<typeof grpc.Client, _grpc_health_v1_HealthClient> & { service: _grpc_health_v1_HealthDefinition }
19+
Health: SubtypeConstructor<_grpc_health_v1_HealthClient> & { service: _grpc_health_v1_HealthDefinition }
2020
HealthCheckRequest: MessageTypeDefinition
2121
HealthCheckResponse: MessageTypeDefinition
2222
}

0 commit comments

Comments
 (0)