diff --git a/examples/flow/output/test/test_grpc_js.js b/examples/flow/output/test/test_grpc_js.js index e8a87e2..db9204d 100644 --- a/examples/flow/output/test/test_grpc_js.js +++ b/examples/flow/output/test/test_grpc_js.js @@ -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; - o?: Array; - p?: Array; - q?: Array; - r?: Array; - s?: - | 'ELEMENT_C' - | 'ELEMENT_D' - ; + + a?: string; + + b?: number; + + c?: number; + + d?: number; + + e?: number; + + n?: Array; + + o?: Array; + + p?: Array; + + q?: Array; + + r?: Array; + + + 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') diff --git a/examples/flow/protos/test.proto b/examples/flow/protos/test.proto index e15ee88..7458188 100644 --- a/examples/flow/protos/test.proto +++ b/examples/flow/protos/test.proto @@ -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; } diff --git a/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl b/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl index 8acd68d..fc99da1 100644 --- a/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl +++ b/examples/flow/templates/{{.File.Package}}/{{.File.Package}}_grpc_js.js.tmpl @@ -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}})) {