Skip to content

Commit

Permalink
feat(js): generate enums from .proto
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Louvigny committed Nov 22, 2018
1 parent b6a31c4 commit 1ec7901
Show file tree
Hide file tree
Showing 10 changed files with 604 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -50,7 +50,7 @@ jobs:

generate:
docker:
- image: bertychat/protoc:v3
- image: bertychat/protoc:v4
working_directory: /go/src/berty.tech
environment:
GOPATH: /go
Expand Down
7 changes: 4 additions & 3 deletions build/docker/protoc/Dockerfile
Expand Up @@ -13,17 +13,18 @@ RUN go get -u -v \
moul.io/protoc-gen-gotemplate \
golang.org/x/tools/cmd/goimports \
github.com/99designs/gqlgen \
github.com/99designs/gorunpkg \
github.com/vektah/gorunpkg \
github.com/spf13/cobra

RUN cd /go/src/github.com/99designs/gqlgen && git checkout v0.6.0 && go install github.com/99designs/gqlgen
RUN rm -f /go/bin/web-editor

FROM golang:1.11-alpine
RUN apk --no-cache add git make protobuf gcc libc-dev && mkdir -p /.cache/go-build && chmod -R 777 /.cache
RUN apk --no-cache add git make protobuf gcc libc-dev nodejs-npm && mkdir -p /.cache/go-build && chmod -R 777 /.cache
RUN mkdir -p /node/ && cd /node && npm install -g prettier prettier-eslint prettier-eslint-cli
COPY --from=pgg /go/bin/* /go/bin/
COPY --from=builder /go/bin/* /go/bin/
COPY --from=pgg /protobuf /protobuf
ENV GOPATH=/go \
PATH=/go/bin:${PATH} \
PATH=/go/bin:/node/node_modules/.bin:${PATH} \
GOROOT=/usr/local/go
2 changes: 1 addition & 1 deletion build/docker/protoc/Makefile
@@ -1,4 +1,4 @@
IMAGE ?= bertychat/protoc:v3
IMAGE ?= bertychat/protoc:v4

build:
docker build --pull -t $(IMAGE) .
Expand Down
Expand Up @@ -14,7 +14,7 @@ import {
import { Pagination } from '../../../../relay'
import { borderBottom, marginLeft, padding } from '../../../../styles'
import { colors } from '../../../../constants'
import { fragments, mutations, queries } from '../../../../graphql'
import { fragments, mutations, queries, enums } from '../../../../graphql'
import Button from '../../../Library/Button'

const Item = fragments.Event(({ data, navigation }) => (
Expand Down Expand Up @@ -51,8 +51,8 @@ const Item = fragments.Event(({ data, navigation }) => (
2: <Icon name={'phone-outgoing'} color={colors.purple} />,
}[data.direction]
}{' '}
<Text style={{ fontWeight: 'bold' }}>Kind</Text>
{' ' + data.kind}
<Text style={{ fontWeight: 'bold' }}>{enums.ValueBertyP2pKindInputKind[data.kind]}</Text>
{' (' + data.kind + ')'}
</Text>
<Text
ellipsizeMode='tail'
Expand Down
247 changes: 247 additions & 0 deletions client/react-native/common/graphql/enums.gen.js
@@ -0,0 +1,247 @@
// GENERATED CODE -- DO NOT EDIT!

export const GoogleProtobufFieldDescriptorProtoInputType = {
TYPE_DOUBLE: 1,
TYPE_FLOAT: 2,
TYPE_INT64: 3,
TYPE_UINT64: 4,
TYPE_INT32: 5,
TYPE_FIXED64: 6,
TYPE_FIXED32: 7,
TYPE_BOOL: 8,
TYPE_STRING: 9,
TYPE_GROUP: 10,
TYPE_MESSAGE: 11,
TYPE_BYTES: 12,
TYPE_UINT32: 13,
TYPE_ENUM: 14,
TYPE_SFIXED32: 15,
TYPE_SFIXED64: 16,
TYPE_SINT32: 17,
TYPE_SINT64: 18,
}

export const ValueGoogleProtobufFieldDescriptorProtoInputType = {
1: 'TYPE_DOUBLE',
2: 'TYPE_FLOAT',
3: 'TYPE_INT64',
4: 'TYPE_UINT64',
5: 'TYPE_INT32',
6: 'TYPE_FIXED64',
7: 'TYPE_FIXED32',
8: 'TYPE_BOOL',
9: 'TYPE_STRING',
10: 'TYPE_GROUP',
11: 'TYPE_MESSAGE',
12: 'TYPE_BYTES',
13: 'TYPE_UINT32',
14: 'TYPE_ENUM',
15: 'TYPE_SFIXED32',
16: 'TYPE_SFIXED64',
17: 'TYPE_SINT32',
18: 'TYPE_SINT64',
}

export const GoogleProtobufFieldDescriptorProtoInputLabel = {
LABEL_OPTIONAL: 1,
LABEL_REQUIRED: 2,
LABEL_REPEATED: 3,
}

export const ValueGoogleProtobufFieldDescriptorProtoInputLabel = {
1: 'LABEL_OPTIONAL',
2: 'LABEL_REQUIRED',
3: 'LABEL_REPEATED',
}

export const GoogleProtobufFileOptionsInputOptimizeMode = {
SPEED: 1,
CODE_SIZE: 2,
LITE_RUNTIME: 3,
}

export const ValueGoogleProtobufFileOptionsInputOptimizeMode = {
1: 'SPEED',
2: 'CODE_SIZE',
3: 'LITE_RUNTIME',
}

export const GoogleProtobufFieldOptionsInputCType = {
STRING: 0,
CORD: 1,
STRING_PIECE: 2,
}

export const ValueGoogleProtobufFieldOptionsInputCType = {
0: 'STRING',
1: 'CORD',
2: 'STRING_PIECE',
}

export const GoogleProtobufFieldOptionsInputJSType = {
JS_NORMAL: 0,
JS_STRING: 1,
JS_NUMBER: 2,
}

export const ValueGoogleProtobufFieldOptionsInputJSType = {
0: 'JS_NORMAL',
1: 'JS_STRING',
2: 'JS_NUMBER',
}

export const GoogleProtobufMethodOptionsInputIdempotencyLevel = {
IDEMPOTENCY_UNKNOWN: 0,
NO_SIDE_EFFECTS: 1,
IDEMPOTENT: 2,
}

export const ValueGoogleProtobufMethodOptionsInputIdempotencyLevel = {
0: 'IDEMPOTENCY_UNKNOWN',
1: 'NO_SIDE_EFFECTS',
2: 'IDEMPOTENT',
}

export const BertyEntityDeviceInputStatus = {
Unknown: 0,
Connected: 1,
Disconnected: 2,
Available: 3,
Myself: 42,
}

export const ValueBertyEntityDeviceInputStatus = {
0: 'Unknown',
1: 'Connected',
2: 'Disconnected',
3: 'Available',
42: 'Myself',
}

export const BertyEntityContactInputStatus = {
Unknown: 0,
IsFriend: 1,
IsTrustedFriend: 2,
IsRequested: 3,
RequestedMe: 4,
IsBlocked: 5,
Myself: 42,
}

export const ValueBertyEntityContactInputStatus = {
0: 'Unknown',
1: 'IsFriend',
2: 'IsTrustedFriend',
3: 'IsRequested',
4: 'RequestedMe',
5: 'IsBlocked',
42: 'Myself',
}

export const BertyEntityConversationMemberInputStatus = {
Unknown: 0,
Owner: 1,
Active: 2,
Blocked: 3,
}

export const ValueBertyEntityConversationMemberInputStatus = {
0: 'Unknown',
1: 'Owner',
2: 'Active',
3: 'Blocked',
}

export const BertyEntitySenderAliasInputStatus = {
UNKNOWN: 0,
SENT: 1,
SENT_AND_ACKED: 2,
RECEIVED: 3,
}

export const ValueBertyEntitySenderAliasInputStatus = {
0: 'UNKNOWN',
1: 'SENT',
2: 'SENT_AND_ACKED',
3: 'RECEIVED',
}

export const BertyP2pKindInputKind = {
Unknown: 0,
Sent: 101,
Ack: 102,
Ping: 103,
ContactRequest: 201,
ContactRequestAccepted: 202,
ContactShareMe: 203,
ContactShare: 204,
ConversationInvite: 301,
ConversationNewMessage: 302,
DevtoolsMapset: 401,
SenderAliasUpdate: 501,
}

export const ValueBertyP2pKindInputKind = {
0: 'Unknown',
101: 'Sent',
102: 'Ack',
103: 'Ping',
201: 'ContactRequest',
202: 'ContactRequestAccepted',
203: 'ContactShareMe',
204: 'ContactShare',
301: 'ConversationInvite',
302: 'ConversationNewMessage',
401: 'DevtoolsMapset',
501: 'SenderAliasUpdate',
}

export const BertyP2pEventInputDirection = {
UnknownDirection: 0,
Incoming: 1,
Outgoing: 2,
}

export const ValueBertyP2pEventInputDirection = {
0: 'UnknownDirection',
1: 'Incoming',
2: 'Outgoing',
}

export const BertyP2pMetricsTypeInputMetricsType = {
PEER: 0,
PROTOCOL: 1,
GLOBAL: 2,
}

export const ValueBertyP2pMetricsTypeInputMetricsType = {
0: 'PEER',
1: 'PROTOCOL',
2: 'GLOBAL',
}

export const BertyP2pConnectionTypeInputConnectionType = {
NOT_CONNECTED: 0,
CONNECTED: 1,
CAN_CONNECT: 2,
CANNOT_CONNECT: 3,
}

export const ValueBertyP2pConnectionTypeInputConnectionType = {
0: 'NOT_CONNECTED',
1: 'CONNECTED',
2: 'CAN_CONNECT',
3: 'CANNOT_CONNECT',
}

export const BertyNodeNullableTrueFalseInputNullableTrueFalse = {
Null: 0,
True: 1,
False: 2,
}

export const ValueBertyNodeNullableTrueFalseInputNullableTrueFalse = {
0: 'Null',
1: 'True',
2: 'False',
}
1 change: 1 addition & 0 deletions client/react-native/common/graphql/index.js
Expand Up @@ -2,3 +2,4 @@ export * as mutations from './mutations'
export * as queries from './queries'
export * as subscriptions from './subscriptions'
export * as fragments from './fragments'
export * as enums from './enums.gen'
9 changes: 6 additions & 3 deletions core/Makefile
Expand Up @@ -15,7 +15,8 @@ GENERATED_FILES = \
api/client/jsonclient/berty.node.service.gen.go \
$(call rwildcard $(CODE_PATHS), *.gen.go) \
api/p2p/kind.gen.go \
api/node/graphql/service.gen.graphql
api/node/graphql/service.gen.graphql \
api/node/graphql/enums.gen.js
CGO_LDFLAGS ?= -L/usr/local/opt/openssl/lib
CGO_CPPFLAGS ?= -I/usr/local/opt/openssl/include
BUILD_ENV ?= GO111MODULE=on CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CPPFLAGS="$(CGO_CPPFLAGS)"
Expand Down Expand Up @@ -98,7 +99,7 @@ generate: .generated
--workdir="/go/src/berty.tech/core" \
--entrypoint="sh" \
--rm \
bertychat/protoc:v3 \
bertychat/protoc:v4 \
-xec 'make generate_local'
touch $@

Expand Down Expand Up @@ -158,9 +159,11 @@ api/p2p/kind.gen.go: $(PROTOS)
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=false,single-package-mode=true,all=true,template_dir=./api/p2p:./api/p2p ./api/p2p/kind.proto
goimports -w ./api/p2p

generate.graphql api/node/graphql/service.gen.graphql: $(PROTOS)
generate.graphql api/node/graphql/service.gen.graphql api/node/graphql/enums.gen.js: $(PROTOS)
mkdir -p ./api/node/graphql
$(PROTOC) $(PROTOC_OPTS) --gotemplate_out=debug=false,all=true,template_dir=./api/node:./api/node/graphql ./api/node/service.proto
goimports -w ./api/node/graphql
cd ./api/node/graphql && $(GQLGEN) -c gqlgen.gen.yml -v gen
cp ./api/node/graphql/service.gen.graphql ../client/react-native/common/schema.graphql
prettier-eslint --trailing-comma all --single-quote --no-semi --write ./api/node/graphql/enums.gen.js
cp ./api/node/graphql/enums.gen.js ../client/react-native/common/graphql/enums.gen.js

0 comments on commit 1ec7901

Please sign in to comment.