Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial grpc proxy server project #1012

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) 2021 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)
})
})
})
Loading