From 201a56c4c7c7115cd3a7c8cff864d83223082d12 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Mon, 10 May 2021 12:47:01 -0700 Subject: [PATCH] fix: use require to load proto JSON (#1283) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: use require to load proto JSON * 🦉 Updates from OwlBot Co-authored-by: Owl Bot --- src/v1/publisher_client.ts | 29 +++-------------------------- src/v1/schema_service_client.ts | 19 ++----------------- src/v1/subscriber_client.ts | 19 ++----------------- webpack.config.js | 2 +- 4 files changed, 8 insertions(+), 61 deletions(-) diff --git a/src/v1/publisher_client.ts b/src/v1/publisher_client.ts index 93509242d..b2c771d48 100644 --- a/src/v1/publisher_client.ts +++ b/src/v1/publisher_client.ts @@ -28,11 +28,11 @@ import { IamClient, IamProtos, } from 'google-gax'; -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/v1/publisher_client_config.json`. @@ -150,22 +150,7 @@ export class PublisherClient { 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. @@ -209,15 +194,7 @@ export class PublisherClient { ), }; - // 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); + const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos); // Some methods on this API support automatically batching // requests; denote this. diff --git a/src/v1/schema_service_client.ts b/src/v1/schema_service_client.ts index 5c04c0651..23038577f 100644 --- a/src/v1/schema_service_client.ts +++ b/src/v1/schema_service_client.ts @@ -28,11 +28,11 @@ import { IamClient, IamProtos, } from 'google-gax'; -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/v1/schema_service_client_config.json`. @@ -149,22 +149,7 @@ export class SchemaServiceClient { 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/src/v1/subscriber_client.ts b/src/v1/subscriber_client.ts index 4b8845544..258740cb7 100644 --- a/src/v1/subscriber_client.ts +++ b/src/v1/subscriber_client.ts @@ -28,11 +28,11 @@ import { IamClient, IamProtos, } from 'google-gax'; -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/v1/subscriber_client_config.json`. @@ -151,22 +151,7 @@ export class SubscriberClient { 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/webpack.config.js b/webpack.config.js index 16a13980c..6336ba021 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,4 @@ -// Copyright 2020 Google LLC +// Copyright 2021 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License.