1 4
// Copyright 2020 Google LLC
2 4
//
3 4
// Licensed under the Apache License, Version 2.0 (the "License");
4 4
// you may not use this file except in compliance with the License.
5 4
// You may obtain a copy of the License at
6 4
//
7 4
//     https://www.apache.org/licenses/LICENSE-2.0
8 4
//
9 4
// Unless required by applicable law or agreed to in writing, software
10 4
// distributed under the License is distributed on an "AS IS" BASIS,
11 4
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 4
// See the License for the specific language governing permissions and
13 4
// limitations under the License.
14 4
//
15 4
// ** This file is automatically generated by gapic-generator-typescript. **
16 4
// ** https://github.com/googleapis/gapic-generator-typescript **
17 4
// ** All changes to this file may be overwritten. **
18 4

19 4
import * as gax from 'google-gax';
20 4
import {
21 4
  Callback,
22 4
  CallOptions,
23 4
  Descriptors,
24 4
  ClientOptions,
25 4
  LROperation,
26 4
} from 'google-gax';
27 4
import * as path from 'path';
28 4

29 4
import * as protos from '../../protos/protos';
30 4
import * as gapicConfig from './image_annotator_client_config.json';
31 4
import {operationsProtos} from 'google-gax';
32 4
const version = require('../../../package.json').version;
33 4

34 4
/**
35 4
 *  Service that performs Google Cloud Vision API detection tasks over client
36 4
 *  images, such as face, landmark, logo, label, and text detection. The
37 4
 *  ImageAnnotator service returns detected entities from the images.
38 4
 * @class
39 4
 * @memberof v1
40 4
 */
