Rename js-grpc folder, add enums to example file
This commit is contained in:
		
							
								
								
									
										13
									
								
								examples/flow/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								examples/flow/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| .PHONY: build | ||||
| build: | ||||
| 	mkdir -p output | ||||
| 	protoc -I. --gotemplate_out=template_dir=templates,debug=true:output ./protos/*.proto | ||||
|  | ||||
|  | ||||
| .PHONY: re | ||||
| re: clean build | ||||
|  | ||||
|  | ||||
| .PHONY: clean | ||||
| clean: | ||||
| 	rm -rf output | ||||
							
								
								
									
										203
									
								
								examples/flow/output/test/test_grpc_js.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										203
									
								
								examples/flow/output/test/test_grpc_js.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,203 @@ | ||||
| // @flow | ||||
| // GENERATED CODE -- DO NOT EDIT! | ||||
|  | ||||
| import grpc from 'grpc' | ||||
| import pbFile from './pbFile.js' | ||||
| type TestEnum =  | ||||
|   | 'ELEMENT_A' | ||||
|   | 'ELEMENT_B' | ||||
| ; | ||||
|  | ||||
| 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' | ||||
|   ; | ||||
| |}; | ||||
|  | ||||
| type TestNoStreamRequest = {| | ||||
|   message?: TestMessage; | ||||
| |}; | ||||
|  | ||||
| type TestNoStreamReply = {| | ||||
|   message?: TestMessage; | ||||
|   err_msg?: string; | ||||
| |}; | ||||
|  | ||||
| type TestStreamRequestRequest = {| | ||||
|   message?: TestMessage; | ||||
| |}; | ||||
|  | ||||
| type TestStreamRequestReply = {| | ||||
|   message?: TestMessage; | ||||
|   err_msg?: string; | ||||
| |}; | ||||
|  | ||||
| type TestStreamReplyRequest = {| | ||||
|   message?: TestMessage; | ||||
| |}; | ||||
|  | ||||
| type TestStreamReplyReply = {| | ||||
|   message?: TestMessage; | ||||
|   err_msg?: string; | ||||
| |}; | ||||
|  | ||||
| type TestStreamBothRequest = {| | ||||
|   message?: TestMessage; | ||||
| |}; | ||||
|  | ||||
| type TestStreamBothReply = {| | ||||
|   message?: TestMessage; | ||||
|   err_msg?: string; | ||||
| |}; | ||||
|  | ||||
|  | ||||
| function serialize_test_TestNoStreamRequest(arg: TestNoStreamRequest) { | ||||
|   if (!(arg instanceof pbFile.TestNoStreamRequest)) { | ||||
|     throw new Error('Expected argument of type TestNoStreamRequest') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_test_TestNoStreamRequest(buffer_arg: Array<number>) { | ||||
|   return pbFile.TestNoStreamRequest.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
| function serialize_test_TestNoStreamReply(arg: TestNoStreamReply) { | ||||
|   if (!(arg instanceof pbFile.TestNoStreamReply)) { | ||||
|     throw new Error('Expected argument of type TestNoStreamReply') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_test_TestNoStreamReply(buffer_arg: Array<number>) { | ||||
|   return pbFile.TestNoStreamReply.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
| function serialize_test_TestStreamRequestRequest(arg: TestStreamRequestRequest) { | ||||
|   if (!(arg instanceof pbFile.TestStreamRequestRequest)) { | ||||
|     throw new Error('Expected argument of type TestStreamRequestRequest') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_test_TestStreamRequestRequest(buffer_arg: Array<number>) { | ||||
|   return pbFile.TestStreamRequestRequest.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
| function serialize_test_TestStreamRequestReply(arg: TestStreamRequestReply) { | ||||
|   if (!(arg instanceof pbFile.TestStreamRequestReply)) { | ||||
|     throw new Error('Expected argument of type TestStreamRequestReply') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_test_TestStreamRequestReply(buffer_arg: Array<number>) { | ||||
|   return pbFile.TestStreamRequestReply.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
| function serialize_test_TestStreamReplyRequest(arg: TestStreamReplyRequest) { | ||||
|   if (!(arg instanceof pbFile.TestStreamReplyRequest)) { | ||||
|     throw new Error('Expected argument of type TestStreamReplyRequest') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_test_TestStreamReplyRequest(buffer_arg: Array<number>) { | ||||
|   return pbFile.TestStreamReplyRequest.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
| function serialize_test_TestStreamReplyReply(arg: TestStreamReplyReply) { | ||||
|   if (!(arg instanceof pbFile.TestStreamReplyReply)) { | ||||
|     throw new Error('Expected argument of type TestStreamReplyReply') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_test_TestStreamReplyReply(buffer_arg: Array<number>) { | ||||
|   return pbFile.TestStreamReplyReply.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
| function serialize_test_TestStreamBothRequest(arg: TestStreamBothRequest) { | ||||
|   if (!(arg instanceof pbFile.TestStreamBothRequest)) { | ||||
|     throw new Error('Expected argument of type TestStreamBothRequest') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_test_TestStreamBothRequest(buffer_arg: Array<number>) { | ||||
|   return pbFile.TestStreamBothRequest.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
| function serialize_test_TestStreamBothReply(arg: TestStreamBothReply) { | ||||
|   if (!(arg instanceof pbFile.TestStreamBothReply)) { | ||||
|     throw new Error('Expected argument of type TestStreamBothReply') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_test_TestStreamBothReply(buffer_arg: Array<number>) { | ||||
|   return pbFile.TestStreamBothReply.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
|  | ||||
| export const TestServiceService = { | ||||
|    | ||||
|   testNoStream: { | ||||
|     path: '/test.TestService/TestNoStream', | ||||
|     requestStream: false, | ||||
|     responseStream: false, | ||||
|     requestType: pbFile.TestNoStreamRequest, | ||||
|     responseType: pbFile.TestNoStreamReply, | ||||
|     requestSerialize: serialize_test_TestNoStreamRequest, | ||||
|     requestDeserialize: deserialize_test_TestNoStreamRequest, | ||||
|     responseSerialize: serialize_test_TestNoStreamReply, | ||||
|     responseDeserialize: deserialize_test_TestNoStreamReply, | ||||
|   }, | ||||
|   testStreamRequest: { | ||||
|     path: '/test.TestService/TestStreamRequest', | ||||
|     requestStream: true, | ||||
|     responseStream: false, | ||||
|     requestType: pbFile.TestStreamRequestRequest, | ||||
|     responseType: pbFile.TestStreamRequestReply, | ||||
|     requestSerialize: serialize_test_TestStreamRequestRequest, | ||||
|     requestDeserialize: deserialize_test_TestStreamRequestRequest, | ||||
|     responseSerialize: serialize_test_TestStreamRequestReply, | ||||
|     responseDeserialize: deserialize_test_TestStreamRequestReply, | ||||
|   }, | ||||
|   testStreamReply: { | ||||
|     path: '/test.TestService/TestStreamReply', | ||||
|     requestStream: false, | ||||
|     responseStream: true, | ||||
|     requestType: pbFile.TestStreamReplyRequest, | ||||
|     responseType: pbFile.TestStreamReplyReply, | ||||
|     requestSerialize: serialize_test_TestStreamReplyRequest, | ||||
|     requestDeserialize: deserialize_test_TestStreamReplyRequest, | ||||
|     responseSerialize: serialize_test_TestStreamReplyReply, | ||||
|     responseDeserialize: deserialize_test_TestStreamReplyReply, | ||||
|   }, | ||||
|   testStreamBoth: { | ||||
|     path: '/test.TestService/TestStreamBoth', | ||||
|     requestStream: true, | ||||
|     responseStream: true, | ||||
|     requestType: pbFile.TestStreamBothRequest, | ||||
|     responseType: pbFile.TestStreamBothReply, | ||||
|     requestSerialize: serialize_test_TestStreamBothRequest, | ||||
|     requestDeserialize: deserialize_test_TestStreamBothRequest, | ||||
|     responseSerialize: serialize_test_TestStreamBothReply, | ||||
|     responseDeserialize: deserialize_test_TestStreamBothReply, | ||||
|   }, | ||||
|    | ||||
| } | ||||
|  | ||||
| export const TestServiceClient = grpc.makeGenericClientConstructor(TestServiceService) | ||||
							
								
								
									
										43
									
								
								examples/flow/protos/test.proto
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								examples/flow/protos/test.proto
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| syntax = "proto3"; | ||||
|  | ||||
| package test; | ||||
|  | ||||
| option go_package = "github.com/united-drivers/models/go/test;testpb"; | ||||
|  | ||||
| service TestService { | ||||
|   rpc TestNoStream(TestNoStreamRequest) returns (TestNoStreamReply); | ||||
|   rpc TestStreamRequest(stream TestStreamRequestRequest) returns (TestStreamRequestReply); | ||||
|   rpc TestStreamReply(TestStreamReplyRequest) returns (stream TestStreamReplyReply); | ||||
|   rpc TestStreamBoth(stream TestStreamBothRequest) returns (stream TestStreamBothReply); | ||||
| } | ||||
|  | ||||
| enum TestEnum { | ||||
|   ELEMENT_A = 0; | ||||
|   ELEMENT_B = 1; | ||||
| } | ||||
|  | ||||
| message TestMessage { | ||||
|   string a = 1; | ||||
|   int32 b = 2; | ||||
|   int64 c = 3; | ||||
|   float d = 4; | ||||
|   double e = 5; | ||||
|   repeated string n = 14; | ||||
|   repeated int32 o = 15; | ||||
|   repeated int64 p = 16; | ||||
|   repeated float q = 17; | ||||
|   repeated double r = 18; | ||||
|   enum s { | ||||
|     ELEMENT_C = 0; | ||||
|     ELEMENT_D = 1; | ||||
|   } | ||||
| } | ||||
|  | ||||
| message TestNoStreamRequest { TestMessage message = 1; } | ||||
| message TestNoStreamReply   { TestMessage message = 1; string err_msg = 2; } | ||||
| message TestStreamRequestRequest { TestMessage message = 1; } | ||||
| message TestStreamRequestReply   { TestMessage message = 1; string err_msg = 2; } | ||||
| message TestStreamReplyRequest { TestMessage message = 1; } | ||||
| message TestStreamReplyReply   { TestMessage message = 1; string err_msg = 2; } | ||||
| message TestStreamBothRequest { TestMessage message = 1; } | ||||
| message TestStreamBothReply   { TestMessage message = 1; string err_msg = 2; } | ||||
| @@ -0,0 +1,57 @@ | ||||
| // @flow | ||||
| // GENERATED CODE -- DO NOT EDIT! | ||||
| {{$Package:=.File.Package}} | ||||
| import grpc from 'grpc' | ||||
| import pbFile from './pbFile.js' | ||||
| {{range .File.EnumType}}type {{.Name}} = {{range .Value}} | ||||
|   | '{{.Name}}'{{end}} | ||||
| ;{{end}} | ||||
| {{range .File.MessageType}} | ||||
| type {{.Name}} = {|{{range .Field}} | ||||
|   {{.Name}}?: {{. | jsType}};{{end}}{{range .EnumType}} | ||||
|   {{.Name}}?:{{range .Value}} | ||||
|     | '{{.Name}}'{{end}} | ||||
|   ;{{end}} | ||||
| |}; | ||||
| {{end}} | ||||
| {{range .File.Service}}{{range .Method}} | ||||
| function serialize_{{$Package}}_{{.InputType | shortType}}(arg: {{.InputType | shortType}}) { | ||||
|   if (!(arg instanceof pbFile.{{.InputType | shortType}})) { | ||||
|     throw new Error('Expected argument of type {{.InputType | shortType}}') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_{{$Package}}_{{.InputType | shortType}}(buffer_arg: Array<number>) { | ||||
|   return pbFile.{{.InputType | shortType}}.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
|  | ||||
| function serialize_{{$Package}}_{{.OutputType | shortType}}(arg: {{.OutputType | shortType}}) { | ||||
|   if (!(arg instanceof pbFile.{{.OutputType | shortType}})) { | ||||
|     throw new Error('Expected argument of type {{.OutputType | shortType}}') | ||||
|   } | ||||
|   return new Buffer(arg.serializeBinary()) | ||||
| } | ||||
|  | ||||
| function deserialize_{{$Package}}_{{.OutputType | shortType}}(buffer_arg: Array<number>) { | ||||
|   return pbFile.{{.OutputType | shortType}}.deserializeBinary(new Uint8Array(buffer_arg)) | ||||
| } | ||||
| {{end}}{{end}} | ||||
| {{range .File.Service}} | ||||
| export const {{.Name}}Service = { | ||||
|   {{$serviceName:=.Name}} | ||||
|   {{range .Method}}{{.Name | lowerCamelCase}}: { | ||||
|     path: '/{{$Package}}.{{$serviceName}}/{{.Name}}', | ||||
|     requestStream: {{.ClientStreaming | default "false"}}, | ||||
|     responseStream: {{.ServerStreaming | default "false"}}, | ||||
|     requestType: pbFile.{{.InputType | shortType}}, | ||||
|     responseType: pbFile.{{.OutputType | shortType}}, | ||||
|     requestSerialize: serialize_{{$Package}}_{{.InputType | shortType}}, | ||||
|     requestDeserialize: deserialize_{{$Package}}_{{.InputType | shortType}}, | ||||
|     responseSerialize: serialize_{{$Package}}_{{.OutputType | shortType}}, | ||||
|     responseDeserialize: deserialize_{{$Package}}_{{.OutputType | shortType}}, | ||||
|   }, | ||||
|   {{end}} | ||||
| } | ||||
|  | ||||
| export const {{.Name}}Client = grpc.makeGenericClientConstructor({{.Name}}Service){{end}} | ||||
		Reference in New Issue
	
	Block a user