Skip to content

Commit

Permalink
Update language client autogen. (#2022)
Browse files Browse the repository at this point in the history
Updates #2019
  • Loading branch information
jmuk authored and sofisl committed Oct 13, 2022
1 parent 361fbb7 commit 10cf458
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 41 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-language/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@google-cloud/common": "^0.12.0",
"arrify": "^1.0.1",
"extend": "^3.0.0",
"google-gax": "^0.10.0",
"google-gax": "^0.12.0",
"google-proto-files": "^0.9.1",
"is": "^3.0.1",
"propprop": "^0.3.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/google-cloud-language/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ function Language(options) {
return new Language(options);
}

options = extend({}, options, {
libName: 'gccl',
libVersion: require('../package.json').version
});

this.api = {
Language: v1(options).languageServiceClient(options)
};
Expand Down
9 changes: 5 additions & 4 deletions packages/google-cloud-language/src/v1/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* Copyright 2016 Google Inc. All Rights Reserved.
/*
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,8 +16,8 @@
'use strict';

var languageServiceClient = require('./language_service_client');
var extend = require('extend');
var gax = require('google-gax');
var extend = require('extend');

function v1(options) {
options = extend({
Expand All @@ -29,4 +29,5 @@ function v1(options) {

v1.SERVICE_ADDRESS = languageServiceClient.SERVICE_ADDRESS;
v1.ALL_SCOPES = languageServiceClient.ALL_SCOPES;

module.exports = v1;
64 changes: 37 additions & 27 deletions packages/google-cloud-language/src/v1/language_service_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,47 +62,64 @@ var ALL_SCOPES = [
* @class
*/
function LanguageServiceClient(gaxGrpc, grpcClients, opts) {
opts = opts || {};
var servicePath = opts.servicePath || SERVICE_ADDRESS;
var port = opts.port || DEFAULT_SERVICE_PORT;
var sslCreds = opts.sslCreds || null;
var clientConfig = opts.clientConfig || {};
var appName = opts.appName || 'gax';
var appVersion = opts.appVersion || gax.version;
opts = extend({
servicePath: SERVICE_ADDRESS,
port: DEFAULT_SERVICE_PORT,
clientConfig: {}
}, opts);

var googleApiClient = [
appName + '/' + appVersion,
CODE_GEN_NAME_VERSION,
'gl-node/' + process.versions.node,
CODE_GEN_NAME_VERSION
];
if (opts.libName && opts.libVersion) {
googleApiClient.push(opts.libName + '/' + opts.libVersion);
}
googleApiClient.push(
'gax/' + gax.version,
'nodejs/' + process.version].join(' ');
'grpc/' + gaxGrpc.grpcVersion
);

var defaults = gaxGrpc.constructSettings(
'google.cloud.language.v1.LanguageService',
configData,
clientConfig,
{'x-goog-api-client': googleApiClient});
opts.clientConfig,
{'x-goog-api-client': googleApiClient.join(' ')});

var self = this;

this.auth = gaxGrpc.auth;
var languageServiceStub = gaxGrpc.createStub(
servicePath,
port,
grpcClients.languageServiceClient.google.cloud.language.v1.LanguageService,
{sslCreds: sslCreds});
grpcClients.google.cloud.language.v1.LanguageService,
opts);
var languageServiceStubMethods = [
'analyzeSentiment',
'analyzeEntities',
'analyzeSyntax',
'annotateText'
];
languageServiceStubMethods.forEach(function(methodName) {
this['_' + methodName] = gax.createApiCall(
self['_' + methodName] = gax.createApiCall(
languageServiceStub.then(function(languageServiceStub) {
return languageServiceStub[methodName].bind(languageServiceStub);
return function() {
var args = Array.prototype.slice.call(arguments, 0);
return languageServiceStub[methodName].apply(languageServiceStub, args);
};
}),
defaults[methodName],
null);
}.bind(this));
});
}

/**
* Get the project ID used by this class.
* @aram {function(Error, string)} callback - the callback to be called with
* the current project Id.
*/
LanguageServiceClient.prototype.getProjectId = function(callback) {
return this.auth.getProjectId(callback);
};

// Service calls

/**
Expand Down Expand Up @@ -330,9 +347,6 @@ function LanguageServiceClientBuilder(gaxGrpc) {
}]);
extend(this, languageServiceClient.google.cloud.language.v1);

var grpcClients = {
languageServiceClient: languageServiceClient
};

/**
* Build a new instance of {@link LanguageServiceClient}.
Expand All @@ -347,13 +361,9 @@ function LanguageServiceClientBuilder(gaxGrpc) {
* @param {Object=} opts.clientConfig
* The customized config to build the call settings. See
* {@link gax.constructSettings} for the format.
* @param {number=} opts.appName
* The codename of the calling service.
* @param {String=} opts.appVersion
* The version of the calling service.
*/
this.languageServiceClient = function(opts) {
return new LanguageServiceClient(gaxGrpc, grpcClients, opts);
return new LanguageServiceClient(gaxGrpc, languageServiceClient, opts);
};
extend(this.languageServiceClient, LanguageServiceClient);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
"interfaces": {
"google.cloud.language.v1.LanguageService": {
"retry_codes": {
"retry_codes_def": {
"idempotent": [
"DEADLINE_EXCEEDED",
"UNAVAILABLE"
],
"non_idempotent": []
}
"idempotent": [
"DEADLINE_EXCEEDED",
"UNAVAILABLE"
],
"non_idempotent": []
},
"retry_params": {
"default": {
Expand Down
8 changes: 6 additions & 2 deletions packages/google-cloud-language/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,15 @@ describe('Language', function() {
var expectedLanguageService = {};

fakeV1Override = function(options) {
assert.strictEqual(options, OPTIONS);
var expected = {
libName: 'gccl',
libVersion: require('../package.json').version
};
assert.deepStrictEqual(options, expected);

return {
languageServiceClient: function(options) {
assert.strictEqual(options, OPTIONS);
assert.deepStrictEqual(options, expected);
return expectedLanguageService;
}
};
Expand Down

0 comments on commit 10cf458

Please sign in to comment.