41 4
export class ImageAnnotatorClient {
42 4
  private _terminated = false;
43 4
  private _opts: ClientOptions;
44 4
  private _gaxModule: typeof gax | typeof gax.fallback;
45 4
  private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient;
46 4
  private _protos: {};
47 4
  private _defaults: {[method: string]: gax.CallSettings};
48 4
  auth: gax.GoogleAuth;
49 4
  descriptors: Descriptors = {
50 4
    page: {},
51 4
    stream: {},
52 4
    longrunning: {},
53 4
    batching: {},
54 4
  };
55 4
  innerApiCalls: {[name: string]: Function};
56 4
  pathTemplates: {[name: string]: gax.PathTemplate};
57 4
  operationsClient: gax.OperationsClient;
58 4
  imageAnnotatorStub?: Promise<{[name: string]: Function}>;
59 4

60 4
  /**
61 4
   * Construct an instance of ImageAnnotatorClient.
62 4
   *
63 4
   * @param {object} [options] - The configuration object. See the subsequent
64 4
   *   parameters for more details.
65 4
   * @param {object} [options.credentials] - Credentials object.
66 4
   * @param {string} [options.credentials.client_email]
67 4
   * @param {string} [options.credentials.private_key]
68 4
   * @param {string} [options.email] - Account email address. Required when
69 4
   *     using a .pem or .p12 keyFilename.
70 4
   * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
71 4
   *     .p12 key downloaded from the Google Developers Console. If you provide
72 4
   *     a path to a JSON file, the projectId option below is not necessary.
73 4
   *     NOTE: .pem and .p12 require you to specify options.email as well.
74 4
   * @param {number} [options.port] - The port on which to connect to
75 4
   *     the remote host.
76 4
   * @param {string} [options.projectId] - The project ID from the Google
77 4
   *     Developer's Console, e.g. 'grape-spaceship-123'. We will also check
78 4
   *     the environment variable GCLOUD_PROJECT for your project ID. If your
79 4
   *     app is running in an environment which supports
80 4
   *     {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
81 4
   *     your project ID will be detected automatically.
82 4
   * @param {string} [options.apiEndpoint] - The domain name of the
83 4
   *     API remote host.
84 4
   */
85 4

86 4
  constructor(opts?: ClientOptions) {
87 4
    // Ensure that options include the service address and port.
88 4
    const staticMembers = this.constructor as typeof ImageAnnotatorClient;
89 4
    const servicePath =
90 4
      opts && opts.servicePath
91 4
        ? opts.servicePath
92 4
        : opts && opts.apiEndpoint
93 4
        ? opts.apiEndpoint
94 4
        : staticMembers.servicePath;
95 4
    const port = opts && opts.port ? opts.port : staticMembers.port;
96 4

97 4
    if (!opts) {
98 4
      opts = {servicePath, port};
99 4
    }
100 4
    opts.servicePath = opts.servicePath || servicePath;
101 4
    opts.port = opts.port || port;
102 4

103 4
    // users can override the config from client side, like retry codes name.
104 4
    // The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546
105 4
    // The way to override client config for Showcase API:
106 4
    //
107 4
    // const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}}
108 4
    // const showcaseClient = new showcaseClient({ projectId, customConfig });
109 4
    opts.clientConfig = opts.clientConfig || {};
110 4

111 4
    // If we're running in browser, it's OK to omit `fallback` since
112 4
    // google-gax has `browser` field in its `package.json`.
113 4
    // For Electron (which does not respect `browser` field),
114 4
    // pass `{fallback: true}` to the ImageAnnotatorClient constructor.
115 4
    this._gaxModule = opts.fallback ? gax.fallback : gax;
116 4

117 4
    // Create a `gaxGrpc` object, with any grpc-specific options
118 4
    // sent to the client.
119 4
    opts.scopes = (this.constructor as typeof ImageAnnotatorClient).scopes;
120 4
    this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
121 4

122 4
    // Save options to use in initialize() method.
123 4
    this._opts = opts;
124 4

125 4
    // Save the auth object to the client, for use by other methods.
126 4
    this.auth = this._gaxGrpc.auth as gax.GoogleAuth;
127 4

128 4
    // Determine the client header string.
129 4
    const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
130 4
    if (typeof process !== 'undefined' && 'versions' in process) {
131 4
      clientHeader.push(`gl-node/${process.versions.node}`);
132 4
    } else {
133 0
      clientHeader.push(`gl-web/${this._gaxModule.version}`);
134 0
    }
135 4
    if (!opts.fallback) {
136 4
      clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
137 4
    }
138 4
    if (opts.libName && opts.libVersion) {
139 0
      clientHeader.push(`${opts.libName}/${opts.libVersion}`);
140 0
    }
141 4
    // Load the applicable protos.
142 4
    // For Node.js, pass the path to JSON proto file.
143 4
    // For browsers, pass the JSON content.
144 4

145 4
    const nodejsProtoPath = path.join(
146 4
      __dirname,
147 4
      '..',
148 4
      '..',
149 4
      'protos',
150 4
      'protos.json'
151 4
    );
152 4
    this._protos = this._gaxGrpc.loadProto(
153 4
      opts.fallback
154 4
        ? // eslint-disable-next-line @typescript-eslint/no-var-requires
155 4
          require('../../protos/protos.json')
156 4
        : nodejsProtoPath
157 4
    );
158 4

159 4
    // This API contains "path templates"; forward-slash-separated
160 4
    // identifiers to uniquely identify resources within the API.
161 4
    // Create useful helper objects for these.
162 4
    this.pathTemplates = {
163 4
      productPathTemplate: new this._gaxModule.PathTemplate(
164 4
        'projects/{project}/locations/{location}/products/{product}'
165 4
      ),
166 4
      productSetPathTemplate: new this._gaxModule.PathTemplate(
167 4
        'projects/{project}/locations/{location}/productSets/{product_set}'
168 4
      ),
169 4
      referenceImagePathTemplate: new this._gaxModule.PathTemplate(
170 4
        'projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}'
171 4
      ),
172 4
    };
173 4

174 4
    // This API contains "long-running operations", which return a
175 4
    // an Operation object that allows for tracking of the operation,
176 4
    // rather than holding a request open.
177 4
    const protoFilesRoot = opts.fallback
178 4
      ? this._gaxModule.protobuf.Root.fromJSON(
179 4
          // eslint-disable-next-line @typescript-eslint/no-var-requires
180 4
          require('../../protos/protos.json')
181 4
        )
182 4
      : this._gaxModule.protobuf.loadSync(nodejsProtoPath);
183 4

184 4
    this.operationsClient = this._gaxModule
185 4
      .lro({
186 4
        auth: this.auth,
187 4
        grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
188 4
      })
189 4
      .operationsClient(opts);
190 4
    const asyncBatchAnnotateImagesResponse = protoFilesRoot.lookup(
191 4
      '.google.cloud.vision.v1.AsyncBatchAnnotateImagesResponse'
192 4
    ) as gax.protobuf.Type;
193 4
    const asyncBatchAnnotateImagesMetadata = protoFilesRoot.lookup(
194 4
      '.google.cloud.vision.v1.OperationMetadata'
195 4
    ) as gax.protobuf.Type;
196 4
    const asyncBatchAnnotateFilesResponse = protoFilesRoot.lookup(
197 4
      '.google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse'
198 4
    ) as gax.protobuf.Type;
199 4
    const asyncBatchAnnotateFilesMetadata = protoFilesRoot.lookup(
200 4
      '.google.cloud.vision.v1.OperationMetadata'
201 4
    ) as gax.protobuf.Type;
202 4

203 4
    this.descriptors.longrunning = {
204 4
      asyncBatchAnnotateImages: new this._gaxModule.LongrunningDescriptor(
205 4
        this.operationsClient,
206 4
        asyncBatchAnnotateImagesResponse.decode.bind(
207 4
          asyncBatchAnnotateImagesResponse
208 4
        ),
209 4
        asyncBatchAnnotateImagesMetadata.decode.bind(
210 4
          asyncBatchAnnotateImagesMetadata
211 4
        )
212 4
      ),
213 4
      asyncBatchAnnotateFiles: new this._gaxModule.LongrunningDescriptor(
214 4
        this.operationsClient,
215 4
        asyncBatchAnnotateFilesResponse.decode.bind(
216 4
          asyncBatchAnnotateFilesResponse
217 4
        ),
218 4
        asyncBatchAnnotateFilesMetadata.decode.bind(
219 4
          asyncBatchAnnotateFilesMetadata
220 4
        )
221 4
      ),
222 4
    };
223 4

224 4
    // Put together the default options sent with requests.
225 4
    this._defaults = this._gaxGrpc.constructSettings(
226 4
      'google.cloud.vision.v1.ImageAnnotator',
227 4
      gapicConfig as gax.ClientConfig,
228 4
      opts.clientConfig || {},
229 4
      {'x-goog-api-client': clientHeader.join(' ')}
230 4
    );
231 4

232 4
    // Set up a dictionary of "inner API calls"; the core implementation
233 4
    // of calling the API is handled in `google-gax`, with this code
234 4
    // merely providing the destination and request information.
235 4
    this.innerApiCalls = {};
236 4
  }
237 4

238 4
  /**
239 4
   * Initialize the client.
240 4
   * Performs asynchronous operations (such as authentication) and prepares the client.
241 4
   * This function will be called automatically when any class method is called for the
242 4
   * first time, but if you need to initialize it before calling an actual method,
243 4
   * feel free to call initialize() directly.
244 4
   *
245 4
   * You can await on this method if you want to make sure the client is initialized.
246 4
   *
247 4
   * @returns {Promise} A promise that resolves to an authenticated service stub.
248 4
   */
249 4
  initialize() {
250 4
    // If the client stub promise is already initialized, return immediately.
251 4
    if (this.imageAnnotatorStub) {
252 4
      return this.imageAnnotatorStub;
253 4
    }
254 4

255 4
    // Put together the "service stub" for
256 4
    // google.cloud.vision.v1.ImageAnnotator.
257 4
    this.imageAnnotatorStub = this._gaxGrpc.createStub(
258 4
      this._opts.fallback
259 4
        ? (this._protos as protobuf.Root).lookupService(
260 0
            'google.cloud.vision.v1.ImageAnnotator'
261 4
          )
262 4
        : // eslint-disable-next-line @typescript-eslint/no-explicit-any
263 4
          (this._protos as any).google.cloud.vision.v1.ImageAnnotator,
264 4
      this._opts
265 4
    ) as Promise<{[method: string]: Function}>;
266 4

267 4
    // Iterate over each of the methods that the service provides
268 4
    // and create an API call method for each.
269 4
    const imageAnnotatorStubMethods = [
270 4
      'batchAnnotateImages',
271 4
      'batchAnnotateFiles',
272 4
      'asyncBatchAnnotateImages',
273 4
      'asyncBatchAnnotateFiles',
274 4
    ];
275 4
    for (const methodName of imageAnnotatorStubMethods) {
276 4
      const callPromise = this.imageAnnotatorStub.then(
277 4
        stub => (...args: Array<{}>) => {
278 0
          if (this._terminated) {
279 0
            return Promise.reject('The client has already been closed.');
280 0
          }
281 0
          const func = stub[methodName];
282 0
          return func.apply(stub, args);
283 4
        },
284 4
        (err: Error | null | undefined) => () => {
285 1
          throw err;
286 1
        }
287 4
      );
288 4

289 4
      const descriptor = this.descriptors.longrunning[methodName] || undefined;
290 4
      const apiCall = this._gaxModule.createApiCall(
291 4
        callPromise,
292 4
        this._defaults[methodName],
293 4
        descriptor
294 4
      );
295 4

296 4
      this.innerApiCalls[methodName] = apiCall;
297 4
    }
298 4

299 4
    return this.imageAnnotatorStub;
300 4
  }
301 4

302 4
  /**
303 4
   * The DNS address for this API service.
304 4
   */
305 4
  static get servicePath() {
306 4
    return 'vision.googleapis.com';
307 4
  }
308 4

309 4
  /**
310 4
   * The DNS address for this API service - same as servicePath(),
311 4
   * exists for compatibility reasons.
312 4
   */
313 4
  static get apiEndpoint() {
314 4
    return 'vision.googleapis.com';
315 4
  }
316 4

317 4
  /**
318 4
   * The port for this API service.
319 4
   */
320 4
  static get port() {
321 4
    return 443;
322 4
  }
323 4

324 4
  /**
325 4
   * The scopes needed to make gRPC calls for every method defined
326 4
   * in this service.
327 4
   */
328 4
  static get scopes() {
329 4
    return [
330 4
      'https://www.googleapis.com/auth/cloud-platform',
331 4
      'https://www.googleapis.com/auth/cloud-vision',
332 4
    ];
333 4
  }
334 4

335 4
  getProjectId(): Promise<string>;
336 4
  getProjectId(callback: Callback<string, undefined, undefined>): void;
337 4
  /**
338 4
   * Return the project ID used by this class.
339 4
   * @param {function(Error, string)} callback - the callback to
340 4
   *   be called with the current project Id.
341 4
   */
342 4
  getProjectId(
343 4
    callback?: Callback<string, undefined, undefined>
344 4
  ): Promise<string> | void {
345 4
    if (callback) {
346 4
      this.auth.getProjectId(callback);
347 4
      return;
348 4
    }
349 4
    return this.auth.getProjectId();
350 4
  }
351 4

352 4
  // -------------------
353 4
  // -- Service calls --
354 4
  // -------------------
355 4
  batchAnnotateImages(
356 4
    request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
357 4
    options?: gax.CallOptions
358 4
  ): Promise<
359 4
    [
360 4
      protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
361 4
      protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest | undefined,
362 4
      {} | undefined
363 4
    ]
364 4
  >;
365 4
  batchAnnotateImages(
366 4
    request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
367 4
    options: gax.CallOptions,
368 4
    callback: Callback<
369 4
      protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
370 4
      | protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest
371 4
      | null
372 4
      | undefined,
373 4
      {} | null | undefined
374 4
    >
375 4
  ): void;
376 4
  batchAnnotateImages(
377 4
    request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
378 4
    callback: Callback<
379 4
      protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
380 4
      | protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest
381 4
      | null
382 4
      | undefined,
383 4
      {} | null | undefined
384 4
    >
385 4
  ): void;
386 4
  /**
387 4
   * Run image detection and annotation for a batch of images.
388 4
   *
389 4
   * @param {Object} request
390 4
   *   The request object that will be sent.
391 4
   * @param {number[]} request.requests
392 4
   *   Required. Individual image annotation requests for this batch.
393 4
   * @param {string} request.parent
394 4
   *   Optional. Target project and location to make a call.
395 4
   *
396 4
   *   Format: `projects/{project-id}/locations/{location-id}`.
397 4
   *
398 4
   *   If no parent is specified, a region will be chosen automatically.
399 4
   *
400 4
   *   Supported location-ids:
401 4
   *       `us`: USA country only,
402 4
   *       `asia`: East asia areas, like Japan, Taiwan,
403 4
   *       `eu`: The European Union.
404 4
   *
405 4
   *   Example: `projects/project-A/locations/eu`.
406 4
   * @param {object} [options]
407 4
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
408 4
   * @returns {Promise} - The promise which resolves to an array.
409 4
   *   The first element of the array is an object representing [BatchAnnotateImagesResponse]{@link google.cloud.vision.v1.BatchAnnotateImagesResponse}.
410 4
   *   The promise has a method named "cancel" which cancels the ongoing API call.
411 4
   */
412 4
  batchAnnotateImages(
413 4
    request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
414 4
    optionsOrCallback?:
415 4
      | gax.CallOptions
416 4
      | Callback<
417 4
          protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
418 4
          | protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest
419 4
          | null
420 4
          | undefined,
421 4
          {} | null | undefined
422 4
        >,
423 4
    callback?: Callback<
424 4
      protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
425 4
      | protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest
426 4
      | null
427 4
      | undefined,
428 4
      {} | null | undefined
429 4
    >
430 4
  ): Promise<
431 4
    [
432 4
      protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
433 4
      protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest | undefined,
434 4
      {} | undefined
435 4
    ]
436 4
  > | void {
437 4
    request = request || {};
438 4
    let options: gax.CallOptions;
439 4
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
440 4
      callback = optionsOrCallback;
441 4
      options = {};
442 4
    } else {
443 4
      options = optionsOrCallback as gax.CallOptions;
444 4
    }
445 4
    options = options || {};
446 4
    options.otherArgs = options.otherArgs || {};
447 4
    options.otherArgs.headers = options.otherArgs.headers || {};
448 4
    options.otherArgs.headers[
449 4
      'x-goog-request-params'
450 4
    ] = gax.routingHeader.fromParams({
451 4
      parent: request.parent || '',
452 4
    });
453 4
    this.initialize();
454 4
    return this.innerApiCalls.batchAnnotateImages(request, options, callback);
455 4
  }
