From b787b417c01ceffd2827b2f9a076c8455a7506f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0mol=C3=ADk?= Date: Thu, 17 Sep 2020 08:31:15 +0200 Subject: [PATCH 1/2] Fix path composition on missing package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correct RPC paths (also aligned with the grpc implementation) are - `/Package.Service/Method` - `/Service/Method` (undefined package) Currently the template does not handle well services without package - `/Package.Service/Method` ✅ - `/.Service/Method` ❌ (extra dot) This commit adds the dot conditionally only if Package is not falsy --- src/lib/template/svc_tsd.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/template/svc_tsd.hbs b/src/lib/template/svc_tsd.hbs index a6004f3..b520882 100644 --- a/src/lib/template/svc_tsd.hbs +++ b/src/lib/template/svc_tsd.hbs @@ -17,7 +17,7 @@ interface I{{{serviceName}}}Service extends grpc.ServiceDefinition { - path: string; // "/{{{packageName}}}.{{{serviceName}}}/{{{methodName}}}" + path: string; // "/{{{packageName}}}{{#if packageName}}.{{/if}}{{{serviceName}}}/{{{methodName}}}" requestStream: {{{requestStream}}}; responseStream: {{{responseStream}}}; requestSerialize: grpc.serialize<{{{requestTypeName}}}>; From d8069ed77d1cbbbb917c833be60d3bca52db3748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0mol=C3=ADk?= Date: Thu, 17 Sep 2020 08:40:51 +0200 Subject: [PATCH 2/2] Use type literal for path Using string literal type _should_ not break anything (tested on a larger project) since it is a subtype of string. Using literal instead of generic string allows to do type-safe RPC matching, for example it generic middlewares for cache, ACL etc. Without it we need to match a string for path (long, prone to errors) or method names (ambiguous) and have no way to check, wheather the matching is correct or not. With literals, we can extract all paths from generated stubs with meta-typing and use it in these occasions. --- src/lib/template/svc_tsd.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/template/svc_tsd.hbs b/src/lib/template/svc_tsd.hbs index b520882..bc90e8a 100644 --- a/src/lib/template/svc_tsd.hbs +++ b/src/lib/template/svc_tsd.hbs @@ -17,7 +17,7 @@ interface I{{{serviceName}}}Service extends grpc.ServiceDefinition { - path: string; // "/{{{packageName}}}{{#if packageName}}.{{/if}}{{{serviceName}}}/{{{methodName}}}" + path: "/{{{packageName}}}{{#if packageName}}.{{/if}}{{{serviceName}}}/{{{methodName}}}"; requestStream: {{{requestStream}}}; responseStream: {{{responseStream}}}; requestSerialize: grpc.serialize<{{{requestTypeName}}}>;