Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

fix: use require() to load JSON protos #112

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions src/v3/agents_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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/v3/agents_client_config.json`.
Expand Down Expand Up @@ -147,22 +148,7 @@ export class AgentsClient {
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.
Expand Down Expand Up @@ -240,15 +226,11 @@ export class AgentsClient {
),
};

const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);

// 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);

this.operationsClient = this._gaxModule
.lro({
Expand Down
18 changes: 2 additions & 16 deletions src/v3/entity_types_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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/v3/entity_types_client_config.json`.
Expand Down Expand Up @@ -145,22 +146,7 @@ export class EntityTypesClient {
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.
Expand Down
26 changes: 4 additions & 22 deletions src/v3/environments_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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/v3/environments_client_config.json`.
Expand Down Expand Up @@ -147,22 +148,7 @@ export class EnvironmentsClient {
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.
Expand Down Expand Up @@ -245,15 +231,11 @@ export class EnvironmentsClient {
),
};

const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);

// 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);

this.operationsClient = this._gaxModule
.lro({
Expand Down
18 changes: 2 additions & 16 deletions src/v3/experiments_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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/v3/experiments_client_config.json`.
Expand Down Expand Up @@ -145,22 +146,7 @@ export class ExperimentsClient {
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.
Expand Down
26 changes: 4 additions & 22 deletions src/v3/flows_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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/v3/flows_client_config.json`.
Expand Down Expand Up @@ -147,22 +148,7 @@ export class FlowsClient {
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.
Expand Down Expand Up @@ -240,15 +226,11 @@ export class FlowsClient {
),
};

const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);

// 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);

this.operationsClient = this._gaxModule
.lro({
Expand Down
18 changes: 2 additions & 16 deletions src/v3/intents_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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/v3/intents_client_config.json`.
Expand Down Expand Up @@ -145,22 +146,7 @@ export class IntentsClient {
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.
Expand Down
18 changes: 2 additions & 16 deletions src/v3/pages_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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/v3/pages_client_config.json`.
Expand Down Expand Up @@ -145,22 +146,7 @@ export class PagesClient {
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.
Expand Down
18 changes: 2 additions & 16 deletions src/v3/security_settings_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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/v3/security_settings_service_client_config.json`.
Expand Down Expand Up @@ -146,22 +147,7 @@ export class SecuritySettingsServiceClient {
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.
Expand Down
18 changes: 2 additions & 16 deletions src/v3/session_entity_types_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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/v3/session_entity_types_client_config.json`.
Expand Down Expand Up @@ -145,22 +146,7 @@ export class SessionEntityTypesClient {
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.
Expand Down
18 changes: 2 additions & 16 deletions src/v3/sessions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {Callback, CallOptions, Descriptors, ClientOptions} from 'google-gax';
import * as path from 'path';

import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
/**
* Client JSON configuration object, loaded from
* `src/v3/sessions_client_config.json`.
Expand Down Expand Up @@ -139,22 +140,7 @@ export class SessionsClient {
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.
Expand Down
Loading