Skip to content

Commit

Permalink
fix(ges): lookup definition by original name
Browse files Browse the repository at this point in the history
when not finding it by implementation name
  • Loading branch information
n0v1 committed Oct 13, 2020
1 parent 4f39f7f commit dc5a58b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/grpc-experimental-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ type ServerCall =

type ServerNonStreamCall = ServerUnaryCall<unknown> | ServerReadableStream<unknown>;

// type guard for method definition with property 'originalName'
const isDefinitionWithOriginalName = (def: any): def is { originalName: string } => {
return (
!!def &&
typeof def === 'object' &&
'originalName' in def &&
typeof def.originalName === 'string'
);
};

export class Context {
response: unknown;
constructor(public call: ServerCall, public definition: MethodDefinition<unknown, unknown>) {}
Expand Down Expand Up @@ -53,7 +63,13 @@ export default class ExperimentalServer extends Server {

for (let key in implementations) {
const original = implementations[key];
const def = service[key];
let def = service[key];
if (!def) {
// try to find method definition by original name
def = Object.values(service).find(
def => isDefinitionWithOriginalName(def) && def.originalName === key
);
}
// make sure it is method handler
if (def && def.path && typeof original === 'function') {
newImpletations = {
Expand Down

0 comments on commit dc5a58b

Please sign in to comment.