diff --git a/packages/language/package.json b/packages/language/package.json index 1900078bc79..3dc5d2e631d 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -53,10 +53,9 @@ ], "dependencies": { "@google-cloud/common": "^0.6.0", - "arguejs": "^0.2.3", "arrify": "^1.0.1", "extend": "^3.0.0", - "google-gax": "^0.6.0", + "google-gax": "^0.7.0", "google-proto-files": "^0.8.0", "is": "^3.0.1", "propprop": "^0.3.1", diff --git a/packages/language/src/v1beta1/language_service_api.js b/packages/language/src/v1beta1/language_service_api.js index 14069ed8f67..2460c773334 100644 --- a/packages/language/src/v1beta1/language_service_api.js +++ b/packages/language/src/v1beta1/language_service_api.js @@ -15,7 +15,7 @@ * * EDITING INSTRUCTIONS * This file was generated from the file - * https://github.com/googleapis/googleapis/blob/master/library.proto, + * https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta1/language_service.proto, * and updates to that file get reflected here through a refresh process. * For the short term, the refresh process will only be runnable by Google * engineers. @@ -27,7 +27,6 @@ /* jscs: disable maximumLineLength */ 'use strict'; -var arguejs = require('arguejs'); var configData = require('./language_service_client_config'); var extend = require('extend'); var gax = require('google-gax'); @@ -38,7 +37,6 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; -var DEFAULT_TIMEOUT = 30; /** * The scopes needed to make gRPC calls to all of the methods defined in @@ -54,147 +52,159 @@ var ALL_SCOPES = [ * * This will be created through a builder function which can be obtained by the module. * See the following example of how to initialize the module and how to access to the builder. + * @see {@link languageServiceApi} * * @example - * var languageV1beta1 = require('@google-cloud/language').v1beta1({ - * // optional auth parameters. - * }); - * var api = languageV1beta1.languageServiceApi(); + * var languageV1beta1 = require('@google-cloud/language').v1beta1({ + * // optional auth parameters. + * }); + * var api = languageV1beta1.languageServiceApi(); * * @class - * @param {Object=} opts - The optional parameters. - * @param {String=} opts.servicePath - * The domain name of the API remote host. - * @param {number=} opts.port - * The port on which to connect to the remote host. - * @param {grpc.ClientCredentials=} opts.sslCreds - * A ClientCredentials for use with an SSL-enabled channel. - * @param {Object=} opts.clientConfig - * The customized config to build the call settings. See - * {@link gax.constructSettings} for the format. - * @param {number=} opts.timeout - * The default timeout, in seconds, for calls made through this client. - * @param {number=} opts.appName - * The codename of the calling service. - * @param {String=} opts.appVersion - * The version of the calling service. */ -function LanguageServiceApi(gaxGrpc, grpcClient, opts) { +function LanguageServiceApi(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 timeout = opts.timeout || DEFAULT_TIMEOUT; var appName = opts.appName || 'gax'; - var appVersion = opts.appVersion || gax.Version; + var appVersion = opts.appVersion || gax.version; var googleApiClient = [ appName + '/' + appVersion, CODE_GEN_NAME_VERSION, + 'gax/' + gax.version, 'nodejs/' + process.version].join(' '); var defaults = gaxGrpc.constructSettings( 'google.cloud.language.v1beta1.LanguageService', configData, clientConfig, - timeout, null, null, {'x-goog-api-client': googleApiClient}); - var stub = gaxGrpc.createStub( + var languageServiceStub = gaxGrpc.createStub( servicePath, port, - grpcClient.google.cloud.language.v1beta1.LanguageService, + grpcClients.languageServiceClient.google.cloud.language.v1beta1.LanguageService, {sslCreds: sslCreds}); - var methods = [ + var languageServiceStubMethods = [ 'analyzeSentiment', 'analyzeEntities', 'annotateText' ]; - methods.forEach(function(methodName) { + languageServiceStubMethods.forEach(function(methodName) { this['_' + methodName] = gax.createApiCall( - stub.then(function(stub) { return stub[methodName].bind(stub); }), - defaults[methodName]); + languageServiceStub.then(function(languageServiceStub) { + return languageServiceStub[methodName].bind(languageServiceStub); + }), + defaults[methodName]); }.bind(this)); } -// Callback types - -/** - * @callback APICallback - * @param {?Error} error - the error object if something goes wrong. - * Null if API succeeds. - * @param {?T} response - * The response object when API succeeds. - * @template T - */ - -/** - * @callback EmptyCallback - * @param {?Error} error - the error object if something goes wrong. - * Null if API succeeds. - */ - // Service calls /** * Analyzes the sentiment of the provided text. * - * @param {google.cloud.language.v1beta1.Document} document + * @param {Object} document * Input document. Currently, `analyzeSentiment` only supports English text * ({@link Document.language}="EN"). - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @param {APICallback=} callback + * + * This object should have the same structure as [Document]{@link Document} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeSentimentResponse]{@link AnalyzeSentimentResponse} * @returns {gax.EventEmitter} - the event emitter to handle the call * status. - * @throws an error if the RPC is aborted. + * + * @example + * + * var api = languageV1beta1.languageServiceApi(); + * var document = {}; + * api.analyzeSentiment(document, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); */ -LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment() { - var args = arguejs({ - document: Object, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment( + document, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - document: args.document + document: document }; - return this._analyzeSentiment(req, args.options, args.callback); + return this._analyzeSentiment(req, options, callback); }; /** * Finds named entities (currently finds proper names) in the text, * entity types, salience, mentions for each entity, and other properties. * - * @param {google.cloud.language.v1beta1.Document} document + * @param {Object} document * Input document. - * @param {google.cloud.language.v1beta1.EncodingType} encodingType + * + * This object should have the same structure as [Document]{@link Document} + * @param {number} encodingType * The encoding type used by the API to calculate offsets. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @param {APICallback=} callback + * + * The number should be among the values of [EncodingType]{@link EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeEntitiesResponse]{@link AnalyzeEntitiesResponse} * @returns {gax.EventEmitter} - the event emitter to handle the call * status. - * @throws an error if the RPC is aborted. + * + * @example + * + * var api = languageV1beta1.languageServiceApi(); + * var document = {}; + * var encodingType = EncodingType.NONE; + * api.analyzeEntities(document, encodingType, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); */ -LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities() { - var args = arguejs({ - document: Object, - encodingType: Number, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities( + document, + encodingType, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - document: args.document, - encoding_type: args.encodingType + document: document, + encodingType: encodingType }; - return this._analyzeEntities(req, args.options, args.callback); + return this._analyzeEntities(req, options, callback); }; /** @@ -203,49 +213,101 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities() { * API is intended for users who are familiar with machine learning and need * in-depth text features to build upon. * - * @param {google.cloud.language.v1beta1.Document} document + * @param {Object} document * Input document. - * @param {google.cloud.language.v1beta1.AnnotateTextRequest.Features} features + * + * This object should have the same structure as [Document]{@link Document} + * @param {Object} features * The enabled features. - * @param {google.cloud.language.v1beta1.EncodingType} encodingType + * + * This object should have the same structure as [Features]{@link Features} + * @param {number} encodingType * The encoding type used by the API to calculate offsets. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @param {APICallback=} callback + * + * The number should be among the values of [EncodingType]{@link EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnnotateTextResponse]{@link AnnotateTextResponse} * @returns {gax.EventEmitter} - the event emitter to handle the call * status. - * @throws an error if the RPC is aborted. + * + * @example + * + * var api = languageV1beta1.languageServiceApi(); + * var document = {}; + * var features = {}; + * var encodingType = EncodingType.NONE; + * api.annotateText(document, features, encodingType, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); */ -LanguageServiceApi.prototype.annotateText = function annotateText() { - var args = arguejs({ - document: Object, - features: Object, - encodingType: Number, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +LanguageServiceApi.prototype.annotateText = function annotateText( + document, + features, + encodingType, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - document: args.document, - features: args.features, - encoding_type: args.encodingType + document: document, + features: features, + encodingType: encodingType }; - return this._annotateText(req, args.options, args.callback); + return this._annotateText(req, options, callback); }; -module.exports = function build(gaxGrpc) { - var grpcClient = gaxGrpc.load([{ +function LanguageServiceApiBuilder(gaxGrpc) { + if (!(this instanceof LanguageServiceApiBuilder)) { + return new LanguageServiceApiBuilder(gaxGrpc); + } + + var languageServiceClient = gaxGrpc.load([{ root: require('google-proto-files')('..'), file: 'google/cloud/language/v1beta1/language_service.proto' }]); - var built = grpcClient.google.cloud.language.v1beta1; + extend(this, languageServiceClient.google.cloud.language.v1beta1); - built.languageServiceApi = function(opts) { - return new LanguageServiceApi(gaxGrpc, grpcClient, opts); + var grpcClients = { + languageServiceClient: languageServiceClient }; - extend(built.languageServiceApi, LanguageServiceApi); - return built; -}; + + /** + * Build a new instance of {@link LanguageServiceApi}. + * + * @param {Object=} opts - The optional parameters. + * @param {String=} opts.servicePath + * The domain name of the API remote host. + * @param {number=} opts.port + * The port on which to connect to the remote host. + * @param {grpc.ClientCredentials=} opts.sslCreds + * A ClientCredentials for use with an SSL-enabled channel. + * @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.languageServiceApi = function(opts) { + return new LanguageServiceApi(gaxGrpc, grpcClients, opts); + }; + extend(this.languageServiceApi, LanguageServiceApi); +} +module.exports = LanguageServiceApiBuilder; module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file diff --git a/packages/logging/package.json b/packages/logging/package.json index 8b5646f9b66..e3f6e1d948b 100644 --- a/packages/logging/package.json +++ b/packages/logging/package.json @@ -53,10 +53,9 @@ ], "dependencies": { "@google-cloud/common": "^0.6.0", - "arguejs": "^0.2.3", "arrify": "^1.0.0", "extend": "^3.0.0", - "google-gax": "^0.6.0", + "google-gax": "^0.7.0", "google-proto-files": "^0.8.0", "is": "^3.0.1", "string-format-obj": "^1.0.0" diff --git a/packages/logging/src/v2/config_service_v2_api.js b/packages/logging/src/v2/config_service_v2_api.js index 2c0648a50c6..a6e8a921296 100644 --- a/packages/logging/src/v2/config_service_v2_api.js +++ b/packages/logging/src/v2/config_service_v2_api.js @@ -27,7 +27,6 @@ /* jscs: disable maximumLineLength */ 'use strict'; -var arguejs = require('arguejs'); var configData = require('./config_service_v2_client_config'); var extend = require('extend'); var gax = require('google-gax'); @@ -38,12 +37,11 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; -var DEFAULT_TIMEOUT = 30; var PAGE_DESCRIPTORS = { listSinks: new gax.PageDescriptor( - 'page_token', - 'next_page_token', + 'pageToken', + 'nextPageToken', 'sinks') }; @@ -75,46 +73,47 @@ var ALL_SCOPES = [ * * @class */ -function ConfigServiceV2Api(gaxGrpc, grpcClient, opts) { +function ConfigServiceV2Api(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 timeout = opts.timeout || DEFAULT_TIMEOUT; var appName = opts.appName || 'gax'; - var appVersion = opts.appVersion || gax.Version; + var appVersion = opts.appVersion || gax.version; var googleApiClient = [ appName + '/' + appVersion, CODE_GEN_NAME_VERSION, + 'gax/' + gax.version, 'nodejs/' + process.version].join(' '); var defaults = gaxGrpc.constructSettings( 'google.logging.v2.ConfigServiceV2', configData, clientConfig, - timeout, PAGE_DESCRIPTORS, null, {'x-goog-api-client': googleApiClient}); - var stub = gaxGrpc.createStub( + var configServiceV2Stub = gaxGrpc.createStub( servicePath, port, - grpcClient.google.logging.v2.ConfigServiceV2, + grpcClients.configServiceV2Client.google.logging.v2.ConfigServiceV2, {sslCreds: sslCreds}); - var methods = [ + var configServiceV2StubMethods = [ 'listSinks', 'getSink', 'createSink', 'updateSink', 'deleteSink' ]; - methods.forEach(function(methodName) { + configServiceV2StubMethods.forEach(function(methodName) { this['_' + methodName] = gax.createApiCall( - stub.then(function(stub) { return stub[methodName].bind(stub); }), - defaults[methodName]); + configServiceV2Stub.then(function(configServiceV2Stub) { + return configServiceV2Stub[methodName].bind(configServiceV2Stub); + }), + defaults[methodName]); }.bind(this)); } @@ -189,57 +188,84 @@ ConfigServiceV2Api.prototype.matchSinkFromSinkName = * Lists sinks. * * @param {string} parent - * Required. The resource name containing the sinks. + * Required. The cloud resource containing the sinks. * Example: `"projects/my-logging-project"`. - * @param {Object=} otherArgs - * @param {number=} otherArgs.pageSize + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {number=} options.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this * parameter does not affect the return value. If page streaming is * performed per-page, this determines the maximum number of * resources in a page. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @returns {Stream} - * An object stream. By default, this emits an object representing + * + * @param {function(?Error, ?Object, ?string)=} callback + * When specified, the results are not streamed but this callback + * will be called with the response object representing [ListSinksResponse]{@link ListSinksResponse}. + * The third item will be set if the response contains the token for the further results + * and can be reused to `pageToken` field in the options in the next request. + * @returns {Stream|gax.EventEmitter} + * An object stream which emits an object representing * [LogSink]{@link LogSink} on 'data' event. - * This object can also be configured to emit - * pages of the responses through the options parameter. + * When the callback is specified or streaming is suppressed through options, + * it will return an event emitter to handle the call status and the callback + * will be called with the response object. * * @example * * var api = loggingV2.configServiceV2Api(); * var formattedParent = api.parentPath("[PROJECT]"); + * // Iterate over all elements. * api.listSinks(formattedParent).on('data', function(element) { * // doThingsWith(element) * }); + * + * // Or obtain the paged response through the callback. + * function callback(err, response, nextPageToken) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * if (nextPageToken) { + * // fetch the next page. + * api.listSinks(formattedParent, {pageToken: nextPageToken}, callback); + * } + * } + * api.listSinks(formattedParent, {flattenPages: false}, callback); */ -ConfigServiceV2Api.prototype.listSinks = function listSinks() { - var args = arguejs({ - parent: String, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +ConfigServiceV2Api.prototype.listSinks = function listSinks( + parent, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - parent: args.parent + parent: parent }; - if ('pageSize' in args.otherArgs) { - req.page_size = args.otherArgs.pageSize; + if ('pageSize' in options) { + req.pageSize = options.pageSize; } - return this._listSinks(req, args.options, args.callback); + return this._listSinks(req, options, callback); }; /** * Gets a sink. * * @param {string} sinkName - * The resource name of the sink to return. + * Required. The resource name of the sink to return. * Example: `"projects/my-project-id/sinks/my-sink-id"`. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -259,34 +285,38 @@ ConfigServiceV2Api.prototype.listSinks = function listSinks() { * // doThingsWith(response) * }); */ -ConfigServiceV2Api.prototype.getSink = function getSink() { - var args = arguejs({ - sinkName: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +ConfigServiceV2Api.prototype.getSink = function getSink( + sinkName, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - sink_name: args.sinkName + sinkName: sinkName }; - return this._getSink(req, args.options, args.callback); + return this._getSink(req, options, callback); }; /** * Creates a sink. * * @param {string} parent - * The resource in which to create the sink. + * Required. The resource in which to create the sink. * Example: `"projects/my-project-id"`. - * * The new sink must be provided in the request. * @param {Object} sink - * The new sink, which must not have an identifier that already - * exists. + * Required. The new sink, whose `name` parameter is a sink identifier that + * is not already in use. * * This object should have the same structure as [LogSink]{@link LogSink} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -307,39 +337,41 @@ ConfigServiceV2Api.prototype.getSink = function getSink() { * // doThingsWith(response) * }); */ -ConfigServiceV2Api.prototype.createSink = function createSink() { - var args = arguejs({ - parent: String, - sink: Object, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +ConfigServiceV2Api.prototype.createSink = function createSink( + parent, + sink, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - parent: args.parent, - sink: args.sink + parent: parent, + sink: sink }; - return this._createSink(req, args.options, args.callback); + return this._createSink(req, options, callback); }; /** - * Creates or updates a sink. + * Updates or creates a sink. * * @param {string} sinkName - * The resource name of the sink to update. - * Example: `"projects/my-project-id/sinks/my-sink-id"`. - * - * The updated sink must be provided in the request and have the - * same name that is specified in `sinkName`. If the sink does not - * exist, it is created. + * Required. The resource name of the sink to update, including the parent + * resource and the sink identifier. If the sink does not exist, this method + * creates the sink. Example: `"projects/my-project-id/sinks/my-sink-id"`. * @param {Object} sink - * The updated sink, whose name must be the same as the sink - * identifier in `sinkName`. If `sinkName` does not exist, then + * Required. The updated sink, whose name is the same identifier that appears + * as part of `sinkName`. If `sinkName` does not exist, then * this method creates a new sink. * * This object should have the same structure as [LogSink]{@link LogSink} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -360,29 +392,36 @@ ConfigServiceV2Api.prototype.createSink = function createSink() { * // doThingsWith(response) * }); */ -ConfigServiceV2Api.prototype.updateSink = function updateSink() { - var args = arguejs({ - sinkName: String, - sink: Object, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +ConfigServiceV2Api.prototype.updateSink = function updateSink( + sinkName, + sink, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - sink_name: args.sinkName, - sink: args.sink + sinkName: sinkName, + sink: sink }; - return this._updateSink(req, args.options, args.callback); + return this._updateSink(req, options, callback); }; /** * Deletes a sink. * * @param {string} sinkName - * The resource name of the sink to delete. - * Example: `"projects/my-project-id/sinks/my-sink-id"`. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * Required. The resource name of the sink to delete, including the parent + * resource and the sink identifier. Example: + * `"projects/my-project-id/sinks/my-sink-id"`. It is an error if the sink + * does not exist. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. * @returns {gax.EventEmitter} - the event emitter to handle the call @@ -398,16 +437,21 @@ ConfigServiceV2Api.prototype.updateSink = function updateSink() { * } * }); */ -ConfigServiceV2Api.prototype.deleteSink = function deleteSink() { - var args = arguejs({ - sinkName: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +ConfigServiceV2Api.prototype.deleteSink = function deleteSink( + sinkName, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - sink_name: args.sinkName + sinkName: sinkName }; - return this._deleteSink(req, args.options, args.callback); + return this._deleteSink(req, options, callback); }; function ConfigServiceV2ApiBuilder(gaxGrpc) { @@ -415,11 +459,15 @@ function ConfigServiceV2ApiBuilder(gaxGrpc) { return new ConfigServiceV2ApiBuilder(gaxGrpc); } - var grpcClient = gaxGrpc.load([{ + var configServiceV2Client = gaxGrpc.load([{ root: require('google-proto-files')('..'), file: 'google/logging/v2/logging_config.proto' }]); - extend(this, grpcClient.google.logging.v2); + extend(this, configServiceV2Client.google.logging.v2); + + var grpcClients = { + configServiceV2Client: configServiceV2Client + }; /** * Build a new instance of {@link ConfigServiceV2Api}. @@ -434,15 +482,13 @@ function ConfigServiceV2ApiBuilder(gaxGrpc) { * @param {Object=} opts.clientConfig * The customized config to build the call settings. See * {@link gax.constructSettings} for the format. - * @param {number=} opts.timeout - * The default timeout, in seconds, for calls made through this client. * @param {number=} opts.appName * The codename of the calling service. * @param {String=} opts.appVersion * The version of the calling service. */ this.configServiceV2Api = function(opts) { - return new ConfigServiceV2Api(gaxGrpc, grpcClient, opts); + return new ConfigServiceV2Api(gaxGrpc, grpcClients, opts); }; extend(this.configServiceV2Api, ConfigServiceV2Api); } diff --git a/packages/logging/src/v2/logging_service_v2_api.js b/packages/logging/src/v2/logging_service_v2_api.js index f233264f82f..919cbb245bf 100644 --- a/packages/logging/src/v2/logging_service_v2_api.js +++ b/packages/logging/src/v2/logging_service_v2_api.js @@ -27,7 +27,6 @@ /* jscs: disable maximumLineLength */ 'use strict'; -var arguejs = require('arguejs'); var configData = require('./logging_service_v2_client_config'); var extend = require('extend'); var gax = require('google-gax'); @@ -38,17 +37,16 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; -var DEFAULT_TIMEOUT = 30; var PAGE_DESCRIPTORS = { listLogEntries: new gax.PageDescriptor( - 'page_token', - 'next_page_token', + 'pageToken', + 'nextPageToken', 'entries'), listMonitoredResourceDescriptors: new gax.PageDescriptor( - 'page_token', - 'next_page_token', - 'resource_descriptors') + 'pageToken', + 'nextPageToken', + 'resourceDescriptors') }; /** @@ -78,45 +76,46 @@ var ALL_SCOPES = [ * * @class */ -function LoggingServiceV2Api(gaxGrpc, grpcClient, opts) { +function LoggingServiceV2Api(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 timeout = opts.timeout || DEFAULT_TIMEOUT; var appName = opts.appName || 'gax'; - var appVersion = opts.appVersion || gax.Version; + var appVersion = opts.appVersion || gax.version; var googleApiClient = [ appName + '/' + appVersion, CODE_GEN_NAME_VERSION, + 'gax/' + gax.version, 'nodejs/' + process.version].join(' '); var defaults = gaxGrpc.constructSettings( 'google.logging.v2.LoggingServiceV2', configData, clientConfig, - timeout, PAGE_DESCRIPTORS, null, {'x-goog-api-client': googleApiClient}); - var stub = gaxGrpc.createStub( + var loggingServiceV2Stub = gaxGrpc.createStub( servicePath, port, - grpcClient.google.logging.v2.LoggingServiceV2, + grpcClients.loggingServiceV2Client.google.logging.v2.LoggingServiceV2, {sslCreds: sslCreds}); - var methods = [ + var loggingServiceV2StubMethods = [ 'deleteLog', 'writeLogEntries', 'listLogEntries', 'listMonitoredResourceDescriptors' ]; - methods.forEach(function(methodName) { + loggingServiceV2StubMethods.forEach(function(methodName) { this['_' + methodName] = gax.createApiCall( - stub.then(function(stub) { return stub[methodName].bind(stub); }), - defaults[methodName]); + loggingServiceV2Stub.then(function(loggingServiceV2Stub) { + return loggingServiceV2Stub[methodName].bind(loggingServiceV2Stub); + }), + defaults[methodName]); }.bind(this)); } @@ -194,9 +193,9 @@ LoggingServiceV2Api.prototype.matchLogFromLogName = * @param {string} logName * Required. The resource name of the log to delete. Example: * `"projects/my-project/logs/syslog"`. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. * @returns {gax.EventEmitter} - the event emitter to handle the call @@ -212,16 +211,21 @@ LoggingServiceV2Api.prototype.matchLogFromLogName = * } * }); */ -LoggingServiceV2Api.prototype.deleteLog = function deleteLog() { - var args = arguejs({ - logName: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +LoggingServiceV2Api.prototype.deleteLog = function deleteLog( + logName, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - log_name: args.logName + logName: logName }; - return this._deleteLog(req, args.options, args.callback); + return this._deleteLog(req, options, callback); }; /** @@ -229,39 +233,50 @@ LoggingServiceV2Api.prototype.deleteLog = function deleteLog() { * written by this method. * * @param {Object[]} entries - * Required. The log entries to write. The log entries must have values for - * all required fields. + * Required. The log entries to write. Values supplied for the fields + * `log_name`, `resource`, and `labels` in this `entries.write` request are + * added to those log entries that do not provide their own values for the + * fields. * - * To improve throughput and to avoid exceeding the quota limit for calls - * to `entries.write`, use this field to write multiple log entries at once - * rather than // calling this method for each log entry. + * To improve throughput and to avoid exceeding the + * [quota limit](https://cloud.google.com/logging/quota-policy) for calls to `entries.write`, + * you should write multiple log entries at once rather than + * calling this method for each individual log entry. * * This object should have the same structure as [LogEntry]{@link LogEntry} - * @param {Object=} otherArgs - * @param {string=} otherArgs.logName - * Optional. A default log resource name for those log entries in `entries` - * that do not specify their own `logName`. Example: + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {string=} options.logName + * Optional. A default log resource name that is assigned to all log entries + * in `entries` that do not specify a value for `log_name`. Example: * `"projects/my-project/logs/syslog"`. See * {@link LogEntry}. - * @param {Object=} otherArgs.resource - * Optional. A default monitored resource for those log entries in `entries` - * that do not specify their own `resource`. + * @param {Object=} options.resource + * Optional. A default monitored resource object that is assigned to all log + * entries in `entries` that do not specify a value for `resource`. Example: + * + * { "type": "gce_instance", + * "labels": { + * "zone": "us-central1-a", "instance_id": "00000000000000000000" }} + * + * See {@link LogEntry}. * * This object should have the same structure as [google.api.MonitoredResource]{@link external:"google.api.MonitoredResource"} - * @param {Object.=} otherArgs.labels - * Optional. User-defined `key:value` items that are added to - * the `labels` field of each log entry in `entries`, except when a log - * entry specifies its own `key:value` item with the same key. - * Example: `{ "size": "large", "color":"red" }` - * @param {boolean=} otherArgs.partialSuccess + * @param {Object.=} options.labels + * Optional. Default labels that are added to the `labels` field of all log + * entries in `entries`. If a log entry already has a label with the same key + * as a label in this parameter, then the log entry's label is not changed. + * See {@link LogEntry}. + * @param {boolean=} options.partialSuccess * Optional. Whether valid entries should be written even if some other * entries fail due to INVALID_ARGUMENT or PERMISSION_DENIED errors. If any * entry is not written, the response status will be the error associated * with one of the failed entries and include error details in the form of * WriteLogEntriesPartialErrors. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -281,29 +296,33 @@ LoggingServiceV2Api.prototype.deleteLog = function deleteLog() { * // doThingsWith(response) * }); */ -LoggingServiceV2Api.prototype.writeLogEntries = function writeLogEntries() { - var args = arguejs({ - entries: Array, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +LoggingServiceV2Api.prototype.writeLogEntries = function writeLogEntries( + entries, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - entries: args.entries + entries: entries }; - if ('logName' in args.otherArgs) { - req.log_name = args.otherArgs.logName; + if ('logName' in options) { + req.logName = options.logName; } - if ('resource' in args.otherArgs) { - req.resource = args.otherArgs.resource; + if ('resource' in options) { + req.resource = options.resource; } - if ('labels' in args.otherArgs) { - req.labels = args.otherArgs.labels; + if ('labels' in options) { + req.labels = options.labels; } - if ('partialSuccess' in args.otherArgs) { - req.partial_success = args.otherArgs.partialSuccess; + if ('partialSuccess' in options) { + req.partialSuccess = options.partialSuccess; } - return this._writeLogEntries(req, args.options, args.callback); + return this._writeLogEntries(req, options, callback); }; /** @@ -312,105 +331,169 @@ LoggingServiceV2Api.prototype.writeLogEntries = function writeLogEntries() { * [Exporting Logs](https://cloud.google.com/logging/docs/export). * * @param {string[]} projectIds - * Required. One or more project IDs or project numbers from which to retrieve - * log entries. Examples of a project ID: `"my-project-1A"`, `"1234567890"`. - * @param {Object=} otherArgs - * @param {string=} otherArgs.filter - * Optional. An [advanced logs filter](https://cloud.google.com/logging/docs/view/advanced_filters). - * The filter is compared against all log entries in the projects specified by - * `projectIds`. Only entries that match the filter are retrieved. An empty - * filter matches all log entries. - * @param {string=} otherArgs.orderBy + * Deprecated. One or more project identifiers or project numbers from which + * to retrieve log entries. Examples: `"my-project-1A"`, `"1234567890"`. If + * present, these project identifiers are converted to resource format and + * added to the list of resources in `resourceNames`. Callers should use + * `resourceNames` rather than this parameter. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {string[]=} options.resourceNames + * Optional. One or more cloud resources from which to retrieve log entries. + * Example: `"projects/my-project-1A"`, `"projects/1234567890"`. Projects + * listed in `projectIds` are added to this list. + * @param {string=} options.filter + * Optional. A filter that chooses which log entries to return. See [Advanced + * Logs Filters](https://cloud.google.com/logging/docs/view/advanced_filters). Only log entries that + * match the filter are returned. An empty filter matches all log entries. + * @param {string=} options.orderBy * Optional. How the results should be sorted. Presently, the only permitted * values are `"timestamp asc"` (default) and `"timestamp desc"`. The first * option returns entries in order of increasing values of * `LogEntry.timestamp` (oldest first), and the second option returns entries * in order of decreasing timestamps (newest first). Entries with equal * timestamps are returned in order of `LogEntry.insertId`. - * @param {number=} otherArgs.pageSize + * @param {number=} options.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this * parameter does not affect the return value. If page streaming is * performed per-page, this determines the maximum number of * resources in a page. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @returns {Stream} - * An object stream. By default, this emits an object representing + * + * @param {function(?Error, ?Object, ?string)=} callback + * When specified, the results are not streamed but this callback + * will be called with the response object representing [ListLogEntriesResponse]{@link ListLogEntriesResponse}. + * The third item will be set if the response contains the token for the further results + * and can be reused to `pageToken` field in the options in the next request. + * @returns {Stream|gax.EventEmitter} + * An object stream which emits an object representing * [LogEntry]{@link LogEntry} on 'data' event. - * This object can also be configured to emit - * pages of the responses through the options parameter. + * When the callback is specified or streaming is suppressed through options, + * it will return an event emitter to handle the call status and the callback + * will be called with the response object. * * @example * * var api = loggingV2.loggingServiceV2Api(); * var projectIds = []; + * // Iterate over all elements. * api.listLogEntries(projectIds).on('data', function(element) { * // doThingsWith(element) * }); + * + * // Or obtain the paged response through the callback. + * function callback(err, response, nextPageToken) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * if (nextPageToken) { + * // fetch the next page. + * api.listLogEntries(projectIds, {pageToken: nextPageToken}, callback); + * } + * } + * api.listLogEntries(projectIds, {flattenPages: false}, callback); */ -LoggingServiceV2Api.prototype.listLogEntries = function listLogEntries() { - var args = arguejs({ - projectIds: Array, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +LoggingServiceV2Api.prototype.listLogEntries = function listLogEntries( + projectIds, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - project_ids: args.projectIds + projectIds: projectIds }; - if ('filter' in args.otherArgs) { - req.filter = args.otherArgs.filter; + if ('resourceNames' in options) { + req.resourceNames = options.resourceNames; } - if ('orderBy' in args.otherArgs) { - req.order_by = args.otherArgs.orderBy; + if ('filter' in options) { + req.filter = options.filter; } - if ('pageSize' in args.otherArgs) { - req.page_size = args.otherArgs.pageSize; + if ('orderBy' in options) { + req.orderBy = options.orderBy; } - return this._listLogEntries(req, args.options, args.callback); + if ('pageSize' in options) { + req.pageSize = options.pageSize; + } + return this._listLogEntries(req, options, callback); }; /** * Lists the monitored resource descriptors used by Stackdriver Logging. * - * @param {Object=} otherArgs - * @param {number=} otherArgs.pageSize + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {number=} options.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this * parameter does not affect the return value. If page streaming is * performed per-page, this determines the maximum number of * resources in a page. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @returns {Stream} - * An object stream. By default, this emits an object representing + * + * @param {function(?Error, ?Object, ?string)=} callback + * When specified, the results are not streamed but this callback + * will be called with the response object representing [ListMonitoredResourceDescriptorsResponse]{@link ListMonitoredResourceDescriptorsResponse}. + * The third item will be set if the response contains the token for the further results + * and can be reused to `pageToken` field in the options in the next request. + * @returns {Stream|gax.EventEmitter} + * An object stream which emits an object representing * [google.api.MonitoredResourceDescriptor]{@link external:"google.api.MonitoredResourceDescriptor"} on 'data' event. - * This object can also be configured to emit - * pages of the responses through the options parameter. + * When the callback is specified or streaming is suppressed through options, + * it will return an event emitter to handle the call status and the callback + * will be called with the response object. * * @example * * var api = loggingV2.loggingServiceV2Api(); * + * // Iterate over all elements. * api.listMonitoredResourceDescriptors().on('data', function(element) { * // doThingsWith(element) * }); + * + * // Or obtain the paged response through the callback. + * function callback(err, response, nextPageToken) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * if (nextPageToken) { + * // fetch the next page. + * api.listMonitoredResourceDescriptors({pageToken: nextPageToken}, callback); + * } + * } + * api.listMonitoredResourceDescriptors({flattenPages: false}, callback); + * api.listMonitoredResourceDescriptors(function(err, response) { */ -LoggingServiceV2Api.prototype.listMonitoredResourceDescriptors = function listMonitoredResourceDescriptors() { - var args = arguejs({ - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +LoggingServiceV2Api.prototype.listMonitoredResourceDescriptors = function listMonitoredResourceDescriptors( + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { }; - if ('pageSize' in args.otherArgs) { - req.page_size = args.otherArgs.pageSize; + if ('pageSize' in options) { + req.pageSize = options.pageSize; } - return this._listMonitoredResourceDescriptors(req, args.options, args.callback); + return this._listMonitoredResourceDescriptors(req, options, callback); }; function LoggingServiceV2ApiBuilder(gaxGrpc) { @@ -418,11 +501,15 @@ function LoggingServiceV2ApiBuilder(gaxGrpc) { return new LoggingServiceV2ApiBuilder(gaxGrpc); } - var grpcClient = gaxGrpc.load([{ + var loggingServiceV2Client = gaxGrpc.load([{ root: require('google-proto-files')('..'), file: 'google/logging/v2/logging.proto' }]); - extend(this, grpcClient.google.logging.v2); + extend(this, loggingServiceV2Client.google.logging.v2); + + var grpcClients = { + loggingServiceV2Client: loggingServiceV2Client + }; /** * Build a new instance of {@link LoggingServiceV2Api}. @@ -437,15 +524,13 @@ function LoggingServiceV2ApiBuilder(gaxGrpc) { * @param {Object=} opts.clientConfig * The customized config to build the call settings. See * {@link gax.constructSettings} for the format. - * @param {number=} opts.timeout - * The default timeout, in seconds, for calls made through this client. * @param {number=} opts.appName * The codename of the calling service. * @param {String=} opts.appVersion * The version of the calling service. */ this.loggingServiceV2Api = function(opts) { - return new LoggingServiceV2Api(gaxGrpc, grpcClient, opts); + return new LoggingServiceV2Api(gaxGrpc, grpcClients, opts); }; extend(this.loggingServiceV2Api, LoggingServiceV2Api); } diff --git a/packages/logging/src/v2/metrics_service_v2_api.js b/packages/logging/src/v2/metrics_service_v2_api.js index 55f5adb5353..0f27f45b188 100644 --- a/packages/logging/src/v2/metrics_service_v2_api.js +++ b/packages/logging/src/v2/metrics_service_v2_api.js @@ -27,7 +27,6 @@ /* jscs: disable maximumLineLength */ 'use strict'; -var arguejs = require('arguejs'); var configData = require('./metrics_service_v2_client_config'); var extend = require('extend'); var gax = require('google-gax'); @@ -38,12 +37,11 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; -var DEFAULT_TIMEOUT = 30; var PAGE_DESCRIPTORS = { listLogMetrics: new gax.PageDescriptor( - 'page_token', - 'next_page_token', + 'pageToken', + 'nextPageToken', 'metrics') }; @@ -74,46 +72,47 @@ var ALL_SCOPES = [ * * @class */ -function MetricsServiceV2Api(gaxGrpc, grpcClient, opts) { +function MetricsServiceV2Api(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 timeout = opts.timeout || DEFAULT_TIMEOUT; var appName = opts.appName || 'gax'; - var appVersion = opts.appVersion || gax.Version; + var appVersion = opts.appVersion || gax.version; var googleApiClient = [ appName + '/' + appVersion, CODE_GEN_NAME_VERSION, + 'gax/' + gax.version, 'nodejs/' + process.version].join(' '); var defaults = gaxGrpc.constructSettings( 'google.logging.v2.MetricsServiceV2', configData, clientConfig, - timeout, PAGE_DESCRIPTORS, null, {'x-goog-api-client': googleApiClient}); - var stub = gaxGrpc.createStub( + var metricsServiceV2Stub = gaxGrpc.createStub( servicePath, port, - grpcClient.google.logging.v2.MetricsServiceV2, + grpcClients.metricsServiceV2Client.google.logging.v2.MetricsServiceV2, {sslCreds: sslCreds}); - var methods = [ + var metricsServiceV2StubMethods = [ 'listLogMetrics', 'getLogMetric', 'createLogMetric', 'updateLogMetric', 'deleteLogMetric' ]; - methods.forEach(function(methodName) { + metricsServiceV2StubMethods.forEach(function(methodName) { this['_' + methodName] = gax.createApiCall( - stub.then(function(stub) { return stub[methodName].bind(stub); }), - defaults[methodName]); + metricsServiceV2Stub.then(function(metricsServiceV2Stub) { + return metricsServiceV2Stub[methodName].bind(metricsServiceV2Stub); + }), + defaults[methodName]); }.bind(this)); } @@ -190,44 +189,71 @@ MetricsServiceV2Api.prototype.matchMetricFromMetricName = * @param {string} parent * Required. The resource name containing the metrics. * Example: `"projects/my-project-id"`. - * @param {Object=} otherArgs - * @param {number=} otherArgs.pageSize + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {number=} options.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this * parameter does not affect the return value. If page streaming is * performed per-page, this determines the maximum number of * resources in a page. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @returns {Stream} - * An object stream. By default, this emits an object representing + * + * @param {function(?Error, ?Object, ?string)=} callback + * When specified, the results are not streamed but this callback + * will be called with the response object representing [ListLogMetricsResponse]{@link ListLogMetricsResponse}. + * The third item will be set if the response contains the token for the further results + * and can be reused to `pageToken` field in the options in the next request. + * @returns {Stream|gax.EventEmitter} + * An object stream which emits an object representing * [LogMetric]{@link LogMetric} on 'data' event. - * This object can also be configured to emit - * pages of the responses through the options parameter. + * When the callback is specified or streaming is suppressed through options, + * it will return an event emitter to handle the call status and the callback + * will be called with the response object. * * @example * * var api = loggingV2.metricsServiceV2Api(); * var formattedParent = api.parentPath("[PROJECT]"); + * // Iterate over all elements. * api.listLogMetrics(formattedParent).on('data', function(element) { * // doThingsWith(element) * }); + * + * // Or obtain the paged response through the callback. + * function callback(err, response, nextPageToken) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * if (nextPageToken) { + * // fetch the next page. + * api.listLogMetrics(formattedParent, {pageToken: nextPageToken}, callback); + * } + * } + * api.listLogMetrics(formattedParent, {flattenPages: false}, callback); */ -MetricsServiceV2Api.prototype.listLogMetrics = function listLogMetrics() { - var args = arguejs({ - parent: String, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +MetricsServiceV2Api.prototype.listLogMetrics = function listLogMetrics( + parent, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - parent: args.parent + parent: parent }; - if ('pageSize' in args.otherArgs) { - req.page_size = args.otherArgs.pageSize; + if ('pageSize' in options) { + req.pageSize = options.pageSize; } - return this._listLogMetrics(req, args.options, args.callback); + return this._listLogMetrics(req, options, callback); }; /** @@ -236,9 +262,9 @@ MetricsServiceV2Api.prototype.listLogMetrics = function listLogMetrics() { * @param {string} metricName * The resource name of the desired metric. * Example: `"projects/my-project-id/metrics/my-metric-id"`. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -258,16 +284,21 @@ MetricsServiceV2Api.prototype.listLogMetrics = function listLogMetrics() { * // doThingsWith(response) * }); */ -MetricsServiceV2Api.prototype.getLogMetric = function getLogMetric() { - var args = arguejs({ - metricName: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +MetricsServiceV2Api.prototype.getLogMetric = function getLogMetric( + metricName, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - metric_name: args.metricName + metricName: metricName }; - return this._getLogMetric(req, args.options, args.callback); + return this._getLogMetric(req, options, callback); }; /** @@ -283,9 +314,9 @@ MetricsServiceV2Api.prototype.getLogMetric = function getLogMetric() { * already exists. * * This object should have the same structure as [LogMetric]{@link LogMetric} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -306,18 +337,23 @@ MetricsServiceV2Api.prototype.getLogMetric = function getLogMetric() { * // doThingsWith(response) * }); */ -MetricsServiceV2Api.prototype.createLogMetric = function createLogMetric() { - var args = arguejs({ - parent: String, - metric: Object, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +MetricsServiceV2Api.prototype.createLogMetric = function createLogMetric( + parent, + metric, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - parent: args.parent, - metric: args.metric + parent: parent, + metric: metric }; - return this._createLogMetric(req, args.options, args.callback); + return this._createLogMetric(req, options, callback); }; /** @@ -336,9 +372,9 @@ MetricsServiceV2Api.prototype.createLogMetric = function createLogMetric() { * exist, then a new metric is created. * * This object should have the same structure as [LogMetric]{@link LogMetric} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -359,18 +395,23 @@ MetricsServiceV2Api.prototype.createLogMetric = function createLogMetric() { * // doThingsWith(response) * }); */ -MetricsServiceV2Api.prototype.updateLogMetric = function updateLogMetric() { - var args = arguejs({ - metricName: String, - metric: Object, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +MetricsServiceV2Api.prototype.updateLogMetric = function updateLogMetric( + metricName, + metric, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - metric_name: args.metricName, - metric: args.metric + metricName: metricName, + metric: metric }; - return this._updateLogMetric(req, args.options, args.callback); + return this._updateLogMetric(req, options, callback); }; /** @@ -379,9 +420,9 @@ MetricsServiceV2Api.prototype.updateLogMetric = function updateLogMetric() { * @param {string} metricName * The resource name of the metric to delete. * Example: `"projects/my-project-id/metrics/my-metric-id"`. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. * @returns {gax.EventEmitter} - the event emitter to handle the call @@ -397,16 +438,21 @@ MetricsServiceV2Api.prototype.updateLogMetric = function updateLogMetric() { * } * }); */ -MetricsServiceV2Api.prototype.deleteLogMetric = function deleteLogMetric() { - var args = arguejs({ - metricName: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +MetricsServiceV2Api.prototype.deleteLogMetric = function deleteLogMetric( + metricName, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - metric_name: args.metricName + metricName: metricName }; - return this._deleteLogMetric(req, args.options, args.callback); + return this._deleteLogMetric(req, options, callback); }; function MetricsServiceV2ApiBuilder(gaxGrpc) { @@ -414,11 +460,15 @@ function MetricsServiceV2ApiBuilder(gaxGrpc) { return new MetricsServiceV2ApiBuilder(gaxGrpc); } - var grpcClient = gaxGrpc.load([{ + var metricsServiceV2Client = gaxGrpc.load([{ root: require('google-proto-files')('..'), file: 'google/logging/v2/logging_metrics.proto' }]); - extend(this, grpcClient.google.logging.v2); + extend(this, metricsServiceV2Client.google.logging.v2); + + var grpcClients = { + metricsServiceV2Client: metricsServiceV2Client + }; /** * Build a new instance of {@link MetricsServiceV2Api}. @@ -433,15 +483,13 @@ function MetricsServiceV2ApiBuilder(gaxGrpc) { * @param {Object=} opts.clientConfig * The customized config to build the call settings. See * {@link gax.constructSettings} for the format. - * @param {number=} opts.timeout - * The default timeout, in seconds, for calls made through this client. * @param {number=} opts.appName * The codename of the calling service. * @param {String=} opts.appVersion * The version of the calling service. */ this.metricsServiceV2Api = function(opts) { - return new MetricsServiceV2Api(gaxGrpc, grpcClient, opts); + return new MetricsServiceV2Api(gaxGrpc, grpcClients, opts); }; extend(this.metricsServiceV2Api, MetricsServiceV2Api); } diff --git a/packages/pubsub/package.json b/packages/pubsub/package.json index 03c48ec2653..55438b3aa8d 100644 --- a/packages/pubsub/package.json +++ b/packages/pubsub/package.json @@ -51,10 +51,10 @@ ], "dependencies": { "@google-cloud/common": "^0.6.0", - "arguejs": "^0.2.3", "arrify": "^1.0.0", "extend": "^3.0.0", - "google-gax": "^0.6.0", + "google-gax": "^0.7.0", + "google-proto-files": "^0.8.0", "is": "^3.0.1", "modelo": "^4.2.0", "propprop": "^0.3.0" diff --git a/packages/pubsub/src/v1/publisher_api.js b/packages/pubsub/src/v1/publisher_api.js index 7b5751a5d8b..1cdc9d7551c 100644 --- a/packages/pubsub/src/v1/publisher_api.js +++ b/packages/pubsub/src/v1/publisher_api.js @@ -27,7 +27,6 @@ /* jscs: disable maximumLineLength */ 'use strict'; -var arguejs = require('arguejs'); var configData = require('./publisher_client_config'); var extend = require('extend'); var gax = require('google-gax'); @@ -38,16 +37,15 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; -var DEFAULT_TIMEOUT = 30; var PAGE_DESCRIPTORS = { listTopics: new gax.PageDescriptor( - 'page_token', - 'next_page_token', + 'pageToken', + 'nextPageToken', 'topics'), listTopicSubscriptions: new gax.PageDescriptor( - 'page_token', - 'next_page_token', + 'pageToken', + 'nextPageToken', 'subscriptions') }; @@ -76,19 +74,19 @@ var ALL_SCOPES = [ * * @class */ -function PublisherApi(gaxGrpc, grpcClient, opts) { +function PublisherApi(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 timeout = opts.timeout || DEFAULT_TIMEOUT; var appName = opts.appName || 'gax'; - var appVersion = opts.appVersion || gax.Version; + var appVersion = opts.appVersion || gax.version; var googleApiClient = [ appName + '/' + appVersion, CODE_GEN_NAME_VERSION, + 'gax/' + gax.version, 'nodejs/' + process.version].join(' '); @@ -98,24 +96,41 @@ function PublisherApi(gaxGrpc, grpcClient, opts) { [ 'topic' ], - 'message_ids', - gax.createByteLengthFunction(grpcClient.google.pubsub.v1.PubsubMessage)) + 'messageIds', + gax.createByteLengthFunction(grpcClients.publisherClient.google.pubsub.v1.PubsubMessage)) }; var defaults = gaxGrpc.constructSettings( 'google.pubsub.v1.Publisher', configData, clientConfig, - timeout, PAGE_DESCRIPTORS, bundleDescriptors, {'x-goog-api-client': googleApiClient}); - var stub = gaxGrpc.createStub( + var iamPolicyStub = gaxGrpc.createStub( servicePath, port, - grpcClient.google.pubsub.v1.Publisher, + grpcClients.iamPolicyClient.google.iam.v1.IAMPolicy, {sslCreds: sslCreds}); - var methods = [ + var iamPolicyStubMethods = [ + 'setIamPolicy', + 'getIamPolicy', + 'testIamPermissions' + ]; + iamPolicyStubMethods.forEach(function(methodName) { + this['_' + methodName] = gax.createApiCall( + iamPolicyStub.then(function(iamPolicyStub) { + return iamPolicyStub[methodName].bind(iamPolicyStub); + }), + defaults[methodName]); + }.bind(this)); + + var publisherStub = gaxGrpc.createStub( + servicePath, + port, + grpcClients.publisherClient.google.pubsub.v1.Publisher, + {sslCreds: sslCreds}); + var publisherStubMethods = [ 'createTopic', 'publish', 'getTopic', @@ -123,10 +138,12 @@ function PublisherApi(gaxGrpc, grpcClient, opts) { 'listTopicSubscriptions', 'deleteTopic' ]; - methods.forEach(function(methodName) { + publisherStubMethods.forEach(function(methodName) { this['_' + methodName] = gax.createApiCall( - stub.then(function(stub) { return stub[methodName].bind(stub); }), - defaults[methodName]); + publisherStub.then(function(publisherStub) { + return publisherStub[methodName].bind(publisherStub); + }), + defaults[methodName]); }.bind(this)); } @@ -207,9 +224,9 @@ PublisherApi.prototype.matchTopicFromTopicName = * underscores (`_`), periods (`.`), tildes (`~`), plus (`+`) or percent * signs (`%`). It must be between 3 and 255 characters in length, and it * must not start with `"goog"`. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -229,16 +246,21 @@ PublisherApi.prototype.matchTopicFromTopicName = * // doThingsWith(response) * }); */ -PublisherApi.prototype.createTopic = function createTopic() { - var args = arguejs({ - name: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +PublisherApi.prototype.createTopic = function createTopic( + name, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - name: args.name + name: name }; - return this._createTopic(req, args.options, args.callback); + return this._createTopic(req, options, callback); }; /** @@ -252,9 +274,9 @@ PublisherApi.prototype.createTopic = function createTopic() { * The messages to publish. * * This object should have the same structure as [PubsubMessage]{@link PubsubMessage} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -281,18 +303,23 @@ PublisherApi.prototype.createTopic = function createTopic() { * // doThingsWith(response) * }); */ -PublisherApi.prototype.publish = function publish() { - var args = arguejs({ - topic: String, - messages: Array, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +PublisherApi.prototype.publish = function publish( + topic, + messages, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - topic: args.topic, - messages: args.messages + topic: topic, + messages: messages }; - return this._publish(req, args.options, args.callback); + return this._publish(req, options, callback); }; /** @@ -300,9 +327,9 @@ PublisherApi.prototype.publish = function publish() { * * @param {string} topic * The name of the topic to get. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -322,16 +349,21 @@ PublisherApi.prototype.publish = function publish() { * // doThingsWith(response) * }); */ -PublisherApi.prototype.getTopic = function getTopic() { - var args = arguejs({ - topic: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +PublisherApi.prototype.getTopic = function getTopic( + topic, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - topic: args.topic + topic: topic }; - return this._getTopic(req, args.options, args.callback); + return this._getTopic(req, options, callback); }; /** @@ -339,44 +371,71 @@ PublisherApi.prototype.getTopic = function getTopic() { * * @param {string} project * The name of the cloud project that topics belong to. - * @param {Object=} otherArgs - * @param {number=} otherArgs.pageSize + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {number=} options.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this * parameter does not affect the return value. If page streaming is * performed per-page, this determines the maximum number of * resources in a page. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @returns {Stream} - * An object stream. By default, this emits an object representing + * + * @param {function(?Error, ?Object, ?string)=} callback + * When specified, the results are not streamed but this callback + * will be called with the response object representing [ListTopicsResponse]{@link ListTopicsResponse}. + * The third item will be set if the response contains the token for the further results + * and can be reused to `pageToken` field in the options in the next request. + * @returns {Stream|gax.EventEmitter} + * An object stream which emits an object representing * [Topic]{@link Topic} on 'data' event. - * This object can also be configured to emit - * pages of the responses through the options parameter. + * When the callback is specified or streaming is suppressed through options, + * it will return an event emitter to handle the call status and the callback + * will be called with the response object. * * @example * * var api = pubsubV1.publisherApi(); * var formattedProject = api.projectPath("[PROJECT]"); + * // Iterate over all elements. * api.listTopics(formattedProject).on('data', function(element) { * // doThingsWith(element) * }); + * + * // Or obtain the paged response through the callback. + * function callback(err, response, nextPageToken) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * if (nextPageToken) { + * // fetch the next page. + * api.listTopics(formattedProject, {pageToken: nextPageToken}, callback); + * } + * } + * api.listTopics(formattedProject, {flattenPages: false}, callback); */ -PublisherApi.prototype.listTopics = function listTopics() { - var args = arguejs({ - project: String, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +PublisherApi.prototype.listTopics = function listTopics( + project, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - project: args.project + project: project }; - if ('pageSize' in args.otherArgs) { - req.page_size = args.otherArgs.pageSize; + if ('pageSize' in options) { + req.pageSize = options.pageSize; } - return this._listTopics(req, args.options, args.callback); + return this._listTopics(req, options, callback); }; /** @@ -384,43 +443,70 @@ PublisherApi.prototype.listTopics = function listTopics() { * * @param {string} topic * The name of the topic that subscriptions are attached to. - * @param {Object=} otherArgs - * @param {number=} otherArgs.pageSize + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {number=} options.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this * parameter does not affect the return value. If page streaming is * performed per-page, this determines the maximum number of * resources in a page. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @returns {Stream} - * An object stream. By default, this emits a string on 'data' event. - * This object can also be configured to emit - * pages of the responses through the options parameter. + * + * @param {function(?Error, ?Object, ?string)=} callback + * When specified, the results are not streamed but this callback + * will be called with the response object representing [ListTopicSubscriptionsResponse]{@link ListTopicSubscriptionsResponse}. + * The third item will be set if the response contains the token for the further results + * and can be reused to `pageToken` field in the options in the next request. + * @returns {Stream|gax.EventEmitter} + * An object stream which emits a string on 'data' event. + * When the callback is specified or streaming is suppressed through options, + * it will return an event emitter to handle the call status and the callback + * will be called with the response object. * * @example * * var api = pubsubV1.publisherApi(); * var formattedTopic = api.topicPath("[PROJECT]", "[TOPIC]"); + * // Iterate over all elements. * api.listTopicSubscriptions(formattedTopic).on('data', function(element) { * // doThingsWith(element) * }); + * + * // Or obtain the paged response through the callback. + * function callback(err, response, nextPageToken) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * if (nextPageToken) { + * // fetch the next page. + * api.listTopicSubscriptions(formattedTopic, {pageToken: nextPageToken}, callback); + * } + * } + * api.listTopicSubscriptions(formattedTopic, {flattenPages: false}, callback); */ -PublisherApi.prototype.listTopicSubscriptions = function listTopicSubscriptions() { - var args = arguejs({ - topic: String, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +PublisherApi.prototype.listTopicSubscriptions = function listTopicSubscriptions( + topic, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - topic: args.topic + topic: topic }; - if ('pageSize' in args.otherArgs) { - req.page_size = args.otherArgs.pageSize; + if ('pageSize' in options) { + req.pageSize = options.pageSize; } - return this._listTopicSubscriptions(req, args.options, args.callback); + return this._listTopicSubscriptions(req, options, callback); }; /** @@ -432,9 +518,9 @@ PublisherApi.prototype.listTopicSubscriptions = function listTopicSubscriptions( * * @param {string} topic * Name of the topic to delete. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. * @returns {gax.EventEmitter} - the event emitter to handle the call @@ -450,16 +536,174 @@ PublisherApi.prototype.listTopicSubscriptions = function listTopicSubscriptions( * } * }); */ -PublisherApi.prototype.deleteTopic = function deleteTopic() { - var args = arguejs({ - topic: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +PublisherApi.prototype.deleteTopic = function deleteTopic( + topic, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - topic: args.topic + topic: topic }; - return this._deleteTopic(req, args.options, args.callback); + return this._deleteTopic(req, options, callback); +}; + +/** + * Sets the access control policy on the specified resource. Replaces any + * existing policy. + * + * @param {string} resource + * REQUIRED: The resource for which policy is being specified. + * Resource is usually specified as a path, such as, + * projects/{project}/zones/{zone}/disks/{disk}. + * @param {Object} policy + * REQUIRED: The complete policy to be applied to the 'resource'. The size of + * the policy is limited to a few 10s of KB. An empty policy is in general a + * valid policy but certain services (like Projects) might reject them. + * + * This object should have the same structure as [Policy]{@link Policy} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [Policy]{@link Policy} + * @returns {gax.EventEmitter} - the event emitter to handle the call + * status. + * + * @example + * + * var api = pubsubV1.publisherApi(); + * var formattedResource = api.topicPath("[PROJECT]", "[TOPIC]"); + * var policy = {}; + * api.setIamPolicy(formattedResource, policy, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); + */ +PublisherApi.prototype.setIamPolicy = function setIamPolicy( + resource, + policy, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + var req = { + resource: resource, + policy: policy + }; + return this._setIamPolicy(req, options, callback); +}; + +/** + * Gets the access control policy for a resource. Is empty if the + * policy or the resource does not exist. + * + * @param {string} resource + * REQUIRED: The resource for which policy is being requested. Resource + * is usually specified as a path, such as, projects/{project}. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [Policy]{@link Policy} + * @returns {gax.EventEmitter} - the event emitter to handle the call + * status. + * + * @example + * + * var api = pubsubV1.publisherApi(); + * var formattedResource = api.topicPath("[PROJECT]", "[TOPIC]"); + * api.getIamPolicy(formattedResource, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); + */ +PublisherApi.prototype.getIamPolicy = function getIamPolicy( + resource, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + var req = { + resource: resource + }; + return this._getIamPolicy(req, options, callback); +}; + +/** + * Returns permissions that a caller has on the specified resource. + * + * @param {string} resource + * REQUIRED: The resource for which policy detail is being requested. + * Resource is usually specified as a path, such as, projects/{project}. + * @param {string[]} permissions + * The set of permissions to check for the 'resource'. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [TestIamPermissionsResponse]{@link TestIamPermissionsResponse} + * @returns {gax.EventEmitter} - the event emitter to handle the call + * status. + * + * @example + * + * var api = pubsubV1.publisherApi(); + * var formattedResource = api.topicPath("[PROJECT]", "[TOPIC]"); + * var permissions = []; + * api.testIamPermissions(formattedResource, permissions, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); + */ +PublisherApi.prototype.testIamPermissions = function testIamPermissions( + resource, + permissions, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + var req = { + resource: resource, + permissions: permissions + }; + return this._testIamPermissions(req, options, callback); }; function PublisherApiBuilder(gaxGrpc) { @@ -467,11 +711,22 @@ function PublisherApiBuilder(gaxGrpc) { return new PublisherApiBuilder(gaxGrpc); } - var grpcClient = gaxGrpc.load([{ + var iamPolicyClient = gaxGrpc.load([{ + root: require('google-proto-files')('..'), + file: 'google/iam/v1/iam_policy.proto' + }]); + extend(this, iamPolicyClient.google.iam.v1); + + var publisherClient = gaxGrpc.load([{ root: require('google-proto-files')('..'), file: 'google/pubsub/v1/pubsub.proto' }]); - extend(this, grpcClient.google.pubsub.v1); + extend(this, publisherClient.google.pubsub.v1); + + var grpcClients = { + iamPolicyClient: iamPolicyClient, + publisherClient: publisherClient + }; /** * Build a new instance of {@link PublisherApi}. @@ -486,15 +741,13 @@ function PublisherApiBuilder(gaxGrpc) { * @param {Object=} opts.clientConfig * The customized config to build the call settings. See * {@link gax.constructSettings} for the format. - * @param {number=} opts.timeout - * The default timeout, in seconds, for calls made through this client. * @param {number=} opts.appName * The codename of the calling service. * @param {String=} opts.appVersion * The version of the calling service. */ this.publisherApi = function(opts) { - return new PublisherApi(gaxGrpc, grpcClient, opts); + return new PublisherApi(gaxGrpc, grpcClients, opts); }; extend(this.publisherApi, PublisherApi); } diff --git a/packages/pubsub/src/v1/subscriber_api.js b/packages/pubsub/src/v1/subscriber_api.js index 4a46e1e0258..652a7b4873e 100644 --- a/packages/pubsub/src/v1/subscriber_api.js +++ b/packages/pubsub/src/v1/subscriber_api.js @@ -27,7 +27,6 @@ /* jscs: disable maximumLineLength */ 'use strict'; -var arguejs = require('arguejs'); var configData = require('./subscriber_client_config'); var extend = require('extend'); var gax = require('google-gax'); @@ -38,12 +37,11 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; -var DEFAULT_TIMEOUT = 30; var PAGE_DESCRIPTORS = { listSubscriptions: new gax.PageDescriptor( - 'page_token', - 'next_page_token', + 'pageToken', + 'nextPageToken', 'subscriptions') }; @@ -72,36 +70,53 @@ var ALL_SCOPES = [ * * @class */ -function SubscriberApi(gaxGrpc, grpcClient, opts) { +function SubscriberApi(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 timeout = opts.timeout || DEFAULT_TIMEOUT; var appName = opts.appName || 'gax'; - var appVersion = opts.appVersion || gax.Version; + var appVersion = opts.appVersion || gax.version; var googleApiClient = [ appName + '/' + appVersion, CODE_GEN_NAME_VERSION, + 'gax/' + gax.version, 'nodejs/' + process.version].join(' '); var defaults = gaxGrpc.constructSettings( 'google.pubsub.v1.Subscriber', configData, clientConfig, - timeout, PAGE_DESCRIPTORS, null, {'x-goog-api-client': googleApiClient}); - var stub = gaxGrpc.createStub( + var iamPolicyStub = gaxGrpc.createStub( servicePath, port, - grpcClient.google.pubsub.v1.Subscriber, + grpcClients.iamPolicyClient.google.iam.v1.IAMPolicy, {sslCreds: sslCreds}); - var methods = [ + var iamPolicyStubMethods = [ + 'setIamPolicy', + 'getIamPolicy', + 'testIamPermissions' + ]; + iamPolicyStubMethods.forEach(function(methodName) { + this['_' + methodName] = gax.createApiCall( + iamPolicyStub.then(function(iamPolicyStub) { + return iamPolicyStub[methodName].bind(iamPolicyStub); + }), + defaults[methodName]); + }.bind(this)); + + var subscriberStub = gaxGrpc.createStub( + servicePath, + port, + grpcClients.subscriberClient.google.pubsub.v1.Subscriber, + {sslCreds: sslCreds}); + var subscriberStubMethods = [ 'createSubscription', 'getSubscription', 'listSubscriptions', @@ -111,10 +126,12 @@ function SubscriberApi(gaxGrpc, grpcClient, opts) { 'pull', 'modifyPushConfig' ]; - methods.forEach(function(methodName) { + subscriberStubMethods.forEach(function(methodName) { this['_' + methodName] = gax.createApiCall( - stub.then(function(stub) { return stub[methodName].bind(stub); }), - defaults[methodName]); + subscriberStub.then(function(subscriberStub) { + return subscriberStub[methodName].bind(subscriberStub); + }), + defaults[methodName]); }.bind(this)); } @@ -224,12 +241,13 @@ SubscriberApi.prototype.matchTopicFromTopicName = // Service calls /** - * Creates a subscription to a given topic for a given subscriber. + * Creates a subscription to a given topic. * If the subscription already exists, returns `ALREADY_EXISTS`. * If the corresponding topic doesn't exist, returns `NOT_FOUND`. * * If the name is not provided in the request, the server will assign a random - * name for this subscription on the same project as the topic. + * name for this subscription on the same project as the topic. Note that + * for REST API requests, you must specify a name. * * @param {string} name * The name of the subscription. It must have the format @@ -242,14 +260,18 @@ SubscriberApi.prototype.matchTopicFromTopicName = * The name of the topic from which this subscription is receiving messages. * The value of this field will be `_deleted-topic_` if the topic has been * deleted. - * @param {Object=} otherArgs - * @param {Object=} otherArgs.pushConfig + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {Object=} options.pushConfig * If push delivery is used with this subscription, this field is * used to configure it. An empty `pushConfig` signifies that the subscriber * will pull and ack messages using API methods. * * This object should have the same structure as [PushConfig]{@link PushConfig} - * @param {number=} otherArgs.ackDeadlineSeconds + * @param {number=} options.ackDeadlineSeconds * This value is the maximum time after a subscriber receives a message * before the subscriber should acknowledge the message. After message * delivery but before the ack deadline expires and before the message is @@ -260,6 +282,7 @@ SubscriberApi.prototype.matchTopicFromTopicName = * deadline. To override this value for a given message, call * `ModifyAckDeadline` with the corresponding `ack_id` if using * pull. + * The maximum custom deadline you can specify is 600 seconds (10 minutes). * * For push delivery, this value is also used to set the request timeout for * the call to the push endpoint. @@ -267,10 +290,8 @@ SubscriberApi.prototype.matchTopicFromTopicName = * If the subscriber never acknowledges the message, the Pub/Sub * system will eventually redeliver the message. * - * If this parameter is not set, the default value of 10 seconds is used. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * If this parameter is 0, a default value of 10 seconds is used. + * * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -291,25 +312,29 @@ SubscriberApi.prototype.matchTopicFromTopicName = * // doThingsWith(response) * }); */ -SubscriberApi.prototype.createSubscription = function createSubscription() { - var args = arguejs({ - name: String, - topic: String, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SubscriberApi.prototype.createSubscription = function createSubscription( + name, + topic, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - name: args.name, - topic: args.topic + name: name, + topic: topic }; - if ('pushConfig' in args.otherArgs) { - req.push_config = args.otherArgs.pushConfig; + if ('pushConfig' in options) { + req.pushConfig = options.pushConfig; } - if ('ackDeadlineSeconds' in args.otherArgs) { - req.ack_deadline_seconds = args.otherArgs.ackDeadlineSeconds; + if ('ackDeadlineSeconds' in options) { + req.ackDeadlineSeconds = options.ackDeadlineSeconds; } - return this._createSubscription(req, args.options, args.callback); + return this._createSubscription(req, options, callback); }; /** @@ -317,9 +342,9 @@ SubscriberApi.prototype.createSubscription = function createSubscription() { * * @param {string} subscription * The name of the subscription to get. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -339,16 +364,21 @@ SubscriberApi.prototype.createSubscription = function createSubscription() { * // doThingsWith(response) * }); */ -SubscriberApi.prototype.getSubscription = function getSubscription() { - var args = arguejs({ - subscription: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SubscriberApi.prototype.getSubscription = function getSubscription( + subscription, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - subscription: args.subscription + subscription: subscription }; - return this._getSubscription(req, args.options, args.callback); + return this._getSubscription(req, options, callback); }; /** @@ -356,44 +386,71 @@ SubscriberApi.prototype.getSubscription = function getSubscription() { * * @param {string} project * The name of the cloud project that subscriptions belong to. - * @param {Object=} otherArgs - * @param {number=} otherArgs.pageSize + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {number=} options.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this * parameter does not affect the return value. If page streaming is * performed per-page, this determines the maximum number of * resources in a page. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. - * @returns {Stream} - * An object stream. By default, this emits an object representing + * + * @param {function(?Error, ?Object, ?string)=} callback + * When specified, the results are not streamed but this callback + * will be called with the response object representing [ListSubscriptionsResponse]{@link ListSubscriptionsResponse}. + * The third item will be set if the response contains the token for the further results + * and can be reused to `pageToken` field in the options in the next request. + * @returns {Stream|gax.EventEmitter} + * An object stream which emits an object representing * [Subscription]{@link Subscription} on 'data' event. - * This object can also be configured to emit - * pages of the responses through the options parameter. + * When the callback is specified or streaming is suppressed through options, + * it will return an event emitter to handle the call status and the callback + * will be called with the response object. * * @example * * var api = pubsubV1.subscriberApi(); * var formattedProject = api.projectPath("[PROJECT]"); + * // Iterate over all elements. * api.listSubscriptions(formattedProject).on('data', function(element) { * // doThingsWith(element) * }); + * + * // Or obtain the paged response through the callback. + * function callback(err, response, nextPageToken) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * if (nextPageToken) { + * // fetch the next page. + * api.listSubscriptions(formattedProject, {pageToken: nextPageToken}, callback); + * } + * } + * api.listSubscriptions(formattedProject, {flattenPages: false}, callback); */ -SubscriberApi.prototype.listSubscriptions = function listSubscriptions() { - var args = arguejs({ - project: String, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SubscriberApi.prototype.listSubscriptions = function listSubscriptions( + project, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - project: args.project + project: project }; - if ('pageSize' in args.otherArgs) { - req.page_size = args.otherArgs.pageSize; + if ('pageSize' in options) { + req.pageSize = options.pageSize; } - return this._listSubscriptions(req, args.options, args.callback); + return this._listSubscriptions(req, options, callback); }; /** @@ -405,9 +462,9 @@ SubscriberApi.prototype.listSubscriptions = function listSubscriptions() { * * @param {string} subscription * The subscription to delete. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. * @returns {gax.EventEmitter} - the event emitter to handle the call @@ -423,23 +480,29 @@ SubscriberApi.prototype.listSubscriptions = function listSubscriptions() { * } * }); */ -SubscriberApi.prototype.deleteSubscription = function deleteSubscription() { - var args = arguejs({ - subscription: String, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SubscriberApi.prototype.deleteSubscription = function deleteSubscription( + subscription, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - subscription: args.subscription + subscription: subscription }; - return this._deleteSubscription(req, args.options, args.callback); + return this._deleteSubscription(req, options, callback); }; /** * Modifies the ack deadline for a specific message. This method is useful * to indicate that more time is needed to process a message by the * subscriber, or to make the message available for redelivery if the - * processing was interrupted. + * processing was interrupted. Note that this does not modify the + * subscription-level `ackDeadlineSeconds` used for subsequent messages. * * @param {string} subscription * The name of the subscription. @@ -451,9 +514,9 @@ SubscriberApi.prototype.deleteSubscription = function deleteSubscription() { * ack deadline will expire 10 seconds after the `ModifyAckDeadline` call * was made. Specifying zero may immediately make the message available for * another pull request. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. * @returns {gax.EventEmitter} - the event emitter to handle the call @@ -471,20 +534,25 @@ SubscriberApi.prototype.deleteSubscription = function deleteSubscription() { * } * }); */ -SubscriberApi.prototype.modifyAckDeadline = function modifyAckDeadline() { - var args = arguejs({ - subscription: String, - ackIds: Array, - ackDeadlineSeconds: Number, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SubscriberApi.prototype.modifyAckDeadline = function modifyAckDeadline( + subscription, + ackIds, + ackDeadlineSeconds, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - subscription: args.subscription, - ack_ids: args.ackIds, - ack_deadline_seconds: args.ackDeadlineSeconds + subscription: subscription, + ackIds: ackIds, + ackDeadlineSeconds: ackDeadlineSeconds }; - return this._modifyAckDeadline(req, args.options, args.callback); + return this._modifyAckDeadline(req, options, callback); }; /** @@ -501,9 +569,9 @@ SubscriberApi.prototype.modifyAckDeadline = function modifyAckDeadline() { * @param {string[]} ackIds * The acknowledgment ID for the messages being acknowledged that was returned * by the Pub/Sub system in the `Pull` response. Must not be empty. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. * @returns {gax.EventEmitter} - the event emitter to handle the call @@ -520,18 +588,23 @@ SubscriberApi.prototype.modifyAckDeadline = function modifyAckDeadline() { * } * }); */ -SubscriberApi.prototype.acknowledge = function acknowledge() { - var args = arguejs({ - subscription: String, - ackIds: Array, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SubscriberApi.prototype.acknowledge = function acknowledge( + subscription, + ackIds, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - subscription: args.subscription, - ack_ids: args.ackIds + subscription: subscription, + ackIds: ackIds }; - return this._acknowledge(req, args.options, args.callback); + return this._acknowledge(req, options, callback); }; /** @@ -545,16 +618,18 @@ SubscriberApi.prototype.acknowledge = function acknowledge() { * @param {number} maxMessages * The maximum number of messages returned for this request. The Pub/Sub * system may return fewer than the number specified. - * @param {Object=} otherArgs - * @param {boolean=} otherArgs.returnImmediately + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * + * In addition, options may contain the following optional parameters. + * @param {boolean=} options.returnImmediately * If this is specified as true the system will respond immediately even if * it is not able to return a message in the `Pull` response. Otherwise the * system is allowed to wait until at least one message is available rather * than returning no messages. The client may cancel the request if it does * not wish to wait any longer for the response. - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -575,22 +650,26 @@ SubscriberApi.prototype.acknowledge = function acknowledge() { * // doThingsWith(response) * }); */ -SubscriberApi.prototype.pull = function pull() { - var args = arguejs({ - subscription: String, - maxMessages: Number, - otherArgs: [Object, {}], - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SubscriberApi.prototype.pull = function pull( + subscription, + maxMessages, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - subscription: args.subscription, - max_messages: args.maxMessages + subscription: subscription, + maxMessages: maxMessages }; - if ('returnImmediately' in args.otherArgs) { - req.return_immediately = args.otherArgs.returnImmediately; + if ('returnImmediately' in options) { + req.returnImmediately = options.returnImmediately; } - return this._pull(req, args.options, args.callback); + return this._pull(req, options, callback); }; /** @@ -612,9 +691,9 @@ SubscriberApi.prototype.pull = function pull() { * the subscription if `Pull` is not called. * * This object should have the same structure as [PushConfig]{@link PushConfig} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. * @returns {gax.EventEmitter} - the event emitter to handle the call @@ -631,18 +710,176 @@ SubscriberApi.prototype.pull = function pull() { * } * }); */ -SubscriberApi.prototype.modifyPushConfig = function modifyPushConfig() { - var args = arguejs({ - subscription: String, - pushConfig: Object, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SubscriberApi.prototype.modifyPushConfig = function modifyPushConfig( + subscription, + pushConfig, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + var req = { + subscription: subscription, + pushConfig: pushConfig + }; + return this._modifyPushConfig(req, options, callback); +}; + +/** + * Sets the access control policy on the specified resource. Replaces any + * existing policy. + * + * @param {string} resource + * REQUIRED: The resource for which policy is being specified. + * Resource is usually specified as a path, such as, + * projects/{project}/zones/{zone}/disks/{disk}. + * @param {Object} policy + * REQUIRED: The complete policy to be applied to the 'resource'. The size of + * the policy is limited to a few 10s of KB. An empty policy is in general a + * valid policy but certain services (like Projects) might reject them. + * + * This object should have the same structure as [Policy]{@link Policy} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [Policy]{@link Policy} + * @returns {gax.EventEmitter} - the event emitter to handle the call + * status. + * + * @example + * + * var api = pubsubV1.subscriberApi(); + * var formattedResource = api.subscriptionPath("[PROJECT]", "[SUBSCRIPTION]"); + * var policy = {}; + * api.setIamPolicy(formattedResource, policy, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); + */ +SubscriberApi.prototype.setIamPolicy = function setIamPolicy( + resource, + policy, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + var req = { + resource: resource, + policy: policy + }; + return this._setIamPolicy(req, options, callback); +}; + +/** + * Gets the access control policy for a resource. Is empty if the + * policy or the resource does not exist. + * + * @param {string} resource + * REQUIRED: The resource for which policy is being requested. Resource + * is usually specified as a path, such as, projects/{project}. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [Policy]{@link Policy} + * @returns {gax.EventEmitter} - the event emitter to handle the call + * status. + * + * @example + * + * var api = pubsubV1.subscriberApi(); + * var formattedResource = api.subscriptionPath("[PROJECT]", "[SUBSCRIPTION]"); + * api.getIamPolicy(formattedResource, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); + */ +SubscriberApi.prototype.getIamPolicy = function getIamPolicy( + resource, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - subscription: args.subscription, - push_config: args.pushConfig + resource: resource }; - return this._modifyPushConfig(req, args.options, args.callback); + return this._getIamPolicy(req, options, callback); +}; + +/** + * Returns permissions that a caller has on the specified resource. + * + * @param {string} resource + * REQUIRED: The resource for which policy detail is being requested. + * Resource is usually specified as a path, such as, projects/{project}. + * @param {string[]} permissions + * The set of permissions to check for the 'resource'. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [TestIamPermissionsResponse]{@link TestIamPermissionsResponse} + * @returns {gax.EventEmitter} - the event emitter to handle the call + * status. + * + * @example + * + * var api = pubsubV1.subscriberApi(); + * var formattedResource = api.subscriptionPath("[PROJECT]", "[SUBSCRIPTION]"); + * var permissions = []; + * api.testIamPermissions(formattedResource, permissions, function(err, response) { + * if (err) { + * console.error(err); + * return; + * } + * // doThingsWith(response) + * }); + */ +SubscriberApi.prototype.testIamPermissions = function testIamPermissions( + resource, + permissions, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } + var req = { + resource: resource, + permissions: permissions + }; + return this._testIamPermissions(req, options, callback); }; function SubscriberApiBuilder(gaxGrpc) { @@ -650,11 +887,22 @@ function SubscriberApiBuilder(gaxGrpc) { return new SubscriberApiBuilder(gaxGrpc); } - var grpcClient = gaxGrpc.load([{ + var iamPolicyClient = gaxGrpc.load([{ + root: require('google-proto-files')('..'), + file: 'google/iam/v1/iam_policy.proto' + }]); + extend(this, iamPolicyClient.google.iam.v1); + + var subscriberClient = gaxGrpc.load([{ root: require('google-proto-files')('..'), file: 'google/pubsub/v1/pubsub.proto' }]); - extend(this, grpcClient.google.pubsub.v1); + extend(this, subscriberClient.google.pubsub.v1); + + var grpcClients = { + iamPolicyClient: iamPolicyClient, + subscriberClient: subscriberClient + }; /** * Build a new instance of {@link SubscriberApi}. @@ -669,15 +917,13 @@ function SubscriberApiBuilder(gaxGrpc) { * @param {Object=} opts.clientConfig * The customized config to build the call settings. See * {@link gax.constructSettings} for the format. - * @param {number=} opts.timeout - * The default timeout, in seconds, for calls made through this client. * @param {number=} opts.appName * The codename of the calling service. * @param {String=} opts.appVersion * The version of the calling service. */ this.subscriberApi = function(opts) { - return new SubscriberApi(gaxGrpc, grpcClient, opts); + return new SubscriberApi(gaxGrpc, grpcClients, opts); }; extend(this.subscriberApi, SubscriberApi); } diff --git a/packages/speech/package.json b/packages/speech/package.json index 167c2dafeb3..70c5427274f 100644 --- a/packages/speech/package.json +++ b/packages/speech/package.json @@ -55,10 +55,9 @@ ], "dependencies": { "@google-cloud/common": "^0.6.0", - "arguejs": "^0.2.3", "events-intercept": "^2.0.0", "extend": "^3.0.0", - "google-gax": "^0.6.0", + "google-gax": "^0.7.0", "google-proto-files": "^0.8.0", "is": "^3.1.0", "modelo": "^4.2.0", diff --git a/packages/speech/src/v1beta1/speech_api.js b/packages/speech/src/v1beta1/speech_api.js index 69d253571cb..ebc4582a0d0 100644 --- a/packages/speech/src/v1beta1/speech_api.js +++ b/packages/speech/src/v1beta1/speech_api.js @@ -27,7 +27,6 @@ /* jscs: disable maximumLineLength */ 'use strict'; -var arguejs = require('arguejs'); var configData = require('./speech_client_config'); var extend = require('extend'); var gax = require('google-gax'); @@ -38,7 +37,6 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; -var DEFAULT_TIMEOUT = 30; /** * The scopes needed to make gRPC calls to all of the methods defined in @@ -69,7 +67,6 @@ function SpeechApi(gaxGrpc, grpcClients, opts) { var port = opts.port || DEFAULT_SERVICE_PORT; var sslCreds = opts.sslCreds || null; var clientConfig = opts.clientConfig || {}; - var timeout = opts.timeout || DEFAULT_TIMEOUT; var appName = opts.appName || 'gax'; var appVersion = opts.appVersion || gax.version; @@ -83,7 +80,6 @@ function SpeechApi(gaxGrpc, grpcClients, opts) { 'google.cloud.speech.v1beta1.Speech', configData, clientConfig, - timeout, null, null, {'x-goog-api-client': googleApiClient}); @@ -121,9 +117,9 @@ function SpeechApi(gaxGrpc, grpcClients, opts) { * [Required] The audio data to be recognized. * * This object should have the same structure as [RecognitionAudio]{@link RecognitionAudio} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -144,24 +140,30 @@ function SpeechApi(gaxGrpc, grpcClients, opts) { * // doThingsWith(response) * }); */ -SpeechApi.prototype.syncRecognize = function syncRecognize() { - var args = arguejs({ - config: Object, - audio: Object, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SpeechApi.prototype.syncRecognize = function syncRecognize( + config, + audio, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - config: args.config, - audio: args.audio + config: config, + audio: audio }; - return this._syncRecognize(req, args.options, args.callback); + return this._syncRecognize(req, options, callback); }; /** * Perform asynchronous speech-recognition: receive results via the - * google.longrunning.Operations interface. `Operation.response` returns - * `AsyncRecognizeResponse`. + * google.longrunning.Operations interface. Returns either an + * `Operation.error` or an `Operation.response` which contains + * an `AsyncRecognizeResponse` message. * * @param {Object} config * [Required] The `config` message provides information to the recognizer @@ -172,9 +174,9 @@ SpeechApi.prototype.syncRecognize = function syncRecognize() { * [Required] The audio data to be recognized. * * This object should have the same structure as [RecognitionAudio]{@link RecognitionAudio} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -195,18 +197,23 @@ SpeechApi.prototype.syncRecognize = function syncRecognize() { * // doThingsWith(response) * }); */ -SpeechApi.prototype.asyncRecognize = function asyncRecognize() { - var args = arguejs({ - config: Object, - audio: Object, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +SpeechApi.prototype.asyncRecognize = function asyncRecognize( + config, + audio, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - config: args.config, - audio: args.audio + config: config, + audio: audio }; - return this._asyncRecognize(req, args.options, args.callback); + return this._asyncRecognize(req, options, callback); }; function SpeechApiBuilder(gaxGrpc) { @@ -237,8 +244,6 @@ function SpeechApiBuilder(gaxGrpc) { * @param {Object=} opts.clientConfig * The customized config to build the call settings. See * {@link gax.constructSettings} for the format. - * @param {number=} opts.timeout - * The default timeout, in seconds, for calls made through this client. * @param {number=} opts.appName * The codename of the calling service. * @param {String=} opts.appVersion diff --git a/packages/vision/package.json b/packages/vision/package.json index e87830627bd..f7cdf09f63d 100644 --- a/packages/vision/package.json +++ b/packages/vision/package.json @@ -51,11 +51,10 @@ ], "dependencies": { "@google-cloud/common": "^0.6.0", - "arguejs": "^0.2.3", "arrify": "^1.0.0", "async": "^2.0.1", "extend": "^3.0.0", - "google-gax": "^0.6.0", + "google-gax": "^0.7.0", "google-proto-files": "^0.8.0", "is": "^3.0.1", "propprop": "^0.3.0", diff --git a/packages/vision/src/v1/image_annotator_api.js b/packages/vision/src/v1/image_annotator_api.js index 50bee6095e5..de2c47c0b09 100644 --- a/packages/vision/src/v1/image_annotator_api.js +++ b/packages/vision/src/v1/image_annotator_api.js @@ -27,7 +27,6 @@ /* jscs: disable maximumLineLength */ 'use strict'; -var arguejs = require('arguejs'); var configData = require('./image_annotator_client_config'); var extend = require('extend'); var gax = require('google-gax'); @@ -38,7 +37,6 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; -var DEFAULT_TIMEOUT = 30; /** * The scopes needed to make gRPC calls to all of the methods defined in @@ -65,42 +63,43 @@ var ALL_SCOPES = [ * * @class */ -function ImageAnnotatorApi(gaxGrpc, grpcClient, opts) { +function ImageAnnotatorApi(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 timeout = opts.timeout || DEFAULT_TIMEOUT; var appName = opts.appName || 'gax'; - var appVersion = opts.appVersion || gax.Version; + var appVersion = opts.appVersion || gax.version; var googleApiClient = [ appName + '/' + appVersion, CODE_GEN_NAME_VERSION, + 'gax/' + gax.version, 'nodejs/' + process.version].join(' '); var defaults = gaxGrpc.constructSettings( 'google.cloud.vision.v1.ImageAnnotator', configData, clientConfig, - timeout, null, null, {'x-goog-api-client': googleApiClient}); - var stub = gaxGrpc.createStub( + var imageAnnotatorStub = gaxGrpc.createStub( servicePath, port, - grpcClient.google.cloud.vision.v1.ImageAnnotator, + grpcClients.imageAnnotatorClient.google.cloud.vision.v1.ImageAnnotator, {sslCreds: sslCreds}); - var methods = [ + var imageAnnotatorStubMethods = [ 'batchAnnotateImages' ]; - methods.forEach(function(methodName) { + imageAnnotatorStubMethods.forEach(function(methodName) { this['_' + methodName] = gax.createApiCall( - stub.then(function(stub) { return stub[methodName].bind(stub); }), - defaults[methodName]); + imageAnnotatorStub.then(function(imageAnnotatorStub) { + return imageAnnotatorStub[methodName].bind(imageAnnotatorStub); + }), + defaults[methodName]); }.bind(this)); } @@ -113,9 +112,9 @@ function ImageAnnotatorApi(gaxGrpc, grpcClient, opts) { * Individual image annotation requests for this batch. * * This object should have the same structure as [AnnotateImageRequest]{@link AnnotateImageRequest} - * @param {gax.CallOptions=} options - * Overrides the default settings for this call, e.g, timeout, - * retries, etc. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * @@ -135,16 +134,21 @@ function ImageAnnotatorApi(gaxGrpc, grpcClient, opts) { * // doThingsWith(response) * }); */ -ImageAnnotatorApi.prototype.batchAnnotateImages = function batchAnnotateImages() { - var args = arguejs({ - requests: Array, - options: [gax.CallOptions], - callback: [Function] - }, arguments); +ImageAnnotatorApi.prototype.batchAnnotateImages = function batchAnnotateImages( + requests, + options, + callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + if (options === undefined) { + options = {}; + } var req = { - requests: args.requests + requests: requests }; - return this._batchAnnotateImages(req, args.options, args.callback); + return this._batchAnnotateImages(req, options, callback); }; function ImageAnnotatorApiBuilder(gaxGrpc) { @@ -152,11 +156,15 @@ function ImageAnnotatorApiBuilder(gaxGrpc) { return new ImageAnnotatorApiBuilder(gaxGrpc); } - var grpcClient = gaxGrpc.load([{ + var imageAnnotatorClient = gaxGrpc.load([{ root: require('google-proto-files')('..'), file: 'google/cloud/vision/v1/image_annotator.proto' }]); - extend(this, grpcClient.google.cloud.vision.v1); + extend(this, imageAnnotatorClient.google.cloud.vision.v1); + + var grpcClients = { + imageAnnotatorClient: imageAnnotatorClient + }; /** * Build a new instance of {@link ImageAnnotatorApi}. @@ -171,15 +179,13 @@ function ImageAnnotatorApiBuilder(gaxGrpc) { * @param {Object=} opts.clientConfig * The customized config to build the call settings. See * {@link gax.constructSettings} for the format. - * @param {number=} opts.timeout - * The default timeout, in seconds, for calls made through this client. * @param {number=} opts.appName * The codename of the calling service. * @param {String=} opts.appVersion * The version of the calling service. */ this.imageAnnotatorApi = function(opts) { - return new ImageAnnotatorApi(gaxGrpc, grpcClient, opts); + return new ImageAnnotatorApi(gaxGrpc, grpcClients, opts); }; extend(this.imageAnnotatorApi, ImageAnnotatorApi); }