diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/CODE_OF_CONDUCT.md b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/CODE_OF_CONDUCT.md new file mode 100644 index 00000000000..2add2547a81 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/CODE_OF_CONDUCT.md @@ -0,0 +1,94 @@ + +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the project’s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + +Reports should be directed to *googleapis-stewards@google.com*, the +Project Steward(s) for *Google Cloud Client Libraries*. It is the Project Steward’s duty to +receive and address reported violations of the code of conduct. They will then +work with a committee consisting of representatives from the Open Source +Programs Office and the Google Open Source Strategy team. If for any reason you +are uncomfortable reaching out to the Project Steward, please email +opensource@google.com. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/CONTRIBUTING.md b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/CONTRIBUTING.md new file mode 100644 index 00000000000..099d8bfb0e8 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/CONTRIBUTING.md @@ -0,0 +1,76 @@ +# How to become a contributor and submit your own code + +**Table of contents** + +* [Contributor License Agreements](#contributor-license-agreements) +* [Contributing a patch](#contributing-a-patch) +* [Running the tests](#running-the-tests) +* [Releasing the library](#releasing-the-library) + +## Contributor License Agreements + +We'd love to accept your sample apps and patches! Before we can take them, we +have to jump a couple of legal hurdles. + +Please fill out either the individual or corporate Contributor License Agreement +(CLA). + + * If you are an individual writing original source code and you're sure you + own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual). + * If you work for a company that wants to allow you to contribute your work, + then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). + +Follow either of the two links above to access the appropriate CLA and +instructions for how to sign and return it. Once we receive it, we'll be able to +accept your pull requests. + +## Contributing A Patch + +1. Submit an issue describing your proposed change to the repo in question. +1. The repo owner will respond to your issue promptly. +1. If your proposed change is accepted, and you haven't already done so, sign a + Contributor License Agreement (see details above). +1. Fork the desired repo, develop and test your code changes. +1. Ensure that your code adheres to the existing style in the code to which + you are contributing. +1. Ensure that your code has an appropriate set of tests which all pass. +1. Title your pull request following [Conventional Commits](https://www.conventionalcommits.org/) styling. +1. Submit a pull request. + +### Before you begin + +1. [Select or create a Cloud Platform project][projects]. +1. [Enable billing for your project][billing]. +1. [Enable the Duplicate_methods_test API][enable_api]. +1. [Set up authentication with a service account][auth] so you can access the + API from your local workstation. + + +## Running the tests + +1. [Prepare your environment for Node.js setup][setup]. + +1. Install dependencies: + + npm install + +1. Run the tests: + + # Run unit tests. + npm test + + # Run sample integration tests. + npm run samples-test + + # Run all system tests. + npm run system-test + +1. Lint (and maybe fix) any changes: + + npm run fix + +[setup]: https://cloud.google.com/nodejs/docs/setup +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=duplicatemethodstest.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/getting-started \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/LICENSE b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/README.md b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/README.md new file mode 100644 index 00000000000..2ad47e789f2 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/README.md @@ -0,0 +1,108 @@ +[//]: # "This README.md file is auto-generated, all changes to this file will be lost." +[//]: # "The comments you see below are used to generate those parts of the template in later states." +Google Cloud Platform logo + +# [Duplicate Methods Test Service API: Nodejs Client][homepage] + +[//]: # "releaseLevel" + +[![npm version](https://img.shields.io/npm/v/@google-cloud/duplicate_methods_test-esm.svg)](https://www.npmjs.org/package/@google-cloud/duplicate_methods_test-esm) + +Duplicate Methods Test Service API client for Node.js + +[//]: # "partials.introduction" + +A comprehensive list of changes in each version may be found in +[the CHANGELOG][homepage_changelog]. + +* [Duplicate Methods Test Service API Nodejs Client API Reference](https://cloud.google.com/nodejs/docs/reference/duplicate_methods_test/latest) + + +Read more about the client libraries for Cloud APIs, including the older +Google APIs Client Libraries, in [Client Libraries Explained][explained]. + +[explained]: https://cloud.google.com/apis/docs/client-libraries-explained + +**Table of contents:** + +* [Quickstart](#quickstart) + * [Before you begin](#before-you-begin) + * [Installing the client library](#installing-the-client-library) + +* [Versioning](#versioning) +* [Contributing](#contributing) +* [License](#license) + +## Quickstart +### Before you begin + +1. [Select or create a Cloud Platform project][projects]. +1. [Enable billing for your project][billing]. +1. [Enable the Duplicate Methods Test Service API API][enable_api]. +1. [Set up authentication][auth] so you can access the + API from your local workstation. +### Installing the client library + +```bash +npm install @google-cloud/duplicate_methods_test-esm +``` + +[//]: # "partials.body" + +## Samples + +Samples are in the [`samples/`][homepage_samples] directory. Each sample's `README.md` has instructions for running its sample. + +[//]: # "samples" + +## Supported Node.js Versions + +Our client libraries follow the [Node.js release schedule](https://github.com/nodejs/release#release-schedule). +Libraries are compatible with all current _active_ and _maintenance_ versions of +Node.js. +If you are using an end-of-life version of Node.js, we recommend that you update +as soon as possible to an actively supported LTS version. + +Google's client libraries support legacy versions of Node.js runtimes on a +best-efforts basis with the following warnings: + +* Legacy versions are not tested in continuous integration. +* Some security patches and features cannot be backported. +* Dependencies cannot be kept up-to-date. + +Client libraries targeting some end-of-life versions of Node.js are available, and +can be installed through npm [dist-tags](https://docs.npmjs.com/cli/dist-tag). +The dist-tags follow the naming convention `legacy-(version)`. +For example, `npm install @google-cloud/duplicate_methods_test-esm@legacy-8` installs client libraries +for versions compatible with Node.js 8. + +## Versioning + +This library follows [Semantic Versioning](http://semver.org/). + +More Information: [Google Cloud Platform Launch Stages][launch_stages] + +[launch_stages]: https://cloud.google.com/terms/launch-stages + +## Contributing + +Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test/CONTRIBUTING.md). + +Please note that this `README.md` +and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`) +are generated from a central template. + +## License + +Apache Version 2.0 + +See [LICENSE](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test/LICENSE) + +[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=duplicatemethodstest.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/external/set-up-adc-local +[homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test/samples +[homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test/CHANGELOG.md +[homepage]: https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/index.ts b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/index.ts new file mode 100644 index 00000000000..2f77a606018 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/index.ts @@ -0,0 +1,26 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as v1 from './v1/index.js'; +const DuplicateMethodsTestServiceClient = v1.DuplicateMethodsTestServiceClient; +type DuplicateMethodsTestServiceClient = v1.DuplicateMethodsTestServiceClient; +export {v1, DuplicateMethodsTestServiceClient}; +export default {v1, DuplicateMethodsTestServiceClient}; +// @ts-ignore +import * as protos from '../../protos/protos.js'; +export {protos} diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/json-helper.cjs b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/json-helper.cjs new file mode 100644 index 00000000000..3c1fc730201 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/json-helper.cjs @@ -0,0 +1,20 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/* eslint-disable node/no-missing-require */ +function getJSON(path) { + return require(path); +} + +exports.getJSON = getJSON; diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_client.ts b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_client.ts new file mode 100644 index 00000000000..49a70fe1fe3 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_client.ts @@ -0,0 +1,917 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +/* global window */ +import * as gax from 'google-gax'; +import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, IamClient, IamProtos, LocationsClient, LocationProtos} from 'google-gax'; +import {Transform} from 'stream'; +// @ts-ignore +import type * as protos from '../../../protos/protos.js'; +import * as duplicate_methods_test_service_client_config from './duplicate_methods_test_service_client_config.json'; +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath} from 'url'; +import {getJSON} from '../json-helper.cjs'; +// @ts-ignore +const dirname = path.dirname(fileURLToPath(import.meta.url)); + +/** + * Client JSON configuration object, loaded from + * `src/v1/duplicate_methods_test_service_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +const gapicConfig = getJSON( + path.join(dirname, 'duplicate_methods_test_service_client_config.json') +); + +const jsonProtos = getJSON( + path.join(dirname, '..', '..', '..', 'protos/protos.json') +); +import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; +const version = getJSON( + path.join(dirname, '..', '..', '..', '..', 'package.json') +).version; + +/** + * @class + * @memberof v1 + */ +export class DuplicateMethodsTestServiceClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; + private _log = logging.log('duplicate_methods_test-esm'); + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + iamClient: IamClient; + locationsClient: LocationsClient; + duplicateMethodsTestServiceStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of DuplicateMethodsTestServiceClient. + * + * @param {object} [options] - The configuration object. + * The options accepted by the constructor are described in detail + * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * API remote host. + * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. + * Follows the structure of {@link gapicConfig}. + * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode. + * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. + * For more information, please check the + * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new DuplicateMethodsTestServiceClient({fallback: 'rest'}, gax); + * ``` + */ + constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + // Ensure that options include all the required fields. + const staticMembers = this.constructor as typeof DuplicateMethodsTestServiceClient; + if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { + throw new Error('Please set either universe_domain or universeDomain, but not both.'); + } + const universeDomainEnvVar = (typeof process === 'object' && typeof process.env === 'object') ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] : undefined; + this._universeDomain = opts?.universeDomain ?? opts?.universe_domain ?? universeDomainEnvVar ?? 'googleapis.com'; + this._servicePath = 'duplicatemethodstest.' + this._universeDomain; + const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; + this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + const port = opts?.port || staticMembers.port; + const clientConfig = opts?.clientConfig ?? {}; + const fallback = opts?.fallback ?? (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== this._servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = gax as typeof gax; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = this._servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === this._servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); + + this.locationsClient = new this._gaxModule.LocationsClient( + this._gaxGrpc, + opts + ); + + + // Add ESM headers + const isEsm = true; + const isEsmString = isEsm ? '-esm' : '-cjs'; + // Determine the client header string. + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; + if (typeof process === 'object' && 'versions' in process) { + clientHeader.push(`gl-node/{process.versions.node}${isEsmString}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else if (opts.fallback === 'rest' ) { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos as gax.protobuf.INamespace); + + // Some of the methods on this service return "paged" results, + // (e.g. 50 results at a time, with tokens to get subsequent + // pages). Denote the keys used for pagination and results. + this.descriptors.page = { + listLocations: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'locations') + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.duplicate_methods_test.v1.DuplicateMethodsTestService', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = this._gaxModule.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.duplicateMethodsTestServiceStub) { + return this.duplicateMethodsTestServiceStub; + } + + // Put together the "service stub" for + // google.duplicate_methods_test.v1.DuplicateMethodsTestService. + this.duplicateMethodsTestServiceStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.duplicate_methods_test.v1.DuplicateMethodsTestService') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.duplicate_methods_test.v1.DuplicateMethodsTestService, + this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + + // Iterate over each of the methods that the service provides + // and create an API call method for each. + const duplicateMethodsTestServiceStubMethods = + ['getIamPolicy', 'listLocations', 'echo']; + for (const methodName of duplicateMethodsTestServiceStubMethods) { + const callPromise = this.duplicateMethodsTestServiceStub.then( + stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + + const descriptor = + this.descriptors.page[methodName] || + undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor, + this._opts.fallback + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.duplicateMethodsTestServiceStub; + } + + /** + * 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 === 'object' && typeof process.emitWarning === 'function') { + process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning'); + } + return 'duplicatemethodstest.googleapis.com'; + } + + /** + * The DNS address for this API service - same as servicePath, + * exists for compatibility reasons. + * @deprecated Use the apiEndpoint method of the client instance. + * @returns {string} The DNS address for this service. + */ + static get apiEndpoint() { + if (typeof process === 'object' && typeof process.emitWarning === 'function') { + process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning'); + } + return 'duplicatemethodstest.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. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return [ + 'https://www.googleapis.com/auth/cloud-platform' + ]; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId(callback?: Callback): + Promise|void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- +/** + * Native GetIamPolicy method that conflicts with the IAMPolicy mixin. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {google.iam.v1.GetPolicyOptions} request.options + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + * @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. + * The first element of the array is an object representing {@link protos.google.iam.v1.Policy|Policy}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/duplicate_methods_test_service.get_iam_policy.js + * region_tag:duplicatemethodstest_v1_generated_DuplicateMethodsTestService_GetIamPolicy_async + */ + getIamPolicy( + request?: protos.google.iam.v1.IGetIamPolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|undefined, {}|undefined + ]>; + getIamPolicy( + request: protos.google.iam.v1.IGetIamPolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): void; + getIamPolicy( + request: protos.google.iam.v1.IGetIamPolicyRequest, + callback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): void; + getIamPolicy( + request?: protos.google.iam.v1.IGetIamPolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'resource': request.resource ?? '', + }); + this.initialize().catch(err => {throw err}); + this._log.info('getIamPolicy request %j', request); + const wrappedCallback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>|undefined = callback + ? (error, response, options, rawResponse) => { + this._log.info('getIamPolicy response %j', response); + callback!(error, response, options, rawResponse); + } + : undefined; + return this.innerApiCalls.getIamPolicy(request, options, wrappedCallback) + ?.then(([response, options, rawResponse]: [ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|undefined, {}|undefined + ]) => { + this._log.info('getIamPolicy response %j', response); + return [response, options, rawResponse]; + }).catch((error: any) => { + if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { + const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos) as unknown as gax.protobuf.Type; + error.statusDetails = decodeAnyProtosInArray(error.statusDetails, protos); + } + throw error; + }); + } +/** + * Another native method to ensure the service is valid and has other methods. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.content + * @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. + * The first element of the array is an object representing {@link protos.google.duplicate_methods_test.v1.EchoResponse|EchoResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/duplicate_methods_test_service.echo.js + * region_tag:duplicatemethodstest_v1_generated_DuplicateMethodsTestService_Echo_async + */ + echo( + request?: protos.google.duplicate_methods_test.v1.IEchoRequest, + options?: CallOptions): + Promise<[ + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|undefined, {}|undefined + ]>; + echo( + request: protos.google.duplicate_methods_test.v1.IEchoRequest, + options: CallOptions, + callback: Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>): void; + echo( + request: protos.google.duplicate_methods_test.v1.IEchoRequest, + callback: Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>): void; + echo( + request?: protos.google.duplicate_methods_test.v1.IEchoRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + this.initialize().catch(err => {throw err}); + this._log.info('echo request %j', request); + const wrappedCallback: Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>|undefined = callback + ? (error, response, options, rawResponse) => { + this._log.info('echo response %j', response); + callback!(error, response, options, rawResponse); + } + : undefined; + return this.innerApiCalls.echo(request, options, wrappedCallback) + ?.then(([response, options, rawResponse]: [ + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|undefined, {}|undefined + ]) => { + this._log.info('echo response %j', response); + return [response, options, rawResponse]; + }).catch((error: any) => { + if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { + const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos) as unknown as gax.protobuf.Type; + error.statusDetails = decodeAnyProtosInArray(error.statusDetails, protos); + } + throw error; + }); + } + + /** + * Native ListLocations method that conflicts with the Locations mixin. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * The resource that owns the locations collection, if applicable. + * @param {string} request.filter + * The standard list filter. + * @param {number} request.pageSize + * The standard list page size. + * @param {string} request.pageToken + * The standard list page token. + * @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. + * The first element of the array is Array of {@link protos.google.cloud.location.Location|Location}. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * Note that it can affect your quota. + * We recommend using `listLocationsAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listLocations( + request?: protos.google.cloud.location.IListLocationsRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.location.ILocation[], + protos.google.cloud.location.IListLocationsRequest|null, + protos.google.cloud.location.IListLocationsResponse + ]>; + listLocations( + request: protos.google.cloud.location.IListLocationsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>): void; + listLocations( + request: protos.google.cloud.location.IListLocationsRequest, + callback: PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>): void; + listLocations( + request?: protos.google.cloud.location.IListLocationsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>, + callback?: PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>): + Promise<[ + protos.google.cloud.location.ILocation[], + protos.google.cloud.location.IListLocationsRequest|null, + protos.google.cloud.location.IListLocationsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize().catch(err => {throw err}); + const wrappedCallback: PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>|undefined = callback + ? (error, values, nextPageRequest, rawResponse) => { + this._log.info('listLocations values %j', values); + callback!(error, values, nextPageRequest, rawResponse); + } + : undefined; + this._log.info('listLocations request %j', request); + return this.innerApiCalls + .listLocations(request, options, wrappedCallback) + ?.then(([response, input, output]: [ + protos.google.cloud.location.ILocation[], + protos.google.cloud.location.IListLocationsRequest|null, + protos.google.cloud.location.IListLocationsResponse + ]) => { + this._log.info('listLocations values %j', response); + return [response, input, output]; + }); + } + +/** + * Equivalent to `listLocations`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * The resource that owns the locations collection, if applicable. + * @param {string} request.filter + * The standard list filter. + * @param {number} request.pageSize + * The standard list page size. + * @param {string} request.pageToken + * The standard list page token. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing {@link protos.google.cloud.location.Location|Location} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listLocationsAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listLocationsStream( + request?: protos.google.cloud.location.IListLocationsRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + const defaultCallSettings = this._defaults['listLocations']; + const callSettings = defaultCallSettings.merge(options); + this.initialize().catch(err => {throw err}); + this._log.info('listLocations stream %j', request); + return this.descriptors.page.listLocations.createStream( + this.innerApiCalls.listLocations as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listLocations`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * The resource that owns the locations collection, if applicable. + * @param {string} request.filter + * The standard list filter. + * @param {number} request.pageSize + * The standard list page size. + * @param {string} request.pageToken + * The standard list page token. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. + * When you iterate the returned iterable, each element will be an object representing + * {@link protos.google.cloud.location.Location|Location}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + * @example include:samples/generated/v1/duplicate_methods_test_service.list_locations.js + * region_tag:duplicatemethodstest_v1_generated_DuplicateMethodsTestService_ListLocations_async + */ + listLocationsAsync( + request?: protos.google.cloud.location.IListLocationsRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + const defaultCallSettings = this._defaults['listLocations']; + const callSettings = defaultCallSettings.merge(options); + this.initialize().catch(err => {throw err}); + this._log.info('listLocations iterate %j', request); + return this.descriptors.page.listLocations.asyncIterate( + this.innerApiCalls['listLocations'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } +/** + * Gets the access control policy for a resource. Returns an empty policy + * if the resource exists and does not have a policy set. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {Object} [request.options] + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + * + * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}. + * @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/interfaces/CallOptions.html | 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.iam.v1.Policy | Policy}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @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/interfaces/CallOptions.html | 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.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + /** + request: IamProtos.google.iam.v1.SetIamPolicyRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.Policy]> { + return this.iamClient.setIamPolicy(request, options, callback); + } + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @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/interfaces/CallOptions.html | 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.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + */ + /** + request: IamProtos.google.iam.v1.TestIamPermissionsRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { + return this.iamClient.testIamPermissions(request, options, callback); + } + + + /** + * Gets information about a location. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Resource name for the location. + * @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. + * The first element of the array is an object representing {@link google.cloud.location.Location | Location}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example + * ``` + * const [response] = await client.getLocation(request); + * ``` + */ + getLocation( + request: LocationProtos.google.cloud.location.IGetLocationRequest, + options?: + | gax.CallOptions + | Callback< + LocationProtos.google.cloud.location.ILocation, + | LocationProtos.google.cloud.location.IGetLocationRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + LocationProtos.google.cloud.location.ILocation, + | LocationProtos.google.cloud.location.IGetLocationRequest + | null + | undefined, + {} | null | undefined + > + ): Promise { + return this.locationsClient.getLocation(request, options, callback); + } + + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + if (this.duplicateMethodsTestServiceStub && !this._terminated) { + return this.duplicateMethodsTestServiceStub.then(stub => { + this._log.info('ending gRPC channel'); + this._terminated = true; + stub.close(); + this.iamClient.close().catch(err => {throw err}); + this.locationsClient.close().catch(err => {throw err}); + }); + } + return Promise.resolve(); + } +} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_client_config.json b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_client_config.json new file mode 100644 index 00000000000..be7baac9386 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_client_config.json @@ -0,0 +1,38 @@ +{ + "interfaces": { + "google.duplicate_methods_test.v1.DuplicateMethodsTestService": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "GetIamPolicy": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "ListLocations": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "Echo": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_proto_list.json b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_proto_list.json new file mode 100644 index 00000000000..d3ee7abc5db --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/duplicate_methods_test_service_proto_list.json @@ -0,0 +1,3 @@ +[ + "../../protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto" +] diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/index.ts b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/index.ts new file mode 100644 index 00000000000..0104bde3222 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/src/v1/index.ts @@ -0,0 +1,19 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +export {DuplicateMethodsTestServiceClient} from './duplicate_methods_test_service_client.js'; diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.cjs b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.cjs new file mode 100644 index 00000000000..dc8c439b40a --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.cjs @@ -0,0 +1,27 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + +/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ +const duplicate-methods-test = require('@google-cloud/duplicate_methods_test-esm'); + +function main() { + const duplicateMethodsTestServiceClient = new duplicate-methods-test.DuplicateMethodsTestServiceClient(); +} + +main(); diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.js b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.js new file mode 100644 index 00000000000..26d8bef5a41 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.js @@ -0,0 +1,27 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + +/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ +import * as duplicate-methods-test from '@google-cloud/duplicate_methods_test-esm'; + +function main() { + const duplicateMethodsTestServiceClient = new duplicate-methods-test.DuplicateMethodsTestServiceClient(); +} + +main(); diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.ts b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.ts new file mode 100644 index 00000000000..cf215c8b06c --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/fixtures/sample/src/index.ts @@ -0,0 +1,33 @@ +/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {DuplicateMethodsTestServiceClient} from '@google-cloud/duplicate_methods_test-esm'; + +// check that the client class type name can be used +function doStuffWithDuplicateMethodsTestServiceClient(client: DuplicateMethodsTestServiceClient) { + client.close(); +} + +function main() { + // check that the client instance can be created + const duplicateMethodsTestServiceClient = new DuplicateMethodsTestServiceClient(); + doStuffWithDuplicateMethodsTestServiceClient(duplicateMethodsTestServiceClient); +} + +main(); diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/install.ts b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/install.ts new file mode 100644 index 00000000000..e079c4fa110 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/system-test/install.ts @@ -0,0 +1,55 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {packNTest} from 'pack-n-play'; +import {readFileSync} from 'fs'; +import {describe, it} from 'mocha'; + +describe('📦 pack-n-play test', () => { + it('TypeScript', async function() { + this.timeout(300000); + await packNTest({ + packageDir: process.cwd(), + sample: { + description: 'TypeScript user can use the type definitions', + ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() + } + }); + }); + + it('ESM module', async function() { + this.timeout(300000); + await packNTest({ + sample: { + description: 'Should be able to import using ESM', + esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), + }, + }); + }); + + it('CJS module', async function() { + this.timeout(300000); + await packNTest({ + sample: { + description: 'Should be able to import using CJS', + cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), + }, + }); + }); + +}); diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/test/gapic_duplicate_methods_test_service_v1.ts b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/test/gapic_duplicate_methods_test_service_v1.ts new file mode 100644 index 00000000000..ad48c9cffc7 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/esm/test/gapic_duplicate_methods_test_service_v1.ts @@ -0,0 +1,977 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +// @ts-ignore +import * as protos from '../../protos/protos.js'; +import assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as duplicatemethodstestserviceModule from '../src/index.js'; + +import {PassThrough} from 'stream'; + +import {protobuf, IamProtos, LocationProtos} from 'google-gax'; +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath} from 'url'; + +// @ts-ignore +const dirname = path.dirname(fileURLToPath(import.meta.url)); +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + JSON.parse( + fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') + )) + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type?.fields[field]?.resolvedType as protobuf.Type; + } + return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; +} + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message) + .toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { + return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { mockStream.write({}); }); + } + setImmediate(() => { mockStream.end(); }); + } else { + setImmediate(() => { mockStream.write({}); }); + setImmediate(() => { mockStream.end(); }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + } + }; + } + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.DuplicateMethodsTestServiceClient', () => { + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'duplicatemethodstest.googleapis.com'); + }); + + it('has universeDomain', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, "googleapis.com"); + }); + + if (typeof process === 'object' && typeof process.emitWarning === 'function') { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient.servicePath; + assert.strictEqual(servicePath, 'duplicatemethodstest.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'duplicatemethodstest.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({universeDomain: 'example.com'}); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'duplicatemethodstest.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({universe_domain: 'example.com'}); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'duplicatemethodstest.example.com'); + }); + + if (typeof process === 'object' && 'env' in process) { + describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { + it('sets apiEndpoint from environment variable', () => { + const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'duplicatemethodstest.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } + }); + + it('value configured in code has priority over environment variable', () => { + const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({universeDomain: 'configured.example.com'}); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'duplicatemethodstest.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } + }); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + }); + + it('has port', () => { + const port = duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.duplicateMethodsTestServiceStub, undefined); + await client.initialize(); + assert(client.duplicateMethodsTestServiceStub); + }); + + it('has close method for the initialized client', done => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize().catch(err => {throw err}); + assert(client.duplicateMethodsTestServiceStub); + client.close().then(() => { + done(); + }).catch(err => {throw err}); + }); + + it('has close method for the non-initialized client', done => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.duplicateMethodsTestServiceStub, undefined); + client.close().then(() => { + done(); + }).catch(err => {throw err}); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error|null, projectId?: string|null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + }); + + describe('getIamPolicy', () => { + it('invokes getIamPolicy without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.Policy() + ); + client.innerApiCalls.getIamPolicy = stubSimpleCall(expectedResponse); + const [response] = await client.getIamPolicy(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.Policy() + ); + client.innerApiCalls.getIamPolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getIamPolicy( + request, + (err?: Error|null, result?: protos.google.iam.v1.IPolicy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; + const expectedError = new Error('expected'); + client.innerApiCalls.getIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getIamPolicy(request), expectedError); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy with closed client', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch(err => {throw err}); + await assert.rejects(client.getIamPolicy(request), expectedError); + }); + }); + + describe('echo', () => { + it('invokes echo without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoResponse() + ); + client.innerApiCalls.echo = stubSimpleCall(expectedResponse); + const [response] = await client.echo(request); + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes echo without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoResponse() + ); + client.innerApiCalls.echo = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.echo( + request, + (err?: Error|null, result?: protos.google.duplicate_methods_test.v1.IEchoResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes echo with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoRequest() + ); + const expectedError = new Error('expected'); + client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.echo(request), expectedError); + }); + + it('invokes echo with closed client', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoRequest() + ); + const expectedError = new Error('The client has already been closed.'); + client.close().catch(err => {throw err}); + await assert.rejects(client.echo(request), expectedError); + }); + }); + + describe('listLocations', () => { + it('invokes listLocations without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + ]; + client.innerApiCalls.listLocations = stubSimpleCall(expectedResponse); + const [response] = await client.listLocations(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listLocations without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + ]; + client.innerApiCalls.listLocations = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listLocations( + request, + (err?: Error|null, result?: protos.google.cloud.location.ILocation[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listLocations with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedError = new Error('expected'); + client.innerApiCalls.listLocations = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listLocations(request), expectedError); + const actualRequest = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listLocationsStream without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + ]; + client.descriptors.page.listLocations.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listLocationsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.location.Location[] = []; + stream.on('data', (response: protos.google.cloud.location.Location) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert((client.descriptors.page.listLocations.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listLocations, request)); + assert( + (client.descriptors.page.listLocations.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listLocationsStream with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedError = new Error('expected'); + client.descriptors.page.listLocations.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listLocationsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.location.Location[] = []; + stream.on('data', (response: protos.google.cloud.location.Location) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listLocations.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listLocations, request)); + assert( + (client.descriptors.page.listLocations.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listLocations without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + ]; + client.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.location.ILocation[] = []; + const iterable = client.listLocationsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listLocations.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listLocations.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listLocations with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedError = new Error('expected'); + client.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listLocations.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listLocations.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + describe('setIamPolicy', () => { + it('invokes setIamPolicy without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); + const response = await client.setIamPolicy(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes setIamPolicy without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.setIamPolicy( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }).catch(err => {throw err}); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0)); + }); + it('invokes setIamPolicy with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('testIamPermissions', () => { + it('invokes testIamPermissions without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); + const response = await client.testIamPermissions(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes testIamPermissions without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.testIamPermissions( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }).catch(err => {throw err}); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0)); + }); + it('invokes testIamPermissions with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.GetLocationRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new LocationProtos.google.cloud.location.Location() + ); + client.locationsClient.getLocation = stubSimpleCall(expectedResponse); + const response = await client.getLocation(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.locationsClient.getLocation as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes getLocation without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.GetLocationRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new LocationProtos.google.cloud.location.Location() + ); + client.locationsClient.getLocation = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getLocation( + request, + expectedOptions, + ( + err?: Error | null, + result?: LocationProtos.google.cloud.location.ILocation | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.locationsClient.getLocation as SinonStub) + .getCall(0)); + }); + it('invokes getLocation with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.GetLocationRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.locationsClient.getLocation = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getLocation(request, expectedOptions), expectedError); + assert((client.locationsClient.getLocation as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); +}); diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/package.json b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/package.json new file mode 100644 index 00000000000..276b80e372b --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/package.json @@ -0,0 +1,105 @@ +{ + "name": "@google-cloud/duplicate_methods_test-esm", + "version": "0.1.0", + "description": "Duplicate_methods_test client for Node.js", + "repository": "googleapis/nodejs-duplicate-methods-test", + "license": "Apache-2.0", + "author": "Google LLC", + "main": "./build/cjs/src/index.cjs", + "types": "./build/cjs/src/index.d.ts", + "type": "module", + "exports": { + ".": { + "import": { + "types": "./build/esm/src/index.d.ts", + "default": "./build/esm/src/index.js" + }, + "require": { + "types": "./build/cjs/src/index.d.ts", + "default": "./build/cjs/src/index.cjs" + } + }, + "./build/protos/protos": { + "import": { + "types": "./build/protos/protos/protos.d.ts", + "default": "./build/protos/protos/protos.js" + }, + "require": { + "types": "./build/protos/protos/protos.d.ts", + "default": "./build/protos/protos/protos.cjs" + } + } + }, + "files": [ + "build/esm", + "build/cjs", + "build/protos", + "!build/esm/**/*.map", + "!build/cjs/**/*.map" + ], + "keywords": [ + "google apis client", + "google api client", + "google apis", + "google api", + "google", + "google cloud platform", + "google cloud", + "cloud", + "google duplicateMethodsTest", + "duplicateMethodsTest", + "duplicate methods test service" + ], + "scripts": { + "clean": "gts clean", + "compile-protos": "compileProtos esm/src --esm ", + "docs": "jsdoc -c .jsdoc.cjs", + "postpack": "minifyProtoJson build/cjs && minifyProtoJson build/esm", + "predocs-test": "npm run docs", + "docs-test": "linkinator docs", + "fix": "gts fix", + "lint": "gts check", + "prepare": "npm run compile-protos && npm run compile", + "system-test:cjs": "c8 mocha build/cjs/system-test", + "system-test:esm": "c8 mocha build/esm/system-test", + "system-test": "npm run system-test:esm && npm run system-test:cjs", + "test:cjs": "c8 mocha build/cjs/test", + "test:esm": "c8 mocha build/esm/test", + "test": "npm run test:cjs && npm run test:esm", + "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", + "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", + "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", + "compile": "npm run compile:esm && rm -rf esm/src/json-helper.d.cts && npm run compile:cjs && rm -rf build/protos && cp -r protos build/protos", + "samples-test": "cd samples/ && npm link ../ && npm i && npm test" + }, + "dependencies": { + "google-gax": "^5.1.1-rc.1" + }, + "devDependencies": { + "@babel/cli": "^7.28.3", + "@babel/core": "^7.28.5", + "@babel/preset-env": "^7.28.5", + "@babel/preset-typescript": "^7.28.5", + "@types/mocha": "^10.0.10", + "@types/node": "^22.18.12", + "@types/sinon": "^17.0.4", + "babel-plugin-replace-import-extension": "^1.1.5", + "c8": "^10.1.3", + "gapic-tools": "^1.0.3", + "gts": "^6.0.2", + "jsdoc": "^4.0.5", + "jsdoc-region-tag": "^4.0.1", + "jsdoc-fresh": "^5.0.2", + "long": "^5.3.2", + "mocha": "^11.7.4", + "pack-n-play": "^4.2.1", + "typescript": "5.8.3", + "sinon": "^21.0.0", + "ts-loader": "^8.4.0", + "webpack": "^5.102.1", + "webpack-cli": "^6.0.1" + }, + "engines": { + "node": ">=v18" + } +} diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto new file mode 100644 index 00000000000..b91e79094ff --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto @@ -0,0 +1,66 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.duplicate_methods_test.v1; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/iam/v1/iam_policy.proto"; +import "google/iam/v1/policy.proto"; +import "google/cloud/location/locations.proto"; + +option csharp_namespace = "Google.DuplicateMethodsTest.V1"; +option go_package = "google.golang.org/genproto/googleapis/duplicate_methods_test/v1;duplicate_methods_test"; +option java_multiple_files = true; +option java_outer_classname = "DuplicateMethodsTestProto"; +option java_package = "com.google.duplicate_methods_test.v1"; +option php_namespace = "Google\\DuplicateMethodsTest\\V1"; +option ruby_package = "Google::DuplicateMethodsTest::V1"; + +service DuplicateMethodsTestService { + option (google.api.default_host) = "duplicatemethodstest.googleapis.com"; + option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; + + // Native GetIamPolicy method that conflicts with the IAMPolicy mixin. + rpc GetIamPolicy(google.iam.v1.GetIamPolicyRequest) returns (google.iam.v1.Policy) { + option (google.api.http) = { + get: "/v1/{resource=projects/*}:getIamPolicy" + }; + } + + // Native ListLocations method that conflicts with the Locations mixin. + rpc ListLocations(google.cloud.location.ListLocationsRequest) returns (google.cloud.location.ListLocationsResponse) { + option (google.api.http) = { + get: "/v1/{name=projects/*}/locations" + }; + } + + // Another native method to ensure the service is valid and has other methods. + rpc Echo(EchoRequest) returns (EchoResponse) { + option (google.api.http) = { + post: "/v1/echo" + body: "*" + }; + } +} + +message EchoRequest { + string content = 1; +} + +message EchoResponse { + string content = 1; +} diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.echo.js b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.echo.js new file mode 100644 index 00000000000..64b901b97c4 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.echo.js @@ -0,0 +1,59 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main() { + // [START duplicatemethodstest_v1_generated_DuplicateMethodsTestService_Echo_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + */ + // const content = 'abc123' + + // Imports the Duplicate_methods_test library + const {DuplicateMethodsTestServiceClient} = require('@google-cloud/duplicate_methods_test-esm').v1; + + // Instantiates a client + const duplicateMethodsTestClient = new DuplicateMethodsTestServiceClient(); + + async function callEcho() { + // Construct request + const request = { + }; + + // Run request + const response = await duplicateMethodsTestClient.echo(request); + console.log(response); + } + + callEcho(); + // [END duplicatemethodstest_v1_generated_DuplicateMethodsTestService_Echo_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.get_iam_policy.js b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.get_iam_policy.js new file mode 100644 index 00000000000..caa51373b49 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.get_iam_policy.js @@ -0,0 +1,67 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main(resource) { + // [START duplicatemethodstest_v1_generated_DuplicateMethodsTestService_GetIamPolicy_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + */ + // const resource = 'abc123' + /** + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + */ + // const options = {} + + // Imports the Duplicate_methods_test library + const {DuplicateMethodsTestServiceClient} = require('@google-cloud/duplicate_methods_test-esm').v1; + + // Instantiates a client + const duplicateMethodsTestClient = new DuplicateMethodsTestServiceClient(); + + async function callGetIamPolicy() { + // Construct request + const request = { + resource, + }; + + // Run request + const response = await duplicateMethodsTestClient.getIamPolicy(request); + console.log(response); + } + + callGetIamPolicy(); + // [END duplicatemethodstest_v1_generated_DuplicateMethodsTestService_GetIamPolicy_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.list_locations.js b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.list_locations.js new file mode 100644 index 00000000000..a6e028742d6 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/duplicate_methods_test_service.list_locations.js @@ -0,0 +1,74 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main() { + // [START duplicatemethodstest_v1_generated_DuplicateMethodsTestService_ListLocations_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * The resource that owns the locations collection, if applicable. + */ + // const name = 'abc123' + /** + * The standard list filter. + */ + // const filter = 'abc123' + /** + * The standard list page size. + */ + // const pageSize = 1234 + /** + * The standard list page token. + */ + // const pageToken = 'abc123' + + // Imports the Duplicate_methods_test library + const {DuplicateMethodsTestServiceClient} = require('@google-cloud/duplicate_methods_test-esm').v1; + + // Instantiates a client + const duplicateMethodsTestClient = new DuplicateMethodsTestServiceClient(); + + async function callListLocations() { + // Construct request + const request = { + }; + + // Run request + const iterable = duplicateMethodsTestClient.listLocationsAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + callListLocations(); + // [END duplicatemethodstest_v1_generated_DuplicateMethodsTestService_ListLocations_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/snippet_metadata_google.duplicate_methods_test.v1.json b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/snippet_metadata_google.duplicate_methods_test.v1.json new file mode 100644 index 00000000000..5e881b6e29b --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/samples/generated/v1/snippet_metadata_google.duplicate_methods_test.v1.json @@ -0,0 +1,151 @@ +{ + "clientLibrary": { + "name": "nodejs-duplicate-methods-test", + "version": "0.1.0", + "language": "TYPESCRIPT", + "apis": [ + { + "id": "google.duplicate_methods_test.v1", + "version": "v1" + } + ] + }, + "snippets": [ + { + "regionTag": "duplicatemethodstest_v1_generated_DuplicateMethodsTestService_GetIamPolicy_async", + "title": "DuplicateMethodsTestService getIamPolicy Sample", + "origin": "API_DEFINITION", + "description": " Native GetIamPolicy method that conflicts with the IAMPolicy mixin.", + "canonical": true, + "file": "duplicate_methods_test_service.get_iam_policy.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 59, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "GetIamPolicy", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.GetIamPolicy", + "async": true, + "parameters": [ + { + "name": "resource", + "type": "TYPE_STRING" + }, + { + "name": "options", + "type": ".google.iam.v1.GetPolicyOptions" + } + ], + "resultType": ".google.iam.v1.Policy", + "client": { + "shortName": "DuplicateMethodsTestServiceClient", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestServiceClient" + }, + "method": { + "shortName": "GetIamPolicy", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.GetIamPolicy", + "service": { + "shortName": "DuplicateMethodsTestService", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService" + } + } + } + }, + { + "regionTag": "duplicatemethodstest_v1_generated_DuplicateMethodsTestService_ListLocations_async", + "title": "DuplicateMethodsTestService listLocations Sample", + "origin": "API_DEFINITION", + "description": " Native ListLocations method that conflicts with the Locations mixin.", + "canonical": true, + "file": "duplicate_methods_test_service.list_locations.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 66, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "ListLocations", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.ListLocations", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + }, + { + "name": "filter", + "type": "TYPE_STRING" + }, + { + "name": "page_size", + "type": "TYPE_INT32" + }, + { + "name": "page_token", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.location.ListLocationsResponse", + "client": { + "shortName": "DuplicateMethodsTestServiceClient", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestServiceClient" + }, + "method": { + "shortName": "ListLocations", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.ListLocations", + "service": { + "shortName": "DuplicateMethodsTestService", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService" + } + } + } + }, + { + "regionTag": "duplicatemethodstest_v1_generated_DuplicateMethodsTestService_Echo_async", + "title": "DuplicateMethodsTestService echo Sample", + "origin": "API_DEFINITION", + "description": " Another native method to ensure the service is valid and has other methods.", + "canonical": true, + "file": "duplicate_methods_test_service.echo.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 51, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "Echo", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.Echo", + "async": true, + "parameters": [ + { + "name": "content", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.duplicate_methods_test.v1.EchoResponse", + "client": { + "shortName": "DuplicateMethodsTestServiceClient", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestServiceClient" + }, + "method": { + "shortName": "Echo", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.Echo", + "service": { + "shortName": "DuplicateMethodsTestService", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService" + } + } + } + } + ] +} diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/tsconfig.esm.json b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/tsconfig.esm.json new file mode 100644 index 00000000000..9ea46f074fa --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/tsconfig.esm.json @@ -0,0 +1,27 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build", + "resolveJsonModule": true, + "module": "es2020", + "moduleResolution": "node", + "esModuleInterop": true, + "sourceMap": false, + "allowJs": true, + "lib": [ + "es2020", + "DOM" + ] + }, + "include": [ + "esm/src/*.ts", + "esm/src/**/*.ts", + "esm/test/*.ts", + "esm/test/**/*.ts", + "esm/system-test/*.ts", + "esm/src/**/*.json", + "protos/protos.json", + "esm/src/*.cjs" + ] +} diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/tsconfig.json b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/tsconfig.json new file mode 100644 index 00000000000..110f6eccd41 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/tsconfig.json @@ -0,0 +1,32 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "compilerOptions": { + "rootDir": ".", + "resolveJsonModule": true, + "moduleResolution": "node", + "allowJs": true, + "esModuleInterop": true, + "sourceMap": false, + "target": "esnext", + "module": "CommonJS", + "declaration": true, + "strict": true, + "isolatedModules": false, + "emitDeclarationOnly": true, + "lib": [ + "es2023", + "dom" + ] + }, + "include": [ + "esm/src/*.ts", + "esm/src/**/*.ts", + "esm/test/*.ts", + "esm/test/**/*.ts", + "esm/src/**/*.json", + "esm/system-test/*.ts", + "esm/src/*.cjs", + "samples/**/*.json", + "protos/protos.json" + ] +} diff --git a/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/webpack.config.cjs b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/webpack.config.cjs new file mode 100644 index 00000000000..59e373662ce --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines-esm/duplicate_methods_test-esm/webpack.config.cjs @@ -0,0 +1,64 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +const path = require('path'); + +module.exports = { + entry: './src/index.ts', + output: { + library: 'DuplicateMethodsTestService', + filename: './duplicate-methods-test-service.js', + }, + node: { + child_process: 'empty', + fs: 'empty', + crypto: 'empty', + }, + resolve: { + alias: { + '../../../package.json': path.resolve(__dirname, 'package.json'), + }, + extensions: ['.js', '.json', '.ts'], + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/ + }, + { + test: /node_modules[\\/]@grpc[\\/]grpc-js/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]grpc/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]retry-request/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]https?-proxy-agent/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]gtoken/, + use: 'null-loader' + }, + ], + }, + mode: 'production', +}; diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/CODE_OF_CONDUCT.md b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/CODE_OF_CONDUCT.md new file mode 100644 index 00000000000..2add2547a81 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/CODE_OF_CONDUCT.md @@ -0,0 +1,94 @@ + +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the project’s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + +Reports should be directed to *googleapis-stewards@google.com*, the +Project Steward(s) for *Google Cloud Client Libraries*. It is the Project Steward’s duty to +receive and address reported violations of the code of conduct. They will then +work with a committee consisting of representatives from the Open Source +Programs Office and the Google Open Source Strategy team. If for any reason you +are uncomfortable reaching out to the Project Steward, please email +opensource@google.com. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct.html \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/CONTRIBUTING.md b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/CONTRIBUTING.md new file mode 100644 index 00000000000..099d8bfb0e8 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/CONTRIBUTING.md @@ -0,0 +1,76 @@ +# How to become a contributor and submit your own code + +**Table of contents** + +* [Contributor License Agreements](#contributor-license-agreements) +* [Contributing a patch](#contributing-a-patch) +* [Running the tests](#running-the-tests) +* [Releasing the library](#releasing-the-library) + +## Contributor License Agreements + +We'd love to accept your sample apps and patches! Before we can take them, we +have to jump a couple of legal hurdles. + +Please fill out either the individual or corporate Contributor License Agreement +(CLA). + + * If you are an individual writing original source code and you're sure you + own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual). + * If you work for a company that wants to allow you to contribute your work, + then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). + +Follow either of the two links above to access the appropriate CLA and +instructions for how to sign and return it. Once we receive it, we'll be able to +accept your pull requests. + +## Contributing A Patch + +1. Submit an issue describing your proposed change to the repo in question. +1. The repo owner will respond to your issue promptly. +1. If your proposed change is accepted, and you haven't already done so, sign a + Contributor License Agreement (see details above). +1. Fork the desired repo, develop and test your code changes. +1. Ensure that your code adheres to the existing style in the code to which + you are contributing. +1. Ensure that your code has an appropriate set of tests which all pass. +1. Title your pull request following [Conventional Commits](https://www.conventionalcommits.org/) styling. +1. Submit a pull request. + +### Before you begin + +1. [Select or create a Cloud Platform project][projects]. +1. [Enable billing for your project][billing]. +1. [Enable the Duplicate_methods_test API][enable_api]. +1. [Set up authentication with a service account][auth] so you can access the + API from your local workstation. + + +## Running the tests + +1. [Prepare your environment for Node.js setup][setup]. + +1. Install dependencies: + + npm install + +1. Run the tests: + + # Run unit tests. + npm test + + # Run sample integration tests. + npm run samples-test + + # Run all system tests. + npm run system-test + +1. Lint (and maybe fix) any changes: + + npm run fix + +[setup]: https://cloud.google.com/nodejs/docs/setup +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=duplicatemethodstest.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/getting-started \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/LICENSE b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/README.md b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/README.md new file mode 100644 index 00000000000..689fabc4ed5 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/README.md @@ -0,0 +1,108 @@ +[//]: # "This README.md file is auto-generated, all changes to this file will be lost." +[//]: # "The comments you see below are used to generate those parts of the template in later states." +Google Cloud Platform logo + +# [Duplicate Methods Test Service API: Nodejs Client][homepage] + +[//]: # "releaseLevel" + +[![npm version](https://img.shields.io/npm/v/@google-cloud/duplicate_methods_test.svg)](https://www.npmjs.org/package/@google-cloud/duplicate_methods_test) + +Duplicate Methods Test Service API client for Node.js + +[//]: # "partials.introduction" + +A comprehensive list of changes in each version may be found in +[the CHANGELOG][homepage_changelog]. + +* [Duplicate Methods Test Service API Nodejs Client API Reference](https://cloud.google.com/nodejs/docs/reference/duplicate_methods_test/latest) + + +Read more about the client libraries for Cloud APIs, including the older +Google APIs Client Libraries, in [Client Libraries Explained][explained]. + +[explained]: https://cloud.google.com/apis/docs/client-libraries-explained + +**Table of contents:** + +* [Quickstart](#quickstart) + * [Before you begin](#before-you-begin) + * [Installing the client library](#installing-the-client-library) + +* [Versioning](#versioning) +* [Contributing](#contributing) +* [License](#license) + +## Quickstart +### Before you begin + +1. [Select or create a Cloud Platform project][projects]. +1. [Enable billing for your project][billing]. +1. [Enable the Duplicate Methods Test Service API API][enable_api]. +1. [Set up authentication][auth] so you can access the + API from your local workstation. +### Installing the client library + +```bash +npm install @google-cloud/duplicate_methods_test +``` + +[//]: # "partials.body" + +## Samples + +Samples are in the [`samples/`][homepage_samples] directory. Each sample's `README.md` has instructions for running its sample. + +[//]: # "samples" + +## Supported Node.js Versions + +Our client libraries follow the [Node.js release schedule](https://github.com/nodejs/release#release-schedule). +Libraries are compatible with all current _active_ and _maintenance_ versions of +Node.js. +If you are using an end-of-life version of Node.js, we recommend that you update +as soon as possible to an actively supported LTS version. + +Google's client libraries support legacy versions of Node.js runtimes on a +best-efforts basis with the following warnings: + +* Legacy versions are not tested in continuous integration. +* Some security patches and features cannot be backported. +* Dependencies cannot be kept up-to-date. + +Client libraries targeting some end-of-life versions of Node.js are available, and +can be installed through npm [dist-tags](https://docs.npmjs.com/cli/dist-tag). +The dist-tags follow the naming convention `legacy-(version)`. +For example, `npm install @google-cloud/duplicate_methods_test@legacy-8` installs client libraries +for versions compatible with Node.js 8. + +## Versioning + +This library follows [Semantic Versioning](http://semver.org/). + +More Information: [Google Cloud Platform Launch Stages][launch_stages] + +[launch_stages]: https://cloud.google.com/terms/launch-stages + +## Contributing + +Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test/CONTRIBUTING.md). + +Please note that this `README.md` +and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`) +are generated from a central template. + +## License + +Apache Version 2.0 + +See [LICENSE](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test/LICENSE) + +[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=duplicatemethodstest.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/external/set-up-adc-local +[homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test/samples +[homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test/CHANGELOG.md +[homepage]: https://github.com/googleapis/google-cloud-node/blob/main/packages/google-duplicate_methods_test diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/package.json b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/package.json new file mode 100644 index 00000000000..63d39e58107 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/package.json @@ -0,0 +1,58 @@ +{ + "name": "@google-cloud/duplicate_methods_test", + "version": "0.1.0", + "description": "Duplicate_methods_test client for Node.js", + "repository": "googleapis/nodejs-duplicate-methods-test", + "license": "Apache-2.0", + "author": "Google LLC", + "main": "build/src/index.js", + "files": [ + "build/src", + "build/protos" + ], + "keywords": [ + "google apis client", + "google api client", + "google apis", + "google api", + "google", + "google cloud platform", + "google cloud", + "cloud", + "google duplicateMethodsTest", + "duplicateMethodsTest", + "duplicate methods test service" + ], + "scripts": { + "clean": "gts clean", + "compile": "tsc -p . && cp -r protos build/ && minifyProtoJson", + "compile-protos": "compileProtos src", + "docs": "jsdoc -c .jsdoc.js", + "fix": "gts fix", + "lint": "gts check", + "prepare": "npm run compile-protos && npm run compile", + "system-test": "c8 mocha build/system-test", + "test": "c8 mocha build/test" + }, + "dependencies": { + "google-gax": "^5.1.1-rc.1" + }, + "devDependencies": { + "@types/mocha": "^10.0.10", + "@types/node": "^22.18.12", + "@types/sinon": "^17.0.4", + "c8": "^10.1.3", + "gapic-tools": "^1.0.3", + "gts": "^6.0.2", + "jsdoc": "^4.0.5", + "jsdoc-fresh": "^5.0.2", + "jsdoc-region-tag": "^4.0.1", + "mocha": "^11.7.4", + "pack-n-play": "^4.2.1", + "typescript": "5.8.3", + "sinon": "^21.0.0" + }, + "engines": { + "node": ">=v18" + } +} diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto new file mode 100644 index 00000000000..b91e79094ff --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto @@ -0,0 +1,66 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.duplicate_methods_test.v1; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/iam/v1/iam_policy.proto"; +import "google/iam/v1/policy.proto"; +import "google/cloud/location/locations.proto"; + +option csharp_namespace = "Google.DuplicateMethodsTest.V1"; +option go_package = "google.golang.org/genproto/googleapis/duplicate_methods_test/v1;duplicate_methods_test"; +option java_multiple_files = true; +option java_outer_classname = "DuplicateMethodsTestProto"; +option java_package = "com.google.duplicate_methods_test.v1"; +option php_namespace = "Google\\DuplicateMethodsTest\\V1"; +option ruby_package = "Google::DuplicateMethodsTest::V1"; + +service DuplicateMethodsTestService { + option (google.api.default_host) = "duplicatemethodstest.googleapis.com"; + option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; + + // Native GetIamPolicy method that conflicts with the IAMPolicy mixin. + rpc GetIamPolicy(google.iam.v1.GetIamPolicyRequest) returns (google.iam.v1.Policy) { + option (google.api.http) = { + get: "/v1/{resource=projects/*}:getIamPolicy" + }; + } + + // Native ListLocations method that conflicts with the Locations mixin. + rpc ListLocations(google.cloud.location.ListLocationsRequest) returns (google.cloud.location.ListLocationsResponse) { + option (google.api.http) = { + get: "/v1/{name=projects/*}/locations" + }; + } + + // Another native method to ensure the service is valid and has other methods. + rpc Echo(EchoRequest) returns (EchoResponse) { + option (google.api.http) = { + post: "/v1/echo" + body: "*" + }; + } +} + +message EchoRequest { + string content = 1; +} + +message EchoResponse { + string content = 1; +} diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.echo.js b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.echo.js new file mode 100644 index 00000000000..a99b8cf9ee6 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.echo.js @@ -0,0 +1,59 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main() { + // [START duplicatemethodstest_v1_generated_DuplicateMethodsTestService_Echo_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + */ + // const content = 'abc123' + + // Imports the Duplicate_methods_test library + const {DuplicateMethodsTestServiceClient} = require('@google-cloud/duplicate_methods_test').v1; + + // Instantiates a client + const duplicateMethodsTestClient = new DuplicateMethodsTestServiceClient(); + + async function callEcho() { + // Construct request + const request = { + }; + + // Run request + const response = await duplicateMethodsTestClient.echo(request); + console.log(response); + } + + callEcho(); + // [END duplicatemethodstest_v1_generated_DuplicateMethodsTestService_Echo_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.get_iam_policy.js b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.get_iam_policy.js new file mode 100644 index 00000000000..a0285e3a018 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.get_iam_policy.js @@ -0,0 +1,67 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main(resource) { + // [START duplicatemethodstest_v1_generated_DuplicateMethodsTestService_GetIamPolicy_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + */ + // const resource = 'abc123' + /** + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + */ + // const options = {} + + // Imports the Duplicate_methods_test library + const {DuplicateMethodsTestServiceClient} = require('@google-cloud/duplicate_methods_test').v1; + + // Instantiates a client + const duplicateMethodsTestClient = new DuplicateMethodsTestServiceClient(); + + async function callGetIamPolicy() { + // Construct request + const request = { + resource, + }; + + // Run request + const response = await duplicateMethodsTestClient.getIamPolicy(request); + console.log(response); + } + + callGetIamPolicy(); + // [END duplicatemethodstest_v1_generated_DuplicateMethodsTestService_GetIamPolicy_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.list_locations.js b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.list_locations.js new file mode 100644 index 00000000000..a6d87f2e660 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/duplicate_methods_test_service.list_locations.js @@ -0,0 +1,74 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main() { + // [START duplicatemethodstest_v1_generated_DuplicateMethodsTestService_ListLocations_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * The resource that owns the locations collection, if applicable. + */ + // const name = 'abc123' + /** + * The standard list filter. + */ + // const filter = 'abc123' + /** + * The standard list page size. + */ + // const pageSize = 1234 + /** + * The standard list page token. + */ + // const pageToken = 'abc123' + + // Imports the Duplicate_methods_test library + const {DuplicateMethodsTestServiceClient} = require('@google-cloud/duplicate_methods_test').v1; + + // Instantiates a client + const duplicateMethodsTestClient = new DuplicateMethodsTestServiceClient(); + + async function callListLocations() { + // Construct request + const request = { + }; + + // Run request + const iterable = duplicateMethodsTestClient.listLocationsAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + callListLocations(); + // [END duplicatemethodstest_v1_generated_DuplicateMethodsTestService_ListLocations_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/snippet_metadata_google.duplicate_methods_test.v1.json b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/snippet_metadata_google.duplicate_methods_test.v1.json new file mode 100644 index 00000000000..5e881b6e29b --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/samples/generated/v1/snippet_metadata_google.duplicate_methods_test.v1.json @@ -0,0 +1,151 @@ +{ + "clientLibrary": { + "name": "nodejs-duplicate-methods-test", + "version": "0.1.0", + "language": "TYPESCRIPT", + "apis": [ + { + "id": "google.duplicate_methods_test.v1", + "version": "v1" + } + ] + }, + "snippets": [ + { + "regionTag": "duplicatemethodstest_v1_generated_DuplicateMethodsTestService_GetIamPolicy_async", + "title": "DuplicateMethodsTestService getIamPolicy Sample", + "origin": "API_DEFINITION", + "description": " Native GetIamPolicy method that conflicts with the IAMPolicy mixin.", + "canonical": true, + "file": "duplicate_methods_test_service.get_iam_policy.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 59, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "GetIamPolicy", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.GetIamPolicy", + "async": true, + "parameters": [ + { + "name": "resource", + "type": "TYPE_STRING" + }, + { + "name": "options", + "type": ".google.iam.v1.GetPolicyOptions" + } + ], + "resultType": ".google.iam.v1.Policy", + "client": { + "shortName": "DuplicateMethodsTestServiceClient", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestServiceClient" + }, + "method": { + "shortName": "GetIamPolicy", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.GetIamPolicy", + "service": { + "shortName": "DuplicateMethodsTestService", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService" + } + } + } + }, + { + "regionTag": "duplicatemethodstest_v1_generated_DuplicateMethodsTestService_ListLocations_async", + "title": "DuplicateMethodsTestService listLocations Sample", + "origin": "API_DEFINITION", + "description": " Native ListLocations method that conflicts with the Locations mixin.", + "canonical": true, + "file": "duplicate_methods_test_service.list_locations.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 66, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "ListLocations", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.ListLocations", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + }, + { + "name": "filter", + "type": "TYPE_STRING" + }, + { + "name": "page_size", + "type": "TYPE_INT32" + }, + { + "name": "page_token", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.location.ListLocationsResponse", + "client": { + "shortName": "DuplicateMethodsTestServiceClient", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestServiceClient" + }, + "method": { + "shortName": "ListLocations", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.ListLocations", + "service": { + "shortName": "DuplicateMethodsTestService", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService" + } + } + } + }, + { + "regionTag": "duplicatemethodstest_v1_generated_DuplicateMethodsTestService_Echo_async", + "title": "DuplicateMethodsTestService echo Sample", + "origin": "API_DEFINITION", + "description": " Another native method to ensure the service is valid and has other methods.", + "canonical": true, + "file": "duplicate_methods_test_service.echo.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 51, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "Echo", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.Echo", + "async": true, + "parameters": [ + { + "name": "content", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.duplicate_methods_test.v1.EchoResponse", + "client": { + "shortName": "DuplicateMethodsTestServiceClient", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestServiceClient" + }, + "method": { + "shortName": "Echo", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService.Echo", + "service": { + "shortName": "DuplicateMethodsTestService", + "fullName": "google.duplicate_methods_test.v1.DuplicateMethodsTestService" + } + } + } + } + ] +} diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/index.ts b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/index.ts new file mode 100644 index 00000000000..f49a9ce39e4 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/index.ts @@ -0,0 +1,25 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as v1 from './v1'; +const DuplicateMethodsTestServiceClient = v1.DuplicateMethodsTestServiceClient; +type DuplicateMethodsTestServiceClient = v1.DuplicateMethodsTestServiceClient; +export {v1, DuplicateMethodsTestServiceClient}; +export default {v1, DuplicateMethodsTestServiceClient}; +import * as protos from '../protos/protos'; +export {protos} diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_client.ts b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_client.ts new file mode 100644 index 00000000000..9ae11f613b7 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_client.ts @@ -0,0 +1,899 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +/* global window */ +import type * as gax from 'google-gax'; +import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall, IamClient, IamProtos, LocationsClient, LocationProtos} from 'google-gax'; +import {Transform} from 'stream'; +import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); +import {loggingUtils as logging, decodeAnyProtosInArray} from 'google-gax'; + +/** + * Client JSON configuration object, loaded from + * `src/v1/duplicate_methods_test_service_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +import * as gapicConfig from './duplicate_methods_test_service_client_config.json'; +const version = require('../../../package.json').version; + +/** + * @class + * @memberof v1 + */ +export class DuplicateMethodsTestServiceClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + private _universeDomain: string; + private _servicePath: string; + private _log = logging.log('duplicate_methods_test'); + + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + iamClient: IamClient; + locationsClient: LocationsClient; + duplicateMethodsTestServiceStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of DuplicateMethodsTestServiceClient. + * + * @param {object} [options] - The configuration object. + * The options accepted by the constructor are described in detail + * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * API remote host. + * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. + * Follows the structure of {@link gapicConfig}. + * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode. + * For more information, please check the + * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new DuplicateMethodsTestServiceClient({fallback: true}, gax); + * ``` + */ + constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + // Ensure that options include all the required fields. + const staticMembers = this.constructor as typeof DuplicateMethodsTestServiceClient; + if (opts?.universe_domain && opts?.universeDomain && opts?.universe_domain !== opts?.universeDomain) { + throw new Error('Please set either universe_domain or universeDomain, but not both.'); + } + const universeDomainEnvVar = (typeof process === 'object' && typeof process.env === 'object') ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] : undefined; + this._universeDomain = opts?.universeDomain ?? opts?.universe_domain ?? universeDomainEnvVar ?? 'googleapis.com'; + this._servicePath = 'duplicatemethodstest.' + this._universeDomain; + const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath; + this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + const port = opts?.port || staticMembers.port; + const clientConfig = opts?.clientConfig ?? {}; + const fallback = opts?.fallback ?? (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== this._servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = require('google-gax') as typeof gax; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = this._servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === this._servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts); + + this.locationsClient = new this._gaxModule.LocationsClient( + this._gaxGrpc, + opts + ); + + + // Determine the client header string. + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; + if (typeof process === 'object' && 'versions' in process) { + clientHeader.push(`gl-node/${process.versions.node}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); + + // Some of the methods on this service return "paged" results, + // (e.g. 50 results at a time, with tokens to get subsequent + // pages). Denote the keys used for pagination and results. + this.descriptors.page = { + listLocations: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'locations') + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.duplicate_methods_test.v1.DuplicateMethodsTestService', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = this._gaxModule.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.duplicateMethodsTestServiceStub) { + return this.duplicateMethodsTestServiceStub; + } + + // Put together the "service stub" for + // google.duplicate_methods_test.v1.DuplicateMethodsTestService. + this.duplicateMethodsTestServiceStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.duplicate_methods_test.v1.DuplicateMethodsTestService') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.duplicate_methods_test.v1.DuplicateMethodsTestService, + this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + + // Iterate over each of the methods that the service provides + // and create an API call method for each. + const duplicateMethodsTestServiceStubMethods = + ['getIamPolicy', 'listLocations', 'echo']; + for (const methodName of duplicateMethodsTestServiceStubMethods) { + const callPromise = this.duplicateMethodsTestServiceStub.then( + stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + + const descriptor = + this.descriptors.page[methodName] || + undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor, + this._opts.fallback + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.duplicateMethodsTestServiceStub; + } + + /** + * 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 === 'object' && typeof process.emitWarning === 'function') { + process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning'); + } + return 'duplicatemethodstest.googleapis.com'; + } + + /** + * 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 === 'object' && typeof process.emitWarning === 'function') { + process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning'); + } + return 'duplicatemethodstest.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. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return [ + 'https://www.googleapis.com/auth/cloud-platform' + ]; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId(callback?: Callback): + Promise|void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- +/** + * Native GetIamPolicy method that conflicts with the IAMPolicy mixin. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {google.iam.v1.GetPolicyOptions} request.options + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + * @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. + * The first element of the array is an object representing {@link protos.google.iam.v1.Policy|Policy}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/duplicate_methods_test_service.get_iam_policy.js + * region_tag:duplicatemethodstest_v1_generated_DuplicateMethodsTestService_GetIamPolicy_async + */ + getIamPolicy( + request?: protos.google.iam.v1.IGetIamPolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|undefined, {}|undefined + ]>; + getIamPolicy( + request: protos.google.iam.v1.IGetIamPolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): void; + getIamPolicy( + request: protos.google.iam.v1.IGetIamPolicyRequest, + callback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): void; + getIamPolicy( + request?: protos.google.iam.v1.IGetIamPolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'resource': request.resource ?? '', + }); + this.initialize().catch(err => {throw err}); + this._log.info('getIamPolicy request %j', request); + const wrappedCallback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>|undefined = callback + ? (error, response, options, rawResponse) => { + this._log.info('getIamPolicy response %j', response); + callback!(error, response, options, rawResponse); // We verified callback above. + } + : undefined; + return this.innerApiCalls.getIamPolicy(request, options, wrappedCallback) + ?.then(([response, options, rawResponse]: [ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|undefined, + {}|undefined + ]) => { + this._log.info('getIamPolicy response %j', response); + return [response, options, rawResponse]; + }).catch((error: any) => { + if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { + const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos) as unknown as gax.protobuf.Type; + error.statusDetails = decodeAnyProtosInArray(error.statusDetails, protos); + } + throw error; + }); + } +/** + * Another native method to ensure the service is valid and has other methods. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.content + * @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. + * The first element of the array is an object representing {@link protos.google.duplicate_methods_test.v1.EchoResponse|EchoResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/duplicate_methods_test_service.echo.js + * region_tag:duplicatemethodstest_v1_generated_DuplicateMethodsTestService_Echo_async + */ + echo( + request?: protos.google.duplicate_methods_test.v1.IEchoRequest, + options?: CallOptions): + Promise<[ + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|undefined, {}|undefined + ]>; + echo( + request: protos.google.duplicate_methods_test.v1.IEchoRequest, + options: CallOptions, + callback: Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>): void; + echo( + request: protos.google.duplicate_methods_test.v1.IEchoRequest, + callback: Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>): void; + echo( + request?: protos.google.duplicate_methods_test.v1.IEchoRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + this.initialize().catch(err => {throw err}); + this._log.info('echo request %j', request); + const wrappedCallback: Callback< + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|null|undefined, + {}|null|undefined>|undefined = callback + ? (error, response, options, rawResponse) => { + this._log.info('echo response %j', response); + callback!(error, response, options, rawResponse); // We verified callback above. + } + : undefined; + return this.innerApiCalls.echo(request, options, wrappedCallback) + ?.then(([response, options, rawResponse]: [ + protos.google.duplicate_methods_test.v1.IEchoResponse, + protos.google.duplicate_methods_test.v1.IEchoRequest|undefined, + {}|undefined + ]) => { + this._log.info('echo response %j', response); + return [response, options, rawResponse]; + }).catch((error: any) => { + if (error && 'statusDetails' in error && error.statusDetails instanceof Array) { + const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos) as unknown as gax.protobuf.Type; + error.statusDetails = decodeAnyProtosInArray(error.statusDetails, protos); + } + throw error; + }); + } + + /** + * Native ListLocations method that conflicts with the Locations mixin. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * The resource that owns the locations collection, if applicable. + * @param {string} request.filter + * The standard list filter. + * @param {number} request.pageSize + * The standard list page size. + * @param {string} request.pageToken + * The standard list page token. + * @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. + * The first element of the array is Array of {@link protos.google.cloud.location.Location|Location}. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * Note that it can affect your quota. + * We recommend using `listLocationsAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listLocations( + request?: protos.google.cloud.location.IListLocationsRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.location.ILocation[], + protos.google.cloud.location.IListLocationsRequest|null, + protos.google.cloud.location.IListLocationsResponse + ]>; + listLocations( + request: protos.google.cloud.location.IListLocationsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>): void; + listLocations( + request: protos.google.cloud.location.IListLocationsRequest, + callback: PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>): void; + listLocations( + request?: protos.google.cloud.location.IListLocationsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>, + callback?: PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>): + Promise<[ + protos.google.cloud.location.ILocation[], + protos.google.cloud.location.IListLocationsRequest|null, + protos.google.cloud.location.IListLocationsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize().catch(err => {throw err}); + const wrappedCallback: PaginationCallback< + protos.google.cloud.location.IListLocationsRequest, + protos.google.cloud.location.IListLocationsResponse|null|undefined, + protos.google.cloud.location.ILocation>|undefined = callback + ? (error, values, nextPageRequest, rawResponse) => { + this._log.info('listLocations values %j', values); + callback!(error, values, nextPageRequest, rawResponse); // We verified callback above. + } + : undefined; + this._log.info('listLocations request %j', request); + return this.innerApiCalls + .listLocations(request, options, wrappedCallback) + ?.then(([response, input, output]: [ + protos.google.cloud.location.ILocation[], + protos.google.cloud.location.IListLocationsRequest|null, + protos.google.cloud.location.IListLocationsResponse + ]) => { + this._log.info('listLocations values %j', response); + return [response, input, output]; + }); + } + +/** + * Equivalent to `listLocations`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * The resource that owns the locations collection, if applicable. + * @param {string} request.filter + * The standard list filter. + * @param {number} request.pageSize + * The standard list page size. + * @param {string} request.pageToken + * The standard list page token. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing {@link protos.google.cloud.location.Location|Location} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listLocationsAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listLocationsStream( + request?: protos.google.cloud.location.IListLocationsRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + const defaultCallSettings = this._defaults['listLocations']; + const callSettings = defaultCallSettings.merge(options); + this.initialize().catch(err => {throw err}); + this._log.info('listLocations stream %j', request); + return this.descriptors.page.listLocations.createStream( + this.innerApiCalls.listLocations as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listLocations`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * The resource that owns the locations collection, if applicable. + * @param {string} request.filter + * The standard list filter. + * @param {number} request.pageSize + * The standard list page size. + * @param {string} request.pageToken + * The standard list page token. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. + * When you iterate the returned iterable, each element will be an object representing + * {@link protos.google.cloud.location.Location|Location}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + * @example include:samples/generated/v1/duplicate_methods_test_service.list_locations.js + * region_tag:duplicatemethodstest_v1_generated_DuplicateMethodsTestService_ListLocations_async + */ + listLocationsAsync( + request?: protos.google.cloud.location.IListLocationsRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + const defaultCallSettings = this._defaults['listLocations']; + const callSettings = defaultCallSettings.merge(options); + this.initialize().catch(err => {throw err}); + this._log.info('listLocations iterate %j', request); + return this.descriptors.page.listLocations.asyncIterate( + this.innerApiCalls['listLocations'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } +/** + * Gets the access control policy for a resource. Returns an empty policy + * if the resource exists and does not have a policy set. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {Object} [request.options] + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + * + * This object should have the same structure as {@link google.iam.v1.GetPolicyOptions | GetPolicyOptions}. + * @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/interfaces/CallOptions.html | 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.iam.v1.Policy | Policy}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @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/interfaces/CallOptions.html | 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.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ + /** + request: IamProtos.google.iam.v1.SetIamPolicyRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.Policy, + IamProtos.google.iam.v1.SetIamPolicyRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.Policy]> { + return this.iamClient.setIamPolicy(request, options, callback); + } + +/** + * Returns permissions that a caller has on the specified resource. If the + * resource does not exist, this will return an empty set of + * permissions, not a NOT_FOUND error. + * + * Note: This operation is designed to be used for building + * permission-aware UIs and command-line tools, not for authorization + * checking. This operation may "fail open" without warning. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see {@link https://cloud.google.com/iam/docs/overview#permissions | IAM Overview }. + * @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/interfaces/CallOptions.html | 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.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + */ + /** + request: IamProtos.google.iam.v1.TestIamPermissionsRequest, + options?: + | gax.CallOptions + | Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + >, + callback?: Callback< + IamProtos.google.iam.v1.TestIamPermissionsResponse, + IamProtos.google.iam.v1.TestIamPermissionsRequest | null | undefined, + {} | null | undefined + > + ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { + return this.iamClient.testIamPermissions(request, options, callback); + } + + + /** + * Gets information about a location. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Resource name for the location. + * @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. + * The first element of the array is an object representing {@link google.cloud.location.Location | Location}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example + * ``` + * const [response] = await client.getLocation(request); + * ``` + */ + getLocation( + request: LocationProtos.google.cloud.location.IGetLocationRequest, + options?: + | gax.CallOptions + | Callback< + LocationProtos.google.cloud.location.ILocation, + | LocationProtos.google.cloud.location.IGetLocationRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + LocationProtos.google.cloud.location.ILocation, + | LocationProtos.google.cloud.location.IGetLocationRequest + | null + | undefined, + {} | null | undefined + > + ): Promise { + return this.locationsClient.getLocation(request, options, callback); + } + + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + if (this.duplicateMethodsTestServiceStub && !this._terminated) { + return this.duplicateMethodsTestServiceStub.then(stub => { + this._log.info('ending gRPC channel'); + this._terminated = true; + stub.close(); + this.iamClient.close().catch(err => {throw err}); + this.locationsClient.close().catch(err => {throw err}); + }); + } + return Promise.resolve(); + } +} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_client_config.json b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_client_config.json new file mode 100644 index 00000000000..be7baac9386 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_client_config.json @@ -0,0 +1,38 @@ +{ + "interfaces": { + "google.duplicate_methods_test.v1.DuplicateMethodsTestService": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "GetIamPolicy": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "ListLocations": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "Echo": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_proto_list.json b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_proto_list.json new file mode 100644 index 00000000000..d3ee7abc5db --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/duplicate_methods_test_service_proto_list.json @@ -0,0 +1,3 @@ +[ + "../../protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto" +] diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/index.ts b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/index.ts new file mode 100644 index 00000000000..37e108cedea --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/src/v1/index.ts @@ -0,0 +1,19 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +export {DuplicateMethodsTestServiceClient} from './duplicate_methods_test_service_client'; diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/fixtures/sample/src/index.js b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/fixtures/sample/src/index.js new file mode 100644 index 00000000000..c9c75f89903 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/fixtures/sample/src/index.js @@ -0,0 +1,27 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + +/* eslint-disable node/no-missing-require, no-unused-vars */ +const duplicate-methods-test = require('@google-cloud/duplicate_methods_test'); + +function main() { + const duplicateMethodsTestServiceClient = new duplicate-methods-test.DuplicateMethodsTestServiceClient(); +} + +main(); diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/fixtures/sample/src/index.ts b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/fixtures/sample/src/index.ts new file mode 100644 index 00000000000..4327cd683d8 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/fixtures/sample/src/index.ts @@ -0,0 +1,32 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {DuplicateMethodsTestServiceClient} from '@google-cloud/duplicate_methods_test'; + +// check that the client class type name can be used +function doStuffWithDuplicateMethodsTestServiceClient(client: DuplicateMethodsTestServiceClient) { + client.close(); +} + +function main() { + // check that the client instance can be created + const duplicateMethodsTestServiceClient = new DuplicateMethodsTestServiceClient(); + doStuffWithDuplicateMethodsTestServiceClient(duplicateMethodsTestServiceClient); +} + +main(); diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/install.ts b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/install.ts new file mode 100644 index 00000000000..394f3362d20 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/system-test/install.ts @@ -0,0 +1,49 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {packNTest} from 'pack-n-play'; +import {readFileSync} from 'fs'; +import {describe, it} from 'mocha'; + +describe('📦 pack-n-play test', () => { + + it('TypeScript code', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), + sample: { + description: 'TypeScript user can use the type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } + }; + await packNTest(options); + }); + + it('JavaScript code', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), + sample: { + description: 'JavaScript user can use the library', + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } + }; + await packNTest(options); + }); + +}); diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/test/gapic_duplicate_methods_test_service_v1.ts b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/test/gapic_duplicate_methods_test_service_v1.ts new file mode 100644 index 00000000000..e9f1676ac7c --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/test/gapic_duplicate_methods_test_service_v1.ts @@ -0,0 +1,968 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as duplicatemethodstestserviceModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf, IamProtos, LocationProtos} from 'google-gax'; + +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message) + .toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { + return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { mockStream.write({}); }); + } + setImmediate(() => { mockStream.end(); }); + } else { + setImmediate(() => { mockStream.write({}); }); + setImmediate(() => { mockStream.end(); }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + } + }; + } + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.DuplicateMethodsTestServiceClient', () => { + describe('Common methods', () => { + it('has apiEndpoint', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient(); + const apiEndpoint = client.apiEndpoint; + assert.strictEqual(apiEndpoint, 'duplicatemethodstest.googleapis.com'); + }); + + it('has universeDomain', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient(); + const universeDomain = client.universeDomain; + assert.strictEqual(universeDomain, "googleapis.com"); + }); + + if (typeof process === 'object' && typeof process.emitWarning === 'function') { + it('throws DeprecationWarning if static servicePath is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const servicePath = duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient.servicePath; + assert.strictEqual(servicePath, 'duplicatemethodstest.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + + it('throws DeprecationWarning if static apiEndpoint is used', () => { + const stub = sinon.stub(process, 'emitWarning'); + const apiEndpoint = duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient.apiEndpoint; + assert.strictEqual(apiEndpoint, 'duplicatemethodstest.googleapis.com'); + assert(stub.called); + stub.restore(); + }); + } + it('sets apiEndpoint according to universe domain camelCase', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({universeDomain: 'example.com'}); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'duplicatemethodstest.example.com'); + }); + + it('sets apiEndpoint according to universe domain snakeCase', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({universe_domain: 'example.com'}); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'duplicatemethodstest.example.com'); + }); + + if (typeof process === 'object' && 'env' in process) { + describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { + it('sets apiEndpoint from environment variable', () => { + const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient(); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'duplicatemethodstest.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } + }); + + it('value configured in code has priority over environment variable', () => { + const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({universeDomain: 'configured.example.com'}); + const servicePath = client.apiEndpoint; + assert.strictEqual(servicePath, 'duplicatemethodstest.configured.example.com'); + if (saved) { + process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; + } else { + delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; + } + }); + }); + } + it('does not allow setting both universeDomain and universe_domain', () => { + assert.throws(() => { new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); + }); + + it('has port', () => { + const port = duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.duplicateMethodsTestServiceStub, undefined); + await client.initialize(); + assert(client.duplicateMethodsTestServiceStub); + }); + + it('has close method for the initialized client', done => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize().catch(err => {throw err}); + assert(client.duplicateMethodsTestServiceStub); + client.close().then(() => { + done(); + }).catch(err => {throw err}); + }); + + it('has close method for the non-initialized client', done => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.duplicateMethodsTestServiceStub, undefined); + client.close().then(() => { + done(); + }).catch(err => {throw err}); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error|null, projectId?: string|null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + }); + + describe('getIamPolicy', () => { + it('invokes getIamPolicy without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.Policy() + ); + client.innerApiCalls.getIamPolicy = stubSimpleCall(expectedResponse); + const [response] = await client.getIamPolicy(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.Policy() + ); + client.innerApiCalls.getIamPolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getIamPolicy( + request, + (err?: Error|null, result?: protos.google.iam.v1.IPolicy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; + const expectedError = new Error('expected'); + client.innerApiCalls.getIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getIamPolicy(request), expectedError); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy with closed client', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close().catch(err => {throw err}); + await assert.rejects(client.getIamPolicy(request), expectedError); + }); + }); + + describe('echo', () => { + it('invokes echo without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoResponse() + ); + client.innerApiCalls.echo = stubSimpleCall(expectedResponse); + const [response] = await client.echo(request); + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes echo without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoResponse() + ); + client.innerApiCalls.echo = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.echo( + request, + (err?: Error|null, result?: protos.google.duplicate_methods_test.v1.IEchoResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes echo with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoRequest() + ); + const expectedError = new Error('expected'); + client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.echo(request), expectedError); + }); + + it('invokes echo with closed client', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.duplicate_methods_test.v1.EchoRequest() + ); + const expectedError = new Error('The client has already been closed.'); + client.close().catch(err => {throw err}); + await assert.rejects(client.echo(request), expectedError); + }); + }); + + describe('listLocations', () => { + it('invokes listLocations without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + ]; + client.innerApiCalls.listLocations = stubSimpleCall(expectedResponse); + const [response] = await client.listLocations(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listLocations without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + ]; + client.innerApiCalls.listLocations = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listLocations( + request, + (err?: Error|null, result?: protos.google.cloud.location.ILocation[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listLocations with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedError = new Error('expected'); + client.innerApiCalls.listLocations = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listLocations(request), expectedError); + const actualRequest = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listLocations as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listLocationsStream without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + ]; + client.descriptors.page.listLocations.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listLocationsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.location.Location[] = []; + stream.on('data', (response: protos.google.cloud.location.Location) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert((client.descriptors.page.listLocations.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listLocations, request)); + assert( + (client.descriptors.page.listLocations.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listLocationsStream with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedError = new Error('expected'); + client.descriptors.page.listLocations.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listLocationsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.location.Location[] = []; + stream.on('data', (response: protos.google.cloud.location.Location) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listLocations.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listLocations, request)); + assert( + (client.descriptors.page.listLocations.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listLocations without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + generateSampleMessage(new protos.google.cloud.location.Location()), + ]; + client.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.location.ILocation[] = []; + const iterable = client.listLocationsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listLocations.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listLocations.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listLocations with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.location.ListLocationsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.location.ListLocationsRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; + const expectedError = new Error('expected'); + client.descriptors.page.listLocations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listLocationsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.location.ILocation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listLocations.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listLocations.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + describe('setIamPolicy', () => { + it('invokes setIamPolicy without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); + const response = await client.setIamPolicy(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes setIamPolicy without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.Policy() + ); + client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.setIamPolicy( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }).catch(err => {throw err}); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0)); + }); + it('invokes setIamPolicy with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.SetIamPolicyRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); + assert((client.iamClient.setIamPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('testIamPermissions', () => { + it('invokes testIamPermissions without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); + const response = await client.testIamPermissions(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes testIamPermissions without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsResponse() + ); + client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.testIamPermissions( + request, + expectedOptions, + (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }).catch(err => {throw err}); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0)); + }); + it('invokes testIamPermissions with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new IamProtos.google.iam.v1.TestIamPermissionsRequest() + ); + request.resource = ''; + const expectedHeaderRequestParams = 'resource='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); + assert((client.iamClient.testIamPermissions as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + describe('getLocation', () => { + it('invokes getLocation without error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.GetLocationRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new LocationProtos.google.cloud.location.Location() + ); + client.locationsClient.getLocation = stubSimpleCall(expectedResponse); + const response = await client.getLocation(request, expectedOptions); + assert.deepStrictEqual(response, [expectedResponse]); + assert((client.locationsClient.getLocation as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + it('invokes getLocation without error using callback', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.GetLocationRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new LocationProtos.google.cloud.location.Location() + ); + client.locationsClient.getLocation = sinon.stub().callsArgWith(2, null, expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getLocation( + request, + expectedOptions, + ( + err?: Error | null, + result?: LocationProtos.google.cloud.location.ILocation | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.locationsClient.getLocation as SinonStub) + .getCall(0)); + }); + it('invokes getLocation with error', async () => { + const client = new duplicatemethodstestserviceModule.v1.DuplicateMethodsTestServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + await client.initialize(); + const request = generateSampleMessage( + new LocationProtos.google.cloud.location.GetLocationRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.locationsClient.getLocation = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getLocation(request, expectedOptions), expectedError); + assert((client.locationsClient.getLocation as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); +}); diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/tsconfig.json b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/tsconfig.json new file mode 100644 index 00000000000..ca73e7bfc82 --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/tsconfig.json @@ -0,0 +1,22 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build", + "resolveJsonModule": true, + "lib": [ + "es2023", + "dom" + ] + }, + "include": [ + "src/*.ts", + "src/**/*.ts", + "test/*.ts", + "test/**/*.ts", + "system-test/*.ts", + "src/**/*.json", + "samples/**/*.json", + "protos/protos.json" + ] +} diff --git a/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/webpack.config.js b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/webpack.config.js new file mode 100644 index 00000000000..59e373662ce --- /dev/null +++ b/core/generator/gapic-generator-typescript/baselines/duplicate_methods_test/webpack.config.js @@ -0,0 +1,64 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +const path = require('path'); + +module.exports = { + entry: './src/index.ts', + output: { + library: 'DuplicateMethodsTestService', + filename: './duplicate-methods-test-service.js', + }, + node: { + child_process: 'empty', + fs: 'empty', + crypto: 'empty', + }, + resolve: { + alias: { + '../../../package.json': path.resolve(__dirname, 'package.json'), + }, + extensions: ['.js', '.json', '.ts'], + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/ + }, + { + test: /node_modules[\\/]@grpc[\\/]grpc-js/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]grpc/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]retry-request/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]https?-proxy-agent/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]gtoken/, + use: 'null-loader' + }, + ], + }, + mode: 'production', +}; diff --git a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_iam.njk b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_iam.njk index 281ad5a33bc..2e3d3b938f5 100644 --- a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_iam.njk +++ b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_iam.njk @@ -1,4 +1,4 @@ -{%- macro iamServiceMethods() -%} +{%- macro iamServiceMethods(service) -%} {#- This part will be added into src/version/client.ts. If the --service-yaml contains "google.iam.v1.IAMPolicy", it means the client requires IAM methods [setIamPolicy, getIamPolicy, testIamPermission]. @@ -30,7 +30,8 @@ * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. * The promise has a method named "cancel" which cancels the ongoing API call. */ - getIamPolicy( +{%- if service.iamPolicyMixinFlags.getIamPolicy == true %} + /** request: IamProtos.google.iam.v1.GetIamPolicyRequest, options?: | gax.CallOptions @@ -47,6 +48,7 @@ ):Promise<[IamProtos.google.iam.v1.Policy]> { return this.iamClient.getIamPolicy(request, options, callback); } +{%- endif %} /** * Returns permissions that a caller has on the specified resource. If the @@ -77,7 +79,8 @@ * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. * The promise has a method named "cancel" which cancels the ongoing API call. */ - setIamPolicy( +{%- if service.iamPolicyMixinFlags.setIamPolicy %} + /** request: IamProtos.google.iam.v1.SetIamPolicyRequest, options?: | gax.CallOptions @@ -94,6 +97,7 @@ ):Promise<[IamProtos.google.iam.v1.Policy]> { return this.iamClient.setIamPolicy(request, options, callback); } +{%- endif %} /** * Returns permissions that a caller has on the specified resource. If the @@ -125,7 +129,8 @@ * The promise has a method named "cancel" which cancels the ongoing API call. * */ - testIamPermissions( +{%- if service.iamPolicyMixinFlags.testIamPermissions %} + /** request: IamProtos.google.iam.v1.TestIamPermissionsRequest, options?: | gax.CallOptions @@ -142,4 +147,5 @@ ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { return this.iamClient.testIamPermissions(request, options, callback); } +{%- endif %} {%- endmacro -%} diff --git a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_locations.njk b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_locations.njk index 728b057d544..1db7c0bbfc5 100644 --- a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_locations.njk +++ b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_locations.njk @@ -1,4 +1,4 @@ -{%- macro locationServiceMethods() -%} +{%- macro locationServiceMethods(service) -%} {#- This part will be added into src/version/client.ts. If the --service-yaml contains "google.cloud.location.Locations", it means the client requires Locations methods [getLocation, listLocations]. @@ -6,6 +6,7 @@ [getLocation, listLocations] methods are created which is calling the corresponding methods from LocationsClient in google-gax. Note that since the listLocations method is a paginated method, we default to using listLocationsAsync for ease of use. -#} +{%- if service.locationMixinFlags.getLocation %} /** * Gets information about a location. * @@ -45,7 +46,9 @@ ): Promise { return this.locationsClient.getLocation(request, options, callback); } +{%- endif %} +{%- if service.locationMixinFlags.listLocations %} /** * Lists information about the supported locations for this service. Returns an iterable object. * @@ -83,4 +86,5 @@ ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } +{%- endif %} {%- endmacro -%} diff --git a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk index da67e250fe7..e4a61222783 100644 --- a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk +++ b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk @@ -1103,10 +1103,10 @@ export class {{ service.name }}Client { {%- endif %} {%- endfor %} {%- if service.IAMPolicyMixin > 0 %} -{{ iam.iamServiceMethods()}} +{{ iam.iamServiceMethods(service)}} {% endif -%} {%- if service.LocationMixin > 0 %} -{{ location.locationServiceMethods()}} +{{ location.locationServiceMethods(service)}} {% endif -%} {%- if service.LongRunningOperationsMixin > 0 %} {{ operations.operationsServiceMethods()}} diff --git a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/test/gapic_$service_$version.ts.njk b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/test/gapic_$service_$version.ts.njk index cb601868033..b23796cfb16 100644 --- a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/test/gapic_$service_$version.ts.njk +++ b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/test/gapic_$service_$version.ts.njk @@ -1089,6 +1089,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { {%- if (service.IAMPolicyMixin) > 0 %} {%- set IAMmethods = ['getIamPolicy', 'setIamPolicy', 'testIamPermissions'] %} {%- for method in IAMmethods %} +{%- if service.iamPolicyMixinFlags[method] %} describe('{{ method }}', () => { it('invokes {{ method }} without error', async () => { const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client( @@ -1204,10 +1205,12 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { .getCall(0).calledWith(request, expectedOptions, undefined)); }); }); +{%- endif %} {%- endfor %} {%- endif %} {%- if service.LocationMixin > 0 %} {%- set method = 'getLocation' %} +{%- if service.locationMixinFlags.getLocation %} describe('{{ method }}', () => { it('invokes {{ method }} without error', async () => { const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client( @@ -1314,7 +1317,9 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { .getCall(0).calledWith(request, expectedOptions, undefined)); }); }); +{%- endif %} {%- set method = 'listLocations' %} +{%- if service.locationMixinFlags.listLocations %} describe('{{ method }}Async', () => { it('uses async iteration with {{method}} without error', async () => { const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client({{- util.initClientOptions(api.rest) -}}); @@ -1396,6 +1401,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { }); }); {%- endif %} +{%- endif %} {%- if (service.LongRunningOperationsMixin) > 0 %} {%- set Operationsmethods = ['getOperation', 'cancelOperation', 'deleteOperation'] %} {%- for method in Operationsmethods %} diff --git a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_iam.njk b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_iam.njk index 281ad5a33bc..a756f6d798d 100644 --- a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_iam.njk +++ b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_iam.njk @@ -1,4 +1,4 @@ -{%- macro iamServiceMethods() -%} +{%- macro iamServiceMethods(service) -%} {#- This part will be added into src/version/client.ts. If the --service-yaml contains "google.iam.v1.IAMPolicy", it means the client requires IAM methods [setIamPolicy, getIamPolicy, testIamPermission]. @@ -30,7 +30,8 @@ * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. * The promise has a method named "cancel" which cancels the ongoing API call. */ - getIamPolicy( +{%- if service.iamPolicyMixinFlags.getIamPolicy %} + /** request: IamProtos.google.iam.v1.GetIamPolicyRequest, options?: | gax.CallOptions @@ -47,6 +48,7 @@ ):Promise<[IamProtos.google.iam.v1.Policy]> { return this.iamClient.getIamPolicy(request, options, callback); } +{%- endif %} /** * Returns permissions that a caller has on the specified resource. If the @@ -77,7 +79,8 @@ * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. * The promise has a method named "cancel" which cancels the ongoing API call. */ - setIamPolicy( +{%- if service.iamPolicyMixinFlags.setIamPolicy %} + /** request: IamProtos.google.iam.v1.SetIamPolicyRequest, options?: | gax.CallOptions @@ -94,6 +97,7 @@ ):Promise<[IamProtos.google.iam.v1.Policy]> { return this.iamClient.setIamPolicy(request, options, callback); } +{%- endif %} /** * Returns permissions that a caller has on the specified resource. If the @@ -125,7 +129,8 @@ * The promise has a method named "cancel" which cancels the ongoing API call. * */ - testIamPermissions( +{%- if service.iamPolicyMixinFlags.testIamPermissions %} + /** request: IamProtos.google.iam.v1.TestIamPermissionsRequest, options?: | gax.CallOptions @@ -142,4 +147,5 @@ ):Promise<[IamProtos.google.iam.v1.TestIamPermissionsResponse]> { return this.iamClient.testIamPermissions(request, options, callback); } +{%- endif %} {%- endmacro -%} diff --git a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_locations.njk b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_locations.njk index 728b057d544..1db7c0bbfc5 100644 --- a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_locations.njk +++ b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_locations.njk @@ -1,4 +1,4 @@ -{%- macro locationServiceMethods() -%} +{%- macro locationServiceMethods(service) -%} {#- This part will be added into src/version/client.ts. If the --service-yaml contains "google.cloud.location.Locations", it means the client requires Locations methods [getLocation, listLocations]. @@ -6,6 +6,7 @@ [getLocation, listLocations] methods are created which is calling the corresponding methods from LocationsClient in google-gax. Note that since the listLocations method is a paginated method, we default to using listLocationsAsync for ease of use. -#} +{%- if service.locationMixinFlags.getLocation %} /** * Gets information about a location. * @@ -45,7 +46,9 @@ ): Promise { return this.locationsClient.getLocation(request, options, callback); } +{%- endif %} +{%- if service.locationMixinFlags.listLocations %} /** * Lists information about the supported locations for this service. Returns an iterable object. * @@ -83,4 +86,5 @@ ): AsyncIterable { return this.locationsClient.listLocationsAsync(request, options); } +{%- endif %} {%- endmacro -%} diff --git a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/src/$version/$service_client.ts.njk b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/src/$version/$service_client.ts.njk index 62d4d28e97d..ce28ddabb44 100644 --- a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/src/$version/$service_client.ts.njk +++ b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/src/$version/$service_client.ts.njk @@ -1110,10 +1110,10 @@ export class {{ service.name }}Client { {%- endif %} {%- endfor %} {%- if service.IAMPolicyMixin > 0 %} -{{ iam.iamServiceMethods()}} +{{ iam.iamServiceMethods(service)}} {% endif -%} {%- if service.LocationMixin > 0 %} -{{ location.locationServiceMethods()}} +{{ location.locationServiceMethods(service)}} {% endif -%} {%- if service.LongRunningOperationsMixin > 0 %} {{ operations.operationsServiceMethods()}} diff --git a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/test/gapic_$service_$version.ts.njk b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/test/gapic_$service_$version.ts.njk index 0d723c4e2ea..bf5cc387e40 100644 --- a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/test/gapic_$service_$version.ts.njk +++ b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/test/gapic_$service_$version.ts.njk @@ -1095,6 +1095,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { {%- if (service.IAMPolicyMixin) > 0 %} {%- set IAMmethods = ['getIamPolicy', 'setIamPolicy', 'testIamPermissions'] %} {%- for method in IAMmethods %} +{%- if service.iamPolicyMixinFlags[method] %} describe('{{ method }}', () => { it('invokes {{ method }} without error', async () => { const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client( @@ -1210,10 +1211,12 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { .getCall(0).calledWith(request, expectedOptions, undefined)); }); }); +{%- endif %} {%- endfor %} {%- endif %} {%- if service.LocationMixin > 0 %} {%- set method = 'getLocation' %} +{%- if service.locationMixinFlags.getLocation %} describe('{{ method }}', () => { it('invokes {{ method }} without error', async () => { const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client( @@ -1320,7 +1323,9 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { .getCall(0).calledWith(request, expectedOptions, undefined)); }); }); +{%- endif %} {%- set method = 'listLocations' %} +{%- if service.locationMixinFlags.listLocations %} describe('{{ method }}Async', () => { it('uses async iteration with {{method}} without error', async () => { const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client({{- util.initClientOptions(api.rest) -}}); @@ -1402,6 +1407,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { }); }); {%- endif %} +{%- endif %} {%- if (service.LongRunningOperationsMixin) > 0 %} {%- set Operationsmethods = ['getOperation', 'cancelOperation', 'deleteOperation'] %} {%- for method in Operationsmethods %} diff --git a/core/generator/gapic-generator-typescript/test-fixtures/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto b/core/generator/gapic-generator-typescript/test-fixtures/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto new file mode 100644 index 00000000000..b91e79094ff --- /dev/null +++ b/core/generator/gapic-generator-typescript/test-fixtures/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto @@ -0,0 +1,66 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.duplicate_methods_test.v1; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/iam/v1/iam_policy.proto"; +import "google/iam/v1/policy.proto"; +import "google/cloud/location/locations.proto"; + +option csharp_namespace = "Google.DuplicateMethodsTest.V1"; +option go_package = "google.golang.org/genproto/googleapis/duplicate_methods_test/v1;duplicate_methods_test"; +option java_multiple_files = true; +option java_outer_classname = "DuplicateMethodsTestProto"; +option java_package = "com.google.duplicate_methods_test.v1"; +option php_namespace = "Google\\DuplicateMethodsTest\\V1"; +option ruby_package = "Google::DuplicateMethodsTest::V1"; + +service DuplicateMethodsTestService { + option (google.api.default_host) = "duplicatemethodstest.googleapis.com"; + option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; + + // Native GetIamPolicy method that conflicts with the IAMPolicy mixin. + rpc GetIamPolicy(google.iam.v1.GetIamPolicyRequest) returns (google.iam.v1.Policy) { + option (google.api.http) = { + get: "/v1/{resource=projects/*}:getIamPolicy" + }; + } + + // Native ListLocations method that conflicts with the Locations mixin. + rpc ListLocations(google.cloud.location.ListLocationsRequest) returns (google.cloud.location.ListLocationsResponse) { + option (google.api.http) = { + get: "/v1/{name=projects/*}/locations" + }; + } + + // Another native method to ensure the service is valid and has other methods. + rpc Echo(EchoRequest) returns (EchoResponse) { + option (google.api.http) = { + post: "/v1/echo" + body: "*" + }; + } +} + +message EchoRequest { + string content = 1; +} + +message EchoResponse { + string content = 1; +} diff --git a/core/generator/gapic-generator-typescript/test-fixtures/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.yaml b/core/generator/gapic-generator-typescript/test-fixtures/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.yaml new file mode 100644 index 00000000000..2cacee59791 --- /dev/null +++ b/core/generator/gapic-generator-typescript/test-fixtures/protos/google/duplicatemethodstest/v1/duplicate_methods_test_v1.yaml @@ -0,0 +1,26 @@ +type: google.api.Service +config_version: 3 +name: duplicatemethodstest.googleapis.com +title: Duplicate Methods Test Service API + +apis: +- name: google.duplicate_methods_test.v1.DuplicateMethodsTestService +- name: google.iam.v1.IAMPolicy +- name: google.cloud.location.Locations + +# We don't need to define HTTP rules for the native methods here if they are in the proto, +# but we can define standard ones if we want to ensure full coverage. +http: + rules: + - selector: google.iam.v1.IAMPolicy.SetIamPolicy + post: '/v1/{resource=projects/*}:setIamPolicy' + body: '*' + - selector: google.iam.v1.IAMPolicy.GetIamPolicy + get: '/v1/{resource=projects/*}:getIamPolicy' + - selector: google.iam.v1.IAMPolicy.TestIamPermissions + post: '/v1/{resource=projects/*}:testIamPermissions' + body: '*' + - selector: google.cloud.location.Locations.GetLocation + get: '/v1/{name=projects/*}/locations' + - selector: google.cloud.location.Locations.ListLocations + get: '/v1/{name=projects/*}/locations' diff --git a/core/generator/gapic-generator-typescript/typescript/src/schema/proto.ts b/core/generator/gapic-generator-typescript/typescript/src/schema/proto.ts index dc3d4e20c48..d5c52199bf0 100644 --- a/core/generator/gapic-generator-typescript/typescript/src/schema/proto.ts +++ b/core/generator/gapic-generator-typescript/typescript/src/schema/proto.ts @@ -83,6 +83,21 @@ export interface MethodDescriptorProto maxResultsParameter?: boolean; } +export interface MixinConfig { + enabled: boolean; +} + +export interface IamPolicyMixinConfig extends MixinConfig { + getIamPolicy: boolean; + setIamPolicy: boolean; + testIamPermissions: boolean; +} + +export interface LocationMixinConfig extends MixinConfig { + getLocation: boolean; + listLocations: boolean; +} + export interface ServiceDescriptorProto extends protos.google.protobuf.IServiceDescriptorProto { internalMethods: MethodDescriptorProto[]; @@ -111,6 +126,8 @@ export interface ServiceDescriptorProto IAMPolicyMixin: number; LocationMixin: number; LongRunningOperationsMixin: number; + iamPolicyMixinFlags?: IamPolicyMixinConfig; + locationMixinFlags?: LocationMixinConfig; protoFile: string; diregapicLRO?: MethodDescriptorProto[]; httpRules?: protos.google.api.IHttpRule[]; @@ -1031,6 +1048,21 @@ export function augmentService(parameters: AugmentServiceParameters) { SelectiveGapicType.INTERNAL, ); + const nativeMethods = augmentedService.method || []; + const nativeMethodNames = nativeMethods.map(m => m.name); + augmentedService.iamPolicyMixinFlags = { + enabled: augmentedService.IAMPolicyMixin === 1, + getIamPolicy: !nativeMethodNames.includes('GetIamPolicy'), + setIamPolicy: !nativeMethodNames.includes('SetIamPolicy'), + testIamPermissions: !nativeMethodNames.includes('TestIamPermissions'), + }; + + augmentedService.locationMixinFlags = { + enabled: augmentedService.LocationMixin === 1, + getLocation: !nativeMethodNames.includes('GetLocation'), + listLocations: !nativeMethodNames.includes('ListLocations'), + }; + augmentedService.bundleConfigsMethods = augmentedService.method.filter( method => method.bundleConfig, ); diff --git a/core/generator/gapic-generator-typescript/typescript/test/unit/baselines-esm.ts b/core/generator/gapic-generator-typescript/typescript/test/unit/baselines-esm.ts index 08e36ff03e8..47ada20e155 100644 --- a/core/generator/gapic-generator-typescript/typescript/test/unit/baselines-esm.ts +++ b/core/generator/gapic-generator-typescript/typescript/test/unit/baselines-esm.ts @@ -23,6 +23,14 @@ describe('Baseline tests: ESM', () => { useCommonProto: true, format: 'esm', }); + runBaselineTest({ + baselineName: 'duplicate_methods_test-esm', + outputDir: '.test-out-duplicate_methods_test-esm', + protoPath: 'google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto', + serviceYaml: 'google/duplicatemethodstest/v1/duplicate_methods_test_v1.yaml', + useCommonProto: true, + format: 'esm', + }); runBaselineTest({ baselineName: 'dlp-esm', outputDir: '.test-out-dlp-esm', diff --git a/core/generator/gapic-generator-typescript/typescript/test/unit/baselines.ts b/core/generator/gapic-generator-typescript/typescript/test/unit/baselines.ts index 735b2e7ee22..8475cf03d10 100644 --- a/core/generator/gapic-generator-typescript/typescript/test/unit/baselines.ts +++ b/core/generator/gapic-generator-typescript/typescript/test/unit/baselines.ts @@ -22,6 +22,13 @@ describe('Baseline tests', () => { protoPath: 'google/cloud/bigquery/v2/*.proto', useCommonProto: true, }); + runBaselineTest({ + baselineName: 'duplicate_methods_test', + outputDir: '.test-out-duplicate_methods_test', + protoPath: 'google/duplicatemethodstest/v1/duplicate_methods_test_v1.proto', + serviceYaml: 'google/duplicatemethodstest/v1/duplicate_methods_test_v1.yaml', + useCommonProto: true, + }); runBaselineTest({ baselineName: 'dlp', outputDir: '.test-out-dlp', diff --git a/core/generator/gapic-generator-typescript/typescript/test/unit/proto.ts b/core/generator/gapic-generator-typescript/typescript/test/unit/proto.ts index 26cc3a16793..1d274ec2893 100644 --- a/core/generator/gapic-generator-typescript/typescript/test/unit/proto.ts +++ b/core/generator/gapic-generator-typescript/typescript/test/unit/proto.ts @@ -420,6 +420,52 @@ describe('src/schema/proto.ts', () => { assert.strictEqual(proto.services[fd.service[0].name].protoFile, fd.name); }); + it('should calculate mixin flags accurately for duplicate methods', () => { + const fd = {} as protos.google.protobuf.FileDescriptorProto; + fd.service = [{} as protos.google.protobuf.ServiceDescriptorProto]; + fd.service[0].name = 'TestService'; + fd.service[0].method = [ + {name: 'GetIamPolicy'}, + {name: 'ListLocations'}, + ] as protos.google.protobuf.MethodDescriptorProto[]; + + // Simulating mixins being enabled (non-zero value) + (fd.service[0] as any).IAMPolicyMixin = 1; + (fd.service[0] as any).LocationMixin = 1; + + const options: Options = { + grpcServiceConfig: {} as protos.grpc.service_config.ServiceConfig, + }; + + const augmentedService = augmentService({ + allMessages: {}, + localMessages: {}, + packageName: 'google.showcase.v1beta1', + service: fd.service[0], + commentsMap: new CommentsMap([fd]), + allResourceDatabase: new ResourceDatabase(), + resourceDatabase: new ResourceDatabase(), + options, + protoFile: 'fd', + }); + + assert.strictEqual( + augmentedService.iamPolicyMixinFlags?.getIamPolicy, + false + ); // Native GetIamPolicy exists + assert.strictEqual(augmentedService.iamPolicyMixinFlags?.setIamPolicy, true); + assert.strictEqual( + augmentedService.iamPolicyMixinFlags?.testIamPermissions, + true + ); + + assert.strictEqual(augmentedService.locationMixinFlags?.getLocation, true); + assert.strictEqual( + augmentedService.locationMixinFlags?.listLocations, + false + ); // Native ListLocations exists + }); + it('should return api version if it exists', () => { const fd = {} as protos.google.protobuf.FileDescriptorProto; fd.name = 'google/cloud/showcase/v1beta1/test.proto';