From ffc56c11d43d0361c9d161918fee80c11f9dd2ce Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Fri, 7 May 2021 20:29:08 -0700 Subject: [PATCH 1/2] fix: use require to load proto JSON --- protos/protos.d.ts | 14 +++++++------- protos/protos.js | 28 ++++++++++++++-------------- src/v1/publisher_client.ts | 29 +++-------------------------- src/v1/schema_service_client.ts | 19 ++----------------- src/v1/subscriber_client.ts | 19 ++----------------- webpack.config.js | 2 +- 6 files changed, 29 insertions(+), 82 deletions(-) diff --git a/protos/protos.d.ts b/protos/protos.d.ts index 2bc15192a..53b30b43d 100644 --- a/protos/protos.d.ts +++ b/protos/protos.d.ts @@ -4891,7 +4891,7 @@ export namespace google { public time?: (google.protobuf.ITimestamp|null); /** SeekRequest snapshot. */ - public snapshot: string; + public snapshot?: (string|null); /** SeekRequest target. */ public target?: ("time"|"snapshot"); @@ -6024,7 +6024,7 @@ export namespace google { public parent: string; /** ValidateMessageRequest name. */ - public name: string; + public name?: (string|null); /** ValidateMessageRequest schema. */ public schema?: (google.pubsub.v1.ISchema|null); @@ -6348,19 +6348,19 @@ export namespace google { public selector: string; /** HttpRule get. */ - public get: string; + public get?: (string|null); /** HttpRule put. */ - public put: string; + public put?: (string|null); /** HttpRule post. */ - public post: string; + public post?: (string|null); /** HttpRule delete. */ - public delete: string; + public delete?: (string|null); /** HttpRule patch. */ - public patch: string; + public patch?: (string|null); /** HttpRule custom. */ public custom?: (google.api.ICustomHttpPattern|null); diff --git a/protos/protos.js b/protos/protos.js index 2d3c27e71..9290302f9 100644 --- a/protos/protos.js +++ b/protos/protos.js @@ -11168,11 +11168,11 @@ /** * SeekRequest snapshot. - * @member {string} snapshot + * @member {string|null|undefined} snapshot * @memberof google.pubsub.v1.SeekRequest * @instance */ - SeekRequest.prototype.snapshot = ""; + SeekRequest.prototype.snapshot = null; // OneOf field names bound to virtual getters and setters var $oneOfFields; @@ -13629,11 +13629,11 @@ /** * ValidateMessageRequest name. - * @member {string} name + * @member {string|null|undefined} name * @memberof google.pubsub.v1.ValidateMessageRequest * @instance */ - ValidateMessageRequest.prototype.name = ""; + ValidateMessageRequest.prototype.name = null; /** * ValidateMessageRequest schema. @@ -14391,43 +14391,43 @@ /** * HttpRule get. - * @member {string} get + * @member {string|null|undefined} get * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.get = ""; + HttpRule.prototype.get = null; /** * HttpRule put. - * @member {string} put + * @member {string|null|undefined} put * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.put = ""; + HttpRule.prototype.put = null; /** * HttpRule post. - * @member {string} post + * @member {string|null|undefined} post * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.post = ""; + HttpRule.prototype.post = null; /** * HttpRule delete. - * @member {string} delete + * @member {string|null|undefined} delete * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype["delete"] = ""; + HttpRule.prototype["delete"] = null; /** * HttpRule patch. - * @member {string} patch + * @member {string|null|undefined} patch * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.patch = ""; + HttpRule.prototype.patch = null; /** * HttpRule custom. 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. From ae17ea32491813d9421c3d62459d55cd0a0155da Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Sat, 8 May 2021 03:34:40 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protos/protos.d.ts | 14 +++++++------- protos/protos.js | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/protos/protos.d.ts b/protos/protos.d.ts index 53b30b43d..2bc15192a 100644 --- a/protos/protos.d.ts +++ b/protos/protos.d.ts @@ -4891,7 +4891,7 @@ export namespace google { public time?: (google.protobuf.ITimestamp|null); /** SeekRequest snapshot. */ - public snapshot?: (string|null); + public snapshot: string; /** SeekRequest target. */ public target?: ("time"|"snapshot"); @@ -6024,7 +6024,7 @@ export namespace google { public parent: string; /** ValidateMessageRequest name. */ - public name?: (string|null); + public name: string; /** ValidateMessageRequest schema. */ public schema?: (google.pubsub.v1.ISchema|null); @@ -6348,19 +6348,19 @@ export namespace google { public selector: string; /** HttpRule get. */ - public get?: (string|null); + public get: string; /** HttpRule put. */ - public put?: (string|null); + public put: string; /** HttpRule post. */ - public post?: (string|null); + public post: string; /** HttpRule delete. */ - public delete?: (string|null); + public delete: string; /** HttpRule patch. */ - public patch?: (string|null); + public patch: string; /** HttpRule custom. */ public custom?: (google.api.ICustomHttpPattern|null); diff --git a/protos/protos.js b/protos/protos.js index 9290302f9..2d3c27e71 100644 --- a/protos/protos.js +++ b/protos/protos.js @@ -11168,11 +11168,11 @@ /** * SeekRequest snapshot. - * @member {string|null|undefined} snapshot + * @member {string} snapshot * @memberof google.pubsub.v1.SeekRequest * @instance */ - SeekRequest.prototype.snapshot = null; + SeekRequest.prototype.snapshot = ""; // OneOf field names bound to virtual getters and setters var $oneOfFields; @@ -13629,11 +13629,11 @@ /** * ValidateMessageRequest name. - * @member {string|null|undefined} name + * @member {string} name * @memberof google.pubsub.v1.ValidateMessageRequest * @instance */ - ValidateMessageRequest.prototype.name = null; + ValidateMessageRequest.prototype.name = ""; /** * ValidateMessageRequest schema. @@ -14391,43 +14391,43 @@ /** * HttpRule get. - * @member {string|null|undefined} get + * @member {string} get * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.get = null; + HttpRule.prototype.get = ""; /** * HttpRule put. - * @member {string|null|undefined} put + * @member {string} put * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.put = null; + HttpRule.prototype.put = ""; /** * HttpRule post. - * @member {string|null|undefined} post + * @member {string} post * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.post = null; + HttpRule.prototype.post = ""; /** * HttpRule delete. - * @member {string|null|undefined} delete + * @member {string} delete * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype["delete"] = null; + HttpRule.prototype["delete"] = ""; /** * HttpRule patch. - * @member {string|null|undefined} patch + * @member {string} patch * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.patch = null; + HttpRule.prototype.patch = ""; /** * HttpRule custom.