456 4
  batchAnnotateFiles(
457 4
    request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest,
458 4
    options?: gax.CallOptions
459 4
  ): Promise<
460 4
    [
461 4
      protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
462 4
      protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest | undefined,
463 4
      {} | undefined
464 4
    ]
465 4
  >;
466 4
  batchAnnotateFiles(
467 4
    request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest,
468 4
    options: gax.CallOptions,
469 4
    callback: Callback<
470 4
      protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
471 4
      | protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest
472 4
      | null
473 4
      | undefined,
474 4
      {} | null | undefined
475 4
    >
476 4
  ): void;
477 4
  batchAnnotateFiles(
478 4
    request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest,
479 4
    callback: Callback<
480 4
      protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
481 4
      | protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest
482 4
      | null
483 4
      | undefined,
484 4
      {} | null | undefined
485 4
    >
486 4
  ): void;
487 4
  /**
488 4
   * Service that performs image detection and annotation for a batch of files.
489 4
   * Now only "application/pdf", "image/tiff" and "image/gif" are supported.
490 4
   *
491 4
   * This service will extract at most 5 (customers can specify which 5 in
492 4
   * AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each
493 4
   * file provided and perform detection and annotation for each image
494 4
   * extracted.
495 4
   *
496 4
   * @param {Object} request
497 4
   *   The request object that will be sent.
498 4
   * @param {number[]} request.requests
499 4
   *   Required. The list of file annotation requests. Right now we support only one
500 4
   *   AnnotateFileRequest in BatchAnnotateFilesRequest.
501 4
   * @param {string} request.parent
502 4
   *   Optional. Target project and location to make a call.
503 4
   *
504 4
   *   Format: `projects/{project-id}/locations/{location-id}`.
505 4
   *
506 4
   *   If no parent is specified, a region will be chosen automatically.
507 4
   *
508 4
   *   Supported location-ids:
509 4
   *       `us`: USA country only,
510 4
   *       `asia`: East asia areas, like Japan, Taiwan,
511 4
   *       `eu`: The European Union.
512 4
   *
513 4
   *   Example: `projects/project-A/locations/eu`.
514 4
   * @param {object} [options]
515 4
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
516 4
   * @returns {Promise} - The promise which resolves to an array.
517 4
   *   The first element of the array is an object representing [BatchAnnotateFilesResponse]{@link google.cloud.vision.v1.BatchAnnotateFilesResponse}.
518 4
   *   The promise has a method named "cancel" which cancels the ongoing API call.
519 4
   */
