Basic support for nested Enums / Messages

This commit is contained in:
Mathieu Acthernoene 2017-01-10 11:22:18 +01:00
parent 6cbc8f35eb
commit 66e9d20e1f
3 changed files with 179 additions and 40 deletions

View File

@ -4,65 +4,173 @@
import grpc from 'grpc'
import pbFile from './pbFile.js'
export type TestEnum =
| 'ELEMENT_A'
| 'ELEMENT_B'
;
export type TestEnum = {|
ELEMENT_A?: 0;
ELEMENT_B?: 1;
|};
export type TestNestedEnum = {|
ELEMENT_C?: 0;
ELEMENT_D?: 1;
|};
export type TestNestedMessage = {|
s?: string;
t?: number;
|};
export type TestMessage = {|
a?: string;
b?: number;
c?: number;
d?: number;
e?: number;
n?: Array<string>;
o?: Array<number>;
p?: Array<number>;
q?: Array<number>;
r?: Array<number>;
s?:
| 'ELEMENT_C'
| 'ELEMENT_D'
;
a?: string;
b?: number;
c?: number;
d?: number;
e?: number;
n?: Array<string>;
o?: Array<number>;
p?: Array<number>;
q?: Array<number>;
r?: Array<number>;
TestNestedMessage?: TestNestedMessage;
TestNestedEnum?: TestNestedEnum;
|};
export type TestNoStreamRequest = {|
message?: TestMessage;
message?: TestMessage;
|};
export type TestNoStreamReply = {|
message?: TestMessage;
err_msg?: string;
message?: TestMessage;
err_msg?: string;
|};
export type TestStreamRequestRequest = {|
message?: TestMessage;
message?: TestMessage;
|};
export type TestStreamRequestReply = {|
message?: TestMessage;
err_msg?: string;
message?: TestMessage;
err_msg?: string;
|};
export type TestStreamReplyRequest = {|
message?: TestMessage;
message?: TestMessage;
|};
export type TestStreamReplyReply = {|
message?: TestMessage;
err_msg?: string;
message?: TestMessage;
err_msg?: string;
|};
export type TestStreamBothRequest = {|
message?: TestMessage;
message?: TestMessage;
|};
export type TestStreamBothReply = {|
message?: TestMessage;
err_msg?: string;
message?: TestMessage;
err_msg?: string;
|};
function serialize_test_TestNoStreamRequest(arg: TestNoStreamRequest) {
if (!(arg instanceof pbFile.TestNoStreamRequest)) {
throw new Error('Expected argument of type TestNoStreamRequest')

View File

@ -27,7 +27,11 @@ message TestMessage {
repeated int64 p = 16;
repeated float q = 17;
repeated double r = 18;
enum s {
message TestNestedMessage {
string s = 1;
int32 t = 2;
}
enum TestNestedEnum {
ELEMENT_C = 0;
ELEMENT_D = 1;
}

View File

@ -3,18 +3,45 @@
{{$Package:=.File.Package}}
import grpc from 'grpc'
import pbFile from './pbFile.js'
{{range .File.EnumType}}
export type {{.Name}} = {{range .Value}}
| '{{.Name}}'{{end}}
;{{end}}
{{range .File.MessageType}}
export type {{.Name}} = {|{{range .Field}}
{{.Name}}?: {{. | jsType}};{{end}}{{range .EnumType}}
{{.Name}}?:{{range .Value}}
| '{{.Name}}'{{end}}
;{{end}}
export type {{.Name}} = {|
{{range .Value}}
{{.Name}}?: {{.Number}};
{{end}}
|};
{{end}}
{{range .File.MessageType}}
{{range .EnumType}}
export type {{.Name}} = {|
{{range .Value}}
{{.Name}}?: {{.Number}};
{{end}}
|};
{{end}}
{{range .NestedType}}
export type {{.Name}} = {|
{{range .Field}}
{{.Name}}?: {{. | jsType}};
{{end}}
|};
{{end}}
export type {{.Name}} = {|
{{range .Field}}
{{.Name}}?: {{. | jsType}};
{{end}}
{{range .NestedType}}
{{.Name}}?: {{.Name}};
{{end}}
{{range .EnumType}}
{{.Name}}?: {{.Name}};
{{end}}
|};
{{end}}
{{range .File.Service}}{{range .Method}}
function serialize_{{$Package}}_{{.InputType | shortType}}(arg: {{.InputType | shortType}}) {
if (!(arg instanceof pbFile.{{.InputType | shortType}})) {