Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
build: adopt changes to generator formatting (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Apr 22, 2020
1 parent 3afe642 commit 0284c22
Show file tree
Hide file tree
Showing 9 changed files with 432 additions and 345 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
- run: node --version
- run: npm install
- run: npm test
- name: coverage
uses: codecov/codecov-action@v1
with:
name: actions ${{ matrix.node }}
fail_ci_if_error: true
windows:
runs-on: windows-latest
steps:
Expand All @@ -27,6 +32,11 @@ jobs:
node-version: 12
- run: npm install
- run: npm test
- name: coverage
uses: codecov/codecov-action@v1
with:
name: actions windows
fail_ci_if_error: true
lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -45,13 +55,3 @@ jobs:
node-version: 12
- run: npm install
- run: npm run docs-test
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 13
- run: npm install
- run: npm test
- run: ./node_modules/.bin/c8 report --reporter=text-lcov | npx codecovorg -a ${{ secrets.CODECOV_API_KEY }} -r $GITHUB_REPOSITORY --pipe
234 changes: 117 additions & 117 deletions protos/protos.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ const SpeechTranslationServiceClient = v1beta1.SpeechTranslationServiceClient;
export {v1beta1, SpeechTranslationServiceClient};
export default {v1beta1, SpeechTranslationServiceClient};
import * as protos from '../protos/protos';
export {protos}
export {protos};
123 changes: 70 additions & 53 deletions src/v1beta1/speech_translation_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export class SpeechTranslationServiceClient {
private _protos: {};
private _defaults: {[method: string]: gax.CallSettings};
auth: gax.GoogleAuth;
descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}, batching: {}};
descriptors: Descriptors = {
page: {},
stream: {},
longrunning: {},
batching: {},
};
innerApiCalls: {[name: string]: Function};
speechTranslationServiceStub?: Promise<{[name: string]: Function}>;

