-
Notifications
You must be signed in to change notification settings - Fork 171
Service support? #69
Comments
@matthewmueller I think some work has been done on Protobuf: https://github.com/cuelang/cue/tree/master/encoding/protobuf @mpvl would have a better idea of the state of that code, though. |
@matthewmueller This is not planned at the moment, although I have given it some thought. The main reason not though is that I didn't have a concrete use case and I'm not sure how that would look like. But as @jlongtine said, the infrastructure for Proto parsing and conversion is already in place. So it would be useful to know what exactly expect to do with such a feature. |
@matthewmueller if you have a concrete example of how you would want to be using CUE this way I would be quite interested. |
Hey @mpvl! I'm imagining an implementation of protobuf's generators that adds constraint-based validation. Tons of unknowns here, but conceptually I was thinking something like this: user.cue email: "\w+@\w+\.\w{2,}" // some regex for email
CreateInput: {
email: email
password: string // perhaps @len(string) > 0 <= 30
born: >= 1900 <= 2019
}
CreateOutput: {
id: >=0
email: email
born: >= 1900 <= 2019
}
UpdateInput: {
email?: email
password?: string
born?: >= 1900 <= 2019
}
UpdateOutput: {
ok: true | false
}
User: {
create(in: CreateInput): CreateOutput
update(in: UpdateInput): UpdateOutput
} Then, run Usage would look something like this: main.go package main
import "cue/user"
func main() {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
var u user.CreateInput
if err := user.Create.Unmarshal(buf, &u); err != nil {
panic(err)
}
fmt.Println("got a user.CreateInput!", u)
} @neelance do you have some thoughts on this? Our discussion sparked this initial issue 😊 |
Just to add some thoughts here: with the upcoming proposal to generalize and harmonize the syntax, something that gets close to the above rpc signatures is:
or maybe
(The scanner still recognizes Especially the former would require a minimal syntactic adjustment and generalizes, syntactically, what expressions are allowed as a label. We are also considering allowing the call syntax for structs. Consider, this,
On tip, which supports embedded scalars, this can be written as:
The ideas is to allow an extension of the builtin syntax for structs as well, allowing
Where This would also allow builtins to have Swift-style named arguments, which would allow some things to be written clearly, like:
Conversely, we could consider unnamed arguments for structs to map to the fields with name These extensions to the call syntax also suggest the following possible syntax for rpc calls:
The problem with this is that there is an ambiguity with the proposed syntax (#165) for computed labels, especially if we want to allow unnamed arguments. A possible solution for this is to repurpose
This would remove that ambiguity and this notation has precedence in functional languages. A disadvantage of this approach is that it introduces more syntax (although limited). An advantage of doing so, though, is that it also would allow named return arguments without complications:
Another advantage of using Note that with both proposed syntaxes, the existing field syntax would allow attributes to be defined along the arguments. This means it allows attributing additional meaning to arguments that are irrelevant to CUE, such as:
or
So so far, the best candidates are either of the form Thoughts welcome. |
I'm in favor of the |
This issue has been migrated to cue-lang/cue#69. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
I'm very interested in CUE for inter process communication. I was wondering if there are any plans to add function signatures to enforce how two processes can communicate with each other?
Something like services in Thrift / Protobuf or queries & mutations in a GraphQL schema.
This seems a bit outside of the core motivation for CUE, but it does seem like CUE would fit very well here too.
The text was updated successfully, but these errors were encountered: