@google-cloud/web-risk
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -9,1 +9,3 @@ import * as v1beta1 from './v1beta1'; | ||
export default _default; | ||
import * as protos from '../protos/protos'; | ||
export { protos }; |
@@ -27,2 +27,4 @@ "use strict"; | ||
exports.default = { v1beta1, WebRiskServiceV1Beta1Client }; | ||
const protos = require("../protos/protos"); | ||
exports.protos = protos; | ||
//# sourceMappingURL=index.js.map |
@@ -14,4 +14,9 @@ import * as gax from 'google-gax'; | ||
private _terminated; | ||
private _opts; | ||
private _gaxModule; | ||
private _gaxGrpc; | ||
private _protos; | ||
private _defaults; | ||
auth: gax.GoogleAuth; | ||
webRiskServiceV1Beta1Stub: Promise<{ | ||
webRiskServiceV1Beta1Stub?: Promise<{ | ||
[name: string]: Function; | ||
@@ -41,4 +46,2 @@ }>; | ||
* your project ID will be detected automatically. | ||
* @param {function} [options.promise] - Custom promise module to use instead | ||
* of native Promises. | ||
* @param {string} [options.apiEndpoint] - The domain name of the | ||
@@ -49,2 +52,16 @@ * API remote host. | ||
/** | ||
* Initialize the client. | ||
* Performs asynchronous operations (such as authentication) and prepares the client. | ||
* This function will be called automatically when any class method is called for the | ||
* first time, but if you need to initialize it before calling an actual method, | ||
* feel free to call initialize() directly. | ||
* | ||
* You can await on this method if you want to make sure the client is initialized. | ||
* | ||
* @returns {Promise} A promise that resolves to an authenticated service stub. | ||
*/ | ||
initialize(): Promise<{ | ||
[name: string]: Function; | ||
}>; | ||
/** | ||
* The DNS address for this API service. | ||
@@ -51,0 +68,0 @@ */ |
@@ -53,4 +53,2 @@ "use strict"; | ||
* your project ID will be detected automatically. | ||
* @param {function} [options.promise] - Custom promise module to use instead | ||
* of native Promises. | ||
* @param {string} [options.apiEndpoint] - The domain name of the | ||
@@ -84,3 +82,3 @@ * API remote host. | ||
// But if we were explicitly requested to use fallback, let's do it now. | ||
const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; | ||
this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; | ||
// Create a `gaxGrpc` object, with any grpc-specific options | ||
@@ -90,7 +88,9 @@ // sent to the client. | ||
.constructor.scopes; | ||
const gaxGrpc = new gaxModule.GrpcClient(opts); | ||
this._gaxGrpc = new this._gaxModule.GrpcClient(opts); | ||
// Save options to use in initialize() method. | ||
this._opts = opts; | ||
// Save the auth object to the client, for use by other methods. | ||
this.auth = gaxGrpc.auth; | ||
this.auth = this._gaxGrpc.auth; | ||
// Determine the client header string. | ||
const clientHeader = [`gax/${gaxModule.version}`, `gapic/${version}`]; | ||
const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; | ||
if (typeof process !== 'undefined' && 'versions' in process) { | ||
@@ -100,6 +100,6 @@ clientHeader.push(`gl-node/${process.versions.node}`); | ||
else { | ||
clientHeader.push(`gl-web/${gaxModule.version}`); | ||
clientHeader.push(`gl-web/${this._gaxModule.version}`); | ||
} | ||
if (!opts.fallback) { | ||
clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); | ||
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); | ||
} | ||
@@ -113,5 +113,5 @@ if (opts.libName && opts.libVersion) { | ||
const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); | ||
const protos = gaxGrpc.loadProto(opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath); | ||
this._protos = this._gaxGrpc.loadProto(opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath); | ||
// Put together the default options sent with requests. | ||
const defaults = gaxGrpc.constructSettings('google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') }); | ||
this._defaults = this._gaxGrpc.constructSettings('google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') }); | ||
// Set up a dictionary of "inner API calls"; the core implementation | ||
@@ -121,8 +121,26 @@ // of calling the API is handled in `google-gax`, with this code | ||
this._innerApiCalls = {}; | ||
} | ||
/** | ||
* Initialize the client. | ||
* Performs asynchronous operations (such as authentication) and prepares the client. | ||
* This function will be called automatically when any class method is called for the | ||
* first time, but if you need to initialize it before calling an actual method, | ||
* feel free to call initialize() directly. | ||
* | ||
* You can await on this method if you want to make sure the client is initialized. | ||
* | ||
* @returns {Promise} A promise that resolves to an authenticated service stub. | ||
*/ | ||
initialize() { | ||
// If the client stub promise is already initialized, return immediately. | ||
if (this.webRiskServiceV1Beta1Stub) { | ||
return this.webRiskServiceV1Beta1Stub; | ||
} | ||
// Put together the "service stub" for | ||
// google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1. | ||
this.webRiskServiceV1Beta1Stub = gaxGrpc.createStub(opts.fallback | ||
? protos.lookupService('google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1') | ||
this.webRiskServiceV1Beta1Stub = this._gaxGrpc.createStub(this._opts.fallback | ||
? this._protos.lookupService('google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1') | ||
: // tslint:disable-next-line no-any | ||
protos.google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1, opts); | ||
this._protos.google.cloud.webrisk.v1beta1 | ||
.WebRiskServiceV1Beta1, this._opts); | ||
// Iterate over each of the methods that the service provides | ||
@@ -144,3 +162,3 @@ // and create an API call method for each. | ||
}); | ||
const apiCall = gaxModule.createApiCall(innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || | ||
const apiCall = this._gaxModule.createApiCall(innerCallPromise, this._defaults[methodName], this._descriptors.page[methodName] || | ||
this._descriptors.stream[methodName] || | ||
@@ -152,2 +170,3 @@ this._descriptors.longrunning[methodName]); | ||
} | ||
return this.webRiskServiceV1Beta1Stub; | ||
} | ||
@@ -221,2 +240,3 @@ /** | ||
options = options || {}; | ||
this.initialize(); | ||
return this._innerApiCalls.computeThreatListDiff(request, options, callback); | ||
@@ -250,2 +270,3 @@ } | ||
options = options || {}; | ||
this.initialize(); | ||
return this._innerApiCalls.searchUris(request, options, callback); | ||
@@ -284,2 +305,3 @@ } | ||
options = options || {}; | ||
this.initialize(); | ||
return this._innerApiCalls.searchHashes(request, options, callback); | ||
@@ -293,2 +315,3 @@ } | ||
close() { | ||
this.initialize(); | ||
if (!this._terminated) { | ||
@@ -295,0 +318,0 @@ return this.webRiskServiceV1Beta1Stub.then(stub => { |
@@ -7,2 +7,10 @@ # Changelog | ||
## [1.6.0](https://www.github.com/googleapis/nodejs-web-risk/compare/v1.5.0...v1.6.0) (2020-03-06) | ||
### Features | ||
* deferred client initialization ([#123](https://www.github.com/googleapis/nodejs-web-risk/issues/123)) ([ebafd9f](https://www.github.com/googleapis/nodejs-web-risk/commit/ebafd9fade2cf3bd3d464e55216fcd2c57225c40)) | ||
* export protos in src/index.ts ([4003c2c](https://www.github.com/googleapis/nodejs-web-risk/commit/4003c2cbc5a235d49e56165331fd85f58e5d9373)) | ||
## [1.5.0](https://www.github.com/googleapis/nodejs-web-risk/compare/v1.4.1...v1.5.0) (2020-01-30) | ||
@@ -9,0 +17,0 @@ |
{ | ||
"repository": "googleapis/nodejs-web-risk", | ||
"name": "@google-cloud/web-risk", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"author": "Google LLC", | ||
@@ -42,11 +42,9 @@ "description": "Web Risk API client for Node.js", | ||
"http2spy": "^1.0.0", | ||
"intelli-espower-loader": "^1.0.1", | ||
"jsdoc": "^3.5.5", | ||
"jsdoc-fresh": "^1.0.1", | ||
"jsdoc-region-tag": "^1.0.2", | ||
"linkinator": "^1.4.0", | ||
"linkinator": "^2.0.0", | ||
"mocha": "^7.0.0", | ||
"null-loader": "^3.0.0", | ||
"pack-n-play": "^1.0.0-2", | ||
"power-assert": "^1.4.4", | ||
"prettier": "^1.17.0", | ||
@@ -71,3 +69,4 @@ "ts-loader": "^6.2.1", | ||
"prepare": "npm run compile", | ||
"pretest": "npm run compile" | ||
"pretest": "npm run compile", | ||
"prelint": "cd samples; npm link ../; npm i" | ||
}, | ||
@@ -74,0 +73,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1155528
23
19040