Expand Down Expand Up @@ -70,11 +75,14 @@ export class SpeechTranslationServiceClient {

constructor(opts?: ClientOptions) {
// Ensure that options include the service address and port.
const staticMembers = this.constructor as typeof SpeechTranslationServiceClient;
const servicePath = opts && opts.servicePath ?
opts.servicePath :
((opts && opts.apiEndpoint) ? opts.apiEndpoint :
staticMembers.servicePath);
const staticMembers = this
.constructor as typeof SpeechTranslationServiceClient;
const servicePath =
opts && opts.servicePath
? opts.servicePath
: opts && opts.apiEndpoint
? opts.apiEndpoint
: staticMembers.servicePath;
const port = opts && opts.port ? opts.port : staticMembers.port;

if (!opts) {
Expand All @@ -84,8 +92,8 @@ export class SpeechTranslationServiceClient {
opts.port = opts.port || port;
opts.clientConfig = opts.clientConfig || {};

const isBrowser = (typeof window !== 'undefined');
if (isBrowser){
const isBrowser = typeof window !== 'undefined';
if (isBrowser) {
opts.fallback = true;
}
// If we are in browser, we are already using fallback because of the
Expand All @@ -95,20 +103,18 @@ export class SpeechTranslationServiceClient {

// Create a `gaxGrpc` object, with any grpc-specific options
// sent to the client.
opts.scopes = (this.constructor as typeof SpeechTranslationServiceClient).scopes;
opts.scopes = (this
.constructor as typeof SpeechTranslationServiceClient).scopes;
this._gaxGrpc = new this._gaxModule.GrpcClient(opts);

// Save options to use in initialize() method.
this._opts = opts;

// Save the auth object to the client, for use by other methods.
this.auth = (this._gaxGrpc.auth as gax.GoogleAuth);
this.auth = this._gaxGrpc.auth as gax.GoogleAuth;

// Determine the client header string.
const clientHeader = [
`gax/${this._gaxModule.version}`,
`gapic/${version}`,
];
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
if (typeof process !== 'undefined' && 'versions' in process) {
clientHeader.push(`gl-node/${process.versions.node}`);
} else {
Expand All @@ -124,24 +130,35 @@ export class SpeechTranslationServiceClient {
// For Node.js, pass the path to JSON proto file.
// For browsers, pass the JSON content.

const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json');
const nodejsProtoPath = path.join(
__dirname,
'..',
'..',
'protos',
'protos.json'
);
this._protos = this._gaxGrpc.loadProto(
opts.fallback ?
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("../../protos/protos.json") :
nodejsProtoPath
opts.fallback
? // eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../protos/protos.json')
: nodejsProtoPath
);

// Some of the methods on this service provide streaming responses.
// Provide descriptors for these.
this.descriptors.stream = {
streamingTranslateSpeech: new this._gaxModule.StreamDescriptor(gax.StreamType.BIDI_STREAMING)
streamingTranslateSpeech: new this._gaxModule.StreamDescriptor(
gax.StreamType.BIDI_STREAMING
),
};

// Put together the default options sent with requests.
this._defaults = this._gaxGrpc.constructSettings(
'google.cloud.mediatranslation.v1beta1.SpeechTranslationService', gapicConfig as gax.ClientConfig,
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')});
'google.cloud.mediatranslation.v1beta1.SpeechTranslationService',
gapicConfig as gax.ClientConfig,
opts.clientConfig || {},
{'x-goog-api-client': clientHeader.join(' ')}
);

// Set up a dictionary of "inner API calls"; the core implementation
// of calling the API is handled in `google-gax`, with this code
Expand Down Expand Up @@ -169,16 +186,19 @@ export class SpeechTranslationServiceClient {
// Put together the "service stub" for
// google.cloud.mediatranslation.v1beta1.SpeechTranslationService.
this.speechTranslationServiceStub = this._gaxGrpc.createStub(
this._opts.fallback ?
(this._protos as protobuf.Root).lookupService('google.cloud.mediatranslation.v1beta1.SpeechTranslationService') :
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this._protos as any).google.cloud.mediatranslation.v1beta1.SpeechTranslationService,
this._opts) as Promise<{[method: string]: Function}>;
this._opts.fallback
? (this._protos as protobuf.Root).lookupService(
'google.cloud.mediatranslation.v1beta1.SpeechTranslationService'
)
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
(this._protos as any).google.cloud.mediatranslation.v1beta1
.SpeechTranslationService,
this._opts
) as Promise<{[method: string]: Function}>;

// Iterate over each of the methods that the service provides
// and create an API call method for each.
const speechTranslationServiceStubMethods =
['streamingTranslateSpeech'];
const speechTranslationServiceStubMethods = ['streamingTranslateSpeech'];
for (const methodName of speechTranslationServiceStubMethods) {
const callPromise = this.speechTranslationServiceStub.then(
stub => (...args: Array<{}>) => {
Expand All @@ -188,16 +208,17 @@ export class SpeechTranslationServiceClient {
const func = stub[methodName];
return func.apply(stub, args);
},
(err: Error|null|undefined) => () => {
(err: Error | null | undefined) => () => {
throw err;
});
}
);

const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
this.descriptors.page[methodName] ||
this.descriptors.stream[methodName] ||
this.descriptors.longrunning[methodName]
this.descriptors.stream[methodName] ||
this.descriptors.longrunning[methodName]
);

this.innerApiCalls[methodName] = apiCall;
Expand Down Expand Up @@ -233,9 +254,7 @@ export class SpeechTranslationServiceClient {
* in this service.
*/
static get scopes() {
return [
'https://www.googleapis.com/auth/cloud-platform'
];
return ['https://www.googleapis.com/auth/cloud-platform'];
}

getProjectId(): Promise<string>;
Expand All @@ -245,8 +264,9 @@ export class SpeechTranslationServiceClient {
* @param {function(Error, string)} callback - the callback to
* be called with the current project Id.
*/
getProjectId(callback?: Callback<string, undefined, undefined>):
Promise<string>|void {
getProjectId(
callback?: Callback<string, undefined, undefined>
): Promise<string> | void {
if (callback) {
this.auth.getProjectId(callback);
return;
Expand All @@ -258,25 +278,22 @@ export class SpeechTranslationServiceClient {
// -- Service calls --
// -------------------

/**
* Performs bidirectional streaming speech translation: receive results while
* sending audio. This method is only available via the gRPC API (not REST).
*
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Stream}
* An object stream which is both readable and writable. It accepts objects
* representing [StreamingTranslateSpeechRequest]{@link google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest} for write() method, and
* will emit objects representing [StreamingTranslateSpeechResponse]{@link google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse} on 'data' event asynchronously.
*/
streamingTranslateSpeech(
options?: gax.CallOptions):
gax.CancellableStream {
/**
* Performs bidirectional streaming speech translation: receive results while
* sending audio. This method is only available via the gRPC API (not REST).
*
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Stream}
* An object stream which is both readable and writable. It accepts objects
* representing [StreamingTranslateSpeechRequest]{@link google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest} for write() method, and
* will emit objects representing [StreamingTranslateSpeechResponse]{@link google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse} on 'data' event asynchronously.
*/
streamingTranslateSpeech(options?: gax.CallOptions): gax.CancellableStream {
this.initialize();
return this.innerApiCalls.streamingTranslateSpeech(options);
}


/**
* Terminate the GRPC channel and close the client.
*
Expand Down
8 changes: 4 additions & 4 deletions synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
"git": {
"name": ".",
"remote": "https://github.com/googleapis/nodejs-media-translation.git",
"sha": "901ed15f49ae7dfc047d95a44f1b65a7be0dc934"
"sha": "3afe642f6e6955b49c188e66f29115a5deb8c0f6"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "3028060618e8024af9a32b3ab3456c160091ecb7",
"internalRef": "306450502"
"sha": "42ee97c1b93a0e3759bbba3013da309f670a90ab",
"internalRef": "307114445"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "52638600f387deb98efb5f9c85fec39e82aa9052"
"sha": "19465d3ec5e5acdb01521d8f3bddd311bcbee28d"
}
}
],
Expand Down
1 change: 0 additions & 1 deletion system-test/fixtures/sample/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **


/* eslint-disable node/no-missing-require, no-unused-vars */
const mediatranslation = require('@google-cloud/media-translation');

Expand Down
32 changes: 17 additions & 15 deletions system-test/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,36 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

import { packNTest } from 'pack-n-play';
import { readFileSync } from 'fs';
import { describe, it } from 'mocha';
import {packNTest} from 'pack-n-play';
import {readFileSync} from 'fs';
import {describe, it} from 'mocha';

describe('typescript consumer tests', () => {

it('should have correct type signature for typescript users', async function() {
it('should have correct type signature for typescript users', async function () {
this.timeout(300000);
const options = {
packageDir: process.cwd(), // path to your module.
packageDir: process.cwd(), // path to your module.
sample: {
description: 'typescript based user can use the type definitions',
ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString()
}
ts: readFileSync(
'./system-test/fixtures/sample/src/index.ts'
).toString(),
},
};
await packNTest(options); // will throw upon error.
await packNTest(options); // will throw upon error.
});

it('should have correct type signature for javascript users', async function() {
it('should have correct type signature for javascript users', async function () {
this.timeout(300000);
const options = {
packageDir: process.cwd(), // path to your module.
packageDir: process.cwd(), // path to your module.
sample: {
description: 'typescript based user can use the type definitions',
ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString()
}
ts: readFileSync(
'./system-test/fixtures/sample/src/index.js'
).toString(),
},
};
await packNTest(options); // will throw upon error.
await packNTest(options); // will throw upon error.
});

});
Loading

0 comments on commit 0284c22

Please sign in to comment.