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 v1p4beta1
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.v1p4beta1.AsyncBatchAnnotateImagesResponse'
192 4
    ) as gax.protobuf.Type;
193 4
    const asyncBatchAnnotateImagesMetadata = protoFilesRoot.lookup(
194 4
      '.google.cloud.vision.v1p4beta1.OperationMetadata'
195 4
    ) as gax.protobuf.Type;
196 4
    const asyncBatchAnnotateFilesResponse = protoFilesRoot.lookup(
197 4
      '.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateFilesResponse'
198 4
    ) as gax.protobuf.Type;
199 4
    const asyncBatchAnnotateFilesMetadata = protoFilesRoot.lookup(
200 4
      '.google.cloud.vision.v1p4beta1.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.v1p4beta1.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.v1p4beta1.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.v1p4beta1.ImageAnnotator'
261 4
          )
262 4
        : // eslint-disable-next-line @typescript-eslint/no-explicit-any
263 4
          (this._protos as any).google.cloud.vision.v1p4beta1.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 0
          throw err;
286 0
        }
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.v1p4beta1.IBatchAnnotateImagesRequest,
357 4
    options?: gax.CallOptions
358 4
  ): Promise<
359 4
    [
360 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse,
361 4
      (
362 4
        | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest
363 4
        | undefined
364 4
      ),
365 4
      {} | undefined
366 4
    ]
367 4
  >;
368 4
  batchAnnotateImages(
369 4
    request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest,
370 4
    options: gax.CallOptions,
371 4
    callback: Callback<
372 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse,
373 4
      | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest
374 4
      | null
375 4
      | undefined,
376 4
      {} | null | undefined
377 4
    >
378 4
  ): void;
379 4
  batchAnnotateImages(
380 4
    request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest,
381 4
    callback: Callback<
382 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse,
383 4
      | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest
384 4
      | null
385 4
      | undefined,
386 4
      {} | null | undefined
387 4
    >
388 4
  ): void;
389 4
  /**
390 4
   * Run image detection and annotation for a batch of images.
391 4
   *
392 4
   * @param {Object} request
393 4
   *   The request object that will be sent.
394 4
   * @param {number[]} request.requests
395 4
   *   Required. Individual image annotation requests for this batch.
396 4
   * @param {object} [options]
397 4
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
398 4
   * @returns {Promise} - The promise which resolves to an array.
399 4
   *   The first element of the array is an object representing [BatchAnnotateImagesResponse]{@link google.cloud.vision.v1p4beta1.BatchAnnotateImagesResponse}.
400 4
   *   The promise has a method named "cancel" which cancels the ongoing API call.
401 4
   */
402 4
  batchAnnotateImages(
403 4
    request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest,
404 4
    optionsOrCallback?:
405 4
      | gax.CallOptions
406 4
      | Callback<
407 4
          protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse,
408 4
          | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest
409 4
          | null
410 4
          | undefined,
411 4
          {} | null | undefined
412 4
        >,
413 4
    callback?: Callback<
414 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse,
415 4
      | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest
416 4
      | null
417 4
      | undefined,
418 4
      {} | null | undefined
419 4
    >
420 4
  ): Promise<
421 4
    [
422 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesResponse,
423 4
      (
424 4
        | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateImagesRequest
425 4
        | undefined
426 4
      ),
427 4
      {} | undefined
428 4
    ]
429 4
  > | void {
430 4
    request = request || {};
431 4
    let options: gax.CallOptions;
432 4
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
433 4
      callback = optionsOrCallback;
434 4
      options = {};
435 4
    } else {
436 4
      options = optionsOrCallback as gax.CallOptions;
437 4
    }
438 4
    options = options || {};
439 4
    this.initialize();
440 4
    return this.innerApiCalls.batchAnnotateImages(request, options, callback);
441 4
  }
442 4
  batchAnnotateFiles(
443 4
    request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest,
444 4
    options?: gax.CallOptions
445 4
  ): Promise<
446 4
    [
447 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse,
448 4
      (
449 4
        | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest
450 4
        | undefined
451 4
      ),
452 4
      {} | undefined
453 4
    ]
454 4
  >;
455 4
  batchAnnotateFiles(
456 4
    request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest,
457 4
    options: gax.CallOptions,
458 4
    callback: Callback<
459 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse,
460 4
      | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest
461 4
      | null
462 4
      | undefined,
463 4
      {} | null | undefined
464 4
    >
465 4
  ): void;
466 4
  batchAnnotateFiles(
467 4
    request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest,
468 4
    callback: Callback<
469 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse,
470 4
      | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest
471 4
      | null
472 4
      | undefined,
473 4
      {} | null | undefined
474 4
    >
475 4
  ): void;
476 4
  /**
477 4
   * Service that performs image detection and annotation for a batch of files.
478 4
   * Now only "application/pdf", "image/tiff" and "image/gif" are supported.
479 4
   *
480 4
   * This service will extract at most 5 (customers can specify which 5 in
481 4
   * AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each
482 4
   * file provided and perform detection and annotation for each image
483 4
   * extracted.
484 4
   *
485 4
   * @param {Object} request
486 4
   *   The request object that will be sent.
487 4
   * @param {number[]} request.requests
488 4
   *   Required. The list of file annotation requests. Right now we support only
489 4
   *   one AnnotateFileRequest in BatchAnnotateFilesRequest.
490 4
   * @param {object} [options]
491 4
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
492 4
   * @returns {Promise} - The promise which resolves to an array.
493 4
   *   The first element of the array is an object representing [BatchAnnotateFilesResponse]{@link google.cloud.vision.v1p4beta1.BatchAnnotateFilesResponse}.
494 4
   *   The promise has a method named "cancel" which cancels the ongoing API call.
495 4
   */
496 4
  batchAnnotateFiles(
497 4
    request: protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest,
498 4
    optionsOrCallback?:
499 4
      | gax.CallOptions
500 4
      | Callback<
501 4
          protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse,
502 4
          | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest
503 4
          | null
504 4
          | undefined,
505 4
          {} | null | undefined
506 4
        >,
507 4
    callback?: Callback<
508 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse,
509 4
      | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest
510 4
      | null
511 4
      | undefined,
512 4
      {} | null | undefined
513 4
    >
514 4
  ): Promise<
515 4
    [
516 4
      protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesResponse,
517 4
      (
518 4
        | protos.google.cloud.vision.v1p4beta1.IBatchAnnotateFilesRequest
519 4
        | undefined
520 4
      ),
521 4
      {} | undefined
522 4
    ]
523 4
  > | void {
524 4
    request = request || {};
525 4
    let options: gax.CallOptions;
526 4
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
527 4
      callback = optionsOrCallback;
528 4
      options = {};
529 4
    } else {
530 4
      options = optionsOrCallback as gax.CallOptions;
531 4
    }
532 4
    options = options || {};
533 4
    this.initialize();
534 4
    return this.innerApiCalls.batchAnnotateFiles(request, options, callback);
535 4
  }
536 4

537 4
  asyncBatchAnnotateImages(
538 4
    request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest,
539 4
    options?: gax.CallOptions
540 4
  ): Promise<
541 4
    [
542 4
      LROperation<
543 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse,
544 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
545 4
      >,
546 4
      protos.google.longrunning.IOperation | undefined,
547 4
      {} | undefined
548 4
    ]
549 4
  >;
550 4
  asyncBatchAnnotateImages(
551 4
    request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest,
552 4
    options: gax.CallOptions,
553 4
    callback: Callback<
554 4
      LROperation<
555 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse,
556 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
557 4
      >,
558 4
      protos.google.longrunning.IOperation | null | undefined,
559 4
      {} | null | undefined
560 4
    >
561 4
  ): void;
562 4
  asyncBatchAnnotateImages(
563 4
    request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest,
564 4
    callback: Callback<
565 4
      LROperation<
566 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse,
567 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
568 4
      >,
569 4
      protos.google.longrunning.IOperation | null | undefined,
570 4
      {} | null | undefined
571 4
    >
572 4
  ): void;
573 4
  /**
574 4
   * Run asynchronous image detection and annotation for a list of images.
575 4
   *
576 4
   * Progress and results can be retrieved through the
577 4
   * `google.longrunning.Operations` interface.
578 4
   * `Operation.metadata` contains `OperationMetadata` (metadata).
579 4
   * `Operation.response` contains `AsyncBatchAnnotateImagesResponse` (results).
580 4
   *
581 4
   * This service will write image annotation outputs to json files in customer
582 4
   * GCS bucket, each json file containing BatchAnnotateImagesResponse proto.
583 4
   *
584 4
   * @param {Object} request
585 4
   *   The request object that will be sent.
586 4
   * @param {number[]} request.requests
587 4
   *   Required. Individual image annotation requests for this batch.
588 4
   * @param {google.cloud.vision.v1p4beta1.OutputConfig} request.outputConfig
589 4
   *   Required. The desired output location and metadata (e.g. format).
590 4
   * @param {object} [options]
591 4
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
592 4
   * @returns {Promise} - The promise which resolves to an array.
593 4
   *   The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}.
594 4
   *   The promise has a method named "cancel" which cancels the ongoing API call.
595 4
   */
596 4
  asyncBatchAnnotateImages(
597 4
    request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesRequest,
598 4
    optionsOrCallback?:
599 4
      | gax.CallOptions
600 4
      | Callback<
601 4
          LROperation<
602 4
            protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse,
603 4
            protos.google.cloud.vision.v1p4beta1.IOperationMetadata
604 4
          >,
605 4
          protos.google.longrunning.IOperation | null | undefined,
606 4
          {} | null | undefined
607 4
        >,
608 4
    callback?: Callback<
609 4
      LROperation<
610 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse,
611 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
612 4
      >,
613 4
      protos.google.longrunning.IOperation | null | undefined,
614 4
      {} | null | undefined
615 4
    >
616 4
  ): Promise<
617 4
    [
618 4
      LROperation<
619 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateImagesResponse,
620 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
621 4
      >,
622 4
      protos.google.longrunning.IOperation | undefined,
623 4
      {} | undefined
624 4
    ]
625 4
  > | void {
626 4
    request = request || {};
627 4
    let options: gax.CallOptions;
628 4
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
629 4
      callback = optionsOrCallback;
630 4
      options = {};
631 4
    } else {
632 4
      options = optionsOrCallback as gax.CallOptions;
633 4
    }
634 4
    options = options || {};
635 4
    this.initialize();
636 4
    return this.innerApiCalls.asyncBatchAnnotateImages(
637 4
      request,
638 4
      options,
639 4
      callback
640 4
    );
641 4
  }
642 4
  /**
643 4
   * Check the status of the long running operation returned by the asyncBatchAnnotateImages() method.
644 4
   * @param {String} name
645 4
   *   The operation name that will be passed.
646 4
   * @returns {Promise} - The promise which resolves to an object.
647 4
   *   The decoded operation object has result and metadata field to get information from.
648 4
   *
649 4
   * @example:
650 4
   *   const decodedOperation = await checkAsyncBatchAnnotateImagesProgress(name);
651 4
   *   console.log(decodedOperation.result);
652 4
   *   console.log(decodedOperation.done);
653 4
   *   console.log(decodedOperation.metadata);
654 4
   *
655 4
   */
656 4
  async checkAsyncBatchAnnotateImagesProgress(
657 4
    name: string
658 4
  ): Promise<
659 4
    LROperation<
660 4
      protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateImagesResponse,
661 4
      protos.google.cloud.vision.v1p4beta1.OperationMetadata
662 4
    >
663 4
  > {
664 4
    const request = new operationsProtos.google.longrunning.GetOperationRequest(
665 4
      {name}
666 4
    );
667 4
    const [operation] = await this.operationsClient.getOperation(request);
668 4
    const decodeOperation = new gax.Operation(
669 4
      operation,
670 4
      this.descriptors.longrunning.asyncBatchAnnotateImages,
671 4
      gax.createDefaultBackoffSettings()
672 4
    );
673 4
    return decodeOperation as LROperation<
674 4
      protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateImagesResponse,
675 4
      protos.google.cloud.vision.v1p4beta1.OperationMetadata
676 4
    >;
677 1
  }
678 4
  asyncBatchAnnotateFiles(
679 4
    request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest,
680 4
    options?: gax.CallOptions
681 4
  ): Promise<
682 4
    [
683 4
      LROperation<
684 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse,
685 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
686 4
      >,
687 4
      protos.google.longrunning.IOperation | undefined,
688 4
      {} | undefined
689 4
    ]
690 4
  >;
691 4
  asyncBatchAnnotateFiles(
692 4
    request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest,
693 4
    options: gax.CallOptions,
694 4
    callback: Callback<
695 4
      LROperation<
696 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse,
697 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
698 4
      >,
699 4
      protos.google.longrunning.IOperation | null | undefined,
700 4
      {} | null | undefined
701 4
    >
702 4
  ): void;
703 4
  asyncBatchAnnotateFiles(
704 4
    request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest,
705 4
    callback: Callback<
706 4
      LROperation<
707 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse,
708 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
709 4
      >,
710 4
      protos.google.longrunning.IOperation | null | undefined,
711 4
      {} | null | undefined
712 4
    >
713 4
  ): void;
714 4
  /**
715 4
   * Run asynchronous image detection and annotation for a list of generic
716 4
   * files, such as PDF files, which may contain multiple pages and multiple
717 4
   * images per page. Progress and results can be retrieved through the
718 4
   * `google.longrunning.Operations` interface.
719 4
   * `Operation.metadata` contains `OperationMetadata` (metadata).
720 4
   * `Operation.response` contains `AsyncBatchAnnotateFilesResponse` (results).
721 4
   *
722 4
   * @param {Object} request
723 4
   *   The request object that will be sent.
724 4
   * @param {number[]} request.requests
725 4
   *   Required. Individual async file annotation requests for this batch.
726 4
   * @param {object} [options]
727 4
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
728 4
   * @returns {Promise} - The promise which resolves to an array.
729 4
   *   The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}.
730 4
   *   The promise has a method named "cancel" which cancels the ongoing API call.
731 4
   */
732 4
  asyncBatchAnnotateFiles(
733 4
    request: protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesRequest,
734 4
    optionsOrCallback?:
735 4
      | gax.CallOptions
736 4
      | Callback<
737 4
          LROperation<
738 4
            protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse,
739 4
            protos.google.cloud.vision.v1p4beta1.IOperationMetadata
740 4
          >,
741 4
          protos.google.longrunning.IOperation | null | undefined,
742 4
          {} | null | undefined
743 4
        >,
744 4
    callback?: Callback<
745 4
      LROperation<
746 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse,
747 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
748 4
      >,
749 4
      protos.google.longrunning.IOperation | null | undefined,
750 4
      {} | null | undefined
751 4
    >
752 4
  ): Promise<
753 4
    [
754 4
      LROperation<
755 4
        protos.google.cloud.vision.v1p4beta1.IAsyncBatchAnnotateFilesResponse,
756 4
        protos.google.cloud.vision.v1p4beta1.IOperationMetadata
757 4
      >,
758 4
      protos.google.longrunning.IOperation | undefined,
759 4
      {} | undefined
760 4
    ]
761 4
  > | void {
762 4
    request = request || {};
763 4
    let options: gax.CallOptions;
764 4
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
765 4
      callback = optionsOrCallback;
766 4
      options = {};
767 4
    } else {
768 4
      options = optionsOrCallback as gax.CallOptions;
769 4
    }
770 4
    options = options || {};
771 4
    this.initialize();
772 4
    return this.innerApiCalls.asyncBatchAnnotateFiles(
773 4
      request,
774 4
      options,
775 4
      callback
776 4
    );
777 4
  }
778 4
  /**
779 4
   * Check the status of the long running operation returned by the asyncBatchAnnotateFiles() method.
780 4
   * @param {String} name
781 4
   *   The operation name that will be passed.
782 4
   * @returns {Promise} - The promise which resolves to an object.
783 4
   *   The decoded operation object has result and metadata field to get information from.
784 4
   *
785 4
   * @example:
786 4
   *   const decodedOperation = await checkAsyncBatchAnnotateFilesProgress(name);
787 4
   *   console.log(decodedOperation.result);
788 4
   *   console.log(decodedOperation.done);
789 4
   *   console.log(decodedOperation.metadata);
790 4
   *
791 4
   */
792 4
  async checkAsyncBatchAnnotateFilesProgress(
793 4
    name: string
794 4
  ): Promise<
795 4
    LROperation<
796 4
      protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateFilesResponse,
797 4
      protos.google.cloud.vision.v1p4beta1.OperationMetadata
798 4
    >
799 4
  > {
800 4
    const request = new operationsProtos.google.longrunning.GetOperationRequest(
801 4
      {name}
802 4
    );
803 4
    const [operation] = await this.operationsClient.getOperation(request);
804 4
    const decodeOperation = new gax.Operation(
805 4
      operation,
806 4
      this.descriptors.longrunning.asyncBatchAnnotateFiles,
807 4
      gax.createDefaultBackoffSettings()
808 4
    );
809 4
    return decodeOperation as LROperation<
810 4
      protos.google.cloud.vision.v1p4beta1.AsyncBatchAnnotateFilesResponse,
811 4
      protos.google.cloud.vision.v1p4beta1.OperationMetadata
812 4
    >;
813 1
  }
814 4
  // --------------------
815 4
  // -- Path templates --
816 4
  // --------------------
817 4

818 4
  /**
819 4
   * Return a fully-qualified product resource name string.
820 4
   *
821 4
   * @param {string} project
822 4
   * @param {string} location
823 4
   * @param {string} product
824 4
   * @returns {string} Resource name string.
825 4
   */
826 4
  productPath(project: string, location: string, product: string) {
827 4
    return this.pathTemplates.productPathTemplate.render({
828 4
      project: project,
829 4
      location: location,
830 4
      product: product,
831 4
    });
832 4
  }
833 4

834 4
  /**
835 4
   * Parse the project from Product resource.
836 4
   *
837 4
   * @param {string} productName
838 4
   *   A fully-qualified path representing Product resource.
839 4
   * @returns {string} A string representing the project.
840 4
   */
841 4
  matchProjectFromProductName(productName: string) {
842 4
    return this.pathTemplates.productPathTemplate.match(productName).project;
843 4
  }
844 4

845 4
  /**
846 4
   * Parse the location from Product resource.
847 4
   *
848 4
   * @param {string} productName
849 4
   *   A fully-qualified path representing Product resource.
850 4
   * @returns {string} A string representing the location.
851 4
   */
852 4
  matchLocationFromProductName(productName: string) {
853 4
    return this.pathTemplates.productPathTemplate.match(productName).location;
854 4
  }
855 4

856 4
  /**
857 4
   * Parse the product from Product resource.
858 4
   *
859 4
   * @param {string} productName
860 4
   *   A fully-qualified path representing Product resource.
861 4
   * @returns {string} A string representing the product.
862 4
   */
863 4
  matchProductFromProductName(productName: string) {
864 4
    return this.pathTemplates.productPathTemplate.match(productName).product;
865 4
  }
866 4

867 4
  /**
868 4
   * Return a fully-qualified productSet resource name string.
869 4
   *
870 4
   * @param {string} project
871 4
   * @param {string} location
872 4
   * @param {string} product_set
873 4
   * @returns {string} Resource name string.
874 4
   */
875 4
  productSetPath(project: string, location: string, productSet: string) {
876 4
    return this.pathTemplates.productSetPathTemplate.render({
877 4
      project: project,
878 4
      location: location,
879 4
      product_set: productSet,
880 4
    });
881 4
  }
882 4

883 4
  /**
884 4
   * Parse the project from ProductSet resource.
885 4
   *
886 4
   * @param {string} productSetName
887 4
   *   A fully-qualified path representing ProductSet resource.
888 4
   * @returns {string} A string representing the project.
889 4
   */
890 4
  matchProjectFromProductSetName(productSetName: string) {
891 4
    return this.pathTemplates.productSetPathTemplate.match(productSetName)
892 4
      .project;
893 4
  }
894 4

895 4
  /**
896 4
   * Parse the location from ProductSet resource.
897 4
   *
898 4
   * @param {string} productSetName
899 4
   *   A fully-qualified path representing ProductSet resource.
900 4
   * @returns {string} A string representing the location.
901 4
   */
902 4
  matchLocationFromProductSetName(productSetName: string) {
903 4
    return this.pathTemplates.productSetPathTemplate.match(productSetName)
904 4
      .location;
905 4
  }
906 4

907 4
  /**
908 4
   * Parse the product_set from ProductSet resource.
909 4
   *
910 4
   * @param {string} productSetName
911 4
   *   A fully-qualified path representing ProductSet resource.
912 4
   * @returns {string} A string representing the product_set.
913 4
   */
914 4
  matchProductSetFromProductSetName(productSetName: string) {
915 4
    return this.pathTemplates.productSetPathTemplate.match(productSetName)
916 4
      .product_set;
917 4
  }
918 4

919 4
  /**
920 4
   * Return a fully-qualified referenceImage resource name string.
921 4
   *
922 4
   * @param {string} project
923 4
   * @param {string} location
924 4
   * @param {string} product
925 4
   * @param {string} reference_image
926 4
   * @returns {string} Resource name string.
927 4
   */
928 4
  referenceImagePath(
929 4
    project: string,
930 4
    location: string,
931 4
    product: string,
932 4
    referenceImage: string
933 4
  ) {
934 4
    return this.pathTemplates.referenceImagePathTemplate.render({
935 4
      project: project,
936 4
      location: location,
937 4
      product: product,
938 4
      reference_image: referenceImage,
939 4
    });
940 4
  }
941 4

942 4
  /**
943 4
   * Parse the project from ReferenceImage resource.
944 4
   *
945 4
   * @param {string} referenceImageName
946 4
   *   A fully-qualified path representing ReferenceImage resource.
947 4
   * @returns {string} A string representing the project.
948 4
   */
949 4
  matchProjectFromReferenceImageName(referenceImageName: string) {
950 4
    return this.pathTemplates.referenceImagePathTemplate.match(
951 4
      referenceImageName
952 4
    ).project;
953 4
  }
954 4

955 4
  /**
956 4
   * Parse the location from ReferenceImage resource.
957 4
   *
958 4
   * @param {string} referenceImageName
959 4
   *   A fully-qualified path representing ReferenceImage resource.
960 4
   * @returns {string} A string representing the location.
961 4
   */
962 4
  matchLocationFromReferenceImageName(referenceImageName: string) {
963 4
    return this.pathTemplates.referenceImagePathTemplate.match(
964 4
      referenceImageName
965 4
    ).location;
966 4
  }
967 4

968 4
  /**
969 4
   * Parse the product from ReferenceImage resource.
970 4
   *
971 4
   * @param {string} referenceImageName
972 4
   *   A fully-qualified path representing ReferenceImage resource.
973 4
   * @returns {string} A string representing the product.
974 4
   */
975 4
  matchProductFromReferenceImageName(referenceImageName: string) {
976 4
    return this.pathTemplates.referenceImagePathTemplate.match(
977 4
      referenceImageName
978 4
    ).product;
979 4
  }
980 4

981 4
  /**
982 4
   * Parse the reference_image from ReferenceImage resource.
983 4
   *
984 4
   * @param {string} referenceImageName
985 4
   *   A fully-qualified path representing ReferenceImage resource.
986 4
   * @returns {string} A string representing the reference_image.
987 4
   */
988 4
  matchReferenceImageFromReferenceImageName(referenceImageName: string) {
989 4
    return this.pathTemplates.referenceImagePathTemplate.match(
990 4
      referenceImageName
991 4
    ).reference_image;
992 4
  }
993 4

994 4
  /**
995 4
   * Terminate the GRPC channel and close the client.
996 4
   *
997 4
   * The client will no longer be usable and all future behavior is undefined.
998 4
   */
999 4
  close(): Promise<void> {
1000 4
    this.initialize();
1001 4
    if (!this._terminated) {
1002 4
      return this.imageAnnotatorStub!.then(stub => {
1003 4
        this._terminated = true;
1004 4
        stub.close();
1005 4
      });
1006 4
    }
1007 0
    return Promise.resolve();
1008 0
  }
1009 4
}
1010 4
import {FeaturesMethod} from '../helpers';
1011 4
// eslint-disable-next-line @typescript-eslint/no-empty-interface
1012 4
export interface ImageAnnotatorClient extends FeaturesMethod {}

Read our documentation on viewing source code .

Loading