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: add support for Struct in NestJS #762

Merged
merged 9 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 13 additions & 9 deletions integration/grpc-js/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,13 @@ export const Struct = {
},

unwrap(message: Struct): { [key: string]: any } {
if (!message.fields) {
return message;
}
const object: { [key: string]: any } = {};
Object.keys(message.fields).forEach((key) => {
object[key] = message.fields[key];
const unwrappedValue = Value.unwrap(message.fields[key]);
object[key] = unwrappedValue !== undefined ? unwrappedValue : message.fields[key];
});
return object;
},
Expand Down Expand Up @@ -380,18 +384,18 @@ export const Value = {
return result;
},

unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
if (message?.stringValue !== undefined) {
unwrap(message: any): string | number | boolean | Object | null | Array<any> | undefined {
if (message?.hasOwnProperty("stringValue") && message?.stringValue !== undefined) {
return message.stringValue;
} else if (message?.numberValue !== undefined) {
} else if (message?.hasOwnProperty("numberValue") && message?.numberValue !== undefined) {
return message.numberValue;
} else if (message?.boolValue !== undefined) {
} else if (message?.hasOwnProperty("boolValue") && message?.boolValue !== undefined) {
return message.boolValue;
} else if (message?.structValue !== undefined) {
return message.structValue;
} else if (message?.listValue !== undefined) {
} else if (message?.hasOwnProperty("structValue") && message?.structValue !== undefined) {
return Struct.unwrap(message.structValue as any);
} else if (message?.hasOwnProperty("listValue") && message?.listValue !== undefined) {
return message.listValue;
} else if (message?.nullValue !== undefined) {
} else if (message?.hasOwnProperty("nullValue") && message?.nullValue !== undefined) {
return null;
}
return undefined;
Expand Down
24 changes: 24 additions & 0 deletions integration/nestjs-metadata-grpc-js/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ export interface Villain {

export const HERO_PACKAGE_NAME = "hero";

function createBaseHeroById(): HeroById {
return { id: 0 };
}

export const HeroById = {};

function createBaseVillainById(): VillainById {
return { id: 0 };
}

export const VillainById = {};

function createBaseHero(): Hero {
return { id: 0, name: "" };
}

export const Hero = {};

function createBaseVillain(): Villain {
return { id: 0, name: "" };
}

export const Villain = {};

export interface HeroServiceClient {
findOneHero(request: HeroById, metadata?: Metadata): Observable<Hero>;

Expand Down
24 changes: 24 additions & 0 deletions integration/nestjs-metadata-observables/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ export interface Villain {

export const HERO_PACKAGE_NAME = "hero";

function createBaseHeroById(): HeroById {
return { id: 0 };
}

export const HeroById = {};

function createBaseVillainById(): VillainById {
return { id: 0 };
}

export const VillainById = {};

function createBaseHero(): Hero {
return { id: 0, name: "" };
}

export const Hero = {};

function createBaseVillain(): Villain {
return { id: 0, name: "" };
}

export const Villain = {};

export interface HeroServiceClient {
findOneHero(request: HeroById, metadata?: Metadata): Observable<Hero>;

Expand Down
24 changes: 24 additions & 0 deletions integration/nestjs-metadata-restparameters/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ export interface Villain {

export const HERO_PACKAGE_NAME = "hero";

function createBaseHeroById(): HeroById {
return { id: 0 };
}

export const HeroById = {};

function createBaseVillainById(): VillainById {
return { id: 0 };
}

export const VillainById = {};

function createBaseHero(): Hero {
return { id: 0, name: "" };
}

export const Hero = {};

function createBaseVillain(): Villain {
return { id: 0, name: "" };
}

export const Villain = {};

export interface HeroServiceClient {
findOneHero(request: HeroById, metadata: Metadata, ...rest: any): Observable<Hero>;

Expand Down
24 changes: 24 additions & 0 deletions integration/nestjs-metadata/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ export interface Villain {

export const HERO_PACKAGE_NAME = "hero";

function createBaseHeroById(): HeroById {
return { id: 0 };
}

export const HeroById = {};

function createBaseVillainById(): VillainById {
return { id: 0 };
}

export const VillainById = {};

function createBaseHero(): Hero {
return { id: 0, name: "" };
}

export const Hero = {};

function createBaseVillain(): Villain {
return { id: 0, name: "" };
}

export const Villain = {};

export interface HeroServiceClient {
findOneHero(request: HeroById, metadata?: Metadata): Observable<Hero>;

Expand Down
24 changes: 24 additions & 0 deletions integration/nestjs-restparameters/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ export interface Villain {

export const HERO_PACKAGE_NAME = "hero";

function createBaseHeroById(): HeroById {
return { id: 0 };
}

export const HeroById = {};

function createBaseVillainById(): VillainById {
return { id: 0 };
}

export const VillainById = {};

function createBaseHero(): Hero {
return { id: 0, name: "" };
}

export const Hero = {};

function createBaseVillain(): Villain {
return { id: 0, name: "" };
}

export const Villain = {};

export interface HeroServiceClient {
findOneHero(request: HeroById, ...rest: any): Observable<Hero>;

Expand Down
24 changes: 24 additions & 0 deletions integration/nestjs-simple-observables/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ export interface Villain {

export const HERO_PACKAGE_NAME = "hero";

function createBaseHeroById(): HeroById {
return { id: 0 };
}

export const HeroById = {};

function createBaseVillainById(): VillainById {
return { id: 0 };
}

export const VillainById = {};

function createBaseHero(): Hero {
return { id: 0, name: "" };
}

export const Hero = {};

function createBaseVillain(): Villain {
return { id: 0, name: "" };
}

export const Villain = {};

export interface HeroServiceClient {
findOneHero(request: HeroById): Observable<Hero>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export interface Empty {
}

export const GOOGLE_PROTOBUF_PACKAGE_NAME = "google.protobuf";

function createBaseEmpty(): Empty {
return {};
}

export const Empty = {};
6 changes: 6 additions & 0 deletions integration/nestjs-simple-restparameters/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export interface User {

export const HERO_PACKAGE_NAME = "hero";

function createBaseUser(): User {
return { id: 0, name: "" };
}

export const User = {};

export interface HeroServiceClient {
findCurrentUser(request: Empty, ...rest: any): Observable<User>;
}
Expand Down
6 changes: 6 additions & 0 deletions integration/nestjs-simple-usedate/google/protobuf/empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export interface Empty {
}

export const GOOGLE_PROTOBUF_PACKAGE_NAME = "google.protobuf";

function createBaseEmpty(): Empty {
return {};
}

export const Empty = {};
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ export interface Timestamp {
}

export const GOOGLE_PROTOBUF_PACKAGE_NAME = "google.protobuf";

function createBaseTimestamp(): Timestamp {
return { seconds: 0, nanos: 0 };
}

export const Timestamp = {};
24 changes: 24 additions & 0 deletions integration/nestjs-simple-usedate/hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ wrappers[".google.protobuf.Timestamp"] = {
},
} as any;

function createBaseHeroById(): HeroById {
return { id: 0 };
}

export const HeroById = {};

function createBaseVillainById(): VillainById {
return { id: 0 };
}

export const VillainById = {};

function createBaseHero(): Hero {
return { id: 0, name: "", birthDate: undefined };
}

export const Hero = {};

function createBaseVillain(): Villain {
return { id: 0, name: "" };
}

export const Villain = {};

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

Expand Down
6 changes: 6 additions & 0 deletions integration/nestjs-simple/google/protobuf/empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export interface Empty {
}

export const GOOGLE_PROTOBUF_PACKAGE_NAME = "google.protobuf";

function createBaseEmpty(): Empty {
return {};
}

export const Empty = {};
Loading