520 4
  batchAnnotateFiles(
521 4
    request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest,
522 4
    optionsOrCallback?:
523 4
      | gax.CallOptions
524 4
      | Callback<
525 4
          protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
526 4
          | protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest
527 4
          | null
528 4
          | undefined,
529 4
          {} | null | undefined
530 4
        >,
531 4
    callback?: Callback<
532 4
      protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
533 4
      | protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest
534 4
      | null
535 4
      | undefined,
536 4
      {} | null | undefined
537 4
    >
538 4
  ): Promise<
539 4
    [
540 4
      protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
541 4
      protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest | undefined,
542 4
      {} | undefined
543 4
    ]
544 4
  > | void {
545 4
    request = request || {};
546 4
    let options: gax.CallOptions;
547 4
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
548 4
      callback = optionsOrCallback;
549 4
      options = {};
550 4
    } else {
551 4
      options = optionsOrCallback as gax.CallOptions;
552 4
    }
553 4
    options = options || {};
554 4
    options.otherArgs = options.otherArgs || {};
555 4
    options.otherArgs.headers = options.otherArgs.headers || {};
556 4
    options.otherArgs.headers[
557 4
      'x-goog-request-params'
558 4
    ] = gax.routingHeader.fromParams({
559 4
      parent: request.parent || '',
560 4
    });
