From b3b9aec439a0a96a480c8653328058235b3aa8d7 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Wed, 11 Jan 2017 15:20:01 +0100 Subject: [PATCH] Update example, remove strict types --- examples/flow/output/test/test_grpc_js.js | 135 +++++++++--------- .../{{.File.Package}}_grpc_js.js.tmpl | 59 +++++--- 2 files changed, 106 insertions(+), 88 deletions(-) diff --git a/examples/flow/output/test/test_grpc_js.js b/examples/flow/output/test/test_grpc_js.js index 460dcb4..cef1073 100644 --- a/examples/flow/output/test/test_grpc_js.js +++ b/examples/flow/output/test/test_grpc_js.js @@ -5,108 +5,109 @@ import base64 from 'base64-js' import test_pb from './test_pb' -export type TestEnum = {| - ELEMENT_A?: 0; - ELEMENT_B?: 1; -|}; +export type TestEnum = { + ELEMENT_A?: 0; + ELEMENT_B?: 1; +}; + + +export type TestMessage$TestNestedEnum = { + ELEMENT_C?: 0; + ELEMENT_D?: 1; +}; + + +export type TestMessage$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; + u?: TestEnum; + v?: TestMessage$TestNestedEnum; + w?: Array; +}; -export type TestMessage$TestNestedEnum = {| - ELEMENT_C?: 0; - ELEMENT_D?: 1; -|}; - - -export type TestMessage$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; - u?: TestEnum; - v?: TestMessage$TestNestedEnum; - w?: Array; -|}; +export type TestNoStreamRequest = { + message?: TestMessage; +}; -export type TestNoStreamRequest = {| - message?: TestMessage; -|}; + +export type TestNoStreamReply = { + message?: TestMessage; + err_msg?: string; +}; -export type TestNoStreamReply = {| - message?: TestMessage; - err_msg?: string; -|}; + +export type TestStreamRequestRequest = { + message?: TestMessage; +}; -export type TestStreamRequestRequest = {| - message?: TestMessage; -|}; + +export type TestStreamRequestReply = { + message?: TestMessage; + err_msg?: string; +}; -export type TestStreamRequestReply = {| - message?: TestMessage; - err_msg?: string; -|}; + +export type TestStreamReplyRequest = { + message?: TestMessage; +}; -export type TestStreamReplyRequest = {| - message?: TestMessage; -|}; + +export type TestStreamReplyReply = { + message?: TestMessage; + err_msg?: string; +}; -export type TestStreamReplyReply = {| - message?: TestMessage; - err_msg?: string; -|}; + +export type TestStreamBothRequest = { + message?: TestMessage; +}; -export type TestStreamBothRequest = {| - message?: TestMessage; -|}; +export type TestStreamBothReply = { + message?: TestMessage; + err_msg?: string; +}; - - -export type TestStreamBothReply = {| - message?: TestMessage; - err_msg?: string; -|}; - - -const serializeToBase64 = (byteArray: Uint8Array): string => - base64.fromByteArray(byteArray) - -const deserializeFromBase64 = (base64Encoded: string): Uint8Array => - new Uint8Array(base64.toByteArray(base64Encoded)) +const serializeToBase64 = (byteArray: Uint8Array): string => base64.fromByteArray(byteArray) +const deserializeFromBase64 = (base64Encoded: string): Uint8Array => new Uint8Array(base64.toByteArray(base64Encoded)) function serialize_test_TestNoStreamRequest(arg : TestNoStreamRequest): string { 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 580ed35..376c519 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 @@ -1,32 +1,49 @@ // @flow // GENERATED CODE -- DO NOT EDIT! -{{$Package:=.File.Package}} + +{{- $Package:=.File.Package}} + import base64 from 'base64-js' -import {{$Package}}_pb from './{{$Package}}_pb'{{range .File.Dependency}} -import {{. | replace "/" "_" | trimSuffix ".proto" }}_pb from '../{{. | trimSuffix ".proto" }}_pb'{{end}} +import {{$Package}}_pb from './{{$Package}}_pb' + +{{- range .File.Dependency}} +import {{. | replace "/" "_" | trimSuffix ".proto" }}_pb from '../{{. | trimSuffix ".proto" }}_pb' +{{- end}} {{range .File.EnumType}} -export type {{.Name}} = {|{{range .Value}} - {{.Name}}?: {{.Number}};{{end}} -|}; -{{end}} +export type {{.Name}} = { + {{- range .Value}} + {{.Name}}?: {{.Number}}; + {{- end}} +}; +{{- end}} + +{{- range .File.MessageType}} +{{- $MessageType := .Name}} -{{range .File.MessageType}} -{{$MessageType := .Name}} {{range .EnumType}} -export type {{$MessageType}}${{.Name}} = {|{{range .Value}} - {{.Name}}?: {{.Number}};{{end}} -|}; -{{end}} +export type {{$MessageType}}${{.Name}} = { + {{- range .Value}} + {{.Name}}?: {{.Number}}; + {{- end}} +}; +{{- end}} + {{range .NestedType}} -export type {{$MessageType}}${{.Name}} = {|{{range .Field}} - {{.Name}}?: {{. | jsType}};{{end}} -|}; -{{end}} -export type {{.Name}} = {|{{range .Field}} - {{.Name}}?: {{. | jsType}};{{end}} -|}; -{{end}} +export type {{$MessageType}}${{.Name}} = { + {{- range .Field}} + {{.Name}}?: {{. | jsType}}; + {{- end}} +}; +{{- end}} + +export type {{.Name}} = { + {{- range .Field}} + {{.Name}}?: {{. | jsType}}; + {{- end}} +}; + +{{- end}} const serializeToBase64 = (byteArray: Uint8Array): string => base64.fromByteArray(byteArray) const deserializeFromBase64 = (base64Encoded: string): Uint8Array => new Uint8Array(base64.toByteArray(base64Encoded))