Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix bad grpc.Metadata import. Fixes #188. #259

Merged
merged 2 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions integration/grpc-js/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Binary file modified integration/grpc-js/simple.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions integration/grpc-js/simple.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable */
import { util, configure, Writer, Reader } from 'protobufjs/minimal';
import * as Long from 'long';
import {
makeGenericClientConstructor,
ChannelCredentials,
Expand All @@ -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';

Expand Down
3 changes: 2 additions & 1 deletion integration/grpc-web-no-streaming-observable/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -354,7 +355,7 @@ export const Empty = {
* but with the streaming method removed.
*/
export interface DashState {
UserSettings(request: DeepPartial<Empty>, metadata?: grpc.Metadata): Observable<DashUserSettingsState>;
UserSettings(request: DeepPartial<Empty>, metadata?: Metadata): Observable<DashUserSettingsState>;
}

export class DashStateClientImpl implements DashState {
Expand Down
3 changes: 2 additions & 1 deletion integration/grpc-web-no-streaming/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -352,7 +353,7 @@ export const Empty = {
* but with the streaming method removed.
*/
export interface DashState {
UserSettings(request: DeepPartial<Empty>, metadata?: grpc.Metadata): Promise<DashUserSettingsState>;
UserSettings(request: DeepPartial<Empty>, metadata?: Metadata): Promise<DashUserSettingsState>;
}

export class DashStateClientImpl implements DashState {
Expand Down
11 changes: 6 additions & 5 deletions integration/grpc-web/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -730,8 +731,8 @@ export const Empty = {
};

export interface DashState {
UserSettings(request: DeepPartial<Empty>, metadata?: grpc.Metadata): Promise<DashUserSettingsState>;
ActiveUserSettingsStream(request: DeepPartial<Empty>, metadata?: grpc.Metadata): Observable<DashUserSettingsState>;
UserSettings(request: DeepPartial<Empty>, metadata?: Metadata): Promise<DashUserSettingsState>;
ActiveUserSettingsStream(request: DeepPartial<Empty>, metadata?: Metadata): Observable<DashUserSettingsState>;
}

export class DashStateClientImpl implements DashState {
Expand Down Expand Up @@ -804,9 +805,9 @@ export const DashStateActiveUserSettingsStreamDesc: UnaryMethodDefinitionish = {
* ----------------------
*/
export interface DashAPICreds {
Create(request: DeepPartial<DashAPICredsCreateReq>, metadata?: grpc.Metadata): Promise<DashCred>;
Update(request: DeepPartial<DashAPICredsUpdateReq>, metadata?: grpc.Metadata): Promise<DashCred>;
Delete(request: DeepPartial<DashAPICredsDeleteReq>, metadata?: grpc.Metadata): Promise<DashCred>;
Create(request: DeepPartial<DashAPICredsCreateReq>, metadata?: Metadata): Promise<DashCred>;
Update(request: DeepPartial<DashAPICredsUpdateReq>, metadata?: Metadata): Promise<DashCred>;
Delete(request: DeepPartial<DashAPICredsDeleteReq>, metadata?: Metadata): Promise<DashCred>;
}

export class DashAPICredsClientImpl implements DashAPICreds {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { GetBasicRequest } from './only-types-grpc-metadata';

describe('BasicService', () => {
it('compiles', () => {
const g: GetBasicRequest = { name: 'asdf' };
expect(g).toBeTruthy();
});
});
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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) {}
}
16 changes: 16 additions & 0 deletions integration/only-types-grpc-metadata/only-types-grpc-metadata.ts
Original file line number Diff line number Diff line change
@@ -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<GetBasicResponse>;
}
1 change: 1 addition & 0 deletions integration/only-types-grpc-metadata/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
outputEncodeMethods=false,outputJsonMethods=false,outputClientImpl=false,lowerCaseServiceMethods=true,addGrpcMetadata=true
Binary file modified integration/type-registry/bar/bar.bin
Binary file not shown.
Binary file modified integration/type-registry/foo.bin
Binary file not shown.
11 changes: 1 addition & 10 deletions integration/type-registry/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions src/generate-nestjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -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`);
Expand Down
5 changes: 3 additions & 2 deletions src/generate-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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`);
Expand Down