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

feat(#852): Added handler for Google primitives Wrappers compatible with NestJS integration #855

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Binary file modified integration/batching-with-context-esModuleInterop/batching.bin
Binary file not shown.
95 changes: 95 additions & 0 deletions integration/nestjs-simple/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* eslint-disable */

export const protobufPackage = "google.protobuf";

/**
* Wrapper message for `double`.
*
* The JSON representation for `DoubleValue` is JSON number.
*/
export interface DoubleValue {
/** The double value. */
value: number;
}

/**
* Wrapper message for `float`.
*
* The JSON representation for `FloatValue` is JSON number.
*/
export interface FloatValue {
/** The float value. */
value: number;
}

/**
* Wrapper message for `int64`.
*
* The JSON representation for `Int64Value` is JSON string.
*/
export interface Int64Value {
/** The int64 value. */
value: number;
}

/**
* Wrapper message for `uint64`.
*
* The JSON representation for `UInt64Value` is JSON string.
*/
export interface UInt64Value {
/** The uint64 value. */
value: number;
}

/**
* Wrapper message for `int32`.
*
* The JSON representation for `Int32Value` is JSON number.
*/
export interface Int32Value {
/** The int32 value. */
value: number;
}

/**
* Wrapper message for `uint32`.
*
* The JSON representation for `UInt32Value` is JSON number.
*/
export interface UInt32Value {
/** The uint32 value. */
value: number;
}

/**
* Wrapper message for `bool`.
*
* The JSON representation for `BoolValue` is JSON `true` and `false`.
*/
export interface BoolValue {
/** The bool value. */
value: boolean;
}

/**
* Wrapper message for `string`.
*
* The JSON representation for `StringValue` is JSON string.
*/
export interface StringValue {
/** The string value. */
value: string;
}

/**
* Wrapper message for `bytes`.
*
* The JSON representation for `BytesValue` is JSON string.
*/
export interface BytesValue {
/** The bytes value. */
value: Uint8Array;
}

export const GOOGLE_PROTOBUF_PACKAGE_NAME = "google.protobuf";
Binary file modified integration/nestjs-simple/hero.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions integration/nestjs-simple/hero.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/wrappers.proto";

package hero;

Expand All @@ -28,6 +29,9 @@ message Hero {
string name = 2;
.google.protobuf.Timestamp birth_date = 3;
.google.protobuf.Struct external_data = 4;
.google.protobuf.StringValue nick_name = 5;
.google.protobuf.BoolValue is_famous = 6;
.google.protobuf.Int32Value experience = 7;
}

message Villain {
Expand Down
84 changes: 84 additions & 0 deletions integration/nestjs-simple/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface Hero {
name: string;
birthDate: Timestamp | undefined;
externalData: { [key: string]: any } | undefined;
nickName: string | undefined;
isFamous: boolean | undefined;
experience: number | undefined;
}

export interface Villain {
Expand All @@ -32,6 +35,87 @@ export const HERO_PACKAGE_NAME = "hero";

wrappers[".google.protobuf.Struct"] = { fromObject: Struct.wrap, toObject: Struct.unwrap } as any;

wrappers[".google.protobuf.StringValue"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

wrappers[".google.protobuf.Int32Value"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

wrappers[".google.protobuf.UInt32Value"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

wrappers[".google.protobuf.DoubleValue"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

wrappers[".google.protobuf.FloatValue"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

wrappers[".google.protobuf.Int64Value"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

wrappers[".google.protobuf.UInt64Value"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

wrappers[".google.protobuf.BoolValue"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

wrappers[".google.protobuf.BytesValue"] = {
fromObject(value: any) {
return { value };
},
toObject(message: { value: any }) {
return message.value;
},
} as any;

export interface HeroServiceClient {
addOneHero(request: Hero): Observable<Empty>;

Expand Down
6 changes: 6 additions & 0 deletions integration/nestjs-simple/nestjs-project/hero.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ export class HeroController implements HeroServiceController {
name: "Stephenh",
birthDate: { seconds: 1, nanos: 2 },
externalData: { foo: "bar", fizz: 1, nested: { isFailing: false, arr: [1, "foo", ["bar"]] } },
isFamous: true,
experience: 1000,
nickName: 'Hackerman'
},
{
id: 2,
name: "Iangregsondev",
birthDate: { seconds: 1, nanos: 3 },
externalData: { bar: 10, baz: "foo", isPassing: true },
isFamous: true,
experience: 1000,
nickName: 'Foo'
},
];

Expand Down
2 changes: 1 addition & 1 deletion integration/nestjs-simple/nestjs-simple-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("nestjs-simple-test nestjs", () => {

it("should addOneHero", async () => {
const emptyResponse = await heroService
.addOneHero({ id: 3, name: "Toon", birthDate: undefined, externalData: { some: "data" } })
.addOneHero({ id: 3, name: "Toon", birthDate: undefined, externalData: { some: "data" }, nickName: "Guy", experience: 1000, isFamous: true })
.toPromise();
expect(emptyResponse).toEqual({});
});
Expand Down
3 changes: 3 additions & 0 deletions integration/nestjs-simple/sample-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export class SampleService implements HeroServiceController {
name: "test",
birthDate: undefined,
externalData: { foo: "bar", fizz: 1, nested: { isFailing: false, array: [1, "foo", ["bar"]] } },
experience: 1000,
nickName: "test",
isFamous: true
});
}

Expand Down
Loading
Loading