561 4
    this.initialize();
562 4
    return this.innerApiCalls.batchAnnotateFiles(request, options, callback);
563 4
  }
564 4

565 4
  asyncBatchAnnotateImages(
566 4
    request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest,
567 4
    options?: gax.CallOptions
568 4
  ): Promise<
569 4
    [
570 4
      LROperation<
571 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse,
572 4
        protos.google.cloud.vision.v1.IOperationMetadata
573 4
      >,
574 4
      protos.google.longrunning.IOperation | undefined,
575 4
      {} | undefined
576 4
    ]
577 4
  >;
578 4
  asyncBatchAnnotateImages(
579 4
    request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest,
580 4
    options: gax.CallOptions,
581 4
    callback: Callback<
582 4
      LROperation<
583 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse,
584 4
        protos.google.cloud.vision.v1.IOperationMetadata
585 4
      >,
586 4
      protos.google.longrunning.IOperation | null | undefined,
587 4
      {} | null | undefined
588 4
    >
589 4
  ): void;
590 4
  asyncBatchAnnotateImages(
591 4
    request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest,
592 4
    callback: Callback<
593 4
      LROperation<
594 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse,
595 4
        protos.google.cloud.vision.v1.IOperationMetadata
596 4
      >,
597 4
      protos.google.longrunning.IOperation | null | undefined,
598 4
      {} | null | undefined
599 4
    >
600 4
  ): void;
601 4
  /**
602 4
   * Run asynchronous image detection and annotation for a list of images.
603 4
   *
604 4
   * Progress and results can be retrieved through the
605 4
   * `google.longrunning.Operations` interface.
606 4
   * `Operation.metadata` contains `OperationMetadata` (metadata).
607 4
   * `Operation.response` contains `AsyncBatchAnnotateImagesResponse` (results).
608 4
   *
609 4
   * This service will write image annotation outputs to json files in customer
610 4
   * GCS bucket, each json file containing BatchAnnotateImagesResponse proto.
611 4
   *
612 4
   * @param {Object} request
613 4
   *   The request object that will be sent.
614 4
   * @param {number[]} request.requests
615 4
   *   Required. Individual image annotation requests for this batch.
616 4
   * @param {google.cloud.vision.v1.OutputConfig} request.outputConfig
617 4
   *   Required. The desired output location and metadata (e.g. format).
618 4
   * @param {string} request.parent
619 4
   *   Optional. Target project and location to make a call.
620 4
   *
621 4
   *   Format: `projects/{project-id}/locations/{location-id}`.
622 4
   *
623 4
   *   If no parent is specified, a region will be chosen automatically.
624 4
   *
625 4
   *   Supported location-ids:
626 4
   *       `us`: USA country only,
627 4
   *       `asia`: East asia areas, like Japan, Taiwan,
628 4
   *       `eu`: The European Union.
629 4
   *
630 4
   *   Example: `projects/project-A/locations/eu`.
631 4
   * @param {object} [options]
632 4
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
633 4
   * @returns {Promise} - The promise which resolves to an array.
634 4
   *   The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}.
635 4
   *   The promise has a method named "cancel" which cancels the ongoing API call.
636 4
   */
637 4
  asyncBatchAnnotateImages(
638 4
    request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest,
639 4
    optionsOrCallback?:
640 4
      | gax.CallOptions
641 4
      | Callback<
642 4
          LROperation<
643 4
            protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse,
644 4
            protos.google.cloud.vision.v1.IOperationMetadata
645 4
          >,
646 4
          protos.google.longrunning.IOperation | null | undefined,
647 4
          {} | null | undefined
648 4
        >,
649 4
    callback?: Callback<
650 4
      LROperation<
651 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse,
652 4
        protos.google.cloud.vision.v1.IOperationMetadata
653 4
      >,
654 4
      protos.google.longrunning.IOperation | null | undefined,
655 4
      {} | null | undefined
656 4
    >
657 4
  ): Promise<
658 4
    [
659 4
      LROperation<
660 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse,
661 4
        protos.google.cloud.vision.v1.IOperationMetadata
662 4
      >,
663 4
      protos.google.longrunning.IOperation | undefined,
664 4
      {} | undefined
665 4
    ]
