Reuse protobuf for Typescript and other languages
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",
}
@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.
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;
I am also interested in it.