Open aklikic opened 1 year ago
For command and event classes generated from proto files to have common base class/trait where less amount of copy-paste code would be required.
Commands and events are generated by ScalaPB. We generate only the entities. That is to say, our codegen is not responsible for generating all classes, only the component's skeletons.
There are means to ask ScalaPB to make the generated classes extend a given trait, but that requires the user to learn about it and use some ScalaPB extensions. See https://github.com/lightbend/kalix-proxy/issues/1738#issuecomment-1429969165
But that opens the door to other kinds of issues, for example, the proto needs to be cleaned up before being used to generate clients.
FYI I tried this and it seems to give us what we want out-of-the-box:
import "scalapb/scalapb.proto";
option (scalapb.options) = {
// Generate the base trait.
preamble: ["sealed trait CompanyAccessEvent {}"];
single_file: true;
};
message CompanyAccessModified {
option (scalapb.message).extends = "CompanyAccessEvent";
string sharing_company_id = 1;
string receiving_company_business_id = 2;
string permission = 3;
EventMetadata metadata = 1000;
}
import "scalapb/scalapb.proto";
option (scalapb.options) = {
// Generate the base trait.
preamble: ["sealed trait CompanyAccessCommand {}"];
single_file: true;
};
message ModifyCompanyAccessCommand {
option (scalapb.message).extends = "CompanyAccessCommand";
string sharing_company_id = 1 [(kalix.field).entity_key = true];
string receiving_company_business_id = 2 [(kalix.field).entity_key = true];
string permission = 3;
string note = 4;
}
Generated commands end events then have with CompanyAccessCommand
and with CompanyAccessEvent
.
Scalapb fulfills this requirement.
Problem:
When writing a framework agnostic domain logic in Kalix it requires huge amount of copy-paste code
Porposed solution:
For command and event classes generated from proto files to have common base class/trait where less amount of copy-paste code would be required.
Example
Domain logic (in case of common base class/trait):