666 4
  > | void {
667 4
    request = request || {};
668 4
    let options: gax.CallOptions;
669 4
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
670 4
      callback = optionsOrCallback;
671 4
      options = {};
672 4
    } else {
673 4
      options = optionsOrCallback as gax.CallOptions;
674 4
    }
675 4
    options = options || {};
676 4
    options.otherArgs = options.otherArgs || {};
677 4
    options.otherArgs.headers = options.otherArgs.headers || {};
678 4
    options.otherArgs.headers[
679 4
      'x-goog-request-params'
680 4
    ] = gax.routingHeader.fromParams({
681 4
      parent: request.parent || '',
682 4
    });
683 4
    this.initialize();
684 4
    return this.innerApiCalls.asyncBatchAnnotateImages(
685 4
      request,
686 4
      options,
687 4
      callback
688 4
    );
689 4
  }
690 4
  /**
691 4
   * Check the status of the long running operation returned by the asyncBatchAnnotateImages() method.
692 4
   * @param {String} name
693 4
   *   The operation name that will be passed.
694 4
   * @returns {Promise} - The promise which resolves to an object.
695 4
   *   The decoded operation object has result and metadata field to get information from.
696 4
   *
697 4
   * @example:
698 4
   *   const decodedOperation = await checkAsyncBatchAnnotateImagesProgress(name);
699 4
   *   console.log(decodedOperation.result);
700 4
   *   console.log(decodedOperation.done);
701 4
   *   console.log(decodedOperation.metadata);
702 4
   *
703 4
   */
704 4
  async checkAsyncBatchAnnotateImagesProgress(
705 4
    name: string
706 4
  ): Promise<
707 4
    LROperation<
708 4
      protos.google.cloud.vision.v1.AsyncBatchAnnotateImagesResponse,
709 4
      protos.google.cloud.vision.v1.OperationMetadata
710 4
    >
711 4
  > {
712 4
    const request = new operationsProtos.google.longrunning.GetOperationRequest(
713 4
      {name}
714 4
    );
715 4
    const [operation] = await this.operationsClient.getOperation(request);
716 4
    const decodeOperation = new gax.Operation(
717 4
      operation,
718 4
      this.descriptors.longrunning.asyncBatchAnnotateImages,
719 4
      gax.createDefaultBackoffSettings()
720 4
    );
721 4
    return decodeOperation as LROperation<
722 4
      protos.google.cloud.vision.v1.AsyncBatchAnnotateImagesResponse,
723 4
      protos.google.cloud.vision.v1.OperationMetadata
724 4
    >;
725 1
  }
726 4
  asyncBatchAnnotateFiles(
727 4
    request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest,
728 4
    options?: gax.CallOptions
729 4
  ): Promise<
730 4
    [
731 4
      LROperation<
732 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse,
733 4
        protos.google.cloud.vision.v1.IOperationMetadata
734 4
      >,
735 4
      protos.google.longrunning.IOperation | undefined,
736 4
      {} | undefined
737 4
    ]
738 4
  >;
739 4
  asyncBatchAnnotateFiles(
740 4
    request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest,
741 4
    options: gax.CallOptions,
742 4
    callback: Callback<
743 4
      LROperation<
744 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse,
745 4
        protos.google.cloud.vision.v1.IOperationMetadata
746 4
      >,
747 4
      protos.google.longrunning.IOperation | null | undefined,
748 4
      {} | null | undefined
749 4
    >
750 4
  ): void;
751 4
  asyncBatchAnnotateFiles(
752 4
    request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest,
753 4
    callback: Callback<
754 4
      LROperation<
755 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse,
756 4
        protos.google.cloud.vision.v1.IOperationMetadata
757 4
      >,
758 4
      protos.google.longrunning.IOperation | null | undefined,
759 4
      {} | null | undefined
760 4
    >
761 4
  ): void;
762 4
  /**
763 4
   * Run asynchronous image detection and annotation for a list of generic
764 4
   * files, such as PDF files, which may contain multiple pages and multiple
765 4
   * images per page. Progress and results can be retrieved through the
766 4
   * `google.longrunning.Operations` interface.
767 4
   * `Operation.metadata` contains `OperationMetadata` (metadata).
768 4
   * `Operation.response` contains `AsyncBatchAnnotateFilesResponse` (results).
769 4
   *
770 4
   * @param {Object} request
771 4
   *   The request object that will be sent.
772 4
   * @param {number[]} request.requests
773 4
   *   Required. Individual async file annotation requests for this batch.
774 4
   * @param {string} request.parent
775 4
   *   Optional. Target project and location to make a call.
776 4
   *
777 4
   *   Format: `projects/{project-id}/locations/{location-id}`.
778 4
   *
779 4
   *   If no parent is specified, a region will be chosen automatically.
780 4
   *
781 4
   *   Supported location-ids:
782 4
   *       `us`: USA country only,
783 4
   *       `asia`: East asia areas, like Japan, Taiwan,
784 4
   *       `eu`: The European Union.
785 4
   *
786 4
   *   Example: `projects/project-A/locations/eu`.
787 4
   * @param {object} [options]
788 4
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
789 4
   * @returns {Promise} - The promise which resolves to an array.
790 4
   *   The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}.
791 4
   *   The promise has a method named "cancel" which cancels the ongoing API call.
792 4
   */
