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 8bf81d02a..9439153c5 100644 Binary files a/integration/grpc-js/simple.bin and b/integration/grpc-js/simple.bin differ 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..64585bdcd --- /dev/null +++ b/integration/only-types-grpc-metadata/only-types-grpc-metadata-test.ts @@ -0,0 +1,8 @@ +import { GetBasicRequest } from './only-types-grpc-metadata'; + +describe('BasicService', () => { + it('compiles', () => { + const g: GetBasicRequest = { name: 'asdf' }; + expect(g).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 000000000..cf8fe7025 Binary files /dev/null and b/integration/only-types-grpc-metadata/only-types-grpc-metadata.bin differ 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 792e0d452..ad66e39c1 100644 Binary files a/integration/type-registry/bar/bar.bin and b/integration/type-registry/bar/bar.bin differ diff --git a/integration/type-registry/foo.bin b/integration/type-registry/foo.bin index ee29d4b22..f3f967f61 100644 Binary files a/integration/type-registry/foo.bin and b/integration/type-registry/foo.bin differ diff --git a/integration/type-registry/google/protobuf/timestamp.ts b/integration/type-registry/google/protobuf/timestamp.ts index 4b951a24d..ab0527dae 100644 --- a/integration/type-registry/google/protobuf/timestamp.ts +++ b/integration/type-registry/google/protobuf/timestamp.ts @@ -57,16 +57,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/src/generate-nestjs.ts b/src/generate-nestjs.ts index 644059d80..b262715fc 100644 --- a/src/generate-nestjs.ts +++ b/src/generate-nestjs.ts @@ -14,6 +14,8 @@ import { maybeAddComment, singular } from './utils'; import { camelCase } from './case'; import { Context } from './context'; +const Metadata = imp('Metadata@grpc'); + export function generateNestjsServiceController( ctx: Context, fileDesc: FileDescriptorProto, @@ -41,7 +43,7 @@ export function generateNestjsServiceController( // Use metadata as last argument for interface only configuration if (options.addGrpcMetadata) { const q = options.addNestjsRestParameter ? '' : '?'; - params.push(code`metadata${q}: ${imp('Metadata@grpc')}`); + params.push(code`metadata${q}: ${Metadata}`); } if (options.addNestjsRestParameter) { params.push(code`...rest: any`); @@ -114,7 +116,7 @@ export function generateNestjsServiceClient( // Use metadata as last argument for interface only configuration if (options.addGrpcMetadata) { const q = options.addNestjsRestParameter ? '' : '?'; - params.push(code`metadata${q}: ${imp('Metadata@grpc')}`); + params.push(code`metadata${q}: ${Metadata}`); } if (options.addNestjsRestParameter) { params.push(code`...rest: any`); diff --git a/src/generate-services.ts b/src/generate-services.ts index 8e7b9caf6..e0e8607a0 100644 --- a/src/generate-services.ts +++ b/src/generate-services.ts @@ -21,6 +21,7 @@ import { Context } from './context'; const hash = imp('hash*object-hash'); const dataloader = imp('DataLoader*dataloader'); const Reader = imp('Reader@protobufjs/minimal'); +const Metadata = imp('Metadata@grpc'); /** * Generates an interface for `serviceDesc`. @@ -66,10 +67,10 @@ export function generateService( // Use metadata as last argument for interface only configuration if (options.outputClientImpl === 'grpc-web') { - params.push(code`metadata?: grpc.Metadata`); + params.push(code`metadata?: ${Metadata}`); } else if (options.addGrpcMetadata) { const q = options.addNestjsRestParameter ? '' : '?'; - params.push(code`metadata${q}: Metadata@grpc`); + params.push(code`metadata${q}: ${Metadata}`); } if (options.addNestjsRestParameter) { params.push(code`...rest: any`);