diff --git a/packages/google-cloud-vision/.eslintrc.json b/packages/google-cloud-vision/.eslintrc.json new file mode 100644 index 00000000000..78215349546 --- /dev/null +++ b/packages/google-cloud-vision/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/packages/google-cloud-vision/.eslintrc.yml b/packages/google-cloud-vision/.eslintrc.yml deleted file mode 100644 index 73eeec27612..00000000000 --- a/packages/google-cloud-vision/.eslintrc.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -extends: - - 'eslint:recommended' - - 'plugin:node/recommended' - - prettier -plugins: - - node - - prettier -rules: - prettier/prettier: error - block-scoped-var: error - eqeqeq: error - no-warning-comments: warn - no-var: error - prefer-const: error diff --git a/packages/google-cloud-vision/.prettierrc b/packages/google-cloud-vision/.prettierrc deleted file mode 100644 index df6eac07446..00000000000 --- a/packages/google-cloud-vision/.prettierrc +++ /dev/null @@ -1,8 +0,0 @@ ---- -bracketSpacing: false -printWidth: 80 -semi: true -singleQuote: true -tabWidth: 2 -trailingComma: es5 -useTabs: false diff --git a/packages/google-cloud-vision/.prettierrc.js b/packages/google-cloud-vision/.prettierrc.js new file mode 100644 index 00000000000..08cba3775be --- /dev/null +++ b/packages/google-cloud-vision/.prettierrc.js @@ -0,0 +1,17 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +module.exports = { + ...require('gts/.prettierrc.json') +} diff --git a/packages/google-cloud-vision/package.json b/packages/google-cloud-vision/package.json index 356cd015398..47ebf71856b 100644 --- a/packages/google-cloud-vision/package.json +++ b/packages/google-cloud-vision/package.json @@ -5,7 +5,7 @@ "license": "Apache-2.0", "author": "Google Inc", "engines": { - "node": ">=8.10.0" + "node": ">=10" }, "repository": "googleapis/nodejs-vision", "main": "build/src/index.js", @@ -44,35 +44,36 @@ }, "dependencies": { "@google-cloud/promisify": "^1.0.4", - "google-gax": "^1.14.1", + "google-gax": "^2.0.1", "is": "^3.3.0" }, "devDependencies": { + "@google-cloud/storage": "^4.3.1", + "@types/is": "0.0.21", "@types/mocha": "^7.0.1", "@types/node": "^13.7.4", "@types/is": "0.0.21", "@types/sinon": "^9.0.0", "@types/uuid": "^3.4.7", "c8": "^7.1.0", - "@google-cloud/storage": "^4.3.1", "codecov": "^3.6.5", "eslint": "^6.8.0", "eslint-config-prettier": "^6.10.0", "eslint-plugin-node": "^11.0.0", "eslint-plugin-prettier": "^3.1.2", - "gts": "^1.1.2", + "gts": "2.0.0-alpha.9", "jsdoc": "^3.6.3", "jsdoc-fresh": "^1.0.2", "jsdoc-region-tag": "^1.0.4", "linkinator": "^2.0.3", "mocha": "^7.0.1", - "prettier": "^1.19.1", - "sinon": "^9.0.0", - "uuid": "^3.4.0", "null-loader": "^3.0.0", "pack-n-play": "^1.0.0-2", + "prettier": "^1.19.1", + "sinon": "^9.0.1", "ts-loader": "^6.2.1", - "typescript": "^3.7.0", + "typescript": "^3.8.3", + "uuid": "^3.4.0", "webpack": "^4.41.6", "webpack-cli": "^3.3.11" } diff --git a/packages/google-cloud-vision/smoke-test/image_annotator_smoke_test.js b/packages/google-cloud-vision/smoke-test/image_annotator_smoke_test.js index a1e5ba1a760..d7c97223dc1 100644 --- a/packages/google-cloud-vision/smoke-test/image_annotator_smoke_test.js +++ b/packages/google-cloud-vision/smoke-test/image_annotator_smoke_test.js @@ -18,7 +18,8 @@ const {describe, it} = require('mocha'); describe('ImageAnnotatorSmokeTest', () => { it('successfully makes a call to the service', done => { - const vision = require('../src'); + // eslint-disable-next-line node/no-missing-require + const vision = require('@google-cloud/vision'); const client = new vision.v1p3beta1.ImageAnnotatorClient({ // optional auth parameters. diff --git a/packages/google-cloud-vision/src/helpers.ts b/packages/google-cloud-vision/src/helpers.ts index bc5cfc664b9..d316e463a7b 100644 --- a/packages/google-cloud-vision/src/helpers.ts +++ b/packages/google-cloud-vision/src/helpers.ts @@ -43,7 +43,7 @@ export interface FeaturesMethod { } interface ImprovedRequest { image?: {source?: {filename: string}; content?: Uint8Array | string | null}; - // tslint:disable-next-line no-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any features?: any; } @@ -82,7 +82,7 @@ interface VisionClient { ): void; } -// tslint:disable-next-line no-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any const _requestToObject = (request: any) => { if (is.string(request)) { // Is this a URL or a local file? @@ -353,6 +353,7 @@ export function call(apiVersion: string) { }); const protoFilesRoot = gax.protobuf.Root.fromJSON( + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../protos/protos.json') ); const features = (protoFilesRoot.lookup( diff --git a/packages/google-cloud-vision/src/v1/image_annotator_client.ts b/packages/google-cloud-vision/src/v1/image_annotator_client.ts index 55a79e81ee2..409cb183a41 100644 --- a/packages/google-cloud-vision/src/v1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1/image_annotator_client.ts @@ -18,7 +18,6 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, @@ -27,7 +26,7 @@ import { } from 'google-gax'; import * as path from 'path'; -import * as protosTypes from '../../protos/protos'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './image_annotator_client_config.json'; const version = require('../../../package.json').version; @@ -40,14 +39,6 @@ const version = require('../../../package.json').version; * @memberof v1 */ export class ImageAnnotatorClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; - private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -55,6 +46,14 @@ export class ImageAnnotatorClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; operationsClient: gax.OperationsClient; imageAnnotatorStub?: Promise<{[name: string]: Function}>; @@ -147,13 +146,16 @@ export class ImageAnnotatorClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. - this._pathTemplates = { + this.pathTemplates = { productPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/products/{product}' ), @@ -170,6 +172,7 @@ export class ImageAnnotatorClient { // rather than holding a request open. const protoFilesRoot = opts.fallback ? this._gaxModule.protobuf.Root.fromJSON( + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json') ) : this._gaxModule.protobuf.loadSync(nodejsProtoPath); @@ -193,7 +196,7 @@ export class ImageAnnotatorClient { '.google.cloud.vision.v1.OperationMetadata' ) as gax.protobuf.Type; - this._descriptors.longrunning = { + this.descriptors.longrunning = { asyncBatchAnnotateImages: new this._gaxModule.LongrunningDescriptor( this.operationsClient, asyncBatchAnnotateImagesResponse.decode.bind( @@ -225,7 +228,7 @@ export class ImageAnnotatorClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -252,7 +255,7 @@ export class ImageAnnotatorClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.vision.v1.ImageAnnotator' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.vision.v1.ImageAnnotator, this._opts ) as Promise<{[method: string]: Function}>; @@ -265,9 +268,8 @@ export class ImageAnnotatorClient { 'asyncBatchAnnotateImages', 'asyncBatchAnnotateFiles', ]; - for (const methodName of imageAnnotatorStubMethods) { - const innerCallPromise = this.imageAnnotatorStub.then( + const callPromise = this.imageAnnotatorStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -281,20 +283,14 @@ export class ImageAnnotatorClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.imageAnnotatorStub; @@ -354,26 +350,34 @@ export class ImageAnnotatorClient { // -- Service calls -- // ------------------- batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesResponse, - ( - | protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest - | undefined - ), + protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest | undefined, {} | undefined ] >; batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + batchAnnotateImages( + request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest, + callback: Callback< + protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -403,28 +407,27 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesResponse, - ( - | protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest - | undefined - ), + protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest | undefined, {} | undefined ] > | void { @@ -445,25 +448,37 @@ export class ImageAnnotatorClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.batchAnnotateImages(request, options, callback); + return this.innerApiCalls.batchAnnotateImages(request, options, callback); } batchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest | undefined, + protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest | undefined, {} | undefined ] >; batchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse, + | protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest + | null + | undefined, + {} | null | undefined + > + ): void; + batchAnnotateFiles( + request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest, + callback: Callback< + protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse, + | protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -500,24 +515,27 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ batchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesResponse, - | protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest + protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse, + | protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse, + | protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest + | null + | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest | undefined, + protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest | undefined, {} | undefined ] > | void { @@ -538,32 +556,43 @@ export class ImageAnnotatorClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.batchAnnotateFiles(request, options, callback); + return this.innerApiCalls.batchAnnotateFiles(request, options, callback); } asyncBatchAnnotateImages( - request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; asyncBatchAnnotateImages( - request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + asyncBatchAnnotateImages( + request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -603,32 +632,32 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ asyncBatchAnnotateImages( - request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -649,35 +678,46 @@ export class ImageAnnotatorClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.asyncBatchAnnotateImages( + return this.innerApiCalls.asyncBatchAnnotateImages( request, options, callback ); } asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + asyncBatchAnnotateFiles( + request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -712,32 +752,32 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1.IOperationMetadata + protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -758,7 +798,7 @@ export class ImageAnnotatorClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.asyncBatchAnnotateFiles( + return this.innerApiCalls.asyncBatchAnnotateFiles( request, options, callback @@ -777,10 +817,10 @@ export class ImageAnnotatorClient { * @returns {string} Resource name string. */ productPath(project: string, location: string, product: string) { - return this._pathTemplates.productPathTemplate.render({ - project, - location, - product, + return this.pathTemplates.productPathTemplate.render({ + project: project, + location: location, + product: product, }); } @@ -792,7 +832,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).project; + return this.pathTemplates.productPathTemplate.match(productName).project; } /** @@ -803,7 +843,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).location; + return this.pathTemplates.productPathTemplate.match(productName).location; } /** @@ -814,7 +854,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product. */ matchProductFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).product; + return this.pathTemplates.productPathTemplate.match(productName).product; } /** @@ -826,9 +866,9 @@ export class ImageAnnotatorClient { * @returns {string} Resource name string. */ productSetPath(project: string, location: string, productSet: string) { - return this._pathTemplates.productSetPathTemplate.render({ - project, - location, + return this.pathTemplates.productSetPathTemplate.render({ + project: project, + location: location, product_set: productSet, }); } @@ -841,7 +881,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .project; } @@ -853,7 +893,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .location; } @@ -865,7 +905,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product_set. */ matchProductSetFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .product_set; } @@ -884,10 +924,10 @@ export class ImageAnnotatorClient { product: string, referenceImage: string ) { - return this._pathTemplates.referenceImagePathTemplate.render({ - project, - location, - product, + return this.pathTemplates.referenceImagePathTemplate.render({ + project: project, + location: location, + product: product, reference_image: referenceImage, }); } @@ -900,7 +940,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).project; } @@ -913,7 +953,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).location; } @@ -926,7 +966,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product. */ matchProductFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).product; } @@ -939,7 +979,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the reference_image. */ matchReferenceImageFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).reference_image; } @@ -961,4 +1001,5 @@ export class ImageAnnotatorClient { } } import {FeaturesMethod} from '../helpers'; +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ImageAnnotatorClient extends FeaturesMethod {} diff --git a/packages/google-cloud-vision/src/v1/product_search_client.ts b/packages/google-cloud-vision/src/v1/product_search_client.ts index c1174e40b4f..c4ac1909c44 100644 --- a/packages/google-cloud-vision/src/v1/product_search_client.ts +++ b/packages/google-cloud-vision/src/v1/product_search_client.ts @@ -18,19 +18,19 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, ClientOptions, LROperation, PaginationCallback, - PaginationResponse, + GaxCall, } from 'google-gax'; import * as path from 'path'; import {Transform} from 'stream'; -import * as protosTypes from '../../protos/protos'; +import {RequestType} from 'google-gax/build/src/apitypes'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './product_search_client_config.json'; const version = require('../../../package.json').version; @@ -54,14 +54,6 @@ const version = require('../../../package.json').version; * @memberof v1 */ export class ProductSearchClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; - private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -69,6 +61,14 @@ export class ProductSearchClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; operationsClient: gax.OperationsClient; productSearchStub?: Promise<{[name: string]: Function}>; @@ -161,13 +161,16 @@ export class ProductSearchClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. - this._pathTemplates = { + this.pathTemplates = { locationPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}' ), @@ -185,7 +188,7 @@ export class ProductSearchClient { // Some of the methods on this service return "paged" results, // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. - this._descriptors.page = { + this.descriptors.page = { listProductSets: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', @@ -213,6 +216,7 @@ export class ProductSearchClient { // rather than holding a request open. const protoFilesRoot = opts.fallback ? this._gaxModule.protobuf.Root.fromJSON( + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json') ) : this._gaxModule.protobuf.loadSync(nodejsProtoPath); @@ -236,7 +240,7 @@ export class ProductSearchClient { '.google.cloud.vision.v1.BatchOperationMetadata' ) as gax.protobuf.Type; - this._descriptors.longrunning = { + this.descriptors.longrunning = { importProductSets: new this._gaxModule.LongrunningDescriptor( this.operationsClient, importProductSetsResponse.decode.bind(importProductSetsResponse), @@ -260,7 +264,7 @@ export class ProductSearchClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -287,7 +291,7 @@ export class ProductSearchClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.vision.v1.ProductSearch' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.vision.v1.ProductSearch, this._opts ) as Promise<{[method: string]: Function}>; @@ -315,9 +319,8 @@ export class ProductSearchClient { 'importProductSets', 'purgeProducts', ]; - for (const methodName of productSearchStubMethods) { - const innerCallPromise = this.productSearchStub.then( + const callPromise = this.productSearchStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -331,20 +334,14 @@ export class ProductSearchClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.productSearchStub; @@ -404,22 +401,30 @@ export class ProductSearchClient { // -- Service calls -- // ------------------- createProductSet( - request: protosTypes.google.cloud.vision.v1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1.ICreateProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.ICreateProductSetRequest | undefined, + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.ICreateProductSetRequest | undefined, {} | undefined ] >; createProductSet( - request: protosTypes.google.cloud.vision.v1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1.ICreateProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.ICreateProductSetRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.ICreateProductSetRequest | null | undefined, + {} | null | undefined + > + ): void; + createProductSet( + request: protos.google.cloud.vision.v1.ICreateProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.ICreateProductSetRequest | null | undefined, + {} | null | undefined > ): void; /** @@ -450,24 +455,25 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createProductSet( - request: protosTypes.google.cloud.vision.v1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1.ICreateProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - | protosTypes.google.cloud.vision.v1.ICreateProductSetRequest + protos.google.cloud.vision.v1.IProductSet, + | protos.google.cloud.vision.v1.ICreateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.ICreateProductSetRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.ICreateProductSetRequest | null | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.ICreateProductSetRequest | undefined, + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.ICreateProductSetRequest | undefined, {} | undefined ] > | void { @@ -488,25 +494,33 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createProductSet(request, options, callback); + return this.innerApiCalls.createProductSet(request, options, callback); } getProductSet( - request: protosTypes.google.cloud.vision.v1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1.IGetProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IGetProductSetRequest | undefined, + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IGetProductSetRequest | undefined, {} | undefined ] >; getProductSet( - request: protosTypes.google.cloud.vision.v1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1.IGetProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IGetProductSetRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IGetProductSetRequest | null | undefined, + {} | null | undefined + > + ): void; + getProductSet( + request: protos.google.cloud.vision.v1.IGetProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IGetProductSetRequest | null | undefined, + {} | null | undefined > ): void; /** @@ -530,23 +544,25 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getProductSet( - request: protosTypes.google.cloud.vision.v1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1.IGetProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IGetProductSetRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProductSet, + | protos.google.cloud.vision.v1.IGetProductSetRequest + | null + | undefined, + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IGetProductSetRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IGetProductSetRequest | null | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IGetProductSetRequest | undefined, + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IGetProductSetRequest | undefined, {} | undefined ] > | void { @@ -567,25 +583,33 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getProductSet(request, options, callback); + return this.innerApiCalls.getProductSet(request, options, callback); } updateProductSet( - request: protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1.IUpdateProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest | undefined, + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IUpdateProductSetRequest | undefined, {} | undefined ] >; updateProductSet( - request: protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1.IUpdateProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IUpdateProductSetRequest | null | undefined, + {} | null | undefined + > + ): void; + updateProductSet( + request: protos.google.cloud.vision.v1.IUpdateProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IUpdateProductSetRequest | null | undefined, + {} | null | undefined > ): void; /** @@ -614,24 +638,25 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ updateProductSet( - request: protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1.IUpdateProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - | protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest + protos.google.cloud.vision.v1.IProductSet, + | protos.google.cloud.vision.v1.IUpdateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IUpdateProductSetRequest | null | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProductSet, - protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest | undefined, + protos.google.cloud.vision.v1.IProductSet, + protos.google.cloud.vision.v1.IUpdateProductSetRequest | undefined, {} | undefined ] > | void { @@ -652,25 +677,33 @@ export class ProductSearchClient { 'product_set.name': request.productSet!.name || '', }); this.initialize(); - return this._innerApiCalls.updateProductSet(request, options, callback); + return this.innerApiCalls.updateProductSet(request, options, callback); } deleteProductSet( - request: protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1.IDeleteProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest | undefined, + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductSetRequest | undefined, {} | undefined ] >; deleteProductSet( - request: protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1.IDeleteProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest | undefined, - {} | undefined + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductSetRequest | null | undefined, + {} | null | undefined + > + ): void; + deleteProductSet( + request: protos.google.cloud.vision.v1.IDeleteProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductSetRequest | null | undefined, + {} | null | undefined > ): void; /** @@ -693,24 +726,25 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteProductSet( - request: protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1.IDeleteProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IDeleteProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest | undefined, - {} | undefined + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductSetRequest | null | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest | undefined, + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductSetRequest | undefined, {} | undefined ] > | void { @@ -731,25 +765,33 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteProductSet(request, options, callback); + return this.innerApiCalls.deleteProductSet(request, options, callback); } createProduct( - request: protosTypes.google.cloud.vision.v1.ICreateProductRequest, + request: protos.google.cloud.vision.v1.ICreateProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.ICreateProductRequest | undefined, + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.ICreateProductRequest | undefined, {} | undefined ] >; createProduct( - request: protosTypes.google.cloud.vision.v1.ICreateProductRequest, + request: protos.google.cloud.vision.v1.ICreateProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.ICreateProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.ICreateProductRequest | null | undefined, + {} | null | undefined + > + ): void; + createProduct( + request: protos.google.cloud.vision.v1.ICreateProductRequest, + callback: Callback< + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.ICreateProductRequest | null | undefined, + {} | null | undefined > ): void; /** @@ -783,23 +825,25 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createProduct( - request: protosTypes.google.cloud.vision.v1.ICreateProductRequest, + request: protos.google.cloud.vision.v1.ICreateProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.ICreateProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + | protos.google.cloud.vision.v1.ICreateProductRequest + | null + | undefined, + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.ICreateProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.ICreateProductRequest | null | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.ICreateProductRequest | undefined, + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.ICreateProductRequest | undefined, {} | undefined ] > | void { @@ -820,25 +864,33 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createProduct(request, options, callback); + return this.innerApiCalls.createProduct(request, options, callback); } getProduct( - request: protosTypes.google.cloud.vision.v1.IGetProductRequest, + request: protos.google.cloud.vision.v1.IGetProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IGetProductRequest | undefined, + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IGetProductRequest | undefined, {} | undefined ] >; getProduct( - request: protosTypes.google.cloud.vision.v1.IGetProductRequest, + request: protos.google.cloud.vision.v1.IGetProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IGetProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IGetProductRequest | null | undefined, + {} | null | undefined + > + ): void; + getProduct( + request: protos.google.cloud.vision.v1.IGetProductRequest, + callback: Callback< + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IGetProductRequest | null | undefined, + {} | null | undefined > ): void; /** @@ -862,23 +914,23 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getProduct( - request: protosTypes.google.cloud.vision.v1.IGetProductRequest, + request: protos.google.cloud.vision.v1.IGetProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IGetProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IGetProductRequest | null | undefined, + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IGetProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IGetProductRequest | null | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IGetProductRequest | undefined, + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IGetProductRequest | undefined, {} | undefined ] > | void { @@ -899,25 +951,33 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getProduct(request, options, callback); + return this.innerApiCalls.getProduct(request, options, callback); } updateProduct( - request: protosTypes.google.cloud.vision.v1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1.IUpdateProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IUpdateProductRequest | undefined, + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IUpdateProductRequest | undefined, {} | undefined ] >; updateProduct( - request: protosTypes.google.cloud.vision.v1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1.IUpdateProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IUpdateProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IUpdateProductRequest | null | undefined, + {} | null | undefined + > + ): void; + updateProduct( + request: protos.google.cloud.vision.v1.IUpdateProductRequest, + callback: Callback< + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IUpdateProductRequest | null | undefined, + {} | null | undefined > ): void; /** @@ -955,23 +1015,25 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ updateProduct( - request: protosTypes.google.cloud.vision.v1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1.IUpdateProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IUpdateProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + | protos.google.cloud.vision.v1.IUpdateProductRequest + | null + | undefined, + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IUpdateProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IUpdateProductRequest | null | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct, - protosTypes.google.cloud.vision.v1.IUpdateProductRequest | undefined, + protos.google.cloud.vision.v1.IProduct, + protos.google.cloud.vision.v1.IUpdateProductRequest | undefined, {} | undefined ] > | void { @@ -992,25 +1054,33 @@ export class ProductSearchClient { 'product.name': request.product!.name || '', }); this.initialize(); - return this._innerApiCalls.updateProduct(request, options, callback); + return this.innerApiCalls.updateProduct(request, options, callback); } deleteProduct( - request: protosTypes.google.cloud.vision.v1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1.IDeleteProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductRequest | undefined, + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductRequest | undefined, {} | undefined ] >; deleteProduct( - request: protosTypes.google.cloud.vision.v1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1.IDeleteProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductRequest | undefined, - {} | undefined + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductRequest | null | undefined, + {} | null | undefined + > + ): void; + deleteProduct( + request: protos.google.cloud.vision.v1.IDeleteProductRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductRequest | null | undefined, + {} | null | undefined > ): void; /** @@ -1034,23 +1104,25 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteProduct( - request: protosTypes.google.cloud.vision.v1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1.IDeleteProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductRequest | undefined, - {} | undefined + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IDeleteProductRequest + | null + | undefined, + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductRequest | undefined, - {} | undefined + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductRequest | null | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IDeleteProductRequest | undefined, + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteProductRequest | undefined, {} | undefined ] > | void { @@ -1071,29 +1143,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteProduct(request, options, callback); + return this.innerApiCalls.deleteProduct(request, options, callback); } createReferenceImage( - request: protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1.ICreateReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IReferenceImage, - ( - | protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest - | undefined - ), + protos.google.cloud.vision.v1.IReferenceImage, + protos.google.cloud.vision.v1.ICreateReferenceImageRequest | undefined, {} | undefined ] >; createReferenceImage( - request: protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1.ICreateReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage, - | protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1.IReferenceImage, + | protos.google.cloud.vision.v1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createReferenceImage( + request: protos.google.cloud.vision.v1.ICreateReferenceImageRequest, + callback: Callback< + protos.google.cloud.vision.v1.IReferenceImage, + | protos.google.cloud.vision.v1.ICreateReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1139,28 +1219,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createReferenceImage( - request: protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1.ICreateReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage, - | protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1.IReferenceImage, + | protos.google.cloud.vision.v1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage, - | protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1.IReferenceImage, + | protos.google.cloud.vision.v1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IReferenceImage, - ( - | protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest - | undefined - ), + protos.google.cloud.vision.v1.IReferenceImage, + protos.google.cloud.vision.v1.ICreateReferenceImageRequest | undefined, {} | undefined ] > | void { @@ -1181,29 +1260,37 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createReferenceImage(request, options, callback); + return this.innerApiCalls.createReferenceImage(request, options, callback); } deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1.IDeleteReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteReferenceImageRequest | undefined, {} | undefined ] >; deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1.IDeleteReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteReferenceImage( + request: protos.google.cloud.vision.v1.IDeleteReferenceImageRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IDeleteReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1230,28 +1317,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1.IDeleteReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IDeleteReferenceImageRequest | undefined, {} | undefined ] > | void { @@ -1272,25 +1358,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteReferenceImage(request, options, callback); + return this.innerApiCalls.deleteReferenceImage(request, options, callback); } getReferenceImage( - request: protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1.IGetReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IReferenceImage, - protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest | undefined, + protos.google.cloud.vision.v1.IReferenceImage, + protos.google.cloud.vision.v1.IGetReferenceImageRequest | undefined, {} | undefined ] >; getReferenceImage( - request: protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1.IGetReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage, - protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IReferenceImage, + | protos.google.cloud.vision.v1.IGetReferenceImageRequest + | null + | undefined, + {} | null | undefined + > + ): void; + getReferenceImage( + request: protos.google.cloud.vision.v1.IGetReferenceImageRequest, + callback: Callback< + protos.google.cloud.vision.v1.IReferenceImage, + | protos.google.cloud.vision.v1.IGetReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1315,24 +1413,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getReferenceImage( - request: protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1.IGetReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage, - | protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest + protos.google.cloud.vision.v1.IReferenceImage, + | protos.google.cloud.vision.v1.IGetReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage, - protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1.IReferenceImage, + | protos.google.cloud.vision.v1.IGetReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1.IReferenceImage, - protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest | undefined, + protos.google.cloud.vision.v1.IReferenceImage, + protos.google.cloud.vision.v1.IGetReferenceImageRequest | undefined, {} | undefined ] > | void { @@ -1353,29 +1454,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getReferenceImage(request, options, callback); + return this.innerApiCalls.getReferenceImage(request, options, callback); } addProductToProductSet( - request: protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1.IAddProductToProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IAddProductToProductSetRequest | undefined, {} | undefined ] >; addProductToProductSet( - request: protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1.IAddProductToProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + addProductToProductSet( + request: protos.google.cloud.vision.v1.IAddProductToProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IAddProductToProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1407,28 +1516,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ addProductToProductSet( - request: protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1.IAddProductToProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IAddProductToProductSetRequest | undefined, {} | undefined ] > | void { @@ -1449,33 +1557,44 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.addProductToProductSet( + return this.innerApiCalls.addProductToProductSet( request, options, callback ); } removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + | protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest | undefined ), {} | undefined ] >; removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + removeProductFromProductSet( + request: protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1500,26 +1619,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest + | protos.google.cloud.vision.v1.IRemoveProductFromProductSetRequest | undefined ), {} | undefined @@ -1542,7 +1663,7 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.removeProductFromProductSet( + return this.innerApiCalls.removeProductFromProductSet( request, options, callback @@ -1550,28 +1671,39 @@ export class ProductSearchClient { } importProductSets( - request: protosTypes.google.cloud.vision.v1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1.IImportProductSetsRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.cloud.vision.v1.IImportProductSetsResponse, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; importProductSets( - request: protosTypes.google.cloud.vision.v1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1.IImportProductSetsRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.cloud.vision.v1.IImportProductSetsResponse, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + importProductSets( + request: protos.google.cloud.vision.v1.IImportProductSetsRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1.IImportProductSetsResponse, + protos.google.cloud.vision.v1.IBatchOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -1602,32 +1734,32 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ importProductSets( - request: protosTypes.google.cloud.vision.v1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1.IImportProductSetsRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.cloud.vision.v1.IImportProductSetsResponse, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.cloud.vision.v1.IImportProductSetsResponse, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.cloud.vision.v1.IImportProductSetsResponse, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -1648,31 +1780,42 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.importProductSets(request, options, callback); + return this.innerApiCalls.importProductSets(request, options, callback); } purgeProducts( - request: protosTypes.google.cloud.vision.v1.IPurgeProductsRequest, + request: protos.google.cloud.vision.v1.IPurgeProductsRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; purgeProducts( - request: protosTypes.google.cloud.vision.v1.IPurgeProductsRequest, + request: protos.google.cloud.vision.v1.IPurgeProductsRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + purgeProducts( + request: protos.google.cloud.vision.v1.IPurgeProductsRequest, + callback: Callback< + LROperation< + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IBatchOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -1722,32 +1865,32 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ purgeProducts( - request: protosTypes.google.cloud.vision.v1.IPurgeProductsRequest, + request: protos.google.cloud.vision.v1.IPurgeProductsRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -1768,25 +1911,33 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.purgeProducts(request, options, callback); + return this.innerApiCalls.purgeProducts(request, options, callback); } listProductSets( - request: protosTypes.google.cloud.vision.v1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1.IListProductSetsRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProductSet[], - protosTypes.google.cloud.vision.v1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductSetsResponse + protos.google.cloud.vision.v1.IProductSet[], + protos.google.cloud.vision.v1.IListProductSetsRequest | null, + protos.google.cloud.vision.v1.IListProductSetsResponse ] >; listProductSets( - request: protosTypes.google.cloud.vision.v1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1.IListProductSetsRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1.IProductSet[], - protosTypes.google.cloud.vision.v1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductSetsResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1.IListProductSetsRequest, + protos.google.cloud.vision.v1.IListProductSetsResponse | null | undefined, + protos.google.cloud.vision.v1.IProductSet + > + ): void; + listProductSets( + request: protos.google.cloud.vision.v1.IListProductSetsRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1.IListProductSetsRequest, + protos.google.cloud.vision.v1.IListProductSetsResponse | null | undefined, + protos.google.cloud.vision.v1.IProductSet > ): void; /** @@ -1826,24 +1977,26 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProductSets( - request: protosTypes.google.cloud.vision.v1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1.IListProductSetsRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1.IProductSet[], - protosTypes.google.cloud.vision.v1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductSetsResponse + | PaginationCallback< + protos.google.cloud.vision.v1.IListProductSetsRequest, + | protos.google.cloud.vision.v1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1.IProductSet >, - callback?: Callback< - protosTypes.google.cloud.vision.v1.IProductSet[], - protosTypes.google.cloud.vision.v1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductSetsResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1.IListProductSetsRequest, + protos.google.cloud.vision.v1.IListProductSetsResponse | null | undefined, + protos.google.cloud.vision.v1.IProductSet > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProductSet[], - protosTypes.google.cloud.vision.v1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductSetsResponse + protos.google.cloud.vision.v1.IProductSet[], + protos.google.cloud.vision.v1.IListProductSetsRequest | null, + protos.google.cloud.vision.v1.IListProductSetsResponse ] > | void { request = request || {}; @@ -1863,7 +2016,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listProductSets(request, options, callback); + return this.innerApiCalls.listProductSets(request, options, callback); } /** @@ -1895,7 +2048,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [ProductSet]{@link google.cloud.vision.v1.ProductSet} on 'data' event. */ listProductSetsStream( - request?: protosTypes.google.cloud.vision.v1.IListProductSetsRequest, + request?: protos.google.cloud.vision.v1.IListProductSetsRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -1909,29 +2062,80 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProductSets.createStream( - this._innerApiCalls.listProductSets as gax.GaxCall, + return this.descriptors.page.listProductSets.createStream( + this.innerApiCalls.listProductSets as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProductSets}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The project from which ProductSets should be listed. + * + * Format is `projects/PROJECT_ID/locations/LOC_ID`. + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductSetsAsync( + request?: protos.google.cloud.vision.v1.IListProductSetsRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProductSets.asyncIterate( + this.innerApiCalls['listProductSets'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listProducts( - request: protosTypes.google.cloud.vision.v1.IListProductsRequest, + request: protos.google.cloud.vision.v1.IListProductsRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsResponse + protos.google.cloud.vision.v1.IProduct[], + protos.google.cloud.vision.v1.IListProductsRequest | null, + protos.google.cloud.vision.v1.IListProductsResponse ] >; listProducts( - request: protosTypes.google.cloud.vision.v1.IListProductsRequest, + request: protos.google.cloud.vision.v1.IListProductsRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1.IListProductsRequest, + protos.google.cloud.vision.v1.IListProductsResponse | null | undefined, + protos.google.cloud.vision.v1.IProduct + > + ): void; + listProducts( + request: protos.google.cloud.vision.v1.IListProductsRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1.IListProductsRequest, + protos.google.cloud.vision.v1.IListProductsResponse | null | undefined, + protos.google.cloud.vision.v1.IProduct > ): void; /** @@ -1971,24 +2175,26 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProducts( - request: protosTypes.google.cloud.vision.v1.IListProductsRequest, + request: protos.google.cloud.vision.v1.IListProductsRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsResponse + | PaginationCallback< + protos.google.cloud.vision.v1.IListProductsRequest, + | protos.google.cloud.vision.v1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1.IProduct >, - callback?: Callback< - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1.IListProductsRequest, + protos.google.cloud.vision.v1.IListProductsResponse | null | undefined, + protos.google.cloud.vision.v1.IProduct > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsResponse + protos.google.cloud.vision.v1.IProduct[], + protos.google.cloud.vision.v1.IListProductsRequest | null, + protos.google.cloud.vision.v1.IListProductsResponse ] > | void { request = request || {}; @@ -2008,7 +2214,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listProducts(request, options, callback); + return this.innerApiCalls.listProducts(request, options, callback); } /** @@ -2041,7 +2247,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [Product]{@link google.cloud.vision.v1.Product} on 'data' event. */ listProductsStream( - request?: protosTypes.google.cloud.vision.v1.IListProductsRequest, + request?: protos.google.cloud.vision.v1.IListProductsRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2055,29 +2261,85 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProducts.createStream( - this._innerApiCalls.listProducts as gax.GaxCall, + return this.descriptors.page.listProducts.createStream( + this.innerApiCalls.listProducts as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProducts}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The project OR ProductSet from which Products should be listed. + * + * Format: + * `projects/PROJECT_ID/locations/LOC_ID` + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductsAsync( + request?: protos.google.cloud.vision.v1.IListProductsRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProducts.asyncIterate( + this.innerApiCalls['listProducts'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listReferenceImages( - request: protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1.IListReferenceImagesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IReferenceImage[], - protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1.IListReferenceImagesResponse + protos.google.cloud.vision.v1.IReferenceImage[], + protos.google.cloud.vision.v1.IListReferenceImagesRequest | null, + protos.google.cloud.vision.v1.IListReferenceImagesResponse ] >; listReferenceImages( - request: protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1.IListReferenceImagesRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage[], - protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1.IListReferenceImagesResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1.IReferenceImage + > + ): void; + listReferenceImages( + request: protos.google.cloud.vision.v1.IListReferenceImagesRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1.IReferenceImage > ): void; /** @@ -2122,24 +2384,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listReferenceImages( - request: protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1.IListReferenceImagesRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage[], - protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1.IListReferenceImagesResponse + | PaginationCallback< + protos.google.cloud.vision.v1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1.IReferenceImage >, - callback?: Callback< - protosTypes.google.cloud.vision.v1.IReferenceImage[], - protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1.IListReferenceImagesResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1.IReferenceImage > ): Promise< [ - protosTypes.google.cloud.vision.v1.IReferenceImage[], - protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1.IListReferenceImagesResponse + protos.google.cloud.vision.v1.IReferenceImage[], + protos.google.cloud.vision.v1.IListReferenceImagesRequest | null, + protos.google.cloud.vision.v1.IListReferenceImagesResponse ] > | void { request = request || {}; @@ -2159,7 +2425,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listReferenceImages(request, options, callback); + return this.innerApiCalls.listReferenceImages(request, options, callback); } /** @@ -2195,7 +2461,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [ReferenceImage]{@link google.cloud.vision.v1.ReferenceImage} on 'data' event. */ listReferenceImagesStream( - request?: protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest, + request?: protos.google.cloud.vision.v1.IListReferenceImagesRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2209,29 +2475,88 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listReferenceImages.createStream( - this._innerApiCalls.listReferenceImages as gax.GaxCall, + return this.descriptors.page.listReferenceImages.createStream( + this.innerApiCalls.listReferenceImages as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listReferenceImages}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. Resource name of the product containing the reference images. + * + * Format is + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * A token identifying a page of results to be returned. This is the value + * of `nextPageToken` returned in a previous reference image list request. + * + * Defaults to the first page if not specified. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listReferenceImagesAsync( + request?: protos.google.cloud.vision.v1.IListReferenceImagesRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listReferenceImages.asyncIterate( + this.innerApiCalls['listReferenceImages'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1.IListProductsInProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsInProductSetResponse + protos.google.cloud.vision.v1.IProduct[], + protos.google.cloud.vision.v1.IListProductsInProductSetRequest | null, + protos.google.cloud.vision.v1.IListProductsInProductSetResponse ] >; listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1.IListProductsInProductSetRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsInProductSetResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1.IProduct + > + ): void; + listProductsInProductSet( + request: protos.google.cloud.vision.v1.IListProductsInProductSetRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1.IProduct > ): void; /** @@ -2273,24 +2598,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1.IListProductsInProductSetRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsInProductSetResponse + | PaginationCallback< + protos.google.cloud.vision.v1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1.IProduct >, - callback?: Callback< - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsInProductSetResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1.IProduct > ): Promise< [ - protosTypes.google.cloud.vision.v1.IProduct[], - protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1.IListProductsInProductSetResponse + protos.google.cloud.vision.v1.IProduct[], + protos.google.cloud.vision.v1.IListProductsInProductSetRequest | null, + protos.google.cloud.vision.v1.IListProductsInProductSetResponse ] > | void { request = request || {}; @@ -2310,7 +2639,7 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.listProductsInProductSet( + return this.innerApiCalls.listProductsInProductSet( request, options, callback @@ -2347,7 +2676,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [Product]{@link google.cloud.vision.v1.Product} on 'data' event. */ listProductsInProductSetStream( - request?: protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest, + request?: protos.google.cloud.vision.v1.IListProductsInProductSetRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2361,12 +2690,56 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProductsInProductSet.createStream( - this._innerApiCalls.listProductsInProductSet as gax.GaxCall, + return this.descriptors.page.listProductsInProductSet.createStream( + this.innerApiCalls.listProductsInProductSet as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProductsInProductSet}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The ProductSet resource for which to retrieve Products. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductsInProductSetAsync( + request?: protos.google.cloud.vision.v1.IListProductsInProductSetRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + name: request.name || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProductsInProductSet.asyncIterate( + this.innerApiCalls['listProductsInProductSet'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } // -------------------- // -- Path templates -- // -------------------- @@ -2379,9 +2752,9 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ locationPath(project: string, location: string) { - return this._pathTemplates.locationPathTemplate.render({ - project, - location, + return this.pathTemplates.locationPathTemplate.render({ + project: project, + location: location, }); } @@ -2393,7 +2766,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName).project; + return this.pathTemplates.locationPathTemplate.match(locationName).project; } /** @@ -2404,8 +2777,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName) - .location; + return this.pathTemplates.locationPathTemplate.match(locationName).location; } /** @@ -2417,10 +2789,10 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ productPath(project: string, location: string, product: string) { - return this._pathTemplates.productPathTemplate.render({ - project, - location, - product, + return this.pathTemplates.productPathTemplate.render({ + project: project, + location: location, + product: product, }); } @@ -2432,7 +2804,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).project; + return this.pathTemplates.productPathTemplate.match(productName).project; } /** @@ -2443,7 +2815,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).location; + return this.pathTemplates.productPathTemplate.match(productName).location; } /** @@ -2454,7 +2826,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product. */ matchProductFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).product; + return this.pathTemplates.productPathTemplate.match(productName).product; } /** @@ -2466,9 +2838,9 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ productSetPath(project: string, location: string, productSet: string) { - return this._pathTemplates.productSetPathTemplate.render({ - project, - location, + return this.pathTemplates.productSetPathTemplate.render({ + project: project, + location: location, product_set: productSet, }); } @@ -2481,7 +2853,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .project; } @@ -2493,7 +2865,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .location; } @@ -2505,7 +2877,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product_set. */ matchProductSetFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .product_set; } @@ -2524,10 +2896,10 @@ export class ProductSearchClient { product: string, referenceImage: string ) { - return this._pathTemplates.referenceImagePathTemplate.render({ - project, - location, - product, + return this.pathTemplates.referenceImagePathTemplate.render({ + project: project, + location: location, + product: product, reference_image: referenceImage, }); } @@ -2540,7 +2912,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).project; } @@ -2553,7 +2925,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).location; } @@ -2566,7 +2938,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product. */ matchProductFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).product; } @@ -2579,7 +2951,7 @@ export class ProductSearchClient { * @returns {string} A string representing the reference_image. */ matchReferenceImageFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).reference_image; } diff --git a/packages/google-cloud-vision/src/v1p1beta1/image_annotator_client.ts b/packages/google-cloud-vision/src/v1p1beta1/image_annotator_client.ts index a3786cb4ba8..182823fa71a 100644 --- a/packages/google-cloud-vision/src/v1p1beta1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1p1beta1/image_annotator_client.ts @@ -17,16 +17,10 @@ // ** All changes to this file may be overwritten. ** import * as gax from 'google-gax'; -import { - APICallback, - Callback, - CallOptions, - Descriptors, - ClientOptions, -} from 'google-gax'; +import {Callback, CallOptions, Descriptors, ClientOptions} from 'google-gax'; import * as path from 'path'; -import * as protosTypes from '../../protos/protos'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './image_annotator_client_config.json'; const version = require('../../../package.json').version; @@ -39,13 +33,6 @@ const version = require('../../../package.json').version; * @memberof v1p1beta1 */ export class ImageAnnotatorClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -53,6 +40,13 @@ export class ImageAnnotatorClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; imageAnnotatorStub?: Promise<{[name: string]: Function}>; /** @@ -144,7 +138,10 @@ export class ImageAnnotatorClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // Put together the default options sent with requests. @@ -158,7 +155,7 @@ export class ImageAnnotatorClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -185,7 +182,7 @@ export class ImageAnnotatorClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.vision.v1p1beta1.ImageAnnotator' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.vision.v1p1beta1.ImageAnnotator, this._opts ) as Promise<{[method: string]: Function}>; @@ -193,9 +190,8 @@ export class ImageAnnotatorClient { // Iterate over each of the methods that the service provides // and create an API call method for each. const imageAnnotatorStubMethods = ['batchAnnotateImages']; - for (const methodName of imageAnnotatorStubMethods) { - const innerCallPromise = this.imageAnnotatorStub.then( + const callPromise = this.imageAnnotatorStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -209,20 +205,14 @@ export class ImageAnnotatorClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.imageAnnotatorStub; @@ -282,26 +272,37 @@ export class ImageAnnotatorClient { // -- Service calls -- // ------------------- batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, ( - | protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + | protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest | undefined ), {} | undefined ] >; batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + batchAnnotateImages( + request: protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest, + callback: Callback< + protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -318,26 +319,28 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse, ( - | protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest + | protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest | undefined ), {} | undefined @@ -353,7 +356,7 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.batchAnnotateImages(request, options, callback); + return this.innerApiCalls.batchAnnotateImages(request, options, callback); } /** @@ -373,4 +376,5 @@ export class ImageAnnotatorClient { } } import {FeaturesMethod} from '../helpers'; +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ImageAnnotatorClient extends FeaturesMethod {} diff --git a/packages/google-cloud-vision/src/v1p2beta1/image_annotator_client.ts b/packages/google-cloud-vision/src/v1p2beta1/image_annotator_client.ts index a8438b164c5..f2eef439883 100644 --- a/packages/google-cloud-vision/src/v1p2beta1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1p2beta1/image_annotator_client.ts @@ -18,7 +18,6 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, @@ -27,7 +26,7 @@ import { } from 'google-gax'; import * as path from 'path'; -import * as protosTypes from '../../protos/protos'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './image_annotator_client_config.json'; const version = require('../../../package.json').version; @@ -40,13 +39,6 @@ const version = require('../../../package.json').version; * @memberof v1p2beta1 */ export class ImageAnnotatorClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -54,6 +46,13 @@ export class ImageAnnotatorClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; operationsClient: gax.OperationsClient; imageAnnotatorStub?: Promise<{[name: string]: Function}>; @@ -146,7 +145,10 @@ export class ImageAnnotatorClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "long-running operations", which return a @@ -154,6 +156,7 @@ export class ImageAnnotatorClient { // rather than holding a request open. const protoFilesRoot = opts.fallback ? this._gaxModule.protobuf.Root.fromJSON( + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json') ) : this._gaxModule.protobuf.loadSync(nodejsProtoPath); @@ -171,7 +174,7 @@ export class ImageAnnotatorClient { '.google.cloud.vision.v1p2beta1.OperationMetadata' ) as gax.protobuf.Type; - this._descriptors.longrunning = { + this.descriptors.longrunning = { asyncBatchAnnotateFiles: new this._gaxModule.LongrunningDescriptor( this.operationsClient, asyncBatchAnnotateFilesResponse.decode.bind( @@ -194,7 +197,7 @@ export class ImageAnnotatorClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -221,7 +224,7 @@ export class ImageAnnotatorClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.vision.v1p2beta1.ImageAnnotator' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.vision.v1p2beta1.ImageAnnotator, this._opts ) as Promise<{[method: string]: Function}>; @@ -232,9 +235,8 @@ export class ImageAnnotatorClient { 'batchAnnotateImages', 'asyncBatchAnnotateFiles', ]; - for (const methodName of imageAnnotatorStubMethods) { - const innerCallPromise = this.imageAnnotatorStub.then( + const callPromise = this.imageAnnotatorStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -248,20 +250,14 @@ export class ImageAnnotatorClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.imageAnnotatorStub; @@ -321,26 +317,37 @@ export class ImageAnnotatorClient { // -- Service calls -- // ------------------- batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, ( - | protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + | protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest | undefined ), {} | undefined ] >; batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + batchAnnotateImages( + request: protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest, + callback: Callback< + protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -357,26 +364,28 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse, ( - | protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest + | protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest | undefined ), {} | undefined @@ -392,32 +401,43 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.batchAnnotateImages(request, options, callback); + return this.innerApiCalls.batchAnnotateImages(request, options, callback); } asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p2beta1.IOperationMetadata + protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p2beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p2beta1.IOperationMetadata + protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p2beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + asyncBatchAnnotateFiles( + request: protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p2beta1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -439,32 +459,32 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p2beta1.IOperationMetadata + protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p2beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p2beta1.IOperationMetadata + protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p2beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p2beta1.IOperationMetadata + protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p2beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -478,7 +498,7 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.asyncBatchAnnotateFiles( + return this.innerApiCalls.asyncBatchAnnotateFiles( request, options, callback @@ -502,4 +522,5 @@ export class ImageAnnotatorClient { } } import {FeaturesMethod} from '../helpers'; +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ImageAnnotatorClient extends FeaturesMethod {} diff --git a/packages/google-cloud-vision/src/v1p3beta1/image_annotator_client.ts b/packages/google-cloud-vision/src/v1p3beta1/image_annotator_client.ts index 700f8dadc2c..a23040d64c3 100644 --- a/packages/google-cloud-vision/src/v1p3beta1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1p3beta1/image_annotator_client.ts @@ -18,7 +18,6 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, @@ -27,7 +26,7 @@ import { } from 'google-gax'; import * as path from 'path'; -import * as protosTypes from '../../protos/protos'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './image_annotator_client_config.json'; const version = require('../../../package.json').version; @@ -40,14 +39,6 @@ const version = require('../../../package.json').version; * @memberof v1p3beta1 */ export class ImageAnnotatorClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; - private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -55,6 +46,14 @@ export class ImageAnnotatorClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; operationsClient: gax.OperationsClient; imageAnnotatorStub?: Promise<{[name: string]: Function}>; @@ -147,13 +146,16 @@ export class ImageAnnotatorClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. - this._pathTemplates = { + this.pathTemplates = { productPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/products/{product}' ), @@ -170,6 +172,7 @@ export class ImageAnnotatorClient { // rather than holding a request open. const protoFilesRoot = opts.fallback ? this._gaxModule.protobuf.Root.fromJSON( + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json') ) : this._gaxModule.protobuf.loadSync(nodejsProtoPath); @@ -187,7 +190,7 @@ export class ImageAnnotatorClient { '.google.cloud.vision.v1p3beta1.OperationMetadata' ) as gax.protobuf.Type; - this._descriptors.longrunning = { + this.descriptors.longrunning = { asyncBatchAnnotateFiles: new this._gaxModule.LongrunningDescriptor( this.operationsClient, asyncBatchAnnotateFilesResponse.decode.bind( @@ -210,7 +213,7 @@ export class ImageAnnotatorClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -237,7 +240,7 @@ export class ImageAnnotatorClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.vision.v1p3beta1.ImageAnnotator' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.vision.v1p3beta1.ImageAnnotator, this._opts ) as Promise<{[method: string]: Function}>; @@ -248,9 +251,8 @@ export class ImageAnnotatorClient { 'batchAnnotateImages', 'asyncBatchAnnotateFiles', ]; - for (const methodName of imageAnnotatorStubMethods) { - const innerCallPromise = this.imageAnnotatorStub.then( + const callPromise = this.imageAnnotatorStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -264,20 +266,14 @@ export class ImageAnnotatorClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.imageAnnotatorStub; @@ -337,26 +333,37 @@ export class ImageAnnotatorClient { // -- Service calls -- // ------------------- batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, ( - | protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + | protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest | undefined ), {} | undefined ] >; batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + batchAnnotateImages( + request: protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -373,26 +380,28 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse, ( - | protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest + | protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest | undefined ), {} | undefined @@ -408,32 +417,43 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.batchAnnotateImages(request, options, callback); + return this.innerApiCalls.batchAnnotateImages(request, options, callback); } asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p3beta1.IOperationMetadata + protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p3beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p3beta1.IOperationMetadata + protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p3beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + asyncBatchAnnotateFiles( + request: protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p3beta1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -455,32 +475,32 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p3beta1.IOperationMetadata + protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p3beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p3beta1.IOperationMetadata + protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p3beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p3beta1.IOperationMetadata + protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p3beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -494,7 +514,7 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.asyncBatchAnnotateFiles( + return this.innerApiCalls.asyncBatchAnnotateFiles( request, options, callback @@ -513,10 +533,10 @@ export class ImageAnnotatorClient { * @returns {string} Resource name string. */ productPath(project: string, location: string, product: string) { - return this._pathTemplates.productPathTemplate.render({ - project, - location, - product, + return this.pathTemplates.productPathTemplate.render({ + project: project, + location: location, + product: product, }); } @@ -528,7 +548,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).project; + return this.pathTemplates.productPathTemplate.match(productName).project; } /** @@ -539,7 +559,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).location; + return this.pathTemplates.productPathTemplate.match(productName).location; } /** @@ -550,7 +570,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product. */ matchProductFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).product; + return this.pathTemplates.productPathTemplate.match(productName).product; } /** @@ -562,9 +582,9 @@ export class ImageAnnotatorClient { * @returns {string} Resource name string. */ productSetPath(project: string, location: string, productSet: string) { - return this._pathTemplates.productSetPathTemplate.render({ - project, - location, + return this.pathTemplates.productSetPathTemplate.render({ + project: project, + location: location, product_set: productSet, }); } @@ -577,7 +597,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .project; } @@ -589,7 +609,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .location; } @@ -601,7 +621,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product_set. */ matchProductSetFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .product_set; } @@ -620,10 +640,10 @@ export class ImageAnnotatorClient { product: string, referenceImage: string ) { - return this._pathTemplates.referenceImagePathTemplate.render({ - project, - location, - product, + return this.pathTemplates.referenceImagePathTemplate.render({ + project: project, + location: location, + product: product, reference_image: referenceImage, }); } @@ -636,7 +656,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).project; } @@ -649,7 +669,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).location; } @@ -662,7 +682,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product. */ matchProductFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).product; } @@ -675,7 +695,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the reference_image. */ matchReferenceImageFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).reference_image; } @@ -697,4 +717,5 @@ export class ImageAnnotatorClient { } } import {FeaturesMethod} from '../helpers'; +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ImageAnnotatorClient extends FeaturesMethod {} diff --git a/packages/google-cloud-vision/src/v1p3beta1/product_search_client.ts b/packages/google-cloud-vision/src/v1p3beta1/product_search_client.ts index 332285c7910..e25c2cba8c4 100644 --- a/packages/google-cloud-vision/src/v1p3beta1/product_search_client.ts +++ b/packages/google-cloud-vision/src/v1p3beta1/product_search_client.ts @@ -18,19 +18,19 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, ClientOptions, LROperation, PaginationCallback, - PaginationResponse, + GaxCall, } from 'google-gax'; import * as path from 'path'; import {Transform} from 'stream'; -import * as protosTypes from '../../protos/protos'; +import {RequestType} from 'google-gax/build/src/apitypes'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './product_search_client_config.json'; const version = require('../../../package.json').version; @@ -54,14 +54,6 @@ const version = require('../../../package.json').version; * @memberof v1p3beta1 */ export class ProductSearchClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; - private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -69,6 +61,14 @@ export class ProductSearchClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; operationsClient: gax.OperationsClient; productSearchStub?: Promise<{[name: string]: Function}>; @@ -161,13 +161,16 @@ export class ProductSearchClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. - this._pathTemplates = { + this.pathTemplates = { locationPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}' ), @@ -185,7 +188,7 @@ export class ProductSearchClient { // Some of the methods on this service return "paged" results, // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. - this._descriptors.page = { + this.descriptors.page = { listProductSets: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', @@ -213,6 +216,7 @@ export class ProductSearchClient { // rather than holding a request open. const protoFilesRoot = opts.fallback ? this._gaxModule.protobuf.Root.fromJSON( + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json') ) : this._gaxModule.protobuf.loadSync(nodejsProtoPath); @@ -230,7 +234,7 @@ export class ProductSearchClient { '.google.cloud.vision.v1p3beta1.BatchOperationMetadata' ) as gax.protobuf.Type; - this._descriptors.longrunning = { + this.descriptors.longrunning = { importProductSets: new this._gaxModule.LongrunningDescriptor( this.operationsClient, importProductSetsResponse.decode.bind(importProductSetsResponse), @@ -249,7 +253,7 @@ export class ProductSearchClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -276,7 +280,7 @@ export class ProductSearchClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.vision.v1p3beta1.ProductSearch' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.vision.v1p3beta1.ProductSearch, this._opts ) as Promise<{[method: string]: Function}>; @@ -303,9 +307,8 @@ export class ProductSearchClient { 'listProductsInProductSet', 'importProductSets', ]; - for (const methodName of productSearchStubMethods) { - const innerCallPromise = this.productSearchStub.then( + const callPromise = this.productSearchStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -319,20 +322,14 @@ export class ProductSearchClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.productSearchStub; @@ -392,26 +389,34 @@ export class ProductSearchClient { // -- Service calls -- // ------------------- createProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProductSet, + protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest | undefined, {} | undefined ] >; createProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createProductSet( + request: protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -442,28 +447,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProductSet, + protos.google.cloud.vision.v1p3beta1.ICreateProductSetRequest | undefined, {} | undefined ] > | void { @@ -484,29 +488,37 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createProductSet(request, options, callback); + return this.innerApiCalls.createProductSet(request, options, callback); } getProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProductSet, + protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest | undefined, {} | undefined ] >; getProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + getProductSet( + request: protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -530,28 +542,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProductSet, + protos.google.cloud.vision.v1p3beta1.IGetProductSetRequest | undefined, {} | undefined ] > | void { @@ -572,29 +583,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getProductSet(request, options, callback); + return this.innerApiCalls.getProductSet(request, options, callback); } updateProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProductSet, + protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest | undefined, {} | undefined ] >; updateProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + updateProductSet( + request: protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -623,28 +642,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ updateProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest + protos.google.cloud.vision.v1p3beta1.IProductSet, + | protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProductSet, + protos.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest | undefined, {} | undefined ] > | void { @@ -665,29 +683,37 @@ export class ProductSearchClient { 'product_set.name': request.productSet!.name || '', }); this.initialize(); - return this._innerApiCalls.updateProductSet(request, options, callback); + return this.innerApiCalls.updateProductSet(request, options, callback); } deleteProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest | undefined, {} | undefined ] >; deleteProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteProductSet( + request: protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -714,28 +740,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest | undefined, {} | undefined ] > | void { @@ -756,29 +781,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteProductSet(request, options, callback); + return this.innerApiCalls.deleteProductSet(request, options, callback); } createProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - ( - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProduct, + protos.google.cloud.vision.v1p3beta1.ICreateProductRequest | undefined, {} | undefined ] >; createProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.ICreateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createProduct( + request: protos.google.cloud.vision.v1p3beta1.ICreateProductRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.ICreateProductRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -812,28 +845,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.ICreateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.ICreateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - ( - | protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProduct, + protos.google.cloud.vision.v1p3beta1.ICreateProductRequest | undefined, {} | undefined ] > | void { @@ -854,25 +886,37 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createProduct(request, options, callback); + return this.innerApiCalls.createProduct(request, options, callback); } getProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct, + protos.google.cloud.vision.v1p3beta1.IGetProductRequest | undefined, {} | undefined ] >; getProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.IGetProductRequest + | null + | undefined, + {} | null | undefined + > + ): void; + getProduct( + request: protos.google.cloud.vision.v1p3beta1.IGetProductRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.IGetProductRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -896,24 +940,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - | protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.IGetProductRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.IGetProductRequest + | null + | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct, + protos.google.cloud.vision.v1p3beta1.IGetProductRequest | undefined, {} | undefined ] > | void { @@ -934,29 +981,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getProduct(request, options, callback); + return this.innerApiCalls.getProduct(request, options, callback); } updateProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProduct, + protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest | undefined, {} | undefined ] >; updateProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + updateProduct( + request: protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -993,28 +1048,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ updateProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest + protos.google.cloud.vision.v1p3beta1.IProduct, + | protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest - | undefined - ), + protos.google.cloud.vision.v1p3beta1.IProduct, + protos.google.cloud.vision.v1p3beta1.IUpdateProductRequest | undefined, {} | undefined ] > | void { @@ -1035,29 +1089,37 @@ export class ProductSearchClient { 'product.name': request.product!.name || '', }); this.initialize(); - return this._innerApiCalls.updateProduct(request, options, callback); + return this.innerApiCalls.updateProduct(request, options, callback); } deleteProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest | undefined, {} | undefined ] >; deleteProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteProduct( + request: protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1085,28 +1147,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteProduct( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p3beta1.IDeleteProductRequest | undefined, {} | undefined ] > | void { @@ -1127,29 +1188,40 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteProduct(request, options, callback); + return this.innerApiCalls.deleteProduct(request, options, callback); } createReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, + protos.google.cloud.vision.v1p3beta1.IReferenceImage, ( - | protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + | protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest | undefined ), {} | undefined ] >; createReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1p3beta1.IReferenceImage, + | protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createReferenceImage( + request: protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IReferenceImage, + | protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1195,26 +1267,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1p3beta1.IReferenceImage, + | protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1p3beta1.IReferenceImage, + | protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, + protos.google.cloud.vision.v1p3beta1.IReferenceImage, ( - | protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest + | protos.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest | undefined ), {} | undefined @@ -1237,29 +1311,40 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createReferenceImage(request, options, callback); + return this.innerApiCalls.createReferenceImage(request, options, callback); } deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + | protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest | undefined ), {} | undefined ] >; deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteReferenceImage( + request: protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1290,26 +1375,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest + | protos.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest | undefined ), {} | undefined @@ -1332,29 +1419,40 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteReferenceImage(request, options, callback); + return this.innerApiCalls.deleteReferenceImage(request, options, callback); } getReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, + protos.google.cloud.vision.v1p3beta1.IReferenceImage, ( - | protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + | protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest | undefined ), {} | undefined ] >; getReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + protos.google.cloud.vision.v1p3beta1.IReferenceImage, + | protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + getReferenceImage( + request: protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest, + callback: Callback< + protos.google.cloud.vision.v1p3beta1.IReferenceImage, + | protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1379,26 +1477,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getReferenceImage( - request: protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + protos.google.cloud.vision.v1p3beta1.IReferenceImage, + | protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + protos.google.cloud.vision.v1p3beta1.IReferenceImage, + | protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage, + protos.google.cloud.vision.v1p3beta1.IReferenceImage, ( - | protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest + | protos.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest | undefined ), {} | undefined @@ -1421,29 +1521,40 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getReferenceImage(request, options, callback); + return this.innerApiCalls.getReferenceImage(request, options, callback); } addProductToProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + | protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest | undefined ), {} | undefined ] >; addProductToProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + addProductToProductSet( + request: protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1475,26 +1586,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ addProductToProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest + | protos.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest | undefined ), {} | undefined @@ -1517,33 +1630,44 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.addProductToProductSet( + return this.innerApiCalls.addProductToProductSet( request, options, callback ); } removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + | protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest | undefined ), {} | undefined ] >; removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + removeProductFromProductSet( + request: protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1572,26 +1696,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest + | protos.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest | undefined ), {} | undefined @@ -1614,7 +1740,7 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.removeProductFromProductSet( + return this.innerApiCalls.removeProductFromProductSet( request, options, callback @@ -1622,28 +1748,39 @@ export class ProductSearchClient { } importProductSets( - request: protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1p3beta1.IImportProductSetsRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p3beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p3beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; importProductSets( - request: protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1p3beta1.IImportProductSetsRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p3beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p3beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + importProductSets( + request: protos.google.cloud.vision.v1p3beta1.IImportProductSetsRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p3beta1.IBatchOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -1674,32 +1811,32 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ importProductSets( - request: protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1p3beta1.IImportProductSetsRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p3beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p3beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p3beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p3beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p3beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p3beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -1720,25 +1857,37 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.importProductSets(request, options, callback); + return this.innerApiCalls.importProductSets(request, options, callback); } listProductSets( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsResponse + protos.google.cloud.vision.v1p3beta1.IProductSet[], + protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest | null, + protos.google.cloud.vision.v1p3beta1.IListProductSetsResponse ] >; listProductSets( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProductSet + > + ): void; + listProductSets( + request: protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProductSet > ): void; /** @@ -1778,24 +1927,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProductSets( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsResponse + | PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProductSet >, - callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProductSet > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsResponse + protos.google.cloud.vision.v1p3beta1.IProductSet[], + protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest | null, + protos.google.cloud.vision.v1p3beta1.IListProductSetsResponse ] > | void { request = request || {}; @@ -1815,7 +1968,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listProductSets(request, options, callback); + return this.innerApiCalls.listProductSets(request, options, callback); } /** @@ -1847,7 +2000,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [ProductSet]{@link google.cloud.vision.v1p3beta1.ProductSet} on 'data' event. */ listProductSetsStream( - request?: protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + request?: protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -1861,29 +2014,84 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProductSets.createStream( - this._innerApiCalls.listProductSets as gax.GaxCall, + return this.descriptors.page.listProductSets.createStream( + this.innerApiCalls.listProductSets as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProductSets}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The project from which ProductSets should be listed. + * + * Format is `projects/PROJECT_ID/locations/LOC_ID`. + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductSetsAsync( + request?: protos.google.cloud.vision.v1p3beta1.IListProductSetsRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProductSets.asyncIterate( + this.innerApiCalls['listProductSets'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listProducts( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductsRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsResponse + protos.google.cloud.vision.v1p3beta1.IProduct[], + protos.google.cloud.vision.v1p3beta1.IListProductsRequest | null, + protos.google.cloud.vision.v1p3beta1.IListProductsResponse ] >; listProducts( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductsRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductsRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct + > + ): void; + listProducts( + request: protos.google.cloud.vision.v1p3beta1.IListProductsRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductsRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct > ): void; /** @@ -1923,24 +2131,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProducts( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductsRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsResponse + | PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductsRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct >, - callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductsRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsResponse + protos.google.cloud.vision.v1p3beta1.IProduct[], + protos.google.cloud.vision.v1p3beta1.IListProductsRequest | null, + protos.google.cloud.vision.v1p3beta1.IListProductsResponse ] > | void { request = request || {}; @@ -1960,7 +2172,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listProducts(request, options, callback); + return this.innerApiCalls.listProducts(request, options, callback); } /** @@ -1993,7 +2205,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [Product]{@link google.cloud.vision.v1p3beta1.Product} on 'data' event. */ listProductsStream( - request?: protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest, + request?: protos.google.cloud.vision.v1p3beta1.IListProductsRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2007,29 +2219,85 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProducts.createStream( - this._innerApiCalls.listProducts as gax.GaxCall, + return this.descriptors.page.listProducts.createStream( + this.innerApiCalls.listProducts as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProducts}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The project OR ProductSet from which Products should be listed. + * + * Format: + * `projects/PROJECT_ID/locations/LOC_ID` + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductsAsync( + request?: protos.google.cloud.vision.v1p3beta1.IListProductsRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProducts.asyncIterate( + this.innerApiCalls['listProducts'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listReferenceImages( - request: protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + protos.google.cloud.vision.v1p3beta1.IReferenceImage[], + protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest | null, + protos.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse ] >; listReferenceImages( - request: protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IReferenceImage + > + ): void; + listReferenceImages( + request: protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IReferenceImage > ): void; /** @@ -2074,24 +2342,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listReferenceImages( - request: protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + | PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IReferenceImage >, - callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IReferenceImage > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse + protos.google.cloud.vision.v1p3beta1.IReferenceImage[], + protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest | null, + protos.google.cloud.vision.v1p3beta1.IListReferenceImagesResponse ] > | void { request = request || {}; @@ -2111,7 +2383,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listReferenceImages(request, options, callback); + return this.innerApiCalls.listReferenceImages(request, options, callback); } /** @@ -2147,7 +2419,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [ReferenceImage]{@link google.cloud.vision.v1p3beta1.ReferenceImage} on 'data' event. */ listReferenceImagesStream( - request?: protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + request?: protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2161,29 +2433,88 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listReferenceImages.createStream( - this._innerApiCalls.listReferenceImages as gax.GaxCall, + return this.descriptors.page.listReferenceImages.createStream( + this.innerApiCalls.listReferenceImages as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listReferenceImages}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. Resource name of the product containing the reference images. + * + * Format is + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * A token identifying a page of results to be returned. This is the value + * of `nextPageToken` returned in a previous reference image list request. + * + * Defaults to the first page if not specified. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listReferenceImagesAsync( + request?: protos.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listReferenceImages.asyncIterate( + this.innerApiCalls['listReferenceImages'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + protos.google.cloud.vision.v1p3beta1.IProduct[], + protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest | null, + protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse ] >; listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct + > + ): void; + listProductsInProductSet( + request: protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct > ): void; /** @@ -2225,24 +2556,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + | PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct >, - callback?: Callback< - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1p3beta1.IProduct > ): Promise< [ - protosTypes.google.cloud.vision.v1p3beta1.IProduct[], - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse + protos.google.cloud.vision.v1p3beta1.IProduct[], + protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest | null, + protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetResponse ] > | void { request = request || {}; @@ -2262,7 +2597,7 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.listProductsInProductSet( + return this.innerApiCalls.listProductsInProductSet( request, options, callback @@ -2299,7 +2634,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [Product]{@link google.cloud.vision.v1p3beta1.Product} on 'data' event. */ listProductsInProductSetStream( - request?: protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + request?: protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2313,12 +2648,56 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProductsInProductSet.createStream( - this._innerApiCalls.listProductsInProductSet as gax.GaxCall, + return this.descriptors.page.listProductsInProductSet.createStream( + this.innerApiCalls.listProductsInProductSet as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProductsInProductSet}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The ProductSet resource for which to retrieve Products. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductsInProductSetAsync( + request?: protos.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + name: request.name || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProductsInProductSet.asyncIterate( + this.innerApiCalls['listProductsInProductSet'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } // -------------------- // -- Path templates -- // -------------------- @@ -2331,9 +2710,9 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ locationPath(project: string, location: string) { - return this._pathTemplates.locationPathTemplate.render({ - project, - location, + return this.pathTemplates.locationPathTemplate.render({ + project: project, + location: location, }); } @@ -2345,7 +2724,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName).project; + return this.pathTemplates.locationPathTemplate.match(locationName).project; } /** @@ -2356,8 +2735,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName) - .location; + return this.pathTemplates.locationPathTemplate.match(locationName).location; } /** @@ -2369,10 +2747,10 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ productPath(project: string, location: string, product: string) { - return this._pathTemplates.productPathTemplate.render({ - project, - location, - product, + return this.pathTemplates.productPathTemplate.render({ + project: project, + location: location, + product: product, }); } @@ -2384,7 +2762,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).project; + return this.pathTemplates.productPathTemplate.match(productName).project; } /** @@ -2395,7 +2773,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).location; + return this.pathTemplates.productPathTemplate.match(productName).location; } /** @@ -2406,7 +2784,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product. */ matchProductFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).product; + return this.pathTemplates.productPathTemplate.match(productName).product; } /** @@ -2418,9 +2796,9 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ productSetPath(project: string, location: string, productSet: string) { - return this._pathTemplates.productSetPathTemplate.render({ - project, - location, + return this.pathTemplates.productSetPathTemplate.render({ + project: project, + location: location, product_set: productSet, }); } @@ -2433,7 +2811,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .project; } @@ -2445,7 +2823,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .location; } @@ -2457,7 +2835,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product_set. */ matchProductSetFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .product_set; } @@ -2476,10 +2854,10 @@ export class ProductSearchClient { product: string, referenceImage: string ) { - return this._pathTemplates.referenceImagePathTemplate.render({ - project, - location, - product, + return this.pathTemplates.referenceImagePathTemplate.render({ + project: project, + location: location, + product: product, reference_image: referenceImage, }); } @@ -2492,7 +2870,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).project; } @@ -2505,7 +2883,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).location; } @@ -2518,7 +2896,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product. */ matchProductFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).product; } @@ -2531,7 +2909,7 @@ export class ProductSearchClient { * @returns {string} A string representing the reference_image. */ matchReferenceImageFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).reference_image; } diff --git a/packages/google-cloud-vision/src/v1p4beta1/image_annotator_client.ts b/packages/google-cloud-vision/src/v1p4beta1/image_annotator_client.ts index 523adfe9104..ac649dc957c 100644 --- a/packages/google-cloud-vision/src/v1p4beta1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1p4beta1/image_annotator_client.ts @@ -18,7 +18,6 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, @@ -27,7 +26,7 @@ import { } from 'google-gax'; import * as path from 'path'; -import * as protosTypes from '../../protos/protos'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './image_annotator_client_config.json'; const version = require('../../../package.json').version; @@ -40,14 +39,6 @@ const version = require('../../../package.json').version; * @memberof v1p4beta1 */ export class ImageAnnotatorClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; - private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -55,6 +46,14 @@ export class ImageAnnotatorClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; operationsClient: gax.OperationsClient; imageAnnotatorStub?: Promise<{[name: string]: Function}>; @@ -147,13 +146,16 @@ export class ImageAnnotatorClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. - this._pathTemplates = { + this.pathTemplates = { productPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/products/{product}' ), @@ -170,6 +172,7 @@ export class ImageAnnotatorClient { // rather than holding a request open. const protoFilesRoot = opts.fallback ? this._gaxModule.protobuf.Root.fromJSON( + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json') ) : this._gaxModule.protobuf.loadSync(nodejsProtoPath); @@ -193,7 +196,7 @@ export class ImageAnnotatorClient { '.google.cloud.vision.v1p4beta1.OperationMetadata' ) as gax.protobuf.Type; - this._descriptors.longrunning = { + this.descriptors.longrunning = { asyncBatchAnnotateImages: new this._gaxModule.LongrunningDescriptor( this.operationsClient, asyncBatchAnnotateImagesResponse.decode.bind( @@ -225,7 +228,7 @@ export class ImageAnnotatorClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -252,7 +255,7 @@ export class ImageAnnotatorClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.vision.v1p4beta1.ImageAnnotator' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.vision.v1p4beta1.ImageAnnotator, this._opts ) as Promise<{[method: string]: Function}>; @@ -265,9 +268,8 @@ export class ImageAnnotatorClient { 'asyncBatchAnnotateImages', 'asyncBatchAnnotateFiles', ]; - for (const methodName of imageAnnotatorStubMethods) { - const innerCallPromise = this.imageAnnotatorStub.then( + const callPromise = this.imageAnnotatorStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -281,20 +283,14 @@ export class ImageAnnotatorClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.imageAnnotatorStub; @@ -354,26 +350,37 @@ export class ImageAnnotatorClient { // -- Service calls -- // ------------------- batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, ( - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest | undefined ), {} | undefined ] >; batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + batchAnnotateImages( + request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -390,26 +397,28 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ batchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse, ( - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest | undefined ), {} | undefined @@ -425,29 +434,40 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.batchAnnotateImages(request, options, callback); + return this.innerApiCalls.batchAnnotateImages(request, options, callback); } batchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, ( - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest | undefined ), {} | undefined ] >; batchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + batchAnnotateFiles( + request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -471,26 +491,28 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ batchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse, ( - | protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest + | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest | undefined ), {} | undefined @@ -506,32 +528,43 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.batchAnnotateFiles(request, options, callback); + return this.innerApiCalls.batchAnnotateFiles(request, options, callback); } asyncBatchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; asyncBatchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + asyncBatchAnnotateImages( + request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -558,32 +591,32 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ asyncBatchAnnotateImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -597,35 +630,46 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.asyncBatchAnnotateImages( + return this.innerApiCalls.asyncBatchAnnotateImages( request, options, callback ); } asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + asyncBatchAnnotateFiles( + request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -647,32 +691,32 @@ export class ImageAnnotatorClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ asyncBatchAnnotateFiles( - request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest, + request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, - protosTypes.google.cloud.vision.v1p4beta1.IOperationMetadata + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -686,7 +730,7 @@ export class ImageAnnotatorClient { } options = options || {}; this.initialize(); - return this._innerApiCalls.asyncBatchAnnotateFiles( + return this.innerApiCalls.asyncBatchAnnotateFiles( request, options, callback @@ -705,10 +749,10 @@ export class ImageAnnotatorClient { * @returns {string} Resource name string. */ productPath(project: string, location: string, product: string) { - return this._pathTemplates.productPathTemplate.render({ - project, - location, - product, + return this.pathTemplates.productPathTemplate.render({ + project: project, + location: location, + product: product, }); } @@ -720,7 +764,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).project; + return this.pathTemplates.productPathTemplate.match(productName).project; } /** @@ -731,7 +775,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).location; + return this.pathTemplates.productPathTemplate.match(productName).location; } /** @@ -742,7 +786,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product. */ matchProductFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).product; + return this.pathTemplates.productPathTemplate.match(productName).product; } /** @@ -754,9 +798,9 @@ export class ImageAnnotatorClient { * @returns {string} Resource name string. */ productSetPath(project: string, location: string, productSet: string) { - return this._pathTemplates.productSetPathTemplate.render({ - project, - location, + return this.pathTemplates.productSetPathTemplate.render({ + project: project, + location: location, product_set: productSet, }); } @@ -769,7 +813,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .project; } @@ -781,7 +825,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .location; } @@ -793,7 +837,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product_set. */ matchProductSetFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .product_set; } @@ -812,10 +856,10 @@ export class ImageAnnotatorClient { product: string, referenceImage: string ) { - return this._pathTemplates.referenceImagePathTemplate.render({ - project, - location, - product, + return this.pathTemplates.referenceImagePathTemplate.render({ + project: project, + location: location, + product: product, reference_image: referenceImage, }); } @@ -828,7 +872,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the project. */ matchProjectFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).project; } @@ -841,7 +885,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the location. */ matchLocationFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).location; } @@ -854,7 +898,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the product. */ matchProductFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).product; } @@ -867,7 +911,7 @@ export class ImageAnnotatorClient { * @returns {string} A string representing the reference_image. */ matchReferenceImageFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).reference_image; } @@ -889,4 +933,5 @@ export class ImageAnnotatorClient { } } import {FeaturesMethod} from '../helpers'; +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ImageAnnotatorClient extends FeaturesMethod {} diff --git a/packages/google-cloud-vision/src/v1p4beta1/product_search_client.ts b/packages/google-cloud-vision/src/v1p4beta1/product_search_client.ts index fe612195fc7..89850fbe9c3 100644 --- a/packages/google-cloud-vision/src/v1p4beta1/product_search_client.ts +++ b/packages/google-cloud-vision/src/v1p4beta1/product_search_client.ts @@ -18,19 +18,19 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, ClientOptions, LROperation, PaginationCallback, - PaginationResponse, + GaxCall, } from 'google-gax'; import * as path from 'path'; import {Transform} from 'stream'; -import * as protosTypes from '../../protos/protos'; +import {RequestType} from 'google-gax/build/src/apitypes'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './product_search_client_config.json'; const version = require('../../../package.json').version; @@ -58,14 +58,6 @@ const version = require('../../../package.json').version; * @memberof v1p4beta1 */ export class ProductSearchClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; - private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -73,6 +65,14 @@ export class ProductSearchClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; operationsClient: gax.OperationsClient; productSearchStub?: Promise<{[name: string]: Function}>; @@ -165,13 +165,16 @@ export class ProductSearchClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. - this._pathTemplates = { + this.pathTemplates = { locationPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}' ), @@ -189,7 +192,7 @@ export class ProductSearchClient { // Some of the methods on this service return "paged" results, // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. - this._descriptors.page = { + this.descriptors.page = { listProductSets: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', @@ -217,6 +220,7 @@ export class ProductSearchClient { // rather than holding a request open. const protoFilesRoot = opts.fallback ? this._gaxModule.protobuf.Root.fromJSON( + // eslint-disable-next-line @typescript-eslint/no-var-requires require('../../protos/protos.json') ) : this._gaxModule.protobuf.loadSync(nodejsProtoPath); @@ -240,7 +244,7 @@ export class ProductSearchClient { '.google.cloud.vision.v1p4beta1.BatchOperationMetadata' ) as gax.protobuf.Type; - this._descriptors.longrunning = { + this.descriptors.longrunning = { importProductSets: new this._gaxModule.LongrunningDescriptor( this.operationsClient, importProductSetsResponse.decode.bind(importProductSetsResponse), @@ -264,7 +268,7 @@ export class ProductSearchClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -291,7 +295,7 @@ export class ProductSearchClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.vision.v1p4beta1.ProductSearch' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.vision.v1p4beta1.ProductSearch, this._opts ) as Promise<{[method: string]: Function}>; @@ -319,9 +323,8 @@ export class ProductSearchClient { 'importProductSets', 'purgeProducts', ]; - for (const methodName of productSearchStubMethods) { - const innerCallPromise = this.productSearchStub.then( + const callPromise = this.productSearchStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -335,20 +338,14 @@ export class ProductSearchClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.productSearchStub; @@ -408,26 +405,34 @@ export class ProductSearchClient { // -- Service calls -- // ------------------- createProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProductSet, + protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest | undefined, {} | undefined ] >; createProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createProductSet( + request: protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -458,28 +463,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProductSet, + protos.google.cloud.vision.v1p4beta1.ICreateProductSetRequest | undefined, {} | undefined ] > | void { @@ -500,29 +504,37 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createProductSet(request, options, callback); + return this.innerApiCalls.createProductSet(request, options, callback); } getProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProductSet, + protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest | undefined, {} | undefined ] >; getProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + getProductSet( + request: protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -546,28 +558,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProductSet, + protos.google.cloud.vision.v1p4beta1.IGetProductSetRequest | undefined, {} | undefined ] > | void { @@ -588,29 +599,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getProductSet(request, options, callback); + return this.innerApiCalls.getProductSet(request, options, callback); } updateProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProductSet, + protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest | undefined, {} | undefined ] >; updateProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + updateProductSet( + request: protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -639,28 +658,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ updateProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest + protos.google.cloud.vision.v1p4beta1.IProductSet, + | protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProductSet, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProductSet, + protos.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest | undefined, {} | undefined ] > | void { @@ -681,29 +699,37 @@ export class ProductSearchClient { 'product_set.name': request.productSet!.name || '', }); this.initialize(); - return this._innerApiCalls.updateProductSet(request, options, callback); + return this.innerApiCalls.updateProductSet(request, options, callback); } deleteProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest | undefined, {} | undefined ] >; deleteProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteProductSet( + request: protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -726,28 +752,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest | undefined, {} | undefined ] > | void { @@ -768,29 +793,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteProductSet(request, options, callback); + return this.innerApiCalls.deleteProductSet(request, options, callback); } createProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - ( - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProduct, + protos.google.cloud.vision.v1p4beta1.ICreateProductRequest | undefined, {} | undefined ] >; createProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.ICreateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createProduct( + request: protos.google.cloud.vision.v1p4beta1.ICreateProductRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.ICreateProductRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -824,28 +857,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.ICreateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.ICreateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - ( - | protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProduct, + protos.google.cloud.vision.v1p4beta1.ICreateProductRequest | undefined, {} | undefined ] > | void { @@ -866,25 +898,37 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createProduct(request, options, callback); + return this.innerApiCalls.createProduct(request, options, callback); } getProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct, + protos.google.cloud.vision.v1p4beta1.IGetProductRequest | undefined, {} | undefined ] >; getProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.IGetProductRequest + | null + | undefined, + {} | null | undefined + > + ): void; + getProduct( + request: protos.google.cloud.vision.v1p4beta1.IGetProductRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.IGetProductRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -908,24 +952,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - | protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.IGetProductRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest | undefined, - {} | undefined + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.IGetProductRequest + | null + | undefined, + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct, + protos.google.cloud.vision.v1p4beta1.IGetProductRequest | undefined, {} | undefined ] > | void { @@ -946,29 +993,37 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getProduct(request, options, callback); + return this.innerApiCalls.getProduct(request, options, callback); } updateProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProduct, + protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest | undefined, {} | undefined ] >; updateProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + updateProduct( + request: protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1006,28 +1061,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ updateProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest + protos.google.cloud.vision.v1p4beta1.IProduct, + | protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest - | undefined - ), + protos.google.cloud.vision.v1p4beta1.IProduct, + protos.google.cloud.vision.v1p4beta1.IUpdateProductRequest | undefined, {} | undefined ] > | void { @@ -1048,29 +1102,37 @@ export class ProductSearchClient { 'product.name': request.product!.name || '', }); this.initialize(); - return this._innerApiCalls.updateProduct(request, options, callback); + return this.innerApiCalls.updateProduct(request, options, callback); } deleteProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest | undefined, {} | undefined ] >; deleteProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteProduct( + request: protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1094,28 +1156,27 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteProduct( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IDeleteProductRequest | undefined, {} | undefined ] > | void { @@ -1136,29 +1197,40 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteProduct(request, options, callback); + return this.innerApiCalls.deleteProduct(request, options, callback); } createReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, + protos.google.cloud.vision.v1p4beta1.IReferenceImage, ( - | protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + | protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest | undefined ), {} | undefined ] >; createReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1p4beta1.IReferenceImage, + | protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createReferenceImage( + request: protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IReferenceImage, + | protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1205,26 +1277,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1p4beta1.IReferenceImage, + | protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + protos.google.cloud.vision.v1p4beta1.IReferenceImage, + | protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, + protos.google.cloud.vision.v1p4beta1.IReferenceImage, ( - | protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest + | protos.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest | undefined ), {} | undefined @@ -1247,29 +1321,40 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createReferenceImage(request, options, callback); + return this.innerApiCalls.createReferenceImage(request, options, callback); } deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + | protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest | undefined ), {} | undefined ] >; deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteReferenceImage( + request: protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1296,26 +1381,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest + | protos.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest | undefined ), {} | undefined @@ -1338,29 +1425,40 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteReferenceImage(request, options, callback); + return this.innerApiCalls.deleteReferenceImage(request, options, callback); } getReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, + protos.google.cloud.vision.v1p4beta1.IReferenceImage, ( - | protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + | protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest | undefined ), {} | undefined ] >; getReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + protos.google.cloud.vision.v1p4beta1.IReferenceImage, + | protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + getReferenceImage( + request: protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest, + callback: Callback< + protos.google.cloud.vision.v1p4beta1.IReferenceImage, + | protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1385,26 +1483,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getReferenceImage( - request: protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest, + request: protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + protos.google.cloud.vision.v1p4beta1.IReferenceImage, + | protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, - | protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + protos.google.cloud.vision.v1p4beta1.IReferenceImage, + | protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage, + protos.google.cloud.vision.v1p4beta1.IReferenceImage, ( - | protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest + | protos.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest | undefined ), {} | undefined @@ -1427,29 +1527,40 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getReferenceImage(request, options, callback); + return this.innerApiCalls.getReferenceImage(request, options, callback); } addProductToProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + | protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest | undefined ), {} | undefined ] >; addProductToProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + addProductToProductSet( + request: protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1481,26 +1592,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ addProductToProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest + | protos.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest | undefined ), {} | undefined @@ -1523,33 +1636,44 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.addProductToProductSet( + return this.innerApiCalls.addProductToProductSet( request, options, callback ); } removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + | protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest | undefined ), {} | undefined ] >; removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + removeProductFromProductSet( + request: protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -1575,26 +1699,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ removeProductFromProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest + | protos.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest | undefined ), {} | undefined @@ -1617,7 +1743,7 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.removeProductFromProductSet( + return this.innerApiCalls.removeProductFromProductSet( request, options, callback @@ -1625,28 +1751,39 @@ export class ProductSearchClient { } importProductSets( - request: protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1p4beta1.IImportProductSetsRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; importProductSets( - request: protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1p4beta1.IImportProductSetsRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + importProductSets( + request: protos.google.cloud.vision.v1p4beta1.IImportProductSetsRequest, + callback: Callback< + LROperation< + protos.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -1677,32 +1814,32 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ importProductSets( - request: protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsRequest, + request: protos.google.cloud.vision.v1p4beta1.IImportProductSetsRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -1723,31 +1860,42 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.importProductSets(request, options, callback); + return this.innerApiCalls.importProductSets(request, options, callback); } purgeProducts( - request: protosTypes.google.cloud.vision.v1p4beta1.IPurgeProductsRequest, + request: protos.google.cloud.vision.v1p4beta1.IPurgeProductsRequest, options?: gax.CallOptions ): Promise< [ LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] >; purgeProducts( - request: protosTypes.google.cloud.vision.v1p4beta1.IPurgeProductsRequest, + request: protos.google.cloud.vision.v1p4beta1.IPurgeProductsRequest, options: gax.CallOptions, callback: Callback< LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + purgeProducts( + request: protos.google.cloud.vision.v1p4beta1.IPurgeProductsRequest, + callback: Callback< + LROperation< + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): void; /** @@ -1797,32 +1945,32 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ purgeProducts( - request: protosTypes.google.cloud.vision.v1p4beta1.IPurgeProductsRequest, + request: protos.google.cloud.vision.v1p4beta1.IPurgeProductsRequest, optionsOrCallback?: | gax.CallOptions | Callback< LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined >, callback?: Callback< LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, - {} | undefined + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined > ): Promise< [ LROperation< - protosTypes.google.protobuf.IEmpty, - protosTypes.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata >, - protosTypes.google.longrunning.IOperation | undefined, + protos.google.longrunning.IOperation | undefined, {} | undefined ] > | void { @@ -1843,25 +1991,37 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.purgeProducts(request, options, callback); + return this.innerApiCalls.purgeProducts(request, options, callback); } listProductSets( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsResponse + protos.google.cloud.vision.v1p4beta1.IProductSet[], + protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest | null, + protos.google.cloud.vision.v1p4beta1.IListProductSetsResponse ] >; listProductSets( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProductSet + > + ): void; + listProductSets( + request: protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProductSet > ): void; /** @@ -1901,24 +2061,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProductSets( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsResponse + | PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProductSet >, - callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductSetsResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProductSet > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProductSet[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsResponse + protos.google.cloud.vision.v1p4beta1.IProductSet[], + protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest | null, + protos.google.cloud.vision.v1p4beta1.IListProductSetsResponse ] > | void { request = request || {}; @@ -1938,7 +2102,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listProductSets(request, options, callback); + return this.innerApiCalls.listProductSets(request, options, callback); } /** @@ -1970,7 +2134,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [ProductSet]{@link google.cloud.vision.v1p4beta1.ProductSet} on 'data' event. */ listProductSetsStream( - request?: protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + request?: protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -1984,29 +2148,84 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProductSets.createStream( - this._innerApiCalls.listProductSets as gax.GaxCall, + return this.descriptors.page.listProductSets.createStream( + this.innerApiCalls.listProductSets as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProductSets}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The project from which ProductSets should be listed. + * + * Format is `projects/PROJECT_ID/locations/LOC_ID`. + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductSetsAsync( + request?: protos.google.cloud.vision.v1p4beta1.IListProductSetsRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProductSets.asyncIterate( + this.innerApiCalls['listProductSets'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listProducts( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductsRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsResponse + protos.google.cloud.vision.v1p4beta1.IProduct[], + protos.google.cloud.vision.v1p4beta1.IListProductsRequest | null, + protos.google.cloud.vision.v1p4beta1.IListProductsResponse ] >; listProducts( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductsRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductsRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct + > + ): void; + listProducts( + request: protos.google.cloud.vision.v1p4beta1.IListProductsRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductsRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct > ): void; /** @@ -2046,24 +2265,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProducts( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductsRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsResponse + | PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductsRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct >, - callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductsRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductsResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsResponse + protos.google.cloud.vision.v1p4beta1.IProduct[], + protos.google.cloud.vision.v1p4beta1.IListProductsRequest | null, + protos.google.cloud.vision.v1p4beta1.IListProductsResponse ] > | void { request = request || {}; @@ -2083,7 +2306,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listProducts(request, options, callback); + return this.innerApiCalls.listProducts(request, options, callback); } /** @@ -2116,7 +2339,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [Product]{@link google.cloud.vision.v1p4beta1.Product} on 'data' event. */ listProductsStream( - request?: protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest, + request?: protos.google.cloud.vision.v1p4beta1.IListProductsRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2130,29 +2353,85 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProducts.createStream( - this._innerApiCalls.listProducts as gax.GaxCall, + return this.descriptors.page.listProducts.createStream( + this.innerApiCalls.listProducts as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProducts}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The project OR ProductSet from which Products should be listed. + * + * Format: + * `projects/PROJECT_ID/locations/LOC_ID` + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductsAsync( + request?: protos.google.cloud.vision.v1p4beta1.IListProductsRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProducts.asyncIterate( + this.innerApiCalls['listProducts'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listReferenceImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + protos.google.cloud.vision.v1p4beta1.IReferenceImage[], + protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest | null, + protos.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse ] >; listReferenceImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IReferenceImage + > + ): void; + listReferenceImages( + request: protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IReferenceImage > ): void; /** @@ -2197,24 +2476,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listReferenceImages( - request: protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + request: protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + | PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IReferenceImage >, - callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + | protos.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IReferenceImage > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IReferenceImage[], - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse + protos.google.cloud.vision.v1p4beta1.IReferenceImage[], + protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest | null, + protos.google.cloud.vision.v1p4beta1.IListReferenceImagesResponse ] > | void { request = request || {}; @@ -2234,7 +2517,7 @@ export class ProductSearchClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listReferenceImages(request, options, callback); + return this.innerApiCalls.listReferenceImages(request, options, callback); } /** @@ -2270,7 +2553,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [ReferenceImage]{@link google.cloud.vision.v1p4beta1.ReferenceImage} on 'data' event. */ listReferenceImagesStream( - request?: protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + request?: protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2284,29 +2567,88 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listReferenceImages.createStream( - this._innerApiCalls.listReferenceImages as gax.GaxCall, + return this.descriptors.page.listReferenceImages.createStream( + this.innerApiCalls.listReferenceImages as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listReferenceImages}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. Resource name of the product containing the reference images. + * + * Format is + * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * A token identifying a page of results to be returned. This is the value + * of `nextPageToken` returned in a previous reference image list request. + * + * Defaults to the first page if not specified. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listReferenceImagesAsync( + request?: protos.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listReferenceImages.asyncIterate( + this.innerApiCalls['listReferenceImages'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + protos.google.cloud.vision.v1p4beta1.IProduct[], + protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest | null, + protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse ] >; listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + callback: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct + > + ): void; + listProductsInProductSet( + request: protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + callback: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct > ): void; /** @@ -2348,24 +2690,28 @@ export class ProductSearchClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listProductsInProductSet( - request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + request: protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + | PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct >, - callback?: Callback< - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + callback?: PaginationCallback< + protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + | protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + | null + | undefined, + protos.google.cloud.vision.v1p4beta1.IProduct > ): Promise< [ - protosTypes.google.cloud.vision.v1p4beta1.IProduct[], - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest | null, - protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse + protos.google.cloud.vision.v1p4beta1.IProduct[], + protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest | null, + protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetResponse ] > | void { request = request || {}; @@ -2385,7 +2731,7 @@ export class ProductSearchClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.listProductsInProductSet( + return this.innerApiCalls.listProductsInProductSet( request, options, callback @@ -2422,7 +2768,7 @@ export class ProductSearchClient { * An object stream which emits an object representing [Product]{@link google.cloud.vision.v1p4beta1.Product} on 'data' event. */ listProductsInProductSetStream( - request?: protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + request?: protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -2436,12 +2782,56 @@ export class ProductSearchClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listProductsInProductSet.createStream( - this._innerApiCalls.listProductsInProductSet as gax.GaxCall, + return this.descriptors.page.listProductsInProductSet.createStream( + this.innerApiCalls.listProductsInProductSet as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listProductsInProductSet}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The ProductSet resource for which to retrieve Products. + * + * Format is: + * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` + * @param {number} request.pageSize + * The maximum number of items to return. Default 10, maximum 100. + * @param {string} request.pageToken + * The next_page_token returned from a previous List request, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listProductsInProductSetAsync( + request?: protos.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + name: request.name || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listProductsInProductSet.asyncIterate( + this.innerApiCalls['listProductsInProductSet'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } // -------------------- // -- Path templates -- // -------------------- @@ -2454,9 +2844,9 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ locationPath(project: string, location: string) { - return this._pathTemplates.locationPathTemplate.render({ - project, - location, + return this.pathTemplates.locationPathTemplate.render({ + project: project, + location: location, }); } @@ -2468,7 +2858,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName).project; + return this.pathTemplates.locationPathTemplate.match(locationName).project; } /** @@ -2479,8 +2869,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName) - .location; + return this.pathTemplates.locationPathTemplate.match(locationName).location; } /** @@ -2492,10 +2881,10 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ productPath(project: string, location: string, product: string) { - return this._pathTemplates.productPathTemplate.render({ - project, - location, - product, + return this.pathTemplates.productPathTemplate.render({ + project: project, + location: location, + product: product, }); } @@ -2507,7 +2896,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).project; + return this.pathTemplates.productPathTemplate.match(productName).project; } /** @@ -2518,7 +2907,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).location; + return this.pathTemplates.productPathTemplate.match(productName).location; } /** @@ -2529,7 +2918,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product. */ matchProductFromProductName(productName: string) { - return this._pathTemplates.productPathTemplate.match(productName).product; + return this.pathTemplates.productPathTemplate.match(productName).product; } /** @@ -2541,9 +2930,9 @@ export class ProductSearchClient { * @returns {string} Resource name string. */ productSetPath(project: string, location: string, productSet: string) { - return this._pathTemplates.productSetPathTemplate.render({ - project, - location, + return this.pathTemplates.productSetPathTemplate.render({ + project: project, + location: location, product_set: productSet, }); } @@ -2556,7 +2945,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .project; } @@ -2568,7 +2957,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .location; } @@ -2580,7 +2969,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product_set. */ matchProductSetFromProductSetName(productSetName: string) { - return this._pathTemplates.productSetPathTemplate.match(productSetName) + return this.pathTemplates.productSetPathTemplate.match(productSetName) .product_set; } @@ -2599,10 +2988,10 @@ export class ProductSearchClient { product: string, referenceImage: string ) { - return this._pathTemplates.referenceImagePathTemplate.render({ - project, - location, - product, + return this.pathTemplates.referenceImagePathTemplate.render({ + project: project, + location: location, + product: product, reference_image: referenceImage, }); } @@ -2615,7 +3004,7 @@ export class ProductSearchClient { * @returns {string} A string representing the project. */ matchProjectFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).project; } @@ -2628,7 +3017,7 @@ export class ProductSearchClient { * @returns {string} A string representing the location. */ matchLocationFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).location; } @@ -2641,7 +3030,7 @@ export class ProductSearchClient { * @returns {string} A string representing the product. */ matchProductFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).product; } @@ -2654,7 +3043,7 @@ export class ProductSearchClient { * @returns {string} A string representing the reference_image. */ matchReferenceImageFromReferenceImageName(referenceImageName: string) { - return this._pathTemplates.referenceImagePathTemplate.match( + return this.pathTemplates.referenceImagePathTemplate.match( referenceImageName ).reference_image; } diff --git a/packages/google-cloud-vision/synth.metadata b/packages/google-cloud-vision/synth.metadata index d21fb950c85..62d3d8ee85f 100644 --- a/packages/google-cloud-vision/synth.metadata +++ b/packages/google-cloud-vision/synth.metadata @@ -1,23 +1,5 @@ { - "updateTime": "2020-03-22T12:00:35.095134Z", - "sources": [ - { - "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "0be7105dc52590fa9a24e784052298ae37ce53aa", - "internalRef": "302154871", - "log": "0be7105dc52590fa9a24e784052298ae37ce53aa\nAdd BUILD.bazel file to asset/v1p1beta1\n\nPiperOrigin-RevId: 302154871\n\n6c248fd13e8543f8d22cbf118d978301a9fbe2a8\nAdd missing resource annotations and additional_bindings to dialogflow v2 API.\n\nPiperOrigin-RevId: 302063117\n\n9a3a7f33be9eeacf7b3e98435816b7022d206bd7\nChange the service name from \"chromeos-moblab.googleapis.com\" to \"chromeosmoblab.googleapis.com\"\n\nPiperOrigin-RevId: 302060989\n\n98a339237577e3de26cb4921f75fb5c57cc7a19f\nfeat: devtools/build/v1 publish client library config annotations\n\n* add details field to some of the BuildEvents\n* add final_invocation_id and build_tool_exit_code fields to BuildStatus\n\nPiperOrigin-RevId: 302044087\n\ncfabc98c6bbbb22d1aeaf7612179c0be193b3a13\nfeat: home/graph/v1 publish client library config annotations & comment updates\n\nThis change includes adding the client library configuration annotations, updated proto comments, and some client library configuration files.\n\nPiperOrigin-RevId: 302042647\n\nc8c8c0bd15d082db9546253dbaad1087c7a9782c\nchore: use latest gapic-generator in bazel WORKSPACE.\nincluding the following commits from gapic-generator:\n- feat: take source protos in all sub-packages (#3144)\n\nPiperOrigin-RevId: 301843591\n\ne4daf5202ea31cb2cb6916fdbfa9d6bd771aeb4c\nAdd bazel file for v1 client lib generation\n\nPiperOrigin-RevId: 301802926\n\n275fbcce2c900278d487c33293a3c7e1fbcd3a34\nfeat: pubsub/v1 add an experimental filter field to Subscription\n\nPiperOrigin-RevId: 301661567\n\nf2b18cec51d27c999ad30011dba17f3965677e9c\nFix: UpdateBackupRequest.backup is a resource, not a resource reference - remove annotation.\n\nPiperOrigin-RevId: 301636171\n\n800384063ac93a0cac3a510d41726fa4b2cd4a83\nCloud Billing Budget API v1beta1\nModified api documentation to include warnings about the new filter field.\n\nPiperOrigin-RevId: 301634389\n\n0cc6c146b660db21f04056c3d58a4b752ee445e3\nCloud Billing Budget API v1alpha1\nModified api documentation to include warnings about the new filter field.\n\nPiperOrigin-RevId: 301630018\n\nff2ea00f69065585c3ac0993c8b582af3b6fc215\nFix: Add resource definition for a parent of InspectTemplate which was otherwise missing.\n\nPiperOrigin-RevId: 301623052\n\n55fa441c9daf03173910760191646399338f2b7c\nAdd proto definition for AccessLevel, AccessPolicy, and ServicePerimeter.\n\nPiperOrigin-RevId: 301620844\n\ne7b10591c5408a67cf14ffafa267556f3290e262\nCloud Bigtable Managed Backup service and message proto files.\n\nPiperOrigin-RevId: 301585144\n\nd8e226f702f8ddf92915128c9f4693b63fb8685d\nfeat: Add time-to-live in a queue for builds\n\nPiperOrigin-RevId: 301579876\n\n430375af011f8c7a5174884f0d0e539c6ffa7675\ndocs: add missing closing backtick\n\nPiperOrigin-RevId: 301538851\n\n0e9f1f60ded9ad1c2e725e37719112f5b487ab65\nbazel: Use latest release of gax_java\n\nPiperOrigin-RevId: 301480457\n\n5058c1c96d0ece7f5301a154cf5a07b2ad03a571\nUpdate GAPIC v2 with batching parameters for Logging API\n\nPiperOrigin-RevId: 301443847\n\n64ab9744073de81fec1b3a6a931befc8a90edf90\nFix: Introduce location-based organization/folder/billing-account resources\nChore: Update copyright years\n\nPiperOrigin-RevId: 301373760\n\n23d5f09e670ebb0c1b36214acf78704e2ecfc2ac\nUpdate field_behavior annotations in V1 and V2.\n\nPiperOrigin-RevId: 301337970\n\nb2cf37e7fd62383a811aa4d54d013ecae638851d\nData Catalog V1 API\n\nPiperOrigin-RevId: 301282503\n\n1976b9981e2900c8172b7d34b4220bdb18c5db42\nCloud DLP api update. Adds missing fields to Finding and adds support for hybrid jobs.\n\nPiperOrigin-RevId: 301205325\n\nae78682c05e864d71223ce22532219813b0245ac\nfix: several sample code blocks in comments are now properly indented for markdown\n\nPiperOrigin-RevId: 301185150\n\ndcd171d04bda5b67db13049320f97eca3ace3731\nPublish Media Translation API V1Beta1\n\nPiperOrigin-RevId: 301180096\n\nff1713453b0fbc5a7544a1ef6828c26ad21a370e\nAdd protos and BUILD rules for v1 API.\n\nPiperOrigin-RevId: 301179394\n\n8386761d09819b665b6a6e1e6d6ff884bc8ff781\nfeat: chromeos/modlab publish protos and config for Chrome OS Moblab API.\n\nPiperOrigin-RevId: 300843960\n\nb2e2bc62fab90e6829e62d3d189906d9b79899e4\nUpdates to GCS gRPC API spec:\n\n1. Changed GetIamPolicy and TestBucketIamPermissions to use wrapper messages around google.iam.v1 IAM requests messages, and added CommonRequestParams. This lets us support RequesterPays buckets.\n2. Added a metadata field to GetObjectMediaResponse, to support resuming an object media read safely (by extracting the generation of the object being read, and using it in the resumed read request).\n\nPiperOrigin-RevId: 300817706\n\n7fd916ce12335cc9e784bb9452a8602d00b2516c\nAdd deprecated_collections field for backward-compatiblity in PHP and monolith-generated Python and Ruby clients.\n\nGenerate TopicName class in Java which covers the functionality of both ProjectTopicName and DeletedTopicName. Introduce breaking changes to be fixed by synth.py.\n\nDelete default retry parameters.\n\nRetry codes defs can be deleted once # https://github.com/googleapis/gapic-generator/issues/3137 is fixed.\n\nPiperOrigin-RevId: 300813135\n\n047d3a8ac7f75383855df0166144f891d7af08d9\nfix!: google/rpc refactor ErrorInfo.type to ErrorInfo.reason and comment updates.\n\nPiperOrigin-RevId: 300773211\n\nfae4bb6d5aac52aabe5f0bb4396466c2304ea6f6\nAdding RetryPolicy to pubsub.proto\n\nPiperOrigin-RevId: 300769420\n\n7d569be2928dbd72b4e261bf9e468f23afd2b950\nAdding additional protocol buffer annotations to v3.\n\nPiperOrigin-RevId: 300718800\n\n13942d1a85a337515040a03c5108993087dc0e4f\nAdd logging protos for Recommender v1.\n\nPiperOrigin-RevId: 300689896\n\na1a573c3eecfe2c404892bfa61a32dd0c9fb22b6\nfix: change go package to use cloud.google.com/go/maps\n\nPiperOrigin-RevId: 300661825\n\nc6fbac11afa0c7ab2972d9df181493875c566f77\nfeat: publish documentai/v1beta2 protos\n\nPiperOrigin-RevId: 300656808\n\n5202a9e0d9903f49e900f20fe5c7f4e42dd6588f\nProtos for v1beta1 release of Cloud Security Center Settings API\n\nPiperOrigin-RevId: 300580858\n\n83518e18655d9d4ac044acbda063cc6ecdb63ef8\nAdds gapic.yaml file and BUILD.bazel file.\n\nPiperOrigin-RevId: 300554200\n\n836c196dc8ef8354bbfb5f30696bd3477e8db5e2\nRegenerate recommender v1beta1 gRPC ServiceConfig file for Insights methods.\n\nPiperOrigin-RevId: 300549302\n\n34a5450c591b6be3d6566f25ac31caa5211b2f3f\nIncreases the default timeout from 20s to 30s for MetricService\n\nPiperOrigin-RevId: 300474272\n\n5d8bffe87cd01ba390c32f1714230e5a95d5991d\nfeat: use the latest gapic-generator in WORKSPACE for bazel build.\n\nPiperOrigin-RevId: 300461878\n\nd631c651e3bcfac5d371e8560c27648f7b3e2364\nUpdated the GAPIC configs to include parameters for Backups APIs.\n\nPiperOrigin-RevId: 300443402\n\n678afc7055c1adea9b7b54519f3bdb228013f918\nAdding Game Servers v1beta API.\n\nPiperOrigin-RevId: 300433218\n\n80d2bd2c652a5e213302041b0620aff423132589\nEnable proto annotation and gapic v2 for talent API.\n\nPiperOrigin-RevId: 300393997\n\n85e454be7a353f7fe1bf2b0affb753305785b872\ndocs(google/maps/roads): remove mention of nonexported api\n\nPiperOrigin-RevId: 300367734\n\nbf839ae632e0f263a729569e44be4b38b1c85f9c\nAdding protocol buffer annotations and updated config info for v1 and v2.\n\nPiperOrigin-RevId: 300276913\n\n309b899ca18a4c604bce63882a161d44854da549\nPublish `Backup` APIs and protos.\n\nPiperOrigin-RevId: 300246038\n\neced64c3f122421350b4aca68a28e89121d20db8\nadd PHP client libraries\n\nPiperOrigin-RevId: 300193634\n\n7727af0e39df1ae9ad715895c8576d7b65cf6c6d\nfeat: use the latest gapic-generator and protoc-java-resource-name-plugin in googleapis/WORKSPACE.\n\nPiperOrigin-RevId: 300188410\n\n2a25aa351dd5b5fe14895266aff5824d90ce757b\nBreaking change: remove the ProjectOrTenant resource and its references.\n\nPiperOrigin-RevId: 300182152\n\na499dbb28546379415f51803505cfb6123477e71\nUpdate web risk v1 gapic config and BUILD file.\n\nPiperOrigin-RevId: 300152177\n\n52701da10fec2a5f9796e8d12518c0fe574488fe\nFix: apply appropriate namespace/package options for C#, PHP and Ruby.\n\nPiperOrigin-RevId: 300123508\n\n365c029b8cdb63f7751b92ab490f1976e616105c\nAdd CC targets to the kms protos.\n\nThese are needed by go/tink.\n\nPiperOrigin-RevId: 300038469\n\n4ba9aa8a4a1413b88dca5a8fa931824ee9c284e6\nExpose logo recognition API proto for GA.\n\nPiperOrigin-RevId: 299971671\n\n1c9fc2c9e03dadf15f16b1c4f570955bdcebe00e\nAdding ruby_package option to accessapproval.proto for the Ruby client libraries generation.\n\nPiperOrigin-RevId: 299955924\n\n1cc6f0a7bfb147e6f2ede911d9b01e7a9923b719\nbuild(google/maps/routes): generate api clients\n\nPiperOrigin-RevId: 299955905\n\n29a47c965aac79e3fe8e3314482ca0b5967680f0\nIncrease timeout to 1hr for method `dropRange` in bigtable/admin/v2, which is\nsynced with the timeout setting in gapic_yaml.\n\nPiperOrigin-RevId: 299917154\n\n8f631c4c70a60a9c7da3749511ee4ad432b62898\nbuild(google/maps/roads/v1op): move go to monorepo pattern\n\nPiperOrigin-RevId: 299885195\n\nd66816518844ebbf63504c9e8dfc7133921dd2cd\nbuild(google/maps/roads/v1op): Add bazel build files to generate clients.\n\nPiperOrigin-RevId: 299851148\n\naf7dff701fabe029672168649c62356cf1bb43d0\nAdd LogPlayerReports and LogImpressions to Playable Locations service\n\nPiperOrigin-RevId: 299724050\n\nb6927fca808f38df32a642c560082f5bf6538ced\nUpdate BigQuery Connection API v1beta1 proto: added credential to CloudSqlProperties.\n\nPiperOrigin-RevId: 299503150\n\n91e1fb5ef9829c0c7a64bfa5bde330e6ed594378\nchore: update protobuf (protoc) version to 3.11.2\n\nPiperOrigin-RevId: 299404145\n\n30e36b4bee6749c4799f4fc1a51cc8f058ba167d\nUpdate cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 299399890\n\nffbb493674099f265693872ae250711b2238090c\nfeat: cloudbuild/v1 add new fields and annotate OUTPUT_OUT fields.\n\nPiperOrigin-RevId: 299397780\n\nbc973a15818e00c19e121959832676e9b7607456\nbazel: Fix broken common dependency\n\nPiperOrigin-RevId: 299397431\n\n71094a343e3b962e744aa49eb9338219537474e4\nchore: bigtable/admin/v2 publish retry config\n\nPiperOrigin-RevId: 299391875\n\n8f488efd7bda33885cb674ddd023b3678c40bd82\nfeat: Migrate logging to GAPIC v2; release new features.\n\nIMPORTANT: This is a breaking change for client libraries\nin all languages.\n\nCommitter: @lukesneeringer, @jskeet\nPiperOrigin-RevId: 299370279\n\n007605bf9ad3a1fd775014ebefbf7f1e6b31ee71\nUpdate API for bigqueryreservation v1beta1.\n- Adds flex capacity commitment plan to CapacityCommitment.\n- Adds methods for getting and updating BiReservations.\n- Adds methods for updating/splitting/merging CapacityCommitments.\n\nPiperOrigin-RevId: 299368059\n\n" - } - }, - { - "git": { - "name": "synthtool", - "remote": "https://github.com/googleapis/synthtool.git", - "sha": "7e98e1609c91082f4eeb63b530c6468aefd18cfd" - } - } - ], + "updateTime": "2020-03-31T20:16:47.942825Z", "destinations": [ { "client": { diff --git a/packages/google-cloud-vision/system-test/fixtures/sample/src/index.js b/packages/google-cloud-vision/system-test/fixtures/sample/src/index.js index b0c1b966eab..2e1ab78148a 100644 --- a/packages/google-cloud-vision/system-test/fixtures/sample/src/index.js +++ b/packages/google-cloud-vision/system-test/fixtures/sample/src/index.js @@ -16,7 +16,6 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** - /* eslint-disable node/no-missing-require, no-unused-vars */ const vision = require('@google-cloud/vision'); diff --git a/packages/google-cloud-vision/system-test/fixtures/sample/src/index.ts b/packages/google-cloud-vision/system-test/fixtures/sample/src/index.ts index 2bd299ee3b2..b980f0dc451 100644 --- a/packages/google-cloud-vision/system-test/fixtures/sample/src/index.ts +++ b/packages/google-cloud-vision/system-test/fixtures/sample/src/index.ts @@ -19,8 +19,8 @@ import {ImageAnnotatorClient, ProductSearchClient} from '@google-cloud/vision'; function main() { - const imageAnnotatorClient = new ImageAnnotatorClient(); - const productSearchClient = new ProductSearchClient(); + new ImageAnnotatorClient(); + new ProductSearchClient(); } main(); diff --git a/packages/google-cloud-vision/system-test/image_annotator_smoke_test.ts b/packages/google-cloud-vision/system-test/image_annotator_smoke_test.ts index e0f5c1f2c13..a5aae16104d 100644 --- a/packages/google-cloud-vision/system-test/image_annotator_smoke_test.ts +++ b/packages/google-cloud-vision/system-test/image_annotator_smoke_test.ts @@ -16,6 +16,7 @@ import {describe, it} from 'mocha'; describe('ImageAnnotatorSmokeTest', () => { it('successfully makes a call to the service', done => { + // eslint-disable-next-line @typescript-eslint/no-var-requires const vision = require('../src'); const client = new vision.v1p3beta1.ImageAnnotatorClient({ diff --git a/packages/google-cloud-vision/system-test/vision-v1p2beta1.ts b/packages/google-cloud-vision/system-test/vision-v1p2beta1.ts index 5b98620e090..dd45d21e102 100644 --- a/packages/google-cloud-vision/system-test/vision-v1p2beta1.ts +++ b/packages/google-cloud-vision/system-test/vision-v1p2beta1.ts @@ -16,6 +16,7 @@ import {describe, it} from 'mocha'; describe('ImageAnnotatorSmokeTest', () => { it('successfully makes a call to the service', done => { + // eslint-disable-next-line @typescript-eslint/no-var-requires const vision = require('../src'); const client = new vision.v1p2beta1.ImageAnnotatorClient({ diff --git a/packages/google-cloud-vision/test/gapic-image_annotator-v1.ts b/packages/google-cloud-vision/test/gapic-image_annotator-v1.ts deleted file mode 100644 index 20b0c4c7c6c..00000000000 --- a/packages/google-cloud-vision/test/gapic-image_annotator-v1.ts +++ /dev/null @@ -1,361 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const imageannotatorModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -function mockLongRunningGrpcMethod( - expectedRequest: {}, - response: {} | null, - error?: {} | null -) { - return (request: {}) => { - assert.deepStrictEqual(request, expectedRequest); - const mockOperation = { - promise() { - return new Promise((resolve, reject) => { - if (error) { - reject(error); - } else { - resolve([response]); - } - }); - }, - }; - return Promise.resolve([mockOperation]); - }; -} -describe('v1.ImageAnnotatorClient', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1.ImageAnnotatorClient.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = imageannotatorModule.v1.ImageAnnotatorClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - fallback: true, - }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.imageAnnotatorStub, undefined); - await client.initialize(); - assert(client.imageAnnotatorStub); - }); - it('has close method', () => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - describe('batchAnnotateImages', () => { - it('invokes batchAnnotateImages without error', done => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.batchAnnotateImages(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes batchAnnotateImages with error', done => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IBatchAnnotateImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - null, - error - ); - client.batchAnnotateImages(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('batchAnnotateFiles', () => { - it('invokes batchAnnotateFiles without error', done => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateFiles = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.batchAnnotateFiles(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes batchAnnotateFiles with error', done => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IBatchAnnotateFilesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateFiles = mockSimpleGrpcMethod( - request, - null, - error - ); - client.batchAnnotateFiles(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('asyncBatchAnnotateImages', () => { - it('invokes asyncBatchAnnotateImages without error', done => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateImages = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .asyncBatchAnnotateImages(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes asyncBatchAnnotateImages with error', done => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateImages = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .asyncBatchAnnotateImages(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); - describe('asyncBatchAnnotateFiles', () => { - it('invokes asyncBatchAnnotateFiles without error', done => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateFiles = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .asyncBatchAnnotateFiles(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes asyncBatchAnnotateFiles with error', done => { - const client = new imageannotatorModule.v1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateFiles = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .asyncBatchAnnotateFiles(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); -}); diff --git a/packages/google-cloud-vision/test/gapic-image_annotator-v1p1beta1.ts b/packages/google-cloud-vision/test/gapic-image_annotator-v1p1beta1.ts deleted file mode 100644 index 581da6fda90..00000000000 --- a/packages/google-cloud-vision/test/gapic-image_annotator-v1p1beta1.ts +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const imageannotatorModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -describe('v1p1beta1.ImageAnnotatorClient', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1p1beta1.ImageAnnotatorClient.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1p1beta1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = imageannotatorModule.v1p1beta1.ImageAnnotatorClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ - fallback: true, - }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.imageAnnotatorStub, undefined); - await client.initialize(); - assert(client.imageAnnotatorStub); - }); - it('has close method', () => { - const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - describe('batchAnnotateImages', () => { - it('invokes batchAnnotateImages without error', done => { - const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.batchAnnotateImages(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes batchAnnotateImages with error', done => { - const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - null, - error - ); - client.batchAnnotateImages(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); -}); diff --git a/packages/google-cloud-vision/test/gapic-image_annotator-v1p2beta1.ts b/packages/google-cloud-vision/test/gapic-image_annotator-v1p2beta1.ts deleted file mode 100644 index 38765a09818..00000000000 --- a/packages/google-cloud-vision/test/gapic-image_annotator-v1p2beta1.ts +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const imageannotatorModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -function mockLongRunningGrpcMethod( - expectedRequest: {}, - response: {} | null, - error?: {} | null -) { - return (request: {}) => { - assert.deepStrictEqual(request, expectedRequest); - const mockOperation = { - promise() { - return new Promise((resolve, reject) => { - if (error) { - reject(error); - } else { - resolve([response]); - } - }); - }, - }; - return Promise.resolve([mockOperation]); - }; -} -describe('v1p2beta1.ImageAnnotatorClient', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1p2beta1.ImageAnnotatorClient.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1p2beta1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = imageannotatorModule.v1p2beta1.ImageAnnotatorClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ - fallback: true, - }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.imageAnnotatorStub, undefined); - await client.initialize(); - assert(client.imageAnnotatorStub); - }); - it('has close method', () => { - const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - describe('batchAnnotateImages', () => { - it('invokes batchAnnotateImages without error', done => { - const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.batchAnnotateImages(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes batchAnnotateImages with error', done => { - const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - null, - error - ); - client.batchAnnotateImages(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('asyncBatchAnnotateFiles', () => { - it('invokes asyncBatchAnnotateFiles without error', done => { - const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateFiles = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .asyncBatchAnnotateFiles(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes asyncBatchAnnotateFiles with error', done => { - const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateFiles = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .asyncBatchAnnotateFiles(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); -}); diff --git a/packages/google-cloud-vision/test/gapic-image_annotator-v1p3beta1.ts b/packages/google-cloud-vision/test/gapic-image_annotator-v1p3beta1.ts deleted file mode 100644 index e7bd6dec31a..00000000000 --- a/packages/google-cloud-vision/test/gapic-image_annotator-v1p3beta1.ts +++ /dev/null @@ -1,238 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const imageannotatorModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -function mockLongRunningGrpcMethod( - expectedRequest: {}, - response: {} | null, - error?: {} | null -) { - return (request: {}) => { - assert.deepStrictEqual(request, expectedRequest); - const mockOperation = { - promise() { - return new Promise((resolve, reject) => { - if (error) { - reject(error); - } else { - resolve([response]); - } - }); - }, - }; - return Promise.resolve([mockOperation]); - }; -} -describe('v1p3beta1.ImageAnnotatorClient', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1p3beta1.ImageAnnotatorClient.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1p3beta1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = imageannotatorModule.v1p3beta1.ImageAnnotatorClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ - fallback: true, - }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.imageAnnotatorStub, undefined); - await client.initialize(); - assert(client.imageAnnotatorStub); - }); - it('has close method', () => { - const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - describe('batchAnnotateImages', () => { - it('invokes batchAnnotateImages without error', done => { - const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.batchAnnotateImages(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes batchAnnotateImages with error', done => { - const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - null, - error - ); - client.batchAnnotateImages(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('asyncBatchAnnotateFiles', () => { - it('invokes asyncBatchAnnotateFiles without error', done => { - const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateFiles = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .asyncBatchAnnotateFiles(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes asyncBatchAnnotateFiles with error', done => { - const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateFiles = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .asyncBatchAnnotateFiles(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); -}); diff --git a/packages/google-cloud-vision/test/gapic-image_annotator-v1p4beta1.ts b/packages/google-cloud-vision/test/gapic-image_annotator-v1p4beta1.ts deleted file mode 100644 index d759ba83979..00000000000 --- a/packages/google-cloud-vision/test/gapic-image_annotator-v1p4beta1.ts +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const imageannotatorModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -function mockLongRunningGrpcMethod( - expectedRequest: {}, - response: {} | null, - error?: {} | null -) { - return (request: {}) => { - assert.deepStrictEqual(request, expectedRequest); - const mockOperation = { - promise() { - return new Promise((resolve, reject) => { - if (error) { - reject(error); - } else { - resolve([response]); - } - }); - }, - }; - return Promise.resolve([mockOperation]); - }; -} -describe('v1p4beta1.ImageAnnotatorClient', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1p4beta1.ImageAnnotatorClient.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1p4beta1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = imageannotatorModule.v1p4beta1.ImageAnnotatorClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - fallback: true, - }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.imageAnnotatorStub, undefined); - await client.initialize(); - assert(client.imageAnnotatorStub); - }); - it('has close method', () => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - describe('batchAnnotateImages', () => { - it('invokes batchAnnotateImages without error', done => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.batchAnnotateImages(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes batchAnnotateImages with error', done => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateImages = mockSimpleGrpcMethod( - request, - null, - error - ); - client.batchAnnotateImages(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('batchAnnotateFiles', () => { - it('invokes batchAnnotateFiles without error', done => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateFiles = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.batchAnnotateFiles(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes batchAnnotateFiles with error', done => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.batchAnnotateFiles = mockSimpleGrpcMethod( - request, - null, - error - ); - client.batchAnnotateFiles(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('asyncBatchAnnotateImages', () => { - it('invokes asyncBatchAnnotateImages without error', done => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateImages = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .asyncBatchAnnotateImages(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes asyncBatchAnnotateImages with error', done => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateImages = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .asyncBatchAnnotateImages(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); - describe('asyncBatchAnnotateFiles', () => { - it('invokes asyncBatchAnnotateFiles without error', done => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateFiles = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .asyncBatchAnnotateFiles(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes asyncBatchAnnotateFiles with error', done => { - const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest = {}; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.asyncBatchAnnotateFiles = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .asyncBatchAnnotateFiles(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); -}); diff --git a/packages/google-cloud-vision/test/gapic-product_search-v1.ts b/packages/google-cloud-vision/test/gapic-product_search-v1.ts deleted file mode 100644 index 2df4049344a..00000000000 --- a/packages/google-cloud-vision/test/gapic-product_search-v1.ts +++ /dev/null @@ -1,1193 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const productsearchModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -function mockLongRunningGrpcMethod( - expectedRequest: {}, - response: {} | null, - error?: {} | null -) { - return (request: {}) => { - assert.deepStrictEqual(request, expectedRequest); - const mockOperation = { - promise() { - return new Promise((resolve, reject) => { - if (error) { - reject(error); - } else { - resolve([response]); - } - }); - }, - }; - return Promise.resolve([mockOperation]); - }; -} -describe('v1.ProductSearchClient', () => { - it('has servicePath', () => { - const servicePath = productsearchModule.v1.ProductSearchClient.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = productsearchModule.v1.ProductSearchClient.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = productsearchModule.v1.ProductSearchClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new productsearchModule.v1.ProductSearchClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new productsearchModule.v1.ProductSearchClient({ - fallback: true, - }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.productSearchStub, undefined); - await client.initialize(); - assert(client.productSearchStub); - }); - it('has close method', () => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - describe('createProductSet', () => { - it('invokes createProductSet without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.ICreateProductSetRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createProductSet with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.ICreateProductSetRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getProductSet', () => { - it('invokes getProductSet without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IGetProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getProductSet with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IGetProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('updateProductSet', () => { - it('invokes updateProductSet without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest = {}; - request.productSet = {}; - request.productSet.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.updateProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateProductSet with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IUpdateProductSetRequest = {}; - request.productSet = {}; - request.productSet.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.updateProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteProductSet', () => { - it('invokes deleteProductSet without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteProductSet with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IDeleteProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('createProduct', () => { - it('invokes createProduct without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.ICreateProductRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createProduct with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.ICreateProductRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getProduct', () => { - it('invokes getProduct without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IGetProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getProduct with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IGetProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('updateProduct', () => { - it('invokes updateProduct without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IUpdateProductRequest = {}; - request.product = {}; - request.product.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.updateProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateProduct with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IUpdateProductRequest = {}; - request.product = {}; - request.product.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.updateProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteProduct', () => { - it('invokes deleteProduct without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IDeleteProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteProduct with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IDeleteProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('createReferenceImage', () => { - it('invokes createReferenceImage without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createReferenceImage with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.ICreateReferenceImageRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteReferenceImage', () => { - it('invokes deleteReferenceImage without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteReferenceImage with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IDeleteReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getReferenceImage', () => { - it('invokes getReferenceImage without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getReferenceImage with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IGetReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('addProductToProductSet', () => { - it('invokes addProductToProductSet without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.addProductToProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.addProductToProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes addProductToProductSet with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IAddProductToProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.addProductToProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.addProductToProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('removeProductFromProductSet', () => { - it('invokes removeProductFromProductSet without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.removeProductFromProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.removeProductFromProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes removeProductFromProductSet with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IRemoveProductFromProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.removeProductFromProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.removeProductFromProductSet( - request, - (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - } - ); - }); - }); - describe('importProductSets', () => { - it('invokes importProductSets without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IImportProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.importProductSets = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .importProductSets(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes importProductSets with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IImportProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.importProductSets = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .importProductSets(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); - describe('purgeProducts', () => { - it('invokes purgeProducts without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IPurgeProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.purgeProducts = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .purgeProducts(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes purgeProducts with error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IPurgeProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.purgeProducts = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .purgeProducts(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); - describe('listProductSets', () => { - it('invokes listProductSets without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IListProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProductSets = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProductSets(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listProductSetsStream', () => { - it('invokes listProductSetsStream without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IListProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProductSets = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductSetsStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listProducts', () => { - it('invokes listProducts without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IListProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProducts = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProducts(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listProductsStream', () => { - it('invokes listProductsStream without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IListProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProducts = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductsStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listReferenceImages', () => { - it('invokes listReferenceImages without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listReferenceImages = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listReferenceImages(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listReferenceImagesStream', () => { - it('invokes listReferenceImagesStream without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IListReferenceImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listReferenceImages = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listReferenceImagesStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listProductsInProductSet', () => { - it('invokes listProductsInProductSet without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProductsInProductSet = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProductsInProductSet( - request, - (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - } - ); - }); - }); - describe('listProductsInProductSetStream', () => { - it('invokes listProductsInProductSetStream without error', done => { - const client = new productsearchModule.v1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1.IListProductsInProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProductsInProductSet = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductsInProductSetStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); -}); diff --git a/packages/google-cloud-vision/test/gapic-product_search-v1p3beta1.ts b/packages/google-cloud-vision/test/gapic-product_search-v1p3beta1.ts deleted file mode 100644 index 3c6d8b676e6..00000000000 --- a/packages/google-cloud-vision/test/gapic-product_search-v1p3beta1.ts +++ /dev/null @@ -1,1128 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const productsearchModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -function mockLongRunningGrpcMethod( - expectedRequest: {}, - response: {} | null, - error?: {} | null -) { - return (request: {}) => { - assert.deepStrictEqual(request, expectedRequest); - const mockOperation = { - promise() { - return new Promise((resolve, reject) => { - if (error) { - reject(error); - } else { - resolve([response]); - } - }); - }, - }; - return Promise.resolve([mockOperation]); - }; -} -describe('v1p3beta1.ProductSearchClient', () => { - it('has servicePath', () => { - const servicePath = - productsearchModule.v1p3beta1.ProductSearchClient.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - productsearchModule.v1p3beta1.ProductSearchClient.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = productsearchModule.v1p3beta1.ProductSearchClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - fallback: true, - }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.productSearchStub, undefined); - await client.initialize(); - assert(client.productSearchStub); - }); - it('has close method', () => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - describe('createProductSet', () => { - it('invokes createProductSet without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createProductSet with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductSetRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getProductSet', () => { - it('invokes getProductSet without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getProductSet with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('updateProductSet', () => { - it('invokes updateProductSet without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest = {}; - request.productSet = {}; - request.productSet.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.updateProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateProductSet with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductSetRequest = {}; - request.productSet = {}; - request.productSet.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.updateProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteProductSet', () => { - it('invokes deleteProductSet without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteProductSet with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('createProduct', () => { - it('invokes createProduct without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createProduct with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.ICreateProductRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getProduct', () => { - it('invokes getProduct without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getProduct with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IGetProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('updateProduct', () => { - it('invokes updateProduct without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest = {}; - request.product = {}; - request.product.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.updateProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateProduct with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IUpdateProductRequest = {}; - request.product = {}; - request.product.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.updateProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteProduct', () => { - it('invokes deleteProduct without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteProduct with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('createReferenceImage', () => { - it('invokes createReferenceImage without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createReferenceImage with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.ICreateReferenceImageRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteReferenceImage', () => { - it('invokes deleteReferenceImage without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteReferenceImage with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IDeleteReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getReferenceImage', () => { - it('invokes getReferenceImage without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getReferenceImage with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IGetReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('addProductToProductSet', () => { - it('invokes addProductToProductSet without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.addProductToProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.addProductToProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes addProductToProductSet with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IAddProductToProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.addProductToProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.addProductToProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('removeProductFromProductSet', () => { - it('invokes removeProductFromProductSet without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.removeProductFromProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.removeProductFromProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes removeProductFromProductSet with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IRemoveProductFromProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.removeProductFromProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.removeProductFromProductSet( - request, - (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - } - ); - }); - }); - describe('importProductSets', () => { - it('invokes importProductSets without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.importProductSets = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .importProductSets(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes importProductSets with error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IImportProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.importProductSets = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .importProductSets(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); - describe('listProductSets', () => { - it('invokes listProductSets without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProductSets = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProductSets(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listProductSetsStream', () => { - it('invokes listProductSetsStream without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IListProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProductSets = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductSetsStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listProducts', () => { - it('invokes listProducts without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProducts = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProducts(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listProductsStream', () => { - it('invokes listProductsStream without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProducts = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductsStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listReferenceImages', () => { - it('invokes listReferenceImages without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listReferenceImages = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listReferenceImages(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listReferenceImagesStream', () => { - it('invokes listReferenceImagesStream without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IListReferenceImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listReferenceImages = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listReferenceImagesStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listProductsInProductSet', () => { - it('invokes listProductsInProductSet without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProductsInProductSet = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProductsInProductSet( - request, - (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - } - ); - }); - }); - describe('listProductsInProductSetStream', () => { - it('invokes listProductsInProductSetStream without error', done => { - const client = new productsearchModule.v1p3beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p3beta1.IListProductsInProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProductsInProductSet = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductsInProductSetStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); -}); diff --git a/packages/google-cloud-vision/test/gapic-product_search-v1p4beta1.ts b/packages/google-cloud-vision/test/gapic-product_search-v1p4beta1.ts deleted file mode 100644 index b22dd8b48ec..00000000000 --- a/packages/google-cloud-vision/test/gapic-product_search-v1p4beta1.ts +++ /dev/null @@ -1,1195 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const productsearchModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -function mockLongRunningGrpcMethod( - expectedRequest: {}, - response: {} | null, - error?: {} | null -) { - return (request: {}) => { - assert.deepStrictEqual(request, expectedRequest); - const mockOperation = { - promise() { - return new Promise((resolve, reject) => { - if (error) { - reject(error); - } else { - resolve([response]); - } - }); - }, - }; - return Promise.resolve([mockOperation]); - }; -} -describe('v1p4beta1.ProductSearchClient', () => { - it('has servicePath', () => { - const servicePath = - productsearchModule.v1p4beta1.ProductSearchClient.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - productsearchModule.v1p4beta1.ProductSearchClient.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = productsearchModule.v1p4beta1.ProductSearchClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - fallback: true, - }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.productSearchStub, undefined); - await client.initialize(); - assert(client.productSearchStub); - }); - it('has close method', () => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - describe('createProductSet', () => { - it('invokes createProductSet without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createProductSet with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductSetRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getProductSet', () => { - it('invokes getProductSet without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getProductSet with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('updateProductSet', () => { - it('invokes updateProductSet without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest = {}; - request.productSet = {}; - request.productSet.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.updateProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateProductSet with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductSetRequest = {}; - request.productSet = {}; - request.productSet.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.updateProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteProductSet', () => { - it('invokes deleteProductSet without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteProductSet with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('createProduct', () => { - it('invokes createProduct without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createProduct with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.ICreateProductRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getProduct', () => { - it('invokes getProduct without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getProduct with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IGetProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('updateProduct', () => { - it('invokes updateProduct without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest = {}; - request.product = {}; - request.product.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.updateProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateProduct with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IUpdateProductRequest = {}; - request.product = {}; - request.product.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.updateProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteProduct', () => { - it('invokes deleteProduct without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProduct = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteProduct(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteProduct with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteProductRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteProduct = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteProduct(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('createReferenceImage', () => { - it('invokes createReferenceImage without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createReferenceImage with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.ICreateReferenceImageRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteReferenceImage', () => { - it('invokes deleteReferenceImage without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteReferenceImage with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IDeleteReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getReferenceImage', () => { - it('invokes getReferenceImage without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getReferenceImage = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getReferenceImage(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getReferenceImage with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IGetReferenceImageRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getReferenceImage = mockSimpleGrpcMethod( - request, - null, - error - ); - client.getReferenceImage(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('addProductToProductSet', () => { - it('invokes addProductToProductSet without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.addProductToProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.addProductToProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes addProductToProductSet with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IAddProductToProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.addProductToProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.addProductToProductSet(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('removeProductFromProductSet', () => { - it('invokes removeProductFromProductSet without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.removeProductFromProductSet = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.removeProductFromProductSet(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes removeProductFromProductSet with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IRemoveProductFromProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.removeProductFromProductSet = mockSimpleGrpcMethod( - request, - null, - error - ); - client.removeProductFromProductSet( - request, - (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - } - ); - }); - }); - describe('importProductSets', () => { - it('invokes importProductSets without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.importProductSets = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .importProductSets(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes importProductSets with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IImportProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.importProductSets = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .importProductSets(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); - describe('purgeProducts', () => { - it('invokes purgeProducts without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IPurgeProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.purgeProducts = mockLongRunningGrpcMethod( - request, - expectedResponse - ); - client - .purgeProducts(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then((responses: [Operation]) => { - assert.deepStrictEqual(responses[0], expectedResponse); - done(); - }) - .catch((err: {}) => { - done(err); - }); - }); - - it('invokes purgeProducts with error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IPurgeProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.purgeProducts = mockLongRunningGrpcMethod( - request, - null, - error - ); - client - .purgeProducts(request) - .then((responses: [Operation]) => { - const operation = responses[0]; - return operation ? operation.promise() : {}; - }) - .then(() => { - assert.fail(); - }) - .catch((err: FakeError) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - done(); - }); - }); - }); - describe('listProductSets', () => { - it('invokes listProductSets without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProductSets = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProductSets(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listProductSetsStream', () => { - it('invokes listProductSetsStream without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IListProductSetsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProductSets = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductSetsStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listProducts', () => { - it('invokes listProducts without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProducts = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProducts(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listProductsStream', () => { - it('invokes listProductsStream without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProducts = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductsStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listReferenceImages', () => { - it('invokes listReferenceImages without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listReferenceImages = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listReferenceImages(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listReferenceImagesStream', () => { - it('invokes listReferenceImagesStream without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IListReferenceImagesRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listReferenceImages = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listReferenceImagesStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); - describe('listProductsInProductSet', () => { - it('invokes listProductsInProductSet without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listProductsInProductSet = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listProductsInProductSet( - request, - (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - } - ); - }); - }); - describe('listProductsInProductSetStream', () => { - it('invokes listProductsInProductSetStream without error', done => { - const client = new productsearchModule.v1p4beta1.ProductSearchClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.vision.v1p4beta1.IListProductsInProductSetRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listProductsInProductSet = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listProductsInProductSetStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); -}); diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1.ts new file mode 100644 index 00000000000..efef61e331b --- /dev/null +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1.ts @@ -0,0 +1,925 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as imageannotatorModule from '../src'; + +import {protobuf, LROperation} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubLongRunningCall( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().rejects(callError) + : sinon.stub().resolves([mockOperation]); +} + +function stubLongRunningCallWithCallback( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().callsArgWith(2, callError) + : sinon.stub().callsArgWith(2, null, mockOperation); +} + +describe('v1.ImageAnnotatorClient', () => { + it('has servicePath', () => { + const servicePath = + imageannotatorModule.v1.ImageAnnotatorClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + imageannotatorModule.v1.ImageAnnotatorClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = imageannotatorModule.v1.ImageAnnotatorClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.imageAnnotatorStub, undefined); + await client.initialize(); + assert(client.imageAnnotatorStub); + }); + + it('has close method', () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('batchAnnotateImages', () => { + it('invokes batchAnnotateImages without error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + expectedResponse + ); + const [response] = await client.batchAnnotateImages(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes batchAnnotateImages without error using callback', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.batchAnnotateImages( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes batchAnnotateImages with error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.batchAnnotateImages(request); + }, expectedError); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('batchAnnotateFiles', () => { + it('invokes batchAnnotateFiles without error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateFilesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateFilesResponse() + ); + client.innerApiCalls.batchAnnotateFiles = stubSimpleCall( + expectedResponse + ); + const [response] = await client.batchAnnotateFiles(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes batchAnnotateFiles without error using callback', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateFilesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateFilesResponse() + ); + client.innerApiCalls.batchAnnotateFiles = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.batchAnnotateFiles( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes batchAnnotateFiles with error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.BatchAnnotateFilesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.batchAnnotateFiles = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.batchAnnotateFiles(request); + }, expectedError); + assert( + (client.innerApiCalls.batchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('asyncBatchAnnotateImages', () => { + it('invokes asyncBatchAnnotateImages without error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateImages = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.asyncBatchAnnotateImages(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateImages without error using callback', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateImages = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.asyncBatchAnnotateImages( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1.IOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes asyncBatchAnnotateImages with call error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateImages = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.asyncBatchAnnotateImages(request); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateImages with LRO error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateImages = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.asyncBatchAnnotateImages(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('asyncBatchAnnotateFiles', () => { + it('invokes asyncBatchAnnotateFiles without error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.asyncBatchAnnotateFiles(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateFiles without error using callback', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.asyncBatchAnnotateFiles( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1.IOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes asyncBatchAnnotateFiles with call error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.asyncBatchAnnotateFiles(request); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateFiles with LRO error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.asyncBatchAnnotateFiles(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('Path templates', () => { + describe('product', () => { + const fakePath = '/rendered/path/product'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + }; + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productPath', () => { + const result = client.productPath( + 'projectValue', + 'locationValue', + 'productValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductName', () => { + const result = client.matchProjectFromProductName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductName', () => { + const result = client.matchLocationFromProductName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromProductName', () => { + const result = client.matchProductFromProductName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('productSet', () => { + const fakePath = '/rendered/path/productSet'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product_set: 'productSetValue', + }; + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productSetPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productSetPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productSetPath', () => { + const result = client.productSetPath( + 'projectValue', + 'locationValue', + 'productSetValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productSetPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductSetName', () => { + const result = client.matchProjectFromProductSetName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductSetName', () => { + const result = client.matchLocationFromProductSetName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductSetFromProductSetName', () => { + const result = client.matchProductSetFromProductSetName(fakePath); + assert.strictEqual(result, 'productSetValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('referenceImage', () => { + const fakePath = '/rendered/path/referenceImage'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + reference_image: 'referenceImageValue', + }; + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.referenceImagePathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.referenceImagePathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('referenceImagePath', () => { + const result = client.referenceImagePath( + 'projectValue', + 'locationValue', + 'productValue', + 'referenceImageValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.referenceImagePathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromReferenceImageName', () => { + const result = client.matchProjectFromReferenceImageName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromReferenceImageName', () => { + const result = client.matchLocationFromReferenceImageName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromReferenceImageName', () => { + const result = client.matchProductFromReferenceImageName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchReferenceImageFromReferenceImageName', () => { + const result = client.matchReferenceImageFromReferenceImageName( + fakePath + ); + assert.strictEqual(result, 'referenceImageValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +}); diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1p1beta1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1p1beta1.ts new file mode 100644 index 00000000000..4e771dc3cf4 --- /dev/null +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1p1beta1.ts @@ -0,0 +1,227 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as imageannotatorModule from '../src'; + +import {protobuf} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +describe('v1p1beta1.ImageAnnotatorClient', () => { + it('has servicePath', () => { + const servicePath = + imageannotatorModule.v1p1beta1.ImageAnnotatorClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + imageannotatorModule.v1p1beta1.ImageAnnotatorClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = imageannotatorModule.v1p1beta1.ImageAnnotatorClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.imageAnnotatorStub, undefined); + await client.initialize(); + assert(client.imageAnnotatorStub); + }); + + it('has close method', () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('batchAnnotateImages', () => { + it('invokes batchAnnotateImages without error', async () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p1beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p1beta1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + expectedResponse + ); + const [response] = await client.batchAnnotateImages(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes batchAnnotateImages without error using callback', async () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p1beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p1beta1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.batchAnnotateImages( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p1beta1.IBatchAnnotateImagesResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes batchAnnotateImages with error', async () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p1beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.batchAnnotateImages(request); + }, expectedError); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); +}); diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1p2beta1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1p2beta1.ts new file mode 100644 index 00000000000..071e165982c --- /dev/null +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1p2beta1.ts @@ -0,0 +1,386 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as imageannotatorModule from '../src'; + +import {protobuf, LROperation} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubLongRunningCall( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().rejects(callError) + : sinon.stub().resolves([mockOperation]); +} + +function stubLongRunningCallWithCallback( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().callsArgWith(2, callError) + : sinon.stub().callsArgWith(2, null, mockOperation); +} + +describe('v1p2beta1.ImageAnnotatorClient', () => { + it('has servicePath', () => { + const servicePath = + imageannotatorModule.v1p2beta1.ImageAnnotatorClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + imageannotatorModule.v1p2beta1.ImageAnnotatorClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = imageannotatorModule.v1p2beta1.ImageAnnotatorClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.imageAnnotatorStub, undefined); + await client.initialize(); + assert(client.imageAnnotatorStub); + }); + + it('has close method', () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('batchAnnotateImages', () => { + it('invokes batchAnnotateImages without error', async () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + expectedResponse + ); + const [response] = await client.batchAnnotateImages(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes batchAnnotateImages without error using callback', async () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.batchAnnotateImages( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p2beta1.IBatchAnnotateImagesResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes batchAnnotateImages with error', async () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.batchAnnotateImages(request); + }, expectedError); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('asyncBatchAnnotateFiles', () => { + it('invokes asyncBatchAnnotateFiles without error', async () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.asyncBatchAnnotateFiles(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateFiles without error using callback', async () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.asyncBatchAnnotateFiles( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p2beta1.IOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1p2beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p2beta1.IOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes asyncBatchAnnotateFiles with call error', async () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.asyncBatchAnnotateFiles(request); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateFiles with LRO error', async () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.asyncBatchAnnotateFiles(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); +}); diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1p3beta1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1p3beta1.ts new file mode 100644 index 00000000000..19df46dfead --- /dev/null +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1p3beta1.ts @@ -0,0 +1,594 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as imageannotatorModule from '../src'; + +import {protobuf, LROperation} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubLongRunningCall( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().rejects(callError) + : sinon.stub().resolves([mockOperation]); +} + +function stubLongRunningCallWithCallback( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().callsArgWith(2, callError) + : sinon.stub().callsArgWith(2, null, mockOperation); +} + +describe('v1p3beta1.ImageAnnotatorClient', () => { + it('has servicePath', () => { + const servicePath = + imageannotatorModule.v1p3beta1.ImageAnnotatorClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + imageannotatorModule.v1p3beta1.ImageAnnotatorClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = imageannotatorModule.v1p3beta1.ImageAnnotatorClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.imageAnnotatorStub, undefined); + await client.initialize(); + assert(client.imageAnnotatorStub); + }); + + it('has close method', () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('batchAnnotateImages', () => { + it('invokes batchAnnotateImages without error', async () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + expectedResponse + ); + const [response] = await client.batchAnnotateImages(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes batchAnnotateImages without error using callback', async () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.batchAnnotateImages( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IBatchAnnotateImagesResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes batchAnnotateImages with error', async () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.batchAnnotateImages(request); + }, expectedError); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('asyncBatchAnnotateFiles', () => { + it('invokes asyncBatchAnnotateFiles without error', async () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.asyncBatchAnnotateFiles(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateFiles without error using callback', async () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.asyncBatchAnnotateFiles( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p3beta1.IOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1p3beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p3beta1.IOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes asyncBatchAnnotateFiles with call error', async () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.asyncBatchAnnotateFiles(request); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateFiles with LRO error', async () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.asyncBatchAnnotateFiles(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('Path templates', () => { + describe('product', () => { + const fakePath = '/rendered/path/product'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + }; + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productPath', () => { + const result = client.productPath( + 'projectValue', + 'locationValue', + 'productValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductName', () => { + const result = client.matchProjectFromProductName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductName', () => { + const result = client.matchLocationFromProductName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromProductName', () => { + const result = client.matchProductFromProductName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('productSet', () => { + const fakePath = '/rendered/path/productSet'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product_set: 'productSetValue', + }; + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productSetPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productSetPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productSetPath', () => { + const result = client.productSetPath( + 'projectValue', + 'locationValue', + 'productSetValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productSetPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductSetName', () => { + const result = client.matchProjectFromProductSetName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductSetName', () => { + const result = client.matchLocationFromProductSetName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductSetFromProductSetName', () => { + const result = client.matchProductSetFromProductSetName(fakePath); + assert.strictEqual(result, 'productSetValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('referenceImage', () => { + const fakePath = '/rendered/path/referenceImage'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + reference_image: 'referenceImageValue', + }; + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.referenceImagePathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.referenceImagePathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('referenceImagePath', () => { + const result = client.referenceImagePath( + 'projectValue', + 'locationValue', + 'productValue', + 'referenceImageValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.referenceImagePathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromReferenceImageName', () => { + const result = client.matchProjectFromReferenceImageName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromReferenceImageName', () => { + const result = client.matchLocationFromReferenceImageName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromReferenceImageName', () => { + const result = client.matchProductFromReferenceImageName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchReferenceImageFromReferenceImageName', () => { + const result = client.matchReferenceImageFromReferenceImageName( + fakePath + ); + assert.strictEqual(result, 'referenceImageValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +}); diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1p4beta1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1p4beta1.ts new file mode 100644 index 00000000000..f581827d8aa --- /dev/null +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1p4beta1.ts @@ -0,0 +1,813 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as imageannotatorModule from '../src'; + +import {protobuf, LROperation} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubLongRunningCall( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().rejects(callError) + : sinon.stub().resolves([mockOperation]); +} + +function stubLongRunningCallWithCallback( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().callsArgWith(2, callError) + : sinon.stub().callsArgWith(2, null, mockOperation); +} + +describe('v1p4beta1.ImageAnnotatorClient', () => { + it('has servicePath', () => { + const servicePath = + imageannotatorModule.v1p4beta1.ImageAnnotatorClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + imageannotatorModule.v1p4beta1.ImageAnnotatorClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = imageannotatorModule.v1p4beta1.ImageAnnotatorClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.imageAnnotatorStub, undefined); + await client.initialize(); + assert(client.imageAnnotatorStub); + }); + + it('has close method', () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('batchAnnotateImages', () => { + it('invokes batchAnnotateImages without error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + expectedResponse + ); + const [response] = await client.batchAnnotateImages(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes batchAnnotateImages without error using callback', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateImagesResponse() + ); + client.innerApiCalls.batchAnnotateImages = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.batchAnnotateImages( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes batchAnnotateImages with error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.batchAnnotateImages = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.batchAnnotateImages(request); + }, expectedError); + assert( + (client.innerApiCalls.batchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('batchAnnotateFiles', () => { + it('invokes batchAnnotateFiles without error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateFilesResponse() + ); + client.innerApiCalls.batchAnnotateFiles = stubSimpleCall( + expectedResponse + ); + const [response] = await client.batchAnnotateFiles(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes batchAnnotateFiles without error using callback', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateFilesResponse() + ); + client.innerApiCalls.batchAnnotateFiles = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.batchAnnotateFiles( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.batchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes batchAnnotateFiles with error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.BatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.batchAnnotateFiles = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.batchAnnotateFiles(request); + }, expectedError); + assert( + (client.innerApiCalls.batchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('asyncBatchAnnotateImages', () => { + it('invokes asyncBatchAnnotateImages without error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateImages = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.asyncBatchAnnotateImages(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateImages without error using callback', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateImages = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.asyncBatchAnnotateImages( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes asyncBatchAnnotateImages with call error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateImages = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.asyncBatchAnnotateImages(request); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateImages with LRO error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateImagesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateImages = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.asyncBatchAnnotateImages(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('asyncBatchAnnotateFiles', () => { + it('invokes asyncBatchAnnotateFiles without error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.asyncBatchAnnotateFiles(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateFiles without error using callback', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.asyncBatchAnnotateFiles( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse, + protos.google.cloud.vision.v1p4beta1.IOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes asyncBatchAnnotateFiles with call error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.asyncBatchAnnotateFiles(request); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes asyncBatchAnnotateFiles with LRO error', async () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateFilesRequest() + ); + const expectedOptions = {}; + const expectedError = new Error('expected'); + client.innerApiCalls.asyncBatchAnnotateFiles = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.asyncBatchAnnotateFiles(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.asyncBatchAnnotateFiles as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('Path templates', () => { + describe('product', () => { + const fakePath = '/rendered/path/product'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + }; + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productPath', () => { + const result = client.productPath( + 'projectValue', + 'locationValue', + 'productValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductName', () => { + const result = client.matchProjectFromProductName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductName', () => { + const result = client.matchLocationFromProductName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromProductName', () => { + const result = client.matchProductFromProductName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('productSet', () => { + const fakePath = '/rendered/path/productSet'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product_set: 'productSetValue', + }; + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productSetPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productSetPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productSetPath', () => { + const result = client.productSetPath( + 'projectValue', + 'locationValue', + 'productSetValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productSetPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductSetName', () => { + const result = client.matchProjectFromProductSetName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductSetName', () => { + const result = client.matchLocationFromProductSetName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductSetFromProductSetName', () => { + const result = client.matchProductSetFromProductSetName(fakePath); + assert.strictEqual(result, 'productSetValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('referenceImage', () => { + const fakePath = '/rendered/path/referenceImage'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + reference_image: 'referenceImageValue', + }; + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.referenceImagePathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.referenceImagePathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('referenceImagePath', () => { + const result = client.referenceImagePath( + 'projectValue', + 'locationValue', + 'productValue', + 'referenceImageValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.referenceImagePathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromReferenceImageName', () => { + const result = client.matchProjectFromReferenceImageName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromReferenceImageName', () => { + const result = client.matchLocationFromReferenceImageName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromReferenceImageName', () => { + const result = client.matchProductFromReferenceImageName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchReferenceImageFromReferenceImageName', () => { + const result = client.matchReferenceImageFromReferenceImageName( + fakePath + ); + assert.strictEqual(result, 'referenceImageValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +}); diff --git a/packages/google-cloud-vision/test/gapic_product_search_v1.ts b/packages/google-cloud-vision/test/gapic_product_search_v1.ts new file mode 100644 index 00000000000..e431c4144c6 --- /dev/null +++ b/packages/google-cloud-vision/test/gapic_product_search_v1.ts @@ -0,0 +1,3493 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as productsearchModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf, LROperation} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubLongRunningCall( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().rejects(callError) + : sinon.stub().resolves([mockOperation]); +} + +function stubLongRunningCallWithCallback( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().callsArgWith(2, callError) + : sinon.stub().callsArgWith(2, null, mockOperation); +} + +function stubPageStreamingCall( + responses?: ResponseType[], + error?: Error +) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error + ? sinon.stub().callsArgWith(2, error) + : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { + mockStream.write({}); + }); + } + setImmediate(() => { + mockStream.end(); + }); + } else { + setImmediate(() => { + mockStream.write({}); + }); + setImmediate(() => { + mockStream.end(); + }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall( + responses?: ResponseType[], + error?: Error +) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + }, + }; + }, + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.ProductSearchClient', () => { + it('has servicePath', () => { + const servicePath = productsearchModule.v1.ProductSearchClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = productsearchModule.v1.ProductSearchClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = productsearchModule.v1.ProductSearchClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new productsearchModule.v1.ProductSearchClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new productsearchModule.v1.ProductSearchClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.productSearchStub, undefined); + await client.initialize(); + assert(client.productSearchStub); + }); + + it('has close method', () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('createProductSet', () => { + it('invokes createProductSet without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ProductSet() + ); + client.innerApiCalls.createProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.createProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createProductSet without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ProductSet() + ); + client.innerApiCalls.createProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createProductSet with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getProductSet', () => { + it('invokes getProductSet without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ProductSet() + ); + client.innerApiCalls.getProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.getProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getProductSet without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ProductSet() + ); + client.innerApiCalls.getProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getProductSet with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('updateProductSet', () => { + it('invokes updateProductSet without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ProductSet() + ); + client.innerApiCalls.updateProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.updateProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes updateProductSet without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ProductSet() + ); + client.innerApiCalls.updateProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.updateProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes updateProductSet with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updateProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.updateProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteProductSet', () => { + it('invokes deleteProductSet without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.deleteProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteProductSet without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteProductSet with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('createProduct', () => { + it('invokes createProduct without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.Product() + ); + client.innerApiCalls.createProduct = stubSimpleCall(expectedResponse); + const [response] = await client.createProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createProduct without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.Product() + ); + client.innerApiCalls.createProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createProduct with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getProduct', () => { + it('invokes getProduct without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.Product() + ); + client.innerApiCalls.getProduct = stubSimpleCall(expectedResponse); + const [response] = await client.getProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getProduct without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.Product() + ); + client.innerApiCalls.getProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getProduct with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('updateProduct', () => { + it('invokes updateProduct without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.Product() + ); + client.innerApiCalls.updateProduct = stubSimpleCall(expectedResponse); + const [response] = await client.updateProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes updateProduct without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.Product() + ); + client.innerApiCalls.updateProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.updateProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes updateProduct with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updateProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.updateProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteProduct', () => { + it('invokes deleteProduct without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProduct = stubSimpleCall(expectedResponse); + const [response] = await client.deleteProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteProduct without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteProduct( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteProduct with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('createReferenceImage', () => { + it('invokes createReferenceImage without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ); + client.innerApiCalls.createReferenceImage = stubSimpleCall( + expectedResponse + ); + const [response] = await client.createReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ); + client.innerApiCalls.createReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IReferenceImage | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createReferenceImage with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteReferenceImage', () => { + it('invokes deleteReferenceImage without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteReferenceImage = stubSimpleCall( + expectedResponse + ); + const [response] = await client.deleteReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteReferenceImage with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getReferenceImage', () => { + it('invokes getReferenceImage without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ); + client.innerApiCalls.getReferenceImage = stubSimpleCall(expectedResponse); + const [response] = await client.getReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ); + client.innerApiCalls.getReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IReferenceImage | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getReferenceImage with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('addProductToProductSet', () => { + it('invokes addProductToProductSet without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.addProductToProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.addProductToProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes addProductToProductSet without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.addProductToProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.addProductToProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes addProductToProductSet with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.addProductToProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.addProductToProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('removeProductFromProductSet', () => { + it('invokes removeProductFromProductSet without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.removeProductFromProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes removeProductFromProductSet without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.removeProductFromProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes removeProductFromProductSet with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.removeProductFromProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('importProductSets', () => { + it('invokes importProductSets without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.importProductSets = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.importProductSets(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes importProductSets without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.importProductSets = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.importProductSets( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1.IImportProductSetsResponse, + protos.google.cloud.vision.v1.IBatchOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1.IImportProductSetsResponse, + protos.google.cloud.vision.v1.IBatchOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes importProductSets with call error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.importProductSets = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.importProductSets(request); + }, expectedError); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes importProductSets with LRO error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.importProductSets = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.importProductSets(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('purgeProducts', () => { + it('invokes purgeProducts without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.PurgeProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.purgeProducts = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.purgeProducts(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.purgeProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes purgeProducts without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.PurgeProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.purgeProducts = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.purgeProducts( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IBatchOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1.IBatchOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.purgeProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes purgeProducts with call error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.PurgeProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.purgeProducts = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.purgeProducts(request); + }, expectedError); + assert( + (client.innerApiCalls.purgeProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes purgeProducts with LRO error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.PurgeProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.purgeProducts = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.purgeProducts(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.purgeProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('listProductSets', () => { + it('invokes listProductSets without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + ]; + client.innerApiCalls.listProductSets = stubSimpleCall(expectedResponse); + const [response] = await client.listProductSets(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductSets without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + ]; + client.innerApiCalls.listProductSets = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProductSets( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProductSet[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProductSets with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProductSets = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProductSets(request); + }, expectedError); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductSetsStream without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + ]; + client.descriptors.page.listProductSets.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductSetsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1.ProductSet[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1.ProductSet) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProductSets.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductSets, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductSetsStream with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductSets.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductSetsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1.ProductSet[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1.ProductSet) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProductSets.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductSets, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductSets without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + generateSampleMessage(new protos.google.cloud.vision.v1.ProductSet()), + ]; + client.descriptors.page.listProductSets.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1.IProductSet[] = []; + const iterable = client.listProductSetsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductSets with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductSets.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductSetsAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1.IProductSet[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listProducts', () => { + it('invokes listProducts without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + ]; + client.innerApiCalls.listProducts = stubSimpleCall(expectedResponse); + const [response] = await client.listProducts(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProducts without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + ]; + client.innerApiCalls.listProducts = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProducts( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProduct[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProducts with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProducts = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProducts(request); + }, expectedError); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsStream without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + ]; + client.descriptors.page.listProducts.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1.Product[] = []; + stream.on('data', (response: protos.google.cloud.vision.v1.Product) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProducts.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProducts, request) + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductsStream with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProducts.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1.Product[] = []; + stream.on('data', (response: protos.google.cloud.vision.v1.Product) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProducts.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProducts, request) + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProducts without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + ]; + client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1.IProduct[] = []; + const iterable = client.listProductsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProducts with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductsAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1.IProduct[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listReferenceImages', () => { + it('invokes listReferenceImages without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + ]; + client.innerApiCalls.listReferenceImages = stubSimpleCall( + expectedResponse + ); + const [response] = await client.listReferenceImages(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listReferenceImages without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + ]; + client.innerApiCalls.listReferenceImages = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listReferenceImages( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IReferenceImage[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listReferenceImages with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listReferenceImages = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listReferenceImages(request); + }, expectedError); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listReferenceImagesStream without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + ]; + client.descriptors.page.listReferenceImages.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listReferenceImagesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1.ReferenceImage[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1.ReferenceImage) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listReferenceImages.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listReferenceImages, request) + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listReferenceImagesStream with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listReferenceImages.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listReferenceImagesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1.ReferenceImage[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1.ReferenceImage) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listReferenceImages.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listReferenceImages, request) + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listReferenceImages without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1.ReferenceImage() + ), + ]; + client.descriptors.page.listReferenceImages.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1.IReferenceImage[] = []; + const iterable = client.listReferenceImagesAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listReferenceImages with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listReferenceImages.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listReferenceImagesAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1.IReferenceImage[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listProductsInProductSet', () => { + it('invokes listProductsInProductSet without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + ]; + client.innerApiCalls.listProductsInProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.listProductsInProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsInProductSet without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + ]; + client.innerApiCalls.listProductsInProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProductsInProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1.IProduct[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProductsInProductSet with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProductsInProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProductsInProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsInProductSetStream without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + ]; + client.descriptors.page.listProductsInProductSet.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductsInProductSetStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1.Product[] = []; + stream.on('data', (response: protos.google.cloud.vision.v1.Product) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductsInProductSet, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductsInProductSetStream with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductsInProductSet.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductsInProductSetStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1.Product[] = []; + stream.on('data', (response: protos.google.cloud.vision.v1.Product) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductsInProductSet, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductsInProductSet without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + generateSampleMessage(new protos.google.cloud.vision.v1.Product()), + ]; + client.descriptors.page.listProductsInProductSet.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1.IProduct[] = []; + const iterable = client.listProductsInProductSetAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductsInProductSet with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductsInProductSet.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductsInProductSetAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1.IProduct[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('Path templates', () => { + describe('location', () => { + const fakePath = '/rendered/path/location'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + }; + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.locationPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.locationPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('locationPath', () => { + const result = client.locationPath('projectValue', 'locationValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.locationPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromLocationName', () => { + const result = client.matchProjectFromLocationName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.locationPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromLocationName', () => { + const result = client.matchLocationFromLocationName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.locationPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('product', () => { + const fakePath = '/rendered/path/product'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + }; + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productPath', () => { + const result = client.productPath( + 'projectValue', + 'locationValue', + 'productValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductName', () => { + const result = client.matchProjectFromProductName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductName', () => { + const result = client.matchLocationFromProductName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromProductName', () => { + const result = client.matchProductFromProductName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('productSet', () => { + const fakePath = '/rendered/path/productSet'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product_set: 'productSetValue', + }; + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productSetPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productSetPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productSetPath', () => { + const result = client.productSetPath( + 'projectValue', + 'locationValue', + 'productSetValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productSetPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductSetName', () => { + const result = client.matchProjectFromProductSetName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductSetName', () => { + const result = client.matchLocationFromProductSetName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductSetFromProductSetName', () => { + const result = client.matchProductSetFromProductSetName(fakePath); + assert.strictEqual(result, 'productSetValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('referenceImage', () => { + const fakePath = '/rendered/path/referenceImage'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + reference_image: 'referenceImageValue', + }; + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.referenceImagePathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.referenceImagePathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('referenceImagePath', () => { + const result = client.referenceImagePath( + 'projectValue', + 'locationValue', + 'productValue', + 'referenceImageValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.referenceImagePathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromReferenceImageName', () => { + const result = client.matchProjectFromReferenceImageName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromReferenceImageName', () => { + const result = client.matchLocationFromReferenceImageName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromReferenceImageName', () => { + const result = client.matchProductFromReferenceImageName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchReferenceImageFromReferenceImageName', () => { + const result = client.matchReferenceImageFromReferenceImageName( + fakePath + ); + assert.strictEqual(result, 'referenceImageValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +}); diff --git a/packages/google-cloud-vision/test/gapic_product_search_v1p3beta1.ts b/packages/google-cloud-vision/test/gapic_product_search_v1p3beta1.ts new file mode 100644 index 00000000000..ef12b4d35bd --- /dev/null +++ b/packages/google-cloud-vision/test/gapic_product_search_v1p3beta1.ts @@ -0,0 +1,3422 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as productsearchModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf, LROperation} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubLongRunningCall( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().rejects(callError) + : sinon.stub().resolves([mockOperation]); +} + +function stubLongRunningCallWithCallback( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().callsArgWith(2, callError) + : sinon.stub().callsArgWith(2, null, mockOperation); +} + +function stubPageStreamingCall( + responses?: ResponseType[], + error?: Error +) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error + ? sinon.stub().callsArgWith(2, error) + : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { + mockStream.write({}); + }); + } + setImmediate(() => { + mockStream.end(); + }); + } else { + setImmediate(() => { + mockStream.write({}); + }); + setImmediate(() => { + mockStream.end(); + }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall( + responses?: ResponseType[], + error?: Error +) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + }, + }; + }, + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1p3beta1.ProductSearchClient', () => { + it('has servicePath', () => { + const servicePath = + productsearchModule.v1p3beta1.ProductSearchClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + productsearchModule.v1p3beta1.ProductSearchClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = productsearchModule.v1p3beta1.ProductSearchClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.productSearchStub, undefined); + await client.initialize(); + assert(client.productSearchStub); + }); + + it('has close method', () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('createProductSet', () => { + it('invokes createProductSet without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ); + client.innerApiCalls.createProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.createProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createProductSet without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ); + client.innerApiCalls.createProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createProductSet with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getProductSet', () => { + it('invokes getProductSet without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ); + client.innerApiCalls.getProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.getProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getProductSet without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ); + client.innerApiCalls.getProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getProductSet with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('updateProductSet', () => { + it('invokes updateProductSet without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ); + client.innerApiCalls.updateProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.updateProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes updateProductSet without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ); + client.innerApiCalls.updateProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.updateProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes updateProductSet with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updateProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.updateProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteProductSet', () => { + it('invokes deleteProductSet without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.deleteProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteProductSet without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteProductSet with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('createProduct', () => { + it('invokes createProduct without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ); + client.innerApiCalls.createProduct = stubSimpleCall(expectedResponse); + const [response] = await client.createProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createProduct without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ); + client.innerApiCalls.createProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createProduct with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getProduct', () => { + it('invokes getProduct without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ); + client.innerApiCalls.getProduct = stubSimpleCall(expectedResponse); + const [response] = await client.getProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getProduct without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ); + client.innerApiCalls.getProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getProduct with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('updateProduct', () => { + it('invokes updateProduct without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ); + client.innerApiCalls.updateProduct = stubSimpleCall(expectedResponse); + const [response] = await client.updateProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes updateProduct without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ); + client.innerApiCalls.updateProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.updateProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes updateProduct with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updateProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.updateProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteProduct', () => { + it('invokes deleteProduct without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProduct = stubSimpleCall(expectedResponse); + const [response] = await client.deleteProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteProduct without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteProduct( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteProduct with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('createReferenceImage', () => { + it('invokes createReferenceImage without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ); + client.innerApiCalls.createReferenceImage = stubSimpleCall( + expectedResponse + ); + const [response] = await client.createReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ); + client.innerApiCalls.createReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IReferenceImage | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createReferenceImage with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteReferenceImage', () => { + it('invokes deleteReferenceImage without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteReferenceImage = stubSimpleCall( + expectedResponse + ); + const [response] = await client.deleteReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteReferenceImage with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getReferenceImage', () => { + it('invokes getReferenceImage without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ); + client.innerApiCalls.getReferenceImage = stubSimpleCall(expectedResponse); + const [response] = await client.getReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ); + client.innerApiCalls.getReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IReferenceImage | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getReferenceImage with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('addProductToProductSet', () => { + it('invokes addProductToProductSet without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.addProductToProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.addProductToProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes addProductToProductSet without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.addProductToProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.addProductToProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes addProductToProductSet with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.addProductToProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.addProductToProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('removeProductFromProductSet', () => { + it('invokes removeProductFromProductSet without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.removeProductFromProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes removeProductFromProductSet without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.removeProductFromProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes removeProductFromProductSet with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.removeProductFromProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('importProductSets', () => { + it('invokes importProductSets without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.importProductSets = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.importProductSets(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes importProductSets without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.importProductSets = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.importProductSets( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p3beta1.IBatchOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1p3beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p3beta1.IBatchOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes importProductSets with call error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.importProductSets = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.importProductSets(request); + }, expectedError); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes importProductSets with LRO error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.importProductSets = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.importProductSets(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('listProductSets', () => { + it('invokes listProductSets without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + ]; + client.innerApiCalls.listProductSets = stubSimpleCall(expectedResponse); + const [response] = await client.listProductSets(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductSets without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + ]; + client.innerApiCalls.listProductSets = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProductSets( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProductSet[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProductSets with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProductSets = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProductSets(request); + }, expectedError); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductSetsStream without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + ]; + client.descriptors.page.listProductSets.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductSetsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p3beta1.ProductSet[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p3beta1.ProductSet) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProductSets.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductSets, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductSetsStream with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductSets.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductSetsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p3beta1.ProductSet[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p3beta1.ProductSet) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProductSets.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductSets, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductSets without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ProductSet() + ), + ]; + client.descriptors.page.listProductSets.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1p3beta1.IProductSet[] = []; + const iterable = client.listProductSetsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductSets with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductSets.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductSetsAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1p3beta1.IProductSet[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listProducts', () => { + it('invokes listProducts without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + ]; + client.innerApiCalls.listProducts = stubSimpleCall(expectedResponse); + const [response] = await client.listProducts(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProducts without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + ]; + client.innerApiCalls.listProducts = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProducts( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProduct[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProducts with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProducts = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProducts(request); + }, expectedError); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsStream without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + ]; + client.descriptors.page.listProducts.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p3beta1.Product[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p3beta1.Product) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProducts.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProducts, request) + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductsStream with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProducts.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p3beta1.Product[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p3beta1.Product) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProducts.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProducts, request) + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProducts without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + ]; + client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1p3beta1.IProduct[] = []; + const iterable = client.listProductsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProducts with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductsAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1p3beta1.IProduct[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listReferenceImages', () => { + it('invokes listReferenceImages without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + ]; + client.innerApiCalls.listReferenceImages = stubSimpleCall( + expectedResponse + ); + const [response] = await client.listReferenceImages(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listReferenceImages without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + ]; + client.innerApiCalls.listReferenceImages = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listReferenceImages( + request, + ( + err?: Error | null, + result?: + | protos.google.cloud.vision.v1p3beta1.IReferenceImage[] + | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listReferenceImages with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listReferenceImages = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listReferenceImages(request); + }, expectedError); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listReferenceImagesStream without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + ]; + client.descriptors.page.listReferenceImages.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listReferenceImagesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p3beta1.ReferenceImage[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p3beta1.ReferenceImage) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listReferenceImages.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listReferenceImages, request) + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listReferenceImagesStream with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listReferenceImages.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listReferenceImagesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p3beta1.ReferenceImage[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p3beta1.ReferenceImage) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listReferenceImages.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listReferenceImages, request) + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listReferenceImages without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ReferenceImage() + ), + ]; + client.descriptors.page.listReferenceImages.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1p3beta1.IReferenceImage[] = []; + const iterable = client.listReferenceImagesAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listReferenceImages with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listReferenceImages.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listReferenceImagesAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1p3beta1.IReferenceImage[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listProductsInProductSet', () => { + it('invokes listProductsInProductSet without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + ]; + client.innerApiCalls.listProductsInProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.listProductsInProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsInProductSet without error using callback', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + ]; + client.innerApiCalls.listProductsInProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProductsInProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p3beta1.IProduct[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProductsInProductSet with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProductsInProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProductsInProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsInProductSetStream without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + ]; + client.descriptors.page.listProductsInProductSet.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductsInProductSetStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p3beta1.Product[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p3beta1.Product) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductsInProductSet, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductsInProductSetStream with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductsInProductSet.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductsInProductSetStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p3beta1.Product[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p3beta1.Product) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductsInProductSet, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductsInProductSet without error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.Product() + ), + ]; + client.descriptors.page.listProductsInProductSet.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1p3beta1.IProduct[] = []; + const iterable = client.listProductsInProductSetAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductsInProductSet with error', async () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p3beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductsInProductSet.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductsInProductSetAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1p3beta1.IProduct[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('Path templates', () => { + describe('location', () => { + const fakePath = '/rendered/path/location'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + }; + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.locationPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.locationPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('locationPath', () => { + const result = client.locationPath('projectValue', 'locationValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.locationPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromLocationName', () => { + const result = client.matchProjectFromLocationName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.locationPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromLocationName', () => { + const result = client.matchLocationFromLocationName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.locationPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('product', () => { + const fakePath = '/rendered/path/product'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + }; + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productPath', () => { + const result = client.productPath( + 'projectValue', + 'locationValue', + 'productValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductName', () => { + const result = client.matchProjectFromProductName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductName', () => { + const result = client.matchLocationFromProductName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromProductName', () => { + const result = client.matchProductFromProductName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('productSet', () => { + const fakePath = '/rendered/path/productSet'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product_set: 'productSetValue', + }; + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productSetPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productSetPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productSetPath', () => { + const result = client.productSetPath( + 'projectValue', + 'locationValue', + 'productSetValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productSetPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductSetName', () => { + const result = client.matchProjectFromProductSetName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductSetName', () => { + const result = client.matchLocationFromProductSetName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductSetFromProductSetName', () => { + const result = client.matchProductSetFromProductSetName(fakePath); + assert.strictEqual(result, 'productSetValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('referenceImage', () => { + const fakePath = '/rendered/path/referenceImage'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + reference_image: 'referenceImageValue', + }; + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.referenceImagePathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.referenceImagePathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('referenceImagePath', () => { + const result = client.referenceImagePath( + 'projectValue', + 'locationValue', + 'productValue', + 'referenceImageValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.referenceImagePathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromReferenceImageName', () => { + const result = client.matchProjectFromReferenceImageName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromReferenceImageName', () => { + const result = client.matchLocationFromReferenceImageName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromReferenceImageName', () => { + const result = client.matchProductFromReferenceImageName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchReferenceImageFromReferenceImageName', () => { + const result = client.matchReferenceImageFromReferenceImageName( + fakePath + ); + assert.strictEqual(result, 'referenceImageValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +}); diff --git a/packages/google-cloud-vision/test/gapic_product_search_v1p4beta1.ts b/packages/google-cloud-vision/test/gapic_product_search_v1p4beta1.ts new file mode 100644 index 00000000000..f4abbafd745 --- /dev/null +++ b/packages/google-cloud-vision/test/gapic_product_search_v1p4beta1.ts @@ -0,0 +1,3581 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as productsearchModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf, LROperation} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubLongRunningCall( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().rejects(callError) + : sinon.stub().resolves([mockOperation]); +} + +function stubLongRunningCallWithCallback( + response?: ResponseType, + callError?: Error, + lroError?: Error +) { + const innerStub = lroError + ? sinon.stub().rejects(lroError) + : sinon.stub().resolves([response]); + const mockOperation = { + promise: innerStub, + }; + return callError + ? sinon.stub().callsArgWith(2, callError) + : sinon.stub().callsArgWith(2, null, mockOperation); +} + +function stubPageStreamingCall( + responses?: ResponseType[], + error?: Error +) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error + ? sinon.stub().callsArgWith(2, error) + : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { + mockStream.write({}); + }); + } + setImmediate(() => { + mockStream.end(); + }); + } else { + setImmediate(() => { + mockStream.write({}); + }); + setImmediate(() => { + mockStream.end(); + }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall( + responses?: ResponseType[], + error?: Error +) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + }, + }; + }, + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1p4beta1.ProductSearchClient', () => { + it('has servicePath', () => { + const servicePath = + productsearchModule.v1p4beta1.ProductSearchClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + productsearchModule.v1p4beta1.ProductSearchClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = productsearchModule.v1p4beta1.ProductSearchClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.productSearchStub, undefined); + await client.initialize(); + assert(client.productSearchStub); + }); + + it('has close method', () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('createProductSet', () => { + it('invokes createProductSet without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ); + client.innerApiCalls.createProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.createProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createProductSet without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ); + client.innerApiCalls.createProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createProductSet with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateProductSetRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.createProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getProductSet', () => { + it('invokes getProductSet without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ); + client.innerApiCalls.getProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.getProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getProductSet without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ); + client.innerApiCalls.getProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getProductSet with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.getProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('updateProductSet', () => { + it('invokes updateProductSet without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ); + client.innerApiCalls.updateProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.updateProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes updateProductSet without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ); + client.innerApiCalls.updateProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.updateProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProductSet | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes updateProductSet with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.UpdateProductSetRequest() + ); + request.productSet = {}; + request.productSet.name = ''; + const expectedHeaderRequestParams = 'product_set.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updateProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.updateProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.updateProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteProductSet', () => { + it('invokes deleteProductSet without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProductSet = stubSimpleCall(expectedResponse); + const [response] = await client.deleteProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteProductSet without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteProductSet with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('createProduct', () => { + it('invokes createProduct without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ); + client.innerApiCalls.createProduct = stubSimpleCall(expectedResponse); + const [response] = await client.createProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createProduct without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ); + client.innerApiCalls.createProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createProduct with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateProductRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.createProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getProduct', () => { + it('invokes getProduct without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ); + client.innerApiCalls.getProduct = stubSimpleCall(expectedResponse); + const [response] = await client.getProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getProduct without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ); + client.innerApiCalls.getProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getProduct with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.getProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('updateProduct', () => { + it('invokes updateProduct without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ); + client.innerApiCalls.updateProduct = stubSimpleCall(expectedResponse); + const [response] = await client.updateProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes updateProduct without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ); + client.innerApiCalls.updateProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.updateProduct( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProduct | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes updateProduct with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.UpdateProductRequest() + ); + request.product = {}; + request.product.name = ''; + const expectedHeaderRequestParams = 'product.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updateProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.updateProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.updateProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteProduct', () => { + it('invokes deleteProduct without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProduct = stubSimpleCall(expectedResponse); + const [response] = await client.deleteProduct(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteProduct without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteProduct = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteProduct( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteProduct with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteProductRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteProduct = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteProduct(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteProduct as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('createReferenceImage', () => { + it('invokes createReferenceImage without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ); + client.innerApiCalls.createReferenceImage = stubSimpleCall( + expectedResponse + ); + const [response] = await client.createReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ); + client.innerApiCalls.createReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IReferenceImage | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createReferenceImage with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.CreateReferenceImageRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.createReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteReferenceImage', () => { + it('invokes deleteReferenceImage without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteReferenceImage = stubSimpleCall( + expectedResponse + ); + const [response] = await client.deleteReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteReferenceImage with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.DeleteReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.deleteReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getReferenceImage', () => { + it('invokes getReferenceImage without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ); + client.innerApiCalls.getReferenceImage = stubSimpleCall(expectedResponse); + const [response] = await client.getReferenceImage(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getReferenceImage without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ); + client.innerApiCalls.getReferenceImage = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getReferenceImage( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IReferenceImage | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getReferenceImage with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.GetReferenceImageRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getReferenceImage = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.getReferenceImage(request); + }, expectedError); + assert( + (client.innerApiCalls.getReferenceImage as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('addProductToProductSet', () => { + it('invokes addProductToProductSet without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.addProductToProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.addProductToProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes addProductToProductSet without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.addProductToProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.addProductToProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes addProductToProductSet with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.AddProductToProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.addProductToProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.addProductToProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.addProductToProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('removeProductFromProductSet', () => { + it('invokes removeProductFromProductSet without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.removeProductFromProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes removeProductFromProductSet without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.removeProductFromProductSet( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes removeProductFromProductSet with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.RemoveProductFromProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.removeProductFromProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.removeProductFromProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.removeProductFromProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('importProductSets', () => { + it('invokes importProductSets without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.importProductSets = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.importProductSets(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes importProductSets without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.importProductSets = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.importProductSets( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.vision.v1p4beta1.IImportProductSetsResponse, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes importProductSets with call error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.importProductSets = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.importProductSets(request); + }, expectedError); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes importProductSets with LRO error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ImportProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.importProductSets = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.importProductSets(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.importProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('purgeProducts', () => { + it('invokes purgeProducts without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.PurgeProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.purgeProducts = stubLongRunningCall( + expectedResponse + ); + const [operation] = await client.purgeProducts(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.purgeProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes purgeProducts without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.PurgeProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.purgeProducts = stubLongRunningCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.purgeProducts( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.protobuf.IEmpty, + protos.google.cloud.vision.v1p4beta1.IBatchOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.purgeProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes purgeProducts with call error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.PurgeProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.purgeProducts = stubLongRunningCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.purgeProducts(request); + }, expectedError); + assert( + (client.innerApiCalls.purgeProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes purgeProducts with LRO error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.PurgeProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.purgeProducts = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.purgeProducts(request); + assert.rejects(async () => { + await operation.promise(); + }, expectedError); + assert( + (client.innerApiCalls.purgeProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('listProductSets', () => { + it('invokes listProductSets without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + ]; + client.innerApiCalls.listProductSets = stubSimpleCall(expectedResponse); + const [response] = await client.listProductSets(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductSets without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + ]; + client.innerApiCalls.listProductSets = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProductSets( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProductSet[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProductSets with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProductSets = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProductSets(request); + }, expectedError); + assert( + (client.innerApiCalls.listProductSets as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductSetsStream without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + ]; + client.descriptors.page.listProductSets.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductSetsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p4beta1.ProductSet[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p4beta1.ProductSet) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProductSets.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductSets, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductSetsStream with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductSets.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductSetsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p4beta1.ProductSet[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p4beta1.ProductSet) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProductSets.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductSets, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductSets without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ProductSet() + ), + ]; + client.descriptors.page.listProductSets.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1p4beta1.IProductSet[] = []; + const iterable = client.listProductSetsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductSets with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductSetsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductSets.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductSetsAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1p4beta1.IProductSet[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductSets + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listProducts', () => { + it('invokes listProducts without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + ]; + client.innerApiCalls.listProducts = stubSimpleCall(expectedResponse); + const [response] = await client.listProducts(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProducts without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + ]; + client.innerApiCalls.listProducts = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProducts( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProduct[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProducts with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProducts = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProducts(request); + }, expectedError); + assert( + (client.innerApiCalls.listProducts as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsStream without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + ]; + client.descriptors.page.listProducts.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p4beta1.Product[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p4beta1.Product) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProducts.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProducts, request) + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductsStream with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProducts.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p4beta1.Product[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p4beta1.Product) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProducts.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProducts, request) + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProducts without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + ]; + client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1p4beta1.IProduct[] = []; + const iterable = client.listProductsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProducts with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductsAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1p4beta1.IProduct[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProducts + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listReferenceImages', () => { + it('invokes listReferenceImages without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + ]; + client.innerApiCalls.listReferenceImages = stubSimpleCall( + expectedResponse + ); + const [response] = await client.listReferenceImages(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listReferenceImages without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + ]; + client.innerApiCalls.listReferenceImages = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listReferenceImages( + request, + ( + err?: Error | null, + result?: + | protos.google.cloud.vision.v1p4beta1.IReferenceImage[] + | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listReferenceImages with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listReferenceImages = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listReferenceImages(request); + }, expectedError); + assert( + (client.innerApiCalls.listReferenceImages as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listReferenceImagesStream without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + ]; + client.descriptors.page.listReferenceImages.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listReferenceImagesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p4beta1.ReferenceImage[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p4beta1.ReferenceImage) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listReferenceImages.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listReferenceImages, request) + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listReferenceImagesStream with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listReferenceImages.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listReferenceImagesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p4beta1.ReferenceImage[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p4beta1.ReferenceImage) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listReferenceImages.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listReferenceImages, request) + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listReferenceImages without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ReferenceImage() + ), + ]; + client.descriptors.page.listReferenceImages.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1p4beta1.IReferenceImage[] = []; + const iterable = client.listReferenceImagesAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listReferenceImages with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListReferenceImagesRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listReferenceImages.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listReferenceImagesAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1p4beta1.IReferenceImage[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listReferenceImages + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('listProductsInProductSet', () => { + it('invokes listProductsInProductSet without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + ]; + client.innerApiCalls.listProductsInProductSet = stubSimpleCall( + expectedResponse + ); + const [response] = await client.listProductsInProductSet(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsInProductSet without error using callback', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + ]; + client.innerApiCalls.listProductsInProductSet = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listProductsInProductSet( + request, + ( + err?: Error | null, + result?: protos.google.cloud.vision.v1p4beta1.IProduct[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listProductsInProductSet with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listProductsInProductSet = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.listProductsInProductSet(request); + }, expectedError); + assert( + (client.innerApiCalls.listProductsInProductSet as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listProductsInProductSetStream without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + ]; + client.descriptors.page.listProductsInProductSet.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listProductsInProductSetStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p4beta1.Product[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p4beta1.Product) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductsInProductSet, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('invokes listProductsInProductSetStream with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductsInProductSet.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listProductsInProductSetStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.vision.v1p4beta1.Product[] = []; + stream.on( + 'data', + (response: protos.google.cloud.vision.v1p4beta1.Product) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listProductsInProductSet, request) + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductsInProductSet without error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.Product() + ), + ]; + client.descriptors.page.listProductsInProductSet.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.vision.v1p4beta1.IProduct[] = []; + const iterable = client.listProductsInProductSetAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listProductsInProductSet with error', async () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.vision.v1p4beta1.ListProductsInProductSetRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedError = new Error('expected'); + client.descriptors.page.listProductsInProductSet.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listProductsInProductSetAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.vision.v1p4beta1.IProduct[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listProductsInProductSet + .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ + 'x-goog-request-params' + ], + expectedHeaderRequestParams + ); + }); + }); + + describe('Path templates', () => { + describe('location', () => { + const fakePath = '/rendered/path/location'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + }; + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.locationPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.locationPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('locationPath', () => { + const result = client.locationPath('projectValue', 'locationValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.locationPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromLocationName', () => { + const result = client.matchProjectFromLocationName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.locationPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromLocationName', () => { + const result = client.matchLocationFromLocationName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.locationPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('product', () => { + const fakePath = '/rendered/path/product'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + }; + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productPath', () => { + const result = client.productPath( + 'projectValue', + 'locationValue', + 'productValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductName', () => { + const result = client.matchProjectFromProductName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductName', () => { + const result = client.matchLocationFromProductName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromProductName', () => { + const result = client.matchProductFromProductName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.productPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('productSet', () => { + const fakePath = '/rendered/path/productSet'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product_set: 'productSetValue', + }; + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.productSetPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.productSetPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('productSetPath', () => { + const result = client.productSetPath( + 'projectValue', + 'locationValue', + 'productSetValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.productSetPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProductSetName', () => { + const result = client.matchProjectFromProductSetName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromProductSetName', () => { + const result = client.matchLocationFromProductSetName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductSetFromProductSetName', () => { + const result = client.matchProductSetFromProductSetName(fakePath); + assert.strictEqual(result, 'productSetValue'); + assert( + (client.pathTemplates.productSetPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('referenceImage', () => { + const fakePath = '/rendered/path/referenceImage'; + const expectedParameters = { + project: 'projectValue', + location: 'locationValue', + product: 'productValue', + reference_image: 'referenceImageValue', + }; + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.referenceImagePathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.referenceImagePathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('referenceImagePath', () => { + const result = client.referenceImagePath( + 'projectValue', + 'locationValue', + 'productValue', + 'referenceImageValue' + ); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.referenceImagePathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromReferenceImageName', () => { + const result = client.matchProjectFromReferenceImageName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchLocationFromReferenceImageName', () => { + const result = client.matchLocationFromReferenceImageName(fakePath); + assert.strictEqual(result, 'locationValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchProductFromReferenceImageName', () => { + const result = client.matchProductFromReferenceImageName(fakePath); + assert.strictEqual(result, 'productValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchReferenceImageFromReferenceImageName', () => { + const result = client.matchReferenceImageFromReferenceImageName( + fakePath + ); + assert.strictEqual(result, 'referenceImageValue'); + assert( + (client.pathTemplates.referenceImagePathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +}); diff --git a/packages/google-cloud-vision/test/helpers.test.ts b/packages/google-cloud-vision/test/helpers.test.ts index ef806b5239e..e32e76e571c 100644 --- a/packages/google-cloud-vision/test/helpers.test.ts +++ b/packages/google-cloud-vision/test/helpers.test.ts @@ -20,6 +20,7 @@ import * as is from 'is'; import * as sinon from 'sinon'; import * as prototypes from '../protos/protos'; import * as assert from 'assert'; +// eslint-disable-next-line @typescript-eslint/no-var-requires const vision = require('../src'); describe('Vision helper methods', () => { diff --git a/packages/google-cloud-vision/test/index.test.ts b/packages/google-cloud-vision/test/index.test.ts index cedd41e4f6b..ec8dc564016 100644 --- a/packages/google-cloud-vision/test/index.test.ts +++ b/packages/google-cloud-vision/test/index.test.ts @@ -14,7 +14,7 @@ import * as assert from 'assert'; import {describe, it} from 'mocha'; - +// eslint-disable-next-line @typescript-eslint/no-var-requires const vision = require('../src'); describe('Vision', () => { diff --git a/packages/google-cloud-vision/webpack.config.js b/packages/google-cloud-vision/webpack.config.js index 4d93660dc26..ed13edf1f2d 100644 --- a/packages/google-cloud-vision/webpack.config.js +++ b/packages/google-cloud-vision/webpack.config.js @@ -36,27 +36,27 @@ module.exports = { { test: /\.tsx?$/, use: 'ts-loader', - exclude: /node_modules/ + exclude: /node_modules/, }, { test: /node_modules[\\/]@grpc[\\/]grpc-js/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]grpc/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]retry-request/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]https?-proxy-agent/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]gtoken/, - use: 'null-loader' + use: 'null-loader', }, ], },