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

exportCommonSymbols=false doesn't work as expected #915

Closed
eladhaim opened this issue Sep 2, 2023 · 2 comments
Closed

exportCommonSymbols=false doesn't work as expected #915

eladhaim opened this issue Sep 2, 2023 · 2 comments

Comments

@eladhaim
Copy link
Contributor

eladhaim commented Sep 2, 2023

          it doesn't work, i have an example:

2 proto files:

bar.proto

package com.services;

service Bar {
    rpc Service (BarRequest) returns (BarResponse) {}
}

message BarRequest {
    string id = 1;
}

message BarResponse { 
    string id = 1;
}

foo.proto

package com.services;

service Foo {
    rpc Service (FooRequest) returns (FooResponse) {}
}

message FooRequest {
    string id = 1;
}

message FooResponse { 
    string id = 1;
}

Output:

bar.ts

/* eslint-disable */
import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices";
import { Observable } from "rxjs";
import { messageTypeRegistry } from "./typeRegistry";

export interface BarRequest {
  $type: "BarRequest";
  id: string;
}

export interface BarResponse {
  $type: "BarResponse";
  id: string;
}

export const COM_SERVICES_PACKAGE_NAME = "com.services";

export const BarRequest = { $type: "BarRequest" as const };

messageTypeRegistry.set(BarRequest.$type, BarRequest);

export const BarResponse = { $type: "BarResponse" as const };

messageTypeRegistry.set(BarResponse.$type, BarResponse);

export interface BarClient {
  service(request: BarRequest): Observable<BarResponse>;
}

export interface BarController {
  service(request: BarRequest): Promise<BarResponse> | Observable<BarResponse> | BarResponse;
}

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

export const BAR_SERVICE_NAME = "Bar";

foo.ts

/* eslint-disable */
import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices";
import { Observable } from "rxjs";
import { messageTypeRegistry } from "./typeRegistry";

export interface FooRequest {
  $type: "com.services.FooRequest";
  id: string;
}

export interface FooResponse {
  $type: "com.services.FooResponse";
  id: string;
}

export const COM_SERVICES_PACKAGE_NAME = "com.services";

export const FooRequest = { $type: "com.services.FooRequest" as const };

messageTypeRegistry.set(FooRequest.$type, FooRequest);

export const FooResponse = { $type: "com.services.FooResponse" as const };

messageTypeRegistry.set(FooResponse.$type, FooResponse);

export interface FooClient {
  service(request: FooRequest): Observable<FooResponse>;
}

export interface FooController {
  service(request: FooRequest): Promise<FooResponse> | Observable<FooResponse> | FooResponse;
}

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

export const FOO_SERVICE_NAME = "Foo";

has you see both of them exports the "COM_SERVICES_PACKAGE_NAME" which make it impossible import both of the files to the same index.ts

Originally posted by @eladhaim in #911 (comment)

@stephenh
Copy link
Owner

stephenh commented Sep 2, 2023

Ah yeah, I see; that code is generated here:

https://github.com/stephenh/ts-proto/blob/main/src/main.ts#L161

If you have suggestions/PRs for how to avoid the duplication, feel free to submit a PR!

@stephenh
Copy link
Owner

stephenh commented Sep 3, 2023

Fixed in #916 , thanks @eladhaim

@stephenh stephenh closed this as completed Sep 3, 2023
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