Comparing version 2.1.6 to 2.1.7
@@ -8,1 +8,4 @@ export * from 'nice-grpc-common'; | ||
export * from './client/Client'; | ||
export { ServiceDefinition, MethodDefinition, CompatServiceDefinition, NormalizedServiceDefinition, } from './service-definitions'; | ||
export { TsProtoServiceDefinition } from './service-definitions/ts-proto'; | ||
export { ServiceDefinition as GrpcJsServiceDefinition } from '@grpc/grpc-js'; |
@@ -1,7 +0,13 @@ | ||
import * as grpc from '@grpc/grpc-js'; | ||
import { ServiceDefinition as GrpcJsServiceDefinition } from '@grpc/grpc-js'; | ||
import { FromGrpcJsServiceDefinition } from './grpc-js'; | ||
import { FromTsProtoServiceDefinition, TsProtoServiceDefinition } from './ts-proto'; | ||
/** | ||
* A nice-grpc service definition. | ||
*/ | ||
export type ServiceDefinition = { | ||
[method: string]: AnyMethodDefinition; | ||
}; | ||
/** | ||
* A nice-grpc method definition. | ||
*/ | ||
export type MethodDefinition<RequestIn, RequestOut, ResponseIn, ResponseOut, RequestStream extends boolean = boolean, ResponseStream extends boolean = boolean> = { | ||
@@ -19,4 +25,15 @@ path: string; | ||
}; | ||
/** | ||
* A nice-grpc method definition with any request and response types. | ||
*/ | ||
export type AnyMethodDefinition = MethodDefinition<any, any, any, any>; | ||
export type CompatServiceDefinition = ServiceDefinition | grpc.ServiceDefinition | TsProtoServiceDefinition; | ||
export type NormalizedServiceDefinition<Service extends CompatServiceDefinition> = Service extends ServiceDefinition ? Service : Service extends grpc.ServiceDefinition ? FromGrpcJsServiceDefinition<Service> : Service extends TsProtoServiceDefinition ? FromTsProtoServiceDefinition<Service> : never; | ||
/** | ||
* A service definition that can be converted to a nice-grpc service definition | ||
* i.e. a nice-grpc service definition, a grpc-js service definition or a | ||
* ts-proto service definition. | ||
*/ | ||
export type CompatServiceDefinition = ServiceDefinition | GrpcJsServiceDefinition | TsProtoServiceDefinition; | ||
/** | ||
* A nice-grpc service definition converted from a CompatServiceDefinition. | ||
*/ | ||
export type NormalizedServiceDefinition<Service extends CompatServiceDefinition> = Service extends ServiceDefinition ? Service : Service extends GrpcJsServiceDefinition ? FromGrpcJsServiceDefinition<Service> : Service extends TsProtoServiceDefinition ? FromTsProtoServiceDefinition<Service> : never; |
{ | ||
"name": "nice-grpc", | ||
"version": "2.1.6", | ||
"version": "2.1.7", | ||
"description": "A Node.js gRPC library that is nice to you", | ||
@@ -50,3 +50,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "dcb7b98bb34e99d16e276e806fdccad60e6072ab" | ||
"gitHead": "fa26b226f2ab9f5cdaae1773b0064d7d4c84544a" | ||
} |
@@ -10,1 +10,10 @@ export * from 'nice-grpc-common'; | ||
export * from './client/Client'; | ||
export { | ||
ServiceDefinition, | ||
MethodDefinition, | ||
CompatServiceDefinition, | ||
NormalizedServiceDefinition, | ||
} from './service-definitions'; | ||
export {TsProtoServiceDefinition} from './service-definitions/ts-proto'; | ||
export {ServiceDefinition as GrpcJsServiceDefinition} from '@grpc/grpc-js'; |
@@ -1,3 +0,6 @@ | ||
import * as grpc from '@grpc/grpc-js'; | ||
import { | ||
ServiceDefinition as GrpcJsServiceDefinition, | ||
MethodDefinition as GrpcJsMethodDefinition, | ||
} from '@grpc/grpc-js'; | ||
import { | ||
fromGrpcJsServiceDefinition, | ||
@@ -14,2 +17,5 @@ FromGrpcJsServiceDefinition, | ||
/** | ||
* A nice-grpc service definition. | ||
*/ | ||
export type ServiceDefinition = { | ||
@@ -19,2 +25,5 @@ [method: string]: AnyMethodDefinition; | ||
/** | ||
* A nice-grpc method definition. | ||
*/ | ||
export type MethodDefinition< | ||
@@ -40,9 +49,20 @@ RequestIn, | ||
/** | ||
* A nice-grpc method definition with any request and response types. | ||
*/ | ||
export type AnyMethodDefinition = MethodDefinition<any, any, any, any>; | ||
/** | ||
* A service definition that can be converted to a nice-grpc service definition | ||
* i.e. a nice-grpc service definition, a grpc-js service definition or a | ||
* ts-proto service definition. | ||
*/ | ||
export type CompatServiceDefinition = | ||
| ServiceDefinition | ||
| grpc.ServiceDefinition | ||
| GrpcJsServiceDefinition | ||
| TsProtoServiceDefinition; | ||
/** | ||
* A nice-grpc service definition converted from a CompatServiceDefinition. | ||
*/ | ||
export type NormalizedServiceDefinition< | ||
@@ -52,3 +72,3 @@ Service extends CompatServiceDefinition, | ||
? Service | ||
: Service extends grpc.ServiceDefinition | ||
: Service extends GrpcJsServiceDefinition | ||
? FromGrpcJsServiceDefinition<Service> | ||
@@ -75,4 +95,4 @@ : Service extends TsProtoServiceDefinition | ||
definition: ServiceDefinition, | ||
): grpc.ServiceDefinition { | ||
const result: {[key: string]: grpc.MethodDefinition<any, any>} = {}; | ||
): GrpcJsServiceDefinition { | ||
const result: {[key: string]: GrpcJsMethodDefinition<any, any>} = {}; | ||
@@ -89,3 +109,3 @@ for (const [key, method] of Object.entries(definition)) { | ||
definition: AnyMethodDefinition, | ||
): grpc.MethodDefinition<any, any> { | ||
): GrpcJsMethodDefinition<any, any> { | ||
return { | ||
@@ -92,0 +112,0 @@ path: definition.path, |
Sorry, the diff of this file is not supported yet
199372
3547