From 31808095791eeee24ebdedbddf72b075ee3fd6bf Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:48:18 -0800 Subject: [PATCH] feat: Trusted Private Cloud support, use the universeDomain parameter (#5018) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Added option for user to set labels docs: Updated various comments chore: configure longrunning operations PiperOrigin-RevId: 604671304 Source-Link: https://github.com/googleapis/googleapis/commit/f4c047f491294628d60be57ede025aaee831e98c Source-Link: https://github.com/googleapis/googleapis-gen/commit/939ab9ea6efe368126440b42e6beac7897d3a1c2 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXZpc2lvbi8uT3dsQm90LnlhbWwiLCJoIjoiOTM5YWI5ZWE2ZWZlMzY4MTI2NDQwYjQyZTZiZWFjNzg5N2QzYTFjMiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * build: update gapic-generator-typescript to v4.4.1 PiperOrigin-RevId: 604765466 Source-Link: https://github.com/googleapis/googleapis/commit/40203ca1880849480bbff7b8715491060bbccdf1 Source-Link: https://github.com/googleapis/googleapis-gen/commit/07b7f3dad8aa1912d4acdcfd6365bb4236e4b54b Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXZpc2lvbi8uT3dsQm90LnlhbWwiLCJoIjoiMDdiN2YzZGFkOGFhMTkxMmQ0YWNkY2ZkNjM2NWJiNDIzNmU0YjU0YiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- .../google/cloud/vision/v1/geometry.proto | 2 +- .../cloud/vision/v1/image_annotator.proto | 78 +++- .../cloud/vision/v1/product_search.proto | 9 +- .../vision/v1/product_search_service.proto | 126 +++--- .../cloud/vision/v1/text_annotation.proto | 7 +- .../cloud/vision/v1/web_detection.proto | 2 +- .../google-cloud-vision/protos/protos.d.ts | 24 ++ packages/google-cloud-vision/protos/protos.js | 244 ++++++++++- .../google-cloud-vision/protos/protos.json | 37 +- ...ge_annotator.async_batch_annotate_files.js | 8 + ...e_annotator.async_batch_annotate_images.js | 8 + .../image_annotator.batch_annotate_files.js | 12 +- .../image_annotator.batch_annotate_images.js | 8 + .../product_search.create_reference_image.js | 3 +- .../v1/product_search.list_product_sets.js | 2 +- .../v1/product_search.list_products.js | 2 +- ...uct_search.list_products_in_product_set.js | 2 +- .../product_search.list_reference_images.js | 2 +- ..._search.remove_product_from_product_set.js | 3 +- ...ippet_metadata_google.cloud.vision.v1.json | 28 +- .../product_search.list_product_sets.js | 2 +- .../v1p3beta1/product_search.list_products.js | 2 +- ...uct_search.list_products_in_product_set.js | 2 +- .../product_search.list_reference_images.js | 2 +- .../product_search.list_product_sets.js | 2 +- .../v1p4beta1/product_search.list_products.js | 2 +- ...uct_search.list_products_in_product_set.js | 2 +- .../product_search.list_reference_images.js | 2 +- .../src/v1/image_annotator_client.ts | 265 +++++++++++- .../src/v1/product_search_client.ts | 259 +++++++++++- .../src/v1p1beta1/image_annotator_client.ts | 58 ++- .../src/v1p2beta1/image_annotator_client.ts | 58 ++- .../src/v1p3beta1/image_annotator_client.ts | 58 ++- .../src/v1p3beta1/product_search_client.ts | 58 ++- .../src/v1p4beta1/image_annotator_client.ts | 58 ++- .../src/v1p4beta1/product_search_client.ts | 58 ++- .../test/gapic_image_annotator_v1.ts | 390 +++++++++++++++++- .../test/gapic_image_annotator_v1p1beta1.ts | 62 ++- .../test/gapic_image_annotator_v1p2beta1.ts | 62 ++- .../test/gapic_image_annotator_v1p3beta1.ts | 62 ++- .../test/gapic_image_annotator_v1p4beta1.ts | 62 ++- .../test/gapic_product_search_v1.ts | 367 +++++++++++++++- .../test/gapic_product_search_v1p3beta1.ts | 62 ++- .../test/gapic_product_search_v1p4beta1.ts | 62 ++- 44 files changed, 2391 insertions(+), 233 deletions(-) diff --git a/packages/google-cloud-vision/protos/google/cloud/vision/v1/geometry.proto b/packages/google-cloud-vision/protos/google/cloud/vision/v1/geometry.proto index 0394bb54d4b..78349df6cb9 100644 --- a/packages/google-cloud-vision/protos/google/cloud/vision/v1/geometry.proto +++ b/packages/google-cloud-vision/protos/google/cloud/vision/v1/geometry.proto @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-vision/protos/google/cloud/vision/v1/image_annotator.proto b/packages/google-cloud-vision/protos/google/cloud/vision/v1/image_annotator.proto index 46953e6843a..79e2df34086 100644 --- a/packages/google-cloud-vision/protos/google/cloud/vision/v1/image_annotator.proto +++ b/packages/google-cloud-vision/protos/google/cloud/vision/v1/image_annotator.proto @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -46,7 +46,8 @@ service ImageAnnotator { "https://www.googleapis.com/auth/cloud-vision"; // Run image detection and annotation for a batch of images. - rpc BatchAnnotateImages(BatchAnnotateImagesRequest) returns (BatchAnnotateImagesResponse) { + rpc BatchAnnotateImages(BatchAnnotateImagesRequest) + returns (BatchAnnotateImagesResponse) { option (google.api.http) = { post: "/v1/images:annotate" body: "*" @@ -69,7 +70,8 @@ service ImageAnnotator { // AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each // file provided and perform detection and annotation for each image // extracted. - rpc BatchAnnotateFiles(BatchAnnotateFilesRequest) returns (BatchAnnotateFilesResponse) { + rpc BatchAnnotateFiles(BatchAnnotateFilesRequest) + returns (BatchAnnotateFilesResponse) { option (google.api.http) = { post: "/v1/files:annotate" body: "*" @@ -94,7 +96,8 @@ service ImageAnnotator { // // This service will write image annotation outputs to json files in customer // GCS bucket, each json file containing BatchAnnotateImagesResponse proto. - rpc AsyncBatchAnnotateImages(AsyncBatchAnnotateImagesRequest) returns (google.longrunning.Operation) { + rpc AsyncBatchAnnotateImages(AsyncBatchAnnotateImagesRequest) + returns (google.longrunning.Operation) { option (google.api.http) = { post: "/v1/images:asyncBatchAnnotate" body: "*" @@ -120,7 +123,8 @@ service ImageAnnotator { // `google.longrunning.Operations` interface. // `Operation.metadata` contains `OperationMetadata` (metadata). // `Operation.response` contains `AsyncBatchAnnotateFilesResponse` (results). - rpc AsyncBatchAnnotateFiles(AsyncBatchAnnotateFilesRequest) returns (google.longrunning.Operation) { + rpc AsyncBatchAnnotateFiles(AsyncBatchAnnotateFilesRequest) + returns (google.longrunning.Operation) { option (google.api.http) = { post: "/v1/files:asyncBatchAnnotate" body: "*" @@ -566,7 +570,9 @@ message SafeSearchAnnotation { // Likelihood that this is a medical image. Likelihood medical = 3; - // Likelihood that this image contains violent content. + // Likelihood that this image contains violent content. Violent content may + // include death, serious harm, or injury to individuals or groups of + // individuals. Likelihood violence = 4; // Likelihood that the request image contains racy content. Racy content may @@ -644,8 +650,8 @@ message CropHintsParams { // Parameters for web detection request. message WebDetectionParams { - // Whether to include results derived from the geo information in the image. - bool include_geo_results = 2; + // This field has no effect on results. + bool include_geo_results = 2 [deprecated = true]; } // Parameters for text detections. This is used to control TEXT_DETECTION and @@ -656,7 +662,13 @@ message TextDetectionParams { // score for TEXT_DETECTION as well. bool enable_text_detection_confidence_score = 9; - // A list of advanced OCR options to fine-tune OCR behavior. + // A list of advanced OCR options to further fine-tune OCR behavior. + // Current valid values are: + // + // - `legacy_layout`: a heuristics layout detection algorithm, which serves as + // an alternative to the current ML-based layout detection algorithm. + // Customers can choose the best suitable layout algorithm based on their + // situation. repeated string advanced_ocr_options = 11; } @@ -767,7 +779,8 @@ message AnnotateImageResponse { // Multiple image annotation requests are batched into a single service call. message BatchAnnotateImagesRequest { // Required. Individual image annotation requests for this batch. - repeated AnnotateImageRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; + repeated AnnotateImageRequest requests = 1 + [(google.api.field_behavior) = REQUIRED]; // Optional. Target project and location to make a call. // @@ -782,6 +795,14 @@ message BatchAnnotateImagesRequest { // // Example: `projects/project-A/locations/eu`. string parent = 4; + + // Optional. The labels with user-defined metadata for the request. + // + // Label keys and values can be no longer than 63 characters + // (Unicode codepoints), can only contain lowercase letters, numeric + // characters, underscores and dashes. International characters are allowed. + // Label values are optional. Label keys must start with a letter. + map labels = 5 [(google.api.field_behavior) = OPTIONAL]; } // Response to a batch image annotation request. @@ -838,9 +859,10 @@ message AnnotateFileResponse { // A list of requests to annotate files using the BatchAnnotateFiles API. message BatchAnnotateFilesRequest { - // Required. The list of file annotation requests. Right now we support only one - // AnnotateFileRequest in BatchAnnotateFilesRequest. - repeated AnnotateFileRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; + // Required. The list of file annotation requests. Right now we support only + // one AnnotateFileRequest in BatchAnnotateFilesRequest. + repeated AnnotateFileRequest requests = 1 + [(google.api.field_behavior) = REQUIRED]; // Optional. Target project and location to make a call. // @@ -855,6 +877,14 @@ message BatchAnnotateFilesRequest { // // Example: `projects/project-A/locations/eu`. string parent = 3; + + // Optional. The labels with user-defined metadata for the request. + // + // Label keys and values can be no longer than 63 characters + // (Unicode codepoints), can only contain lowercase letters, numeric + // characters, underscores and dashes. International characters are allowed. + // Label values are optional. Label keys must start with a letter. + map labels = 5 [(google.api.field_behavior) = OPTIONAL]; } // A list of file annotation responses. @@ -888,7 +918,8 @@ message AsyncAnnotateFileResponse { // Request for async image annotation for a list of images. message AsyncBatchAnnotateImagesRequest { // Required. Individual image annotation requests for this batch. - repeated AnnotateImageRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; + repeated AnnotateImageRequest requests = 1 + [(google.api.field_behavior) = REQUIRED]; // Required. The desired output location and metadata (e.g. format). OutputConfig output_config = 2 [(google.api.field_behavior) = REQUIRED]; @@ -906,6 +937,14 @@ message AsyncBatchAnnotateImagesRequest { // // Example: `projects/project-A/locations/eu`. string parent = 4; + + // Optional. The labels with user-defined metadata for the request. + // + // Label keys and values can be no longer than 63 characters + // (Unicode codepoints), can only contain lowercase letters, numeric + // characters, underscores and dashes. International characters are allowed. + // Label values are optional. Label keys must start with a letter. + map labels = 5 [(google.api.field_behavior) = OPTIONAL]; } // Response to an async batch image annotation request. @@ -918,7 +957,8 @@ message AsyncBatchAnnotateImagesResponse { // call. message AsyncBatchAnnotateFilesRequest { // Required. Individual async file annotation requests for this batch. - repeated AsyncAnnotateFileRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; + repeated AsyncAnnotateFileRequest requests = 1 + [(google.api.field_behavior) = REQUIRED]; // Optional. Target project and location to make a call. // @@ -933,6 +973,14 @@ message AsyncBatchAnnotateFilesRequest { // // Example: `projects/project-A/locations/eu`. string parent = 4; + + // Optional. The labels with user-defined metadata for the request. + // + // Label keys and values can be no longer than 63 characters + // (Unicode codepoints), can only contain lowercase letters, numeric + // characters, underscores and dashes. International characters are allowed. + // Label values are optional. Label keys must start with a letter. + map labels = 5 [(google.api.field_behavior) = OPTIONAL]; } // Response to an async batch file annotation request. diff --git a/packages/google-cloud-vision/protos/google/cloud/vision/v1/product_search.proto b/packages/google-cloud-vision/protos/google/cloud/vision/v1/product_search.proto index 98ece54578b..ed58f0137ce 100644 --- a/packages/google-cloud-vision/protos/google/cloud/vision/v1/product_search.proto +++ b/packages/google-cloud-vision/protos/google/cloud/vision/v1/product_search.proto @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,13 +34,14 @@ message ProductSearchParams { // If it is not specified, system discretion will be applied. BoundingPoly bounding_poly = 9; - // The resource name of a [ProductSet][google.cloud.vision.v1.ProductSet] to be searched for similar images. + // The resource name of a [ProductSet][google.cloud.vision.v1.ProductSet] to + // be searched for similar images. // // Format is: // `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID`. string product_set = 6 [(google.api.resource_reference) = { - type: "vision.googleapis.com/ProductSet" - }]; + type: "vision.googleapis.com/ProductSet" + }]; // The list of product categories to search in. Currently, we only consider // the first category, and either "homegoods-v2", "apparel-v2", "toys-v2", diff --git a/packages/google-cloud-vision/protos/google/cloud/vision/v1/product_search_service.proto b/packages/google-cloud-vision/protos/google/cloud/vision/v1/product_search_service.proto index f97b443ca23..58e55c0101e 100644 --- a/packages/google-cloud-vision/protos/google/cloud/vision/v1/product_search_service.proto +++ b/packages/google-cloud-vision/protos/google/cloud/vision/v1/product_search_service.proto @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,16 +37,18 @@ option objc_class_prefix = "GCVN"; // Manages Products and ProductSets of reference images for use in product // search. It uses the following resource model: // -// - The API has a collection of [ProductSet][google.cloud.vision.v1.ProductSet] resources, named -// `projects/*/locations/*/productSets/*`, which acts as a way to put different -// products into groups to limit identification. +// - The API has a collection of [ProductSet][google.cloud.vision.v1.ProductSet] +// resources, named `projects/*/locations/*/productSets/*`, which acts as a way +// to put different products into groups to limit identification. // // In parallel, // -// - The API has a collection of [Product][google.cloud.vision.v1.Product] resources, named +// - The API has a collection of [Product][google.cloud.vision.v1.Product] +// resources, named // `projects/*/locations/*/products/*` // -// - Each [Product][google.cloud.vision.v1.Product] has a collection of [ReferenceImage][google.cloud.vision.v1.ReferenceImage] resources, named +// - Each [Product][google.cloud.vision.v1.Product] has a collection of +// [ReferenceImage][google.cloud.vision.v1.ReferenceImage] resources, named // `projects/*/locations/*/products/*/referenceImages/*` service ProductSearch { option (google.api.default_host) = "vision.googleapis.com"; @@ -74,7 +76,8 @@ service ProductSearch { // // * Returns INVALID_ARGUMENT if page_size is greater than 100, or less // than 1. - rpc ListProductSets(ListProductSetsRequest) returns (ListProductSetsResponse) { + rpc ListProductSets(ListProductSetsRequest) + returns (ListProductSetsResponse) { option (google.api.http) = { get: "/v1/{parent=projects/*/locations/*}/productSets" }; @@ -113,7 +116,8 @@ service ProductSearch { // ProductSet are not deleted. // // The actual image files are not deleted from Google Cloud Storage. - rpc DeleteProductSet(DeleteProductSetRequest) returns (google.protobuf.Empty) { + rpc DeleteProductSet(DeleteProductSetRequest) + returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/v1/{name=projects/*/locations/*/productSets/*}" }; @@ -214,12 +218,14 @@ service ProductSearch { // * Returns INVALID_ARGUMENT if bounding_poly is not provided, and nothing // compatible with the parent product's product_category is detected. // * Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons. - rpc CreateReferenceImage(CreateReferenceImageRequest) returns (ReferenceImage) { + rpc CreateReferenceImage(CreateReferenceImageRequest) + returns (ReferenceImage) { option (google.api.http) = { post: "/v1/{parent=projects/*/locations/*/products/*}/referenceImages" body: "reference_image" }; - option (google.api.method_signature) = "parent,reference_image,reference_image_id"; + option (google.api.method_signature) = + "parent,reference_image,reference_image_id"; } // Permanently deletes a reference image. @@ -229,7 +235,8 @@ service ProductSearch { // caches are refreshed. // // The actual image files are not deleted from Google Cloud Storage. - rpc DeleteReferenceImage(DeleteReferenceImageRequest) returns (google.protobuf.Empty) { + rpc DeleteReferenceImage(DeleteReferenceImageRequest) + returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/v1/{name=projects/*/locations/*/products/*/referenceImages/*}" }; @@ -243,7 +250,8 @@ service ProductSearch { // * Returns NOT_FOUND if the parent product does not exist. // * Returns INVALID_ARGUMENT if the page_size is greater than 100, or less // than 1. - rpc ListReferenceImages(ListReferenceImagesRequest) returns (ListReferenceImagesResponse) { + rpc ListReferenceImages(ListReferenceImagesRequest) + returns (ListReferenceImagesResponse) { option (google.api.http) = { get: "/v1/{parent=projects/*/locations/*/products/*}/referenceImages" }; @@ -270,7 +278,8 @@ service ProductSearch { // Possible errors: // // * Returns NOT_FOUND if the Product or the ProductSet doesn't exist. - rpc AddProductToProductSet(AddProductToProductSetRequest) returns (google.protobuf.Empty) { + rpc AddProductToProductSet(AddProductToProductSetRequest) + returns (google.protobuf.Empty) { option (google.api.http) = { post: "/v1/{name=projects/*/locations/*/productSets/*}:addProduct" body: "*" @@ -279,7 +288,8 @@ service ProductSearch { } // Removes a Product from the specified ProductSet. - rpc RemoveProductFromProductSet(RemoveProductFromProductSetRequest) returns (google.protobuf.Empty) { + rpc RemoveProductFromProductSet(RemoveProductFromProductSetRequest) + returns (google.protobuf.Empty) { option (google.api.http) = { post: "/v1/{name=projects/*/locations/*/productSets/*}:removeProduct" body: "*" @@ -294,7 +304,8 @@ service ProductSearch { // Possible errors: // // * Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1. - rpc ListProductsInProductSet(ListProductsInProductSetRequest) returns (ListProductsInProductSetResponse) { + rpc ListProductsInProductSet(ListProductsInProductSetRequest) + returns (ListProductsInProductSetResponse) { option (google.api.http) = { get: "/v1/{name=projects/*/locations/*/productSets/*}/products" }; @@ -304,15 +315,16 @@ service ProductSearch { // Asynchronous API that imports a list of reference images to specified // product sets based on a list of image information. // - // The [google.longrunning.Operation][google.longrunning.Operation] API can be used to keep track of the - // progress and results of the request. + // The [google.longrunning.Operation][google.longrunning.Operation] API can be + // used to keep track of the progress and results of the request. // `Operation.metadata` contains `BatchOperationMetadata`. (progress) // `Operation.response` contains `ImportProductSetsResponse`. (results) // // The input source of this method is a csv file on Google Cloud Storage. // For the format of the csv file please see // [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]. - rpc ImportProductSets(ImportProductSetsRequest) returns (google.longrunning.Operation) { + rpc ImportProductSets(ImportProductSetsRequest) + returns (google.longrunning.Operation) { option (google.api.http) = { post: "/v1/{parent=projects/*/locations/*}/productSets:import" body: "*" @@ -345,10 +357,11 @@ service ProductSearch { // ProductSet, you must wait until the PurgeProducts operation has finished // for that ProductSet. // - // The [google.longrunning.Operation][google.longrunning.Operation] API can be used to keep track of the - // progress and results of the request. + // The [google.longrunning.Operation][google.longrunning.Operation] API can be + // used to keep track of the progress and results of the request. // `Operation.metadata` contains `BatchOperationMetadata`. (progress) - rpc PurgeProducts(PurgeProductsRequest) returns (google.longrunning.Operation) { + rpc PurgeProducts(PurgeProductsRequest) + returns (google.longrunning.Operation) { option (google.api.http) = { post: "/v1/{parent=projects/*/locations/*}/products:purge" body: "*" @@ -395,10 +408,11 @@ message Product { // characters long. string description = 3; - // Immutable. The category for the product identified by the reference image. This should - // be one of "homegoods-v2", "apparel-v2", "toys-v2", "packagedgoods-v1" or - // "general-v1". The legacy categories "homegoods", "apparel", and "toys" are - // still supported, but these should not be used for new products. + // Immutable. The category for the product identified by the reference image. + // This should be one of "homegoods-v2", "apparel-v2", "toys-v2", + // "packagedgoods-v1" or "general-v1". The legacy categories "homegoods", + // "apparel", and "toys" are still supported, but these should not be used for + // new products. string product_category = 4 [(google.api.field_behavior) = IMMUTABLE]; // Key-value pairs that can be attached to a product. At query time, @@ -444,7 +458,8 @@ message ProductSet { // "1970-01-01T00:00:00Z". // // This field is ignored when creating a ProductSet. - google.protobuf.Timestamp index_time = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; + google.protobuf.Timestamp index_time = 3 + [(google.api.field_behavior) = OUTPUT_ONLY]; // Output only. If there was an error with indexing the product set, the field // is populated. @@ -474,15 +489,16 @@ message ReferenceImage { // The URI must start with `gs://`. string uri = 2 [(google.api.field_behavior) = REQUIRED]; - // Optional. Bounding polygons around the areas of interest in the reference image. - // If this field is empty, the system will try to detect regions of + // Optional. Bounding polygons around the areas of interest in the reference + // image. If this field is empty, the system will try to detect regions of // interest. At most 10 bounding polygons will be used. // // The provided shape is converted into a non-rotated rectangle. Once // converted, the small edge of the rectangle must be greater than or equal // to 300 pixels. The aspect ratio must be 1:4 or less (i.e. 1:3 is ok; 1:5 // is not). - repeated BoundingPoly bounding_polys = 3 [(google.api.field_behavior) = OPTIONAL]; + repeated BoundingPoly bounding_polys = 3 + [(google.api.field_behavior) = OPTIONAL]; } // Request message for the `CreateProduct` method. @@ -546,9 +562,7 @@ message GetProductRequest { // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` string name = 1 [ (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "vision.googleapis.com/Product" - } + (google.api.resource_reference) = { type: "vision.googleapis.com/Product" } ]; } @@ -574,9 +588,7 @@ message DeleteProductRequest { // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` string name = 1 [ (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "vision.googleapis.com/Product" - } + (google.api.resource_reference) = { type: "vision.googleapis.com/Product" } ]; } @@ -673,15 +685,14 @@ message DeleteProductSetRequest { // Request message for the `CreateReferenceImage` method. message CreateReferenceImageRequest { - // Required. Resource name of the product in which to create the reference image. + // Required. Resource name of the product in which to create the reference + // image. // // Format is // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. string parent = 1 [ (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "vision.googleapis.com/Product" - } + (google.api.resource_reference) = { type: "vision.googleapis.com/Product" } ]; // Required. The reference image to create. @@ -703,9 +714,7 @@ message ListReferenceImagesRequest { // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. string parent = 1 [ (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "vision.googleapis.com/Product" - } + (google.api.resource_reference) = { type: "vision.googleapis.com/Product" } ]; // The maximum number of items to return. Default 10, maximum 100. @@ -777,9 +786,7 @@ message AddProductToProductSetRequest { // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` string product = 2 [ (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "vision.googleapis.com/Product" - } + (google.api.resource_reference) = { type: "vision.googleapis.com/Product" } ]; } @@ -796,15 +803,14 @@ message RemoveProductFromProductSetRequest { } ]; - // Required. The resource name for the Product to be removed from this ProductSet. + // Required. The resource name for the Product to be removed from this + // ProductSet. // // Format is: // `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` string product = 2 [ (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "vision.googleapis.com/Product" - } + (google.api.resource_reference) = { type: "vision.googleapis.com/Product" } ]; } @@ -866,15 +872,17 @@ message ImportProductSetsGcsSource { // `product-display-name` column refers to // [display_name][google.cloud.vision.v1.Product.display_name], the // `product-category` column refers to - // [product_category][google.cloud.vision.v1.Product.product_category], and the - // `labels` column refers to [product_labels][google.cloud.vision.v1.Product.product_labels]. + // [product_category][google.cloud.vision.v1.Product.product_category], and + // the `labels` column refers to + // [product_labels][google.cloud.vision.v1.Product.product_labels]. // // The `image-id` column is optional but must be unique if provided. If it is // empty, the system will automatically assign a unique id to the image. // // The `product-display-name` column is optional. If it is empty, the system - // sets the [display_name][google.cloud.vision.v1.Product.display_name] field for the product to a - // space (" "). You can update the `display_name` later by using the API. + // sets the [display_name][google.cloud.vision.v1.Product.display_name] field + // for the product to a space (" "). You can update the `display_name` later + // by using the API. // // If a `Product` with the specified `product-id` already exists, then the // system ignores the `product-display-name`, `product-category`, and `labels` @@ -928,14 +936,17 @@ message ImportProductSetsRequest { ]; // Required. The input content for the list of requests. - ImportProductSetsInputConfig input_config = 2 [(google.api.field_behavior) = REQUIRED]; + ImportProductSetsInputConfig input_config = 2 + [(google.api.field_behavior) = REQUIRED]; } // Response message for the `ImportProductSets` method. // // This message is returned by the -// [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] method in the returned -// [google.longrunning.Operation.response][google.longrunning.Operation.response] field. +// [google.longrunning.Operations.GetOperation][google.longrunning.Operations.GetOperation] +// method in the returned +// [google.longrunning.Operation.response][google.longrunning.Operation.response] +// field. message ImportProductSetsResponse { // The list of reference_images that are imported successfully. repeated ReferenceImage reference_images = 1; @@ -982,7 +993,8 @@ message BatchOperationMetadata { google.protobuf.Timestamp submit_time = 2; // The time when the batch request is finished and - // [google.longrunning.Operation.done][google.longrunning.Operation.done] is set to true. + // [google.longrunning.Operation.done][google.longrunning.Operation.done] is + // set to true. google.protobuf.Timestamp end_time = 3; } diff --git a/packages/google-cloud-vision/protos/google/cloud/vision/v1/text_annotation.proto b/packages/google-cloud-vision/protos/google/cloud/vision/v1/text_annotation.proto index e84a596a260..bc1c799e83d 100644 --- a/packages/google-cloud-vision/protos/google/cloud/vision/v1/text_annotation.proto +++ b/packages/google-cloud-vision/protos/google/cloud/vision/v1/text_annotation.proto @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,8 +30,9 @@ option objc_class_prefix = "GCVN"; // TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol // Each structural component, starting from Page, may further have their own // properties. Properties describe detected languages, breaks etc.. Please refer -// to the [TextAnnotation.TextProperty][google.cloud.vision.v1.TextAnnotation.TextProperty] message definition below for more -// detail. +// to the +// [TextAnnotation.TextProperty][google.cloud.vision.v1.TextAnnotation.TextProperty] +// message definition below for more detail. message TextAnnotation { // Detected language for a structural component. message DetectedLanguage { diff --git a/packages/google-cloud-vision/protos/google/cloud/vision/v1/web_detection.proto b/packages/google-cloud-vision/protos/google/cloud/vision/v1/web_detection.proto index 5f36bb7ace5..71dc333bc07 100644 --- a/packages/google-cloud-vision/protos/google/cloud/vision/v1/web_detection.proto +++ b/packages/google-cloud-vision/protos/google/cloud/vision/v1/web_detection.proto @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-vision/protos/protos.d.ts b/packages/google-cloud-vision/protos/protos.d.ts index b7a1838591e..69fd2764340 100644 --- a/packages/google-cloud-vision/protos/protos.d.ts +++ b/packages/google-cloud-vision/protos/protos.d.ts @@ -3252,6 +3252,9 @@ export namespace google { /** BatchAnnotateImagesRequest parent */ parent?: (string|null); + + /** BatchAnnotateImagesRequest labels */ + labels?: ({ [k: string]: string }|null); } /** Represents a BatchAnnotateImagesRequest. */ @@ -3269,6 +3272,9 @@ export namespace google { /** BatchAnnotateImagesRequest parent. */ public parent: string; + /** BatchAnnotateImagesRequest labels. */ + public labels: { [k: string]: string }; + /** * Creates a new BatchAnnotateImagesRequest instance using the specified properties. * @param [properties] Properties to set @@ -3682,6 +3688,9 @@ export namespace google { /** BatchAnnotateFilesRequest parent */ parent?: (string|null); + + /** BatchAnnotateFilesRequest labels */ + labels?: ({ [k: string]: string }|null); } /** Represents a BatchAnnotateFilesRequest. */ @@ -3699,6 +3708,9 @@ export namespace google { /** BatchAnnotateFilesRequest parent. */ public parent: string; + /** BatchAnnotateFilesRequest labels. */ + public labels: { [k: string]: string }; + /** * Creates a new BatchAnnotateFilesRequest instance using the specified properties. * @param [properties] Properties to set @@ -4097,6 +4109,9 @@ export namespace google { /** AsyncBatchAnnotateImagesRequest parent */ parent?: (string|null); + + /** AsyncBatchAnnotateImagesRequest labels */ + labels?: ({ [k: string]: string }|null); } /** Represents an AsyncBatchAnnotateImagesRequest. */ @@ -4117,6 +4132,9 @@ export namespace google { /** AsyncBatchAnnotateImagesRequest parent. */ public parent: string; + /** AsyncBatchAnnotateImagesRequest labels. */ + public labels: { [k: string]: string }; + /** * Creates a new AsyncBatchAnnotateImagesRequest instance using the specified properties. * @param [properties] Properties to set @@ -4300,6 +4318,9 @@ export namespace google { /** AsyncBatchAnnotateFilesRequest parent */ parent?: (string|null); + + /** AsyncBatchAnnotateFilesRequest labels */ + labels?: ({ [k: string]: string }|null); } /** Represents an AsyncBatchAnnotateFilesRequest. */ @@ -4317,6 +4338,9 @@ export namespace google { /** AsyncBatchAnnotateFilesRequest parent. */ public parent: string; + /** AsyncBatchAnnotateFilesRequest labels. */ + public labels: { [k: string]: string }; + /** * Creates a new AsyncBatchAnnotateFilesRequest instance using the specified properties. * @param [properties] Properties to set diff --git a/packages/google-cloud-vision/protos/protos.js b/packages/google-cloud-vision/protos/protos.js index 150fb66453b..520a2b6be08 100644 --- a/packages/google-cloud-vision/protos/protos.js +++ b/packages/google-cloud-vision/protos/protos.js @@ -8723,6 +8723,7 @@ * @interface IBatchAnnotateImagesRequest * @property {Array.|null} [requests] BatchAnnotateImagesRequest requests * @property {string|null} [parent] BatchAnnotateImagesRequest parent + * @property {Object.|null} [labels] BatchAnnotateImagesRequest labels */ /** @@ -8735,6 +8736,7 @@ */ function BatchAnnotateImagesRequest(properties) { this.requests = []; + this.labels = {}; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -8757,6 +8759,14 @@ */ BatchAnnotateImagesRequest.prototype.parent = ""; + /** + * BatchAnnotateImagesRequest labels. + * @member {Object.} labels + * @memberof google.cloud.vision.v1.BatchAnnotateImagesRequest + * @instance + */ + BatchAnnotateImagesRequest.prototype.labels = $util.emptyObject; + /** * Creates a new BatchAnnotateImagesRequest instance using the specified properties. * @function create @@ -8786,6 +8796,9 @@ $root.google.cloud.vision.v1.AnnotateImageRequest.encode(message.requests[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); if (message.parent != null && Object.hasOwnProperty.call(message, "parent")) writer.uint32(/* id 4, wireType 2 =*/34).string(message.parent); + if (message.labels != null && Object.hasOwnProperty.call(message, "labels")) + for (var keys = Object.keys(message.labels), i = 0; i < keys.length; ++i) + writer.uint32(/* id 5, wireType 2 =*/42).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.labels[keys[i]]).ldelim(); return writer; }; @@ -8816,7 +8829,7 @@ BatchAnnotateImagesRequest.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.vision.v1.BatchAnnotateImagesRequest(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.vision.v1.BatchAnnotateImagesRequest(), key, value; while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { @@ -8830,6 +8843,29 @@ message.parent = reader.string(); break; } + case 5: { + if (message.labels === $util.emptyObject) + message.labels = {}; + var end2 = reader.uint32() + reader.pos; + key = ""; + value = ""; + while (reader.pos < end2) { + var tag2 = reader.uint32(); + switch (tag2 >>> 3) { + case 1: + key = reader.string(); + break; + case 2: + value = reader.string(); + break; + default: + reader.skipType(tag2 & 7); + break; + } + } + message.labels[key] = value; + break; + } default: reader.skipType(tag & 7); break; @@ -8877,6 +8913,14 @@ if (message.parent != null && message.hasOwnProperty("parent")) if (!$util.isString(message.parent)) return "parent: string expected"; + if (message.labels != null && message.hasOwnProperty("labels")) { + if (!$util.isObject(message.labels)) + return "labels: object expected"; + var key = Object.keys(message.labels); + for (var i = 0; i < key.length; ++i) + if (!$util.isString(message.labels[key[i]])) + return "labels: string{k:string} expected"; + } return null; }; @@ -8904,6 +8948,13 @@ } if (object.parent != null) message.parent = String(object.parent); + if (object.labels) { + if (typeof object.labels !== "object") + throw TypeError(".google.cloud.vision.v1.BatchAnnotateImagesRequest.labels: object expected"); + message.labels = {}; + for (var keys = Object.keys(object.labels), i = 0; i < keys.length; ++i) + message.labels[keys[i]] = String(object.labels[keys[i]]); + } return message; }; @@ -8922,6 +8973,8 @@ var object = {}; if (options.arrays || options.defaults) object.requests = []; + if (options.objects || options.defaults) + object.labels = {}; if (options.defaults) object.parent = ""; if (message.requests && message.requests.length) { @@ -8931,6 +8984,12 @@ } if (message.parent != null && message.hasOwnProperty("parent")) object.parent = message.parent; + var keys2; + if (message.labels && (keys2 = Object.keys(message.labels)).length) { + object.labels = {}; + for (var j = 0; j < keys2.length; ++j) + object.labels[keys2[j]] = message.labels[keys2[j]]; + } return object; }; @@ -9830,6 +9889,7 @@ * @interface IBatchAnnotateFilesRequest * @property {Array.|null} [requests] BatchAnnotateFilesRequest requests * @property {string|null} [parent] BatchAnnotateFilesRequest parent + * @property {Object.|null} [labels] BatchAnnotateFilesRequest labels */ /** @@ -9842,6 +9902,7 @@ */ function BatchAnnotateFilesRequest(properties) { this.requests = []; + this.labels = {}; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -9864,6 +9925,14 @@ */ BatchAnnotateFilesRequest.prototype.parent = ""; + /** + * BatchAnnotateFilesRequest labels. + * @member {Object.} labels + * @memberof google.cloud.vision.v1.BatchAnnotateFilesRequest + * @instance + */ + BatchAnnotateFilesRequest.prototype.labels = $util.emptyObject; + /** * Creates a new BatchAnnotateFilesRequest instance using the specified properties. * @function create @@ -9893,6 +9962,9 @@ $root.google.cloud.vision.v1.AnnotateFileRequest.encode(message.requests[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); if (message.parent != null && Object.hasOwnProperty.call(message, "parent")) writer.uint32(/* id 3, wireType 2 =*/26).string(message.parent); + if (message.labels != null && Object.hasOwnProperty.call(message, "labels")) + for (var keys = Object.keys(message.labels), i = 0; i < keys.length; ++i) + writer.uint32(/* id 5, wireType 2 =*/42).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.labels[keys[i]]).ldelim(); return writer; }; @@ -9923,7 +9995,7 @@ BatchAnnotateFilesRequest.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.vision.v1.BatchAnnotateFilesRequest(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.vision.v1.BatchAnnotateFilesRequest(), key, value; while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { @@ -9937,6 +10009,29 @@ message.parent = reader.string(); break; } + case 5: { + if (message.labels === $util.emptyObject) + message.labels = {}; + var end2 = reader.uint32() + reader.pos; + key = ""; + value = ""; + while (reader.pos < end2) { + var tag2 = reader.uint32(); + switch (tag2 >>> 3) { + case 1: + key = reader.string(); + break; + case 2: + value = reader.string(); + break; + default: + reader.skipType(tag2 & 7); + break; + } + } + message.labels[key] = value; + break; + } default: reader.skipType(tag & 7); break; @@ -9984,6 +10079,14 @@ if (message.parent != null && message.hasOwnProperty("parent")) if (!$util.isString(message.parent)) return "parent: string expected"; + if (message.labels != null && message.hasOwnProperty("labels")) { + if (!$util.isObject(message.labels)) + return "labels: object expected"; + var key = Object.keys(message.labels); + for (var i = 0; i < key.length; ++i) + if (!$util.isString(message.labels[key[i]])) + return "labels: string{k:string} expected"; + } return null; }; @@ -10011,6 +10114,13 @@ } if (object.parent != null) message.parent = String(object.parent); + if (object.labels) { + if (typeof object.labels !== "object") + throw TypeError(".google.cloud.vision.v1.BatchAnnotateFilesRequest.labels: object expected"); + message.labels = {}; + for (var keys = Object.keys(object.labels), i = 0; i < keys.length; ++i) + message.labels[keys[i]] = String(object.labels[keys[i]]); + } return message; }; @@ -10029,6 +10139,8 @@ var object = {}; if (options.arrays || options.defaults) object.requests = []; + if (options.objects || options.defaults) + object.labels = {}; if (options.defaults) object.parent = ""; if (message.requests && message.requests.length) { @@ -10038,6 +10150,12 @@ } if (message.parent != null && message.hasOwnProperty("parent")) object.parent = message.parent; + var keys2; + if (message.labels && (keys2 = Object.keys(message.labels)).length) { + object.labels = {}; + for (var j = 0; j < keys2.length; ++j) + object.labels[keys2[j]] = message.labels[keys2[j]]; + } return object; }; @@ -10821,6 +10939,7 @@ * @property {Array.|null} [requests] AsyncBatchAnnotateImagesRequest requests * @property {google.cloud.vision.v1.IOutputConfig|null} [outputConfig] AsyncBatchAnnotateImagesRequest outputConfig * @property {string|null} [parent] AsyncBatchAnnotateImagesRequest parent + * @property {Object.|null} [labels] AsyncBatchAnnotateImagesRequest labels */ /** @@ -10833,6 +10952,7 @@ */ function AsyncBatchAnnotateImagesRequest(properties) { this.requests = []; + this.labels = {}; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -10863,6 +10983,14 @@ */ AsyncBatchAnnotateImagesRequest.prototype.parent = ""; + /** + * AsyncBatchAnnotateImagesRequest labels. + * @member {Object.} labels + * @memberof google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest + * @instance + */ + AsyncBatchAnnotateImagesRequest.prototype.labels = $util.emptyObject; + /** * Creates a new AsyncBatchAnnotateImagesRequest instance using the specified properties. * @function create @@ -10894,6 +11022,9 @@ $root.google.cloud.vision.v1.OutputConfig.encode(message.outputConfig, writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim(); if (message.parent != null && Object.hasOwnProperty.call(message, "parent")) writer.uint32(/* id 4, wireType 2 =*/34).string(message.parent); + if (message.labels != null && Object.hasOwnProperty.call(message, "labels")) + for (var keys = Object.keys(message.labels), i = 0; i < keys.length; ++i) + writer.uint32(/* id 5, wireType 2 =*/42).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.labels[keys[i]]).ldelim(); return writer; }; @@ -10924,7 +11055,7 @@ AsyncBatchAnnotateImagesRequest.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest(), key, value; while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { @@ -10942,6 +11073,29 @@ message.parent = reader.string(); break; } + case 5: { + if (message.labels === $util.emptyObject) + message.labels = {}; + var end2 = reader.uint32() + reader.pos; + key = ""; + value = ""; + while (reader.pos < end2) { + var tag2 = reader.uint32(); + switch (tag2 >>> 3) { + case 1: + key = reader.string(); + break; + case 2: + value = reader.string(); + break; + default: + reader.skipType(tag2 & 7); + break; + } + } + message.labels[key] = value; + break; + } default: reader.skipType(tag & 7); break; @@ -10994,6 +11148,14 @@ if (message.parent != null && message.hasOwnProperty("parent")) if (!$util.isString(message.parent)) return "parent: string expected"; + if (message.labels != null && message.hasOwnProperty("labels")) { + if (!$util.isObject(message.labels)) + return "labels: object expected"; + var key = Object.keys(message.labels); + for (var i = 0; i < key.length; ++i) + if (!$util.isString(message.labels[key[i]])) + return "labels: string{k:string} expected"; + } return null; }; @@ -11026,6 +11188,13 @@ } if (object.parent != null) message.parent = String(object.parent); + if (object.labels) { + if (typeof object.labels !== "object") + throw TypeError(".google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest.labels: object expected"); + message.labels = {}; + for (var keys = Object.keys(object.labels), i = 0; i < keys.length; ++i) + message.labels[keys[i]] = String(object.labels[keys[i]]); + } return message; }; @@ -11044,6 +11213,8 @@ var object = {}; if (options.arrays || options.defaults) object.requests = []; + if (options.objects || options.defaults) + object.labels = {}; if (options.defaults) { object.outputConfig = null; object.parent = ""; @@ -11057,6 +11228,12 @@ object.outputConfig = $root.google.cloud.vision.v1.OutputConfig.toObject(message.outputConfig, options); if (message.parent != null && message.hasOwnProperty("parent")) object.parent = message.parent; + var keys2; + if (message.labels && (keys2 = Object.keys(message.labels)).length) { + object.labels = {}; + for (var j = 0; j < keys2.length; ++j) + object.labels[keys2[j]] = message.labels[keys2[j]]; + } return object; }; @@ -11305,6 +11482,7 @@ * @interface IAsyncBatchAnnotateFilesRequest * @property {Array.|null} [requests] AsyncBatchAnnotateFilesRequest requests * @property {string|null} [parent] AsyncBatchAnnotateFilesRequest parent + * @property {Object.|null} [labels] AsyncBatchAnnotateFilesRequest labels */ /** @@ -11317,6 +11495,7 @@ */ function AsyncBatchAnnotateFilesRequest(properties) { this.requests = []; + this.labels = {}; if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) @@ -11339,6 +11518,14 @@ */ AsyncBatchAnnotateFilesRequest.prototype.parent = ""; + /** + * AsyncBatchAnnotateFilesRequest labels. + * @member {Object.} labels + * @memberof google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest + * @instance + */ + AsyncBatchAnnotateFilesRequest.prototype.labels = $util.emptyObject; + /** * Creates a new AsyncBatchAnnotateFilesRequest instance using the specified properties. * @function create @@ -11368,6 +11555,9 @@ $root.google.cloud.vision.v1.AsyncAnnotateFileRequest.encode(message.requests[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); if (message.parent != null && Object.hasOwnProperty.call(message, "parent")) writer.uint32(/* id 4, wireType 2 =*/34).string(message.parent); + if (message.labels != null && Object.hasOwnProperty.call(message, "labels")) + for (var keys = Object.keys(message.labels), i = 0; i < keys.length; ++i) + writer.uint32(/* id 5, wireType 2 =*/42).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.labels[keys[i]]).ldelim(); return writer; }; @@ -11398,7 +11588,7 @@ AsyncBatchAnnotateFilesRequest.decode = function decode(reader, length) { if (!(reader instanceof $Reader)) reader = $Reader.create(reader); - var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest(); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest(), key, value; while (reader.pos < end) { var tag = reader.uint32(); switch (tag >>> 3) { @@ -11412,6 +11602,29 @@ message.parent = reader.string(); break; } + case 5: { + if (message.labels === $util.emptyObject) + message.labels = {}; + var end2 = reader.uint32() + reader.pos; + key = ""; + value = ""; + while (reader.pos < end2) { + var tag2 = reader.uint32(); + switch (tag2 >>> 3) { + case 1: + key = reader.string(); + break; + case 2: + value = reader.string(); + break; + default: + reader.skipType(tag2 & 7); + break; + } + } + message.labels[key] = value; + break; + } default: reader.skipType(tag & 7); break; @@ -11459,6 +11672,14 @@ if (message.parent != null && message.hasOwnProperty("parent")) if (!$util.isString(message.parent)) return "parent: string expected"; + if (message.labels != null && message.hasOwnProperty("labels")) { + if (!$util.isObject(message.labels)) + return "labels: object expected"; + var key = Object.keys(message.labels); + for (var i = 0; i < key.length; ++i) + if (!$util.isString(message.labels[key[i]])) + return "labels: string{k:string} expected"; + } return null; }; @@ -11486,6 +11707,13 @@ } if (object.parent != null) message.parent = String(object.parent); + if (object.labels) { + if (typeof object.labels !== "object") + throw TypeError(".google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest.labels: object expected"); + message.labels = {}; + for (var keys = Object.keys(object.labels), i = 0; i < keys.length; ++i) + message.labels[keys[i]] = String(object.labels[keys[i]]); + } return message; }; @@ -11504,6 +11732,8 @@ var object = {}; if (options.arrays || options.defaults) object.requests = []; + if (options.objects || options.defaults) + object.labels = {}; if (options.defaults) object.parent = ""; if (message.requests && message.requests.length) { @@ -11513,6 +11743,12 @@ } if (message.parent != null && message.hasOwnProperty("parent")) object.parent = message.parent; + var keys2; + if (message.labels && (keys2 = Object.keys(message.labels)).length) { + object.labels = {}; + for (var j = 0; j < keys2.length; ++j) + object.labels[keys2[j]] = message.labels[keys2[j]]; + } return object; }; diff --git a/packages/google-cloud-vision/protos/protos.json b/packages/google-cloud-vision/protos/protos.json index 394efedb024..fc7c98379ba 100644 --- a/packages/google-cloud-vision/protos/protos.json +++ b/packages/google-cloud-vision/protos/protos.json @@ -613,7 +613,10 @@ "fields": { "includeGeoResults": { "type": "bool", - "id": 2 + "id": 2, + "options": { + "deprecated": true + } } } }, @@ -767,6 +770,14 @@ "parent": { "type": "string", "id": 4 + }, + "labels": { + "keyType": "string", + "type": "string", + "id": 5, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } } } }, @@ -835,6 +846,14 @@ "parent": { "type": "string", "id": 3 + }, + "labels": { + "keyType": "string", + "type": "string", + "id": 5, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } } } }, @@ -896,6 +915,14 @@ "parent": { "type": "string", "id": 4 + }, + "labels": { + "keyType": "string", + "type": "string", + "id": 5, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } } } }, @@ -920,6 +947,14 @@ "parent": { "type": "string", "id": 4 + }, + "labels": { + "keyType": "string", + "type": "string", + "id": 5, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } } } }, diff --git a/packages/google-cloud-vision/samples/generated/v1/image_annotator.async_batch_annotate_files.js b/packages/google-cloud-vision/samples/generated/v1/image_annotator.async_batch_annotate_files.js index bf4eac97c61..e4ab1f3d989 100644 --- a/packages/google-cloud-vision/samples/generated/v1/image_annotator.async_batch_annotate_files.js +++ b/packages/google-cloud-vision/samples/generated/v1/image_annotator.async_batch_annotate_files.js @@ -43,6 +43,14 @@ function main(requests) { * Example: `projects/project-A/locations/eu`. */ // const parent = 'abc123' + /** + * Optional. The labels with user-defined metadata for the request. + * Label keys and values can be no longer than 63 characters + * (Unicode codepoints), can only contain lowercase letters, numeric + * characters, underscores and dashes. International characters are allowed. + * Label values are optional. Label keys must start with a letter. + */ + // const labels = [1,2,3,4] // Imports the Vision library const {ImageAnnotatorClient} = require('@google-cloud/vision').v1; diff --git a/packages/google-cloud-vision/samples/generated/v1/image_annotator.async_batch_annotate_images.js b/packages/google-cloud-vision/samples/generated/v1/image_annotator.async_batch_annotate_images.js index 38aa6d7f701..800ecbdcca2 100644 --- a/packages/google-cloud-vision/samples/generated/v1/image_annotator.async_batch_annotate_images.js +++ b/packages/google-cloud-vision/samples/generated/v1/image_annotator.async_batch_annotate_images.js @@ -47,6 +47,14 @@ function main(requests, outputConfig) { * Example: `projects/project-A/locations/eu`. */ // const parent = 'abc123' + /** + * Optional. The labels with user-defined metadata for the request. + * Label keys and values can be no longer than 63 characters + * (Unicode codepoints), can only contain lowercase letters, numeric + * characters, underscores and dashes. International characters are allowed. + * Label values are optional. Label keys must start with a letter. + */ + // const labels = [1,2,3,4] // Imports the Vision library const {ImageAnnotatorClient} = require('@google-cloud/vision').v1; diff --git a/packages/google-cloud-vision/samples/generated/v1/image_annotator.batch_annotate_files.js b/packages/google-cloud-vision/samples/generated/v1/image_annotator.batch_annotate_files.js index 868788d4031..57bacd7fcf5 100644 --- a/packages/google-cloud-vision/samples/generated/v1/image_annotator.batch_annotate_files.js +++ b/packages/google-cloud-vision/samples/generated/v1/image_annotator.batch_annotate_files.js @@ -29,8 +29,8 @@ function main(requests) { * TODO(developer): Uncomment these variables before running the sample. */ /** - * Required. The list of file annotation requests. Right now we support only one - * AnnotateFileRequest in BatchAnnotateFilesRequest. + * Required. The list of file annotation requests. Right now we support only + * one AnnotateFileRequest in BatchAnnotateFilesRequest. */ // const requests = [1,2,3,4] /** @@ -44,6 +44,14 @@ function main(requests) { * Example: `projects/project-A/locations/eu`. */ // const parent = 'abc123' + /** + * Optional. The labels with user-defined metadata for the request. + * Label keys and values can be no longer than 63 characters + * (Unicode codepoints), can only contain lowercase letters, numeric + * characters, underscores and dashes. International characters are allowed. + * Label values are optional. Label keys must start with a letter. + */ + // const labels = [1,2,3,4] // Imports the Vision library const {ImageAnnotatorClient} = require('@google-cloud/vision').v1; diff --git a/packages/google-cloud-vision/samples/generated/v1/image_annotator.batch_annotate_images.js b/packages/google-cloud-vision/samples/generated/v1/image_annotator.batch_annotate_images.js index 3a92d2d555b..8d6366c0678 100644 --- a/packages/google-cloud-vision/samples/generated/v1/image_annotator.batch_annotate_images.js +++ b/packages/google-cloud-vision/samples/generated/v1/image_annotator.batch_annotate_images.js @@ -43,6 +43,14 @@ function main(requests) { * Example: `projects/project-A/locations/eu`. */ // const parent = 'abc123' + /** + * Optional. The labels with user-defined metadata for the request. + * Label keys and values can be no longer than 63 characters + * (Unicode codepoints), can only contain lowercase letters, numeric + * characters, underscores and dashes. International characters are allowed. + * Label values are optional. Label keys must start with a letter. + */ + // const labels = [1,2,3,4] // Imports the Vision library const {ImageAnnotatorClient} = require('@google-cloud/vision').v1; diff --git a/packages/google-cloud-vision/samples/generated/v1/product_search.create_reference_image.js b/packages/google-cloud-vision/samples/generated/v1/product_search.create_reference_image.js index 6f2a7113c97..45878fb1e92 100644 --- a/packages/google-cloud-vision/samples/generated/v1/product_search.create_reference_image.js +++ b/packages/google-cloud-vision/samples/generated/v1/product_search.create_reference_image.js @@ -29,7 +29,8 @@ function main(parent, referenceImage) { * TODO(developer): Uncomment these variables before running the sample. */ /** - * Required. Resource name of the product in which to create the reference image. + * Required. Resource name of the product in which to create the reference + * image. * Format is * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. */ diff --git a/packages/google-cloud-vision/samples/generated/v1/product_search.list_product_sets.js b/packages/google-cloud-vision/samples/generated/v1/product_search.list_product_sets.js index 4d63f300637..67472600a9a 100644 --- a/packages/google-cloud-vision/samples/generated/v1/product_search.list_product_sets.js +++ b/packages/google-cloud-vision/samples/generated/v1/product_search.list_product_sets.js @@ -55,7 +55,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listProductSetsAsync(request); + const iterable = visionClient.listProductSetsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1/product_search.list_products.js b/packages/google-cloud-vision/samples/generated/v1/product_search.list_products.js index 315bb180927..2566b66446f 100644 --- a/packages/google-cloud-vision/samples/generated/v1/product_search.list_products.js +++ b/packages/google-cloud-vision/samples/generated/v1/product_search.list_products.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listProductsAsync(request); + const iterable = visionClient.listProductsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1/product_search.list_products_in_product_set.js b/packages/google-cloud-vision/samples/generated/v1/product_search.list_products_in_product_set.js index f67f85138b8..7592279e483 100644 --- a/packages/google-cloud-vision/samples/generated/v1/product_search.list_products_in_product_set.js +++ b/packages/google-cloud-vision/samples/generated/v1/product_search.list_products_in_product_set.js @@ -56,7 +56,7 @@ function main(name) { }; // Run request - const iterable = await visionClient.listProductsInProductSetAsync(request); + const iterable = visionClient.listProductsInProductSetAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1/product_search.list_reference_images.js b/packages/google-cloud-vision/samples/generated/v1/product_search.list_reference_images.js index b42f5b022ef..183fd428307 100644 --- a/packages/google-cloud-vision/samples/generated/v1/product_search.list_reference_images.js +++ b/packages/google-cloud-vision/samples/generated/v1/product_search.list_reference_images.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listReferenceImagesAsync(request); + const iterable = visionClient.listReferenceImagesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1/product_search.remove_product_from_product_set.js b/packages/google-cloud-vision/samples/generated/v1/product_search.remove_product_from_product_set.js index d10ae651103..576f0ba3a1f 100644 --- a/packages/google-cloud-vision/samples/generated/v1/product_search.remove_product_from_product_set.js +++ b/packages/google-cloud-vision/samples/generated/v1/product_search.remove_product_from_product_set.js @@ -35,7 +35,8 @@ function main(name, product) { */ // const name = 'abc123' /** - * Required. The resource name for the Product to be removed from this ProductSet. + * Required. The resource name for the Product to be removed from this + * ProductSet. * Format is: * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` */ diff --git a/packages/google-cloud-vision/samples/generated/v1/snippet_metadata_google.cloud.vision.v1.json b/packages/google-cloud-vision/samples/generated/v1/snippet_metadata_google.cloud.vision.v1.json index a487a3c6c5f..53a69c269e4 100644 --- a/packages/google-cloud-vision/samples/generated/v1/snippet_metadata_google.cloud.vision.v1.json +++ b/packages/google-cloud-vision/samples/generated/v1/snippet_metadata_google.cloud.vision.v1.json @@ -22,7 +22,7 @@ "segments": [ { "start": 25, - "end": 64, + "end": 72, "type": "FULL" } ], @@ -38,6 +38,10 @@ { "name": "parent", "type": "TYPE_STRING" + }, + { + "name": "labels", + "type": "TYPE_MESSAGE[]" } ], "resultType": ".google.cloud.vision.v1.BatchAnnotateImagesResponse", @@ -66,7 +70,7 @@ "segments": [ { "start": 25, - "end": 65, + "end": 73, "type": "FULL" } ], @@ -82,6 +86,10 @@ { "name": "parent", "type": "TYPE_STRING" + }, + { + "name": "labels", + "type": "TYPE_MESSAGE[]" } ], "resultType": ".google.cloud.vision.v1.BatchAnnotateFilesResponse", @@ -110,7 +118,7 @@ "segments": [ { "start": 25, - "end": 70, + "end": 78, "type": "FULL" } ], @@ -130,6 +138,10 @@ { "name": "parent", "type": "TYPE_STRING" + }, + { + "name": "labels", + "type": "TYPE_MESSAGE[]" } ], "resultType": ".google.longrunning.Operation", @@ -158,7 +170,7 @@ "segments": [ { "start": 25, - "end": 65, + "end": 73, "type": "FULL" } ], @@ -174,6 +186,10 @@ { "name": "parent", "type": "TYPE_STRING" + }, + { + "name": "labels", + "type": "TYPE_MESSAGE[]" } ], "resultType": ".google.longrunning.Operation", @@ -642,7 +658,7 @@ "segments": [ { "start": 25, - "end": 68, + "end": 69, "type": "FULL" } ], @@ -862,7 +878,7 @@ "segments": [ { "start": 25, - "end": 62, + "end": 63, "type": "FULL" } ], diff --git a/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_product_sets.js b/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_product_sets.js index 2d254d4bd5f..b6462e98bf9 100644 --- a/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_product_sets.js +++ b/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_product_sets.js @@ -55,7 +55,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listProductSetsAsync(request); + const iterable = visionClient.listProductSetsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_products.js b/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_products.js index 4f75aee42e3..878f16fb9f2 100644 --- a/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_products.js +++ b/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_products.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listProductsAsync(request); + const iterable = visionClient.listProductsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_products_in_product_set.js b/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_products_in_product_set.js index 9ee5657ddf4..9de670e770b 100644 --- a/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_products_in_product_set.js +++ b/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_products_in_product_set.js @@ -56,7 +56,7 @@ function main(name) { }; // Run request - const iterable = await visionClient.listProductsInProductSetAsync(request); + const iterable = visionClient.listProductsInProductSetAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_reference_images.js b/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_reference_images.js index f0e6094f1ac..69dd72dc990 100644 --- a/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_reference_images.js +++ b/packages/google-cloud-vision/samples/generated/v1p3beta1/product_search.list_reference_images.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listReferenceImagesAsync(request); + const iterable = visionClient.listReferenceImagesAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_product_sets.js b/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_product_sets.js index ec99348db59..4f130fa35b9 100644 --- a/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_product_sets.js +++ b/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_product_sets.js @@ -55,7 +55,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listProductSetsAsync(request); + const iterable = visionClient.listProductSetsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_products.js b/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_products.js index 67c9fd2d2fa..b4193f53c83 100644 --- a/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_products.js +++ b/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_products.js @@ -56,7 +56,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listProductsAsync(request); + const iterable = visionClient.listProductsAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_products_in_product_set.js b/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_products_in_product_set.js index a8fe0b5d81b..fee33dfaed8 100644 --- a/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_products_in_product_set.js +++ b/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_products_in_product_set.js @@ -56,7 +56,7 @@ function main(name) { }; // Run request - const iterable = await visionClient.listProductsInProductSetAsync(request); + const iterable = visionClient.listProductsInProductSetAsync(request); for await (const response of iterable) { console.log(response); } diff --git a/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_reference_images.js b/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_reference_images.js index 0fe26ad774b..4f8f772bbaa 100644 --- a/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_reference_images.js +++ b/packages/google-cloud-vision/samples/generated/v1p4beta1/product_search.list_reference_images.js @@ -58,7 +58,7 @@ function main(parent) { }; // Run request - const iterable = await visionClient.listReferenceImagesAsync(request); + const iterable = visionClient.listReferenceImagesAsync(request); for await (const response of iterable) { console.log(response); } 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 bd7741518bc..36c61e987b3 100644 --- a/packages/google-cloud-vision/src/v1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1/image_annotator_client.ts @@ -29,6 +29,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/image_annotator_client_config.json`. @@ -52,6 +53,8 @@ export class ImageAnnotatorClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -110,8 +113,20 @@ export class ImageAnnotatorClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ImageAnnotatorClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'vision.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -126,7 +141,7 @@ export class ImageAnnotatorClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -151,10 +166,10 @@ export class ImageAnnotatorClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -336,21 +351,52 @@ export class ImageAnnotatorClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. @@ -410,6 +456,13 @@ export class ImageAnnotatorClient { * `eu`: The European Union. * * Example: `projects/project-A/locations/eu`. + * @param {number[]} [request.labels] + * Optional. The labels with user-defined metadata for the request. + * + * Label keys and values can be no longer than 63 characters + * (Unicode codepoints), can only contain lowercase letters, numeric + * characters, underscores and dashes. International characters are allowed. + * Label values are optional. Label keys must start with a letter. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. @@ -505,8 +558,8 @@ export class ImageAnnotatorClient { * @param {Object} request * The request object that will be sent. * @param {number[]} request.requests - * Required. The list of file annotation requests. Right now we support only one - * AnnotateFileRequest in BatchAnnotateFilesRequest. + * Required. The list of file annotation requests. Right now we support only + * one AnnotateFileRequest in BatchAnnotateFilesRequest. * @param {string} request.parent * Optional. Target project and location to make a call. * @@ -520,6 +573,13 @@ export class ImageAnnotatorClient { * `eu`: The European Union. * * Example: `projects/project-A/locations/eu`. + * @param {number[]} [request.labels] + * Optional. The labels with user-defined metadata for the request. + * + * Label keys and values can be no longer than 63 characters + * (Unicode codepoints), can only contain lowercase letters, numeric + * characters, underscores and dashes. International characters are allowed. + * Label values are optional. Label keys must start with a letter. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. @@ -634,6 +694,13 @@ export class ImageAnnotatorClient { * `eu`: The European Union. * * Example: `projects/project-A/locations/eu`. + * @param {number[]} [request.labels] + * Optional. The labels with user-defined metadata for the request. + * + * Label keys and values can be no longer than 63 characters + * (Unicode codepoints), can only contain lowercase letters, numeric + * characters, underscores and dashes. International characters are allowed. + * Label values are optional. Label keys must start with a letter. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. @@ -792,6 +859,13 @@ export class ImageAnnotatorClient { * `eu`: The European Union. * * Example: `projects/project-A/locations/eu`. + * @param {number[]} [request.labels] + * Optional. The labels with user-defined metadata for the request. + * + * Label keys and values can be no longer than 63 characters + * (Unicode codepoints), can only contain lowercase letters, numeric + * characters, underscores and dashes. International characters are allowed. + * Label values are optional. Label keys must start with a letter. * @param {object} [options] * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. * @returns {Promise} - The promise which resolves to an array. @@ -925,6 +999,181 @@ export class ImageAnnotatorClient { protos.google.cloud.vision.v1.OperationMetadata >; } + /** + * Gets the latest state of a long-running operation. Clients can use this + * method to poll the operation result at intervals as recommended by the API + * service. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See {@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} + * for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing + * {@link google.longrunning.Operation | google.longrunning.Operation}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing + * {@link google.longrunning.Operation | google.longrunning.Operation}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * const name = ''; + * const [response] = await client.getOperation({name}); + * // doThingsWith(response) + * ``` + */ + getOperation( + request: protos.google.longrunning.GetOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.longrunning.Operation, + protos.google.longrunning.GetOperationRequest, + {} | null | undefined + >, + callback?: Callback< + protos.google.longrunning.Operation, + protos.google.longrunning.GetOperationRequest, + {} | null | undefined + > + ): Promise<[protos.google.longrunning.Operation]> { + return this.operationsClient.getOperation(request, options, callback); + } + /** + * Lists operations that match the specified filter in the request. If the + * server doesn't support this method, it returns `UNIMPLEMENTED`. 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 - The name of the operation collection. + * @param {string} request.filter - The standard list filter. + * @param {number=} request.pageSize - + * The maximum number of resources contained in the underlying API + * response. If page streaming is performed per-resource, this + * parameter does not affect the return value. If page streaming is + * performed per-page, this determines the maximum number of + * resources in a page. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See {@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the + * details. + * @returns {Object} + * An iterable Object that conforms to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | iteration protocols}. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * for await (const response of client.listOperationsAsync(request)); + * // doThingsWith(response) + * ``` + */ + listOperationsAsync( + request: protos.google.longrunning.ListOperationsRequest, + options?: gax.CallOptions + ): AsyncIterable { + return this.operationsClient.listOperationsAsync(request, options); + } + /** + * Starts asynchronous cancellation on a long-running operation. The server + * makes a best effort to cancel the operation, but success is not + * guaranteed. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. Clients can use + * {@link Operations.GetOperation} or + * other methods to check whether the cancellation succeeded or whether the + * operation completed despite cancellation. On successful cancellation, + * the operation is not deleted; instead, it becomes an operation with + * an {@link Operation.error} value with a {@link google.rpc.Status.code} of + * 1, corresponding to `Code.CANCELLED`. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource to be cancelled. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See {@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the + * details. + * @param {function(?Error)=} callback + * The function which will be called with the result of the API call. + * @return {Promise} - The promise which resolves when API call finishes. + * The promise has a method named "cancel" which cancels the ongoing API + * call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * await client.cancelOperation({name: ''}); + * ``` + */ + cancelOperation( + request: protos.google.longrunning.CancelOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.CancelOperationRequest, + {} | undefined | null + >, + callback?: Callback< + protos.google.longrunning.CancelOperationRequest, + protos.google.protobuf.Empty, + {} | undefined | null + > + ): Promise { + return this.operationsClient.cancelOperation(request, options, callback); + } + + /** + * Deletes a long-running operation. This method indicates that the client is + * no longer interested in the operation result. It does not cancel the + * operation. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource to be deleted. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See {@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} + * for the details. + * @param {function(?Error)=} callback + * The function which will be called with the result of the API call. + * @return {Promise} - The promise which resolves when API call finishes. + * The promise has a method named "cancel" which cancels the ongoing API + * call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * await client.deleteOperation({name: ''}); + * ``` + */ + deleteOperation( + request: protos.google.longrunning.DeleteOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.DeleteOperationRequest, + {} | null | undefined + >, + callback?: Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.DeleteOperationRequest, + {} | null | undefined + > + ): Promise { + return this.operationsClient.deleteOperation(request, options, callback); + } + // -------------------- // -- Path templates -- // -------------------- 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 201ed2af9b2..7eed1b55e57 100644 --- a/packages/google-cloud-vision/src/v1/product_search_client.ts +++ b/packages/google-cloud-vision/src/v1/product_search_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1/product_search_client_config.json`. @@ -43,16 +44,18 @@ const version = require('../../../package.json').version; * Manages Products and ProductSets of reference images for use in product * search. It uses the following resource model: * - * - The API has a collection of {@link protos.google.cloud.vision.v1.ProductSet|ProductSet} resources, named - * `projects/* /locations/* /productSets/*`, which acts as a way to put different - * products into groups to limit identification. + * - The API has a collection of {@link protos.google.cloud.vision.v1.ProductSet|ProductSet} + * resources, named `projects/* /locations/* /productSets/*`, which acts as a way + * to put different products into groups to limit identification. * * In parallel, * - * - The API has a collection of {@link protos.google.cloud.vision.v1.Product|Product} resources, named + * - The API has a collection of {@link protos.google.cloud.vision.v1.Product|Product} + * resources, named * `projects/* /locations/* /products/*` * - * - Each {@link protos.google.cloud.vision.v1.Product|Product} has a collection of {@link protos.google.cloud.vision.v1.ReferenceImage|ReferenceImage} resources, named + * - Each {@link protos.google.cloud.vision.v1.Product|Product} has a collection of + * {@link protos.google.cloud.vision.v1.ReferenceImage|ReferenceImage} resources, named * `projects/* /locations/* /products/* /referenceImages/*` * @class * @memberof v1 @@ -65,6 +68,8 @@ export class ProductSearchClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -123,8 +128,20 @@ export class ProductSearchClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ProductSearchClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'vision.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -139,7 +156,7 @@ export class ProductSearchClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -164,10 +181,10 @@ export class ProductSearchClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -388,21 +405,52 @@ export class ProductSearchClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. @@ -1227,7 +1275,8 @@ export class ProductSearchClient { * @param {Object} request * The request object that will be sent. * @param {string} request.parent - * Required. Resource name of the product in which to create the reference image. + * Required. Resource name of the product in which to create the reference + * image. * * Format is * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID`. @@ -1638,7 +1687,8 @@ export class ProductSearchClient { * Format is: * `projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` * @param {string} request.product - * Required. The resource name for the Product to be removed from this ProductSet. + * Required. The resource name for the Product to be removed from this + * ProductSet. * * Format is: * `projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` @@ -1740,8 +1790,8 @@ export class ProductSearchClient { * Asynchronous API that imports a list of reference images to specified * product sets based on a list of image information. * - * The {@link protos.google.longrunning.Operation|google.longrunning.Operation} API can be used to keep track of the - * progress and results of the request. + * The {@link protos.google.longrunning.Operation|google.longrunning.Operation} API can be + * used to keep track of the progress and results of the request. * `Operation.metadata` contains `BatchOperationMetadata`. (progress) * `Operation.response` contains `ImportProductSetsResponse`. (results) * @@ -1908,8 +1958,8 @@ export class ProductSearchClient { * ProductSet, you must wait until the PurgeProducts operation has finished * for that ProductSet. * - * The {@link protos.google.longrunning.Operation|google.longrunning.Operation} API can be used to keep track of the - * progress and results of the request. + * The {@link protos.google.longrunning.Operation|google.longrunning.Operation} API can be + * used to keep track of the progress and results of the request. * `Operation.metadata` contains `BatchOperationMetadata`. (progress) * * @param {Object} request @@ -2854,6 +2904,181 @@ export class ProductSearchClient { callSettings ) as AsyncIterable; } + /** + * Gets the latest state of a long-running operation. Clients can use this + * method to poll the operation result at intervals as recommended by the API + * service. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See {@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} + * for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing + * {@link google.longrunning.Operation | google.longrunning.Operation}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing + * {@link google.longrunning.Operation | google.longrunning.Operation}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * const name = ''; + * const [response] = await client.getOperation({name}); + * // doThingsWith(response) + * ``` + */ + getOperation( + request: protos.google.longrunning.GetOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.longrunning.Operation, + protos.google.longrunning.GetOperationRequest, + {} | null | undefined + >, + callback?: Callback< + protos.google.longrunning.Operation, + protos.google.longrunning.GetOperationRequest, + {} | null | undefined + > + ): Promise<[protos.google.longrunning.Operation]> { + return this.operationsClient.getOperation(request, options, callback); + } + /** + * Lists operations that match the specified filter in the request. If the + * server doesn't support this method, it returns `UNIMPLEMENTED`. 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 - The name of the operation collection. + * @param {string} request.filter - The standard list filter. + * @param {number=} request.pageSize - + * The maximum number of resources contained in the underlying API + * response. If page streaming is performed per-resource, this + * parameter does not affect the return value. If page streaming is + * performed per-page, this determines the maximum number of + * resources in a page. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See {@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the + * details. + * @returns {Object} + * An iterable Object that conforms to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | iteration protocols}. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * for await (const response of client.listOperationsAsync(request)); + * // doThingsWith(response) + * ``` + */ + listOperationsAsync( + request: protos.google.longrunning.ListOperationsRequest, + options?: gax.CallOptions + ): AsyncIterable { + return this.operationsClient.listOperationsAsync(request, options); + } + /** + * Starts asynchronous cancellation on a long-running operation. The server + * makes a best effort to cancel the operation, but success is not + * guaranteed. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. Clients can use + * {@link Operations.GetOperation} or + * other methods to check whether the cancellation succeeded or whether the + * operation completed despite cancellation. On successful cancellation, + * the operation is not deleted; instead, it becomes an operation with + * an {@link Operation.error} value with a {@link google.rpc.Status.code} of + * 1, corresponding to `Code.CANCELLED`. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource to be cancelled. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See {@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the + * details. + * @param {function(?Error)=} callback + * The function which will be called with the result of the API call. + * @return {Promise} - The promise which resolves when API call finishes. + * The promise has a method named "cancel" which cancels the ongoing API + * call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * await client.cancelOperation({name: ''}); + * ``` + */ + cancelOperation( + request: protos.google.longrunning.CancelOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.CancelOperationRequest, + {} | undefined | null + >, + callback?: Callback< + protos.google.longrunning.CancelOperationRequest, + protos.google.protobuf.Empty, + {} | undefined | null + > + ): Promise { + return this.operationsClient.cancelOperation(request, options, callback); + } + + /** + * Deletes a long-running operation. This method indicates that the client is + * no longer interested in the operation result. It does not cancel the + * operation. If the server doesn't support this method, it returns + * `google.rpc.Code.UNIMPLEMENTED`. + * + * @param {Object} request - The request object that will be sent. + * @param {string} request.name - The name of the operation resource to be deleted. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, + * e.g, timeout, retries, paginations, etc. See {@link + * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} + * for the details. + * @param {function(?Error)=} callback + * The function which will be called with the result of the API call. + * @return {Promise} - The promise which resolves when API call finishes. + * The promise has a method named "cancel" which cancels the ongoing API + * call. + * + * @example + * ``` + * const client = longrunning.operationsClient(); + * await client.deleteOperation({name: ''}); + * ``` + */ + deleteOperation( + request: protos.google.longrunning.DeleteOperationRequest, + options?: + | gax.CallOptions + | Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.DeleteOperationRequest, + {} | null | undefined + >, + callback?: Callback< + protos.google.protobuf.Empty, + protos.google.longrunning.DeleteOperationRequest, + {} | null | undefined + > + ): Promise { + return this.operationsClient.deleteOperation(request, options, callback); + } + // -------------------- // -- Path templates -- // -------------------- 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 512e8185da2..01213b5a7e9 100644 --- a/packages/google-cloud-vision/src/v1p1beta1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1p1beta1/image_annotator_client.ts @@ -27,6 +27,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1p1beta1/image_annotator_client_config.json`. @@ -50,6 +51,8 @@ export class ImageAnnotatorClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -106,8 +109,20 @@ export class ImageAnnotatorClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ImageAnnotatorClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'vision.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -122,7 +137,7 @@ export class ImageAnnotatorClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -147,10 +162,10 @@ export class ImageAnnotatorClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -253,21 +268,52 @@ export class ImageAnnotatorClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. 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 1ade94e9a99..e8e3e037616 100644 --- a/packages/google-cloud-vision/src/v1p2beta1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1p2beta1/image_annotator_client.ts @@ -29,6 +29,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1p2beta1/image_annotator_client_config.json`. @@ -52,6 +53,8 @@ export class ImageAnnotatorClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -109,8 +112,20 @@ export class ImageAnnotatorClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ImageAnnotatorClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'vision.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -125,7 +140,7 @@ export class ImageAnnotatorClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -150,10 +165,10 @@ export class ImageAnnotatorClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -293,21 +308,52 @@ export class ImageAnnotatorClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. 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 c40ad826215..e4df3d8d3ac 100644 --- a/packages/google-cloud-vision/src/v1p3beta1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1p3beta1/image_annotator_client.ts @@ -29,6 +29,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1p3beta1/image_annotator_client_config.json`. @@ -52,6 +53,8 @@ export class ImageAnnotatorClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -110,8 +113,20 @@ export class ImageAnnotatorClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ImageAnnotatorClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'vision.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -126,7 +141,7 @@ export class ImageAnnotatorClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -151,10 +166,10 @@ export class ImageAnnotatorClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -309,21 +324,52 @@ export class ImageAnnotatorClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. 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 1cf688ecf0a..6852d1a00d8 100644 --- a/packages/google-cloud-vision/src/v1p3beta1/product_search_client.ts +++ b/packages/google-cloud-vision/src/v1p3beta1/product_search_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1p3beta1/product_search_client_config.json`. @@ -65,6 +66,8 @@ export class ProductSearchClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -123,8 +126,20 @@ export class ProductSearchClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ProductSearchClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'vision.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -139,7 +154,7 @@ export class ProductSearchClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -164,10 +179,10 @@ export class ProductSearchClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -366,21 +381,52 @@ export class ProductSearchClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. 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 ad5e69c81ab..cc582b70b43 100644 --- a/packages/google-cloud-vision/src/v1p4beta1/image_annotator_client.ts +++ b/packages/google-cloud-vision/src/v1p4beta1/image_annotator_client.ts @@ -29,6 +29,7 @@ import type { import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1p4beta1/image_annotator_client_config.json`. @@ -52,6 +53,8 @@ export class ImageAnnotatorClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -110,8 +113,20 @@ export class ImageAnnotatorClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ImageAnnotatorClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'vision.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -126,7 +141,7 @@ export class ImageAnnotatorClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -151,10 +166,10 @@ export class ImageAnnotatorClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -326,21 +341,52 @@ export class ImageAnnotatorClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. 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 679b0587c3e..d2e233c1559 100644 --- a/packages/google-cloud-vision/src/v1p4beta1/product_search_client.ts +++ b/packages/google-cloud-vision/src/v1p4beta1/product_search_client.ts @@ -31,6 +31,7 @@ import type { import {Transform} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); + /** * Client JSON configuration object, loaded from * `src/v1p4beta1/product_search_client_config.json`. @@ -69,6 +70,8 @@ export class ProductSearchClient { private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; auth: gax.GoogleAuth; descriptors: Descriptors = { page: {}, @@ -127,8 +130,20 @@ export class ProductSearchClient { ) { // Ensure that options include all the required fields. const staticMembers = this.constructor as typeof ProductSearchClient; + if ( + opts?.universe_domain && + opts?.universeDomain && + opts?.universe_domain !== opts?.universeDomain + ) { + throw new Error( + 'Please set either universe_domain or universeDomain, but not both.' + ); + } + this._universeDomain = + opts?.universeDomain ?? opts?.universe_domain ?? 'googleapis.com'; + this._servicePath = 'vision.' + this._universeDomain; const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + opts?.servicePath || opts?.apiEndpoint || this._servicePath; this._providedCustomServicePath = !!( opts?.servicePath || opts?.apiEndpoint ); @@ -143,7 +158,7 @@ export class ProductSearchClient { opts.numericEnums = true; // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + if (servicePath !== this._servicePath && !('scopes' in opts)) { opts['scopes'] = staticMembers.scopes; } @@ -168,10 +183,10 @@ export class ProductSearchClient { this.auth.useJWTAccessWithScope = true; // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; + this.auth.defaultServicePath = this._servicePath; // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { + if (servicePath === this._servicePath) { this.auth.defaultScopes = staticMembers.scopes; } @@ -382,21 +397,52 @@ export class ProductSearchClient { /** * The DNS address for this API service. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get servicePath() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static servicePath is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. + * The DNS address for this API service - same as servicePath. + * @deprecated Use the apiEndpoint method of the client instance. * @returns {string} The DNS address for this service. */ static get apiEndpoint() { + if ( + typeof process !== undefined && + typeof process.emitWarning === 'function' + ) { + process.emitWarning( + 'Static apiEndpoint is deprecated, please use the instance method instead.', + 'DeprecationWarning' + ); + } return 'vision.googleapis.com'; } + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + get apiEndpoint() { + return this._servicePath; + } + + get universeDomain() { + return this._universeDomain; + } + /** * The port for this API service. * @returns {number} The default port for this service. diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1.ts index 8c88c741c50..fd744f00662 100644 --- a/packages/google-cloud-vision/test/gapic_image_annotator_v1.ts +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1.ts @@ -96,18 +96,87 @@ function stubLongRunningCallWithCallback( : sinon.stub().callsArgWith(2, null, mockOperation); } +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.ImageAnnotatorClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1.ImageAnnotatorClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + imageannotatorModule.v1.ImageAnnotatorClient.servicePath; + assert.strictEqual(servicePath, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + imageannotatorModule.v1.ImageAnnotatorClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new imageannotatorModule.v1.ImageAnnotatorClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { @@ -853,6 +922,311 @@ describe('v1.ImageAnnotatorClient', () => { assert((client.operationsClient.getOperation as SinonStub).getCall(0)); }); }); + describe('getOperation', () => { + it('invokes getOperation without error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new operationsProtos.google.longrunning.Operation() + ); + client.operationsClient.getOperation = stubSimpleCall(expectedResponse); + const response = await client.getOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.getOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes getOperation without error using callback', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new operationsProtos.google.longrunning.Operation() + ); + client.operationsClient.getOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.getOperation( + request, + undefined, + ( + err?: Error | null, + result?: operationsProtos.google.longrunning.Operation | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.getOperation as SinonStub).getCall(0)); + }); + it('invokes getOperation with error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.getOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.getOperation(request); + }, expectedError); + assert( + (client.operationsClient.getOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('cancelOperation', () => { + it('invokes cancelOperation without error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.cancelOperation = + stubSimpleCall(expectedResponse); + const response = await client.cancelOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.cancelOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes cancelOperation without error using callback', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.cancelOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.cancelOperation( + request, + undefined, + ( + err?: Error | null, + result?: protos.google.protobuf.Empty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.cancelOperation as SinonStub).getCall(0)); + }); + it('invokes cancelOperation with error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.cancelOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.cancelOperation(request); + }, expectedError); + assert( + (client.operationsClient.cancelOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('deleteOperation', () => { + it('invokes deleteOperation without error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.deleteOperation = + stubSimpleCall(expectedResponse); + const response = await client.deleteOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.deleteOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes deleteOperation without error using callback', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.deleteOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.deleteOperation( + request, + undefined, + ( + err?: Error | null, + result?: protos.google.protobuf.Empty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.deleteOperation as SinonStub).getCall(0)); + }); + it('invokes deleteOperation with error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.deleteOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.deleteOperation(request); + }, expectedError); + assert( + (client.operationsClient.deleteOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('listOperationsAsync', () => { + it('uses async iteration with listOperations without error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsRequest() + ); + const expectedResponse = [ + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + ]; + client.operationsClient.descriptor.listOperations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: operationsProtos.google.longrunning.ListOperationsResponse[] = + []; + const iterable = client.operationsClient.listOperationsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + ( + client.operationsClient.descriptor.listOperations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request + ); + }); + it('uses async iteration with listOperations with error', async () => { + const client = new imageannotatorModule.v1.ImageAnnotatorClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.descriptor.listOperations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.operationsClient.listOperationsAsync(request); + await assert.rejects(async () => { + const responses: operationsProtos.google.longrunning.ListOperationsResponse[] = + []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.operationsClient.descriptor.listOperations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request + ); + }); + }); describe('Path templates', () => { describe('product', () => { diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1p1beta1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1p1beta1.ts index a126c3c2c58..eeca9cc3d0e 100644 --- a/packages/google-cloud-vision/test/gapic_image_annotator_v1p1beta1.ts +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1p1beta1.ts @@ -66,16 +66,62 @@ function stubSimpleCallWithCallback( describe('v1p1beta1.ImageAnnotatorClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1p1beta1.ImageAnnotatorClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1p1beta1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + imageannotatorModule.v1p1beta1.ImageAnnotatorClient.servicePath; + assert.strictEqual(servicePath, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + imageannotatorModule.v1p1beta1.ImageAnnotatorClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new imageannotatorModule.v1p1beta1.ImageAnnotatorClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1p2beta1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1p2beta1.ts index b2730220269..d5028946808 100644 --- a/packages/google-cloud-vision/test/gapic_image_annotator_v1p2beta1.ts +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1p2beta1.ts @@ -98,16 +98,62 @@ function stubLongRunningCallWithCallback( describe('v1p2beta1.ImageAnnotatorClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1p2beta1.ImageAnnotatorClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1p2beta1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + imageannotatorModule.v1p2beta1.ImageAnnotatorClient.servicePath; + assert.strictEqual(servicePath, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + imageannotatorModule.v1p2beta1.ImageAnnotatorClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new imageannotatorModule.v1p2beta1.ImageAnnotatorClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1p3beta1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1p3beta1.ts index a0ea15ee0cf..b3826b8d2de 100644 --- a/packages/google-cloud-vision/test/gapic_image_annotator_v1p3beta1.ts +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1p3beta1.ts @@ -98,16 +98,62 @@ function stubLongRunningCallWithCallback( describe('v1p3beta1.ImageAnnotatorClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1p3beta1.ImageAnnotatorClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1p3beta1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + imageannotatorModule.v1p3beta1.ImageAnnotatorClient.servicePath; + assert.strictEqual(servicePath, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + imageannotatorModule.v1p3beta1.ImageAnnotatorClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new imageannotatorModule.v1p3beta1.ImageAnnotatorClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-vision/test/gapic_image_annotator_v1p4beta1.ts b/packages/google-cloud-vision/test/gapic_image_annotator_v1p4beta1.ts index 07c96f52629..f6332a51b79 100644 --- a/packages/google-cloud-vision/test/gapic_image_annotator_v1p4beta1.ts +++ b/packages/google-cloud-vision/test/gapic_image_annotator_v1p4beta1.ts @@ -98,16 +98,62 @@ function stubLongRunningCallWithCallback( describe('v1p4beta1.ImageAnnotatorClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - imageannotatorModule.v1p4beta1.ImageAnnotatorClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - imageannotatorModule.v1p4beta1.ImageAnnotatorClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + imageannotatorModule.v1p4beta1.ImageAnnotatorClient.servicePath; + assert.strictEqual(servicePath, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + imageannotatorModule.v1p4beta1.ImageAnnotatorClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new imageannotatorModule.v1p4beta1.ImageAnnotatorClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-vision/test/gapic_product_search_v1.ts b/packages/google-cloud-vision/test/gapic_product_search_v1.ts index a04c7a80dc6..25d1e31142f 100644 --- a/packages/google-cloud-vision/test/gapic_product_search_v1.ts +++ b/packages/google-cloud-vision/test/gapic_product_search_v1.ts @@ -161,16 +161,62 @@ function stubAsyncIterationCall( describe('v1.ProductSearchClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - productsearchModule.v1.ProductSearchClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new productsearchModule.v1.ProductSearchClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - productsearchModule.v1.ProductSearchClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new productsearchModule.v1.ProductSearchClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + productsearchModule.v1.ProductSearchClient.servicePath; + assert.strictEqual(servicePath, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + productsearchModule.v1.ProductSearchClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new productsearchModule.v1.ProductSearchClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new productsearchModule.v1.ProductSearchClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new productsearchModule.v1.ProductSearchClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { @@ -3603,6 +3649,311 @@ describe('v1.ProductSearchClient', () => { ); }); }); + describe('getOperation', () => { + it('invokes getOperation without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new operationsProtos.google.longrunning.Operation() + ); + client.operationsClient.getOperation = stubSimpleCall(expectedResponse); + const response = await client.getOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.getOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes getOperation without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new operationsProtos.google.longrunning.Operation() + ); + client.operationsClient.getOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.getOperation( + request, + undefined, + ( + err?: Error | null, + result?: operationsProtos.google.longrunning.Operation | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.getOperation as SinonStub).getCall(0)); + }); + it('invokes getOperation with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.GetOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.getOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.getOperation(request); + }, expectedError); + assert( + (client.operationsClient.getOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('cancelOperation', () => { + it('invokes cancelOperation without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.cancelOperation = + stubSimpleCall(expectedResponse); + const response = await client.cancelOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.cancelOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes cancelOperation without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.cancelOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.cancelOperation( + request, + undefined, + ( + err?: Error | null, + result?: protos.google.protobuf.Empty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.cancelOperation as SinonStub).getCall(0)); + }); + it('invokes cancelOperation with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.CancelOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.cancelOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.cancelOperation(request); + }, expectedError); + assert( + (client.operationsClient.cancelOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('deleteOperation', () => { + it('invokes deleteOperation without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.deleteOperation = + stubSimpleCall(expectedResponse); + const response = await client.deleteOperation(request); + assert.deepStrictEqual(response, [expectedResponse]); + assert( + (client.operationsClient.deleteOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + it('invokes deleteOperation without error using callback', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.operationsClient.deleteOperation = sinon + .stub() + .callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.operationsClient.deleteOperation( + request, + undefined, + ( + err?: Error | null, + result?: protos.google.protobuf.Empty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.operationsClient.deleteOperation as SinonStub).getCall(0)); + }); + it('invokes deleteOperation with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.DeleteOperationRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.deleteOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(async () => { + await client.deleteOperation(request); + }, expectedError); + assert( + (client.operationsClient.deleteOperation as SinonStub) + .getCall(0) + .calledWith(request) + ); + }); + }); + describe('listOperationsAsync', () => { + it('uses async iteration with listOperations without error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsRequest() + ); + const expectedResponse = [ + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsResponse() + ), + ]; + client.operationsClient.descriptor.listOperations.asyncIterate = + stubAsyncIterationCall(expectedResponse); + const responses: operationsProtos.google.longrunning.ListOperationsResponse[] = + []; + const iterable = client.operationsClient.listOperationsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + ( + client.operationsClient.descriptor.listOperations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request + ); + }); + it('uses async iteration with listOperations with error', async () => { + const client = new productsearchModule.v1.ProductSearchClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new operationsProtos.google.longrunning.ListOperationsRequest() + ); + const expectedError = new Error('expected'); + client.operationsClient.descriptor.listOperations.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); + const iterable = client.operationsClient.listOperationsAsync(request); + await assert.rejects(async () => { + const responses: operationsProtos.google.longrunning.ListOperationsResponse[] = + []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + ( + client.operationsClient.descriptor.listOperations + .asyncIterate as SinonStub + ).getCall(0).args[1], + request + ); + }); + }); describe('Path templates', () => { describe('location', () => { diff --git a/packages/google-cloud-vision/test/gapic_product_search_v1p3beta1.ts b/packages/google-cloud-vision/test/gapic_product_search_v1p3beta1.ts index 4f0d978ce7a..30ed0d3ac58 100644 --- a/packages/google-cloud-vision/test/gapic_product_search_v1p3beta1.ts +++ b/packages/google-cloud-vision/test/gapic_product_search_v1p3beta1.ts @@ -161,16 +161,62 @@ function stubAsyncIterationCall( describe('v1p3beta1.ProductSearchClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - productsearchModule.v1p3beta1.ProductSearchClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - productsearchModule.v1p3beta1.ProductSearchClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + productsearchModule.v1p3beta1.ProductSearchClient.servicePath; + assert.strictEqual(servicePath, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + productsearchModule.v1p3beta1.ProductSearchClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new productsearchModule.v1p3beta1.ProductSearchClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new productsearchModule.v1p3beta1.ProductSearchClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => { diff --git a/packages/google-cloud-vision/test/gapic_product_search_v1p4beta1.ts b/packages/google-cloud-vision/test/gapic_product_search_v1p4beta1.ts index 5b7a10dad9c..5203622c97b 100644 --- a/packages/google-cloud-vision/test/gapic_product_search_v1p4beta1.ts +++ b/packages/google-cloud-vision/test/gapic_product_search_v1p4beta1.ts @@ -161,16 +161,62 @@ function stubAsyncIterationCall( describe('v1p4beta1.ProductSearchClient', () => { describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = - productsearchModule.v1p4beta1.ProductSearchClient.servicePath; - assert(servicePath); + it('has apiEndpoint', () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); }); - it('has apiEndpoint', () => { - const apiEndpoint = - productsearchModule.v1p4beta1.ProductSearchClient.apiEndpoint; - assert(apiEndpoint); + it('has universeDomain', () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, 'googleapis.com'); + }); + + if ( + typeof process !== 'undefined' && + typeof process.emitWarning === 'function' + ) { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = + productsearchModule.v1p4beta1.ProductSearchClient.servicePath; + assert.strictEqual(servicePath, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = + productsearchModule.v1p4beta1.ProductSearchClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'vision.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + universeDomain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new productsearchModule.v1p4beta1.ProductSearchClient({ + universe_domain: 'example.com', + }); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'vision.example.com'); + }); + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { + new productsearchModule.v1p4beta1.ProductSearchClient({ + universe_domain: 'example.com', + universeDomain: 'example.net', + }); + }); }); it('has port', () => {