2017-01-05 20:06:24 +03:00
|
|
|
// @flow
|
2016-12-13 21:10:02 +03:00
|
|
|
// GENERATED CODE -- DO NOT EDIT!
|
2017-01-11 17:20:01 +03:00
|
|
|
|
|
|
|
{{- $Package:=.File.Package}}
|
|
|
|
|
2017-01-11 16:52:00 +03:00
|
|
|
import base64 from 'base64-js'
|
2017-01-11 17:20:01 +03:00
|
|
|
import {{$Package}}_pb from './{{$Package}}_pb'
|
|
|
|
|
|
|
|
{{- range .File.Dependency}}
|
|
|
|
import {{. | replace "/" "_" | trimSuffix ".proto" }}_pb from '../{{. | trimSuffix ".proto" }}_pb'
|
|
|
|
{{- end}}
|
2017-01-10 13:22:18 +03:00
|
|
|
|
2017-01-11 18:33:03 +03:00
|
|
|
{{- define "fieldMethods"}}
|
|
|
|
{{- if isFieldRepeated .}}
|
|
|
|
get{{.Name | camelCase}}List?: () => {{. | jsType}};
|
|
|
|
set{{.Name | camelCase}}List?: ({{.Name}}: {{. | jsType}}) => void;
|
|
|
|
add{{.Name | camelCase}}?: ({{.Name}}: {{. | jsType | trimPrefix "Array<" | trimSuffix ">"}}) => void;
|
|
|
|
clear{{.Name | camelCase}}List?: () => void;
|
|
|
|
{{- else}}
|
|
|
|
get{{.Name | camelCase}}?: () => {{. | jsType}};
|
|
|
|
set{{.Name | camelCase}}?: ({{.Name}}: {{. | jsType}}) => void;
|
|
|
|
|
|
|
|
{{- if isFieldMessage .}}
|
|
|
|
clear{{.Name | camelCase}}?: () => void;
|
|
|
|
has{{.Name | camelCase}}?: () => boolean;
|
|
|
|
{{- end}}
|
|
|
|
{{- end}}
|
|
|
|
{{- end}}
|
|
|
|
|
2017-01-06 13:41:42 +03:00
|
|
|
{{range .File.EnumType}}
|
2017-01-11 17:39:51 +03:00
|
|
|
export type {{.Name}} = {|
|
2017-01-11 17:20:01 +03:00
|
|
|
{{- range .Value}}
|
2017-01-11 18:33:03 +03:00
|
|
|
{{.Name}}?: {{.Number}};
|
2017-01-11 17:20:01 +03:00
|
|
|
{{- end}}
|
2017-01-11 17:39:51 +03:00
|
|
|
|};
|
2017-01-11 17:20:01 +03:00
|
|
|
{{- end}}
|
|
|
|
|
|
|
|
{{- range .File.MessageType}}
|
|
|
|
{{- $MessageType := .Name}}
|
2017-01-10 13:22:18 +03:00
|
|
|
|
|
|
|
{{range .EnumType}}
|
2017-01-11 17:39:51 +03:00
|
|
|
export type {{$MessageType}}${{.Name}} = {|
|
2017-01-11 17:20:01 +03:00
|
|
|
{{- range .Value}}
|
2017-01-11 18:33:03 +03:00
|
|
|
{{.Name}}?: {{.Number}};
|
2017-01-11 17:20:01 +03:00
|
|
|
{{- end}}
|
2017-01-11 17:39:51 +03:00
|
|
|
|};
|
2017-01-11 17:20:01 +03:00
|
|
|
{{- end}}
|
|
|
|
|
2017-01-10 13:22:18 +03:00
|
|
|
{{range .NestedType}}
|
2017-01-11 17:20:01 +03:00
|
|
|
export type {{$MessageType}}${{.Name}} = {
|
|
|
|
{{- range .Field}}
|
2017-01-11 18:33:03 +03:00
|
|
|
{{- template "fieldMethods" .}}
|
2017-01-11 17:20:01 +03:00
|
|
|
{{- end}}
|
|
|
|
};
|
|
|
|
{{- end}}
|
|
|
|
|
|
|
|
export type {{.Name}} = {
|
|
|
|
{{- range .Field}}
|
2017-01-11 18:33:03 +03:00
|
|
|
{{- template "fieldMethods" .}}
|
2017-01-11 17:20:01 +03:00
|
|
|
{{- end}}
|
|
|
|
};
|
|
|
|
|
|
|
|
{{- end}}
|
2017-01-10 13:22:18 +03:00
|
|
|
|
2017-01-11 16:52:00 +03:00
|
|
|
const serializeToBase64 = (byteArray: Uint8Array): string => base64.fromByteArray(byteArray)
|
|
|
|
const deserializeFromBase64 = (base64Encoded: string): Uint8Array => new Uint8Array(base64.toByteArray(base64Encoded))
|
|
|
|
|
2016-12-19 17:21:28 +03:00
|
|
|
{{range .File.Service}}{{range .Method}}
|
2017-01-11 16:52:00 +03:00
|
|
|
function serialize_{{$Package}}_{{.InputType | shortType}}(arg : {{.InputType | shortType}}): string {
|
|
|
|
if (!(arg instanceof {{$Package}}_pb.{{.InputType | shortType}})) {
|
2017-01-05 20:06:24 +03:00
|
|
|
throw new Error('Expected argument of type {{.InputType | shortType}}')
|
2016-12-16 18:08:37 +03:00
|
|
|
}
|
2017-01-11 16:52:00 +03:00
|
|
|
return serializeToBase64(arg.serializeBinary())
|
2016-12-13 21:10:02 +03:00
|
|
|
}
|
|
|
|
|
2017-01-11 16:52:00 +03:00
|
|
|
function deserialize_{{$Package}}_{{.InputType | shortType}}(base64Encoded: string): {{.InputType | shortType}} {
|
|
|
|
return {{$Package}}_pb.{{.InputType | shortType}}.deserializeBinary(deserializeFromBase64(base64Encoded))
|
2016-12-13 21:10:02 +03:00
|
|
|
}
|
|
|
|
|
2017-01-11 16:52:00 +03:00
|
|
|
function serialize_{{$Package}}_{{.OutputType | shortType}}(arg : {{.OutputType | shortType}}): string {
|
|
|
|
if (!(arg instanceof {{$Package}}_pb.{{.OutputType | shortType}})) {
|
2017-01-05 20:06:24 +03:00
|
|
|
throw new Error('Expected argument of type {{.OutputType | shortType}}')
|
2016-12-16 18:08:37 +03:00
|
|
|
}
|
2017-01-11 16:52:00 +03:00
|
|
|
return serializeToBase64(arg.serializeBinary())
|
2016-12-13 21:10:02 +03:00
|
|
|
}
|
|
|
|
|
2017-01-11 16:52:00 +03:00
|
|
|
function deserialize_{{$Package}}_{{.OutputType | shortType}}(base64Encoded: string): {{.OutputType | shortType}} {
|
|
|
|
return {{$Package}}_pb.{{.OutputType | shortType}}.deserializeBinary(deserializeFromBase64(base64Encoded))
|
2016-12-20 13:31:46 +03:00
|
|
|
}
|
2017-01-11 16:52:00 +03:00
|
|
|
|
2016-12-20 13:31:46 +03:00
|
|
|
{{end}}{{end}}
|
2017-01-11 16:52:00 +03:00
|
|
|
export default {
|
|
|
|
{{range .File.Service}}
|
|
|
|
{{.Name}}: {
|
2016-12-20 13:31:46 +03:00
|
|
|
{{$serviceName:=.Name}}
|
2017-01-11 16:52:00 +03:00
|
|
|
{{range .Method}}{{.Name | lowerCamelCase}}: {
|
|
|
|
path: '/{{$Package}}.{{$serviceName}}/{{.Name}}',
|
|
|
|
requestStream: {{.ClientStreaming | default "false"}},
|
|
|
|
responseStream: {{.ServerStreaming | default "false"}},
|
|
|
|
requestType: {{$Package}}_pb.{{.InputType | shortType}},
|
|
|
|
responseType: {{$Package}}_pb.{{.OutputType | shortType}},
|
|
|
|
requestSerialize: serialize_{{$Package}}_{{.InputType | shortType}},
|
|
|
|
requestDeserialize: deserialize_{{$Package}}_{{.InputType | shortType}},
|
|
|
|
responseSerialize: serialize_{{$Package}}_{{.OutputType | shortType}},
|
|
|
|
responseDeserialize: deserialize_{{$Package}}_{{.OutputType | shortType}},
|
|
|
|
},
|
|
|
|
{{end}}
|
|
|
|
}
|
2016-12-20 13:31:46 +03:00
|
|
|
{{end}}
|
2016-12-16 18:08:37 +03:00
|
|
|
}
|