Skip to content

Commit 492c60f

Browse files
fix: use require() to load JSON protos (#214)
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 729403f commit 492c60f

File tree

4 files changed

+14
-86
lines changed

4 files changed

+14
-86
lines changed

packages/google-cloud-documentai/src/v1/document_processor_service_client.ts

+4-22
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/document_processor_service_client_config.json`.
@@ -142,22 +143,7 @@ export class DocumentProcessorServiceClient {
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
// This API contains "path templates"; forward-slash-separated
163149
// identifiers to uniquely identify resources within the API.
@@ -171,15 +157,11 @@ export class DocumentProcessorServiceClient {
171157
),
172158
};
173159

160+
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
161+
174162
// This API contains "long-running operations", which return a
175163
// an Operation object that allows for tracking of the operation,
176164
// rather than holding a request open.
177-
const protoFilesRoot = opts.fallback
178-
? this._gaxModule.protobuf.Root.fromJSON(
179-
// eslint-disable-next-line @typescript-eslint/no-var-requires
180-
require('../../protos/protos.json')
181-
)
182-
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);
183165

184166
this.operationsClient = this._gaxModule
185167
.lro({

packages/google-cloud-documentai/src/v1beta1/document_understanding_service_client.ts

+3-21
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/v1beta1/document_understanding_service_client_config.json`.
@@ -140,32 +141,13 @@ export class DocumentUnderstandingServiceClient {
140141
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
141142
}
142143
// Load the applicable protos.
143-
// For Node.js, pass the path to JSON proto file.
144-
// For browsers, pass the JSON content.
144+
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
145145

146-
const nodejsProtoPath = path.join(
147-
__dirname,
148-
'..',
149-
'..',
150-
'protos',
151-
'protos.json'
152-
);
153-
this._protos = this._gaxGrpc.loadProto(
154-
opts.fallback
155-
? // eslint-disable-next-line @typescript-eslint/no-var-requires
156-
require('../../protos/protos.json')
157-
: nodejsProtoPath
158-
);
146+
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
159147

160148
// This API contains "long-running operations", which return a
161149
// an Operation object that allows for tracking of the operation,
162150
// rather than holding a request open.
163-
const protoFilesRoot = opts.fallback
164-
? this._gaxModule.protobuf.Root.fromJSON(
165-
// eslint-disable-next-line @typescript-eslint/no-var-requires
166-
require('../../protos/protos.json')
167-
)
168-
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);
169151

170152
this.operationsClient = this._gaxModule
171153
.lro({

packages/google-cloud-documentai/src/v1beta2/document_understanding_service_client.ts

+3-21
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/v1beta2/document_understanding_service_client_config.json`.
@@ -140,32 +141,13 @@ export class DocumentUnderstandingServiceClient {
140141
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
141142
}
142143
// Load the applicable protos.
143-
// For Node.js, pass the path to JSON proto file.
144-
// For browsers, pass the JSON content.
144+
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
145145

146-
const nodejsProtoPath = path.join(
147-
__dirname,
148-
'..',
149-
'..',
150-
'protos',
151-
'protos.json'
152-
);
153-
this._protos = this._gaxGrpc.loadProto(
154-
opts.fallback
155-
? // eslint-disable-next-line @typescript-eslint/no-var-requires
156-
require('../../protos/protos.json')
157-
: nodejsProtoPath
158-
);
146+
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
159147

160148
// This API contains "long-running operations", which return a
161149
// an Operation object that allows for tracking of the operation,
162150
// rather than holding a request open.
163-
const protoFilesRoot = opts.fallback
164-
? this._gaxModule.protobuf.Root.fromJSON(
165-
// eslint-disable-next-line @typescript-eslint/no-var-requires
166-
require('../../protos/protos.json')
167-
)
168-
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);
169151

170152
this.operationsClient = this._gaxModule
171153
.lro({

packages/google-cloud-documentai/src/v1beta3/document_processor_service_client.ts

+4-22
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/v1beta3/document_processor_service_client_config.json`.
@@ -142,22 +143,7 @@ export class DocumentProcessorServiceClient {
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
// This API contains "path templates"; forward-slash-separated
163149
// identifiers to uniquely identify resources within the API.
@@ -171,15 +157,11 @@ export class DocumentProcessorServiceClient {
171157
),
172158
};
173159

160+
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
161+
174162
// This API contains "long-running operations", which return a
175163
// an Operation object that allows for tracking of the operation,
176164
// rather than holding a request open.
177-
const protoFilesRoot = opts.fallback
178-
? this._gaxModule.protobuf.Root.fromJSON(
179-
// eslint-disable-next-line @typescript-eslint/no-var-requires
180-
require('../../protos/protos.json')
181-
)
182-
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);
183165

184166
this.operationsClient = this._gaxModule
185167
.lro({

0 commit comments

Comments
 (0)