Skip to content

Commit 273d4b9

Browse files
fix: use require() to load JSON protos (#746)
* 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: googleapis/googleapis@75880c3 Source-Link: googleapis/googleapis-gen@77b1804 * 🦉 Updates from OwlBot Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Jeff Ching <[email protected]>
1 parent a567005 commit 273d4b9

File tree

3 files changed

+10
-60
lines changed

3 files changed

+10
-60
lines changed

packages/google-cloud-node/src/v1/speech_client.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import * as path from 'path';
2929

3030
import * as protos from '../../protos/protos';
31+
import jsonProtos = require('../../protos/protos.json');
3132
/**
3233
* Client JSON configuration object, loaded from
3334
* `src/v1/speech_client_config.json`.
@@ -142,22 +143,7 @@ export class SpeechClient {
142143
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
143144
}
144145
// Load the applicable protos.
145-
// For Node.js, pass the path to JSON proto file.
146-
// For browsers, pass the JSON content.
147-
148-
const nodejsProtoPath = path.join(
149-
__dirname,
150-
'..',
151-
'..',
152-
'protos',
153-
'protos.json'
154-
);
155-
this._protos = this._gaxGrpc.loadProto(
156-
opts.fallback
157-
? // eslint-disable-next-line @typescript-eslint/no-var-requires
158-
require('../../protos/protos.json')
159-
: nodejsProtoPath
160-
);
146+
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
161147

162148
// Some of the methods on this service provide streaming responses.
163149
// Provide descriptors for these.
@@ -167,15 +153,11 @@ export class SpeechClient {
167153
),
168154
};
169155

156+
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
157+
170158
// This API contains "long-running operations", which return a
171159
// an Operation object that allows for tracking of the operation,
172160
// rather than holding a request open.
173-
const protoFilesRoot = opts.fallback
174-
? this._gaxModule.protobuf.Root.fromJSON(
175-
// eslint-disable-next-line @typescript-eslint/no-var-requires
176-
require('../../protos/protos.json')
177-
)
178-
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);
179161

180162
this.operationsClient = this._gaxModule
181163
.lro({

packages/google-cloud-node/src/v1p1beta1/adaptation_client.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import * as path from 'path';
3131
import {Transform} from 'stream';
3232
import {RequestType} from 'google-gax/build/src/apitypes';
3333
import * as protos from '../../protos/protos';
34+
import jsonProtos = require('../../protos/protos.json');
3435
/**
3536
* Client JSON configuration object, loaded from
3637
* `src/v1p1beta1/adaptation_client_config.json`.
@@ -145,22 +146,7 @@ export class AdaptationClient {
145146
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
146147
}
147148
// Load the applicable protos.
148-
// For Node.js, pass the path to JSON proto file.
149-
// For browsers, pass the JSON content.
150-
151-
const nodejsProtoPath = path.join(
152-
__dirname,
153-
'..',
154-
'..',
155-
'protos',
156-
'protos.json'
157-
);
158-
this._protos = this._gaxGrpc.loadProto(
159-
opts.fallback
160-
? // eslint-disable-next-line @typescript-eslint/no-var-requires
161-
require('../../protos/protos.json')
162-
: nodejsProtoPath
163-
);
149+
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
164150

165151
// This API contains "path templates"; forward-slash-separated
166152
// identifiers to uniquely identify resources within the API.

packages/google-cloud-node/src/v1p1beta1/speech_client.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import * as path from 'path';
2929

3030
import * as protos from '../../protos/protos';
31+
import jsonProtos = require('../../protos/protos.json');
3132
/**
3233
* Client JSON configuration object, loaded from
3334
* `src/v1p1beta1/speech_client_config.json`.
@@ -143,22 +144,7 @@ export class SpeechClient {
143144
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
144145
}
145146
// Load the applicable protos.
146-
// For Node.js, pass the path to JSON proto file.
147-
// For browsers, pass the JSON content.
148-
149-
const nodejsProtoPath = path.join(
150-
__dirname,
151-
'..',
152-
'..',
153-
'protos',
154-
'protos.json'
155-
);
156-
this._protos = this._gaxGrpc.loadProto(
157-
opts.fallback
158-
? // eslint-disable-next-line @typescript-eslint/no-var-requires
159-
require('../../protos/protos.json')
160-
: nodejsProtoPath
161-
);
147+
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
162148

163149
// This API contains "path templates"; forward-slash-separated
164150
// identifiers to uniquely identify resources within the API.
@@ -180,15 +166,11 @@ export class SpeechClient {
180166
),
181167
};
182168

169+
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
170+
183171
// This API contains "long-running operations", which return a
184172
// an Operation object that allows for tracking of the operation,
185173
// rather than holding a request open.
186-
const protoFilesRoot = opts.fallback
187-
? this._gaxModule.protobuf.Root.fromJSON(
188-
// eslint-disable-next-line @typescript-eslint/no-var-requires
189-
require('../../protos/protos.json')
190-
)
191-
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);
192174

193175
this.operationsClient = this._gaxModule
194176
.lro({

0 commit comments

Comments
 (0)