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

Reuse protobuf for Typescript and other languages #36

Open
IchordeDionysos opened this issue May 27, 2020 · 3 comments
Open

Reuse protobuf for Typescript and other languages #36

IchordeDionysos opened this issue May 27, 2020 · 3 comments

Comments

@IchordeDionysos
Copy link

IchordeDionysos commented May 27, 2020

Is there a way to build the files also for other languages, like Typescript?

We want to have one way to define how our Firestore documents have to look like.
It does seem to work with primitive types like strings, numbers, even Timestamps, ...

syntax = "proto3";

message FirestoreDoc {
    // Works
    google.protobuf.Timestamp timestamp = 1;
    string ref = 2
        [(google.firebase.rules.firebase_rules_field).reference_type = true];

    enum EnumType {
        option (google.firebase.rules.firebase_rules_enum).string_values = true;
        enumValue = 0;
    }

    EnumType type = 3;
}

But once I add a Reference (with the special syntax defined by this project), it breaks with other compilers, like protobufjs.

Also, enums kinda work, but they aren't properly mapped onto string values:

This is generated:

enum EnumType {
  enumValue = 0,
}

This should have been generated:

enum EnumType {
  enumValue = "enumValue",
}
@samtstern
Copy link
Contributor

@IchordeDionysos I do think it should be possible to use the proto extensions here to generate proto bindings in other languages (TS included).

Can you show me a simple end-to-end example of how it fails with references? Show me your proto definition, the command you're using to compile it with protoc, and the error message you get.

@IchordeDionysos
Copy link
Author

I've used protobufjs with a command like:

pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
pbts -o compiled.d.ts compiled.js

And every field where there was a special annotation, like the Reference [1] or the enum string value annotation, it did not work properly.

It just generated an enum with numbers instead of an enum with strings, which is not really helpful...
Also, references were generated as strings and not FirebaseFirestore.DocumentReference

[1] [(google.firebase.rules.firebase_rules_field).reference_type = true];
[2] option (google.firebase.rules.firebase_rules_enum).string_values = true;

@nilsreichardt
Copy link

I am also interested in it.

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

3 participants