tiziano88 / elm-protobuf Goto Github PK
View Code? Open in Web Editor NEWprotobuf plugin for elm
Home Page: https://package.elm-lang.org/packages/tiziano88/elm-protobuf/latest/
License: MIT License
protobuf plugin for elm
Home Page: https://package.elm-lang.org/packages/tiziano88/elm-protobuf/latest/
License: MIT License
There may be a workaround, but I'm having a lot of trouble trying to install latest due to the current tags lacking the "v" prefix.
First thanks for the elm protobuf compiler, its fantastic and lets me roll my own websocket/json-rpc with protobuf+elm on one side and protobuf+go on the other. The compiled elm has been trouble-free until I tried to decode a list of objects (a "Schedule").
the js console shows elm received some json of apparently the right format
response: { id = "90de-18f43f9f486f", method = "ScheduleListResponse", object = { Ok = True, Schedules = { 0 = { Id = "schedules-877d-76499fe253ae", AccountId = "accounts-b8b0-6d34a035a65e", AlgorithmId = "noop", Status = "active" } } } }
after calling scheduleListResponseDecoder response.object
, the decoded object, always has an empty array for Schedules.
ScheduleListResponseMsg { ok = True, message = "", schedules = [] }
the ScheduleListResponse protbuf is defined as
import "proto/schedule.proto";
message ScheduleListResponse {
bool Ok = 1;
string Message = 2;
repeated Schedule Schedules = 3;
}
and the Schedule is
message Schedule {
string Id = 1;
string AccountId = 2;
string AlgorithmId = 3;
string Status = 4;
}
the Elm for ScheduleListResponse also looks good
type alias ScheduleListResponse =
{ ok : Bool -- 1
, message : String -- 2
, schedules : List Schedule -- 3
}
scheduleListResponseDecoder : JD.Decoder ScheduleListResponse
scheduleListResponseDecoder =
JD.lazy <| \_ -> decode ScheduleListResponse
|> required "Ok" JD.bool False
|> required "Message" JD.string ""
|> repeated "Schedules" scheduleDecoder
any ideas what might be wrong?
Given infix functions are problematic in Elm at the moment (they cause conflicts if any 2 libraries define the same function), and may be going away except for in core libraries in 0.19, would it be possible to replace the (<$>)
and (<*>)
in the generated decoders?
(Sorry if this is already done, I have not looked at the implementation, just the expected output in the tests.)
this could generate typed client code for grpc services
When compiling a single proto file that imports another, the referenced types don't seem to be correct:
sub.proto
:
syntax = "proto3";
package Foo;
message Baz2 {
int32 field_a = 1;
}
main.proto
:
syntax = "proto3";
import "sub.proto";
package Foo;
message Baz {
Baz2 field_a = 1;
}
Compiled with: protoc --elm_out=. main.proto sub.proto
Produces incorrect code:
-- Sub.elm
type alias Baz2 =
{ fieldA : Int -- 1
}
-- Main.elm
type alias Baz =
{ fieldA : Maybe Foo_Baz2 -- 1
}
Compiler error for reference:
I cannot find a `Foo_Baz2` type:
16| { fieldA : Maybe Foo_Baz2 -- 1
It seems as though the package name is incorrectly being added to the name of the type.
As a workaround, if I comment out the package name from both proto files it seems to generate correct code.
I don't know if this falls into the unsupported 'Packages' listing in the main README.md, since it didn't list details as to why it wasn't supported.
Interestingly, this is very similar to a bug I just reported in the other Elm protoc project: eriktim/protoc-gen-elm#7
I am wondering your thoughts on creating chainable updateX
methods for each message. This is something I often do in elm for types I create.
There is a history of such methods on proto objects:
setX
methods.setX
methods, though they are unchainable.Example:
message Model {
string string_field = 1;
int64 long_field = 2;
}
Example Proto Output (only new functions shown):
updateStringField : String -> Model -> Model
updateStringField newValue record =
{ record | stringField = newValue }
updateLongField : Int -> Model -> Model
updateLongField newValue record =
{ record | longField = newValue }
Example Usage:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
SomeMsg someStr someLong ->
( model
|> updateStringField someStr
|> updateLongField someLong
, Cmd.none )
I would gladly offer to help with this if you're interested in the idea
I'm using protoc with elm and go to pass data structures back and forth over websocket/json. Its been going great until I tried using enums. To my delight, the elm module uses the string value of each enum option. Unfortunately, the go (and crystal) code generators use the int32 form of an enum option. So {"status":3}
does not decode on the elm side, and {"status":"ready"}
does not decode on the go side Is there a way to get the generated elm code to use the int? I'd rather use the string val name but it appears int is more canonical, and possibly a win for space efficiency.
I have an existing set of pb files that I'd be interested in using with elm, but they're written with proto2, and it looks like migrating to proto3 might require changes to the code interacting with them. Is there a chance we can support proto2 for this?
Here's some protobuf for which the elm protobuf generator results in elm code that fails to compile. For one, the MATCH
enum value and the match
oneof field collide. And after fixing that, I get collisions between for example the Change
message type alias and the change
oneof field.
I can get around this for now by renaming things (and I realize the README checklist lists oneof as unsupported), but seems worth addressing at some point? And I hope a "real-world" test case might be good to have around anyway.
syntax = "proto3";
enum ClaimType {
MATCH = 0;
NOMATCH = 1;
}
message Claim {
ClaimType type = 1;
repeated uint32 cards = 2;
}
message Event {
message Join {
string name = 1;
}
message Claimed {
string name = 1;
ClaimType type = 2;
enum Result {
CORRECT = 0;
WRONG = 1;
LATE = 2;
}
Result result = 3;
}
oneof event_oneof {
Join join = 1;
Claimed claimed = 2;
}
}
message Change {
message Position {
uint32 x = 1;
uint32 y = 2;
}
message Deal {
message Place {
Position position = 1;
uint32 card = 2;
}
repeated Place places = 1;
}
message Match {
repeated Position positions = 1;
}
message Move {
message MoveOne {
Position from = 1;
Position to = 2;
}
repeated MoveOne moves = 1;
}
oneof change_oneof {
Deal deal = 1;
Match match = 2;
Move move = 3;
}
}
message Update {
oneof update_oneof {
Change change = 1;
Event event = 2;
}
}
Are there any steps planned on supporting map
in the near future?
We are currently looking into GRPC and its integration with Elm for Prometheus Alertmanager. Map
support would be a crucial feature for us. (See PR)
When installing this package, now get the following:
โ[~/g/s/g/v/t/front]> elm install tiziano88/elm-protobuf
-- OLD DEPENDENCIES --------------------------------------------------- elm.json
The following packages do not work with Elm 0.19.0 right now:
tiziano88/elm-protobuf
This may be because it is not upgraded yet. It may be because a better solution
came along, so there was no need to upgrade it. Etc. Try asking around on Slack
to learn more about the topic.
Note: Whatever the case, please be kind to the relevant package authors! Having
friendly interactions with users is great motivation, and conversely, getting
berated by strangers on the internet sucks your soul dry. Furthermore, package
authors are humans with families, friends, jobs, vacations, responsibilities,
goals, etc. They face obstacles outside of their technical work you will never
know about, so please assume the best and try to be patient and supportive!
Is this because the version number in the elm.json was not changed from 2.1.0? Or does it need to be republished?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.