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

View File

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

View File

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