@google-cloud/translate
Advanced tools
Comparing version 5.2.0 to 5.3.0
@@ -16,5 +16,10 @@ /// <reference types="node" /> | ||
private _terminated; | ||
private _opts; | ||
private _gaxModule; | ||
private _gaxGrpc; | ||
private _protos; | ||
private _defaults; | ||
auth: gax.GoogleAuth; | ||
operationsClient: gax.OperationsClient; | ||
translationServiceStub: Promise<{ | ||
translationServiceStub?: Promise<{ | ||
[name: string]: Function; | ||
@@ -44,4 +49,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 | ||
@@ -52,2 +55,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. | ||
@@ -54,0 +71,0 @@ */ |
@@ -52,4 +52,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 | ||
@@ -82,11 +80,13 @@ * 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 | ||
// sent to the client. | ||
opts.scopes = this.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) { | ||
@@ -96,6 +96,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}`); | ||
} | ||
@@ -109,3 +109,3 @@ 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); | ||
// This API contains "path templates"; forward-slash-separated | ||
@@ -115,4 +115,4 @@ // identifiers to uniquely identify resources within the API. | ||
this._pathTemplates = { | ||
glossaryPathTemplate: new gaxModule.PathTemplate('projects/{project}/locations/{location}/glossaries/{glossary}'), | ||
locationPathTemplate: new gaxModule.PathTemplate('projects/{project}/locations/{location}'), | ||
glossaryPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/glossaries/{glossary}'), | ||
locationPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}'), | ||
}; | ||
@@ -123,3 +123,3 @@ // Some of the methods on this service return "paged" results, | ||
this._descriptors.page = { | ||
listGlossaries: new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'glossaries'), | ||
listGlossaries: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'glossaries'), | ||
}; | ||
@@ -130,8 +130,8 @@ // This API contains "long-running operations", which return a | ||
const protoFilesRoot = opts.fallback | ||
? gaxModule.protobuf.Root.fromJSON(require('../../protos/protos.json')) | ||
: gaxModule.protobuf.loadSync(nodejsProtoPath); | ||
this.operationsClient = gaxModule | ||
? this._gaxModule.protobuf.Root.fromJSON(require('../../protos/protos.json')) | ||
: this._gaxModule.protobuf.loadSync(nodejsProtoPath); | ||
this.operationsClient = this._gaxModule | ||
.lro({ | ||
auth: this.auth, | ||
grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined, | ||
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined, | ||
}) | ||
@@ -146,8 +146,8 @@ .operationsClient(opts); | ||
this._descriptors.longrunning = { | ||
batchTranslateText: new gaxModule.LongrunningDescriptor(this.operationsClient, batchTranslateTextResponse.decode.bind(batchTranslateTextResponse), batchTranslateTextMetadata.decode.bind(batchTranslateTextMetadata)), | ||
createGlossary: new gaxModule.LongrunningDescriptor(this.operationsClient, createGlossaryResponse.decode.bind(createGlossaryResponse), createGlossaryMetadata.decode.bind(createGlossaryMetadata)), | ||
deleteGlossary: new gaxModule.LongrunningDescriptor(this.operationsClient, deleteGlossaryResponse.decode.bind(deleteGlossaryResponse), deleteGlossaryMetadata.decode.bind(deleteGlossaryMetadata)), | ||
batchTranslateText: new this._gaxModule.LongrunningDescriptor(this.operationsClient, batchTranslateTextResponse.decode.bind(batchTranslateTextResponse), batchTranslateTextMetadata.decode.bind(batchTranslateTextMetadata)), | ||
createGlossary: new this._gaxModule.LongrunningDescriptor(this.operationsClient, createGlossaryResponse.decode.bind(createGlossaryResponse), createGlossaryMetadata.decode.bind(createGlossaryMetadata)), | ||
deleteGlossary: new this._gaxModule.LongrunningDescriptor(this.operationsClient, deleteGlossaryResponse.decode.bind(deleteGlossaryResponse), deleteGlossaryMetadata.decode.bind(deleteGlossaryMetadata)), | ||
}; | ||
// Put together the default options sent with requests. | ||
const defaults = gaxGrpc.constructSettings('google.cloud.translation.v3.TranslationService', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') }); | ||
this._defaults = this._gaxGrpc.constructSettings('google.cloud.translation.v3.TranslationService', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') }); | ||
// Set up a dictionary of "inner API calls"; the core implementation | ||
@@ -157,8 +157,25 @@ // 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.translationServiceStub) { | ||
return this.translationServiceStub; | ||
} | ||
// Put together the "service stub" for | ||
// google.cloud.translation.v3.TranslationService. | ||
this.translationServiceStub = gaxGrpc.createStub(opts.fallback | ||
? protos.lookupService('google.cloud.translation.v3.TranslationService') | ||
this.translationServiceStub = this._gaxGrpc.createStub(this._opts.fallback | ||
? this._protos.lookupService('google.cloud.translation.v3.TranslationService') | ||
: // tslint:disable-next-line no-any | ||
protos.google.cloud.translation.v3.TranslationService, opts); | ||
this._protos.google.cloud.translation.v3.TranslationService, this._opts); | ||
// Iterate over each of the methods that the service provides | ||
@@ -185,3 +202,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] || | ||
@@ -193,2 +210,3 @@ this._descriptors.longrunning[methodName]); | ||
} | ||
return this.translationServiceStub; | ||
} | ||
@@ -325,2 +343,3 @@ /** | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.translateText(request, options, callback); | ||
@@ -391,2 +410,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.detectLanguage(request, options, callback); | ||
@@ -454,2 +474,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.getSupportedLanguages(request, options, callback); | ||
@@ -487,2 +508,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.getGlossary(request, options, callback); | ||
@@ -575,2 +597,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.batchTranslateText(request, options, callback); | ||
@@ -610,2 +633,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.createGlossary(request, options, callback); | ||
@@ -644,2 +668,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.deleteGlossary(request, options, callback); | ||
@@ -701,2 +726,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.listGlossaries(request, options, callback); | ||
@@ -747,2 +773,3 @@ } | ||
const callSettings = new gax.CallSettings(options); | ||
this.initialize(); | ||
return this._descriptors.page.listGlossaries.createStream(this._innerApiCalls.listGlossaries, request, callSettings); | ||
@@ -840,2 +867,3 @@ } | ||
close() { | ||
this.initialize(); | ||
if (!this._terminated) { | ||
@@ -842,0 +870,0 @@ return this.translationServiceStub.then(stub => { |
@@ -16,5 +16,10 @@ /// <reference types="node" /> | ||
private _terminated; | ||
private _opts; | ||
private _gaxModule; | ||
private _gaxGrpc; | ||
private _protos; | ||
private _defaults; | ||
auth: gax.GoogleAuth; | ||
operationsClient: gax.OperationsClient; | ||
translationServiceStub: Promise<{ | ||
translationServiceStub?: Promise<{ | ||
[name: string]: Function; | ||
@@ -44,4 +49,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 | ||
@@ -52,2 +55,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. | ||
@@ -54,0 +71,0 @@ */ |
@@ -52,4 +52,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 | ||
@@ -82,11 +80,13 @@ * 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 | ||
// sent to the client. | ||
opts.scopes = this.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) { | ||
@@ -96,6 +96,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}`); | ||
} | ||
@@ -109,3 +109,3 @@ 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); | ||
// This API contains "path templates"; forward-slash-separated | ||
@@ -115,4 +115,4 @@ // identifiers to uniquely identify resources within the API. | ||
this._pathTemplates = { | ||
glossaryPathTemplate: new gaxModule.PathTemplate('projects/{project}/locations/{location}/glossaries/{glossary}'), | ||
locationPathTemplate: new gaxModule.PathTemplate('projects/{project}/locations/{location}'), | ||
glossaryPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/glossaries/{glossary}'), | ||
locationPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}'), | ||
}; | ||
@@ -123,3 +123,3 @@ // Some of the methods on this service return "paged" results, | ||
this._descriptors.page = { | ||
listGlossaries: new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'glossaries'), | ||
listGlossaries: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'glossaries'), | ||
}; | ||
@@ -130,8 +130,8 @@ // This API contains "long-running operations", which return a | ||
const protoFilesRoot = opts.fallback | ||
? gaxModule.protobuf.Root.fromJSON(require('../../protos/protos.json')) | ||
: gaxModule.protobuf.loadSync(nodejsProtoPath); | ||
this.operationsClient = gaxModule | ||
? this._gaxModule.protobuf.Root.fromJSON(require('../../protos/protos.json')) | ||
: this._gaxModule.protobuf.loadSync(nodejsProtoPath); | ||
this.operationsClient = this._gaxModule | ||
.lro({ | ||
auth: this.auth, | ||
grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined, | ||
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined, | ||
}) | ||
@@ -146,8 +146,8 @@ .operationsClient(opts); | ||
this._descriptors.longrunning = { | ||
batchTranslateText: new gaxModule.LongrunningDescriptor(this.operationsClient, batchTranslateTextResponse.decode.bind(batchTranslateTextResponse), batchTranslateTextMetadata.decode.bind(batchTranslateTextMetadata)), | ||
createGlossary: new gaxModule.LongrunningDescriptor(this.operationsClient, createGlossaryResponse.decode.bind(createGlossaryResponse), createGlossaryMetadata.decode.bind(createGlossaryMetadata)), | ||
deleteGlossary: new gaxModule.LongrunningDescriptor(this.operationsClient, deleteGlossaryResponse.decode.bind(deleteGlossaryResponse), deleteGlossaryMetadata.decode.bind(deleteGlossaryMetadata)), | ||
batchTranslateText: new this._gaxModule.LongrunningDescriptor(this.operationsClient, batchTranslateTextResponse.decode.bind(batchTranslateTextResponse), batchTranslateTextMetadata.decode.bind(batchTranslateTextMetadata)), | ||
createGlossary: new this._gaxModule.LongrunningDescriptor(this.operationsClient, createGlossaryResponse.decode.bind(createGlossaryResponse), createGlossaryMetadata.decode.bind(createGlossaryMetadata)), | ||
deleteGlossary: new this._gaxModule.LongrunningDescriptor(this.operationsClient, deleteGlossaryResponse.decode.bind(deleteGlossaryResponse), deleteGlossaryMetadata.decode.bind(deleteGlossaryMetadata)), | ||
}; | ||
// Put together the default options sent with requests. | ||
const defaults = gaxGrpc.constructSettings('google.cloud.translation.v3beta1.TranslationService', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') }); | ||
this._defaults = this._gaxGrpc.constructSettings('google.cloud.translation.v3beta1.TranslationService', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') }); | ||
// Set up a dictionary of "inner API calls"; the core implementation | ||
@@ -157,8 +157,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.translationServiceStub) { | ||
return this.translationServiceStub; | ||
} | ||
// Put together the "service stub" for | ||
// google.cloud.translation.v3beta1.TranslationService. | ||
this.translationServiceStub = gaxGrpc.createStub(opts.fallback | ||
? protos.lookupService('google.cloud.translation.v3beta1.TranslationService') | ||
this.translationServiceStub = this._gaxGrpc.createStub(this._opts.fallback | ||
? this._protos.lookupService('google.cloud.translation.v3beta1.TranslationService') | ||
: // tslint:disable-next-line no-any | ||
protos.google.cloud.translation.v3beta1.TranslationService, opts); | ||
this._protos.google.cloud.translation.v3beta1 | ||
.TranslationService, this._opts); | ||
// Iterate over each of the methods that the service provides | ||
@@ -185,3 +203,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] || | ||
@@ -193,2 +211,3 @@ this._descriptors.longrunning[methodName]); | ||
} | ||
return this.translationServiceStub; | ||
} | ||
@@ -325,2 +344,3 @@ /** | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.translateText(request, options, callback); | ||
@@ -391,2 +411,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.detectLanguage(request, options, callback); | ||
@@ -454,2 +475,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.getSupportedLanguages(request, options, callback); | ||
@@ -487,2 +509,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.getGlossary(request, options, callback); | ||
@@ -575,2 +598,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.batchTranslateText(request, options, callback); | ||
@@ -610,2 +634,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.createGlossary(request, options, callback); | ||
@@ -644,2 +669,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.deleteGlossary(request, options, callback); | ||
@@ -701,2 +727,3 @@ } | ||
}); | ||
this.initialize(); | ||
return this._innerApiCalls.listGlossaries(request, options, callback); | ||
@@ -747,2 +774,3 @@ } | ||
const callSettings = new gax.CallSettings(options); | ||
this.initialize(); | ||
return this._descriptors.page.listGlossaries.createStream(this._innerApiCalls.listGlossaries, request, callSettings); | ||
@@ -840,2 +868,3 @@ } | ||
close() { | ||
this.initialize(); | ||
if (!this._terminated) { | ||
@@ -842,0 +871,0 @@ return this.translationServiceStub.then(stub => { |
@@ -7,2 +7,9 @@ # Changelog | ||
## [5.3.0](https://www.github.com/googleapis/nodejs-translate/compare/v5.2.0...v5.3.0) (2020-03-06) | ||
### Features | ||
* deferred client initialization ([#460](https://www.github.com/googleapis/nodejs-translate/issues/460)) ([0ed76f4](https://www.github.com/googleapis/nodejs-translate/commit/0ed76f4e83528c2d087a26598535f5daf5a08444)) | ||
## [5.2.0](https://www.github.com/googleapis/nodejs-translate/compare/v5.1.6...v5.2.0) (2020-02-27) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "@google-cloud/translate", | ||
"description": "Cloud Translation API Client Library for Node.js", | ||
"version": "5.2.0", | ||
"version": "5.3.0", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Google Inc.", |
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
2661091
42362