Skip to content

Commit

Permalink
Initial grpc proxy server project
Browse files Browse the repository at this point in the history
  • Loading branch information
bryans99 committed Feb 28, 2022
1 parent 3ae42cd commit f119b79
Show file tree
Hide file tree
Showing 46 changed files with 49,300 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/sdk-codegen-scripts/src/reformatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,28 @@ class GoFormatter extends BaseFormatter {
}
}

class ProtoFormatter extends BaseFormatter {
constructor() {
super('Protobuf')
}

versionStamp() {
return warn('Skipping SDK version updating - not implemented for Protobuf.')
}
}

class GrpcProxyFormatter extends BaseFormatter {
constructor() {
super('Grpc')
}

versionStamp() {
return warn(
'Skipping SDK version updating - not implemented for Grpc proxy.'
)
}
}

type IFormatFiles = { [key: string]: string[] }

type IFormatters = { [key: string]: IReformat }
Expand All @@ -306,6 +328,8 @@ const fileFormatters: IFormatters = {
'.swift': new SwiftFormatter(),
'.ts': new TypescriptFormatter(),
'.go': new GoFormatter(),
'.proto': new ProtoFormatter(),
'.java': new GrpcProxyFormatter(),
}

export class FilesFormatter {
Expand Down
14 changes: 14 additions & 0 deletions packages/sdk-codegen/src/codeGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { SwiftGen } from './swift.gen'
import { PythonGen } from './python.gen'
import { TypescriptGen } from './typescript.gen'
import { GoGen } from './go.gen'
import { ProtoGen } from './proto.gen'
import { GrpcProxyGen } from './grpc_proxy.gen'

export interface IGeneratorSpec {
/** source code file extension regex */
Expand Down Expand Up @@ -101,6 +103,18 @@ export const Generators: Array<IGeneratorSpec> = [
options: '-papiPackage=Looker -ppackageName=looker',
extension: /\.php/gi,
},
{
factory: (api: ApiModel, versions?: IVersionInfo) =>
new ProtoGen(api, versions),
language: 'Protobuf',
extension: /\.proto/gi,
},
{
factory: (api: ApiModel, versions?: IVersionInfo) =>
new GrpcProxyGen(api, versions),
language: 'GrpcProxy',
extension: /\.java/gi,
},
// {
// language: 'R',
// legacy: 'r'
Expand Down
52 changes: 52 additions & 0 deletions packages/sdk-codegen/src/grpc_proxy.gen.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
MIT License
Copyright (c) 2020 Looker Data Sciences, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import { TestConfig } from './testUtils'
import { GrpcProxyGen } from './grpc_proxy.gen'

const config = TestConfig()
const apiTestModel = config.apiTestModel

const gen = new GrpcProxyGen(apiTestModel)

describe('pseudocode', () => {
describe('method signature', () => {
it('optional body and additional param', () => {
const method = apiTestModel.methods.create_user_credentials_email
expect(method).toBeDefined()
const expected = `create_user_credentials_email(user_id, body, fields): CredentialsEmail`
const actual = gen.methodSignature('', method)
expect(actual).toEqual(expected)
})
it('no params', () => {
const method = apiTestModel.methods.all_datagroups
expect(method).toBeDefined()
const expected = `all_datagroups(): Datagroup[]`
const actual = gen.methodSignature('', method)
expect(actual).toEqual(expected)
})
})
})

0 comments on commit f119b79

Please sign in to comment.