Skip to content
This repository has been archived by the owner on Sep 5, 2022. It is now read-only.

Commit

Permalink
GrpcError was properly exported
Browse files Browse the repository at this point in the history
  • Loading branch information
litichevskiydv committed Mar 14, 2021
1 parent fd06c33 commit 91d3146
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 62 deletions.
73 changes: 62 additions & 11 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
MethodDefinition,
ServerUnaryCall,
ServerReadableStream,
ServerWriteableStream,
ServerWritableStream,
ServerDuplexStream,
status,
Metadata,
ServerCredentials,
Server,
Expand All @@ -13,7 +14,7 @@ import { Observable } from "rxjs";

export class GrpcHostBuilder {
/**
* @param {object} [options] grpc native options https://grpc.io/grpc/cpp/group__grpc__arg__keys.html
* @param options gRPC native options https://grpc.io/grpc/cpp/group__grpc__arg__keys.html
*/
constructor(options?: object);

Expand Down Expand Up @@ -80,16 +81,20 @@ type ServerContext = {
createLogger: (options?: object) => Logging.ILogger;
};

type ServiceCall = ServerUnaryCall<any> | ServerReadableStream<any> | ServerWriteableStream<any> | ServerDuplexStream<any, any>;
type ServiceCall =
| ServerUnaryCall<any, any>
| ServerReadableStream<any, any>
| ServerWritableStream<any, any>
| ServerDuplexStream<any, any>;

type handleServiceCall<RequestType, ResponseType> =
| handleUnaryCall<RequestType, ResponseType>
| handleClientStreamingCall<RequestType, ResponseType>
| handleServerStreamingCall<RequestType, ResponseType>
| handleBidiStreamingCall<RequestType, ResponseType>;
type handleUnaryCall<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType>) => Promise<ResponseType>;
type handleClientStreamingCall<RequestType, ResponseType> = (call: ServerReadableStream<RequestType>) => Promise<ResponseType>; // prettier-ignore
type handleServerStreamingCall<RequestType, ResponseType> = (call: ServerWriteableStream<RequestType>) => Promise<void>;
type handleUnaryCall<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType, ResponseType>) => Promise<ResponseType>; // prettier-ignore
type handleClientStreamingCall<RequestType, ResponseType> = (call: ServerReadableStream<RequestType, ResponseType>) => Promise<ResponseType>; // prettier-ignore
type handleServerStreamingCall<RequestType, ResponseType> = (call: ServerWritableStream<RequestType, ResponseType>) => Promise<void>; // prettier-ignore
type handleBidiStreamingCall<RequestType, ResponseType> = (call: ServerDuplexStream<RequestType, ResponseType>) => Promise<void>; // prettier-ignore

/**
Expand Down Expand Up @@ -193,24 +198,70 @@ type serviceMethodImplementation<RequestType, ResponseType> =
| serviceClientStreamingMethodImplementation<RequestType, ResponseType>
| serviceServerStreamingMethodImplementation<RequestType, ResponseType>
| serviceBidiStreamingMethodImplementation<RequestType, ResponseType>;
type serviceUnaryMethodImplementation<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType>) => Promise<ResponseType>; // prettier-ignore
type serviceUnaryMethodImplementation<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType, ResponseType>) => Promise<ResponseType>; // prettier-ignore
type serviceClientStreamingMethodImplementation<RequestType, ResponseType> = (call: ServerIngoingStreamingCall<RequestType>) => Promise<ResponseType>; // prettier-ignore
type serviceServerStreamingMethodImplementation<RequestType, ResponseType> = (call: ServerOutgoingStreamingCall<RequestType>) => Promise<Observable<ResponseType>>; // prettier-ignore
type serviceBidiStreamingMethodImplementation<RequestType, ResponseType> = (call: ServerBidiStreamingCall<RequestType>) => Promise<Observable<ResponseType>>; // prettier-ignore
type UntypedServiceImplementation = { [name: string]: serviceMethodImplementation<any, any> };

interface IInterceptor {
export interface IInterceptor {
/**
* Interceptor implementation.
* @param call Server call.
* @param methodDefinition Metadata for method implementation.
* @param next Next layers executor.
*/
invoke(call: ServiceCall, methodDefinition: MethodDefinition<any, any>, next: handleServiceCall<any, any>): Promise<any>;
invoke(
call: ServiceCall,
methodDefinition: MethodDefinition<any, any>,
next: handleServiceCall<any, any>
): Promise<any>;
}

declare namespace Logging {
interface ILogger {
export namespace Errors {
interface GrpcErrorOptions {
/**
* gRPC response status code
*/
statusCode?: status;

/**
* gRPC response metadata
*/
metadata?: Metadata | { [key: string]: string };

/**
* Error details
*/
details?: Array<any>;

/**
* Inner error
*/
innerError?: Error;
}

export class GrpcError extends Error {
/**
* @param message Error message
* @param options Error options
*/
constructor(message: string, options?: GrpcErrorOptions);

/**
* gRPC response status code
*/
code: status;

/**
* gRPC response metadata
*/
metadata: Metadata;
}
}

export namespace Logging {
export interface ILogger {
error(message: string, payload?: object): void;
warn(message: string, payload?: object): void;
info(message: string, payload?: object): void;
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
GrpcHostBuilder: require("./grpcHostBuilder")
GrpcHostBuilder: require("./grpcHostBuilder"),
Errors: {
GrpcError: require("./errors/grpcError"),
},
};
Loading

0 comments on commit 91d3146

Please sign in to comment.