Skip to content

Commit 9b305fb

Browse files
fix: use require() to load JSON protos (#110)
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
1 parent 3c74df1 commit 9b305fb

File tree

2 files changed

+8
-44
lines changed

2 files changed

+8
-44
lines changed

packages/google-cloud-memcache/src/v1/cloud_memcache_client.ts

+4-22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import * as path from 'path';
3232
import {Transform} from 'stream';
3333
import {RequestType} from 'google-gax/build/src/apitypes';
3434
import * as protos from '../../protos/protos';
35+
import jsonProtos = require('../../protos/protos.json');
3536
/**
3637
* Client JSON configuration object, loaded from
3738
* `src/v1/cloud_memcache_client_config.json`.
@@ -161,22 +162,7 @@ export class CloudMemcacheClient {
161162
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
162163
}
163164
// Load the applicable protos.
164-
// For Node.js, pass the path to JSON proto file.
165-
// For browsers, pass the JSON content.
166-
167-
const nodejsProtoPath = path.join(
168-
__dirname,
169-
'..',
170-
'..',
171-
'protos',
172-
'protos.json'
173-
);
174-
this._protos = this._gaxGrpc.loadProto(
175-
opts.fallback
176-
? // eslint-disable-next-line @typescript-eslint/no-var-requires
177-
require('../../protos/protos.json')
178-
: nodejsProtoPath
179-
);
165+
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
180166

181167
// This API contains "path templates"; forward-slash-separated
182168
// identifiers to uniquely identify resources within the API.
@@ -201,15 +187,11 @@ export class CloudMemcacheClient {
201187
),
202188
};
203189

190+
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
191+
204192
// This API contains "long-running operations", which return a
205193
// an Operation object that allows for tracking of the operation,
206194
// rather than holding a request open.
207-
const protoFilesRoot = opts.fallback
208-
? this._gaxModule.protobuf.Root.fromJSON(
209-
// eslint-disable-next-line @typescript-eslint/no-var-requires
210-
require('../../protos/protos.json')
211-
)
212-
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);
213195

214196
this.operationsClient = this._gaxModule
215197
.lro({

packages/google-cloud-memcache/src/v1beta2/cloud_memcache_client.ts

+4-22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import * as path from 'path';
3232
import {Transform} from 'stream';
3333
import {RequestType} from 'google-gax/build/src/apitypes';
3434
import * as protos from '../../protos/protos';
35+
import jsonProtos = require('../../protos/protos.json');
3536
/**
3637
* Client JSON configuration object, loaded from
3738
* `src/v1beta2/cloud_memcache_client_config.json`.
@@ -161,22 +162,7 @@ export class CloudMemcacheClient {
161162
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
162163
}
163164
// Load the applicable protos.
164-
// For Node.js, pass the path to JSON proto file.
165-
// For browsers, pass the JSON content.
166-
167-
const nodejsProtoPath = path.join(
168-
__dirname,
169-
'..',
170-
'..',
171-
'protos',
172-
'protos.json'
173-
);
174-
this._protos = this._gaxGrpc.loadProto(
175-
opts.fallback
176-
? // eslint-disable-next-line @typescript-eslint/no-var-requires
177-
require('../../protos/protos.json')
178-
: nodejsProtoPath
179-
);
165+
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
180166

181167
// This API contains "path templates"; forward-slash-separated
182168
// identifiers to uniquely identify resources within the API.
@@ -201,15 +187,11 @@ export class CloudMemcacheClient {
201187
),
202188
};
203189

190+
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
191+
204192
// This API contains "long-running operations", which return a
205193
// an Operation object that allows for tracking of the operation,
206194
// rather than holding a request open.
207-
const protoFilesRoot = opts.fallback
208-
? this._gaxModule.protobuf.Root.fromJSON(
209-
// eslint-disable-next-line @typescript-eslint/no-var-requires
210-
require('../../protos/protos.json')
211-
)
212-
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);
213195

214196
this.operationsClient = this._gaxModule
215197
.lro({

0 commit comments

Comments
 (0)