Skip to content

Commit

Permalink
Log requests by client (#1)
Browse files Browse the repository at this point in the history
* Add logger to generated client
  • Loading branch information
kirpichenko authored Mar 6, 2020
1 parent b3a41cc commit 2813da2
Show file tree
Hide file tree
Showing 20 changed files with 2,426 additions and 2,836 deletions.
4 changes: 2 additions & 2 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"strings"
"unicode"

"github.com/antonversal/protoc-gen-ts/base"
"github.com/golang/protobuf/proto"
google_protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
gen "github.com/golang/protobuf/protoc-gen-go/generator"
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
"github.com/join-com/protoc-gen-ts/base"
)

type generator struct {
Expand Down Expand Up @@ -650,7 +650,7 @@ func (g *generator) generateClient(service *google_protobuf.ServiceDescriptorPro
}
g.P(fmt.Sprintf("export class %sClient extends grpcts.Client {", gen.CamelCase(*service.Name)))
g.P("constructor(address: string, credentials?: grpcts.grpc.ChannelCredentials, trace: grpcts.ClientTrace = nodeTrace, options?: object){")
g.P(fmt.Sprintf("super(%sServiceDefinition, address, credentials, trace, options);", g.toLowerFirst(*service.Name)))
g.P(fmt.Sprintf("super(%sServiceDefinition, address, credentials, trace, options, logger);", g.toLowerFirst(*service.Name)))
g.P("}")
for _, method := range service.Method {
inputTypeName := g.getTsTypeFromMessage(method.InputType, true)
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/join-com/protoc-gen-ts

go 1.14

require github.com/golang/protobuf v1.3.4
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"semi": true,
"semi": false,
"singleQuote": true,
"parser": "typescript"
}
33 changes: 4 additions & 29 deletions integrationTests/__tests__/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ describe('decode', () => {
})

describe('timestamp', () => {
it(`encodes timestamp`, () => {
it('encodes timestamp', () => {
expect(decoded.timestamp).toBeDefined()
expect(decoded.timestamp).toEqual(new Date('2014-11-01T12:24:33.123'))
})

it(`encodes timestampRepeated`, () => {
it('encodes timestampRepeated', () => {
expect(decoded.timestampRepeated).toBeDefined()
expect(decoded.timestampRepeated).toEqual([
new Date('2014-02-26T12:00:00.234'),
Expand All @@ -110,43 +110,18 @@ describe('decode', () => {
})

describe('fieldFloat', () => {
it(`encodes fieldFloat`, () => {
it('encodes fieldFloat', () => {
expect(decoded.fieldFloat).toBeDefined()
expect(parseFloat(decoded.fieldFloat)).toEqual(
Math.fround(values.fieldFloat)
)
})

it(`encodes fieldFloatRepeated`, () => {
it('encodes fieldFloatRepeated', () => {
expect(decoded.fieldFloatRepeated).toBeDefined()
expect(decoded.fieldFloatRepeated).toEqual(
values.fieldFloatRepeated.map(Math.fround)
)
})
})
})

describe('decode changed protos', () => {
const root = loadSync(path.join(__dirname, 'protoBefore', 'test.proto'))
const PbTest = root.lookupType('foo.Test')
let buffer: Uint8Array
let decoded: any
const values = {
...baseValues,
fieldEnumRepeated: ['EXECUTE', 'VIEW'],
fieldString2: 'test2',
fieldString3: 'test3'
}

beforeEach(() => {
const message = PbTest.fromObject(values)
buffer = PbTest.encode(message).finish()
decoded = Foo.Test.decode(buffer)
})

it('ignores missing field', () => {
expect(decoded.fieldEnumRepeated).toEqual(['VIEW'])
expect(decoded.fieldString2).not.toBeDefined()
expect(decoded.fieldString3).not.toBeDefined()
})
})
8 changes: 4 additions & 4 deletions integrationTests/__tests__/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ describe('encode', () => {
(timestamp.seconds || 0) * 1000 + (timestamp.nanos || 0) / 1000000
)

it(`encodes timestamp`, () => {
it('encodes timestamp', () => {
expect(decoded.timestamp).toBeDefined()
expect(toDate(decoded.timestamp)).toEqual(values.timestamp)
})

it(`encodes timestampRepeated`, () => {
it('encodes timestampRepeated', () => {
expect(decoded.timestampRepeated).toBeDefined()
expect(decoded.timestampRepeated.map(toDate)).toEqual(
values.timestampRepeated
Expand All @@ -122,14 +122,14 @@ describe('encode', () => {
})

describe('fieldFloat', () => {
it(`encodes fieldFloat`, () => {
it('encodes fieldFloat', () => {
expect(decoded.fieldFloat).toBeDefined()
expect(parseFloat(decoded.fieldFloat)).toEqual(
Math.fround(values.fieldFloat!)
)
})

it(`encodes fieldFloatRepeated`, () => {
it('encodes fieldFloatRepeated', () => {
expect(decoded.fieldFloatRepeated).toBeDefined()
expect(decoded.fieldFloatRepeated).toEqual(
values.fieldFloatRepeated!.map(Math.fround)
Expand Down
Loading

0 comments on commit 2813da2

Please sign in to comment.