793 4
  asyncBatchAnnotateFiles(
794 4
    request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest,
795 4
    optionsOrCallback?:
796 4
      | gax.CallOptions
797 4
      | Callback<
798 4
          LROperation<
799 4
            protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse,
800 4
            protos.google.cloud.vision.v1.IOperationMetadata
801 4
          >,
802 4
          protos.google.longrunning.IOperation | null | undefined,
803 4
          {} | null | undefined
804 4
        >,
805 4
    callback?: Callback<
806 4
      LROperation<
807 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse,
808 4
        protos.google.cloud.vision.v1.IOperationMetadata
809 4
      >,
810 4
      protos.google.longrunning.IOperation | null | undefined,
811 4
      {} | null | undefined
812 4
    >
813 4
  ): Promise<
814 4
    [
815 4
      LROperation<
816 4
        protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse,
817 4
        protos.google.cloud.vision.v1.IOperationMetadata
818 4
      >,
819 4
      protos.google.longrunning.IOperation | undefined,
820 4
      {} | undefined
821 4
    ]
822 4
  > | void {
823 4
    request = request || {};
824 4
    let options: gax.CallOptions;
825 4
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
826 4
      callback = optionsOrCallback;
827 4
      options = {};
828 4
    } else {
829 4
      options = optionsOrCallback as gax.CallOptions;
830 4
    }
831 4
    options = options || {};
832 4
    options.otherArgs = options.otherArgs || {};
833 4
    options.otherArgs.headers = options.otherArgs.headers || {};
834 4
    options.otherArgs.headers[
835 4
      'x-goog-request-params'
836 4
    ] = gax.routingHeader.fromParams({
837 4
      parent: request.parent || '',
838 4
    });
839 4
    this.initialize();
840 4
    return this.innerApiCalls.asyncBatchAnnotateFiles(
841 4
      request,
842 4
      options,
843 4
      callback
844 4
    );
845 4
  }
846 4
  /**
847 4
   * Check the status of the long running operation returned by the asyncBatchAnnotateFiles() method.
848 4
   * @param {String} name
849 4
   *   The operation name that will be passed.
850 4
   * @returns {Promise} - The promise which resolves to an object.
851 4
   *   The decoded operation object has result and metadata field to get information from.
852 4
   *
853 4
   * @example:
854 4
   *   const decodedOperation = await checkAsyncBatchAnnotateFilesProgress(name);
855 4
   *   console.log(decodedOperation.result);
856 4
   *   console.log(decodedOperation.done);
857 4
   *   console.log(decodedOperation.metadata);
858 4
   *
859 4
   */
860 4
  async checkAsyncBatchAnnotateFilesProgress(
861 4
    name: string
862 4
  ): Promise<
863 4
    LROperation<
864 4
      protos.google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse,
865 4
      protos.google.cloud.vision.v1.OperationMetadata
866 4
    >
867 4
  > {
868 4
    const request = new operationsProtos.google.longrunning.GetOperationRequest(
869 4
      {name}
870 4
    );
871 4
    const [operation] = await this.operationsClient.getOperation(request);
872 4
    const decodeOperation = new gax.Operation(
873 4
      operation,
874 4
      this.descriptors.longrunning.asyncBatchAnnotateFiles,
875 4
      gax.createDefaultBackoffSettings()
876 4
    );
877 4
    return decodeOperation as LROperation<
878 4
      protos.google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse,
879 4
      protos.google.cloud.vision.v1.OperationMetadata
880 4
    >;
881 1
  }
882 4
  // --------------------
883 4
  // -- Path templates --
884 4
  // --------------------
885 4

886 4
  /**
887 4
   * Return a fully-qualified product resource name string.
888 4
   *
889 4
   * @param {string} project
890 4
   * @param {string} location
891 4
   * @param {string} product
892 4
   * @returns {string} Resource name string.
893 4
   */
894 4
  productPath(project: string, location: string, product: string) {
895 4
    return this.pathTemplates.productPathTemplate.render({
896 4
      project: project,
897 4
      location: location,
898 4
      product: product,
899 4
    });
900 4
  }
901 4

902 4
  /**
903 4
   * Parse the project from Product resource.
904 4
   *
905 4
   * @param {string} productName
906 4
   *   A fully-qualified path representing Product resource.
907 4
   * @returns {string} A string representing the project.
908 4
   */
909 4
  matchProjectFromProductName(productName: string) {
910 4
    return this.pathTemplates.productPathTemplate.match(productName).project;
911 4
  }
912 4

913 4
  /**
914 4
   * Parse the location from Product resource.
915 4
   *
916 4
   * @param {string} productName
917 4
   *   A fully-qualified path representing Product resource.
918 4
   * @returns {string} A string representing the location.
919 4
   */
920 4
  matchLocationFromProductName(productName: string) {
921 4
    return this.pathTemplates.productPathTemplate.match(productName).location;
922 4
  }
923 4

924 4
  /**
925 4
   * Parse the product from Product resource.
926 4
   *
927 4
   * @param {string} productName
928 4
   *   A fully-qualified path representing Product resource.
929 4
   * @returns {string} A string representing the product.
930 4
   */
931 4
  matchProductFromProductName(productName: string) {
932 4
    return this.pathTemplates.productPathTemplate.match(productName).product;
933 4
  }
934 4

935 4
  /**
936 4
   * Return a fully-qualified productSet resource name string.
937 4
   *
938 4
   * @param {string} project
939 4
   * @param {string} location
940 4
   * @param {string} product_set
941 4
   * @returns {string} Resource name string.
942 4
   */
