From a51fab181de49dcdface085b2ad75bc7adb24404 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 11 May 2021 16:09:22 -0700 Subject: [PATCH] fix: use require() to load JSON protos (#746) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: use require() to load JSON protos The library is regenerated with gapic-generator-typescript v1.3.1. Committer: @alexander-fenster PiperOrigin-RevId: 372468161 Source-Link: https://github.com/googleapis/googleapis/commit/75880c3e6a6aa2597400582848e81bbbfac51dea Source-Link: https://github.com/googleapis/googleapis-gen/commit/77b18044813d4c8c415ff9ea68e76e307eb8e904 * 🦉 Updates from OwlBot Co-authored-by: Owl Bot Co-authored-by: Jeff Ching --- .../src/v1/speech_client.ts | 26 +++---------------- .../src/v1p1beta1/adaptation_client.ts | 18 ++----------- .../src/v1p1beta1/speech_client.ts | 26 +++---------------- 3 files changed, 10 insertions(+), 60 deletions(-) diff --git a/packages/google-cloud-speech/src/v1/speech_client.ts b/packages/google-cloud-speech/src/v1/speech_client.ts index 1ffefa59624..5944cab9b6d 100644 --- a/packages/google-cloud-speech/src/v1/speech_client.ts +++ b/packages/google-cloud-speech/src/v1/speech_client.ts @@ -28,6 +28,7 @@ import { import * as path from 'path'; import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); /** * Client JSON configuration object, loaded from * `src/v1/speech_client_config.json`. @@ -142,22 +143,7 @@ export class SpeechClient { clientHeader.push(`${opts.libName}/${opts.libVersion}`); } // Load the applicable protos. - // For Node.js, pass the path to JSON proto file. - // For browsers, pass the JSON content. - - 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 - ); + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); // Some of the methods on this service provide streaming responses. // Provide descriptors for these. @@ -167,15 +153,11 @@ export class SpeechClient { ), }; + const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos); + // This API contains "long-running operations", which return a // an Operation object that allows for tracking of the operation, // rather than holding a request open. - const protoFilesRoot = opts.fallback - ? this._gaxModule.protobuf.Root.fromJSON( - // eslint-disable-next-line @typescript-eslint/no-var-requires - require('../../protos/protos.json') - ) - : this._gaxModule.protobuf.loadSync(nodejsProtoPath); this.operationsClient = this._gaxModule .lro({ diff --git a/packages/google-cloud-speech/src/v1p1beta1/adaptation_client.ts b/packages/google-cloud-speech/src/v1p1beta1/adaptation_client.ts index 4febac9a459..1e7cf174234 100644 --- a/packages/google-cloud-speech/src/v1p1beta1/adaptation_client.ts +++ b/packages/google-cloud-speech/src/v1p1beta1/adaptation_client.ts @@ -31,6 +31,7 @@ import * as path from 'path'; import {Transform} from 'stream'; import {RequestType} from 'google-gax/build/src/apitypes'; import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); /** * Client JSON configuration object, loaded from * `src/v1p1beta1/adaptation_client_config.json`. @@ -145,22 +146,7 @@ export class AdaptationClient { clientHeader.push(`${opts.libName}/${opts.libVersion}`); } // Load the applicable protos. - // For Node.js, pass the path to JSON proto file. - // For browsers, pass the JSON content. - - 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 - ); + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. diff --git a/packages/google-cloud-speech/src/v1p1beta1/speech_client.ts b/packages/google-cloud-speech/src/v1p1beta1/speech_client.ts index 5786ad63169..51b4f5f9867 100644 --- a/packages/google-cloud-speech/src/v1p1beta1/speech_client.ts +++ b/packages/google-cloud-speech/src/v1p1beta1/speech_client.ts @@ -28,6 +28,7 @@ import { import * as path from 'path'; import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); /** * Client JSON configuration object, loaded from * `src/v1p1beta1/speech_client_config.json`. @@ -143,22 +144,7 @@ export class SpeechClient { clientHeader.push(`${opts.libName}/${opts.libVersion}`); } // Load the applicable protos. - // For Node.js, pass the path to JSON proto file. - // For browsers, pass the JSON content. - - 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 - ); + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. @@ -180,15 +166,11 @@ export class SpeechClient { ), }; + const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos); + // This API contains "long-running operations", which return a // an Operation object that allows for tracking of the operation, // rather than holding a request open. - const protoFilesRoot = opts.fallback - ? this._gaxModule.protobuf.Root.fromJSON( - // eslint-disable-next-line @typescript-eslint/no-var-requires - require('../../protos/protos.json') - ) - : this._gaxModule.protobuf.loadSync(nodejsProtoPath); this.operationsClient = this._gaxModule .lro({