From 5e37de59451be0bac11ee32127711490df0e275e Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Fri, 2 Apr 2021 12:34:14 -0500 Subject: [PATCH 1/2] fix: Fix bad grpc.Metadata import. Fixes #188. --- .../grpc-js/google/protobuf/timestamp.ts | 11 +---------- integration/grpc-js/simple.bin | Bin 9741 -> 9490 bytes integration/grpc-js/simple.ts | 4 ++-- .../example.ts | 3 ++- integration/grpc-web-no-streaming/example.ts | 3 ++- integration/grpc-web/example.ts | 11 ++++++----- .../only-types-grpc-metadata-test.ts | 8 ++++++++ .../only-types-grpc-metadata.bin | Bin 0 -> 518 bytes .../only-types-grpc-metadata.proto | 14 ++++++++++++++ .../only-types-grpc-metadata.ts | 16 ++++++++++++++++ .../only-types-grpc-metadata/parameters.txt | 1 + integration/type-registry/bar/bar.bin | Bin 6817 -> 6573 bytes integration/type-registry/foo.bin | Bin 6612 -> 6368 bytes .../google/protobuf/timestamp.ts | 11 +---------- src/generate-nestjs.ts | 6 ++++-- src/generate-services.ts | 5 +++-- 16 files changed, 60 insertions(+), 33 deletions(-) create mode 100755 integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts create mode 100644 integration/only-types-grpc-metadata/only-types-grpc-metadata.bin create mode 100755 integration/only-types-grpc-metadata/only-types-grpc-metadata.proto create mode 100644 integration/only-types-grpc-metadata/only-types-grpc-metadata.ts create mode 100755 integration/only-types-grpc-metadata/parameters.txt diff --git a/integration/grpc-js/google/protobuf/timestamp.ts b/integration/grpc-js/google/protobuf/timestamp.ts index ef2662595..11a824a90 100644 --- a/integration/grpc-js/google/protobuf/timestamp.ts +++ b/integration/grpc-js/google/protobuf/timestamp.ts @@ -56,16 +56,7 @@ export const protobufPackage = 'google.protobuf'; * .setNanos((int) ((millis % 1000) * 1000000)).build(); * * - * Example 5: Compute Timestamp from Java `Instant.now()`. - * - * Instant now = Instant.now(); - * - * Timestamp timestamp = - * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) - * .setNanos(now.getNano()).build(); - * - * - * Example 6: Compute Timestamp from current time in Python. + * Example 5: Compute Timestamp from current time in Python. * * timestamp = Timestamp() * timestamp.GetCurrentTime() diff --git a/integration/grpc-js/simple.bin b/integration/grpc-js/simple.bin index 8bf81d02ab067392fd4d5589547640e1af3b8ac0..9439153c56ad04698345edcc8e68d1959a0d3efb 100644 GIT binary patch delta 353 zcmeD6ndBwI#Z#P_Tac5gS5TB+k}t)Zj-DB<7{-gS91!;=d8I!fRv^QRAWaF{p;^boD z;1*(5X0Y2F&;Eyz>9YRhSk3~*I-rpnI@*NIE6L1FEiOsSEdZIxc~h5*U5HhVp>uN_ zS05XX6U=xO2B*nC1VRNqOLH-?FbJ{MF?2FAN4iK0_8x38k2?yR%IwLxkgP$jA3Lz4TPwPBLzz(La(7k)Wp#+5KT%a z2ctj0#qd*1iEZ?JK(l|WIe(K4GFHrvD|37%(TlOk9E zrw>kI4W2nWX$9+q=#8B&+Y5a`_GuZpm3hhShD*#jbf3cV>dHTh?M6$pY_(;YRp)jo{HUOi5J-W6S3;M; zXkol64GQi@Y&ZUzL<|RnU=M-;go&4=SBzhUvK#7=Dpd*wZ8B_3e=KJz7$M1@ktBU0`Mqoi9F7t0jGx@PB1QajkzYQ)%=Gnrpx*oZC7E~*Bx%Jd;W lHI}R|g=zHm6QQq;D@yNk&R+!jCgdkZ5lADBmzw`%zX2|bhQt5> diff --git a/integration/grpc-js/simple.ts b/integration/grpc-js/simple.ts index d03f1d2eb..6429837fc 100644 --- a/integration/grpc-js/simple.ts +++ b/integration/grpc-js/simple.ts @@ -1,4 +1,6 @@ /* eslint-disable */ +import { util, configure, Writer, Reader } from 'protobufjs/minimal'; +import * as Long from 'long'; import { makeGenericClientConstructor, ChannelCredentials, @@ -17,8 +19,6 @@ import { ClientDuplexStream, ServiceError, } from '@grpc/grpc-js'; -import { util, configure, Writer, Reader } from 'protobufjs/minimal'; -import * as Long from 'long'; import { Timestamp } from './google/protobuf/timestamp'; import { Empty } from './google/protobuf/empty'; diff --git a/integration/grpc-web-no-streaming-observable/example.ts b/integration/grpc-web-no-streaming-observable/example.ts index 967b220f7..7ae4033a5 100644 --- a/integration/grpc-web-no-streaming-observable/example.ts +++ b/integration/grpc-web-no-streaming-observable/example.ts @@ -5,6 +5,7 @@ import { grpc } from '@improbable-eng/grpc-web'; import { Observable } from 'rxjs'; import { BrowserHeaders } from 'browser-headers'; import { take } from 'rxjs/operators'; +import { Metadata } from 'grpc'; export const protobufPackage = 'rpx'; @@ -354,7 +355,7 @@ export const Empty = { * but with the streaming method removed. */ export interface DashState { - UserSettings(request: DeepPartial, metadata?: grpc.Metadata): Observable; + UserSettings(request: DeepPartial, metadata?: Metadata): Observable; } export class DashStateClientImpl implements DashState { diff --git a/integration/grpc-web-no-streaming/example.ts b/integration/grpc-web-no-streaming/example.ts index 1d9f9e852..59c9eb1f2 100644 --- a/integration/grpc-web-no-streaming/example.ts +++ b/integration/grpc-web-no-streaming/example.ts @@ -3,6 +3,7 @@ import { util, configure, Writer, Reader } from 'protobufjs/minimal'; import * as Long from 'long'; import { grpc } from '@improbable-eng/grpc-web'; import { BrowserHeaders } from 'browser-headers'; +import { Metadata } from 'grpc'; export const protobufPackage = 'rpx'; @@ -352,7 +353,7 @@ export const Empty = { * but with the streaming method removed. */ export interface DashState { - UserSettings(request: DeepPartial, metadata?: grpc.Metadata): Promise; + UserSettings(request: DeepPartial, metadata?: Metadata): Promise; } export class DashStateClientImpl implements DashState { diff --git a/integration/grpc-web/example.ts b/integration/grpc-web/example.ts index 39e79d3ce..b9971b0b7 100644 --- a/integration/grpc-web/example.ts +++ b/integration/grpc-web/example.ts @@ -5,6 +5,7 @@ import { grpc } from '@improbable-eng/grpc-web'; import { Observable } from 'rxjs'; import { BrowserHeaders } from 'browser-headers'; import { share } from 'rxjs/operators'; +import { Metadata } from 'grpc'; export const protobufPackage = 'rpx'; @@ -730,8 +731,8 @@ export const Empty = { }; export interface DashState { - UserSettings(request: DeepPartial, metadata?: grpc.Metadata): Promise; - ActiveUserSettingsStream(request: DeepPartial, metadata?: grpc.Metadata): Observable; + UserSettings(request: DeepPartial, metadata?: Metadata): Promise; + ActiveUserSettingsStream(request: DeepPartial, metadata?: Metadata): Observable; } export class DashStateClientImpl implements DashState { @@ -804,9 +805,9 @@ export const DashStateActiveUserSettingsStreamDesc: UnaryMethodDefinitionish = { * ---------------------- */ export interface DashAPICreds { - Create(request: DeepPartial, metadata?: grpc.Metadata): Promise; - Update(request: DeepPartial, metadata?: grpc.Metadata): Promise; - Delete(request: DeepPartial, metadata?: grpc.Metadata): Promise; + Create(request: DeepPartial, metadata?: Metadata): Promise; + Update(request: DeepPartial, metadata?: Metadata): Promise; + Delete(request: DeepPartial, metadata?: Metadata): Promise; } export class DashAPICredsClientImpl implements DashAPICreds { diff --git a/integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts b/integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts new file mode 100755 index 000000000..4bf86b8d8 --- /dev/null +++ b/integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts @@ -0,0 +1,8 @@ +import { Registration } from './reservation'; + +describe('Reservation', () => { + it('has no JSON conversion', () => { + const r: Registration = { eventName: 'Foo', date: undefined } as Registration; + expect(r).toBeTruthy(); + }); +}); diff --git a/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin b/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin new file mode 100644 index 0000000000000000000000000000000000000000..cf8fe7025853a37f2a6730e17faa6e16126d7382 GIT binary patch literal 518 zcmaix!AiqG5Qb;7n{+$f);Nd_J*Wf}DWnIz33~7%2wv(Fq;ZjgZDJFJ`UXCtZ{zGX z!GnUg`8NN4^M}Qwa{aQ+nr&t4?0Hia*~&KgQ{LpWYEw4lL~9uj6G-9XOX5Fa3Kx03 zEYeflyR*%$o9FiR&DISOs&&4yi8vAG{kfmhGmL*?bycow`&aJb0gZP(+Rgj2uyl>O zyGMsJzjD?cwEHIGU+238DcpYs7?A=P3e+eJNdR(FKvKX65d#IJB!q%zsX&mFdW-{9 z3IZUh0z!kKgV2%gh=Zy>>_{@j`(7tV^`O7g2~PEN;&sC5bgN@voo;nZ9Mr9jiFJCX ti@4puwdZz`OAYja(?!0W32s~i2mHxIqmKCZOnlrC>&*0O5&1{H{08a*R^|Wz literal 0 HcmV?d00001 diff --git a/integration/only-types-grpc-metadata/only-types-grpc-metadata.proto b/integration/only-types-grpc-metadata/only-types-grpc-metadata.proto new file mode 100755 index 000000000..db5c7a53d --- /dev/null +++ b/integration/only-types-grpc-metadata/only-types-grpc-metadata.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package basic; + +message GetBasicRequest { + string name = 1; +} + +message GetBasicResponse { + string name = 1; +} + +service BasicService { + rpc GetBasic (GetBasicRequest) returns (GetBasicResponse) {} +} diff --git a/integration/only-types-grpc-metadata/only-types-grpc-metadata.ts b/integration/only-types-grpc-metadata/only-types-grpc-metadata.ts new file mode 100644 index 000000000..2a428d949 --- /dev/null +++ b/integration/only-types-grpc-metadata/only-types-grpc-metadata.ts @@ -0,0 +1,16 @@ +/* eslint-disable */ +import { Metadata } from 'grpc'; + +export const protobufPackage = 'basic'; + +export interface GetBasicRequest { + name: string; +} + +export interface GetBasicResponse { + name: string; +} + +export interface BasicService { + getBasic(request: GetBasicRequest, metadata?: Metadata): Promise; +} diff --git a/integration/only-types-grpc-metadata/parameters.txt b/integration/only-types-grpc-metadata/parameters.txt new file mode 100755 index 000000000..287cc1c79 --- /dev/null +++ b/integration/only-types-grpc-metadata/parameters.txt @@ -0,0 +1 @@ +outputEncodeMethods=false,outputJsonMethods=false,outputClientImpl=false,lowerCaseServiceMethods=true,addGrpcMetadata=true diff --git a/integration/type-registry/bar/bar.bin b/integration/type-registry/bar/bar.bin index 792e0d45250e539041aacfc1f13fa316dcca864f..ad66e39c1617d8f4517068c5ade6e1ac62db0e46 100644 GIT binary patch delta 246 zcmZ2zy4HAt2nVkOgAzm4W&MdV1&nnQ`!sa4(=$slN|W@G^KEDS=dbqt-1j8adfH_LL&WZ%3%z?V&&i;J0sfl-LLjzf@ZE+ZEU3j-5_ z5KGf!R`L0IO^i(JT)bSYATdUuAR`AqjLQt-3JG&Pg=hiFc1*q`{#?ETp@k77$jHG9 P)xrqW(y{r5#7RZ~AR#qo delta 419 zcmZ2$ywG%l2nU}8gAzm4al?r+1x&4s6MHp`jneb;({obw((`i?^V0S5i_-NAitm)$JFF_YcGE3qt5A;B{bXi{E@9?)P7 z%>+FzE(H*PiYfp_6>MQVh#Kq3j@(k*3bqi1K(&*_`IQ5K3iZ-cOI!=`lQV)-lk@XZ zG&D8gO2B676{nW?CFbQ9Yd{r)I6zf;Nu`-NK;_n4K+9b#fZobURWO@8flqStT7F+P z32rWC76wKkmUc!CL9V%sTr4aMObkLS-IE2y=IeDcGO=^Cxi!&`hU$3Ajza(FZgM(RsSAs!_q3W{!M2P~%x`|yHI@;-(B^jkjddc~@ z`sw*OiFxVzVAV;bY5D~vl?AEA`X!mUsl_FUxdjuSYIEMykCk&A_efr&wgrD-yw_y_QQ`Iw88DVVxMNsbkX9m8sL{w-o2X(rl$;k~33r+Fi|d)UIVU+>g!Bvx0ar zumVQoB)kbmYAA#lAuO^RpyoaCN6F7TVmKfM2M~-P%)REv3E_?}@2aP&RIizI$#gIs zmJ4-^kmR3vE74Y}EYg(mVv*&rRGDFv^iuKl1Bzi?bE+0;o*ZgTVjjzd!XGkS#J1+_ zsV1@IIqU~Y;YPo0P<#i`r>p1mQ-&s$$G7oTFdIfJ2cXCeppZoO5OEw}fXEHKX!-#U uA;Y663iusmhERwvBI`#ng}!DAy>-3!^!KX!uRy Date: Fri, 2 Apr 2021 12:40:39 -0500 Subject: [PATCH 2/2] Fix test. --- .../only-types-grpc-metadata-test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts b/integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts index 4bf86b8d8..64585bdcd 100755 --- a/integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts +++ b/integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts @@ -1,8 +1,8 @@ -import { Registration } from './reservation'; +import { GetBasicRequest } from './only-types-grpc-metadata'; -describe('Reservation', () => { - it('has no JSON conversion', () => { - const r: Registration = { eventName: 'Foo', date: undefined } as Registration; - expect(r).toBeTruthy(); +describe('BasicService', () => { + it('compiles', () => { + const g: GetBasicRequest = { name: 'asdf' }; + expect(g).toBeTruthy(); }); });