943 4
  productSetPath(project: string, location: string, productSet: string) {
944 4
    return this.pathTemplates.productSetPathTemplate.render({
945 4
      project: project,
946 4
      location: location,
947 4
      product_set: productSet,
948 4
    });
949 4
  }
950 4

951 4
  /**
952 4
   * Parse the project from ProductSet resource.
953 4
   *
954 4
   * @param {string} productSetName
955 4
   *   A fully-qualified path representing ProductSet resource.
956 4
   * @returns {string} A string representing the project.
957 4
   */
958 4
  matchProjectFromProductSetName(productSetName: string) {
959 4
    return this.pathTemplates.productSetPathTemplate.match(productSetName)
960 4
      .project;
961 4
  }
962 4

963 4
  /**
964 4
   * Parse the location from ProductSet resource.
965 4
   *
966 4
   * @param {string} productSetName
967 4
   *   A fully-qualified path representing ProductSet resource.
968 4
   * @returns {string} A string representing the location.
969 4
   */
970 4
  matchLocationFromProductSetName(productSetName: string) {
971 4
    return this.pathTemplates.productSetPathTemplate.match(productSetName)
972 4
      .location;
973 4
  }
974 4

975 4
  /**
976 4
   * Parse the product_set from ProductSet resource.
977 4
   *
978 4
   * @param {string} productSetName
979 4
   *   A fully-qualified path representing ProductSet resource.
980 4
   * @returns {string} A string representing the product_set.
981 4
   */
982 4
  matchProductSetFromProductSetName(productSetName: string) {
983 4
    return this.pathTemplates.productSetPathTemplate.match(productSetName)
984 4
      .product_set;
985 4
  }
986 4

987 4
  /**
988 4
   * Return a fully-qualified referenceImage resource name string.
989 4
   *
990 4
   * @param {string} project
991 4
   * @param {string} location
992 4
   * @param {string} product
993 4
   * @param {string} reference_image
994 4
   * @returns {string} Resource name string.
995 4
   */
996 4
  referenceImagePath(
997 4
    project: string,
998 4
    location: string,
999 4
    product: string,
1000 4
    referenceImage: string
1001 4
  ) {
1002 4
    return this.pathTemplates.referenceImagePathTemplate.render({
1003 4
      project: project,
1004 4
      location: location,
1005 4
      product: product,
1006 4
      reference_image: referenceImage,
1007 4
    });
1008 4
  }
1009 4

1010 4
  /**
1011 4
   * Parse the project from ReferenceImage resource.
1012 4
   *
1013 4
   * @param {string} referenceImageName
1014 4
   *   A fully-qualified path representing ReferenceImage resource.
1015 4
   * @returns {string} A string representing the project.
1016 4
   */
1017 4
  matchProjectFromReferenceImageName(referenceImageName: string) {
1018 4
    return this.pathTemplates.referenceImagePathTemplate.match(
1019 4
      referenceImageName
1020 4
    ).project;
1021 4
  }
1022 4

1023 4
  /**
1024 4
   * Parse the location from ReferenceImage resource.
1025 4
   *
1026 4
   * @param {string} referenceImageName
1027 4
   *   A fully-qualified path representing ReferenceImage resource.
1028 4
   * @returns {string} A string representing the location.
1029 4
   */
1030 4
  matchLocationFromReferenceImageName(referenceImageName: string) {
1031 4
    return this.pathTemplates.referenceImagePathTemplate.match(
1032 4
      referenceImageName
1033 4
    ).location;
1034 4
  }
1035 4

1036 4
  /**
1037 4
   * Parse the product from ReferenceImage resource.
1038 4
   *
1039 4
   * @param {string} referenceImageName
1040 4
   *   A fully-qualified path representing ReferenceImage resource.
1041 4
   * @returns {string} A string representing the product.
1042 4
   */
1043 4
  matchProductFromReferenceImageName(referenceImageName: string) {
1044 4
    return this.pathTemplates.referenceImagePathTemplate.match(
1045 4
      referenceImageName
1046 4
    ).product;
1047 4
  }
1048 4

1049 4
  /**
1050 4
   * Parse the reference_image from ReferenceImage resource.
1051 4
   *
1052 4
   * @param {string} referenceImageName
1053 4
   *   A fully-qualified path representing ReferenceImage resource.
1054 4
   * @returns {string} A string representing the reference_image.
1055 4
   */
1056 4
  matchReferenceImageFromReferenceImageName(referenceImageName: string) {
1057 4
    return this.pathTemplates.referenceImagePathTemplate.match(
1058 4
      referenceImageName
1059 4
    ).reference_image;
1060 4
  }
1061 4

1062 4
  /**
1063 4
   * Terminate the GRPC channel and close the client.
1064 4
   *
1065 4
   * The client will no longer be usable and all future behavior is undefined.
1066 4
   */
1067 4
  close(): Promise<void> {
1068 4
    this.initialize();
1069 4
    if (!this._terminated) {
1070 4
      return this.imageAnnotatorStub!.then(stub => {
1071 4
        this._terminated = true;
1072 4
        stub.close();
1073 4
      });
1074 4
    }
1075 0
    return Promise.resolve();
1076 0
  }
1077 4
}
1078 4
import {FeaturesMethod} from '../helpers';
1079 4
// eslint-disable-next-line @typescript-eslint/no-empty-interface
1080 4
export interface ImageAnnotatorClient extends FeaturesMethod {}

Read our documentation on viewing source code .

Loading