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

Add support for generating only NestJS clients #962

Closed
MaksymShuldiner opened this issue Nov 12, 2023 · 2 comments
Closed

Add support for generating only NestJS clients #962

MaksymShuldiner opened this issue Nov 12, 2023 · 2 comments

Comments

@MaksymShuldiner
Copy link

Is there any possibility to generate only client-side code for the nest js app?

Instead of that :

/* eslint-disable */
import { Metadata } from "@grpc/grpc-js";
import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices";
import { Observable } from "rxjs";

export const protobufPackage = "user_profile";

export interface createUserProfileRequest {
  name: string;
}

export interface createUserProfileResponse {
  id: number;
}

export const USER_PROFILE_PACKAGE_NAME = "user_profile";

export interface UserProfileClient {
  createUserProfile(request: createUserProfileRequest, metadata?: Metadata): Observable<createUserProfileResponse>;
}

export interface UserProfileController {
  createUserProfile(
    request: createUserProfileRequest,
    metadata?: Metadata,
  ): Promise<createUserProfileResponse> | Observable<createUserProfileResponse> | createUserProfileResponse;
}

export function UserProfileControllerMethods() {
  return function (constructor: Function) {
    const grpcMethods: string[] = ["createUserProfile"];
    for (const method of grpcMethods) {
      const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
      GrpcMethod("UserProfile", method)(constructor.prototype[method], method, descriptor);
    }
    const grpcStreamMethods: string[] = [];
    for (const method of grpcStreamMethods) {
      const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
      GrpcStreamMethod("UserProfile", method)(constructor.prototype[method], method, descriptor);
    }
  };
}

export const USER_PROFILE_SERVICE_NAME = "UserProfile";

I would like to see something like that:

/* eslint-disable */
import { Metadata } from "@grpc/grpc-js";
import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices";
import { Observable } from "rxjs";

export const protobufPackage = "user_profile";

export interface createUserProfileRequest {
  name: string;
}

export interface createUserProfileResponse {
  id: number;
}

export const USER_PROFILE_PACKAGE_NAME = "user_profile";

export interface UserProfileClient {
  createUserProfile(request: createUserProfileRequest, metadata?: Metadata): Observable<createUserProfileResponse>;
}

export const USER_PROFILE_SERVICE_NAME = "UserProfile";

I managed to reach that by disabling nest-js = true and generation of client Impl and encoding/decoding methods, but it does not generate package and service names

@stephenh
Copy link
Owner

Hi @MaksymShuldiner , looks that is not currently possible... If you'd like to flip our nestJs=true flag into a nestJs=true|clients|services that sounds like a good change, it would be around in here:

#951

If you could submit a PR, that'd be great! Thanks!

@stephenh stephenh changed the title Possibility to generate only client-side code for NEST JS. Add support for generating only NestJS clients Nov 19, 2023
@stephenh
Copy link
Owner

Dup of #527

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants